Skip to content
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

fix(macho): Parse debug_str_offs section #895

Merged
merged 4 commits into from
Feb 4, 2025
Merged
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
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion fails without map_section_name.

}
}
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.
Loading