blob: c97bf64c5da830b50d419193d7023990d80164c9 [file] [log] [blame]
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001/*
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 <iostream>
20
Elliott Hughes07ed66b2012-12-12 18:34:25 -080021#include "base/logging.h"
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070022#include "base/stringprintf.h"
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080023#include "disassembler_arm.h"
Serban Constantinescue6622be2014-02-27 15:36:47 +000024#include "disassembler_arm64.h"
Elliott Hughes60454e82012-04-25 12:56:03 -070025#include "disassembler_mips.h"
Ian Rogers706a10e2012-03-23 17:00:55 -070026#include "disassembler_x86.h"
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080027
28namespace art {
29
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070030Disassembler* Disassembler::Create(InstructionSet instruction_set, DisassemblerOptions* options) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080031 if (instruction_set == kArm || instruction_set == kThumb2) {
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070032 return new arm::DisassemblerArm(options);
Serban Constantinescue6622be2014-02-27 15:36:47 +000033 } else if (instruction_set == kArm64) {
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070034 return new arm64::DisassemblerArm64(options);
Elliott Hughes60454e82012-04-25 12:56:03 -070035 } else if (instruction_set == kMips) {
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070036 return new mips::DisassemblerMips(options);
Ian Rogers706a10e2012-03-23 17:00:55 -070037 } else if (instruction_set == kX86) {
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070038 return new x86::DisassemblerX86(options, false);
Ian Rogers38e12032014-03-14 14:06:14 -070039 } else if (instruction_set == kX86_64) {
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070040 return new x86::DisassemblerX86(options, true);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080041 } else {
Elliott Hughesed64e8d2012-03-02 20:37:45 -080042 UNIMPLEMENTED(FATAL) << "no disassembler for " << instruction_set;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080043 return NULL;
44 }
45}
46
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070047std::string Disassembler::FormatInstructionPointer(const uint8_t* begin) {
48 if (disassembler_options_->absolute_addresses_) {
49 return StringPrintf("%p", begin);
50 } else {
51 size_t offset = begin - disassembler_options_->base_address_;
52 return StringPrintf("0x%08zx", offset);
53 }
54}
55
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080056} // namespace art