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 "base/logging.h"
22 #include "base/stringprintf.h"
23 #include "disassembler_arm.h"
24 #include "disassembler_arm64.h"
25 #include "disassembler_mips.h"
26 #include "disassembler_x86.h"
27 
28 namespace art {
29 
Create(InstructionSet instruction_set,DisassemblerOptions * options)30 Disassembler* Disassembler::Create(InstructionSet instruction_set, DisassemblerOptions* options) {
31   if (instruction_set == kArm || instruction_set == kThumb2) {
32     return new arm::DisassemblerArm(options);
33   } else if (instruction_set == kArm64) {
34     return new arm64::DisassemblerArm64(options);
35   } else if (instruction_set == kMips) {
36     return new mips::DisassemblerMips(options, false);
37   } else if (instruction_set == kMips64) {
38     return new mips::DisassemblerMips(options, true);
39   } else if (instruction_set == kX86) {
40     return new x86::DisassemblerX86(options, false);
41   } else if (instruction_set == kX86_64) {
42     return new x86::DisassemblerX86(options, true);
43   } else {
44     UNIMPLEMENTED(FATAL) << "no disassembler for " << instruction_set;
45     return nullptr;
46   }
47 }
48 
FormatInstructionPointer(const uint8_t * begin)49 std::string Disassembler::FormatInstructionPointer(const uint8_t* begin) {
50   if (disassembler_options_->absolute_addresses_) {
51     return StringPrintf("%p", begin);
52   } else {
53     size_t offset = begin - disassembler_options_->base_address_;
54     return StringPrintf("0x%08zx", offset);
55   }
56 }
57 
58 }  // namespace art
59