Home | History | Annotate | Download | only in disassembler
      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 <iostream>
     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 
     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);
     37   } else if (instruction_set == kX86) {
     38     return new x86::DisassemblerX86(options, false);
     39   } else if (instruction_set == kX86_64) {
     40     return new x86::DisassemblerX86(options, true);
     41   } else {
     42     UNIMPLEMENTED(FATAL) << "no disassembler for " << instruction_set;
     43     return NULL;
     44   }
     45 }
     46 
     47 std::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 
     56 }  // namespace art
     57