10
10
11
11
use self :: InternalDebugLocation :: * ;
12
12
13
- use super :: utils:: { debug_context, span_start } ;
13
+ use super :: utils:: debug_context;
14
14
use super :: metadata:: { scope_metadata, UNKNOWN_COLUMN_NUMBER } ;
15
15
use super :: { FunctionDebugContext , DebugLoc } ;
16
16
@@ -21,7 +21,7 @@ use common::{NodeIdAndSpan, CrateContext, FunctionContext};
21
21
22
22
use libc:: c_uint;
23
23
use std:: ptr;
24
- use syntax_pos:: { self , Span , Pos } ;
24
+ use syntax_pos:: { self , Span , BytePos } ;
25
25
use syntax:: ast;
26
26
27
27
pub fn get_cleanup_debug_loc_for_ast_node < ' a , ' tcx > ( cx : & CrateContext < ' a , ' tcx > ,
@@ -108,21 +108,20 @@ pub fn set_source_location(fcx: &FunctionContext,
108
108
}
109
109
110
110
let dbg_loc = if function_debug_context. source_locations_enabled . get ( ) {
111
- let ( scope , span ) = match debug_loc {
111
+ match debug_loc {
112
112
DebugLoc :: At ( node_id, span) => {
113
- ( scope_metadata ( fcx, node_id, span) , span)
113
+ let scope = scope_metadata ( fcx, node_id, span) ;
114
+ KnownLocation ( scope, span. lo , None )
114
115
}
115
- DebugLoc :: ScopeAt ( scope, span) => ( scope, span) ,
116
- DebugLoc :: None => {
117
- set_debug_location ( fcx. ccx , builder, UnknownLocation ) ;
118
- return ;
116
+ DebugLoc :: ScopeAt ( scope, span, inlined_at) => {
117
+ let inlined_at_loc = match inlined_at {
118
+ Some ( ( scope, span) ) => Some ( ( scope, span. lo ) ) ,
119
+ None => None
120
+ } ;
121
+ KnownLocation ( scope, span. lo , inlined_at_loc)
119
122
}
120
- } ;
121
-
122
- debug ! ( "set_source_location: {}" ,
123
- fcx. ccx. sess( ) . codemap( ) . span_to_string( span) ) ;
124
- let loc = span_start ( fcx. ccx , span) ;
125
- InternalDebugLocation :: new ( scope, loc. line , loc. col . to_usize ( ) )
123
+ DebugLoc :: None => UnknownLocation
124
+ }
126
125
} else {
127
126
UnknownLocation
128
127
} ;
@@ -173,23 +172,12 @@ pub fn start_emitting_source_locations(fcx: &FunctionContext) {
173
172
}
174
173
}
175
174
176
-
177
175
#[ derive( Copy , Clone , PartialEq ) ]
178
176
pub enum InternalDebugLocation {
179
- KnownLocation { scope : DIScope , line : usize , col : usize } ,
177
+ KnownLocation ( DIScope , BytePos , Option < ( DIScope , BytePos ) > ) ,
180
178
UnknownLocation
181
179
}
182
180
183
- impl InternalDebugLocation {
184
- pub fn new ( scope : DIScope , line : usize , col : usize ) -> InternalDebugLocation {
185
- KnownLocation {
186
- scope : scope,
187
- line : line,
188
- col : col,
189
- }
190
- }
191
- }
192
-
193
181
pub fn set_debug_location ( cx : & CrateContext ,
194
182
builder : Option < llvm:: BuilderRef > ,
195
183
debug_location : InternalDebugLocation ) {
@@ -199,19 +187,37 @@ pub fn set_debug_location(cx: &CrateContext,
199
187
}
200
188
}
201
189
190
+ let cm = cx. sess ( ) . codemap ( ) ;
202
191
let metadata_node = match debug_location {
203
- KnownLocation { scope, line, .. } => {
204
- // Always set the column to zero like Clang and GCC
205
- let col = UNKNOWN_COLUMN_NUMBER ;
206
- debug ! ( "setting debug location to {} {}" , line, col) ;
207
-
192
+ KnownLocation ( scope, pos, inlined_at) => {
193
+
194
+ let inlined_at_loc = match inlined_at {
195
+ Some ( ( scope, pos) ) => {
196
+ let loc = cm. lookup_char_pos ( pos) ;
197
+ unsafe {
198
+ llvm:: LLVMRustValueAsMetadata (
199
+ llvm:: LLVMRustDIBuilderCreateDebugLocation (
200
+ debug_context ( cx) . llcontext ,
201
+ loc. line as c_uint ,
202
+ UNKNOWN_COLUMN_NUMBER as c_uint ,
203
+ scope,
204
+ ptr:: null_mut ( ) )
205
+ )
206
+ }
207
+ } ,
208
+ None => ptr:: null_mut ( )
209
+ } ;
210
+
211
+ let loc = cm. lookup_char_pos ( pos) ;
212
+ debug ! ( "setting debug location to line {}" , loc. line) ;
213
+ // Set the column to zero like Clang and GCC
208
214
unsafe {
209
215
llvm:: LLVMRustDIBuilderCreateDebugLocation (
210
216
debug_context ( cx) . llcontext ,
211
- line as c_uint ,
212
- col as c_uint ,
217
+ loc . line as c_uint ,
218
+ UNKNOWN_COLUMN_NUMBER as c_uint ,
213
219
scope,
214
- ptr :: null_mut ( ) )
220
+ inlined_at_loc )
215
221
}
216
222
}
217
223
UnknownLocation => {
0 commit comments