@@ -53,6 +53,16 @@ const DW_TAG_auto_variable: c_uint = 0x100;
5353#[ allow( non_upper_case_globals) ]
5454const DW_TAG_arg_variable : c_uint = 0x101 ;
5555
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+
5666/// A context object for maintaining all state needed by the debuginfo module.
5767pub ( crate ) struct CodegenUnitDebugContext < ' ll , ' tcx > {
5868 llmod : & ' ll llvm:: Module ,
@@ -146,28 +156,23 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
146156 fragment : Option < Range < Size > > ,
147157 ) {
148158 // 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 ( ) } ;
154159 let mut addr_ops = SmallVec :: < [ u64 ; 8 ] > :: new ( ) ;
155160
156161 if direct_offset. bytes ( ) > 0 {
157- addr_ops. push ( op_plus_uconst ( ) ) ;
162+ addr_ops. push ( DW_OP_plus_uconst ) ;
158163 addr_ops. push ( direct_offset. bytes ( ) as u64 ) ;
159164 }
160165 for & offset in indirect_offsets {
161- addr_ops. push ( op_deref ( ) ) ;
166+ addr_ops. push ( DW_OP_deref ) ;
162167 if offset. bytes ( ) > 0 {
163- addr_ops. push ( op_plus_uconst ( ) ) ;
168+ addr_ops. push ( DW_OP_plus_uconst ) ;
164169 addr_ops. push ( offset. bytes ( ) as u64 ) ;
165170 }
166171 }
167172 if let Some ( fragment) = fragment {
168173 // `DW_OP_LLVM_fragment` takes as arguments the fragment's
169174 // offset and size, both of them in bits.
170- addr_ops. push ( op_llvm_fragment ( ) ) ;
175+ addr_ops. push ( DW_OP_LLVM_fragment ) ;
171176 addr_ops. push ( fragment. start . bits ( ) as u64 ) ;
172177 addr_ops. push ( ( fragment. end - fragment. start ) . bits ( ) as u64 ) ;
173178 }
0 commit comments