diff options
author | 2017-03-14 02:33:20 +0000 | |
---|---|---|
committer | 2017-03-14 02:33:20 +0000 | |
commit | 224f6ab7620ddbc20a338e56ccf9952d86b08b51 (patch) | |
tree | f07435d668c04c239dca0036b6b072611d45b046 /dexlayout/dexlayout.cc | |
parent | 13ef0447b43ecbf18d3c4e4c72d66bbbc1815f0c (diff) | |
parent | ec7f1a96683836d9375adc48c6bf802c0ce2160e (diff) |
Merge "Added new -v option to dexlayout to verify output dex file."
Diffstat (limited to 'dexlayout/dexlayout.cc')
-rw-r--r-- | dexlayout/dexlayout.cc | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/dexlayout/dexlayout.cc b/dexlayout/dexlayout.cc index f74fb4e80e..a3104240a0 100644 --- a/dexlayout/dexlayout.cc +++ b/dexlayout/dexlayout.cc @@ -36,6 +36,7 @@ #include "dex_file-inl.h" #include "dex_file_verifier.h" #include "dex_instruction-inl.h" +#include "dex_verify.h" #include "dex_visualize.h" #include "dex_writer.h" #include "jit/profile_compilation_info.h" @@ -1692,7 +1693,8 @@ void DexLayout::LayoutOutputFile(const DexFile* dex_file) { header_->SetFileSize(header_->FileSize() + diff); } -void DexLayout::OutputDexFile(const std::string& dex_file_location) { +void DexLayout::OutputDexFile(const DexFile* dex_file) { + const std::string& dex_file_location = dex_file->GetLocation(); std::string error_msg; std::unique_ptr<File> new_file; if (!options_.output_to_memmap_) { @@ -1725,18 +1727,24 @@ void DexLayout::OutputDexFile(const std::string& dex_file_location) { if (new_file != nullptr) { UNUSED(new_file->FlushCloseOrErase()); } - // Verify the output dex file is ok on debug builds. + // Verify the output dex file's structure for debug builds. if (kIsDebugBuild) { std::string location = "memory mapped file for " + dex_file_location; - std::unique_ptr<const DexFile> dex_file(DexFile::Open(mem_map_->Begin(), - mem_map_->Size(), - location, - header_->Checksum(), - /*oat_dex_file*/ nullptr, - /*verify*/ true, - /*verify_checksum*/ false, - &error_msg)); - DCHECK(dex_file != nullptr) << "Failed to re-open output file:" << error_msg; + std::unique_ptr<const DexFile> output_dex_file(DexFile::Open(mem_map_->Begin(), + mem_map_->Size(), + location, + header_->Checksum(), + /*oat_dex_file*/ nullptr, + /*verify*/ true, + /*verify_checksum*/ false, + &error_msg)); + DCHECK(output_dex_file != nullptr) << "Failed to re-open output file:" << error_msg; + } + // Do IR-level comparison between input and output. This check ignores potential differences + // due to layout, so offsets are not checked. Instead, it checks the data contents of each item. + if (options_.verify_output_) { + std::unique_ptr<dex_ir::Header> orig_header(dex_ir::DexIrBuilder(*dex_file)); + CHECK(VerifyOutputDexFile(orig_header.get(), header_, &error_msg)) << error_msg; } } @@ -1774,7 +1782,7 @@ void DexLayout::ProcessDexFile(const char* file_name, if (info_ != nullptr) { LayoutOutputFile(dex_file); } - OutputDexFile(dex_file->GetLocation()); + OutputDexFile(dex_file); } } |