<rdar://problem/13069948>

Major fixed to allow reading files that are over 4GB. The main problems were that the DataExtractor was using 32 bit offsets as a data cursor, and since we mmap all of our object files we could run into cases where if we had a very large core file that was over 4GB, we were running into the 4GB boundary.

So I defined a new "lldb::offset_t" which should be used for all file offsets.

After making this change, I enabled warnings for data loss and for enexpected implicit conversions temporarily and found a ton of things that I fixed.

Any functions that take an index internally, should use "size_t" for any indexes and also should return "size_t" for any sizes of collections.

llvm-svn: 173463
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp b/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp
index bfff9f3..d9cac0d 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp
@@ -23,20 +23,24 @@
 // GetMaxU64 and GetMaxS64 wrap the similarly named methods from DataExtractor
 // with error handling code and provide for parsing a sequence of values.
 static bool
-GetMaxU64(const lldb_private::DataExtractor &data, 
-          uint32_t *offset, uint64_t *value, uint32_t byte_size) 
+GetMaxU64(const lldb_private::DataExtractor &data,
+          lldb::offset_t *offset,
+          uint64_t *value,
+          uint32_t byte_size)
 {
-    const uint32_t saved_offset = *offset;
+    const lldb::offset_t saved_offset = *offset;
     *value = data.GetMaxU64(offset, byte_size);
     return *offset != saved_offset;
 }
 
 static bool
 GetMaxU64(const lldb_private::DataExtractor &data, 
-          uint32_t *offset, uint64_t *value, uint32_t byte_size, 
+          lldb::offset_t *offset,
+          uint64_t *value,
+          uint32_t byte_size,
           uint32_t count) 
 {
-    uint32_t saved_offset = *offset;
+    lldb::offset_t saved_offset = *offset;
 
     for (uint32_t i = 0; i < count; ++i, ++value)
     {
@@ -51,19 +55,23 @@
 
 static bool
 GetMaxS64(const lldb_private::DataExtractor &data, 
-          uint32_t *offset, int64_t *value, uint32_t byte_size) 
+          lldb::offset_t *offset,
+          int64_t *value,
+          uint32_t byte_size)
 {
-    const uint32_t saved_offset = *offset;
+    const lldb::offset_t saved_offset = *offset;
     *value = data.GetMaxS64(offset, byte_size);
     return *offset != saved_offset;
 }
 
 static bool
 GetMaxS64(const lldb_private::DataExtractor &data, 
-          uint32_t *offset, int64_t *value, uint32_t byte_size, 
+          lldb::offset_t *offset,
+          int64_t *value,
+          uint32_t byte_size,
           uint32_t count) 
 {
-    uint32_t saved_offset = *offset;
+    lldb::offset_t saved_offset = *offset;
 
     for (uint32_t i = 0; i < count; ++i, ++value)
     {
@@ -95,7 +103,7 @@
 }
 
 bool
-ELFHeader::Parse(lldb_private::DataExtractor &data, uint32_t *offset) 
+ELFHeader::Parse(lldb_private::DataExtractor &data, lldb::offset_t *offset) 
 {
     // Read e_ident.  This provides byte order and address size info.
     if (data.GetU8(offset, &e_ident, EI_NIDENT) == NULL)
@@ -190,7 +198,7 @@
 
 bool
 ELFSectionHeader::Parse(const lldb_private::DataExtractor &data,
-                        uint32_t *offset) 
+                        lldb::offset_t *offset)
 {
     const unsigned byte_size = data.GetAddressByteSize();
 
@@ -226,7 +234,7 @@
 }
 
 bool
-ELFSymbol::Parse(const lldb_private::DataExtractor &data, uint32_t *offset) 
+ELFSymbol::Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
 {
     const unsigned byte_size = data.GetAddressByteSize();
     const bool parsing_32 = byte_size == 4;
@@ -276,7 +284,7 @@
 
 bool
 ELFProgramHeader::Parse(const lldb_private::DataExtractor &data, 
-                        uint32_t *offset) 
+                        lldb::offset_t *offset)
 {
     const uint32_t byte_size = data.GetAddressByteSize();
     const bool parsing_32 = byte_size == 4;
@@ -320,7 +328,7 @@
 }
 
 bool
-ELFDynamic::Parse(const lldb_private::DataExtractor &data, uint32_t *offset)
+ELFDynamic::Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
 {
     const unsigned byte_size = data.GetAddressByteSize();
     return GetMaxS64(data, offset, &d_tag, byte_size, 2);
@@ -335,7 +343,7 @@
 }
 
 bool
-ELFRel::Parse(const lldb_private::DataExtractor &data, uint32_t *offset)
+ELFRel::Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
 {
     const unsigned byte_size = data.GetAddressByteSize();
 
@@ -355,7 +363,7 @@
 }
 
 bool
-ELFRela::Parse(const lldb_private::DataExtractor &data, uint32_t *offset)
+ELFRela::Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
 {
     const unsigned byte_size = data.GetAddressByteSize();
 
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h b/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h
index 4579857..77e5cda 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h
@@ -123,7 +123,7 @@
     ///    True if the ELFSectionHeader was successfully read and false
     ///    otherwise.
     bool
-    Parse(lldb_private::DataExtractor &data, uint32_t *offset);
+    Parse(lldb_private::DataExtractor &data, lldb::offset_t *offset);
 
     //--------------------------------------------------------------------------
     /// Examines at most EI_NIDENT bytes starting from the given pointer and
@@ -181,7 +181,7 @@
     ///    True if the ELFSectionHeader was successfully read and false
     ///    otherwise.
     bool
-    Parse(const lldb_private::DataExtractor &data, uint32_t *offset);
+    Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
 };
 
 //------------------------------------------------------------------------------
@@ -216,7 +216,7 @@
     ///    True if the ELFProgramHeader was successfully read and false
     ///    otherwise.
     bool
-    Parse(const lldb_private::DataExtractor &data, uint32_t *offset);
+    Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
 };
 
 //------------------------------------------------------------------------------
@@ -259,7 +259,7 @@
     /// @return
     ///    True if the ELFSymbol was successfully read and false otherwise.
     bool
-    Parse(const lldb_private::DataExtractor &data, uint32_t *offset);
+    Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
 };
 
 //------------------------------------------------------------------------------
