1
1
use std:: ffi:: OsStr ;
2
+ use std:: time:: SystemTime ;
2
3
use std:: path:: { Component , Path } ;
3
4
4
5
use crate :: prelude:: * ;
5
6
6
- use rustc_span:: { FileName , SourceFileAndLine , Pos } ;
7
+ use rustc_span:: { FileName , SourceFile , SourceFileAndLine , Pos , SourceFileHash , SourceFileHashAlgorithm } ;
7
8
8
9
use cranelift_codegen:: binemit:: CodeOffset ;
9
10
10
11
use gimli:: write:: {
11
- Address , AttributeValue , FileId , LineProgram , LineString , LineStringTable , UnitEntryId ,
12
+ Address , AttributeValue , FileId , LineProgram , LineString , FileInfo , LineStringTable , UnitEntryId ,
12
13
} ;
13
14
14
15
// OPTIMIZATION: It is cheaper to do this in one pass than using `.parent()` and `.file_name()`.
@@ -38,9 +39,9 @@ fn osstr_as_utf8_bytes(path: &OsStr) -> &[u8] {
38
39
fn line_program_add_file (
39
40
line_program : & mut LineProgram ,
40
41
line_strings : & mut LineStringTable ,
41
- file : & FileName ,
42
+ file : & SourceFile ,
42
43
) -> FileId {
43
- match file {
44
+ match & file. name {
44
45
FileName :: Real ( path) => {
45
46
let ( dir_path, file_name) = split_path_dir_and_file ( path) ;
46
47
let dir_name = osstr_as_utf8_bytes ( dir_path. as_os_str ( ) ) ;
@@ -57,13 +58,32 @@ fn line_program_add_file(
57
58
line_program. encoding ( ) ,
58
59
line_strings,
59
60
) ;
60
- line_program. add_file ( file_name, dir_id, None )
61
+
62
+ let md5 = Some ( file. src_hash )
63
+ . filter ( |h| matches ! ( h, SourceFileHash { kind: SourceFileHashAlgorithm :: Md5 , .. } ) )
64
+ . map ( |h| {
65
+ let mut buf = [ 0u8 ; super :: MD5_LEN ] ;
66
+ buf. copy_from_slice ( h. hash_bytes ( ) ) ;
67
+ buf
68
+ } ) ;
69
+
70
+ line_program. file_has_timestamp = true ;
71
+ line_program. file_has_md5 = md5. is_some ( ) ;
72
+
73
+ line_program. add_file ( file_name, dir_id, Some ( FileInfo {
74
+ timestamp : SystemTime :: now ( )
75
+ . duration_since ( SystemTime :: UNIX_EPOCH )
76
+ . map ( |t| t. as_secs ( ) )
77
+ . unwrap_or ( 0 ) ,
78
+ size : 0 ,
79
+ md5 : md5. unwrap_or_default ( ) ,
80
+ } ) )
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