1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
use std::mem;
use crate::common::*;
use crate::dbi::Module;
use crate::msf::Stream;
use crate::symbol::SymbolIter;
use crate::FallibleIterator;
mod c13;
mod constants;
#[derive(Clone, Copy, Debug)]
enum LinesSize {
C11(usize),
C13(usize),
}
pub struct ModuleInfo<'s> {
stream: Stream<'s>,
symbols_size: usize,
lines_size: LinesSize,
}
impl<'s> ModuleInfo<'s> {
pub(crate) fn parse(stream: Stream<'s>, module: &Module<'_>) -> Result<Self> {
let info = module.info();
let mut buf = stream.parse_buffer();
if buf.parse_u32()? != constants::CV_SIGNATURE_C13 {
return Err(Error::UnimplementedFeature(
"Unsupported module info format",
));
}
let lines_size = if info.lines_size > 0 {
LinesSize::C11(info.lines_size as usize)
} else {
LinesSize::C13(info.c13_lines_size as usize)
};
let symbols_size = info.symbols_size as usize;
Ok(ModuleInfo {
stream,
symbols_size,
lines_size,
})
}
pub fn symbols(&self) -> Result<SymbolIter<'_>> {
let mut buf = self.stream.parse_buffer();
buf.parse_u32()?;
let symbols = buf.take(self.symbols_size - mem::size_of::<u32>())?;
Ok(SymbolIter::new(symbols.into()))
}
pub fn line_program(&self) -> Result<LineProgram<'_>> {
let start = self.symbols_size as usize;
let inner = match self.lines_size {
LinesSize::C11(_size) => return Err(Error::UnimplementedFeature("C11 line programs")),
LinesSize::C13(size) => {
let data = &self.stream[start..start + size];
LineProgramInner::C13(c13::C13LineProgram::parse(data)?)
}
};
Ok(LineProgram { inner })
}
}
#[derive(Clone, Debug)]
pub enum FileChecksum<'a> {
None,
Md5(&'a [u8]),
Sha1(&'a [u8]),
Sha256(&'a [u8]),
}
impl PartialEq for FileChecksum<'_> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(&FileChecksum::Md5(lhs), &FileChecksum::Md5(rhs)) => lhs == rhs,
(&FileChecksum::Sha1(lhs), &FileChecksum::Sha1(rhs)) => lhs == rhs,
(&FileChecksum::Sha256(lhs), &FileChecksum::Sha256(rhs)) => lhs == rhs,
_ => false,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct FileInfo<'a> {
pub name: StringRef,
pub checksum: FileChecksum<'a>,
}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct FileIndex(pub u32);
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum LineInfoKind {
Expression,
Statement,
}
#[derive(Clone, Debug)]
pub struct LineInfo {
pub offset: PdbInternalSectionOffset,
pub file_index: FileIndex,
pub line_start: u32,
pub line_end: u32,
pub column_start: Option<u16>,
pub column_end: Option<u16>,
pub kind: LineInfoKind,
}
enum LineProgramInner<'a> {
C13(c13::C13LineProgram<'a>),
}
pub struct LineProgram<'a> {
inner: LineProgramInner<'a>,
}
impl<'a> LineProgram<'a> {
pub fn lines(&self) -> LineIterator {
match self.inner {
LineProgramInner::C13(ref inner) => LineIterator {
inner: LineIteratorInner::C13(inner.lines()),
},
}
}
pub fn lines_at_offset(&self, offset: PdbInternalSectionOffset) -> LineIterator {
match self.inner {
LineProgramInner::C13(ref inner) => LineIterator {
inner: LineIteratorInner::C13(inner.lines_at_offset(offset)),
},
}
}
pub fn get_file_info(&self, offset: FileIndex) -> Result<FileInfo<'a>> {
match self.inner {
LineProgramInner::C13(ref inner) => inner.get_file_info(offset),
}
}
}
enum LineIteratorInner<'a> {
C13(c13::C13LineIterator<'a>),
}
pub struct LineIterator<'a> {
inner: LineIteratorInner<'a>,
}
impl<'a> FallibleIterator for LineIterator<'a> {
type Item = LineInfo;
type Error = Error;
fn next(&mut self) -> Result<Option<Self::Item>> {
match self.inner {
LineIteratorInner::C13(ref mut inner) => inner.next(),
}
}
}