Skip to content

Commit 68147ad

Browse files
authored
feat: Added debug IDs to source bundle javascript files (#762)
1 parent 9e55fec commit 68147ad

File tree

10 files changed

+424
-84
lines changed

10 files changed

+424
-84
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
**Features**:
6+
7+
- Added debug IDs to source bundle JavaScript files and source maps. ([#762](https://github.com/getsentry/symbolic/pull/762))
8+
59
**Breaking changes**:
610

711
- Change `DebugSession::source_by_path()` to return `SourceCode` enum with either file content or a URL to fetch it from. ([#758](https://github.com/getsentry/symbolic/pull/758))

symbolic-debuginfo/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ sourcebundle = [
7070
"regex",
7171
"serde_json",
7272
"zip",
73+
"debugid/serde"
7374
]
7475
# WASM processing
7576
wasm = ["bitvec", "dwarf", "wasmparser"]
7677

7778
[dependencies]
7879
bitvec = { version = "1.0.0", optional = true, features = ["alloc"] }
7980
dmsort = "1.0.1"
81+
debugid = { version = "0.8.0" }
8082
elementtree = { version = "1.2.2", optional = true }
8183
elsa = { version = "1.4.0", optional = true }
8284
fallible-iterator = "0.2.0"

symbolic-debuginfo/src/base.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use std::str::FromStr;
66

77
use symbolic_common::{clean_path, join_path, Arch, CodeId, DebugId, Name};
88

9+
use crate::sourcebundle::SourceFileDescriptor;
10+
911
pub(crate) trait Parse<'data>: Sized {
1012
type Error;
1113

@@ -670,17 +672,6 @@ impl fmt::Debug for Function<'_> {
670672
/// A dynamically dispatched iterator over items with the given lifetime.
671673
pub type DynIterator<'a, T> = Box<dyn Iterator<Item = T> + 'a>;
672674

673-
/// Represents a source file referenced by a debug information object file.
674-
#[non_exhaustive]
675-
#[derive(Debug, Clone)]
676-
pub enum SourceCode<'a> {
677-
/// Verbatim source code/file contents.
678-
Content(Cow<'a, str>),
679-
680-
/// Url (usually https) where the content can be fetched from.
681-
Url(Cow<'a, str>),
682-
}
683-
684675
/// A stateful session for interfacing with debug information.
685676
///
686677
/// Debug sessions can be obtained via [`ObjectLike::debug_session`]. Since computing a session may
@@ -728,8 +719,10 @@ pub trait DebugSession<'session> {
728719
fn files(&'session self) -> Self::FileIterator;
729720

730721
/// Looks up a file's source by its full canonicalized path.
731-
/// Returns either source contents, if it was embedded, or a source link.
732-
fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error>;
722+
///
723+
/// Returns a descriptor that has all the information available of the source. It can
724+
/// either contain the source contents directly, if it was embedded, or a source link.
725+
fn source_by_path(&self, path: &str) -> Result<Option<SourceFileDescriptor<'_>>, Self::Error>;
733726
}
734727

735728
/// An object containing debug information.

symbolic-debuginfo/src/breakpad.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use symbolic_common::{Arch, AsSelf, CodeId, DebugId, Language, Name, NameManglin
1313

1414
use crate::base::*;
1515
use crate::function_builder::FunctionBuilder;
16+
use crate::sourcebundle::SourceFileDescriptor;
1617
use crate::Parse;
1718

1819
#[derive(Clone, Debug)]
@@ -1277,7 +1278,10 @@ impl<'data> BreakpadDebugSession<'data> {
12771278
}
12781279

12791280
/// See [DebugSession::source_by_path] for more information.
1280-
pub fn source_by_path(&self, _path: &str) -> Result<Option<SourceCode<'_>>, BreakpadError> {
1281+
pub fn source_by_path(
1282+
&self,
1283+
_path: &str,
1284+
) -> Result<Option<SourceFileDescriptor<'_>>, BreakpadError> {
12811285
Ok(None)
12821286
}
12831287
}
@@ -1295,7 +1299,7 @@ impl<'data, 'session> DebugSession<'session> for BreakpadDebugSession<'data> {
12951299
self.files()
12961300
}
12971301

1298-
fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error> {
1302+
fn source_by_path(&self, path: &str) -> Result<Option<SourceFileDescriptor<'_>>, Self::Error> {
12991303
self.source_by_path(path)
13001304
}
13011305
}

symbolic-debuginfo/src/dwarf.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::base::*;
2929
use crate::function_builder::FunctionBuilder;
3030
#[cfg(feature = "macho")]
3131
use crate::macho::BcSymbolMap;
32+
use crate::sourcebundle::SourceFileDescriptor;
3233

3334
/// This is a fake BcSymbolMap used when macho support is turned off since they are unfortunately
3435
/// part of the dwarf interface
@@ -1332,7 +1333,10 @@ impl<'data> DwarfDebugSession<'data> {
13321333
}
13331334

13341335
/// See [DebugSession::source_by_path] for more information.
1335-
pub fn source_by_path(&self, _path: &str) -> Result<Option<SourceCode<'_>>, DwarfError> {
1336+
pub fn source_by_path(
1337+
&self,
1338+
_path: &str,
1339+
) -> Result<Option<SourceFileDescriptor<'_>>, DwarfError> {
13361340
Ok(None)
13371341
}
13381342
}
@@ -1350,7 +1354,7 @@ impl<'data, 'session> DebugSession<'session> for DwarfDebugSession<'data> {
13501354
self.files()
13511355
}
13521356

1353-
fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error> {
1357+
fn source_by_path(&self, path: &str) -> Result<Option<SourceFileDescriptor<'_>>, Self::Error> {
13541358
self.source_by_path(path)
13551359
}
13561360
}

symbolic-debuginfo/src/object.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,10 @@ impl<'d> ObjectDebugSession<'d> {
484484

485485
/// Looks up a file's source by its full canonicalized path.
486486
/// Returns either source contents, if it was embedded, or a source link.
487-
pub fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, ObjectError> {
487+
pub fn source_by_path(
488+
&self,
489+
path: &str,
490+
) -> Result<Option<SourceFileDescriptor<'_>>, ObjectError> {
488491
match *self {
489492
ObjectDebugSession::Breakpad(ref s) => {
490493
s.source_by_path(path).map_err(ObjectError::transparent)
@@ -518,7 +521,7 @@ impl<'session> DebugSession<'session> for ObjectDebugSession<'_> {
518521
self.files()
519522
}
520523

521-
fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error> {
524+
fn source_by_path(&self, path: &str) -> Result<Option<SourceFileDescriptor<'_>>, Self::Error> {
522525
self.source_by_path(path)
523526
}
524527
}

symbolic-debuginfo/src/pdb.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use symbolic_common::{
2424

2525
use crate::base::*;
2626
use crate::function_stack::FunctionStack;
27+
use crate::sourcebundle::SourceFileDescriptor;
2728
use crate::Parse;
2829

2930
type Pdb<'data> = pdb::PDB<'data, Cursor<&'data [u8]>>;
@@ -638,7 +639,10 @@ impl<'d> PdbDebugSession<'d> {
638639
}
639640

640641
/// See [DebugSession::source_by_path] for more information.
641-
pub fn source_by_path(&self, _path: &str) -> Result<Option<SourceCode<'_>>, PdbError> {
642+
pub fn source_by_path(
643+
&self,
644+
_path: &str,
645+
) -> Result<Option<SourceFileDescriptor<'_>>, PdbError> {
642646
Ok(None)
643647
}
644648
}
@@ -656,7 +660,7 @@ impl<'session> DebugSession<'session> for PdbDebugSession<'_> {
656660
self.files()
657661
}
658662

659-
fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error> {
663+
fn source_by_path(&self, path: &str) -> Result<Option<SourceFileDescriptor<'_>>, Self::Error> {
660664
self.source_by_path(path)
661665
}
662666
}

