Dump the type lookup table in oatdump.

Also fix the offset: we now store an offset relative to the vdex file
begin.

Test: test.py
Change-Id: I4c80d8fef19444437fe14365dd74d4cfde5f0ef2
diff --git a/libdexfile/dex/type_lookup_table.cc b/libdexfile/dex/type_lookup_table.cc
index c46b488..7f4130f 100644
--- a/libdexfile/dex/type_lookup_table.cc
+++ b/libdexfile/dex/type_lookup_table.cc
@@ -144,6 +144,19 @@
   return dex::kDexNoIndex;
 }
 
+void TypeLookupTable::Dump(std::ostream& os) const {
+  size_t size = 1u << mask_bits_;
+  for (uint32_t i = 0; i < size; i++) {
+    const Entry& entry = entries_[i];
+    if (entry.IsEmpty()) {
+      os << i << ": empty";
+    } else {
+      const char* first_checked_str = GetStringData(entry);
+      os << i << ": " << std::string(first_checked_str);
+    }
+  }
+}
+
 uint32_t TypeLookupTable::RawDataLength(uint32_t num_class_defs) {
   return SupportedSize(num_class_defs) ? RoundUpToPowerOfTwo(num_class_defs) * sizeof(Entry) : 0u;
 }
diff --git a/libdexfile/dex/type_lookup_table.h b/libdexfile/dex/type_lookup_table.h
index 5f002d1..a668e62 100644
--- a/libdexfile/dex/type_lookup_table.h
+++ b/libdexfile/dex/type_lookup_table.h
@@ -87,6 +87,8 @@
   // Method returns length of binary data for the specified number of class definitions.
   static uint32_t RawDataLength(uint32_t num_class_defs);
 
+  void Dump(std::ostream& os) const;
+
  private:
   /**
    * To find element we need to compare strings.
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index 7e21f64..f8d8128 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -865,7 +865,6 @@
     os << StringPrintf("location: %s\n", oat_dex_file.GetDexFileLocation().c_str());
     os << StringPrintf("checksum: 0x%08x\n", oat_dex_file.GetDexFileLocationChecksum());
 
-    const uint8_t* const oat_file_begin = oat_dex_file.GetOatFile()->Begin();
     if (oat_dex_file.GetOatFile()->ContainsDexCode()) {
       const uint8_t* const vdex_file_begin = oat_dex_file.GetOatFile()->DexBegin();
 
@@ -892,11 +891,13 @@
     // Print lookup table, if it exists.
     if (oat_dex_file.GetLookupTableData() != nullptr) {
       uint32_t table_offset = dchecked_integral_cast<uint32_t>(
-          oat_dex_file.GetLookupTableData() - oat_file_begin);
+          oat_dex_file.GetLookupTableData() - oat_dex_file.GetOatFile()->DexBegin());
       uint32_t table_size = TypeLookupTable::RawDataLength(dex_file->NumClassDefs());
       os << StringPrintf("type-table: 0x%08x..0x%08x\n",
                          table_offset,
                          table_offset + table_size - 1);
+      const TypeLookupTable& lookup = oat_dex_file.GetTypeLookupTable();
+      lookup.Dump(os);
     }
 
     VariableIndentationOutputStream vios(&os);