1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "leb128.h"
#include "utils.h"
#include "dwarf_cfi.h"
namespace art {
void DW_CFA_advance_loc(std::vector<uint8_t>* buf, uint32_t increment) {
if (increment < 64) {
// Encoding in opcode.
buf->push_back(0x1 << 6 | increment);
} else if (increment < 256) {
// Single byte delta.
buf->push_back(0x02);
buf->push_back(increment);
} else if (increment < 256 * 256) {
// Two byte delta.
buf->push_back(0x03);
buf->push_back(increment & 0xff);
buf->push_back((increment >> 8) & 0xff);
} else {
// Four byte delta.
buf->push_back(0x04);
PushWord(buf, increment);
}
}
void DW_CFA_offset_extended_sf(std::vector<uint8_t>* buf, int reg, int32_t offset) {
buf->push_back(0x11);
EncodeUnsignedLeb128(reg, buf);
EncodeSignedLeb128(offset, buf);
}
void DW_CFA_offset(std::vector<uint8_t>* buf, int reg, uint32_t offset) {
buf->push_back((0x2 << 6) | reg);
EncodeUnsignedLeb128(offset, buf);
}
void DW_CFA_def_cfa_offset(std::vector<uint8_t>* buf, int32_t offset) {
buf->push_back(0x0e);
EncodeUnsignedLeb128(offset, buf);
}
void DW_CFA_remember_state(std::vector<uint8_t>* buf) {
buf->push_back(0x0a);
}
void DW_CFA_restore_state(std::vector<uint8_t>* buf) {
buf->push_back(0x0b);
}
void WriteFDEHeader(std::vector<uint8_t>* buf) {
// 'length' (filled in by other functions).
PushWord(buf, 0);
// 'CIE_pointer' (filled in by linker).
PushWord(buf, 0);
// 'initial_location' (filled in by linker).
PushWord(buf, 0);
// 'address_range' (filled in by other functions).
PushWord(buf, 0);
// Augmentation length: 0
buf->push_back(0);
}
void WriteFDEAddressRange(std::vector<uint8_t>* buf, uint32_t data) {
const int kOffsetOfAddressRange = 12;
CHECK(buf->size() >= kOffsetOfAddressRange + sizeof(uint32_t));
uint8_t *p = buf->data() + kOffsetOfAddressRange;
p[0] = data;
p[1] = data >> 8;
p[2] = data >> 16;
p[3] = data >> 24;
}
void WriteCFILength(std::vector<uint8_t>* buf) {
uint32_t length = buf->size() - 4;
DCHECK_EQ((length & 0x3), 0U);
DCHECK_GT(length, 4U);
uint8_t *p = buf->data();
p[0] = length;
p[1] = length >> 8;
p[2] = length >> 16;
p[3] = length >> 24;
}
void PadCFI(std::vector<uint8_t>* buf) {
while (buf->size() & 0x3) {
buf->push_back(0);
}
}
} // namespace art
|