Skip to content

Commit 1336411

Browse files
committed
Store Arc<Helper> in SymbolMap.
1 parent 3b831e4 commit 1336411

File tree

13 files changed

+133
-205
lines changed

13 files changed

+133
-205
lines changed

samply-api/src/source/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ impl<'a, H: FileAndPathHelper> SourceApi<'a, H> {
8787
}
8888
FramesLookupResult::Unavailable => return Err(SourceError::NoDebugInfo),
8989
FramesLookupResult::NeedDwo { svma, .. } => {
90-
match symbol_map
91-
.lookup_frames_async(svma, self.symbol_manager.helper())
92-
.await
93-
{
90+
match symbol_map.lookup_frames_async(svma).await {
9491
Some(frames) => frames,
9592
None => return Err(SourceError::NoDebugInfo),
9693
}

samply-api/src/symbolicate/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ impl<'a, H: FileAndPathHelper> SymbolicateApi<'a, H> {
132132
}
133133

134134
for (address, svma, _) in external_addresses_dwo {
135-
if let Some(frames) = symbol_map
136-
.lookup_frames_async(svma, self.symbol_manager.helper())
137-
.await
138-
{
135+
if let Some(frames) = symbol_map.lookup_frames_async(svma).await {
139136
symbolication_result.add_address_debug_info(address, frames);
140137
}
141138
}

samply-symbols/src/breakpad/symbol_map.rs

+15-53
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use yoke_derive::Yokeable;
99

1010
use crate::{
1111
symbol_map::{GetInnerSymbolMap, SymbolMapTrait},
12-
AddressInfo, Error, FileContents, FileContentsWrapper, FileLocation, FrameDebugInfo,
13-
FramesLookupResult, SourceFilePath, SymbolInfo, SymbolMap,
12+
AddressInfo, Error, FileContents, FileContentsWrapper, FrameDebugInfo, FramesLookupResult,
13+
SourceFilePath, SymbolInfo,
1414
};
1515

1616
use super::index::{
@@ -19,20 +19,15 @@ use super::index::{
1919
BreakpadSymbolType, FileOrInlineOrigin, ItemMap,
2020
};
2121

22-
pub fn get_symbol_map_for_breakpad_sym<F, FL>(
23-
file_contents: FileContentsWrapper<F>,
24-
file_location: FL,
25-
index_file_contents: Option<FileContentsWrapper<F>>,
26-
) -> Result<SymbolMap<FL, F>, Error>
27-
where
28-
F: FileContents + 'static,
29-
FL: FileLocation,
30-
{
22+
pub fn get_symbol_map_for_breakpad_sym<FC: FileContents + 'static>(
23+
file_contents: FileContentsWrapper<FC>,
24+
index_file_contents: Option<FileContentsWrapper<FC>>,
25+
) -> Result<BreakpadSymbolMap<FC>, Error> {
3126
let outer = BreakpadSymbolMapOuter::new(file_contents, index_file_contents)?;
3227
let symbol_map = BreakpadSymbolMap(Yoke::attach_to_cart(Box::new(outer), |outer| {
3328
outer.make_symbol_map()
3429
}));
35-
Ok(SymbolMap::new_without(file_location, Box::new(symbol_map)))
30+
Ok(symbol_map)
3631
}
3732

3833
pub struct BreakpadSymbolMap<T: FileContents + 'static>(
@@ -333,51 +328,16 @@ impl<'a, T: FileContents> SymbolMapTrait for BreakpadSymbolMapInner<'a, T> {
333328
mod test {
334329
use debugid::DebugId;
335330

336-
use crate::DwoRef;
337-
338331
use super::*;
339332

340-
#[derive(Clone)]
341-
struct DummyLocation;
342-
343-
impl FileLocation for DummyLocation {
344-
fn location_for_dyld_subcache(&self, _suffix: &str) -> Option<Self> {
345-
None
346-
}
347-
348-
fn location_for_external_object_file(&self, _object_file: &str) -> Option<Self> {
349-
None
350-
}
351-
352-
fn location_for_pdb_from_binary(&self, _pdb_path: &str) -> Option<Self> {
353-
None
354-
}
355-
356-
fn location_for_source_file(&self, _source_file_path: &str) -> Option<Self> {
357-
None
358-
}
359-
360-
fn location_for_breakpad_symindex(&self) -> Option<Self> {
361-
None
362-
}
363-
364-
fn location_for_dwo(&self, _dwo_ref: &DwoRef) -> Option<Self> {
365-
None
366-
}
367-
}
368-
impl std::fmt::Display for DummyLocation {
369-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
370-
"DummyLocation".fmt(f)
371-
}
372-
}
373-
374333
#[test]
375334
fn overeager_demangle() {
376335
let sym = b"MODULE Linux x86_64 BE4E976C325246EE9D6B7847A670B2A90 example-linux\nFILE 0 filename\nFUNC 1160 45 0 f\n1160 c 16 0";
377336
let fc = FileContentsWrapper::new(&sym[..]);
378-
let symbol_map = get_symbol_map_for_breakpad_sym(fc, DummyLocation, None).unwrap();
337+
let symbol_map = get_symbol_map_for_breakpad_sym(fc, None).unwrap();
379338
assert_eq!(
380339
symbol_map
340+
.get_inner_symbol_map()
381341
.lookup_relative_address(0x1160)
382342
.unwrap()
383343
.symbol
@@ -416,15 +376,17 @@ mod test {
416376
let full_sym_contents = data_slices.concat();
417377
let sym_fc = FileContentsWrapper::new(full_sym_contents);
418378
let symindex_fc = FileContentsWrapper::new(index_bytes);
419-
let symbol_map =
420-
get_symbol_map_for_breakpad_sym(sym_fc, DummyLocation, Some(symindex_fc)).unwrap();
379+
let symbol_map = get_symbol_map_for_breakpad_sym(sym_fc, Some(symindex_fc)).unwrap();
421380

422381
assert_eq!(
423-
symbol_map.debug_id(),
382+
symbol_map.get_inner_symbol_map().debug_id(),
424383
DebugId::from_breakpad("F1E853FD662672044C4C44205044422E1").unwrap()
425384
);
426385

427-
let lookup_result = symbol_map.lookup_relative_address(0x2b7ed).unwrap();
386+
let lookup_result = symbol_map
387+
.get_inner_symbol_map()
388+
.lookup_relative_address(0x2b7ed)
389+
.unwrap();
428390
assert_eq!(
429391
lookup_result.symbol.name,
430392
"DloadAcquireSectionWriteAccess()"

samply-symbols/src/compact_symbol_table.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{FileContents, FileLocation, SymbolMap};
1+
use crate::{FileAndPathHelper, SymbolMap};
22

33
/// A "compact" representation of a symbol table.
44
/// This is a legacy concept used by the Firefox profiler and kept for
@@ -22,7 +22,7 @@ pub struct CompactSymbolTable {
2222
}
2323

2424
impl CompactSymbolTable {
25-
pub fn from_symbol_map<FL: FileLocation, FC: FileContents>(map: &SymbolMap<FL, FC>) -> Self {
25+
pub fn from_symbol_map<H: FileAndPathHelper>(map: &SymbolMap<H>) -> Self {
2626
let total_str_len = map.iter_symbols().map(|(_, s)| s.len()).sum();
2727
let mut addr = Vec::with_capacity(map.symbol_count());
2828
let mut index = Vec::with_capacity(map.symbol_count() + 1);

samply-symbols/src/elf.rs

+29-33
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use elsa::sync::FrozenVec;
33
use gimli::{CieOrFde, Dwarf, EhFrame, EndianSlice, RunTimeEndian, UnwindSection};
44
use object::{File, FileKind, Object, ObjectSection, ReadRef};
55
use std::io::Cursor;
6+
use std::sync::Arc;
67
use yoke::Yoke;
78
use yoke_derive::Yokeable;
89

910
use crate::dwarf::Addr2lineContextData;
1011
use crate::error::Error;
11-
use crate::shared::{FileAndPathHelper, FileContents, FileContentsWrapper, FileLocation};
12+
use crate::shared::{FileAndPathHelper, FileContents, FileContentsWrapper};
1213
use crate::symbol_map::SymbolMap;
1314
use crate::symbol_map_object::{
1415
AddDwoAndMakeDwarf, ObjectSymbolMap, ObjectSymbolMapInner, ObjectSymbolMapOuter,
@@ -17,28 +18,23 @@ use crate::symbol_map_object::{
1718
};
1819
use crate::{debug_id_for_object, ElfBuildId};
1920

20-
pub async fn load_symbol_map_for_elf<T, FL, H>(
21-
file_location: FL,
22-
file_contents: FileContentsWrapper<T>,
21+
pub async fn load_symbol_map_for_elf<H: FileAndPathHelper>(
22+
file_location: H::FL,
23+
file_contents: FileContentsWrapper<H::F>,
2324
file_kind: FileKind,
24-
helper: &H,
25-
) -> Result<SymbolMap<FL, T>, Error>
26-
where
27-
T: FileContents + 'static,
28-
H: FileAndPathHelper<F = T, FL = FL>,
29-
FL: FileLocation,
30-
{
25+
helper: Arc<H>,
26+
) -> Result<SymbolMap<H>, Error> {
3127
let elf_file =
3228
File::parse(&file_contents).map_err(|e| Error::ObjectParseError(file_kind, e))?;
3329

3430
if let Some(symbol_map) =
35-
try_to_get_symbol_map_from_debug_link(&file_location, &elf_file, file_kind, helper).await
31+
try_to_get_symbol_map_from_debug_link(&file_location, &elf_file, file_kind, &*helper).await
3632
{
3733
return Ok(symbol_map);
3834
}
3935

4036
if let Some(supplementary_file) =
41-
try_to_load_supplementary_file(&file_location, &elf_file, helper).await
37+
try_to_load_supplementary_file(&file_location, &elf_file, &*helper).await
4238
{
4339
let owner = ElfSymbolMapDataAndObjects::new(
4440
file_contents,
@@ -47,7 +43,7 @@ where
4743
None,
4844
)?;
4945
let symbol_map = ObjectSymbolMap::new(owner)?;
50-
return Ok(SymbolMap::new_without(file_location, Box::new(symbol_map)));
46+
return Ok(SymbolMap::new_plain(file_location, Box::new(symbol_map)));
5147
}
5248

5349
// If this file has a .gnu_debugdata section, use the uncompressed object from that section instead.
@@ -59,20 +55,22 @@ where
5955

6056
let owner = ElfSymbolMapDataAndObjects::new(file_contents, None, file_kind, None)?;
6157
let symbol_map = ObjectSymbolMapWithDwoSupport::new(owner)?;
62-
Ok(SymbolMap::new_with(file_location, Box::new(symbol_map)))
58+
Ok(SymbolMap::new_with(
59+
file_location,
60+
Box::new(symbol_map),
61+
helper,
62+
))
6363
}
6464

65-
async fn try_to_get_symbol_map_from_debug_link<'data, H, R, FL, FC>(
66-
original_file_location: &FL,
65+
async fn try_to_get_symbol_map_from_debug_link<'data, H, R>(
66+
original_file_location: &H::FL,
6767
elf_file: &File<'data, R>,
6868
file_kind: FileKind,
6969
helper: &H,
70-
) -> Option<SymbolMap<FL, FC>>
70+
) -> Option<SymbolMap<H>>
7171
where
72-
H: FileAndPathHelper<FL = FL, F = FC>,
7372
R: ReadRef<'data>,
74-
FL: FileLocation,
75-
FC: FileContents + 'static,
73+
H: FileAndPathHelper,
7674
{
7775
let (name, crc) = elf_file.gnu_debuglink().ok().flatten()?;
7876
let debug_id = debug_id_for_object(elf_file)?;
@@ -99,18 +97,16 @@ where
9997
None
10098
}
10199

102-
async fn get_symbol_map_for_debug_link_candidate<H, FL, FC>(
103-
original_file_location: &FL,
104-
path: &FL,
100+
async fn get_symbol_map_for_debug_link_candidate<H>(
101+
original_file_location: &H::FL,
102+
path: &H::FL,
105103
debug_id: DebugId,
106104
expected_crc: u32,
107105
file_kind: FileKind,
108106
helper: &H,
109-
) -> Result<SymbolMap<FL, FC>, Error>
107+
) -> Result<SymbolMap<H>, Error>
110108
where
111-
H: FileAndPathHelper<FL = FL, F = FC>,
112-
FL: FileLocation,
113-
FC: FileContents + 'static,
109+
H: FileAndPathHelper,
114110
{
115111
let file_contents = helper
116112
.load_file(path.clone())
@@ -125,7 +121,7 @@ where
125121

126122
let owner = ElfSymbolMapDataAndObjects::new(file_contents, None, file_kind, Some(debug_id))?;
127123
let symbol_map = ObjectSymbolMap::new(owner)?;
128-
Ok(SymbolMap::new_without(
124+
Ok(SymbolMap::new_plain(
129125
original_file_location.clone(),
130126
Box::new(symbol_map),
131127
))
@@ -268,11 +264,11 @@ where
268264
None
269265
}
270266

271-
fn try_get_symbol_map_from_mini_debug_info<'data, R: ReadRef<'data>, FL: FileLocation, FC>(
267+
fn try_get_symbol_map_from_mini_debug_info<'data, R: ReadRef<'data>, H: FileAndPathHelper>(
272268
elf_file: &File<'data, R>,
273269
file_kind: FileKind,
274-
debug_file_location: &FL,
275-
) -> Option<SymbolMap<FL, FC>> {
270+
debug_file_location: &H::FL,
271+
) -> Option<SymbolMap<H>> {
276272
let debugdata = elf_file.section_by_name(".gnu_debugdata")?;
277273
let data = debugdata.data().ok()?;
278274
let mut cursor = Cursor::new(data);
@@ -281,7 +277,7 @@ fn try_get_symbol_map_from_mini_debug_info<'data, R: ReadRef<'data>, FL: FileLoc
281277
let file_contents = FileContentsWrapper::new(objdata);
282278
let owner = ElfSymbolMapDataAndObjects::new(file_contents, None, file_kind, None).ok()?;
283279
let symbol_map = ObjectSymbolMap::new(owner).ok()?;
284-
Some(SymbolMap::new_without(
280+
Some(SymbolMap::new_plain(
285281
debug_file_location.clone(),
286282
Box::new(symbol_map),
287283
))

samply-symbols/src/jitdump.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ use std::{
1515

1616
use crate::error::Error;
1717
use crate::shared::{
18-
AddressInfo, FileContents, FileContentsCursor, FileContentsWrapper, FileLocation,
19-
FrameDebugInfo, FramesLookupResult, SourceFilePath, SymbolInfo,
18+
AddressInfo, FileContents, FileContentsCursor, FileContentsWrapper, FrameDebugInfo,
19+
FramesLookupResult, SourceFilePath, SymbolInfo,
2020
};
2121
use crate::symbol_map::{GetInnerSymbolMap, SymbolMap, SymbolMapTrait};
22+
use crate::FileAndPathHelper;
2223

2324
pub fn is_jitdump_file<T: FileContents>(file_contents: &FileContentsWrapper<T>) -> bool {
2425
const MAGIC_BYTES_BE: &[u8] = b"JiTD";
@@ -162,19 +163,15 @@ pub struct JitDumpIndexEntry {
162163
pub code_bytes_len: u64,
163164
}
164165

165-
pub fn get_symbol_map_for_jitdump<F, FL>(
166-
file_contents: FileContentsWrapper<F>,
167-
file_location: FL,
168-
) -> Result<SymbolMap<FL, F>, Error>
169-
where
170-
F: FileContents + 'static,
171-
FL: FileLocation,
172-
{
166+
pub fn get_symbol_map_for_jitdump<H: FileAndPathHelper>(
167+
file_contents: FileContentsWrapper<H::F>,
168+
file_location: H::FL,
169+
) -> Result<SymbolMap<H>, Error> {
173170
let outer = JitDumpSymbolMapOuter::new(file_contents)?;
174171
let symbol_map = JitDumpSymbolMap(Yoke::attach_to_cart(Box::new(outer), |outer| {
175172
outer.make_symbol_map()
176173
}));
177-
Ok(SymbolMap::new_without(file_location, Box::new(symbol_map)))
174+
Ok(SymbolMap::new_plain(file_location, Box::new(symbol_map)))
178175
}
179176

180177
pub struct JitDumpSymbolMap<T: FileContents>(

0 commit comments

Comments
 (0)