blob: d9fc371c3635c034f602f0bd87fb9ec0cb5dc3ef [file] [log] [blame]
Christopher Ferris723cf9b2017-01-19 20:08:48 -08001/*
2 * Copyright (C) 2016 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 _LIBUNWINDSTACK_ARM_EXIDX_H
18#define _LIBUNWINDSTACK_ARM_EXIDX_H
19
20#include <stdint.h>
21
22#include <deque>
Christopher Ferris4cc36d22018-06-06 14:47:31 -070023#include <map>
Christopher Ferris723cf9b2017-01-19 20:08:48 -080024
Christopher Ferrisd226a512017-07-14 10:37:19 -070025namespace unwindstack {
26
Christopher Ferris3958f802017-02-01 15:44:40 -080027// Forward declarations.
28class Memory;
29class RegsArm;
Christopher Ferris723cf9b2017-01-19 20:08:48 -080030
31enum ArmStatus : size_t {
32 ARM_STATUS_NONE = 0,
33 ARM_STATUS_NO_UNWIND,
34 ARM_STATUS_FINISH,
35 ARM_STATUS_RESERVED,
36 ARM_STATUS_SPARE,
37 ARM_STATUS_TRUNCATED,
38 ARM_STATUS_READ_FAILED,
39 ARM_STATUS_MALFORMED,
40 ARM_STATUS_INVALID_ALIGNMENT,
41 ARM_STATUS_INVALID_PERSONALITY,
42};
43
44enum ArmOp : uint8_t {
45 ARM_OP_FINISH = 0xb0,
46};
47
Christopher Ferris4cc36d22018-06-06 14:47:31 -070048enum ArmLogType : uint8_t {
49 ARM_LOG_NONE,
50 ARM_LOG_FULL,
51 ARM_LOG_BY_REG,
52};
53
Christopher Ferris723cf9b2017-01-19 20:08:48 -080054class ArmExidx {
55 public:
Christopher Ferris3958f802017-02-01 15:44:40 -080056 ArmExidx(RegsArm* regs, Memory* elf_memory, Memory* process_memory)
Christopher Ferris723cf9b2017-01-19 20:08:48 -080057 : regs_(regs), elf_memory_(elf_memory), process_memory_(process_memory) {}
58 virtual ~ArmExidx() {}
59
60 void LogRawData();
61
Christopher Ferris4cc36d22018-06-06 14:47:31 -070062 void LogByReg();
63
Christopher Ferris723cf9b2017-01-19 20:08:48 -080064 bool ExtractEntryData(uint32_t entry_offset);
65
66 bool Eval();
67
68 bool Decode();
69
70 std::deque<uint8_t>* data() { return &data_; }
71
72 ArmStatus status() { return status_; }
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -080073 uint64_t status_address() { return status_address_; }
Christopher Ferris723cf9b2017-01-19 20:08:48 -080074
Christopher Ferris3958f802017-02-01 15:44:40 -080075 RegsArm* regs() { return regs_; }
Christopher Ferris723cf9b2017-01-19 20:08:48 -080076
77 uint32_t cfa() { return cfa_; }
78 void set_cfa(uint32_t cfa) { cfa_ = cfa; }
79
Christopher Ferris3958f802017-02-01 15:44:40 -080080 bool pc_set() { return pc_set_; }
81 void set_pc_set(bool pc_set) { pc_set_ = pc_set; }
82
Christopher Ferris4cc36d22018-06-06 14:47:31 -070083 void set_log(ArmLogType log_type) { log_type_ = log_type; }
Christopher Ferris723cf9b2017-01-19 20:08:48 -080084 void set_log_skip_execution(bool skip_execution) { log_skip_execution_ = skip_execution; }
85 void set_log_indent(uint8_t indent) { log_indent_ = indent; }
86
87 private:
88 bool GetByte(uint8_t* byte);
Christopher Ferris4cc36d22018-06-06 14:47:31 -070089 void AdjustRegisters(int32_t offset);
Christopher Ferris723cf9b2017-01-19 20:08:48 -080090
91 bool DecodePrefix_10_00(uint8_t byte);
92 bool DecodePrefix_10_01(uint8_t byte);
93 bool DecodePrefix_10_10(uint8_t byte);
94 bool DecodePrefix_10_11_0000();
95 bool DecodePrefix_10_11_0001();
96 bool DecodePrefix_10_11_0010();
97 bool DecodePrefix_10_11_0011();
98 bool DecodePrefix_10_11_01nn();
99 bool DecodePrefix_10_11_1nnn(uint8_t byte);
100 bool DecodePrefix_10(uint8_t byte);
101
102 bool DecodePrefix_11_000(uint8_t byte);
103 bool DecodePrefix_11_001(uint8_t byte);
104 bool DecodePrefix_11_010(uint8_t byte);
105 bool DecodePrefix_11(uint8_t byte);
106
Christopher Ferris3958f802017-02-01 15:44:40 -0800107 RegsArm* regs_ = nullptr;
Christopher Ferris723cf9b2017-01-19 20:08:48 -0800108 uint32_t cfa_ = 0;
109 std::deque<uint8_t> data_;
110 ArmStatus status_ = ARM_STATUS_NONE;
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -0800111 uint64_t status_address_ = 0;
Christopher Ferris723cf9b2017-01-19 20:08:48 -0800112
113 Memory* elf_memory_;
114 Memory* process_memory_;
115
Christopher Ferris4cc36d22018-06-06 14:47:31 -0700116 ArmLogType log_type_ = ARM_LOG_NONE;
Christopher Ferris723cf9b2017-01-19 20:08:48 -0800117 uint8_t log_indent_ = 0;
118 bool log_skip_execution_ = false;
Christopher Ferris3958f802017-02-01 15:44:40 -0800119 bool pc_set_ = false;
Christopher Ferris4cc36d22018-06-06 14:47:31 -0700120 int32_t log_cfa_offset_ = 0;
121 std::map<uint8_t, int32_t> log_regs_;
Christopher Ferris723cf9b2017-01-19 20:08:48 -0800122};
123
Christopher Ferrisd226a512017-07-14 10:37:19 -0700124} // namespace unwindstack
125
Christopher Ferris723cf9b2017-01-19 20:08:48 -0800126#endif // _LIBUNWINDSTACK_ARM_EXIDX_H