@@ -3,12 +3,12 @@ use std::path::{Component, Path};
3
3
4
4
use crate :: prelude:: * ;
5
5
6
- use rustc_span:: { FileName , SourceFileAndLine , Pos } ;
6
+ use rustc_span:: { FileName , SourceFile , SourceFileAndLine , Pos , SourceFileHash , SourceFileHashAlgorithm } ;
7
7
8
8
use cranelift_codegen:: binemit:: CodeOffset ;
9
9
10
10
use gimli:: write:: {
11
- Address , AttributeValue , FileId , LineProgram , LineString , LineStringTable , UnitEntryId ,
11
+ Address , AttributeValue , FileId , LineProgram , LineString , FileInfo , LineStringTable , UnitEntryId ,
12
12
} ;
13
13
14
14
// OPTIMIZATION: It is cheaper to do this in one pass than using `.parent()` and `.file_name()`.
@@ -35,12 +35,28 @@ fn osstr_as_utf8_bytes(path: &OsStr) -> &[u8] {
35
35
}
36
36
}
37
37
38
+ pub ( crate ) const MD5_LEN : usize = 16 ;
39
+
40
+ pub fn make_file_info ( hash : SourceFileHash ) -> Option < FileInfo > {
41
+ if hash. kind == SourceFileHashAlgorithm :: Md5 {
42
+ let mut buf = [ 0u8 ; MD5_LEN ] ;
43
+ buf. copy_from_slice ( hash. hash_bytes ( ) ) ;
44
+ Some ( FileInfo {
45
+ timestamp : 0 ,
46
+ size : 0 ,
47
+ md5 : buf,
48
+ } )
49
+ } else {
50
+ None
51
+ }
52
+ }
53
+
38
54
fn line_program_add_file (
39
55
line_program : & mut LineProgram ,
40
56
line_strings : & mut LineStringTable ,
41
- file : & FileName ,
57
+ file : & SourceFile ,
42
58
) -> FileId {
43
- match file {
59
+ match & file. name {
44
60
FileName :: Real ( path) => {
45
61
let ( dir_path, file_name) = split_path_dir_and_file ( path) ;
46
62
let dir_name = osstr_as_utf8_bytes ( dir_path. as_os_str ( ) ) ;
@@ -57,13 +73,17 @@ fn line_program_add_file(
57
73
line_program. encoding ( ) ,
58
74
line_strings,
59
75
) ;
60
- line_program. add_file ( file_name, dir_id, None )
76
+
77
+ let info = make_file_info ( file. src_hash ) ;
78
+
79
+ line_program. file_has_md5 &= info. is_some ( ) ;
80
+ line_program. add_file ( file_name, dir_id, info)
61
81
}
62
82
// FIXME give more appropriate file names
63
- _ => {
83
+ filename => {
64
84
let dir_id = line_program. default_directory ( ) ;
65
85
let dummy_file_name = LineString :: new (
66
- file . to_string ( ) . into_bytes ( ) ,
86
+ filename . to_string ( ) . into_bytes ( ) ,
67
87
line_program. encoding ( ) ,
68
88
line_strings,
69
89
) ;
@@ -79,7 +99,7 @@ impl<'tcx> DebugContext<'tcx> {
79
99
let file_id = line_program_add_file (
80
100
& mut self . dwarf . unit . line_program ,
81
101
& mut self . dwarf . line_strings ,
82
- & loc. file . name ,
102
+ & loc. file ,
83
103
) ;
84
104
85
105
let entry = self . dwarf . unit . get_mut ( entry_id) ;
@@ -167,7 +187,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
167
187
true
168
188
} ;
169
189
if current_file_changed {
170
- let file_id = line_program_add_file ( line_program, line_strings, & file. name ) ;
190
+ let file_id = line_program_add_file ( line_program, line_strings, & file) ;
171
191
line_program. row ( ) . file = file_id;
172
192
last_file = Some ( file. clone ( ) ) ;
173
193
}
0 commit comments