1
+ import std:: map;
1
2
import std:: map:: hashmap;
2
3
import lib:: llvm:: llvm;
3
4
import lib:: llvm:: ValueRef ;
@@ -17,6 +18,7 @@ export create_function;
17
18
export create_arg;
18
19
export update_source_pos;
19
20
export debug_ctxt;
21
+ export mk_ctxt;
20
22
21
23
const LLVMDebugVersion : int = ( 9 << 16 ) ;
22
24
@@ -75,18 +77,24 @@ fn llnull() -> ValueRef unsafe {
75
77
76
78
fn add_named_metadata ( cx : @crate_ctxt , name : str , val : ValueRef ) {
77
79
str:: as_c_str ( name, { |sbuf|
78
- llvm:: LLVMAddNamedMetadataOperand ( cx. llmod , sbuf,
79
- val)
80
+ llvm:: LLVMAddNamedMetadataOperand ( cx. llmod , sbuf, val)
80
81
} )
81
82
}
82
83
83
84
////////////////
84
85
85
86
type debug_ctxt = {
86
87
llmetadata : metadata_cache ,
87
- names : namegen
88
+ names : namegen ,
89
+ crate_file : str
88
90
} ;
89
91
92
+ fn mk_ctxt ( crate : str ) -> debug_ctxt {
93
+ { llmetadata: map:: int_hash ( ) ,
94
+ names: new_namegen ( ) ,
95
+ crate_file: crate }
96
+ }
97
+
90
98
fn update_cache ( cache : metadata_cache , mdtag : int , val : debug_metadata ) {
91
99
let existing = if cache. contains_key ( mdtag) {
92
100
cache. get ( mdtag)
@@ -99,7 +107,7 @@ fn update_cache(cache: metadata_cache, mdtag: int, val: debug_metadata) {
99
107
type metadata < T > = { node : ValueRef , data : T } ;
100
108
101
109
type file_md = { path: str } ;
102
- type compile_unit_md = { path : str } ;
110
+ type compile_unit_md = { name : str } ;
103
111
type subprogram_md = { id : ast:: node_id } ;
104
112
type local_var_md = { id : ast:: node_id } ;
105
113
type tydesc_md = { hash : uint } ;
@@ -154,48 +162,51 @@ fn cached_metadata<T: copy>(cache: metadata_cache, mdtag: int,
154
162
ret option:: none;
155
163
}
156
164
157
- fn create_compile_unit ( cx : @crate_ctxt , full_path : str )
165
+ fn create_compile_unit ( cx : @crate_ctxt )
158
166
-> @metadata < compile_unit_md > unsafe {
159
167
let cache = get_cache ( cx) ;
168
+ let crate_name = option:: get ( cx. dbg_cx ) . crate_file ;
160
169
let tg = CompileUnitTag ;
161
170
alt cached_metadata :: < @metadata < compile_unit_md > > ( cache, tg,
162
- { |md| md. data . path == full_path } ) {
171
+ { |md| md. data . name == crate_name } ) {
163
172
option:: some ( md) { ret md; }
164
173
option:: none { }
165
174
}
166
175
167
- let work_dir = cx. sess . working_dir ;
168
- let file_path = if str:: starts_with ( full_path, work_dir) {
169
- str:: slice ( full_path, str:: len ( work_dir) , str:: len ( full_path) )
170
- } else {
171
- full_path
172
- } ;
176
+ let ( _, work_dir) = get_file_path_and_dir ( cx. sess . working_dir ,
177
+ crate_name) ;
173
178
let unit_metadata = [ lltag ( tg) ,
174
179
llunused ( ) ,
175
180
lli32 ( DW_LANG_RUST ) ,
176
- llstr ( file_path ) ,
181
+ llstr ( crate_name ) ,
177
182
llstr ( work_dir) ,
178
183
llstr ( #env[ "CFG_VERSION" ] ) ,
179
- lli1 ( false ) , // main compile unit
184
+ lli1 ( true ) , // deprecated: main compile unit
180
185
lli1 ( cx. sess . opts . optimize != 0 u) ,
181
186
llstr ( "" ) , // flags (???)
182
187
lli32 ( 0 ) // runtime version (???)
183
- // list of enum types
184
- // list of retained values
185
- // list of subprograms
186
- // list of global variables
187
188
] ;
188
189
let unit_node = llmdnode ( unit_metadata) ;
189
190
add_named_metadata ( cx, "llvm.dbg.cu" , unit_node) ;
190
- let mdval = @{ node: unit_node, data : { path : full_path } } ;
191
+ let mdval = @{ node: unit_node, data : { name : crate_name } } ;
191
192
update_cache ( cache, tg, compile_unit_metadata ( mdval) ) ;
193
+
192
194
ret mdval;
193
195
}
194
196
195
197
fn get_cache ( cx : @crate_ctxt ) -> metadata_cache {
196
198
option:: get ( cx. dbg_cx ) . llmetadata
197
199
}
198
200
201
+ fn get_file_path_and_dir ( work_dir : str , full_path : str ) -> ( str , str ) {
202
+ ( if str:: starts_with ( full_path, work_dir) {
203
+ str:: slice ( full_path, str:: len ( work_dir) + 1 u,
204
+ str:: len ( full_path) )
205
+ } else {
206
+ full_path
207
+ } , work_dir)
208
+ }
209
+
199
210
fn create_file ( cx : @crate_ctxt , full_path : str ) -> @metadata < file_md > {
200
211
let cache = get_cache ( cx) ; ;
201
212
let tg = FileDescriptorTag ;
@@ -205,12 +216,12 @@ fn create_file(cx: @crate_ctxt, full_path: str) -> @metadata<file_md> {
205
216
option:: none { }
206
217
}
207
218
208
- let fname = path :: basename ( full_path ) ;
209
- let path = path :: dirname ( full_path) ;
210
- let unit_node = create_compile_unit ( cx, full_path ) . node ;
219
+ let ( file_path , work_dir ) = get_file_path_and_dir ( cx . sess . working_dir ,
220
+ full_path) ;
221
+ let unit_node = create_compile_unit ( cx) . node ;
211
222
let file_md = [ lltag ( tg) ,
212
- llstr ( fname ) ,
213
- llstr ( path ) ,
223
+ llstr ( file_path ) ,
224
+ llstr ( work_dir ) ,
214
225
unit_node] ;
215
226
let val = llmdnode ( file_md) ;
216
227
let mdval = @{ node: val, data : { path : full_path} } ;
@@ -310,7 +321,7 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: ast::prim_ty, span: span)
310
321
311
322
let fname = filename_from_span ( cx, span) ;
312
323
let file_node = create_file ( cx, fname) ;
313
- let cu_node = create_compile_unit ( cx, fname ) ;
324
+ let cu_node = create_compile_unit ( cx) ;
314
325
let ( size, align) = size_and_align_of ( cx, t) ;
315
326
let lldata = [ lltag ( tg) ,
316
327
cu_node. node ,
@@ -463,7 +474,7 @@ fn create_composite_type(type_tag: int, name: str, file: ValueRef, line: int,
463
474
lli32 ( line) , // source line definition
464
475
lli64 ( size) , // size of members
465
476
lli64 ( align) , // align
466
- lli64 ( offset) , // offset
477
+ lli32 /*64*/ ( offset) , // offset
467
478
lli32 ( 0 ) , // flags
468
479
if option:: is_none ( derived) {
469
480
llnull ( )
@@ -781,13 +792,9 @@ fn create_function(fcx: fn_ctxt) -> @metadata<subprogram_md> {
781
792
option:: none { }
782
793
}
783
794
784
- let path = path_str ( fcx. path ) ;
785
-
786
795
let loc = codemap:: lookup_char_pos ( cx. sess . codemap ,
787
796
sp. lo ) ;
788
797
let file_node = create_file ( cx, loc. file . name ) . node ;
789
- let key = if cx. item_symbols . contains_key ( fcx. id ) { fcx. id } else { id } ;
790
- let mangled = cx. item_symbols . get ( key) ;
791
798
let ty_node = if cx. sess . opts . extra_debuginfo {
792
799
alt ret_ty. node {
793
800
ast:: ty_nil { llnull( ) }
@@ -804,17 +811,17 @@ fn create_function(fcx: fn_ctxt) -> @metadata<subprogram_md> {
804
811
llunused ( ) ,
805
812
file_node,
806
813
llstr ( ident) ,
807
- llstr ( path ) , //XXX fully-qualified C++ name
808
- llstr ( mangled ) , //XXX MIPS name?????
814
+ llstr ( ident ) , //XXX fully-qualified C++ name
815
+ llstr ( "" ) , //XXX MIPS name?????
809
816
file_node,
810
817
lli32 ( loc. line as int ) ,
811
818
sub_node,
812
819
lli1 ( false ) , //XXX static (check export)
813
- lli1 ( true ) , // not extern
820
+ lli1 ( true ) , // defined in compilation unit
814
821
lli32 ( DW_VIRTUALITY_none ) , // virtual-ness
815
822
lli32 ( 0 i) , //index into virt func
816
- llnull ( ) , // base type with vtbl
817
- lli1 ( false ) , // artificial
823
+ /* llnull()*/ lli32 ( 0 ) , // base type with vtbl
824
+ lli32 ( 256 ) , // flags
818
825
lli1 ( cx. sess . opts . optimize != 0 u) ,
819
826
fcx. llfn
820
827
//list of template params
@@ -825,5 +832,6 @@ fn create_function(fcx: fn_ctxt) -> @metadata<subprogram_md> {
825
832
add_named_metadata ( cx, "llvm.dbg.sp" , val) ;
826
833
let mdval = @{ node: val, data : { id : id} } ;
827
834
update_cache ( cache, SubprogramTag , subprogram_metadata ( mdval) ) ;
835
+
828
836
ret mdval;
829
837
}
0 commit comments