1
1
// See doc.rs for documentation.
2
2
mod doc;
3
3
4
- use rustc_codegen_ssa:: mir:: debuginfo:: VariableAccess :: * ;
5
4
use rustc_codegen_ssa:: mir:: debuginfo:: VariableKind :: * ;
6
5
7
6
use self :: utils:: { DIB , span_start, create_DIArray, is_node_local_to_unit} ;
@@ -28,17 +27,18 @@ use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet};
28
27
use rustc_data_structures:: small_c_str:: SmallCStr ;
29
28
use rustc_index:: vec:: IndexVec ;
30
29
use rustc_codegen_ssa:: debuginfo:: type_names;
31
- use rustc_codegen_ssa:: mir:: debuginfo:: { FunctionDebugContext , DebugScope , VariableAccess ,
30
+ use rustc_codegen_ssa:: mir:: debuginfo:: { FunctionDebugContext , DebugScope ,
32
31
VariableKind } ;
33
32
34
33
use libc:: c_uint;
35
34
use std:: cell:: RefCell ;
36
35
use std:: ffi:: { CStr , CString } ;
37
36
37
+ use smallvec:: SmallVec ;
38
38
use syntax_pos:: { self , BytePos , Span , Pos } ;
39
39
use syntax:: ast;
40
40
use syntax:: symbol:: Symbol ;
41
- use rustc:: ty:: layout:: { self , LayoutOf , HasTyCtxt } ;
41
+ use rustc:: ty:: layout:: { self , LayoutOf , HasTyCtxt , Size } ;
42
42
use rustc_codegen_ssa:: traits:: * ;
43
43
44
44
pub mod gdb;
@@ -153,7 +153,9 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
153
153
variable_name : ast:: Name ,
154
154
variable_type : Ty < ' tcx > ,
155
155
scope_metadata : & ' ll DIScope ,
156
- variable_access : VariableAccess < ' _ , & ' ll Value > ,
156
+ variable_alloca : Self :: Value ,
157
+ direct_offset : Size ,
158
+ indirect_offsets : & [ Size ] ,
157
159
variable_kind : VariableKind ,
158
160
span : Span ,
159
161
) {
@@ -174,43 +176,55 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
174
176
} ;
175
177
let align = cx. align_of ( variable_type) ;
176
178
177
- let name = SmallCStr :: new ( & variable_name. as_str ( ) ) ;
178
- match ( variable_access, & [ ] [ ..] ) {
179
- ( DirectVariable { alloca } , address_operations) |
180
- ( IndirectVariable { alloca, address_operations} , _) => {
181
- let metadata = unsafe {
182
- llvm:: LLVMRustDIBuilderCreateVariable (
183
- DIB ( cx) ,
184
- dwarf_tag,
185
- scope_metadata,
186
- name. as_ptr ( ) ,
187
- file_metadata,
188
- loc. line as c_uint ,
189
- type_metadata,
190
- cx. sess ( ) . opts . optimize != config:: OptLevel :: No ,
191
- DIFlags :: FlagZero ,
192
- argument_index,
193
- align. bytes ( ) as u32 ,
194
- )
195
- } ;
196
- source_loc:: set_debug_location ( self ,
197
- InternalDebugLocation :: new ( scope_metadata, loc. line , loc. col . to_usize ( ) ) ) ;
198
- unsafe {
199
- let debug_loc = llvm:: LLVMGetCurrentDebugLocation ( self . llbuilder ) ;
200
- let instr = llvm:: LLVMRustDIBuilderInsertDeclareAtEnd (
201
- DIB ( cx) ,
202
- alloca,
203
- metadata,
204
- address_operations. as_ptr ( ) ,
205
- address_operations. len ( ) as c_uint ,
206
- debug_loc,
207
- self . llbb ( ) ) ;
208
-
209
- llvm:: LLVMSetInstDebugLocation ( self . llbuilder , instr) ;
210
- }
211
- source_loc:: set_debug_location ( self , UnknownLocation ) ;
179
+ // Convert the direct and indirect offsets to address ops.
180
+ let op_deref = || unsafe { llvm:: LLVMRustDIBuilderCreateOpDeref ( ) } ;
181
+ let op_plus_uconst = || unsafe { llvm:: LLVMRustDIBuilderCreateOpPlusUconst ( ) } ;
182
+ let mut addr_ops = SmallVec :: < [ _ ; 8 ] > :: new ( ) ;
183
+
184
+ if direct_offset. bytes ( ) > 0 {
185
+ addr_ops. push ( op_plus_uconst ( ) ) ;
186
+ addr_ops. push ( direct_offset. bytes ( ) as i64 ) ;
187
+ }
188
+ for & offset in indirect_offsets {
189
+ addr_ops. push ( op_deref ( ) ) ;
190
+ if offset. bytes ( ) > 0 {
191
+ addr_ops. push ( op_plus_uconst ( ) ) ;
192
+ addr_ops. push ( offset. bytes ( ) as i64 ) ;
212
193
}
213
194
}
195
+
196
+ let name = SmallCStr :: new ( & variable_name. as_str ( ) ) ;
197
+ let metadata = unsafe {
198
+ llvm:: LLVMRustDIBuilderCreateVariable (
199
+ DIB ( cx) ,
200
+ dwarf_tag,
201
+ scope_metadata,
202
+ name. as_ptr ( ) ,
203
+ file_metadata,
204
+ loc. line as c_uint ,
205
+ type_metadata,
206
+ cx. sess ( ) . opts . optimize != config:: OptLevel :: No ,
207
+ DIFlags :: FlagZero ,
208
+ argument_index,
209
+ align. bytes ( ) as u32 ,
210
+ )
211
+ } ;
212
+ source_loc:: set_debug_location ( self ,
213
+ InternalDebugLocation :: new ( scope_metadata, loc. line , loc. col . to_usize ( ) ) ) ;
214
+ unsafe {
215
+ let debug_loc = llvm:: LLVMGetCurrentDebugLocation ( self . llbuilder ) ;
216
+ let instr = llvm:: LLVMRustDIBuilderInsertDeclareAtEnd (
217
+ DIB ( cx) ,
218
+ variable_alloca,
219
+ metadata,
220
+ addr_ops. as_ptr ( ) ,
221
+ addr_ops. len ( ) as c_uint ,
222
+ debug_loc,
223
+ self . llbb ( ) ) ;
224
+
225
+ llvm:: LLVMSetInstDebugLocation ( self . llbuilder , instr) ;
226
+ }
227
+ source_loc:: set_debug_location ( self , UnknownLocation ) ;
214
228
}
215
229
216
230
fn set_source_location (
@@ -571,13 +585,4 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
571
585
fn debuginfo_finalize ( & self ) {
572
586
finalize ( self )
573
587
}
574
-
575
- fn debuginfo_upvar_ops_sequence ( & self , byte_offset_of_var_in_env : u64 ) -> [ i64 ; 4 ] {
576
- unsafe {
577
- [ llvm:: LLVMRustDIBuilderCreateOpDeref ( ) ,
578
- llvm:: LLVMRustDIBuilderCreateOpPlusUconst ( ) ,
579
- byte_offset_of_var_in_env as i64 ,
580
- llvm:: LLVMRustDIBuilderCreateOpDeref ( ) ]
581
- }
582
- }
583
588
}
0 commit comments