• 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 #ifndef ART_DISASSEMBLER_DISASSEMBLER_H_
18 #define ART_DISASSEMBLER_DISASSEMBLER_H_
19 
20 #include <stdint.h>
21 
22 #include <iosfwd>
23 
24 #include "base/macros.h"
25 #include "instruction_set.h"
26 
27 namespace art {
28 
29 class DisassemblerOptions {
30  public:
31   // Should the disassembler print absolute or relative addresses.
32   const bool absolute_addresses_;
33 
34   // Base addess for calculating relative code offsets when absolute_addresses_ is false.
35   const uint8_t* const base_address_;
36 
DisassemblerOptions(bool absolute_addresses,const uint8_t * base_address)37   DisassemblerOptions(bool absolute_addresses, const uint8_t* base_address)
38       : absolute_addresses_(absolute_addresses), base_address_(base_address) {}
39 
40  private:
41   DISALLOW_COPY_AND_ASSIGN(DisassemblerOptions);
42 };
43 
44 class Disassembler {
45  public:
46   // Creates a Disassembler for the given InstructionSet with the
47   // non-null DisassemblerOptions which become owned by the
48   // Disassembler.
49   static Disassembler* Create(InstructionSet instruction_set, DisassemblerOptions* options);
50 
~Disassembler()51   virtual ~Disassembler() {
52     delete disassembler_options_;
53   }
54 
55   // Dump a single instruction returning the length of that instruction.
56   virtual size_t Dump(std::ostream& os, const uint8_t* begin) = 0;
57   // Dump instructions within a range.
58   virtual void Dump(std::ostream& os, const uint8_t* begin, const uint8_t* end) = 0;
59 
60  protected:
Disassembler(DisassemblerOptions * disassembler_options)61   explicit Disassembler(DisassemblerOptions* disassembler_options)
62       : disassembler_options_(disassembler_options) {
63     CHECK(disassembler_options_ != nullptr);
64   }
65 
66   std::string FormatInstructionPointer(const uint8_t* begin);
67 
68  private:
69   DisassemblerOptions* disassembler_options_;
70   DISALLOW_COPY_AND_ASSIGN(Disassembler);
71 };
72 
HasBitSet(uint32_t value,uint32_t bit)73 static inline bool HasBitSet(uint32_t value, uint32_t bit) {
74   return (value & (1 << bit)) != 0;
75 }
76 
77 }  // namespace art
78 
79 #endif  // ART_DISASSEMBLER_DISASSEMBLER_H_
80