@@ -75,11 +75,11 @@ struct _DebugContext {
75
75
}
76
76
77
77
/** Create new DebugContext */
78
- pub fn mk_ctxt ( llmod : ModuleRef , crate : ~str , intr : @ ident_interner ) -> DebugContext {
78
+ pub fn mk_ctxt ( llmod : ModuleRef , crate : ~str ) -> DebugContext {
79
79
debug ! ( "mk_ctxt" ) ;
80
80
let builder = unsafe { llvm:: LLVMDIBuilderCreate ( llmod) } ;
81
81
let dcx = @mut _DebugContext {
82
- names : new_namegen ( intr ) ,
82
+ names : new_namegen ( ) ,
83
83
crate_file: crate ,
84
84
builder : builder,
85
85
curr_loc : ( 0 , 0 ) ,
@@ -114,33 +114,9 @@ pub fn finalize(cx: @CrateContext) {
114
114
} ;
115
115
}
116
116
117
- fn filename_from_span ( cx : @CrateContext , sp : codemap:: span ) -> ~str {
118
- /*bad*/ copy cx. sess . codemap . lookup_char_pos ( sp. lo ) . file . name
119
- }
120
-
121
- //fn filename_from_span<'cx>(cx: &'cx CrateContext, sp: codemap::span) -> &'cx str {
122
- // let fname: &str = cx.sess.codemap.lookup_char_pos(sp.lo).file.name;
123
- // return fname;
124
- //}
125
-
126
- fn get_file_path_and_dir ( work_dir : & str , full_path : & str ) -> ( ~str , ~str ) {
127
- let full_path =
128
- if str:: starts_with ( full_path, work_dir) {
129
- str:: slice ( full_path, str:: len ( work_dir) + 1 u,
130
- str:: len ( full_path) ) . to_owned ( )
131
- } else {
132
- full_path. to_owned ( )
133
- } ;
134
-
135
- return ( full_path, work_dir. to_owned ( ) ) ;
136
- }
137
-
138
117
fn create_compile_unit ( cx : @CrateContext ) {
139
118
let crate_name: & str = dbg_cx ( cx) . crate_file ;
140
-
141
- let ( _, work_dir) = get_file_path_and_dir (
142
- cx. sess . working_dir . to_str ( ) , crate_name) ;
143
-
119
+ let work_dir = cx. sess . working_dir . to_str ( ) ;
144
120
let producer = fmt ! ( "rustc version %s" , env!( "CFG_VERSION" ) ) ;
145
121
146
122
do as_c_str( crate_name) |crate_name| {
@@ -158,29 +134,33 @@ fn create_compile_unit(cx: @CrateContext) {
158
134
fn create_file ( cx : @CrateContext , full_path : & str ) -> DIFile {
159
135
let dcx = dbg_cx ( cx) ;
160
136
161
- match dcx. created_files . find ( & full_path. to_owned ( ) ) {
137
+ match dcx. created_files . find_equiv ( & full_path) {
162
138
Some ( file_md) => return * file_md,
163
139
None => ( )
164
140
}
165
141
166
142
debug ! ( "create_file: %s" , full_path) ;
167
143
168
- let ( file_path, work_dir) =
169
- get_file_path_and_dir ( cx. sess . working_dir . to_str ( ) ,
170
- full_path) ;
171
-
144
+ let work_dir = cx. sess . working_dir . to_str ( ) ;
145
+ let file_name =
146
+ if full_path. starts_with ( work_dir) {
147
+ full_path. slice ( work_dir. len ( ) + 1 u, full_path. len ( ) )
148
+ } else {
149
+ full_path
150
+ } ;
151
+
172
152
let file_md =
173
- do as_c_str ( file_path ) |file_path | {
153
+ do as_c_str ( file_name ) |file_name | {
174
154
do as_c_str ( work_dir) |work_dir| { unsafe {
175
- llvm:: LLVMDIBuilderCreateFile ( dcx. builder , file_path , work_dir)
155
+ llvm:: LLVMDIBuilderCreateFile ( dcx. builder , file_name , work_dir)
176
156
} } } ;
177
157
178
158
dcx. created_files . insert ( full_path. to_owned ( ) , file_md) ;
179
159
return file_md;
180
160
}
181
161
182
- fn line_from_span ( cm : @codemap :: CodeMap , sp : span ) -> uint {
183
- cm . lookup_char_pos ( sp . lo ) . line
162
+ fn span_start ( cx : @CrateContext , span : span ) -> codemap :: Loc {
163
+ return cx . sess . codemap . lookup_char_pos ( span . lo ) ;
184
164
}
185
165
186
166
fn create_block ( bcx : block ) -> DILexicalBlock {
@@ -194,31 +174,29 @@ fn create_block(bcx: block) -> DILexicalBlock {
194
174
None => fail ! ( )
195
175
}
196
176
}
197
- let sp = bcx. node_info . get ( ) . span ;
177
+ let span = bcx. node_info . get ( ) . span ;
198
178
let id = bcx. node_info . get ( ) . id ;
199
179
200
180
match dcx. created_blocks . find ( & id) {
201
181
Some ( block) => return * block,
202
182
None => ( )
203
183
}
204
184
205
- debug ! ( "create_block: %s" , bcx. sess( ) . codemap. span_to_str( sp) ) ;
206
-
207
- let start = bcx. sess ( ) . codemap . lookup_char_pos ( sp. lo ) ;
208
- //let end = bcx.sess().codemap.lookup_char_pos(sp.hi);
185
+ debug ! ( "create_block: %s" , bcx. sess( ) . codemap. span_to_str( span) ) ;
209
186
210
187
let parent = match bcx. parent {
211
188
None => create_function ( bcx. fcx ) ,
212
189
Some ( b) => create_block ( b)
213
190
} ;
214
-
215
- let file_md = create_file ( bcx. ccx ( ) , start. file . name ) ;
191
+ let cx = bcx. ccx ( ) ;
192
+ let loc = span_start ( cx, span) ;
193
+ let file_md = create_file ( cx, loc. file . name ) ;
216
194
217
195
let block_md = unsafe {
218
196
llvm:: LLVMDIBuilderCreateLexicalBlock (
219
197
dcx. builder ,
220
198
parent, file_md,
221
- start . line . to_int ( ) as c_uint , start . col . to_int ( ) as c_uint )
199
+ loc . line as c_uint , loc . col . to_uint ( ) as c_uint )
222
200
} ;
223
201
224
202
dcx. created_blocks . insert ( id, block_md) ;
@@ -342,18 +320,16 @@ impl StructContext {
342
320
}
343
321
344
322
fn create_struct ( cx : @CrateContext , t : ty:: t , fields : ~[ ty:: field ] , span : span ) -> DICompositeType {
345
- let fname = filename_from_span ( cx, span) ;
346
- let file_md = create_file ( cx, fname) ;
347
- let line = line_from_span ( cx. sess . codemap , span) ;
323
+ let loc = span_start ( cx, span) ;
324
+ let file_md = create_file ( cx, loc. file . name ) ;
348
325
349
- let mut scx = StructContext :: create ( cx, file_md, ty_to_str ( cx. tcx , t) , line) ;
326
+ let mut scx = StructContext :: create ( cx, file_md, ty_to_str ( cx. tcx , t) , loc . line ) ;
350
327
for fields. each |field| {
351
328
let field_t = field. mt . ty ;
352
329
let ty_md = create_ty ( cx, field_t, span) ;
353
330
let ( size, align) = size_and_align_of ( cx, field_t) ;
354
331
scx. add_member ( cx. sess . str_of ( field. ident ) ,
355
- line_from_span ( cx. sess . codemap , span) ,
356
- size, align, ty_md) ;
332
+ loc. line , size, align, ty_md) ;
357
333
}
358
334
return scx. finalize ( ) ;
359
335
}
@@ -371,25 +347,24 @@ fn voidptr(cx: @CrateContext) -> (DIDerivedType, uint, uint) {
371
347
372
348
fn create_tuple ( cx : @CrateContext , t : ty:: t , elements : & [ ty:: t ] , span : span ) -> DICompositeType {
373
349
let dcx = dbg_cx ( cx) ;
374
- let fname = filename_from_span ( cx, span) ;
375
- let file_md = create_file ( cx, fname ) ;
350
+ let loc = span_start ( cx, span) ;
351
+ let file_md = create_file ( cx, loc . file . name ) ;
376
352
377
353
let name = ( cx. sess . str_of ( ( dcx. names ) ( "tuple" ) ) ) . to_owned ( ) ;
378
354
let mut scx = StructContext :: create ( cx, file_md, name, loc. line ) ;
379
355
380
356
for elements. each |element| {
381
357
let ty_md = create_ty ( cx, * element, span) ;
382
358
let ( size, align) = size_and_align_of ( cx, * element) ;
383
- scx. add_member ( "" , line_from_span ( cx. sess . codemap , span) ,
384
- size, align, ty_md) ;
359
+ scx. add_member ( "" , loc. line , size, align, ty_md) ;
385
360
}
386
361
return scx. finalize ( ) ;
387
362
}
388
363
389
364
fn create_boxed_type ( cx : @CrateContext , contents : ty:: t ,
390
365
span : span , boxed : DIType ) -> DICompositeType {
391
- let fname = filename_from_span ( cx, span) ;
392
- let file_md = create_file ( cx, fname ) ;
366
+ let loc = span_start ( cx, span) ;
367
+ let file_md = create_file ( cx, loc . file . name ) ;
393
368
let int_t = ty:: mk_int ( ) ;
394
369
let refcount_type = create_basic_type ( cx, int_t, span) ;
395
370
let name = ty_to_str ( cx. tcx , contents) ;
@@ -412,8 +387,8 @@ fn create_fixed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
412
387
len : uint , span : span ) -> DIType {
413
388
let dcx = dbg_cx ( cx) ;
414
389
let elem_ty_md = create_ty ( cx, elem_t, span) ;
415
- let fname = filename_from_span ( cx, span) ;
416
- let file_md = create_file ( cx, fname ) ;
390
+ let loc = span_start ( cx, span) ;
391
+ let file_md = create_file ( cx, loc . file . name ) ;
417
392
let ( size, align) = size_and_align_of ( cx, elem_t) ;
418
393
419
394
let subrange = unsafe {
@@ -427,10 +402,10 @@ fn create_fixed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
427
402
}
428
403
429
404
fn create_boxed_vec ( cx : @CrateContext , vec_t : ty:: t , elem_t : ty:: t ,
430
- vec_ty_span : codemap :: span ) -> DICompositeType {
405
+ vec_ty_span : span ) -> DICompositeType {
431
406
let dcx = dbg_cx ( cx) ;
432
- let fname = filename_from_span ( cx, vec_ty_span) ;
433
- let file_md = create_file ( cx, fname ) ;
407
+ let loc = span_start ( cx, vec_ty_span) ;
408
+ let file_md = create_file ( cx, loc . file . name ) ;
434
409
let elem_ty_md = create_ty ( cx, elem_t, vec_ty_span) ;
435
410
436
411
let mut vec_scx = StructContext :: create ( cx, file_md, ty_to_str ( cx. tcx , vec_t) , 0 ) ;
@@ -468,8 +443,8 @@ fn create_boxed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
468
443
}
469
444
470
445
fn create_vec_slice ( cx : @CrateContext , vec_t : ty:: t , elem_t : ty:: t , span : span ) -> DICompositeType {
471
- let fname = filename_from_span ( cx, span) ;
472
- let file_md = create_file ( cx, fname ) ;
446
+ let loc = span_start ( cx, span) ;
447
+ let file_md = create_file ( cx, loc . file . name ) ;
473
448
let elem_ty_md = create_ty ( cx, elem_t, span) ;
474
449
let uint_type = create_basic_type ( cx, ty:: mk_uint ( ) , span) ;
475
450
let elem_ptr = create_pointer_type ( cx, elem_t, span, elem_ty_md) ;
@@ -485,8 +460,8 @@ fn create_vec_slice(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t, span: span)
485
460
fn create_fn_ty ( cx : @CrateContext , fn_ty : ty:: t , inputs : ~[ ty:: t ] , output : ty:: t ,
486
461
span : span ) -> DICompositeType {
487
462
let dcx = dbg_cx ( cx) ;
488
- let fname = filename_from_span ( cx, span) ;
489
- let file_md = create_file ( cx, fname ) ;
463
+ let loc = span_start ( cx, span) ;
464
+ let file_md = create_file ( cx, loc . file . name ) ;
490
465
let ( vp, _, _) = voidptr ( cx) ;
491
466
let output_md = create_ty ( cx, output, span) ;
492
467
let output_ptr_md = create_pointer_type ( cx, output, span, output_md) ;
@@ -593,7 +568,7 @@ pub fn create_local_var(bcx: block, local: @ast::local) -> DIVariable {
593
568
} ;
594
569
let name: & str = cx. sess . str_of ( ident) ;
595
570
debug ! ( "create_local_var: %s" , name) ;
596
-
571
+
597
572
let loc = span_start ( cx, local. span ) ;
598
573
let ty = node_id_type ( bcx, local. node . id ) ;
599
574
let tymd = create_ty ( cx, ty, local. node . ty . span ) ;
@@ -629,12 +604,12 @@ pub fn create_local_var(bcx: block, local: @ast::local) -> DIVariable {
629
604
return var_md;
630
605
}
631
606
632
- pub fn create_arg ( bcx : block , arg : ast:: arg , sp : span ) -> Option < DIVariable > {
607
+ pub fn create_arg ( bcx : block , arg : ast:: arg , span : span ) -> Option < DIVariable > {
633
608
debug ! ( "create_arg" ) ;
634
609
let fcx = bcx. fcx , cx = * fcx. ccx ;
635
610
let dcx = dbg_cx ( cx) ;
636
611
637
- let loc = cx . sess . codemap . lookup_char_pos ( sp . lo ) ;
612
+ let loc = span_start ( cx , span ) ;
638
613
if "<intrinsic>" == loc. file . name {
639
614
return None ;
640
615
}
@@ -654,7 +629,7 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span) -> Option<DIVariable> {
654
629
let ident = path. idents . last ( ) ;
655
630
let name: & str = cx. sess . str_of ( * ident) ;
656
631
let mdnode = do as_c_str ( name) |name| { unsafe {
657
- llvm:: LLVMDIBuilderCreateLocalVariable ( dcx. builder ,
632
+ llvm:: LLVMDIBuilderCreateLocalVariable ( dcx. builder ,
658
633
ArgVariableTag as u32 , context, name,
659
634
filemd, loc. line as c_uint , tymd, false , 0 , 0 )
660
635
// FIXME need to pass a real argument number
@@ -681,16 +656,15 @@ fn set_debug_location(bcx: block, line: uint, col: uint) {
681
656
}
682
657
}
683
658
684
- pub fn update_source_pos ( bcx : block , sp : span ) {
685
- if !bcx. sess ( ) . opts . debuginfo || ( * sp . lo == 0 && * sp . hi == 0 ) {
659
+ pub fn update_source_pos ( bcx : block , span : span ) {
660
+ if !bcx. sess ( ) . opts . debuginfo || ( * span . lo == 0 && * span . hi == 0 ) {
686
661
return ;
687
662
}
688
663
689
- debug ! ( "update_source_pos: %s" , bcx. sess( ) . codemap. span_to_str( sp ) ) ;
664
+ debug ! ( "update_source_pos: %s" , bcx. sess( ) . codemap. span_to_str( span ) ) ;
690
665
691
- let cm = bcx. sess ( ) . codemap ;
692
- let loc = cm. lookup_char_pos ( sp. lo ) ;
693
666
let cx = bcx. ccx ( ) ;
667
+ let loc = span_start ( cx, span) ;
694
668
let mut dcx = dbg_cx ( cx) ;
695
669
696
670
let loc = ( loc. line , loc. col . to_uint ( ) ) ;
@@ -706,7 +680,7 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
706
680
let cx = * fcx. ccx ;
707
681
let mut dcx = dbg_cx ( cx) ;
708
682
let fcx = & mut * fcx;
709
- let sp = fcx. span . get ( ) ;
683
+ let span = fcx. span . get ( ) ;
710
684
711
685
let ( ident, ret_ty, id) = match cx. tcx . items . get_copy ( & fcx. id ) {
712
686
ast_map:: node_item( item, _) => {
@@ -739,7 +713,7 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
739
713
740
714
debug ! ( "create_function: %s, %s" , cx. sess. str_of( ident) , cx. sess. codemap. span_to_str( span) ) ;
741
715
742
- let loc = cx . sess . codemap . lookup_char_pos ( sp . lo ) ;
716
+ let loc = span_start ( cx , span ) ;
743
717
let file_md = create_file ( cx, loc. file . name ) ;
744
718
745
719
let ret_ty_md = if cx. sess . opts . extra_debuginfo {
0 commit comments