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

handle demangling OSX names with underscore prefix #924

Merged
merged 1 commit into from
Jan 25, 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
10 changes: 10 additions & 0 deletions internal/symbolizer/symbolizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ func demangleSingleFunction(fn *profile.Function, options []demangle.Option) {
fn.Name = demangled
return
}

// OSX has all the symbols prefixed with extra '_' so lets try
// once more without it
if strings.HasPrefix(fn.SystemName, "_") {
if demangled := demangle.Filter(fn.SystemName[1:], o...); demangled != fn.SystemName {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we just pass strings.StripPrefix(fn.SystemName, "_"), ... in the demangle.Filter call above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Above? So just cut all the time no matter OS and everything? Then it won't work, since _ is usually used for mangled names for regular OS-es. And cutting it will simply break everything.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, got it.

Can we add a test that will exercise this code path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack. Added test case.

fn.Name = demangled
return
}
}

// Could not demangle. Apply heuristics in case the name is
// already demangled.
name := fn.SystemName
Expand Down
5 changes: 5 additions & 0 deletions internal/symbolizer/symbolizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ func TestDemangleSingleFunction(t *testing.T) {
symbol: "_ZdaPv",
want: "operator delete[]",
},
{
// OSX prepends extra '_', which we're not able to remove. But we handle it when demangling.
symbol: "__ZdaPv",
want: "operator delete[]",
},
{
// Already demangled.
symbol: "operator delete[](void*)",
Expand Down
Loading