: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(error-tracking): scope Flutter AOT source uploads (#124249)
Hugues Pouillote1e70f8e4f95
diff --git a/cli/.sampo/changesets/sullen-runesinger-kalma.md b/cli/.sampo/changesets/sullen-runesinger-kalma.mdnew file mode 100644index 000000000000..b514697a4572--- /dev/null+++ b/cli/.sampo/changesets/sullen-runesinger-kalma.md@@ -0,0 +1,5 @@+---+cargo/posthog-cli: minor+---++Support Flutter AOT symbols and opt-in app source contextdiff --git a/cli/README.md b/cli/README.mdindex 777fb8937e00..2f120c7744c0 100644--- a/cli/README.md+++ b/cli/README.md@@ -102,7 +102,15 @@ A single command handles both desktop/server formats:- **macOS (Apple `.dSYM`):** dSYM bundles are packaged through the same path as `posthog-cli dsym upload`. That path shells out to `dwarfdump` (bundled with Xcode), so it only runs on macOS — if `dwarfdump` is missing, the bundle is reported and skipped while any ELF symbols in the same directory still upload.- **macOS (Mach-O executables):** binaries that embed their own DWARF upload directly, keyed by their `LC_UUID`; universal (fat) binaries upload one symbol set per architecture slice. This branch is cross-platform. It exists mainly for Go, which never produces a dSYM (`dsymutil` reports "no debug symbols in executable") — but note Go compresses the embedded DWARF by default, which symbolication can't read yet, so build with `-ldflags=-compressdwarf=false`. C/Swift/Rust executables normally carry no embedded DWARF; upload their dSYMs instead.-Pass `--include-source` to bundle the referenced source files for richer context around frames.+Pass `--include-source` to bundle referenced source files for context around frames.+For Flutter `.symbols` files, add `--source-root <app-directory>` to include only source files inside your app directory:++```bash+posthog-cli symbol-sets upload --directory ./build/debug-info --include-source --source-root ./lib+```++This option limits uploaded source files, not the debug symbols scanned under `--directory`.+Upload from the build machine while those source files are still available.The standalone `posthog-cli dsym upload` command is unchanged and still recommended for dSYM-only Xcode build phases, where it also reads release and version metadata from each bundle's `Info.plist`.diff --git a/cli/src/debug_symbols/mod.rs b/cli/src/debug_symbols/mod.rsindex 3cd9b964b5a4..29a48f343c2e 100644--- a/cli/src/debug_symbols/mod.rs+++ b/cli/src/debug_symbols/mod.rs@@ -66,6 +66,7 @@ impl DebugSymbolFile {self,release_id: Option<String>,include_source: bool,+ source_root: Option<&Path>,) -> Result<SymbolSetUpload> {use std::io::{Cursor, Write};@@ -81,11 +82,11 @@ impl DebugSymbolFile {if include_source {match source_bundle::extract_source_paths_from_dwarf_bytes(&self.data) {Ok(all_paths) => {- let filtered = filter_native_source_paths(&all_paths);- info!(- "Found {} source paths in DWARF ({} after filtering)",- all_paths.len(),- filtered.len()+ let filtered = source_bundle::filter_source_paths_for_upload(+ &all_paths,+ source_root,+ &self.path,+ is_native_source_path,);if !filtered.is_empty() {match source_bundle::collect_source_files(&filtered) {@@ -126,28 +127,22 @@ impl DebugSymbolFile {}}-/// Filter DWARF source paths for native (Rust/C/C++) builds: on top of the-/// shared system-path filters, drop registry/toolchain sources that aren't-/// part of the user's project tree. Go toolchain sources are already trimmed-/// inside the shared extraction (see `filter_go_toolchain_sources`).-fn filter_native_source_paths(paths: &[String]) -> Vec<&str> {- source_bundle::filter_source_paths(paths)- .into_iter()- .filter(|path| {- const EXCLUDED: &[&str] = &[- "/.cargo/registry/",- "/.cargo/git/",- "/rustc/",- "/.rustup/toolchains/",- "/vendor/",- ];- if EXCLUDED.iter().any(|sub| path.contains(sub)) {- tracing::debug!("Filtered out (native toolchain): {}", path);- return false;- }- true- })- .collect()+/// Drop native registry/toolchain sources outside the user's project tree.+/// Go toolchain sources are already trimmed inside the shared extraction+/// (see `filter_go_toolchain_sources`).+fn is_native_source_path(path: &str) -> bool {+ const EXCLUDED: &[&str] = &[+ "/.cargo/registry/",+ "/.cargo/git/",+ "/rustc/",+ "/.rustup/toolchains/",+ "/vendor/",+ ];+ if EXCLUDED.iter().any(|sub| path.contains(sub)) {+ tracing::debug!("Filtered out (native toolchain): {}", path);+ return false;+ }+ true}/// Walk `directory` and classify everything that looks like native debug@@ -440,10 +435,14 @@ pub fn report_problems(report: &DiscoveryReport, directory: &Path) -> Result<()>////// Uploads come back with no release id; the caller stamps one (if any) after it/// knows there is something to upload, so a fully-skipped run leaves no release.-pub fn package_dsym_bundles(bundles: &[PathBuf], include_source: bool) -> Vec<SymbolSetUpload> {+pub fn package_dsym_bundles(+ bundles: &[PathBuf],+ include_source: bool,+ source_root: Option<&Path>,+) -> Vec<SymbolSetUpload> {let mut uploads = Vec::new();for bundle in bundles {- match DsymFile::new(bundle, include_source) {+ match DsymFile::new(bundle, include_source, source_root) {Ok(dsym_file) => {info!("Processing dSYM {} (UUIDs: {})",diff --git a/cli/src/debug_symbols/upload.rs b/cli/src/debug_symbols/upload.rsindex 73d71353afbf..89aed076d827 100644--- a/cli/src/debug_symbols/upload.rs+++ b/cli/src/debug_symbols/upload.rs@@ -36,6 +36,10 @@ pub struct Args {/// Implies --force unless --skip-on-conflict is set.#[arg(long, default_value_t = false)]pub include_source: bool,++ /// Limit uploaded source files to this directory. Requires --include-source.+ #[arg(long, requires = "include_source")]+ pub source_root: Option<PathBuf>,}pub fn upload(args: &Args) -> Result<()> {@@ -44,8 +48,24 @@ pub fn upload(args: &Args) -> Result<()> {release,conflict,include_source,+ source_root,} = args;let release_args = release.resolve_info_plist()?;+ let source_root = source_root+ .as_ref()+ .map(|root| -> Result<PathBuf> {+ let root = root.canonicalize().map_err(|e| {+ anyhow!(+ "Source root {} canonicalization failed: {e}",+ root.display()+ )+ })?;+ if !root.is_dir() {+ anyhow::bail!("Source root {} is not a directory", root.display());+ }+ Ok(root)+ })+ .transpose()?;let directory = directory.canonicalize().map_err(|e| {anyhow!(@@ -80,12 +100,16 @@ pub fn upload(args: &Args) -> Result<()> {file.path.display(),file.debug_id);- native_uploads.push(file.into_upload(None, *include_source)?);+ native_uploads.push(file.into_upload(None, *include_source, source_root.as_deref())?);}// A failed or oversized dSYM leaves a matching standalone Mach-O as the// fallback. Successfully packaged, uploadable dSYMs take priority.- let dsym_uploads = package_dsym_bundles(&report.dsym_bundles, *include_source);+ let dsym_uploads = package_dsym_bundles(+ &report.dsym_bundles,+ *include_source,+ source_root.as_deref(),+ );let mut uploads = merge_uploads_prefer_dsym(dsym_uploads, native_uploads, MAX_FILE_SIZE);if uploads.is_empty() {diff --git a/cli/src/dsym/mod.rs b/cli/src/dsym/mod.rsindex ca8d141111ed..4858f65bb3c6 100644--- a/cli/src/dsym/mod.rs+++ b/cli/src/dsym/mod.rs@@ -36,7 +36,7 @@ impl DsymFile {/// Each DWARF binary in the bundle gets its own ZIP so that/// stable UUIDs (e.g. app stubs) don't get a new content hash/// when a sibling binary (e.g. debug dylib) changes.- pub fn new(path: &PathBuf, include_source: bool) -> Result<Self> {+ pub fn new(path: &PathBuf, include_source: bool, source_root: Option<&Path>) -> Result<Self> {if !path.is_dir() {anyhow::bail!("Path {} is not a directory", path.display());}@@ -55,7 +55,7 @@ impl DsymFile {let mut entries = Vec::new();for (uuid, arch, dwarf_filename) in &uuid_entries {let dwarf_path = dwarf_dir.join(dwarf_filename);- let data = zip_dwarf_binary(&dwarf_path, arch, include_source)?;+ let data = zip_dwarf_binary(&dwarf_path, arch, include_source, source_root)?;entries.push(DsymEntry {uuid: uuid.clone(),data,@@ -154,9 +154,13 @@ fn extract_dsym_uuids(dsym_path: &PathBuf) -> Result<Vec<(String, String, String/// dwarf — the raw DWARF Mach-O binary (single-arch)/// __source/manifest.json — (optional) source file manifest/// __source/... — (optional) source files-fn zip_dwarf_binary(dwarf_path: &Path, arch: &str, include_source: bool) -> Result<Vec<u8>> {+fn zip_dwarf_binary(+ dwarf_path: &Path,+ arch: &str,+ include_source: bool,+ source_root: Option<&Path>,+) -> Result<Vec<u8>> {use std::io::{Cursor, Write};- use tracing::info;let mut buffer = Cursor::new(Vec::new());@@ -176,11 +180,11 @@ fn zip_dwarf_binary(dwarf_path: &Path, arch: &str, include_source: bool) -> Resuif include_source {match source_bundle::extract_source_paths_from_dwarf(dwarf_path) {Ok(all_paths) => {- let filtered = source_bundle::filter_source_paths(&all_paths);- info!(- "Found {} source paths in DWARF ({} after filtering)",- all_paths.len(),- filtered.len()+ let filtered = source_bundle::filter_source_paths_for_upload(+ &all_paths,+ source_root,+ dwarf_path,+ |_| true,);if !filtered.is_empty() {diff --git a/cli/src/dsym/source_bundle.rs b/cli/src/dsym/source_bundle.rsindex a97cc3649cd7..219fe9c3692d 100644--- a/cli/src/dsym/source_bundle.rs+++ b/cli/src/dsym/source_bundle.rs@@ -562,6 +562,48 @@ pub fn filter_source_paths(paths: &[String]) -> Vec<&str> {.collect()}+pub fn filter_source_paths_under_root<'a>(paths: &'a [String], root: &Path) -> Vec<&'a str> {+ let Ok(root) = root.canonicalize() else {+ return Vec::new();+ };+ filter_source_paths(paths)+ .into_iter()+ .filter(|path| {+ Path::new(path)+ .canonicalize()+ .is_ok_and(|resolved| resolved.starts_with(&root))+ })+ .collect()+}++pub fn filter_source_paths_for_upload<'a>(+ paths: &'a [String],+ source_root: Option<&Path>,+ binary_path: &Path,+ extra_filter: impl Fn(&str) -> bool,+) -> Vec<&'a str> {+ let filtered = match source_root {+ Some(root) => filter_source_paths_under_root(paths, root),+ None => filter_source_paths(paths),+ };+ let filtered: Vec<&str> = filtered+ .into_iter()+ .filter(|path| extra_filter(path))+ .collect();+ info!(+ "Found {} source paths in DWARF ({} after filtering)",+ paths.len(),+ filtered.len()+ );+ if filtered.is_empty() && source_root.is_some() {+ warn!(+ "No readable sources found inside the source root for {}",+ binary_path.display()+ );+ }+ filtered+}+/// Collect source files from disk, reading each file referenced by DWARF debug info.////// Since the CLI runs on the build machine, the absolute paths from DWARF are valid.@@ -723,8 +765,8 @@ pub fn load_sources_from_zip(#[cfg(test)]mod tests {use super::{- build_zip_relative_paths, filter_go_toolchain_sources, is_bundleable_go_source,- read_source_file,+ build_zip_relative_paths, collect_source_files, filter_go_toolchain_sources,+ filter_source_paths_under_root, is_bundleable_go_source, read_source_file,};#[test]@@ -766,6 +808,32 @@ mod tests {}}+ #[test]+ fn source_root_only_includes_files_inside_the_app() {+ let dir = tempfile::tempdir().unwrap();+ let app = dir.path().join("app");+ let framework = dir.path().join("app-framework");+ std::fs::create_dir_all(app.join("lib")).unwrap();+ std::fs::create_dir_all(&framework).unwrap();+ let source = app.join("lib/main.dart");+ let outside = framework.join("main.dart");+ std::fs::write(&source, "void main() {}").unwrap();+ std::fs::write(&outside, "void main() {}").unwrap();+ let paths = vec![+ source.to_string_lossy().into_owned(),+ outside.to_string_lossy().into_owned(),+ app.join("lib/../../app-framework/main.dart")+ .to_string_lossy()+ .into_owned(),+ ];++ let filtered = filter_source_paths_under_root(&paths, &app);+ assert_eq!(filtered, vec![paths[0].as_str()]);+ let sources = collect_source_files(&filtered).unwrap();+ assert_eq!(sources.manifest.files.len(), 1);+ assert_eq!(sources.contents.values().next().unwrap(), b"void main() {}");+ }+#[test]fn symlinked_source_files_are_refused() {let dir = tempfile::tempdir().unwrap();diff --git a/cli/src/dsym/upload.rs b/cli/src/dsym/upload.rsindex 2236378b4725..861e46dba0eb 100644--- a/cli/src/dsym/upload.rs+++ b/cli/src/dsym/upload.rs@@ -191,7 +191,7 @@ pub fn upload(args: &Args) -> Result<()> {for dsym_path in dsym_paths {info!("Processing dSYM: {}", dsym_path.display());- match DsymFile::new(&dsym_path, *include_source) {+ match DsymFile::new(&dsym_path, *include_source, None) {Ok(mut dsym_file) => {dsym_file.release_id = chunk_release_id.clone();info!(diff --git a/cli/tests/debug_symbols.rs b/cli/tests/debug_symbols.rsindex f8a74274c286..1f27e69077a5 100644--- a/cli/tests/debug_symbols.rs+++ b/cli/tests/debug_symbols.rs@@ -4,6 +4,8 @@ use std::path::{Path, PathBuf};use posthog_cli::api::symbol_sets::{dedup_uploads_by_chunk_id, SymbolSetUpload};use posthog_cli::debug_symbols::{discover, elf_debug_id, package_dsym_bundles, report_problems};use posthog_cli::dsym::source_bundle::extract_source_paths_from_dwarf_bytes;+#[cfg(unix)]+use posthog_cli::dsym::source_bundle::read_source_manifest_from_zip;use posthog_symbol_data::{read_symbol_data, AppleDsym, ElfDebugInfo};/// The native ELF fixtures shared with cymbal's symbolication tests; built by@@ -72,7 +74,8 @@ fn extracts_debug_ids_matching_cymbal_fixtures() {#[test]fn discovers_and_packages_elf_files() {- let report = discover(&fixtures_dir()).unwrap();+ let dir = fixtures_dir();+ let report = discover(&dir).unwrap();// The four uncompressed ELF fixtures are found and valid, including the// aarch64-linux-android shared object, whose chunk id must match what an@@ -100,7 +103,7 @@ fn discovers_and_packages_elf_files() {.into_iter().find(|f| f.debug_id == "850c70a2-6592-a70c-3e49-c0e443794d23").unwrap();- let upload = file.into_upload(None, false).unwrap();+ let upload = file.into_upload(None, false, None).unwrap();assert_eq!(upload.chunk_id, "850c70a2-6592-a70c-3e49-c0e443794d23");let unwrapped: ElfDebugInfo = read_symbol_data(&upload.data).unwrap();@@ -109,6 +112,84 @@ fn discovers_and_packages_elf_files() {let mut magic = [0u8; 4];dwarf.read_exact(&mut magic).unwrap();assert_eq!(&magic, b"\x7fELF");++ #[cfg(unix)]+ {+ let source_root = tempfile::Builder::new()+ .prefix("srcpath__")+ .rand_bytes(6)+ .tempdir_in("/tmp")+ .unwrap();+ let root_path = source_root.path().to_str().unwrap();+ let fixture_root = "/cymbal_tests/native";+ assert_eq!(root_path.len(), fixture_root.len());+ let mut dwarf_data = std::fs::read(dir.join("test_binary_pie")).unwrap();+ let original_paths = extract_source_paths_from_dwarf_bytes(&dwarf_data).unwrap();+ let outside_dwarf_path = original_paths+ .iter()+ .find(|path| path.ends_with("/elf-init-2.33.c"))+ .unwrap();+ let outside_root = tempfile::tempdir_in("/tmp").unwrap();+ let outside_dwarf_dir = outside_dwarf_path.rsplit_once('/').unwrap().0;+ let nested_len = outside_dwarf_dir.len() - outside_root.path().to_str().unwrap().len() - 1;+ let outside_path = outside_root+ .path()+ .join("x".repeat(nested_len))+ .join("elf-init-2.33.c");+ std::fs::create_dir_all(outside_path.parent().unwrap()).unwrap();+ std::fs::write(&outside_path, b"outside source").unwrap();+ let mut rewrite_path = |original: &str, replacement: &str| {+ assert_eq!(original.len(), replacement.len());+ let mut replaced = 0;+ for index in 0..=dwarf_data.len() - original.len() {+ if &dwarf_data[index..index + original.len()] == original.as_bytes() {+ dwarf_data[index..index + original.len()]+ .copy_from_slice(replacement.as_bytes());+ replaced += 1;+ }+ }+ assert!(replaced > 0, "missing DWARF path: {original}");+ };+ rewrite_path(fixture_root, root_path);+ rewrite_path(+ outside_dwarf_dir,+ outside_path.parent().unwrap().to_str().unwrap(),+ );+ let source_path = source_root.path().join("test_binary.c");+ let source_contents = std::fs::read(dir.join("test_binary.c")).unwrap();+ std::fs::write(&source_path, &source_contents).unwrap();+ let paths = extract_source_paths_from_dwarf_bytes(&dwarf_data).unwrap();+ assert!(paths+ .iter()+ .any(|path| path == source_path.to_str().unwrap()));+ assert!(+ paths+ .iter()+ .any(|path| path == outside_path.to_str().unwrap()),+ "outside={outside_path:?}, extracted={paths:?}"+ );++ std::fs::write(source_root.path().join("test_binary_pie"), dwarf_data).unwrap();+ let report = discover(source_root.path()).unwrap();+ let upload = report+ .files+ .into_iter()+ .next()+ .unwrap()+ .into_upload(None, true, Some(source_root.path()))+ .unwrap();+ let unwrapped: ElfDebugInfo = read_symbol_data(&upload.data).unwrap();+ let mut zip = zip::ZipArchive::new(std::io::Cursor::new(unwrapped.data)).unwrap();+ let manifest = read_source_manifest_from_zip(&mut zip).unwrap();+ assert_eq!(manifest.files.len(), 1);+ let zip_path = manifest.files.get(source_path.to_str().unwrap()).unwrap();+ let mut bundled = Vec::new();+ zip.by_name(zip_path)+ .unwrap()+ .read_to_end(&mut bundled)+ .unwrap();+ assert_eq!(bundled, source_contents);+ }}#[test]@@ -188,7 +269,7 @@ fn discovers_and_packages_macho_executables() {assert_eq!(file.debug_id, elf_debug_id(&path).unwrap().to_uppercase());// Packaged as an AppleDsym container with the thin Mach-O at `dwarf`.- let upload = file.into_upload(None, false).unwrap();+ let upload = file.into_upload(None, false, None).unwrap();let unwrapped: AppleDsym = read_symbol_data(&upload.data).unwrap();assert_eq!(dwarf_magic(&unwrapped.data), [0xcf, 0xfa, 0xed, 0xfe]);}@@ -259,7 +340,7 @@ fn discovers_every_fat_macho_slice() {// the fat container: the server resolves one thin binary per chunk id.for (file, expected_slice) in report.files.into_iter().zip([&thin, &thin_b]) {assert_eq!(file.debug_id, file.debug_id.to_uppercase());- let upload = file.into_upload(None, false).unwrap();+ let upload = file.into_upload(None, false, None).unwrap();let unwrapped: AppleDsym = read_symbol_data(&upload.data).unwrap();let mut zip = zip::ZipArchive::new(std::io::Cursor::new(unwrapped.data)).unwrap();let mut dwarf = Vec::new();@@ -370,9 +451,9 @@ fn packages_elf_and_dsym_from_one_directory() {let mut uploads: Vec<SymbolSetUpload> = report.files.into_iter()- .map(|f| f.into_upload(None, false).unwrap())+ .map(|f| f.into_upload(None, false, None).unwrap()).collect();- uploads.extend(package_dsym_bundles(&report.dsym_bundles, false));+ uploads.extend(package_dsym_bundles(&report.dsym_bundles, false, None));let uploads = dedup_uploads_by_chunk_id(uploads);assert_eq!(uploads.len(), 2, "one ELF + one dSYM upload");diff --git a/rust/cymbal/src/core/symbolication/symbol_store/native.rs b/rust/cymbal/src/core/symbolication/symbol_store/native.rsindex 4f04fd956c62..48391f934fcf 100644--- a/rust/cymbal/src/core/symbolication/symbol_store/native.rs+++ b/rust/cymbal/src/core/symbolication/symbol_store/native.rs@@ -382,6 +382,71 @@ mod test {}}+ #[test]+ fn flutter_debug_symbols_resolve_dart_location_and_source() {+ use std::io::{Cursor, Write};++ use crate::langs::utils::get_context_lines;++ // The manifest must match the build path embedded in the fixture's DWARF.+ const SOURCE_PATH: &str =+ "/fixtures/flutter/native-symbolication-builds/sample/lib/main.dart";+ const SOURCE: &str = include_str!("../../../../tests/static/native/flutter_sample.dart");+ let artifacts: [(&[u8], u64); 2] = [+ (+ include_bytes!("../../../../tests/static/native/flutter_android_arm64.symbols.zst"),+ 0x205217,+ ),+ (+ include_bytes!("../../../../tests/static/native/flutter_ios_arm64.symbols.zst"),+ 0x14f1f7,+ ),+ ];++ for (compressed, address) in artifacts {+ let dwarf = zstd::decode_all(compressed).unwrap();+ for home_prefix in [b"/Users/".as_slice(), b"/home/".as_slice()] {+ assert!(+ !dwarf+ .windows(home_prefix.len())+ .any(|bytes| bytes == home_prefix),+ "fixture embeds an unredacted home directory"+ );+ }+ let mut zip = zip::ZipWriter::new(Cursor::new(Vec::new()));+ let options = zip::write::SimpleFileOptions::default();+ zip.start_file("dwarf", options).unwrap();+ zip.write_all(&dwarf).unwrap();+ zip.start_file("__source/manifest.json", options).unwrap();+ zip.write_all(+ serde_json::json!({"version": 1, "files": {SOURCE_PATH: "__source/main.dart"}})+ .to_string()+ .as_bytes(),+ )+ .unwrap();+ zip.start_file("__source/main.dart", options).unwrap();+ zip.write_all(SOURCE.as_bytes()).unwrap();+ let data = zip.finish().unwrap().into_inner();++ let symbols = ParsedNativeSymbols::from_zip_data(data.clone(), data.len()).unwrap();+ let frame = symbols.lookup(address).unwrap().remove(0);+ assert_eq!(frame.display_name, "main");+ assert_eq!(frame.full_path.as_deref(), Some(SOURCE_PATH));+ assert_eq!(frame.line, 7);+ let context = get_context_lines(+ symbols+ .get_source(frame.full_path.as_deref().unwrap())+ .unwrap()+ .lines(),+ (frame.line - 1) as usize,+ 3,+ )+ .unwrap();+ assert_eq!(context.line.number, 7);+ assert!(context.line.line.contains("runApp("));+ }+ }+#[test]fn source_lookup_matches_file_name_components_not_suffixes() {let symbols = symbols_with(&[("/src/foobar.c", "foo"), ("/abs/path/Foo.swift", "swift")]);diff --git a/rust/cymbal/src/core/types/langs/native.rs b/rust/cymbal/src/core/types/langs/native.rsindex 8f71c70c7c14..901e3e3b4b41 100644--- a/rust/cymbal/src/core/types/langs/native.rs+++ b/rust/cymbal/src/core/types/langs/native.rs@@ -133,7 +133,8 @@ pub struct RawNativeFrame {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.+ /// filename extension wins when available. Dart AOT frames use this hint+ /// to keep their exact program counter for DWARF lookup.pub lang: Option<String>,pub module: Option<String>,pub function: Option<String>,@@ -236,11 +237,14 @@ impl RawNativeFrame {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);+ // Dart's AOT stack decoder looks up reported PCs directly, including+ // synthetic async frames near function entries. Other native traces+ // report return addresses, so look up the preceding call instruction.+ let lookup_addr = if self.lang.as_deref() == Some("dart") {+ relative_addr+ } else {+ relative_addr.saturating_sub(1)+ };let symbols: Arc<ParsedNativeSymbols> = catalog.lookup(team_id, OrChunkId::chunk_id(debug_image.debug_id.clone()))@@ -497,6 +501,10 @@ impl RawNativeFrame {if self.inline {hasher.update(b"inline");}+ // A Dart lookup can resolve a different function at the same address.+ if self.lang.as_deref() == Some("dart") {+ hasher.update(b"dart-exact-pc");+ }hasher.update(b"native");format!("{:x}", hasher.finalize())@@ -967,6 +975,16 @@ mod test {let id_b = launch_b.frame_id(&[image_at("build-1", 0x104f00000)]);assert_eq!(id_a, id_b);+ let mut dart_a = launch_a.clone();+ dart_a.lang = Some("dart".to_string());+ let mut dart_b = launch_b.clone();+ dart_b.lang = Some("dart".to_string());+ assert_eq!(+ dart_a.frame_id(&[image_at("build-1", 0x100000000)]),+ dart_b.frame_id(&[image_at("build-1", 0x104f00000)])+ );+ assert_ne!(id_a, dart_a.frame_id(&[image_at("build-1", 0x100000000)]));+// Without a matching image the absolute address is hashed, so the ids differ.assert_ne!(launch_a.frame_id(&[]), launch_b.frame_id(&[]));}@@ -1165,6 +1183,42 @@ mod test {assert!(resolved.line.is_some());}+ #[sqlx::test(migrations = "./tests/test_migrations")]+ async fn test_flutter_aot_frame_at_function_entry_keeps_its_program_counter(db: sqlx::PgPool) {+ use crate::frames::RawFrame;++ const ELF: &[u8] =+ include_bytes!("../../../../tests/static/native/flutter_android_arm64.symbols.zst");+ const SOURCE: &str = include_str!("../../../../tests/static/native/flutter_sample.dart");+ let chunk_id = "098518b7-ef99-d0be-1ab8-0642060ddbf3";+ let dwarf = zstd::decode_all(ELF).unwrap();+ let zip = zip_fixture(+ &dwarf,+ Some((+ "/fixtures/flutter/native-symbolication-builds/sample/lib/main.dart",+ SOURCE,+ )),+ );+ let catalog = catalog_for_chunk(&db, chunk_id, zip).await;++ let image_base = 0x7000000000u64;+ let mut raw = native_frame_at(image_base + 0x205210, image_base);+ raw.lang = Some("dart".to_string());+ let debug_images = vec![debug_image_at(chunk_id, image_base)];+ let resolved = RawFrame::Native(raw)+ .resolve(1, &catalog, &debug_images, 3)+ .await+ .unwrap()+ .pop()+ .unwrap();++ assert!(resolved.resolved, "{:?}", resolved.resolve_failure);+ assert_eq!(resolved.resolved_name.as_deref(), Some("main"));+ assert_eq!(resolved.lang, "dart");+ assert_eq!(resolved.line, Some(7));+ assert!(resolved.context.unwrap().line.line.contains("runApp("));+ }+/// 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.diff --git a/rust/cymbal/tests/static/native/flutter_android_arm64.symbols.zst b/rust/cymbal/tests/static/native/flutter_android_arm64.symbols.zstnew file mode 100644index 000000000000..79df90ac69ddBinary files /dev/null and b/rust/cymbal/tests/static/native/flutter_android_arm64.symbols.zst differdiff --git a/rust/cymbal/tests/static/native/flutter_ios_arm64.symbols.zst b/rust/cymbal/tests/static/native/flutter_ios_arm64.symbols.zstnew file mode 100644index 000000000000..2d19735a3767Binary files /dev/null and b/rust/cymbal/tests/static/native/flutter_ios_arm64.symbols.zst differdiff --git a/rust/cymbal/tests/static/native/flutter_sample.dart b/rust/cymbal/tests/static/native/flutter_sample.dartnew file mode 100644index 000000000000..0cfbcd8cf50e--- /dev/null+++ b/rust/cymbal/tests/static/native/flutter_sample.dart@@ -0,0 +1,8 @@+import 'package:flutter/material.dart';++int calculateInventedValue(int input) => input * 7 + 3;++void main() {+ final value = calculateInventedValue(5);+ runApp(MaterialApp(home: Scaffold(body: Center(child: Text('Sample $value')))));+}