Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 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 | |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 19 | #include <ostream> |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 20 | |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 21 | #include "android-base/logging.h" |
| 22 | #include "android-base/stringprintf.h" |
| 23 | |
Roland Levillain | 5af106e | 2018-10-31 19:55:02 +0000 | [diff] [blame] | 24 | #ifdef ART_ENABLE_CODEGEN_arm |
| 25 | # include "disassembler_arm.h" |
| 26 | #endif |
| 27 | |
| 28 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 29 | # include "disassembler_arm64.h" |
| 30 | #endif |
| 31 | |
Roland Levillain | 5af106e | 2018-10-31 19:55:02 +0000 | [diff] [blame] | 32 | #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64) |
| 33 | # include "disassembler_x86.h" |
| 34 | #endif |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 35 | |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 36 | using android::base::StringPrintf; |
| 37 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 38 | namespace art { |
| 39 | |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 40 | Disassembler::Disassembler(DisassemblerOptions* disassembler_options) |
| 41 | : disassembler_options_(disassembler_options) { |
| 42 | CHECK(disassembler_options_ != nullptr); |
| 43 | } |
| 44 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 45 | Disassembler* Disassembler::Create(InstructionSet instruction_set, DisassemblerOptions* options) { |
Roland Levillain | 5af106e | 2018-10-31 19:55:02 +0000 | [diff] [blame] | 46 | switch (instruction_set) { |
| 47 | #ifdef ART_ENABLE_CODEGEN_arm |
| 48 | case InstructionSet::kArm: |
| 49 | case InstructionSet::kThumb2: |
| 50 | return new arm::DisassemblerArm(options); |
| 51 | #endif |
| 52 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 53 | case InstructionSet::kArm64: |
| 54 | return new arm64::DisassemblerArm64(options); |
| 55 | #endif |
Roland Levillain | 5af106e | 2018-10-31 19:55:02 +0000 | [diff] [blame] | 56 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 57 | case InstructionSet::kX86: |
| 58 | return new x86::DisassemblerX86(options, /* supports_rex= */ false); |
| 59 | #endif |
| 60 | #ifdef ART_ENABLE_CODEGEN_x86_64 |
| 61 | case InstructionSet::kX86_64: |
| 62 | return new x86::DisassemblerX86(options, /* supports_rex= */ true); |
| 63 | #endif |
| 64 | default: |
| 65 | UNIMPLEMENTED(FATAL) << static_cast<uint32_t>(instruction_set); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 66 | UNREACHABLE(); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 70 | std::string Disassembler::FormatInstructionPointer(const uint8_t* begin) { |
| 71 | if (disassembler_options_->absolute_addresses_) { |
| 72 | return StringPrintf("%p", begin); |
| 73 | } else { |
| 74 | size_t offset = begin - disassembler_options_->base_address_; |
| 75 | return StringPrintf("0x%08zx", offset); |
| 76 | } |
| 77 | } |
| 78 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 79 | Disassembler* create_disassembler(InstructionSet instruction_set, DisassemblerOptions* options) { |
| 80 | return Disassembler::Create(instruction_set, options); |
| 81 | } |
| 82 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 83 | } // namespace art |