| 1 |
efrain |
1 |
// Copyright 2019 Google
|
|
|
2 |
//
|
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
|
5 |
// You may obtain a copy of the License at
|
|
|
6 |
//
|
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
8 |
//
|
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
12 |
// See the License for the specific language governing permissions and
|
|
|
13 |
// limitations under the License.
|
|
|
14 |
|
|
|
15 |
#pragma once
|
|
|
16 |
|
|
|
17 |
#include <stdbool.h>
|
|
|
18 |
#include <stdint.h>
|
|
|
19 |
#include <sys/types.h>
|
|
|
20 |
|
|
|
21 |
#include "Crashlytics/Crashlytics/Helpers/FIRCLSThreadState.h"
|
|
|
22 |
#include "Crashlytics/Crashlytics/Unwind/Dwarf/FIRCLSDwarfUnwindRegisters.h"
|
|
|
23 |
|
|
|
24 |
#if CLS_DWARF_UNWINDING_SUPPORTED
|
|
|
25 |
|
|
|
26 |
#pragma mark Structures
|
|
|
27 |
typedef struct {
|
|
|
28 |
uint32_t length;
|
|
|
29 |
const void* data;
|
|
|
30 |
} DWARFInstructions;
|
|
|
31 |
|
|
|
32 |
typedef struct {
|
|
|
33 |
uint64_t length;
|
|
|
34 |
uint8_t version;
|
|
|
35 |
uintptr_t ehData; // 8 bytes for 64-bit architectures, 4 bytes for 32
|
|
|
36 |
const char* augmentation;
|
|
|
37 |
uint8_t pointerEncoding;
|
|
|
38 |
uint8_t lsdaEncoding;
|
|
|
39 |
uint8_t personalityEncoding;
|
|
|
40 |
uintptr_t personalityFunction;
|
|
|
41 |
uint64_t codeAlignFactor;
|
|
|
42 |
int64_t dataAlignFactor;
|
|
|
43 |
uint64_t returnAddressRegister; // is 64 bits enough for this value?
|
|
|
44 |
bool signalFrame;
|
|
|
45 |
|
|
|
46 |
DWARFInstructions instructions;
|
|
|
47 |
} DWARFCIERecord;
|
|
|
48 |
|
|
|
49 |
typedef struct {
|
|
|
50 |
uint64_t length;
|
|
|
51 |
uint64_t cieOffset; // also an arch-specific size
|
|
|
52 |
uintptr_t startAddress;
|
|
|
53 |
uintptr_t rangeSize;
|
|
|
54 |
|
|
|
55 |
DWARFInstructions instructions;
|
|
|
56 |
} DWARFFDERecord;
|
|
|
57 |
|
|
|
58 |
typedef struct {
|
|
|
59 |
DWARFCIERecord cie;
|
|
|
60 |
DWARFFDERecord fde;
|
|
|
61 |
} FIRCLSDwarfCFIRecord;
|
|
|
62 |
|
|
|
63 |
typedef enum {
|
|
|
64 |
FIRCLSDwarfRegisterUnused = 0,
|
|
|
65 |
FIRCLSDwarfRegisterInCFA,
|
|
|
66 |
FIRCLSDwarfRegisterOffsetFromCFA,
|
|
|
67 |
FIRCLSDwarfRegisterInRegister,
|
|
|
68 |
FIRCLSDwarfRegisterAtExpression,
|
|
|
69 |
FIRCLSDwarfRegisterIsExpression
|
|
|
70 |
} FIRCLSDwarfRegisterLocation;
|
|
|
71 |
|
|
|
72 |
typedef struct {
|
|
|
73 |
FIRCLSDwarfRegisterLocation location;
|
|
|
74 |
uint64_t value;
|
|
|
75 |
} FIRCLSDwarfRegister;
|
|
|
76 |
|
|
|
77 |
typedef struct {
|
|
|
78 |
uint64_t cfaRegister;
|
|
|
79 |
int64_t cfaRegisterOffset;
|
|
|
80 |
const void* cfaExpression;
|
|
|
81 |
uint32_t spArgSize;
|
|
|
82 |
|
|
|
83 |
FIRCLSDwarfRegister registers[CLS_DWARF_MAX_REGISTER_NUM + 1];
|
|
|
84 |
} FIRCLSDwarfState;
|
|
|
85 |
|
|
|
86 |
__BEGIN_DECLS
|
|
|
87 |
|
|
|
88 |
#pragma mark - Parsing
|
|
|
89 |
bool FIRCLSDwarfParseCIERecord(DWARFCIERecord* cie, const void* ptr);
|
|
|
90 |
bool FIRCLSDwarfParseFDERecord(DWARFFDERecord* fdeRecord,
|
|
|
91 |
bool parseCIE,
|
|
|
92 |
DWARFCIERecord* cieRecord,
|
|
|
93 |
const void* ptr);
|
|
|
94 |
bool FIRCLSDwarfParseCFIFromFDERecord(FIRCLSDwarfCFIRecord* record, const void* ptr);
|
|
|
95 |
bool FIRCLSDwarfParseCFIFromFDERecordOffset(FIRCLSDwarfCFIRecord* record,
|
|
|
96 |
const void* ehFrame,
|
|
|
97 |
uintptr_t fdeOffset);
|
|
|
98 |
|
|
|
99 |
#pragma mark - Properties
|
|
|
100 |
bool FIRCLSDwarfCIEIsValid(DWARFCIERecord* cie);
|
|
|
101 |
bool FIRCLSDwarfCIEHasAugmentationData(DWARFCIERecord* cie);
|
|
|
102 |
|
|
|
103 |
#pragma mark - Execution
|
|
|
104 |
bool FIRCLSDwarfInstructionsEnumerate(DWARFInstructions* instructions,
|
|
|
105 |
DWARFCIERecord* cieRecord,
|
|
|
106 |
FIRCLSDwarfState* state,
|
|
|
107 |
intptr_t pcOffset);
|
|
|
108 |
bool FIRCLSDwarfUnwindComputeRegisters(FIRCLSDwarfCFIRecord* record,
|
|
|
109 |
FIRCLSThreadContext* registers);
|
|
|
110 |
bool FIRCLSDwarfUnwindAssignRegisters(const FIRCLSDwarfState* state,
|
|
|
111 |
const FIRCLSThreadContext* registers,
|
|
|
112 |
uintptr_t cfaRegister,
|
|
|
113 |
FIRCLSThreadContext* outputRegisters);
|
|
|
114 |
|
|
|
115 |
#pragma mark - Register Operations
|
|
|
116 |
bool FIRCLSDwarfCompareRegisters(const FIRCLSThreadContext* a,
|
|
|
117 |
const FIRCLSThreadContext* b,
|
|
|
118 |
uint64_t registerNum);
|
|
|
119 |
|
|
|
120 |
bool FIRCLSDwarfGetCFA(FIRCLSDwarfState* state,
|
|
|
121 |
const FIRCLSThreadContext* registers,
|
|
|
122 |
uintptr_t* cfa);
|
|
|
123 |
uintptr_t FIRCLSDwarfGetSavedRegister(const FIRCLSThreadContext* registers,
|
|
|
124 |
uintptr_t cfaRegister,
|
|
|
125 |
FIRCLSDwarfRegister dRegister);
|
|
|
126 |
|
|
|
127 |
#if DEBUG
|
|
|
128 |
#pragma mark - Debugging
|
|
|
129 |
void FIRCLSCFIRecordShow(FIRCLSDwarfCFIRecord* record);
|
|
|
130 |
void FIRCLSCIERecordShow(DWARFCIERecord* record);
|
|
|
131 |
void FIRCLSFDERecordShow(DWARFFDERecord* record, DWARFCIERecord* cie);
|
|
|
132 |
void FIRCLSDwarfPointerEncodingShow(const char* leadString, uint8_t encoding);
|
|
|
133 |
void FIRCLSDwarfInstructionsShow(DWARFInstructions* instructions, DWARFCIERecord* cie);
|
|
|
134 |
#endif
|
|
|
135 |
|
|
|
136 |
__END_DECLS
|
|
|
137 |
|
|
|
138 |
#endif
|