• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #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 
32 #if defined(ART_ENABLE_CODEGEN_mips) || defined(ART_ENABLE_CODEGEN_mips64)
33 # include "disassembler_mips.h"
34 #endif
35 
36 #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64)
37 # include "disassembler_x86.h"
38 #endif
39 
40 using android::base::StringPrintf;
41 
42 namespace art {
43 
Disassembler(DisassemblerOptions * disassembler_options)44 Disassembler::Disassembler(DisassemblerOptions* disassembler_options)
45     : disassembler_options_(disassembler_options) {
46   CHECK(disassembler_options_ != nullptr);
47 }
48 
Create(InstructionSet instruction_set,DisassemblerOptions * options)49 Disassembler* Disassembler::Create(InstructionSet instruction_set, DisassemblerOptions* options) {
50   switch (instruction_set) {
51 #ifdef ART_ENABLE_CODEGEN_arm
52     case InstructionSet::kArm:
53     case InstructionSet::kThumb2:
54       return new arm::DisassemblerArm(options);
55 #endif
56 #ifdef ART_ENABLE_CODEGEN_arm64
57     case InstructionSet::kArm64:
58       return new arm64::DisassemblerArm64(options);
59 #endif
60 #ifdef ART_ENABLE_CODEGEN_mips
61     case InstructionSet::kMips:
62       return new mips::DisassemblerMips(options, /* is_o32_abi= */ true);
63 #endif
64 #ifdef ART_ENABLE_CODEGEN_mips64
65     case InstructionSet::kMips64:
66       return new mips::DisassemblerMips(options, /* is_o32_abi= */ false);
67 #endif
68 #ifdef ART_ENABLE_CODEGEN_x86
69     case InstructionSet::kX86:
70       return new x86::DisassemblerX86(options, /* supports_rex= */ false);
71 #endif
72 #ifdef ART_ENABLE_CODEGEN_x86_64
73     case InstructionSet::kX86_64:
74       return new x86::DisassemblerX86(options, /* supports_rex= */ true);
75 #endif
76     default:
77       UNIMPLEMENTED(FATAL) << static_cast<uint32_t>(instruction_set);
78       UNREACHABLE();
79   }
80 }
81 
FormatInstructionPointer(const uint8_t * begin)82 std::string Disassembler::FormatInstructionPointer(const uint8_t* begin) {
83   if (disassembler_options_->absolute_addresses_) {
84     return StringPrintf("%p", begin);
85   } else {
86     size_t offset = begin - disassembler_options_->base_address_;
87     return StringPrintf("0x%08zx", offset);
88   }
89 }
90 
create_disassembler(InstructionSet instruction_set,DisassemblerOptions * options)91 Disassembler* create_disassembler(InstructionSet instruction_set, DisassemblerOptions* options) {
92   return Disassembler::Create(instruction_set, options);
93 }
94 
95 }  // namespace art
96