UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
syms_dwarf_expr.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2/* date = October 4th 2021 2:20 pm */
3
4#ifndef SYMS_DWARF_EXPR_H
5#define SYMS_DWARF_EXPR_H
6
8//~ NOTE(allen): Include Generated Types
9
11
13//~ NOTE(allen): Dwarf Register Layout
14
39
59
71
73//~ NOTE(allen): Dwarf Expression Eval Types
74
75//- machine configuration types
77
82
95
96
97//- detail analysis types
99enum{
109
113};
114
118
124
125
126//- location types
135
137 // NOTE(allen): Interpreting Fail Kinds
138 // BadData: the evaluator detected that the dwarf expression operation is incorrectly formed
139 // NotSupported: the evaluator does not support a dwarf feature that was found in the dwarf expression
140 // TimeOut: the evaluator hit the maximum step count
141 // TooComplicated: used by analyzer when it the expression uses features outside of the analyzer's scope
142 // Missing*: the dwarf machine config was missing necessary information to finish the evaluation
143
158
172
173typedef struct SYMS_DwPiece{
174 // NOTE(allen): Hint for Interpreting Pieces
175 // src = decode(loc, is_bit_loc, bit_size);
176 // dst |= (src >> bit_off) << bit_cursor;
177 // bit_cursor += bit_size;
178
185
186typedef struct SYMS_DwLocation{
187 // NOTE(allen): Interpreting a Dwarf Location
188 //
189 // CASE (any number of pieces, fail in the non-piece):
190 // this is how errors are reported, error information is in the non-piece
191 // the 'fail' location kind should never show up in a piece
192 // if there are any pieces they can be treated as correct information that
193 // was successfully decoded before the error was encountered
194 //
195 // CASE (no pieces, empty non-piece):
196 // the data is completely optimized out and unrecoverable
197 //
198 // CASE (no pieces, non-empty non-piece):
199 // the size of the data is not known by the location, but something in the
200 // surrounding context of the location (eg type info) should know the size
201 //
202 // CASE (one-or-more pieces, empty non-piece):
203 // the data is described by the pieces
204 //
205 // CASE (one-or-more pieces, non-empty non-fail non-piece):
206 // this is supposed to be impossible; the non-piece either carries an error
207 // or *all* of the location information about the data, there should never
208 // be a mix of piece-based location and non-piece-based location data.
209
213
216
217
218//- full evaluator state types
223
229
236
242
243
245//~ NOTE(allen): Dwarf Expression Analysis & Eval Functions
246
247//- analyzers
248
249// NOTE(allen): This analyzer provides the most simplified dwarf expression
250// decoding. If the expression consists of a single op that can be interpreted
251// as a valid dwarf expression, then it represents that expression as a simple
252// location.
253//
254// If there is a single 'piece' op that is represeted here as an empty simple
255// location, losing whatever additional size information from the piece.
256//
257// If there is an op that requires the machine configuration data the analyzer
258// fails with "too complicated" - unless the required configuration data is the
259// text section base which this analyzer treats as a non-optional parameter and
260// always decodes successfully.
261//
262// If the expression contains more than one op than the analyzer fails with
263// "too complicated".
264
266
267
268
269// NOTE(allen): This analyzer does a one-pass scan through the expression to
270// help a caller determine what to expect before doing a full evaluation which
271// has to maintain value stacks, perform more checks, and execute any loops
272// that may appear in the expression, etc.
273//
274// For each piece of data that can be equipped to a machine config there is a
275// 'Uses' flag in the analysis. A user can use these flags to determine what to
276// prepare and equip before a full eval. This can be a lot more efficient than
277// always preparing everything, or iteratively equipping and retrying after
278// each failure.
279//
280// The analysis can also catch some cases of bad data and unsupported features.
281// These flags are useful for short circuit style optimizations, but they are
282// not definitive, some bad data can only be caught by the full evaluator.
283// Sometimes the full evaluator might miss bad data that this analyzer will see
284// if control flow in the evaluator completely skips the bad data. A forgiving
285// interpretation of dwarf expression data would only rely on the results of
286// the full evaluator. A more strict interpretation would consider it an error
287// if either this analyzer or the evaluator finds bad data.
288//
289// The analyzer also determines if there is any possibility for non-linear
290// flow. Jumps, branches, and call ops all create non-linear flow. An
291// expression that doesn't have non-linear flow is trivially gauranteed to
292// terminate and therefore a good candidate for conversion to a human readable
293// expression.
294//
295// The call config is optional (may be null). If is provided the analysis
296// includes features seen in all of the expressions that might be reached by
297// call ops from the initial expression.
298
301
302
303
304
305//- full eval
308
309
310//- dw expr val stack
316
317//- dw expr call stack
320 void *ptr, SYMS_U64 size);
322
323
324//- analysis tasks
326
327#endif //SYMS_DWARF_EXPR_H
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition syms_dwarf_expr.h:119
struct SYMS_DwExprAnalysisTask * next
Definition syms_dwarf_expr.h:120
SYMS_String8 data
Definition syms_dwarf_expr.h:122
SYMS_U64 p
Definition syms_dwarf_expr.h:121
Definition syms_dwarf_expr.h:115
SYMS_DwExprFlags flags
Definition syms_dwarf_expr.h:116
Definition syms_dwarf_expr.h:237
SYMS_DwExprCall * stack
Definition syms_dwarf_expr.h:238
SYMS_DwExprCall * free_calls
Definition syms_dwarf_expr.h:239
SYMS_U64 depth
Definition syms_dwarf_expr.h:240
Definition syms_dwarf_expr.h:230
struct SYMS_DwExprCall * next
Definition syms_dwarf_expr.h:231
SYMS_U64 size
Definition syms_dwarf_expr.h:233
void * ptr
Definition syms_dwarf_expr.h:232
SYMS_U64 cursor
Definition syms_dwarf_expr.h:234
Definition syms_dwarf_expr.h:78
SYMS_DwExprResolveCallFunc * func
Definition syms_dwarf_expr.h:80
void * user_ptr
Definition syms_dwarf_expr.h:79
Definition syms_dwarf_expr.h:83
SYMS_U64 * frame_base
Definition syms_dwarf_expr.h:89
SYMS_U64 * tls_address
Definition syms_dwarf_expr.h:91
SYMS_MemoryView * memview
Definition syms_dwarf_expr.h:86
SYMS_DwRegsX64 * regs
Definition syms_dwarf_expr.h:87
SYMS_DwExprMachineCallConfig call
Definition syms_dwarf_expr.h:93
SYMS_U64 * object_address
Definition syms_dwarf_expr.h:90
SYMS_U64 max_step_count
Definition syms_dwarf_expr.h:85
SYMS_U64 * cfa
Definition syms_dwarf_expr.h:92
SYMS_U64 * text_section_base
Definition syms_dwarf_expr.h:88
Definition syms_dwarf_expr.h:219
struct SYMS_DwExprStackNode * next
Definition syms_dwarf_expr.h:220
SYMS_U64 val
Definition syms_dwarf_expr.h:221
Definition syms_dwarf_expr.h:224
SYMS_U64 count
Definition syms_dwarf_expr.h:227
SYMS_DwExprStackNode * free_nodes
Definition syms_dwarf_expr.h:226
SYMS_DwExprStackNode * stack
Definition syms_dwarf_expr.h:225
Definition syms_dwarf_expr.h:186
SYMS_DwPiece * last_piece
Definition syms_dwarf_expr.h:211
SYMS_DwSimpleLoc non_piece_loc
Definition syms_dwarf_expr.h:214
SYMS_U64 count
Definition syms_dwarf_expr.h:212
SYMS_DwPiece * first_piece
Definition syms_dwarf_expr.h:210
Definition syms_dwarf_expr.h:173
struct SYMS_DwPiece * next
Definition syms_dwarf_expr.h:179
SYMS_B32 is_bit_loc
Definition syms_dwarf_expr.h:183
SYMS_U64 bit_size
Definition syms_dwarf_expr.h:181
SYMS_DwSimpleLoc loc
Definition syms_dwarf_expr.h:180
SYMS_U64 bit_off
Definition syms_dwarf_expr.h:182
Definition syms_dwarf_expr.h:15
SYMS_U64 rbp
Definition syms_dwarf_expr.h:24
SYMS_U64 r8
Definition syms_dwarf_expr.h:26
SYMS_U64 rcx
Definition syms_dwarf_expr.h:20
SYMS_U64 rip
Definition syms_dwarf_expr.h:34
SYMS_U64 r15
Definition syms_dwarf_expr.h:33
SYMS_U64 rax
Definition syms_dwarf_expr.h:18
SYMS_U64 r9
Definition syms_dwarf_expr.h:27
SYMS_U64 r[17]
Definition syms_dwarf_expr.h:36
SYMS_U64 rdi
Definition syms_dwarf_expr.h:23
SYMS_U64 rbx
Definition syms_dwarf_expr.h:21
SYMS_U64 rsp
Definition syms_dwarf_expr.h:25
SYMS_U64 r11
Definition syms_dwarf_expr.h:29
SYMS_U64 r12
Definition syms_dwarf_expr.h:30
SYMS_U64 rsi
Definition syms_dwarf_expr.h:22
SYMS_U64 r13
Definition syms_dwarf_expr.h:31
SYMS_U64 r10
Definition syms_dwarf_expr.h:28
SYMS_U64 rdx
Definition syms_dwarf_expr.h:19
SYMS_U64 r14
Definition syms_dwarf_expr.h:32
Definition syms_dwarf_expr.h:159
SYMS_U64 fail_data
Definition syms_dwarf_expr.h:168
SYMS_DwSimpleLocKind kind
Definition syms_dwarf_expr.h:160
SYMS_U64 reg_idx
Definition syms_dwarf_expr.h:163
SYMS_U64 val
Definition syms_dwarf_expr.h:164
SYMS_U64 addr
Definition syms_dwarf_expr.h:162
SYMS_DwLocFailKind fail_kind
Definition syms_dwarf_expr.h:167
SYMS_String8 val_long
Definition syms_dwarf_expr.h:165
Definition syms_base.h:410
Definition syms_base.h:296
Definition syms_base.h:264
#define SYMS_READ_ONLY
Definition syms_base.h:57
#define SYMS_API
Definition syms_base.h:29
SYMS_U32 SYMS_RegID
Definition syms_base.h:107
SYMS_S32 SYMS_B32
Definition syms_base.h:99
#define SYMS_GLOBAL
Definition syms_base.h:42
uint32_t SYMS_U32
Definition syms_crt_overrides.h:38
uint64_t SYMS_U64
Definition syms_crt_overrides.h:39
#define SYMS_Arena
Definition syms_default_arena.h:61
SYMS_API void syms_dw_expr__call_pop(SYMS_DwExprCallStack *stack)
Definition syms_dwarf_expr.c:1450
SYMS_API SYMS_U64 syms_dw_expr__stack_pick(SYMS_DwExprStack *stack, SYMS_U64 idx)
Definition syms_dwarf_expr.c:1407
SYMS_GLOBAL SYMS_READ_ONLY SYMS_RegID syms_dw_reg_table_x86[]
Definition syms_dwarf_expr.h:60
SYMS_API SYMS_B32 syms_dw_expr__stack_is_empty(SYMS_DwExprStack *stack)
Definition syms_dwarf_expr.c:1422
SYMS_API SYMS_U64 syms_dw_expr__stack_pop(SYMS_DwExprStack *stack)
Definition syms_dwarf_expr.c:1395
SYMS_DwSimpleLocKind
Definition syms_dwarf_expr.h:127
@ SYMS_DwSimpleLocKind_Empty
Definition syms_dwarf_expr.h:132
@ SYMS_DwSimpleLocKind_Register
Definition syms_dwarf_expr.h:129
@ SYMS_DwSimpleLocKind_Address
Definition syms_dwarf_expr.h:128
@ SYMS_DwSimpleLocKind_ValueLong
Definition syms_dwarf_expr.h:131
@ SYMS_DwSimpleLocKind_Value
Definition syms_dwarf_expr.h:130
@ SYMS_DwSimpleLocKind_Fail
Definition syms_dwarf_expr.h:133
SYMS_API SYMS_DwLocation syms_dw_expr__eval(SYMS_Arena *arena_optional, void *base, SYMS_U64Range range, SYMS_DwExprMachineConfig *config)
Definition syms_dwarf_expr.c:578
SYMS_API SYMS_DwExprCall * syms_dw_expr__call_top(SYMS_DwExprCallStack *stack)
Definition syms_dwarf_expr.c:1430
SYMS_String8 SYMS_DwExprResolveCallFunc(void *call_user_ptr, SYMS_U64 p)
Definition syms_dwarf_expr.h:76
@ SYMS_DwExprFlag_NonLinearFlow
Definition syms_dwarf_expr.h:112
@ SYMS_DwExprFlag_NotSupported
Definition syms_dwarf_expr.h:110
@ SYMS_DwExprFlag_UsesTLSAddress
Definition syms_dwarf_expr.h:105
@ SYMS_DwExprFlag_UsesMemory
Definition syms_dwarf_expr.h:101
@ SYMS_DwExprFlag_UsesCallResolution
Definition syms_dwarf_expr.h:107
@ SYMS_DwExprFlag_UsesComposite
Definition syms_dwarf_expr.h:108
@ SYMS_DwExprFlag_UsesRegisters
Definition syms_dwarf_expr.h:102
@ SYMS_DwExprFlag_UsesCFA
Definition syms_dwarf_expr.h:106
@ SYMS_DwExprFlag_UsesObjectAddress
Definition syms_dwarf_expr.h:104
@ SYMS_DwExprFlag_BadData
Definition syms_dwarf_expr.h:111
@ SYMS_DwExprFlag_UsesTextBase
Definition syms_dwarf_expr.h:100
@ SYMS_DwExprFlag_UsesFrameBase
Definition syms_dwarf_expr.h:103
SYMS_API SYMS_DwSimpleLoc syms_dw_expr__analyze_fast(void *base, SYMS_U64Range range, SYMS_U64 text_section_base)
Definition syms_dwarf_expr.c:17
SYMS_API void syms_dw_expr__stack_push(SYMS_Arena *arena, SYMS_DwExprStack *stack, SYMS_U64 x)
Definition syms_dwarf_expr.c:1381
SYMS_API void syms_dw_expr__call_push(SYMS_Arena *arena, SYMS_DwExprCallStack *stack, void *ptr, SYMS_U64 size)
Definition syms_dwarf_expr.c:1436
SYMS_DwLocFailKind
Definition syms_dwarf_expr.h:136
@ SYMS_DwLocFailKind_TimeOut
Definition syms_dwarf_expr.h:146
@ SYMS_DwLocFailKind_MissingObjectAddress
Definition syms_dwarf_expr.h:152
@ SYMS_DwLocFailKind_NotSupported
Definition syms_dwarf_expr.h:145
@ SYMS_DwLocFailKind_MissingMemory
Definition syms_dwarf_expr.h:149
@ SYMS_DwLocFailKind_MissingFrameBase
Definition syms_dwarf_expr.h:151
@ SYMS_DwLocFailKind_MissingCFA
Definition syms_dwarf_expr.h:154
@ SYMS_DwLocFailKind_MissingArenaForComposite
Definition syms_dwarf_expr.h:156
@ SYMS_DwLocFailKind_MissingTextBase
Definition syms_dwarf_expr.h:148
@ SYMS_DwLocFailKind_MissingRegisters
Definition syms_dwarf_expr.h:150
@ SYMS_DwLocFailKind_MissingCallResolution
Definition syms_dwarf_expr.h:155
@ SYMS_DwLocFailKind_BadData
Definition syms_dwarf_expr.h:144
@ SYMS_DwLocFailKind_TooComplicated
Definition syms_dwarf_expr.h:147
@ SYMS_DwLocFailKind_MissingTLSAddress
Definition syms_dwarf_expr.h:153
SYMS_U32 SYMS_DwExprFlags
Definition syms_dwarf_expr.h:98
SYMS_API SYMS_DwExprAnalysis syms_dw_expr__analyze_details(void *base, SYMS_U64Range range, SYMS_DwExprMachineCallConfig *call_config)
Definition syms_dwarf_expr.c:192
SYMS_GLOBAL SYMS_READ_ONLY SYMS_RegID syms_dw_reg_table_x64[]
Definition syms_dwarf_expr.h:40
SYMS_API SYMS_DwExprStack syms_dw_expr__stack_make(SYMS_Arena *arena)
Definition syms_dwarf_expr.c:1375
SYMS_API SYMS_DwExprAnalysisTask * syms_dw_expr__analysis_task_from_p(SYMS_DwExprAnalysisTask *first, SYMS_U64 p)
Definition syms_dwarf_expr.c:1461
@ SYMS_RegX64Code_r15
Definition syms_meta_regs_x64.h:103
@ SYMS_RegX64Code_rip
Definition syms_meta_regs_x64.h:106
@ SYMS_RegX64Code_r8
Definition syms_meta_regs_x64.h:96
@ SYMS_RegX64Code_rsi
Definition syms_meta_regs_x64.h:94
@ SYMS_RegX64Code_rsp
Definition syms_meta_regs_x64.h:92
@ SYMS_RegX64Code_rax
Definition syms_meta_regs_x64.h:88
@ SYMS_RegX64Code_rcx
Definition syms_meta_regs_x64.h:89
@ SYMS_RegX64Code_r11
Definition syms_meta_regs_x64.h:99
@ SYMS_RegX64Code_r12
Definition syms_meta_regs_x64.h:100
@ SYMS_RegX64Code_r14
Definition syms_meta_regs_x64.h:102
@ SYMS_RegX64Code_rdi
Definition syms_meta_regs_x64.h:95
@ SYMS_RegX64Code_r10
Definition syms_meta_regs_x64.h:98
@ SYMS_RegX64Code_rbp
Definition syms_meta_regs_x64.h:93
@ SYMS_RegX64Code_rdx
Definition syms_meta_regs_x64.h:90
@ SYMS_RegX64Code_r13
Definition syms_meta_regs_x64.h:101
@ SYMS_RegX64Code_r9
Definition syms_meta_regs_x64.h:97
@ SYMS_RegX64Code_rbx
Definition syms_meta_regs_x64.h:91
@ SYMS_RegX86Code_eip
Definition syms_meta_regs_x86.h:83
@ SYMS_RegX86Code_esi
Definition syms_meta_regs_x86.h:78
@ SYMS_RegX86Code_eax
Definition syms_meta_regs_x86.h:72
@ SYMS_RegX86Code_esp
Definition syms_meta_regs_x86.h:76
@ SYMS_RegX86Code_ebp
Definition syms_meta_regs_x86.h:77
@ SYMS_RegX86Code_edx
Definition syms_meta_regs_x86.h:74
@ SYMS_RegX86Code_edi
Definition syms_meta_regs_x86.h:79
@ SYMS_RegX86Code_ebx
Definition syms_meta_regs_x86.h:75
@ SYMS_RegX86Code_ecx
Definition syms_meta_regs_x86.h:73