Skip to content

Commit

Permalink
fix(macho): Parse debug_str_offs section (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbayer authored Feb 4, 2025
1 parent 4fffc78 commit 07ad880
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Fixes**

- Parse `debug_str_offs` section in Mach-O files ([#895](https://github.com/getsentry/symbolic/pull/895))

## 12.13.3

**Improvements**
Expand Down
20 changes: 20 additions & 0 deletions symbolic-debuginfo/src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,3 +1487,23 @@ impl<'s> Iterator for DwarfFunctionIterator<'s> {
}

impl std::iter::FusedIterator for DwarfFunctionIterator<'_> {}

#[cfg(test)]
mod tests {
use super::*;

use crate::macho::MachObject;

#[cfg(feature = "macho")]
#[test]
fn test_loads_debug_str_offsets() {
// File generated using dsymutil

let data = std::fs::read("tests/fixtures/helloworld").unwrap();

let obj = MachObject::parse(&data).unwrap();

let sections = DwarfSections::from_dwarf(&obj);
assert_eq!(sections.debug_str_offsets.data.len(), 48);
}
}
10 changes: 9 additions & 1 deletion symbolic-debuginfo/src/macho/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ impl<'data> Dwarf<'data> for MachObject<'data> {
for section in segment.into_iter() {
let (header, data) = section.ok()?;
if let Ok(sec) = header.name() {
if sec.starts_with("__") && &sec[2..] == section_name {
if sec.starts_with("__") && map_section_name(&sec[2..]) == section_name {
// In some cases, dsymutil leaves sections headers but removes their
// data from the file. While the addr and size parameters are still
// set, `header.offset` is 0 in that case. We skip them just like the
Expand All @@ -490,6 +490,13 @@ impl<'data> Dwarf<'data> for MachObject<'data> {
}
}

/// See <https://llvm.org/doxygen/MachOObjectFile_8cpp_source.html#l05341>.
fn map_section_name(name: &str) -> &str {
match name {
"debug_str_offs" => "debug_str_offsets",
_ => name,
}
}
/// An iterator over symbols in the MachO file.
///
/// Returned by [`MachObject::symbols`](struct.MachObject.html#method.symbols).
Expand Down Expand Up @@ -801,6 +808,7 @@ impl<'slf, 'd: 'slf> AsSelf<'slf> for MachArchive<'d> {

#[cfg(test)]
mod tests {

use super::*;

#[test]
Expand Down
Binary file added symbolic-debuginfo/tests/fixtures/helloworld
Binary file not shown.

0 comments on commit 07ad880

Please sign in to comment.