11// See doc.rs for documentation.
22mod doc;
33
4- use rustc_codegen_ssa:: mir:: debuginfo:: VariableAccess :: * ;
54use rustc_codegen_ssa:: mir:: debuginfo:: VariableKind :: * ;
65
76use self :: utils:: { DIB , span_start, create_DIArray, is_node_local_to_unit} ;
@@ -28,17 +27,18 @@ use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet};
2827use rustc_data_structures:: small_c_str:: SmallCStr ;
2928use rustc_index:: vec:: IndexVec ;
3029use 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 ,
3231 VariableKind } ;
3332
3433use libc:: c_uint;
3534use std:: cell:: RefCell ;
3635use std:: ffi:: { CStr , CString } ;
3736
37+ use smallvec:: SmallVec ;
3838use syntax_pos:: { self , BytePos , Span , Pos } ;
3939use syntax:: ast;
4040use syntax:: symbol:: Symbol ;
41- use rustc:: ty:: layout:: { self , LayoutOf , HasTyCtxt } ;
41+ use rustc:: ty:: layout:: { self , LayoutOf , HasTyCtxt , Size } ;
4242use rustc_codegen_ssa:: traits:: * ;
4343
4444pub mod gdb;
@@ -153,7 +153,9 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
153153 variable_name : ast:: Name ,
154154 variable_type : Ty < ' tcx > ,
155155 scope_metadata : & ' ll DIScope ,
156- variable_access : VariableAccess < ' _ , & ' ll Value > ,
156+ variable_alloca : Self :: Value ,
157+ direct_offset : Size ,
158+ indirect_offsets : & [ Size ] ,
157159 variable_kind : VariableKind ,
158160 span : Span ,
159161 ) {
@@ -174,43 +176,55 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
174176 } ;
175177 let align = cx. align_of ( variable_type) ;
176178
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 ) ;
212193 }
213194 }
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 ) ;
214228 }
215229
216230 fn set_source_location (
@@ -571,13 +585,4 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
571585 fn debuginfo_finalize ( & self ) {
572586 finalize ( self )
573587 }
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- }
583588}
0 commit comments