1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "disassembler.h" 18 19 #include <ostream> 20 21 #include "android-base/logging.h" 22 #include "android-base/stringprintf.h" 23 24 #include "disassembler_arm.h" 25 #include "disassembler_arm64.h" 26 #include "disassembler_mips.h" 27 #include "disassembler_x86.h" 28 29 using android::base::StringPrintf; 30 31 namespace art { 32 33 Disassembler::Disassembler(DisassemblerOptions* disassembler_options) 34 : disassembler_options_(disassembler_options) { 35 CHECK(disassembler_options_ != nullptr); 36 } 37 38 Disassembler* Disassembler::Create(InstructionSet instruction_set, DisassemblerOptions* options) { 39 if (instruction_set == kArm || instruction_set == kThumb2) { 40 return new arm::DisassemblerArm(options); 41 } else if (instruction_set == kArm64) { 42 return new arm64::DisassemblerArm64(options); 43 } else if (instruction_set == kMips || instruction_set == kMips64) { 44 return new mips::DisassemblerMips(options); 45 } else if (instruction_set == kX86) { 46 return new x86::DisassemblerX86(options, false); 47 } else if (instruction_set == kX86_64) { 48 return new x86::DisassemblerX86(options, true); 49 } else { 50 UNIMPLEMENTED(FATAL) << static_cast<uint32_t>(instruction_set); 51 return nullptr; 52 } 53 } 54 55 std::string Disassembler::FormatInstructionPointer(const uint8_t* begin) { 56 if (disassembler_options_->absolute_addresses_) { 57 return StringPrintf("%p", begin); 58 } else { 59 size_t offset = begin - disassembler_options_->base_address_; 60 return StringPrintf("0x%08zx", offset); 61 } 62 } 63 64 Disassembler* create_disassembler(InstructionSet instruction_set, DisassemblerOptions* options) { 65 return Disassembler::Create(instruction_set, options); 66 } 67 68 } // namespace art 69