diff options
| author | Zachary Turner <zturner@google.com> | 2014-07-02 17:24:07 +0000 |
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2014-07-02 17:24:07 +0000 |
| commit | a746e8e58a460f6667cc9e16eb94d256ea4b0121 (patch) | |
| tree | 39bdccf355cbc36ce7820f8831fc39639e0b694b | |
| parent | 379b97f2856afebc4fbdfb8bdde2251c046a10a3 (diff) | |
| download | bcm5719-llvm-a746e8e58a460f6667cc9e16eb94d256ea4b0121.tar.gz bcm5719-llvm-a746e8e58a460f6667cc9e16eb94d256ea4b0121.zip | |
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
| -rw-r--r-- | lldb/include/lldb/Core/Module.h | 2 | ||||
| -rw-r--r-- | lldb/include/lldb/Core/ValueObject.h | 2 | ||||
| -rw-r--r-- | lldb/include/lldb/Core/ValueObjectChild.h | 2 | ||||
| -rw-r--r-- | lldb/include/lldb/Expression/ClangExpressionDeclMap.h | 8 | ||||
| -rw-r--r-- | lldb/include/lldb/Expression/ClangExpressionVariable.h | 6 | ||||
| -rw-r--r-- | lldb/include/lldb/Symbol/DWARFCallFrameInfo.h | 2 | ||||
| -rw-r--r-- | lldb/include/lldb/Symbol/ObjectFile.h | 6 | ||||
| -rw-r--r-- | lldb/include/lldb/Target/PathMappingList.h | 2 | ||||
| -rw-r--r-- | lldb/source/Core/Module.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Expression/ClangExpressionDeclMap.cpp | 6 | ||||
| -rw-r--r-- | lldb/source/Expression/IRForTarget.cpp | 10 | ||||
| -rw-r--r-- | lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp | 7 | ||||
| -rw-r--r-- | lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h | 2 | ||||
| -rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp | 14 | ||||
| -rw-r--r-- | lldb/source/Symbol/ObjectFile.cpp | 14 | ||||
| -rw-r--r-- | lldb/source/Target/PathMappingList.cpp | 4 |
16 files changed, 45 insertions, 44 deletions
diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h index d95b5dfb8fb..fe5de649ebf 100644 --- a/lldb/include/lldb/Core/Module.h +++ b/lldb/include/lldb/Core/Module.h @@ -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); diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index a2ba44f73b8..ccda33a22e0 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -468,7 +468,7 @@ public: return true; } - virtual off_t + virtual lldb::offset_t GetByteOffset() { return 0; diff --git a/lldb/include/lldb/Core/ValueObjectChild.h b/lldb/include/lldb/Core/ValueObjectChild.h index 40c40608887..07d1f294bd8 100644 --- a/lldb/include/lldb/Core/ValueObjectChild.h +++ b/lldb/include/lldb/Core/ValueObjectChild.h @@ -32,7 +32,7 @@ public: return m_byte_size; } - virtual off_t + virtual lldb::offset_t GetByteOffset() { return m_byte_offset; diff --git a/lldb/include/lldb/Expression/ClangExpressionDeclMap.h b/lldb/include/lldb/Expression/ClangExpressionDeclMap.h index b04e1bd6f11..8a4aa82b872 100644 --- a/lldb/include/lldb/Expression/ClangExpressionDeclMap.h +++ b/lldb/include/lldb/Expression/ClangExpressionDeclMap.h @@ -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) diff --git a/lldb/include/lldb/Expression/ClangExpressionVariable.h b/lldb/include/lldb/Expression/ClangExpressionVariable.h index 5202f095da1..5ee7a305894 100644 --- a/lldb/include/lldb/Expression/ClangExpressionVariable.h +++ b/lldb/include/lldb/Expression/ClangExpressionVariable.h @@ -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: diff --git a/lldb/include/lldb/Symbol/DWARFCallFrameInfo.h b/lldb/include/lldb/Symbol/DWARFCallFrameInfo.h index 13a14f8c404..e67a5a2a8e2 100644 --- a/lldb/include/lldb/Symbol/DWARFCallFrameInfo.h +++ b/lldb/include/lldb/Symbol/DWARFCallFrameInfo.h @@ -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 diff --git a/lldb/include/lldb/Symbol/ObjectFile.h b/lldb/include/lldb/Symbol/ObjectFile.h index 6488cca90ea..0211a13ba37 100644 --- a/lldb/include/lldb/Symbol/ObjectFile.h +++ b/lldb/include/lldb/Symbol/ObjectFile.h @@ -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 diff --git a/lldb/include/lldb/Target/PathMappingList.h b/lldb/include/lldb/Target/PathMappingList.h index b5bcbbfd768..17185cb6849 100644 --- a/lldb/include/lldb/Target/PathMappingList.h +++ b/lldb/include/lldb/Target/PathMappingList.h @@ -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); diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 781d4e1b917..b043857cc8d 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -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()), diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp index 66673dbb463..cce548cf7e7 100644 --- a/lldb/source/Expression/ClangExpressionDeclMap.cpp +++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp @@ -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 ) diff --git a/lldb/source/Expression/IRForTarget.cpp b/lldb/source/Expression/IRForTarget.cpp index c4b776d22ea..7571c253f6b 100644 --- a/lldb/source/Expression/IRForTarget.cpp +++ b/lldb/source/Expression/IRForTarget.cpp @@ -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); diff --git a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp index 5d9ff28fec8..5498bed13eb 100644 --- a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp +++ b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp @@ -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 diff --git a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h index 3a0e2ad679b..47140f5bcaf 100644 --- a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h +++ b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h @@ -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 diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp index 583f49c774d..1eed9ef7080 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -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 diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp index 962ae0083e8..11b54007120 100644 --- a/lldb/source/Symbol/ObjectFile.cpp +++ b/lldb/source/Symbol/ObjectFile.cpp @@ -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); diff --git a/lldb/source/Target/PathMappingList.cpp b/lldb/source/Target/PathMappingList.cpp index 0d70d03a476..2fd517829b8 100644 --- a/lldb/source/Target/PathMappingList.cpp +++ b/lldb/source/Target/PathMappingList.cpp @@ -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; |