symbolic-debuginfo/src/ppdb.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use symbolic_ppdb::EmbeddedSource;
1010
use symbolic_ppdb::{Document, FormatError, PortablePdb};
1111

1212
use crate::base::*;
13+
use crate::sourcebundle::SourceFileDescriptor;
1314

1415
/// An iterator over symbols in a [`PortablePdbObject`].
1516
pub type PortablePdbSymbolIterator<'data> = iter::Empty<Symbol<'data>>;
@@ -191,16 +192,23 @@ impl<'data> PortablePdbDebugSession<'data> {
191192
}
192193

193194
/// See [DebugSession::source_by_path] for more information.
194-
pub fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, FormatError> {
195+
pub fn source_by_path(
196+
&self,
197+
path: &str,
198+
) -> Result<Option<SourceFileDescriptor<'_>>, FormatError> {
195199
let sources = self.sources.borrow_with(|| self.init_sources());
196200
match sources.get(path) {
197201
None => Ok(None),
198-
Some(PPDBSource::Embedded(source)) => source
199-
.get_contents()
200-
.map(|bytes| Some(SourceCode::Content(from_utf8_cow_lossy(&bytes)))),
201-
Some(PPDBSource::Link(document)) => {
202-
Ok(self.ppdb.get_source_link(document).map(SourceCode::Url))
203-
}
202+
Some(PPDBSource::Embedded(source)) => source.get_contents().map(|bytes| {
203+
Some(SourceFileDescriptor::new_embedded(
204+
from_utf8_cow_lossy(&bytes),
205+
None,
206+
))
207+
}),
208+
Some(PPDBSource::Link(document)) => Ok(self
209+
.ppdb
210+
.get_source_link(document)
211+
.map(SourceFileDescriptor::new_remote)),
204212
}
205213
}
206214
}
@@ -218,7 +226,7 @@ impl<'data, 'session> DebugSession<'session> for PortablePdbDebugSession<'data>
218226
self.files()
219227
}
220228

221-
fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error> {
229+
fn source_by_path(&self, path: &str) -> Result<Option<SourceFileDescriptor<'_>>, Self::Error> {
222230
self.source_by_path(path)
223231
}
224232
}

0 commit comments

Comments
 (0)