blob: 062892e65ffb9dd20618ddf33bd8cb5a6c9b255b [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
Ian Rogerscf7f1912014-10-22 22:06:39 -070019#include <ostream>
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080020
Andreas Gampebda1d602016-08-29 17:43:45 -070021#include "android-base/logging.h"
22#include "android-base/stringprintf.h"
23
Roland Levillain5af106e2018-10-31 19:55:02 +000024#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
Vladimir Marko06f1fc02023-07-26 09:38:39 +000032#ifdef ART_ENABLE_CODEGEN_riscv64
33# include "disassembler_riscv64.h"
34#endif
35
Roland Levillain5af106e2018-10-31 19:55:02 +000036#if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64)
37# include "disassembler_x86.h"
38#endif
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080039
Andreas Gampebda1d602016-08-29 17:43:45 -070040using android::base::StringPrintf;
41
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080042namespace art {
43
Andreas Gampebda1d602016-08-29 17:43:45 -070044Disassembler::Disassembler(DisassemblerOptions* disassembler_options)
45 : disassembler_options_(disassembler_options) {
46 CHECK(disassembler_options_ != nullptr);
47}
48
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070049Disassembler* Disassembler::Create(InstructionSet instruction_set, DisassemblerOptions* options) {
Roland Levillain5af106e2018-10-31 19:55:02 +000050 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
Vladimir Marko06f1fc02023-07-26 09:38:39 +000060#ifdef ART_ENABLE_CODEGEN_riscv64
61 case InstructionSet::kRiscv64:
62 return new riscv64::DisassemblerRiscv64(options);
63#endif
Roland Levillain5af106e2018-10-31 19:55:02 +000064#ifdef ART_ENABLE_CODEGEN_x86
65 case InstructionSet::kX86:
66 return new x86::DisassemblerX86(options, /* supports_rex= */ false);
67#endif
68#ifdef ART_ENABLE_CODEGEN_x86_64
69 case InstructionSet::kX86_64:
70 return new x86::DisassemblerX86(options, /* supports_rex= */ true);
71#endif
72 default:
Ulya Trafimovich7aeee972023-01-25 18:02:28 +000073 UNUSED(options);
Roland Levillain5af106e2018-10-31 19:55:02 +000074 UNIMPLEMENTED(FATAL) << static_cast<uint32_t>(instruction_set);
Elliott Hughesc1896c92018-11-29 11:33:18 -080075 UNREACHABLE();
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080076 }
77}
78
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070079std::string Disassembler::FormatInstructionPointer(const uint8_t* begin) {
80 if (disassembler_options_->absolute_addresses_) {
81 return StringPrintf("%p", begin);
82 } else {
83 size_t offset = begin - disassembler_options_->base_address_;
84 return StringPrintf("0x%08zx", offset);
85 }
86}
87
Alexandre Rameseb7b7392015-06-19 14:47:01 +010088Disassembler* create_disassembler(InstructionSet instruction_set, DisassemblerOptions* options) {
89 return Disassembler::Create(instruction_set, options);
90}
91
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080092} // namespace art