@@ -292,7 +292,7 @@
     ///    True if the ELFDynamic entry was successfully read and false
     ///    otherwise.
     bool
-    Parse(const lldb_private::DataExtractor &data, uint32_t *offset);
+    Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
 };
 
 //------------------------------------------------------------------------------
@@ -320,7 +320,7 @@
     /// @return
     ///    True if the ELFRel entry was successfully read and false otherwise.
     bool
-    Parse(const lldb_private::DataExtractor &data, uint32_t *offset);
+    Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
 
     /// Returns the type when the given entry represents a 32-bit relocation.
     static unsigned
@@ -379,7 +379,7 @@
     /// @return
     ///    True if the ELFRela entry was successfully read and false otherwise.
     bool
-    Parse(const lldb_private::DataExtractor &data, uint32_t *offset);
+    Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
 
     /// Returns the type when the given entry represents a 32-bit relocation.
     static unsigned
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index e357aff..a430c26 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -53,7 +53,7 @@
     ~ELFRelocation();
 
     bool
-    Parse(const lldb_private::DataExtractor &data, uint32_t *offset);
+    Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
 
     static unsigned
     RelocType32(const ELFRelocation &rel);
@@ -94,7 +94,7 @@
 }
 
 bool
-ELFRelocation::Parse(const lldb_private::DataExtractor &data, uint32_t *offset)
+ELFRelocation::Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
 {
     if (reloc.is<ELFRel*>())
         return reloc.get<ELFRel*>()->Parse(data, offset);
@@ -270,28 +270,28 @@
     return eByteOrderInvalid;
 }
 
-size_t
+uint32_t
 ObjectFileELF::GetAddressByteSize() const
 {
     return m_data.GetAddressByteSize();
 }
 
-unsigned
+size_t
 ObjectFileELF::SectionIndex(const SectionHeaderCollIter &I)
 {
-    return std::distance(m_section_headers.begin(), I) + 1;
+    return std::distance(m_section_headers.begin(), I) + 1u;
 }
 
-unsigned
+size_t
 ObjectFileELF::SectionIndex(const SectionHeaderCollConstIter &I) const
 {
-    return std::distance(m_section_headers.begin(), I) + 1;
+    return std::distance(m_section_headers.begin(), I) + 1u;
 }
 
 bool
 ObjectFileELF::ParseHeader()
 {
-    uint32_t offset = GetOffset();
+    lldb::offset_t offset = GetOffset();
     return m_header.Parse(m_data, &offset);
 }
 
