Author: zturner Date: Wed Jul 2 12:24:07 2014 New Revision: 212192 URL: http://llvm.org/viewvc/llvm-project?rev=212192&view=rev Log: 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 Modified: lldb/trunk/include/lldb/Core/Module.h lldb/trunk/include/lldb/Core/ValueObject.h lldb/trunk/include/lldb/Core/ValueObjectChild.h lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h lldb/trunk/include/lldb/Symbol/ObjectFile.h lldb/trunk/include/lldb/Target/PathMappingList.h lldb/trunk/source/Core/Module.cpp lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp lldb/trunk/source/Expression/IRForTarget.cpp lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp lldb/trunk/source/Symbol/ObjectFile.cpp lldb/trunk/source/Target/PathMappingList.cpp Modified: lldb/trunk/include/lldb/Core/Module.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Module.h (original) +++ lldb/trunk/include/lldb/Core/Module.h Wed Jul 2 12:24:07 2014 @@ -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); Modified: lldb/trunk/include/lldb/Core/ValueObject.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObject.h (original) +++ lldb/trunk/include/lldb/Core/ValueObject.h Wed Jul 2 12:24:07 2014 @@ -468,7 +468,7 @@ public: return true; } - virtual off_t + virtual lldb::offset_t GetByteOffset() { return 0; Modified: lldb/trunk/include/lldb/Core/ValueObjectChild.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectChild.h?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectChild.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectChild.h Wed Jul 2 12:24:07 2014 @@ -32,7 +32,7 @@ public: return m_byte_size; } - virtual off_t + virtual lldb::offset_t GetByteOffset() { return m_byte_offset; Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Wed Jul 2 12:24:07 2014 @@ -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) Modified: lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h Wed Jul 2 12:24:07 2014 @@ -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: Modified: lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h (original) +++ lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h Wed Jul 2 12:24:07 2014 @@ -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 Modified: lldb/trunk/include/lldb/Symbol/ObjectFile.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ObjectFile.h?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ObjectFile.h (original) +++ lldb/trunk/include/lldb/Symbol/ObjectFile.h Wed Jul 2 12:24:07 2014 @@ -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 Modified: lldb/trunk/include/lldb/Target/PathMappingList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/PathMappingList.h?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/PathMappingList.h (original) +++ lldb/trunk/include/lldb/Target/PathMappingList.h Wed Jul 2 12:24:07 2014 @@ -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); Modified: lldb/trunk/source/Core/Module.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/source/Core/Module.cpp (original) +++ lldb/trunk/source/Core/Module.cpp Wed Jul 2 12:24:07 2014 @@ -235,7 +235,7 @@ Module::Module (const ModuleSpec &module 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()), Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Wed Jul 2 12:24:07 2014 @@ -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::GetStructIn ( 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 ) Modified: lldb/trunk/source/Expression/IRForTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRForTarget.cpp (original) +++ lldb/trunk/source/Expression/IRForTarget.cpp Wed Jul 2 12:24:07 2014 @@ -1519,11 +1519,11 @@ IRForTarget::MaybeHandleVariable (Value } 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 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 { 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 } if (log) - log->Printf(" \"%s\" (\"%s\") placed at %" PRId64, + log->Printf(" \"%s\" (\"%s\") placed at %" PRIu64, name.GetCString(), decl->getNameAsString().c_str(), offset); Modified: lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp (original) +++ lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp Wed Jul 2 12:24:07 2014 @@ -322,14 +322,14 @@ ObjectFileJIT::SetLoadAddress (Target &t 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 ll } return 0; } + size_t ObjectFileJIT::ReadSectionData (const lldb_private::Section *section, lldb_private::DataExtractor& section_data) const Modified: lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h (original) +++ lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h Wed Jul 2 12:24:07 2014 @@ -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 Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp Wed Jul 2 12:24:07 2014 @@ -680,32 +680,32 @@ GDBRemoteRegisterContext::WriteAllRegist // 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 Modified: lldb/trunk/source/Symbol/ObjectFile.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ObjectFile.cpp?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ObjectFile.cpp (original) +++ lldb/trunk/source/Symbol/ObjectFile.cpp Wed Jul 2 12:24:07 2014 @@ -439,7 +439,7 @@ ObjectFile::ReadMemory (const ProcessSP } 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_ } 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 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 Secti } 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); Modified: lldb/trunk/source/Target/PathMappingList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/PathMappingList.cpp?rev=212192&r1=212191&r2=212192&view=diff ============================================================================== --- lldb/trunk/source/Target/PathMappingList.cpp (original) +++ lldb/trunk/source/Target/PathMappingList.cpp Wed Jul 2 12:24:07 2014 @@ -132,9 +132,9 @@ PathMappingList::Replace (const ConstStr } 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; _______________________________________________ lldb-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
