Skip to content

feat: Added debug IDs to source bundle javascript files #762

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

Merged
merged 14 commits into from
Feb 21, 2023
Merged
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
19 changes: 6 additions & 13 deletions symbolic-debuginfo/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::str::FromStr;

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

use crate::sourcebundle::SourceFileDescriptor;

pub(crate) trait Parse<'data>: Sized {
type Error;

Expand Down Expand Up @@ -670,17 +672,6 @@ impl fmt::Debug for Function<'_> {
/// A dynamically dispatched iterator over items with the given lifetime.
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)]
pub enum SourceCode<'a> {
/// Verbatim source code/file contents.
Content(Cow<'a, str>),

/// Url (usually https) where the content can be fetched from.
Url(Cow<'a, str>),
}

/// 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 @@ -728,8 +719,10 @@ pub trait DebugSession<'session> {
fn files(&'session self) -> Self::FileIterator;

/// 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>;
///
/// Returns a descriptor that has all the information available of the source. It can
/// either contain the source contents directly, if it was embedded, or a source link.
fn source_by_path(&self, path: &str) -> Result<Option<SourceFileDescriptor<'_>>, Self::Error>;
}

/// An object containing debug information.
Expand Down
8 changes: 6 additions & 2 deletions symbolic-debuginfo/src/breakpad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use symbolic_common::{Arch, AsSelf, CodeId, DebugId, Language, Name, NameManglin

use crate::base::*;
use crate::function_builder::FunctionBuilder;
use crate::sourcebundle::SourceFileDescriptor;
use crate::Parse;

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -1277,7 +1278,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<SourceFileDescriptor<'_>>, BreakpadError> {
Ok(None)
}
}
Expand All @@ -1295,7 +1299,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<SourceFileDescriptor<'_>>, Self::Error> {
self.source_by_path(path)
}
}
Expand Down
8 changes: 6 additions & 2 deletions symbolic-debuginfo/src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::base::*;
use crate::function_builder::FunctionBuilder;
#[cfg(feature = "macho")]
use crate::macho::BcSymbolMap;
use crate::sourcebundle::SourceFileDescriptor;

/// This is a fake BcSymbolMap used when macho support is turned off since they are unfortunately
/// part of the dwarf interface
Expand Down Expand Up @@ -1332,7 +1333,10 @@ 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<SourceFileDescriptor<'_>>, DwarfError> {
Ok(None)
}
}
Expand All @@ -1350,7 +1354,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<SourceFileDescriptor<'_>>, Self::Error> {
self.source_by_path(path)
}
}
Expand Down
7 changes: 5 additions & 2 deletions symbolic-debuginfo/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,10 @@ 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<SourceFileDescriptor<'_>>, ObjectError> {
match *self {
ObjectDebugSession::Breakpad(ref s) => {
s.source_by_path(path).map_err(ObjectError::transparent)
Expand Down Expand Up @@ -518,7 +521,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<SourceFileDescriptor<'_>>, Self::Error> {
self.source_by_path(path)
}
}
Expand Down
8 changes: 6 additions & 2 deletions symbolic-debuginfo/src/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use symbolic_common::{

use crate::base::*;
use crate::function_stack::FunctionStack;
use crate::sourcebundle::SourceFileDescriptor;
use crate::Parse;

type Pdb<'data> = pdb::PDB<'data, Cursor<&'data [u8]>>;
Expand Down Expand Up @@ -638,7 +639,10 @@ 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<SourceFileDescriptor<'_>>, PdbError> {
Ok(None)
}
}
Expand All @@ -656,7 +660,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<SourceFileDescriptor<'_>>, Self::Error> {
self.source_by_path(path)
}
}
Expand Down
24 changes: 16 additions & 8 deletions symbolic-debuginfo/src/ppdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use symbolic_ppdb::EmbeddedSource;
use symbolic_ppdb::{Document, FormatError, PortablePdb};

use crate::base::*;
use crate::sourcebundle::SourceFileDescriptor;

/// An iterator over symbols in a [`PortablePdbObject`].
pub type PortablePdbSymbolIterator<'data> = iter::Empty<Symbol<'data>>;
Expand Down Expand Up @@ -191,16 +192,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<SourceFileDescriptor<'_>>, FormatError> {
let sources = self.sources.borrow_with(|| self.init_sources());
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))
}
Some(PPDBSource::Embedded(source)) => source.get_contents().map(|bytes| {
Some(SourceFileDescriptor::new_embedded(
from_utf8_cow_lossy(&bytes),
None,
))
}),
Some(PPDBSource::Link(document)) => Ok(self
.ppdb
.get_source_link(document)
.map(SourceFileDescriptor::new_remote)),
}
}
}
Expand All @@ -218,7 +226,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<SourceFileDescriptor<'_>>, Self::Error> {
self.source_by_path(path)
}
}
Expand Down
Loading