@@ -54,12 +54,14 @@ def line_entry_mapping(line_program):
54
54
# a reverse mapping of filename -> #entries.
55
55
lp_entries = line_program .get_entries ()
56
56
for lpe in lp_entries :
57
+ if not lpe .state :
58
+ continue
59
+ filename = lpe_filename (line_program , lpe .state .file )
57
60
# We skip LPEs that don't have an associated file.
58
61
# This can happen if instructions in the compiled binary
59
62
# don't correspond directly to any original source file.
60
- if not lpe . state or lpe . state . file == 0 :
63
+ if filename is None :
61
64
continue
62
- filename = lpe_filename (line_program , lpe .state .file )
63
65
filename_map [filename ] += 1
64
66
65
67
for filename , lpe_count in filename_map .items ():
@@ -77,16 +79,24 @@ def lpe_filename(line_program, file_index):
77
79
lp_header = line_program .header
78
80
file_entries = lp_header ["file_entry" ]
79
81
80
- # File and directory indices are 1-indexed.
81
- file_entry = file_entries [file_index - 1 ]
82
+ # File and directory indices are 1-indexed in DWARF version < 5,
83
+ # 0-indexed in DWARF5.
84
+ if lp_header .version < 5 :
85
+ file_index -= 1
86
+ if file_index == - 1 :
87
+ return None
88
+
89
+ file_entry = file_entries [file_index ]
82
90
dir_index = file_entry ["dir_index" ]
83
91
84
92
# A dir_index of 0 indicates that no absolute directory was recorded during
85
- # compilation; return just the basename.
86
- if dir_index == 0 :
93
+ # compilation in DWARF version < 5 ; return just the basename.
94
+ if dir_index == 0 and lp_header . version < 5 :
87
95
return file_entry .name .decode ()
88
96
89
- directory = lp_header ["include_directory" ][dir_index - 1 ]
97
+ if lp_header .version < 5 :
98
+ dir_index -= 1
99
+ directory = lp_header ["include_directory" ][dir_index ]
90
100
return posixpath .join (directory , file_entry .name ).decode ()
91
101
92
102
0 commit comments