:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(cymbal): resolve native frames against uploaded debug symbols (#62590)
Catalin Irimie5c5f6dba2ea2
diff --git a/rust/Cargo.lock b/rust/Cargo.lockindex 8a4e75f4b771..00119b6c4003 100644--- a/rust/Cargo.lock+++ b/rust/Cargo.lock@@ -2757,6 +2757,7 @@ dependencies = ["tracing-subscriber","uuid","zip 4.6.1",+ "zstd",][[package]]diff --git a/rust/cymbal/Cargo.toml b/rust/cymbal/Cargo.tomlindex d283cbdeb29c..12bd493911ea 100644--- a/rust/cymbal/Cargo.toml+++ b/rust/cymbal/Cargo.toml@@ -60,6 +60,8 @@ httpmock = { workspace = true }mockall = { workspace = true }insta = { version = "1.46.0", features = ["json", "redactions"] }tower.workspace = true+# For decompressing the committed native ELF test fixture+zstd = "0.13"[lints]workspace = truediff --git a/rust/cymbal/src/core/resolver.rs b/rust/cymbal/src/core/resolver.rsindex ce9905a31d75..f7f754d99be2 100644--- a/rust/cymbal/src/core/resolver.rs+++ b/rust/cymbal/src/core/resolver.rs@@ -12,6 +12,7 @@ use crate::core::symbolication::symbol_store::{chunk_id::ChunkIdFetcher,concurrency,hermesmap::HermesMapProvider,+ native::NativeProvider,proguard::ProguardProvider,saving::Saving,sourcemap::SourcemapProvider,@@ -105,13 +106,23 @@ pub fn build_catalog(posthog_pool.clone(),config.object_storage_bucket.clone(),);- let apple_caching = Caching::new(apple_chunk, ss_cache);+ let apple_caching = Caching::new(apple_chunk, ss_cache.clone());let apple_atmostonce = concurrency::AtMostOne::new(apple_caching);+ let native_chunk = ChunkIdFetcher::new(+ NativeProvider {},+ s3_client.clone(),+ posthog_pool.clone(),+ config.object_storage_bucket.clone(),+ );+ let native_caching = Caching::new(native_chunk, ss_cache);+ let native_atmostonce = concurrency::AtMostOne::new(native_caching);+Arc::new(Catalog::new(smp_atmostonce,hmp_atmostonce,pgp_atmostonce,apple_atmostonce,+ native_atmostonce,))}diff --git a/rust/cymbal/src/core/symbolication/resolve.rs b/rust/cymbal/src/core/symbolication/resolve.rsindex e31493e0ebf9..65a0d9d1670e 100644--- a/rust/cymbal/src/core/symbolication/resolve.rs+++ b/rust/cymbal/src/core/symbolication/resolve.rs@@ -168,7 +168,12 @@ impl Resolve<Catalog> for RawFrame {RawFrame::Php(frame) => (Ok(vec![frame.into()]), "php"),RawFrame::Python(frame) => (Ok(vec![frame.into()]), "python"),RawFrame::Ruby(frame) => (Ok(vec![frame.into()]), "ruby"),- RawFrame::Rust(frame) => (Ok(vec![frame.into()]), "rust"),+ RawFrame::Native(frame) => (+ frame+ .resolve(team_id, catalog, debug_images, context_lines)+ .await,+ "native",+ ),RawFrame::Custom(frame) => (Ok(vec![frame.into()]), "custom"),RawFrame::Go(frame) => (Ok(vec![frame.into()]), "go"),RawFrame::Hermes(frame) => (diff --git a/rust/cymbal/src/core/symbolication/symbol/local.rs b/rust/cymbal/src/core/symbolication/symbol/local.rsindex dba5cf78ac08..b628c6d01122 100644--- a/rust/cymbal/src/core/symbolication/symbol/local.rs+++ b/rust/cymbal/src/core/symbolication/symbol/local.rs@@ -266,6 +266,7 @@ mod test {apple::AppleProvider,chunk_id::ChunkIdFetcher,hermesmap::HermesMapProvider,+ native::NativeProvider,proguard::ProguardProvider,saving::{Saving, SymbolSetRecord},sourcemap::SourcemapProvider,@@ -346,7 +347,14 @@ mod test {config.object_storage_bucket.clone(),);- let catalog = Catalog::new(saving_smp, hmp, pgp, apple);+ let native = ChunkIdFetcher::new(+ NativeProvider {},+ client.clone(),+ pool.clone(),+ config.object_storage_bucket.clone(),+ );++ let catalog = Catalog::new(saving_smp, hmp, pgp, apple, native);(config, catalog, server)}diff --git a/rust/cymbal/src/core/symbolication/symbol_store/chunk_id.rs b/rust/cymbal/src/core/symbolication/symbol_store/chunk_id.rsindex ff509c9ee277..34acf70bb749 100644--- a/rust/cymbal/src/core/symbolication/symbol_store/chunk_id.rs+++ b/rust/cymbal/src/core/symbolication/symbol_store/chunk_id.rs@@ -352,6 +352,7 @@ mod test {apple::AppleProvider,chunk_id::{ChunkIdFetcher, OrChunkId, SymbolSetCacheKey},hermesmap::HermesMapProvider,+ native::NativeProvider,proguard::ProguardProvider,saving::SymbolSetRecord,sourcemap::{OwnedSourceMapCache, SourcemapProvider},@@ -519,7 +520,14 @@ mod test {config.object_storage_bucket.clone(),);- let catalog = Catalog::new(chunk_id_fetcher, hermes_map_fetcher, pgp, apple);+ let native = ChunkIdFetcher::new(+ NativeProvider {},+ client.clone(),+ db.clone(),+ config.object_storage_bucket.clone(),+ );++ let catalog = Catalog::new(chunk_id_fetcher, hermes_map_fetcher, pgp, apple, native);let mut frame = get_example_frame();frame.chunk_id = Some(chunk_id.clone());diff --git a/rust/cymbal/src/core/symbolication/symbol_store/mod.rs b/rust/cymbal/src/core/symbolication/symbol_store/mod.rsindex 53f587849b25..bd983deb35be 100644--- a/rust/cymbal/src/core/symbolication/symbol_store/mod.rs+++ b/rust/cymbal/src/core/symbolication/symbol_store/mod.rs@@ -12,7 +12,7 @@ use crate::{symbolication::symbol_store::{apple::AppleRef,hermesmap::ParsedHermesMap,- native::ParsedNativeSymbols,+ native::{NativeRef, ParsedNativeSymbols},proguard::{FetchedMapping, ProguardRef},},};@@ -79,6 +79,10 @@ pub struct Catalog {// Apple dSYM providerpub apple:Box<dyn Provider<Ref = OrChunkId<AppleRef>, Set = ParsedNativeSymbols, Err = ResolveError>>,+ // Native (ELF/dSYM) debug symbol provider+ pub native: Box<+ dyn Provider<Ref = OrChunkId<NativeRef>, Set = ParsedNativeSymbols, Err = ResolveError>,+ >,}impl Catalog {@@ -87,12 +91,14 @@ impl Catalog {hmp: impl Provider<Ref = OrChunkId<HermesRef>, Set = ParsedHermesMap, Err = ResolveError>,pg: impl Provider<Ref = OrChunkId<ProguardRef>, Set = FetchedMapping, Err = ResolveError>,apple: impl Provider<Ref = OrChunkId<AppleRef>, Set = ParsedNativeSymbols, Err = ResolveError>,+ native: impl Provider<Ref = OrChunkId<NativeRef>, Set = ParsedNativeSymbols, Err = ResolveError>,) -> Self {Self {smp: Box::new(smp),hmp: Box::new(hmp),pg: Box::new(pg),apple: Box::new(apple),+ native: Box::new(native),}}}@@ -149,6 +155,17 @@ impl SymbolCatalog<OrChunkId<AppleRef>, ParsedNativeSymbols> for Catalog {}}+#[async_trait]+impl SymbolCatalog<OrChunkId<NativeRef>, ParsedNativeSymbols> for Catalog {+ async fn lookup(+ &self,+ team_id: i32,+ r: OrChunkId<NativeRef>,+ ) -> Result<Arc<ParsedNativeSymbols>, ResolveError> {+ self.native.lookup(team_id, r).await+ }+}+#[async_trait]impl<T> Provider for Twherediff --git a/rust/cymbal/src/core/symbolication/symbol_store/native.rs b/rust/cymbal/src/core/symbolication/symbol_store/native.rsindex 139ffa2b7042..e1b2362e84b3 100644--- a/rust/cymbal/src/core/symbolication/symbol_store/native.rs+++ b/rust/cymbal/src/core/symbolication/symbol_store/native.rs@@ -1,13 +1,22 @@use std::collections::HashMap;+use std::fmt::Display;use std::io::{Cursor, Read};+use async_trait::async_trait;+use bytes::Bytes;use serde::Deserialize;use symbolic::debuginfo::Archive;use symbolic::demangle::{Demangle, DemangleOptions};use symbolic::symcache::{SymCache, SymCacheConverter};use zip::ZipArchive;-use crate::{error::NativeError, symbolication::symbol_store::caching::Countable};+use posthog_symbol_data::{read_symbol_data_with_byte_count, AppleDsym, ElfDebugInfo};++use crate::{+ error::{NativeError, ResolveError, UnhandledError},+ metric_consts::SYMBOL_SET_DECOMPRESSED_BYTES,+ symbolication::symbol_store::{caching::Countable, Fetcher, Parser},+};/// Manifest format for source files bundled in the symbol ZIP under `__source/`#[derive(Deserialize)]@@ -273,3 +282,67 @@ pub struct SymbolInfo {pub full_path: Option<String>,pub line: u32,}++/// Provider for native debug symbols looked up by debug_id. Accepts both+/// `ElfDebugInfo` bundles (uploaded via `posthog-cli debug-symbols upload`)+/// and `AppleDsym` bundles (uploaded via `posthog-cli dsym upload`), so+/// native frames from macOS binaries resolve against existing dSYM uploads.+pub struct NativeProvider {}++#[derive(Debug, Clone)]+pub enum NativeRef {}++#[async_trait]+impl Fetcher for NativeProvider {+ type Ref = NativeRef;+ type Fetched = Bytes;+ type Err = ResolveError;++ async fn fetch(&self, _: i32, _: NativeRef) -> Result<Bytes, Self::Err> {+ unreachable!("NativeRef is impossible to construct, so cannot be passed")+ }+}++#[async_trait]+impl Parser for NativeProvider {+ type Source = Bytes;+ type Set = ParsedNativeSymbols;+ type Err = ResolveError;++ async fn parse(&self, source: Self::Source) -> Result<ParsedNativeSymbols, ResolveError> {+ // Debug-info parsing is the heaviest CPU work in the system: zstd+ // decompress, ZIP expansion, DWARF parse, and symcache conversion.+ // Always offload from the tokio runtime.+ tokio::task::spawn_blocking(move || -> Result<ParsedNativeSymbols, ResolveError> {+ // Slice selection invariant: CLI dSYM uploads are one single-arch+ // binary per UUID (fat binaries are thinned at upload), so a+ // chunk_id lookup always parses the slice it names. The arm64+ // preference inside the symcache conversion only kicks in for+ // legacy raw-zip fat uploads, which predate native frames.+ let (zip_data, decompressed_bytes) =+ match read_symbol_data_with_byte_count::<ElfDebugInfo>(&source) {+ Ok((elf, bytes)) => (elf.data, bytes),+ Err(_) => match read_symbol_data_with_byte_count::<AppleDsym>(&source) {+ Ok((dsym, bytes)) => (dsym.data, bytes),+ // Raw ZIP fallback for dSYMs uploaded before the+ // symbol_data container was introduced.+ Err(_) => {+ let len = source.len();+ (source.to_vec(), len)+ }+ },+ };+ metrics::histogram!(SYMBOL_SET_DECOMPRESSED_BYTES, "kind" => "native")+ .record(decompressed_bytes as f64);+ ParsedNativeSymbols::from_zip_data(zip_data, decompressed_bytes).map_err(Into::into)+ })+ .await+ .map_err(|e| UnhandledError::Other(format!("native debug symbol parse task failed: {e}")))?+ }+}++impl Display for NativeRef {+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ write!(f, "NativeRef")+ }+}diff --git a/rust/cymbal/src/core/types/frames/mod.rs b/rust/cymbal/src/core/types/frames/mod.rsindex 60bad7e7a004..00099e34e7f8 100644--- a/rust/cymbal/src/core/types/frames/mod.rs+++ b/rust/cymbal/src/core/types/frames/mod.rs@@ -7,10 +7,18 @@ use serde_json::Value;use crate::{langs::{- apple::RawAppleFrame, custom::CustomFrame, dart::RawDartFrame, go::RawGoFrame,- hermes::RawHermesFrame, java::RawJavaFrame, js::RawJSFrame, native::DebugImage,- node::RawNodeFrame, php::RawPHPFrame, python::RawPythonFrame, ruby::RawRubyFrame,- rust::RawRustFrame,+ apple::RawAppleFrame,+ custom::CustomFrame,+ dart::RawDartFrame,+ go::RawGoFrame,+ hermes::RawHermesFrame,+ java::RawJavaFrame,+ js::RawJSFrame,+ native::{DebugImage, RawNativeFrame},+ node::RawNodeFrame,+ php::RawPHPFrame,+ python::RawPythonFrame,+ ruby::RawRubyFrame,},metric_consts::FRAME_NOT_RESOLVED,sanitize_source_line,@@ -63,8 +71,10 @@ pub enum RawFrame {Dart(RawDartFrame),#[serde(rename = "apple")]Apple(RawAppleFrame),- #[serde(rename = "rust")]- Rust(RawRustFrame),+ // "rust" accepted defensively: the pre-release Rust SDK emitted it as a+ // pass-through frame shape that RawNativeFrame handles identically.+ #[serde(rename = "native", alias = "rust")]+ Native(RawNativeFrame),#[serde(rename = "custom")]Custom(CustomFrame),// TODO - remove once we're happy no clients are using this anymore@@ -86,7 +96,7 @@ impl RawFrame {| RawFrame::Go(_)| RawFrame::Dart(_)| RawFrame::Apple(_)- | RawFrame::Rust(_)+ | RawFrame::Native(_)| RawFrame::Custom(_) => None,}}@@ -99,7 +109,7 @@ impl RawFrame {RawFrame::Python(raw) => raw.frame_id(),RawFrame::Ruby(raw) => raw.frame_id(),RawFrame::Go(raw) => raw.frame_id(),- RawFrame::Rust(raw) => raw.frame_id(),+ RawFrame::Native(raw) => raw.frame_id(debug_images),RawFrame::Custom(raw) => raw.frame_id(),RawFrame::Hermes(raw) => raw.frame_id(),RawFrame::Java(raw) => raw.frame_id(),@@ -344,24 +354,25 @@ mod test {}#[test]- fn ensure_rust_frames_work() {+ fn ensure_native_frames_parse_and_pass_through() {let data = r#"{"function": "checkout::payment::charge",- "module": "checkout::payment",+ "module": "checkout_service","filename": "src/main.rs",- "resolved": true,+ "lang": "rust","in_app": true,"lineno": 42,- "platform": "rust"+ "instruction_addr": "0x7f3a9c041b2d",+ "image_addr": "0x7f3a9c000000",+ "platform": "native"}"#;let frame: RawFrame = serde_json::from_str(data).unwrap();match frame {- RawFrame::Rust(frame) => {+ RawFrame::Native(frame) => {let resolved: Frame = (&frame).into();- let resolved_frame_id = frame.frame_id();assert_eq!(resolved.lang, "rust");assert_eq!(resolved.mangled_name, "checkout::payment::charge");assert_eq!(@@ -369,33 +380,28 @@ mod test {Some("checkout::payment::charge"));assert_eq!(resolved.source.as_deref(), Some("src/main.rs"));- assert_eq!(resolved.module.as_deref(), Some("checkout::payment"));+ assert_eq!(resolved.module.as_deref(), Some("checkout_service"));assert_eq!(resolved.line, Some(42));assert_eq!(resolved.context, None);-- let unresolved_data = data.replace("\"resolved\": true,", "\"resolved\": false,");- let unresolved_frame: RawFrame = serde_json::from_str(&unresolved_data).unwrap();- match unresolved_frame {- RawFrame::Rust(frame) => assert_eq!(frame.frame_id(), resolved_frame_id),- _ => panic!("Expected a rust frame"),- }+ assert!(resolved.resolved);let missing_function_data =data.replace("\"function\": \"checkout::payment::charge\",\n", "");let missing_function_frame: RawFrame =serde_json::from_str(&missing_function_data).unwrap();match missing_function_frame {- RawFrame::Rust(frame) => {+ RawFrame::Native(frame) => {let resolved: Frame = (&frame).into();assert_eq!(resolved.mangled_name, "");assert_eq!(resolved.resolved_name, None);+ assert!(!resolved.resolved);assert_eq!(resolved.source.as_deref(), Some("src/main.rs"));assert_eq!(resolved.line, Some(42));}- _ => panic!("Expected a rust frame"),+ _ => panic!("Expected a native frame"),}}- _ => panic!("Expected a rust frame"),+ _ => panic!("Expected a native frame"),}}}diff --git a/rust/cymbal/src/core/types/langs/apple.rs b/rust/cymbal/src/core/types/langs/apple.rsindex c5efeaedbb46..b4eca9526829 100644--- a/rust/cymbal/src/core/types/langs/apple.rs+++ b/rust/cymbal/src/core/types/langs/apple.rs@@ -445,8 +445,8 @@ mod test {frames::RawFrame,symbolication::symbol_store::{apple::AppleProvider, chunk_id::ChunkIdFetcher, hermesmap::HermesMapProvider,- proguard::ProguardProvider, saving::SymbolSetRecord, sourcemap::SourcemapProvider,- Catalog, MockS3Client,+ native::NativeProvider, proguard::ProguardProvider, saving::SymbolSetRecord,+ sourcemap::SourcemapProvider, Catalog, MockS3Client,},};@@ -511,7 +511,14 @@ mod test {config.object_storage_bucket.clone(),);- let catalog = Catalog::new(smp, hmp, pgp, apple);+ let native = ChunkIdFetcher::new(+ NativeProvider {},+ client.clone(),+ db.clone(),+ config.object_storage_bucket.clone(),+ );++ let catalog = Catalog::new(smp, hmp, pgp, apple, native);// Use 0x100000334 (line 7 of inner_function, "(void)x").// After the -1 call-site adjustment (0x334 - 1 = 0x333), the symcache@@ -609,8 +616,8 @@ mod test {frames::RawFrame,symbolication::symbol_store::{apple::AppleProvider, chunk_id::ChunkIdFetcher, hermesmap::HermesMapProvider,- proguard::ProguardProvider, saving::SymbolSetRecord, sourcemap::SourcemapProvider,- Catalog, MockS3Client,+ native::NativeProvider, proguard::ProguardProvider, saving::SymbolSetRecord,+ sourcemap::SourcemapProvider, Catalog, MockS3Client,},};@@ -667,6 +674,12 @@ mod test {db.clone(),config.object_storage_bucket.clone(),),+ ChunkIdFetcher::new(+ NativeProvider {},+ client.clone(),+ db.clone(),+ config.object_storage_bucket.clone(),+ ),);// 0x10000034c is inside inlined_leaf as inlined into outer_function.diff --git a/rust/cymbal/src/core/types/langs/hermes.rs b/rust/cymbal/src/core/types/langs/hermes.rsindex b4998791ab57..f4d5ce42caaf 100644--- a/rust/cymbal/src/core/types/langs/hermes.rs+++ b/rust/cymbal/src/core/types/langs/hermes.rs@@ -259,8 +259,8 @@ mod test {langs::{hermes::RawHermesFrame, CommonFrameMetadata},symbolication::symbol_store::{apple::AppleProvider, chunk_id::ChunkIdFetcher, hermesmap::HermesMapProvider,- proguard::ProguardProvider, saving::SymbolSetRecord, sourcemap::SourcemapProvider,- Catalog, MockS3Client,+ native::NativeProvider, proguard::ProguardProvider, saving::SymbolSetRecord,+ sourcemap::SourcemapProvider, Catalog, MockS3Client,},};@@ -330,7 +330,14 @@ mod test {config.object_storage_bucket.clone(),);- let c = Catalog::new(smp, hmp, pgp, apple);+ let native = ChunkIdFetcher::new(+ NativeProvider {},+ client.clone(),+ db.clone(),+ config.object_storage_bucket.clone(),+ );++ let c = Catalog::new(smp, hmp, pgp, apple, native);for (raw_frame, expected_name) in get_frames(chunk_id) {let res = raw_framediff --git a/rust/cymbal/src/core/types/langs/mod.rs b/rust/cymbal/src/core/types/langs/mod.rsindex c28cf58b3409..92140a867ecb 100644--- a/rust/cymbal/src/core/types/langs/mod.rs+++ b/rust/cymbal/src/core/types/langs/mod.rs@@ -12,7 +12,6 @@ pub mod node;pub mod php;pub mod python;pub mod ruby;-pub mod rust;pub mod utils;// Some metadata is common across all languages, so we define it here. In somediff --git a/rust/cymbal/src/core/types/langs/native.rs b/rust/cymbal/src/core/types/langs/native.rsindex d359854fc4ac..5c4139b07070 100644--- a/rust/cymbal/src/core/types/langs/native.rs+++ b/rust/cymbal/src/core/types/langs/native.rs@@ -1,6 +1,22 @@+use std::sync::Arc;++use common_types::error_tracking::FrameId;use serde::{Deserialize, Serialize};+use sha2::{Digest, Sha512};+use symbolic::common::Name;+use symbolic::demangle::{Demangle, DemangleOptions};-use crate::error::NativeError;+use crate::{+ error::{FrameError, NativeError, ResolveError, UnhandledError},+ frames::{record_frame_resolution_failure, Frame},+ langs::utils::{add_raw_to_junk, get_context_lines},+ langs::CommonFrameMetadata,+ symbolication::symbol_store::{+ chunk_id::OrChunkId,+ native::{NativeRef, ParsedNativeSymbols, SymbolInfo},+ SymbolCatalog,+ },+};/// A loaded module (binary image) reported by an SDK alongside native stack/// frames, used to map absolute instruction addresses onto an uploaded debug@@ -89,9 +105,303 @@ pub fn launch_invariant_addr(Some((debug_image.debug_id.clone(), relative_addr))}+/// A native stack frame as sent by SDKs that capture raw instruction+/// addresses (e.g. posthog-rs). Resolution model: when `instruction_addr` is+/// present and a matching debug image was sent, the frame is symbolicated+/// server-side against the uploaded debug symbols; otherwise the client-side+/// enrichment fields (`function`/`filename`/`lineno`) pass through as-is.+#[derive(Debug, Clone, Deserialize, Serialize)]+pub struct RawNativeFrame {+ pub instruction_addr: Option<String>,+ pub symbol_addr: Option<String>,+ pub image_addr: Option<String>,+ /// Display-language hint from the SDK (e.g. "rust"); the resolved+ /// filename extension wins when available.+ pub lang: Option<String>,+ pub module: Option<String>,+ pub function: Option<String>,+ pub filename: Option<String>,+ pub lineno: Option<u32>,+ pub colno: Option<u32>,+ #[serde(flatten)]+ pub meta: CommonFrameMetadata,+}++impl RawNativeFrame {+ pub async fn resolve<C>(+ &self,+ team_id: i32,+ catalog: &C,+ debug_images: &[DebugImage],+ context_lines: usize,+ ) -> Result<Vec<Frame>, UnhandledError>+ where+ C: SymbolCatalog<OrChunkId<NativeRef>, ParsedNativeSymbols>,+ {+ // Frames without an instruction address (e.g. hand-built exception+ // lists) carry only client-side resolution and pass through as-is.+ let Some(instruction_addr) = self.instruction_addr.as_deref() else {+ return Ok(vec![self.into()]);+ };++ match self+ .resolve_impl(+ team_id,+ catalog,+ instruction_addr,+ debug_images,+ context_lines,+ )+ .await+ {+ Ok(frames) => Ok(frames),+ Err(ResolveError::ResolutionError(FrameError::Native(e))) => {+ Ok(vec![self.handle_resolution_error(e)])+ }+ Err(ResolveError::ResolutionError(FrameError::MissingChunkIdData(chunk_id))) => Ok(+ vec![self.handle_resolution_error(NativeError::MissingSymbolSet(chunk_id))],+ ),+ Err(ResolveError::ResolutionError(e)) => {+ tracing::warn!("Unexpected native symbol resolution error: {:?}", e);+ Ok(vec![self.handle_resolution_error(NativeError::ParseError(+ e.to_string(),+ ))])+ }+ Err(ResolveError::UnhandledError(e)) => Err(e),+ }+ }++ async fn resolve_impl<C>(+ &self,+ team_id: i32,+ catalog: &C,+ instruction_addr: &str,+ debug_images: &[DebugImage],+ context_lines: usize,+ ) -> Result<Vec<Frame>, ResolveError>+ where+ C: SymbolCatalog<OrChunkId<NativeRef>, ParsedNativeSymbols>,+ {+ let instruction_addr = parse_hex_address(instruction_addr)?;++ let debug_image =+ find_debug_image(instruction_addr, self.image_addr.as_deref(), debug_images)?;++ let relative_addr = calculate_relative_addr(instruction_addr, debug_image)?;++ // Subtract 1 from return-address frames so the lookup targets the call+ // instruction rather than the instruction after it, giving the correct+ // source line. Safe for top (crash-site) frames too: addr-1 still falls+ // within the same function body.+ let lookup_addr = relative_addr.saturating_sub(1);++ let symbols: Arc<ParsedNativeSymbols> = catalog+ .lookup(team_id, OrChunkId::chunk_id(debug_image.debug_id.clone()))+ .await?;++ let symbol_infos = symbols.lookup(lookup_addr)?;+ if symbol_infos.is_empty() {+ return Err(NativeError::SymbolNotFound(lookup_addr).into());+ }++ // Build one resolved Frame per logical layer. The symcache returns+ // layers innermost-first; reverse to outermost-first so the flattened+ // stack stays in bottom-up order (main first, crash site last).+ let frames: Vec<Frame> = symbol_infos+ .iter()+ .rev()+ .map(|info| {+ let mut frame = self.build_resolved_frame(info);++ // Attach source context to every inlined layer independently.+ if let Some(full_path) = &info.full_path {+ if let Some(source_text) = symbols.get_source(full_path) {+ // symcache line numbers are 1-based (0 = unknown)+ let target_line = if info.line > 0 {+ (info.line - 1) as usize+ } else {+ 0+ };+ frame.context =+ get_context_lines(source_text.lines(), target_line, context_lines);+ }+ }++ frame+ })+ .collect();++ Ok(frames)+ }++ fn build_resolved_frame(&self, symbol_info: &SymbolInfo) -> Frame {+ let mut f = Frame {+ frame_id: FrameId::placeholder(),+ mangled_name: symbol_info.full_name.clone(),+ line: if symbol_info.line > 0 {+ Some(symbol_info.line)+ } else {+ None+ },+ column: None,+ source: symbol_info.filename.clone(),+ in_app: self.meta.in_app,+ resolved_name: Some(symbol_info.display_name.clone()),+ lang: self.lang_for(symbol_info.filename.as_deref()),+ resolved: true,+ resolve_failure: None,++ junk_drawer: None,+ release: None,+ synthetic: self.meta.synthetic,+ context: None,+ suspicious: false,+ module: self.module.clone(),+ code_variables: None,+ };++ add_raw_to_junk(&mut f, self);+ f+ }++ fn handle_resolution_error(&self, err: NativeError) -> Frame {+ record_frame_resolution_failure("native", err.metric_reason(), &err);++ // Demangle the raw function name if the SDK sent a mangled one+ let mangled = self.function.clone().unwrap_or_default();+ let resolved_name = if !mangled.is_empty() {+ let name = Name::from(mangled.as_str());+ Some(+ name.demangle(DemangleOptions::complete())+ .unwrap_or_else(|| mangled.clone()),+ )+ } else {+ None+ };++ // For unresolved frames without a filename, show "module +image_addr"+ // as source (e.g. system libraries we have no debug symbols for).+ let source = self+ .filename+ .clone()+ .or_else(|| match (&self.module, &self.image_addr) {+ (Some(module), Some(addr)) => Some(format!("{} +{}", module, addr)),+ (Some(module), None) => Some(module.clone()),+ _ => None,+ });++ let mut frame = Frame {+ frame_id: FrameId::placeholder(),+ mangled_name: mangled,+ line: self.lineno,+ column: self.colno,+ source,+ in_app: self.meta.in_app,+ resolved_name,+ lang: self.lang_for(self.filename.as_deref()),+ resolved: false,+ resolve_failure: Some(err.to_string()),+ junk_drawer: None,+ release: None,+ synthetic: self.meta.synthetic,+ context: None,+ suspicious: false,+ module: self.module.clone(),+ code_variables: None,+ };++ add_raw_to_junk(&mut frame, self);+ frame+ }++ /// Display language: the resolved filename extension wins (a Rust binary's+ /// stack legitimately contains C/C++ frames from native dependencies),+ /// falling back to the SDK's hint.+ fn lang_for(&self, filename: Option<&str>) -> String {+ match filename.and_then(|f| f.rsplit('.').next()) {+ Some("rs") => "rust".to_string(),+ Some("c") => "c".to_string(),+ Some("cpp" | "cc" | "cxx" | "hpp" | "hh" | "hxx") => "cpp".to_string(),+ // `.h` is ambiguous across C/C++/Objective-C, so default to C.+ Some("h") => "c".to_string(),+ Some("swift") => "swift".to_string(),+ Some("m") => "objectivec".to_string(),+ _ => self.lang.clone().unwrap_or_else(|| "native".to_string()),+ }+ }++ pub fn frame_id(&self, debug_images: &[DebugImage]) -> String {+ let mut hasher = Sha512::new();++ // Prefer the launch-invariant (debug image, relative offset) identity+ // so the frame record cache survives ASLR across process launches.+ match launch_invariant_addr(+ self.instruction_addr.as_deref(),+ self.image_addr.as_deref(),+ debug_images,+ ) {+ Some((debug_id, relative_addr)) => {+ hasher.update(debug_id.as_bytes());+ hasher.update(format!("rel:0x{relative_addr:x}").as_bytes());+ }+ None => {+ if let Some(instruction_addr) = &self.instruction_addr {+ hasher.update(instruction_addr.as_bytes());+ }+ }+ }++ // Client-side identity, which also covers address-less frames.+ self.function+ .as_ref()+ .inspect(|f| hasher.update(f.as_bytes()));+ self.filename+ .as_ref()+ .inspect(|f| hasher.update(f.as_bytes()));+ hasher.update(self.lineno.unwrap_or_default().to_be_bytes());+ hasher.update(self.colno.unwrap_or_default().to_be_bytes());+ self.module+ .as_ref()+ .inspect(|m| hasher.update(m.as_bytes()));+ hasher.update(b"native");++ format!("{:x}", hasher.finalize())+ }+}++impl From<&RawNativeFrame> for Frame {+ fn from(raw: &RawNativeFrame) -> Self {+ let mut f = Frame {+ frame_id: FrameId::placeholder(),+ mangled_name: raw.function.clone().unwrap_or_default(),+ line: raw.lineno,+ column: raw.colno,+ source: raw.filename.clone(),+ in_app: raw.meta.in_app,+ resolved_name: raw.function.clone(),+ lang: raw.lang_for(raw.filename.as_deref()),+ resolved: raw.function.is_some(),+ resolve_failure: None,++ junk_drawer: None,+ release: None,+ synthetic: raw.meta.synthetic,+ context: None,+ suspicious: false,+ module: raw.module.clone(),+ code_variables: None,+ };++ // Store raw frame data in junk drawer for debugging/analysis+ add_raw_to_junk(&mut f, raw);+ f+ }+}+#[cfg(test)]mod test {use super::*;+ use crate::core::symbolication::resolve::Resolve;fn image_at(debug_id: &str, image_addr: u64) -> DebugImage {DebugImage {@@ -179,4 +489,457 @@ mod test {let result = launch_invariant_addr(Some("0x104f04000"), None, &[]);assert_eq!(result, None);}++ #[test]+ fn test_native_frames_without_address_pass_through() {+ let frame = RawNativeFrame {+ instruction_addr: None,+ symbol_addr: None,+ image_addr: None,+ lang: Some("rust".to_string()),+ module: Some("checkout_service".to_string()),+ function: Some("checkout::submit".to_string()),+ filename: Some("src/checkout.rs".to_string()),+ lineno: Some(42),+ colno: None,+ meta: CommonFrameMetadata::default(),+ };++ let resolved: Frame = (&frame).into();+ assert!(resolved.resolved);+ assert_eq!(resolved.resolved_name.as_deref(), Some("checkout::submit"));+ assert_eq!(resolved.source.as_deref(), Some("src/checkout.rs"));+ assert_eq!(resolved.line, Some(42));+ assert_eq!(resolved.lang, "rust");+ }++ #[test]+ fn test_native_frame_id_stable_across_aslr_slides() {+ let frame_at = |instruction_addr: u64, image_addr: u64| RawNativeFrame {+ instruction_addr: Some(format!("0x{instruction_addr:x}")),+ symbol_addr: None,+ image_addr: Some(format!("0x{image_addr:x}")),+ lang: Some("rust".to_string()),+ module: Some("my_service".to_string()),+ function: None,+ filename: None,+ lineno: None,+ colno: None,+ meta: CommonFrameMetadata::default(),+ };++ let launch_a = frame_at(0x100004000, 0x100000000);+ let launch_b = frame_at(0x104f04000, 0x104f00000);++ let id_a = launch_a.frame_id(&[image_at("build-1", 0x100000000)]);+ let id_b = launch_b.frame_id(&[image_at("build-1", 0x104f00000)]);+ assert_eq!(id_a, id_b);++ // Without a matching image the absolute address is hashed, so the ids differ.+ assert_ne!(launch_a.frame_id(&[]), launch_b.frame_id(&[]));+ }++ /// Wrap a fixture ELF in the upload ZIP layout (binary as `dwarf` at the+ /// root, optional `__source/` bundle), mirroring what the CLI produces.+ fn zip_fixture(elf: &[u8], source: Option<(&str, &str)>) -> Vec<u8> {+ use std::io::{Cursor, Write};++ let mut buffer = Cursor::new(Vec::new());+ {+ let mut zip = zip::ZipWriter::new(&mut buffer);+ let options = zip::write::SimpleFileOptions::default()+ .compression_method(zip::CompressionMethod::Deflated);+ zip.start_file("dwarf", options).unwrap();+ zip.write_all(elf).unwrap();++ if let Some((dwarf_path, content)) = source {+ let manifest = serde_json::json!({+ "version": 1,+ "files": { dwarf_path: "__source/0" },+ });+ zip.start_file("__source/manifest.json", options).unwrap();+ zip.write_all(manifest.to_string().as_bytes()).unwrap();+ zip.start_file("__source/0", options).unwrap();+ zip.write_all(content.as_bytes()).unwrap();+ }++ zip.finish().unwrap();+ }++ posthog_symbol_data::write_symbol_data(posthog_symbol_data::ElfDebugInfo {+ data: buffer.into_inner(),+ })+ .unwrap()+ }++ /// Build a catalog whose native provider serves `data` for `chunk_id`.+ async fn catalog_for_chunk(+ db: &sqlx::PgPool,+ chunk_id: &str,+ data: Vec<u8>,+ ) -> crate::symbolication::symbol_store::Catalog {+ use chrono::Utc;+ use mockall::predicate;+ use std::sync::Arc;+ use uuid::Uuid;++ use crate::{+ core::config::ResolverConfig,+ symbolication::symbol_store::{+ apple::AppleProvider, chunk_id::ChunkIdFetcher, hermesmap::HermesMapProvider,+ native::NativeProvider, proguard::ProguardProvider, saving::SymbolSetRecord,+ sourcemap::SourcemapProvider, Catalog, MockS3Client,+ },+ };++ let mut config = ResolverConfig::init_with_defaults().unwrap();+ config.object_storage_bucket = "test-bucket".to_string();++ let mut record = SymbolSetRecord {+ id: Uuid::now_v7(),+ team_id: 1,+ set_ref: chunk_id.to_string(),+ storage_ptr: Some(chunk_id.to_string()),+ failure_reason: None,+ created_at: Utc::now(),+ content_hash: Some("fake-hash".to_string()),+ last_used: Some(Utc::now()),+ };+ record.save(db).await.unwrap();++ let mut client = MockS3Client::default();+ client+ .expect_get()+ .with(+ predicate::eq(config.object_storage_bucket.clone()),+ predicate::eq(chunk_id.to_string()),+ )+ .returning(move |_, _| Ok(Some(bytes::Bytes::from(data.clone()))));+ let client = Arc::new(client);++ Catalog::new(+ ChunkIdFetcher::new(+ SourcemapProvider::new(&config),+ client.clone(),+ db.clone(),+ config.object_storage_bucket.clone(),+ ),+ ChunkIdFetcher::new(+ HermesMapProvider {},+ client.clone(),+ db.clone(),+ config.object_storage_bucket.clone(),+ ),+ ChunkIdFetcher::new(+ ProguardProvider {},+ client.clone(),+ db.clone(),+ config.object_storage_bucket.clone(),+ ),+ ChunkIdFetcher::new(+ AppleProvider {},+ client.clone(),+ db.clone(),+ config.object_storage_bucket.clone(),+ ),+ ChunkIdFetcher::new(+ NativeProvider {},+ client.clone(),+ db.clone(),+ config.object_storage_bucket.clone(),+ ),+ )+ }++ fn native_frame_at(instruction_addr: u64, image_addr: u64) -> RawNativeFrame {+ RawNativeFrame {+ instruction_addr: Some(format!("0x{instruction_addr:x}")),+ symbol_addr: None,+ image_addr: Some(format!("0x{image_addr:x}")),+ lang: Some("rust".to_string()),+ module: Some("test_binary".to_string()),+ function: None,+ filename: None,+ lineno: None,+ colno: None,+ meta: CommonFrameMetadata::default(),+ }+ }++ #[test]+ fn lang_for_maps_source_extensions() {+ // native_frame_at carries lang hint "rust"+ let frame = native_frame_at(0x1000, 0x1000);++ assert_eq!(frame.lang_for(Some("src/main.rs")), "rust");+ assert_eq!(frame.lang_for(Some("foo.c")), "c");+ assert_eq!(frame.lang_for(Some("foo.cpp")), "cpp");+ // C++ headers must not be mislabeled as C+ assert_eq!(frame.lang_for(Some("foo.hpp")), "cpp");+ assert_eq!(frame.lang_for(Some("foo.hh")), "cpp");+ assert_eq!(frame.lang_for(Some("foo.hxx")), "cpp");+ // Plain `.h` is ambiguous, so it stays C+ assert_eq!(frame.lang_for(Some("foo.h")), "c");+ // Unknown / extension-less falls back to the SDK-provided lang hint+ assert_eq!(frame.lang_for(Some("README")), "rust");+ assert_eq!(frame.lang_for(None), "rust");+ }++ fn debug_image_at(debug_id: &str, image_addr: u64) -> DebugImage {+ DebugImage {+ debug_id: debug_id.to_string(),+ image_addr: format!("0x{image_addr:x}"),+ image_vmaddr: None,+ image_size: Some(0x100000),+ code_file: Some("/app/test_binary".to_string()),+ image_type: Some("elf".to_string()),+ arch: Some("x86_64".to_string()),+ }+ }++ // Fixture facts (see tests/static/native/build.sh; constants extracted+ // from the symcache the same way cymbal builds it):+ // test_binary_nopie: debug_id 7561847b-1054-7eb3-7763-4415adfaa134,+ // load_address 0x1000000, inner_function at 0x14a0+ // test_binary_pie: debug_id 850c70a2-6592-a70c-3e49-c0e443794d23,+ // load_address 0x0, inner_function at 0x14a0+ // test_binary_inline: debug_id 140ab543-c098-09dc-22b6-11f72e46d6fe,+ // lookup(0x1474) -> inlined_leaf / inner_function / outer_function+ // test_rust_binary: debug_id d1dea836-4ad3-daad-dd96-0e8626f766e1,+ // charge at 0x10640, lookup(0x10644) ->+ // core::hint::black_box inlined into charge++ /// Non-PIE ELF: the binary links at a fixed base (0x1000000) and loads+ /// there unchanged, so image_addr equals the link-time base.+ #[sqlx::test(migrations = "./tests/test_migrations")]+ async fn test_native_symbolication_elf_non_pie(db: sqlx::PgPool) {+ use crate::frames::RawFrame;++ const ELF: &[u8] = include_bytes!("../../../../tests/static/native/test_binary_nopie");+ let chunk_id = "7561847b-1054-7eb3-7763-4415adfaa134";+ let catalog = catalog_for_chunk(&db, chunk_id, zip_fixture(ELF, None)).await;++ let image_base = 0x1000000u64;+ // 0x14a8 is inside inner_function (entry 0x14a0); the -1 call-site+ // adjustment keeps the lookup inside the function body.+ let frame = RawFrame::Native(native_frame_at(image_base + 0x14a8, image_base));+ let debug_images = vec![debug_image_at(chunk_id, image_base)];++ let resolved = frame+ .resolve(1, &catalog, &debug_images, 15)+ .await+ .unwrap()+ .pop()+ .unwrap();++ assert!(resolved.resolved, "{:?}", resolved.resolve_failure);+ assert_eq!(resolved.resolved_name.as_deref(), Some("inner_function"));+ assert_eq!(resolved.source.as_deref(), Some("test_binary.c"));+ assert_eq!(resolved.lang, "c");+ assert!(resolved.line.is_some());+ }++ /// PIE ELF: links at base 0 and gets an ASLR slide at runtime; the+ /// relative address math must recover the link-time offset.+ #[sqlx::test(migrations = "./tests/test_migrations")]+ async fn test_native_symbolication_elf_pie_with_aslr_slide(db: sqlx::PgPool) {+ use crate::frames::RawFrame;++ const ELF: &[u8] = include_bytes!("../../../../tests/static/native/test_binary_pie");+ let chunk_id = "850c70a2-6592-a70c-3e49-c0e443794d23";+ let catalog = catalog_for_chunk(&db, chunk_id, zip_fixture(ELF, None)).await;++ let slide_base = 0x7f1234560000u64;+ let frame = RawFrame::Native(native_frame_at(slide_base + 0x14a8, slide_base));+ let debug_images = vec![debug_image_at(chunk_id, slide_base)];++ let resolved = frame+ .resolve(1, &catalog, &debug_images, 15)+ .await+ .unwrap()+ .pop()+ .unwrap();++ assert!(resolved.resolved, "{:?}", resolved.resolve_failure);+ assert_eq!(resolved.resolved_name.as_deref(), Some("inner_function"));+ assert_eq!(resolved.source.as_deref(), Some("test_binary.c"));+ assert!(resolved.line.is_some());+ }++ /// One raw frame at an address inside two levels of inlining expands into+ /// three logical frames (outermost first), each with source context from+ /// the bundled `__source/` files.+ #[sqlx::test(migrations = "./tests/test_migrations")]+ async fn test_native_inlined_frame_expansion_with_source(db: sqlx::PgPool) {+ use crate::frames::RawFrame;++ const ELF: &[u8] = include_bytes!("../../../../tests/static/native/test_binary_inline");+ const SOURCE: &str = include_str!("../../../../tests/static/native/test_binary_inline.c");+ let chunk_id = "140ab543-c098-09dc-22b6-11f72e46d6fe";+ let zip = zip_fixture(+ ELF,+ Some(("/cymbal_tests/native/test_binary_inline.c", SOURCE)),+ );+ let catalog = catalog_for_chunk(&db, chunk_id, zip).await;++ let slide_base = 0x7f0000000000u64;+ // 0x1475: after the -1 adjustment the lookup lands on 0x1474, inside+ // inlined_leaf as inlined (via inner_function) into outer_function.+ let frame = RawFrame::Native(native_frame_at(slide_base + 0x1475, slide_base));+ let debug_images = vec![debug_image_at(chunk_id, slide_base)];++ let frames = frame.resolve(1, &catalog, &debug_images, 15).await.unwrap();++ assert_eq!(+ frames.len(),+ 3,+ "expected 3 frames (inlined expansion), got: {frames:#?}"+ );+ assert!(frames.iter().all(|f| f.resolved));++ // Outermost first, innermost last+ assert_eq!(frames[0].resolved_name, Some("outer_function".to_string()));+ assert_eq!(frames[1].resolved_name, Some("inner_function".to_string()));+ assert_eq!(frames[2].resolved_name, Some("inlined_leaf".to_string()));++ for (i, frame) in frames.iter().enumerate() {+ assert!(+ frame.context.is_some(),+ "frame[{i}] ({:?}) has no source context",+ frame.resolved_name+ );+ }++ let leaf_ctx = frames[2].context.as_ref().unwrap();+ let all_lines: Vec<&str> = leaf_ctx+ .before+ .iter()+ .chain(std::iter::once(&leaf_ctx.line))+ .chain(leaf_ctx.after.iter())+ .map(|l| l.line.as_str())+ .collect();+ assert!(+ all_lines.iter().any(|l| l.contains("volatile int x = 99")),+ "expected 'volatile int x = 99' in inlined_leaf context, got: {all_lines:?}"+ );+ }++ /// A rustc-built binary: mangled symbols demangle to rust paths, the+ /// resolved filename drives `lang`, and std inlining expands.+ #[sqlx::test(migrations = "./tests/test_migrations")]+ async fn test_native_rust_symbol_demangling(db: sqlx::PgPool) {+ use crate::frames::RawFrame;++ // Committed compressed: a rustc binary carries debug info for all of+ // std, so even with line-tables-only + LTO it is megabytes raw.+ const ELF_ZST: &[u8] =+ include_bytes!("../../../../tests/static/native/test_rust_binary.zst");+ let elf = zstd::decode_all(ELF_ZST).unwrap();+ let chunk_id = "d1dea836-4ad3-daad-dd96-0e8626f766e1";+ let catalog = catalog_for_chunk(&db, chunk_id, zip_fixture(&elf, None)).await;++ let slide_base = 0x7f0000000000u64;+ // 0x10645: after the -1 adjustment the lookup lands on 0x10644, inside+ // core::hint::black_box as inlined into checkout::payment::charge.+ let frame = RawFrame::Native(native_frame_at(slide_base + 0x10645, slide_base));+ let debug_images = vec![debug_image_at(chunk_id, slide_base)];++ let frames = frame.resolve(1, &catalog, &debug_images, 15).await.unwrap();++ assert_eq!(frames.len(), 2, "expected 2 frames, got: {frames:#?}");+ assert!(frames.iter().all(|f| f.resolved));++ // Outermost: our function, demangled from the rustc-mangled symbol+ assert_eq!(+ frames[0].resolved_name.as_deref(),+ Some("test_rust::checkout::payment::charge")+ );+ assert_eq!(frames[0].source.as_deref(), Some("test_rust.rs"));+ assert_eq!(frames[0].line, Some(9));+ assert_eq!(frames[0].lang, "rust");++ // Innermost: the std function inlined into it+ assert!(+ frames[1]+ .resolved_name+ .as_deref()+ .is_some_and(|n| n.contains("black_box")),+ "expected black_box, got {:?}",+ frames[1].resolved_name+ );+ assert_eq!(frames[1].lang, "rust");+ }++ /// Native frames resolve against `AppleDsym` containers too, so macOS+ /// binaries uploaded via `posthog-cli dsym upload` work without re-upload.+ #[sqlx::test(migrations = "./tests/test_migrations")]+ async fn test_native_resolves_apple_dsym_container(db: sqlx::PgPool) {+ use crate::frames::RawFrame;++ const DSYM_ZIP: &[u8] =+ include_bytes!("../../../../tests/static/apple/test_binary.dSYM.zip");+ let wrapped = posthog_symbol_data::write_symbol_data(posthog_symbol_data::AppleDsym {+ data: DSYM_ZIP.to_vec(),+ })+ .unwrap();++ let chunk_id = "f70b89dc-3eb9-d3aa-d6a0-3b0c87cb0c45";+ let catalog = catalog_for_chunk(&db, chunk_id, wrapped).await;++ // Same address facts as the apple test for this dSYM: 0x100000334 is+ // inside inner_function with the image loaded at 0x100000000.+ let frame = RawFrame::Native(native_frame_at(0x100000334, 0x100000000));+ let debug_images = vec![debug_image_at(chunk_id, 0x100000000)];++ let resolved = frame+ .resolve(1, &catalog, &debug_images, 15)+ .await+ .unwrap()+ .pop()+ .unwrap();++ assert!(resolved.resolved, "{:?}", resolved.resolve_failure);+ assert_eq!(resolved.resolved_name.as_deref(), Some("inner_function"));+ }++ /// Missing symbol set: the frame falls back to client-side enrichment and+ /// records the failure reason instead of erroring the event.+ #[sqlx::test(migrations = "./tests/test_migrations")]+ async fn test_native_missing_symbol_set_falls_back(db: sqlx::PgPool) {+ use crate::frames::RawFrame;++ const ELF: &[u8] = include_bytes!("../../../../tests/static/native/test_binary_pie");+ let catalog = catalog_for_chunk(+ &db,+ "850c70a2-6592-a70c-3e49-c0e443794d23",+ zip_fixture(ELF, None),+ )+ .await;++ let base = 0x7f0000000000u64;+ let mut raw = native_frame_at(base + 0x14a8, base);+ raw.function = Some("client::resolved::name".to_string());+ raw.filename = Some("src/lib.rs".to_string());+ raw.lineno = Some(7);+ let frame = RawFrame::Native(raw);+ // The frame's image points at a debug_id that was never uploaded+ let debug_images = vec![debug_image_at("not-uploaded-debug-id", base)];++ let resolved = frame+ .resolve(1, &catalog, &debug_images, 15)+ .await+ .unwrap()+ .pop()+ .unwrap();++ assert!(!resolved.resolved);+ assert!(resolved.resolve_failure.is_some());+ assert_eq!(+ resolved.resolved_name.as_deref(),+ Some("client::resolved::name")+ );+ assert_eq!(resolved.source.as_deref(), Some("src/lib.rs"));+ assert_eq!(resolved.line, Some(7));+ assert_eq!(resolved.lang, "rust");+ }}diff --git a/rust/cymbal/src/core/types/langs/rust.rs b/rust/cymbal/src/core/types/langs/rust.rsdeleted file mode 100644index 3cee3d5a3cfe..000000000000--- a/rust/cymbal/src/core/types/langs/rust.rs+++ /dev/null@@ -1,63 +0,0 @@-use common_types::error_tracking::FrameId;-use serde::{Deserialize, Serialize};-use sha2::{Digest, Sha512};--use crate::{frames::Frame, langs::CommonFrameMetadata};--#[derive(Debug, Clone, Deserialize, Serialize)]-pub struct RawRustFrame {- pub function: Option<String>,- pub filename: Option<String>,- pub lineno: Option<u32>,- pub colno: Option<u32>,- pub module: Option<String>,- #[serde(default)]- pub resolved: bool,- #[serde(flatten)]- meta: CommonFrameMetadata,-}--impl RawRustFrame {- pub fn frame_id(&self) -> String {- let mut hasher = Sha512::new();-- self.filename- .as_ref()- .inspect(|f| hasher.update(f.as_bytes()));- hasher.update(self.function.as_deref().unwrap_or_default().as_bytes());- hasher.update(self.lineno.unwrap_or_default().to_be_bytes());- hasher.update(self.colno.unwrap_or_default().to_be_bytes());- hasher.update(b"rust");- self.module- .as_ref()- .inspect(|m| hasher.update(m.as_bytes()));- format!("{:x}", hasher.finalize())- }-}--impl From<&RawRustFrame> for Frame {- fn from(value: &RawRustFrame) -> Self {- let function = value.function.clone().unwrap_or_default();-- Frame {- frame_id: FrameId::placeholder(),- mangled_name: function,- line: value.lineno,- column: value.colno,- source: value.filename.clone(),- in_app: value.meta.in_app,- resolved_name: value.function.clone(),- lang: "rust".to_string(),- resolved: value.resolved,- resolve_failure: None,-- junk_drawer: None,- context: None,- release: None,- synthetic: value.meta.synthetic,- suspicious: false,- module: value.module.clone(),- code_variables: None,- }- }-}diff --git a/rust/cymbal/src/modes/processing/stages/resolution/exception.rs b/rust/cymbal/src/modes/processing/stages/resolution/exception.rsindex 50215222e3b0..b079bb490f99 100644--- a/rust/cymbal/src/modes/processing/stages/resolution/exception.rs+++ b/rust/cymbal/src/modes/processing/stages/resolution/exception.rs@@ -91,8 +91,8 @@ mod test {symbolication::symbol::{local::LocalSymbolResolver, SymbolResolver},symbolication::symbol_store::{apple::AppleProvider, chunk_id::ChunkIdFetcher, hermesmap::HermesMapProvider,- proguard::ProguardProvider, saving::SymbolSetRecord, sourcemap::SourcemapProvider,- Catalog, MockS3Client,+ native::NativeProvider, proguard::ProguardProvider, saving::SymbolSetRecord,+ sourcemap::SourcemapProvider, Catalog, MockS3Client,},types::{Exception, Stacktrace},};@@ -163,7 +163,14 @@ mod test {config.resolver.object_storage_bucket.clone(),);- let c = Catalog::new(smp, hmp, pgp, apple);+ let native = ChunkIdFetcher::new(+ NativeProvider {},+ client.clone(),+ db.clone(),+ config.resolver.object_storage_bucket.clone(),+ );++ let c = Catalog::new(smp, hmp, pgp, apple, native);let frame = RawJavaFrame {module: "a1.d".to_string(),diff --git a/rust/cymbal/tests/resolve.rs b/rust/cymbal/tests/resolve.rsindex 418e19a440aa..6e6fcc047511 100644--- a/rust/cymbal/tests/resolve.rs+++ b/rust/cymbal/tests/resolve.rs@@ -12,6 +12,7 @@ use cymbal::{caching::{Caching, SymbolSetCache},chunk_id::OrChunkId,hermesmap::HermesMapProvider,+ native::NativeProvider,proguard::ProguardProvider,sourcemap::{OwnedSourceMapCache, SourcemapProvider},Catalog, Fetcher, Parser,@@ -132,7 +133,11 @@ async fn end_to_end_resolver_test() {inner: AppleProvider {},};- let catalog = Catalog::new(Caching::new(wrapped, cache), hmp, pgp, apple);+ let native = NoOpChunkIdFetcher {+ inner: NativeProvider {},+ };++ let catalog = Catalog::new(Caching::new(wrapped, cache), hmp, pgp, apple, native);let mut resolved_frames = Vec::new();for frame in test_stack {diff --git a/rust/cymbal/tests/static/native/build.sh b/rust/cymbal/tests/static/native/build.shnew file mode 100755index 000000000000..582f192ab22b--- /dev/null+++ b/rust/cymbal/tests/static/native/build.sh@@ -0,0 +1,56 @@+#!/usr/bin/env bash+# Builds the checked-in ELF test fixtures for native symbolication tests.+#+# Requirements:+# - zig (any recent version; used as a hermetic x86_64-linux cross C compiler/linker)+# - rustup with the x86_64-unknown-linux-gnu target installed+# (rustup target add x86_64-unknown-linux-gnu)+#+# DWARF source paths are remapped to the stable prefix /cymbal_tests/native so+# the baked-in test assertions don't depend on the build machine. The binaries+# are never executed by tests — they only need valid DWARF + build ids.+#+# After rebuilding, the address constants in cymbal's native tests must be+# refreshed (they are derived from the symcache; see the comments next to the+# constants in src/langs/native.rs tests).++set -euo pipefail+cd "$(dirname "$0")"++CFLAGS=(-target x86_64-linux-gnu -g -O1 "-fdebug-prefix-map=$PWD=/cymbal_tests/native" -Wl,--build-id=sha1)++# Non-PIE (zig's default): fixed link base, exercises the non-zero+# load-address math.+zig cc "${CFLAGS[@]}" -fno-PIE -o test_binary_nopie test_binary.c++# PIE: link base 0, exercises the ASLR-slide math.+zig cc "${CFLAGS[@]}" -fPIE -pie -o test_binary_pie test_binary.c++# Inline expansion fixture (PIE).+zig cc "${CFLAGS[@]}" -fPIE -pie -o test_binary_inline test_binary_inline.c++# Rust fixture: real rustc-mangled symbols for the demangling assertions.+# zig is used as the cross linker via the zigcc-x86_64-linux wrapper.+cat > .zigcc-x86_64-linux <<'WRAP'+#!/usr/bin/env bash+exec zig cc -target x86_64-linux-gnu "$@"+WRAP+chmod +x .zigcc-x86_64-linux+# rustup explicitly: dev environments often put a non-rustup rustc (without+# cross targets) first in PATH.+# line-tables-only + fat LTO keep the fixture small while matching the+# debug-info profile we recommend for production Rust builds. The binary is+# committed zstd-compressed; tests decompress it in memory.+rustup run stable rustc --target x86_64-unknown-linux-gnu \+ -C debuginfo=line-tables-only -O -C lto=fat -C codegen-units=1 -C panic=abort \+ --remap-path-prefix "$PWD=/cymbal_tests/native" \+ -C linker="$PWD/.zigcc-x86_64-linux" \+ -C link-arg=-Wl,--build-id=sha1 \+ -o test_rust_binary test_rust.rs+rm .zigcc-x86_64-linux+zstd -19 -f -q test_rust_binary+rm test_rust_binary++echo "Built fixtures:"+file test_binary_nopie test_binary_pie test_binary_inline+ls -la test_rust_binary.zstdiff --git a/rust/cymbal/tests/static/native/test_binary.c b/rust/cymbal/tests/static/native/test_binary.cnew file mode 100644index 000000000000..1b337e016ab7--- /dev/null+++ b/rust/cymbal/tests/static/native/test_binary.c@@ -0,0 +1,19 @@+// Minimal test binary for ELF/DWARF symbolication testing.+// Built for x86_64-linux in both PIE and non-PIE flavors — see build.sh.++void inner_function(void) {+ // Line 6 - this should be symbolicated+ volatile int x = 42;+ (void)x;+}++void outer_function(void) {+ // Line 12+ inner_function();+}++int main(void) {+ // Line 17+ outer_function();+ return 0;+}diff --git a/rust/cymbal/tests/static/native/test_binary_inline b/rust/cymbal/tests/static/native/test_binary_inlinenew file mode 100755index 000000000000..d18d02aa827aBinary files /dev/null and b/rust/cymbal/tests/static/native/test_binary_inline differdiff --git a/rust/cymbal/tests/static/native/test_binary_inline.c b/rust/cymbal/tests/static/native/test_binary_inline.cnew file mode 100644index 000000000000..76f7cc0a1ed2--- /dev/null+++ b/rust/cymbal/tests/static/native/test_binary_inline.c@@ -0,0 +1,25 @@+// Test binary with inlined functions for DWARF inline expansion testing.++__attribute__((always_inline))+static inline void inlined_leaf(void) {+ // Line 5 - this is always inlined into its caller+ volatile int x = 99;+ (void)x;+}++__attribute__((always_inline))+inline void inner_function(void) {+ // Line 12+ inlined_leaf(); // inlined_leaf gets inlined here+}++void outer_function(void) {+ // Line 17+ inner_function(); // both layers get inlined here+}++int main(void) {+ // Line 22+ outer_function();+ return 0;+}diff --git a/rust/cymbal/tests/static/native/test_binary_nopie b/rust/cymbal/tests/static/native/test_binary_nopienew file mode 100755index 000000000000..e7b91824797bBinary files /dev/null and b/rust/cymbal/tests/static/native/test_binary_nopie differdiff --git a/rust/cymbal/tests/static/native/test_binary_pie b/rust/cymbal/tests/static/native/test_binary_pienew file mode 100755index 000000000000..880dc3a87514Binary files /dev/null and b/rust/cymbal/tests/static/native/test_binary_pie differdiff --git a/rust/cymbal/tests/static/native/test_rust.rs b/rust/cymbal/tests/static/native/test_rust.rsnew file mode 100644index 000000000000..40dc256f4258--- /dev/null+++ b/rust/cymbal/tests/static/native/test_rust.rs@@ -0,0 +1,18 @@+// Minimal Rust test binary for ELF/DWARF symbolication testing, exercising+// rustc symbol mangling (demangled server-side via symbolic). See build.sh.++mod checkout {+ pub mod payment {+ #[inline(never)]+ pub fn charge() {+ // Line 9 - this should be symbolicated and demangled+ let x = std::hint::black_box(42);+ let _ = x;+ }+ }+}++fn main() {+ // Line 17+ checkout::payment::charge();+}diff --git a/rust/cymbal/tests/static/native/test_rust_binary.zst b/rust/cymbal/tests/static/native/test_rust_binary.zstnew file mode 100755index 000000000000..2b99cc006c0cBinary files /dev/null and b/rust/cymbal/tests/static/native/test_rust_binary.zst differ