@@ -53,6 +53,16 @@ const DW_TAG_auto_variable: c_uint = 0x100;
53
53
#[ allow( non_upper_case_globals) ]
54
54
const DW_TAG_arg_variable : c_uint = 0x101 ;
55
55
56
+ // `DW_OP_*` values taken from:
57
+ // - `llvm/include/llvm/BinaryFormat/Dwarf.def`
58
+ // - `llvm/include/llvm/BinaryFormat/Dwarf.h`
59
+ #[ allow( non_upper_case_globals) ]
60
+ const DW_OP_deref : u64 = 0x06 ;
61
+ #[ allow( non_upper_case_globals) ]
62
+ const DW_OP_plus_uconst : u64 = 0x23 ;
63
+ #[ allow( non_upper_case_globals) ]
64
+ const DW_OP_LLVM_fragment : u64 = 0x1000 ;
65
+
56
66
/// A context object for maintaining all state needed by the debuginfo module.
57
67
pub ( crate ) struct CodegenUnitDebugContext < ' ll , ' tcx > {
58
68
llmod : & ' ll llvm:: Module ,
@@ -146,28 +156,23 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
146
156
fragment : Option < Range < Size > > ,
147
157
) {
148
158
// Convert the direct and indirect offsets and fragment byte range to address ops.
149
- // FIXME(eddyb) use `const`s instead of getting the values via FFI,
150
- // the values should match the ones in the DWARF standard anyway.
151
- let op_deref = || unsafe { llvm:: LLVMRustDIBuilderCreateOpDeref ( ) } ;
152
- let op_plus_uconst = || unsafe { llvm:: LLVMRustDIBuilderCreateOpPlusUconst ( ) } ;
153
- let op_llvm_fragment = || unsafe { llvm:: LLVMRustDIBuilderCreateOpLLVMFragment ( ) } ;
154
159
let mut addr_ops = SmallVec :: < [ u64 ; 8 ] > :: new ( ) ;
155
160
156
161
if direct_offset. bytes ( ) > 0 {
157
- addr_ops. push ( op_plus_uconst ( ) ) ;
162
+ addr_ops. push ( DW_OP_plus_uconst ) ;
158
163
addr_ops. push ( direct_offset. bytes ( ) as u64 ) ;
159
164
}
160
165
for & offset in indirect_offsets {
161
- addr_ops. push ( op_deref ( ) ) ;
166
+ addr_ops. push ( DW_OP_deref ) ;
162
167
if offset. bytes ( ) > 0 {
163
- addr_ops. push ( op_plus_uconst ( ) ) ;
168
+ addr_ops. push ( DW_OP_plus_uconst ) ;
164
169
addr_ops. push ( offset. bytes ( ) as u64 ) ;
165
170
}
166
171
}
167
172
if let Some ( fragment) = fragment {
168
173
// `DW_OP_LLVM_fragment` takes as arguments the fragment's
169
174
// offset and size, both of them in bits.
170
- addr_ops. push ( op_llvm_fragment ( ) ) ;
175
+ addr_ops. push ( DW_OP_LLVM_fragment ) ;
171
176
addr_ops. push ( fragment. start . bits ( ) as u64 ) ;
172
177
addr_ops. push ( ( fragment. end - fragment. start ) . bits ( ) as u64 ) ;
173
178
}
0 commit comments