@@ -445,8 +445,8 @@
         ReadSectionData(dynstr, dynstr_data))
     {
         ELFDynamic symbol;
-        const unsigned section_size = dynsym_data.GetByteSize();
-        unsigned offset = 0;
+        const lldb::offset_t section_size = dynsym_data.GetByteSize();
+        lldb::offset_t offset = 0;
 
         // The only type of entries we are concerned with are tagged DT_NEEDED,
         // yielding the name of a required library.
@@ -492,7 +492,7 @@
         return 0;
 
     uint32_t idx;
-    uint32_t offset;
+    lldb::offset_t offset;
     for (idx = 0, offset = 0; idx < m_header.e_phnum; ++idx)
     {
         if (m_program_headers[idx].Parse(data, &offset) == false)
@@ -530,7 +530,7 @@
         return 0;
 
     uint32_t idx;
-    uint32_t offset;
+    lldb::offset_t offset;
     for (idx = 0, offset = 0; idx < m_header.e_shnum; ++idx)
     {
         if (m_section_headers[idx].Parse(data, &offset) == false)
@@ -698,9 +698,8 @@
              const DataExtractor &strtab_data)
 {
     ELFSymbol symbol;
-    uint32_t offset = 0;
-    const unsigned num_symbols = 
-        symtab_data.GetByteSize() / symtab_shdr->sh_entsize;
+    lldb::offset_t offset = 0;
+    const size_t num_symbols = symtab_data.GetByteSize() / symtab_shdr->sh_entsize;
 
     static ConstString text_section_name(".text");
     static ConstString init_section_name(".init");
@@ -877,8 +876,8 @@
     DataExtractor dynsym_data;
     if (ReadSectionData(dynsym, dynsym_data))
     {
-        const unsigned section_size = dynsym_data.GetByteSize();
-        unsigned cursor = 0;
+        const lldb::offset_t section_size = dynsym_data.GetByteSize();
+        lldb::offset_t cursor = 0;
 
         while (cursor < section_size)
         {
@@ -956,9 +955,9 @@
 {
     ELFRelocation rel(rel_type);
     ELFSymbol symbol;
-    uint32_t offset = 0;
-    const unsigned plt_entsize = plt_hdr->sh_entsize;
-    const unsigned num_relocations = rel_hdr->sh_size / rel_hdr->sh_entsize;
+    lldb::offset_t offset = 0;
+    const elf_xword plt_entsize = plt_hdr->sh_entsize;
+    const elf_xword num_relocations = rel_hdr->sh_size / rel_hdr->sh_entsize;
 
     typedef unsigned (*reloc_info_fn)(const ELFRelocation &rel);
     reloc_info_fn reloc_type;
@@ -985,7 +984,7 @@
         if (reloc_type(rel) != slot_type)
             continue;
 
-        unsigned symbol_offset = reloc_symbol(rel) * sym_hdr->sh_entsize;
+        lldb::offset_t symbol_offset = reloc_symbol(rel) * sym_hdr->sh_entsize;
         uint64_t plt_index = (i + 1) * plt_entsize;
 
         if (!symbol.Parse(symtab_data, &symbol_offset))
@@ -1378,7 +1377,7 @@
 // Dump an token value for the ELF section header member sh_flags
 //----------------------------------------------------------------------
 void
-ObjectFileELF::DumpELFSectionHeader_sh_flags(Stream *s, elf_word sh_flags)
+ObjectFileELF::DumpELFSectionHeader_sh_flags(Stream *s, elf_xword sh_flags)
 {
     *s  << ((sh_flags & SHF_WRITE) ? "WRITE" : "     ")
         << (((sh_flags & SHF_WRITE) && (sh_flags & SHF_ALLOC)) ? '+' : ' ')
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index 9bf6d73..f347c7b 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -84,7 +84,7 @@
     virtual bool
     IsExecutable () const;
 
-    virtual size_t
+    virtual uint32_t
     GetAddressByteSize() const;
 
     virtual lldb_private::Symtab *
@@ -168,11 +168,11 @@
     lldb_private::Address  m_entry_point_address;
 
     /// Returns a 1 based index of the given section header.
-    unsigned
+    size_t
     SectionIndex(const SectionHeaderCollIter &I);
 
     /// Returns a 1 based index of the given section header.
-    unsigned
+    size_t
     SectionIndex(const SectionHeaderCollConstIter &I) const;
 
     /// Parses all section headers present in this object file and populates
@@ -282,7 +282,7 @@
 
     static void
     DumpELFSectionHeader_sh_flags(lldb_private::Stream *s, 
-                                  elf::elf_word sh_flags);
+                                  elf::elf_xword sh_flags);
     //@}
 
     /// ELF dependent module dump routine.