Skip to content

WIP: Return SourceDescriptor in DebugSession #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

**Features**:

- Added debug IDs to source bundle JavaScript files and source maps. ([#762](https://github.com/getsentry/symbolic/pull/762))

**Breaking changes**:

- 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))
Expand Down
2 changes: 2 additions & 0 deletions symbolic-debuginfo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ sourcebundle = [
"regex",
"serde_json",
"zip",
"debugid/serde"
]
# WASM processing
wasm = ["bitvec", "dwarf", "wasmparser"]

[dependencies]
bitvec = { version = "1.0.0", optional = true, features = ["alloc"] }
dmsort = "1.0.1"
debugid = { version = "0.8.0" }
elementtree = { version = "1.2.2", optional = true }
elsa = { version = "1.4.0", optional = true }
fallible-iterator = "0.2.0"
Expand Down
10 changes: 8 additions & 2 deletions symbolic-debuginfo/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ pub type DynIterator<'a, T> = Box<dyn Iterator<Item = T> + 'a>;

/// Represents a source file referenced by a debug information object file.
#[non_exhaustive]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SourceCode<'a> {
/// Verbatim source code/file contents.
Content(Cow<'a, str>),
Expand All @@ -681,6 +681,12 @@ pub enum SourceCode<'a> {
Url(Cow<'a, str>),
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceDescriptor<'source> {
pub source_code: SourceCode<'source>,
pub debug_id: Option<DebugId>,
}

/// A stateful session for interfacing with debug information.
///
/// Debug sessions can be obtained via [`ObjectLike::debug_session`]. Since computing a session may
Expand Down Expand Up @@ -729,7 +735,7 @@ pub trait DebugSession<'session> {

/// Looks up a file's source by its full canonicalized path.
/// Returns either source contents, if it was embedded, or a source link.
fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error>;
fn source_by_path(&self, path: &str) -> Result<Option<SourceDescriptor<'_>>, Self::Error>;
}

/// An object containing debug information.
Expand Down
7 changes: 5 additions & 2 deletions symbolic-debuginfo/src/breakpad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,10 @@ impl<'data> BreakpadDebugSession<'data> {
}

/// See [DebugSession::source_by_path] for more information.
pub fn source_by_path(&self, _path: &str) -> Result<Option<SourceCode<'_>>, BreakpadError> {
pub fn source_by_path(
&self,
_path: &str,
) -> Result<Option<SourceDescriptor<'_>>, BreakpadError> {
Ok(None)
}
}
Expand All @@ -1295,7 +1298,7 @@ impl<'data, 'session> DebugSession<'session> for BreakpadDebugSession<'data> {
self.files()
}

fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error> {
fn source_by_path(&self, path: &str) -> Result<Option<SourceDescriptor<'_>>, Self::Error> {
self.source_by_path(path)
}
}
Expand Down
4 changes: 2 additions & 2 deletions symbolic-debuginfo/src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ impl<'data> DwarfDebugSession<'data> {
}

/// See [DebugSession::source_by_path] for more information.
pub fn source_by_path(&self, _path: &str) -> Result<Option<SourceCode<'_>>, DwarfError> {
pub fn source_by_path(&self, _path: &str) -> Result<Option<SourceDescriptor<'_>>, DwarfError> {
Ok(None)
}
}
Expand All @@ -1350,7 +1350,7 @@ impl<'data, 'session> DebugSession<'session> for DwarfDebugSession<'data> {
self.files()
}

fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error> {
fn source_by_path(&self, path: &str) -> Result<Option<SourceDescriptor<'_>>, Self::Error> {
self.source_by_path(path)
}
}
Expand Down
4 changes: 2 additions & 2 deletions symbolic-debuginfo/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ impl<'d> ObjectDebugSession<'d> {

/// Looks up a file's source by its full canonicalized path.
/// Returns either source contents, if it was embedded, or a source link.
pub fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, ObjectError> {
pub fn source_by_path(&self, path: &str) -> Result<Option<SourceDescriptor<'_>>, ObjectError> {
match *self {
ObjectDebugSession::Breakpad(ref s) => {
s.source_by_path(path).map_err(ObjectError::transparent)
Expand Down Expand Up @@ -518,7 +518,7 @@ impl<'session> DebugSession<'session> for ObjectDebugSession<'_> {
self.files()
}

fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error> {
fn source_by_path(&self, path: &str) -> Result<Option<SourceDescriptor<'_>>, Self::Error> {
self.source_by_path(path)
}
}
Expand Down
4 changes: 2 additions & 2 deletions symbolic-debuginfo/src/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ impl<'d> PdbDebugSession<'d> {
}

/// See [DebugSession::source_by_path] for more information.
pub fn source_by_path(&self, _path: &str) -> Result<Option<SourceCode<'_>>, PdbError> {
pub fn source_by_path(&self, _path: &str) -> Result<Option<SourceDescriptor<'_>>, PdbError> {
Ok(None)
}
}
Expand All @@ -656,7 +656,7 @@ impl<'session> DebugSession<'session> for PdbDebugSession<'_> {
self.files()
}

fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error> {
fn source_by_path(&self, path: &str) -> Result<Option<SourceDescriptor<'_>>, Self::Error> {
self.source_by_path(path)
}
}
Expand Down
14 changes: 10 additions & 4 deletions symbolic-debuginfo/src/ppdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,23 @@ impl<'data> PortablePdbDebugSession<'data> {
}

/// See [DebugSession::source_by_path] for more information.
pub fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, FormatError> {
pub fn source_by_path(&self, path: &str) -> Result<Option<SourceDescriptor<'_>>, FormatError> {
let sources = self.sources.borrow_with(|| self.init_sources());
match sources.get(path) {
let source = match sources.get(path) {
None => Ok(None),
Some(PPDBSource::Embedded(source)) => source
.get_contents()
.map(|bytes| Some(SourceCode::Content(from_utf8_cow_lossy(&bytes)))),
Some(PPDBSource::Link(document)) => {
Ok(self.ppdb.get_source_link(document).map(SourceCode::Url))
}
}
}?;

Ok(source.map(|source_code| SourceDescriptor {
source_code,
// TODO: Should we use the pdb id for this?
debug_id: None,
}))
}
}

Expand All @@ -218,7 +224,7 @@ impl<'data, 'session> DebugSession<'session> for PortablePdbDebugSession<'data>
self.files()
}

fn source_by_path(&self, path: &str) -> Result<Option<SourceCode<'_>>, Self::Error> {
fn source_by_path(&self, path: &str) -> Result<Option<SourceDescriptor<'_>>, Self::Error> {
self.source_by_path(path)
}
}
Expand Down
Loading