Skip to content

fix: line number support for unity 6.5 and newer - #2805

Open
bitsandfoxes wants to merge 12 commits into
mainfrom
feat/fix-symbols-unity-6.5
Open

fix: line number support for unity 6.5 and newer#2805
bitsandfoxes wants to merge 12 commits into
mainfrom
feat/fix-symbols-unity-6.5

Conversation

@bitsandfoxes

Copy link
Copy Markdown
Contributor

Context

In Unity 6.3 and older, when building the game you'd end up with an output folder looking like that

.
├── game-name_BackUpThisFolder_ButDontShipItWithYourGame
│   ├── GameAssembly.dSYM
│   ├── il2cppOutput
│   └── Managed
|        ├ all-the-dlls.dll
|        └ all-the-dlls.pdb
└── game-name.app

The Managed directory would contain all the stripped down .dll and matching .pdb files. Starting with 6.5 the Managed folder contains the .dll only. To get to the .pdb you will need to do a Development build and opt-in to Script Debugging. Not ideal.

What this does

These options provide the UnityLinker with the additional argument --link-symbols.

So starting with Unity 6.5 on top of adding --emit-source-mapping to IL2CPP we need to add this argument when the UnityLinker gets invoked. Since there are no callbacks and the backdoor of AdditionalIl2CppArguments only works for IL2CPP we're putting it on the environment in the pre-build-step to be picked up.

We'll need to find a less brittle way of getting to the debug symbols

Before

Screenshot 2026-08-07 at 15 14 31

After

Screenshot 2026-08-07 at 15 24 22

Testing

We're now also validating that the stack trace on the resulting events coming from the integration tests do have correct line numbers.

Comment thread src/Sentry.Unity.Editor/Il2CppBuildPreProcess.cs Outdated
@bitsandfoxes bitsandfoxes changed the title write additional unitylinker args fix: line number support for unity 6.5 and newer Aug 7, 2026
Comment thread src/Sentry.Unity.Editor/Il2CppBuildPreProcess.cs Outdated
bitsandfoxes and others added 2 commits August 7, 2026 17:59
Start Unity Editor with --link-symbols in its process environment to determine whether Linux Bee reads the setting before build preprocessing.

Refs #2805

Co-Authored-By: OpenCode <noreply@openai.com>
Comment thread .github/workflows/test-build-linux.yml Outdated
The process-start linker argument reached UnityLinker but did not restore Linux source resolution, so remove the temporary CI override.

Refs #2805

Co-Authored-By: OpenCode <noreply@openai.com>
Comment thread src/Sentry.Unity.Editor/Il2CppBuildPreProcess.cs Outdated
Comment thread test/IntegrationTest/Integration.Tests.ps1
Comment thread src/Sentry.Unity.Editor/Il2CppBuildPreProcess.cs Outdated
Comment thread test/IntegrationTest/Integration.Tests.ps1 Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8b55488. Configure here.

RemoveLinkSymbolsArgument(
() => Environment.GetEnvironmentVariable(UnityLinkerAdditionalArgumentsEnvironmentVariable),
arguments => Environment.SetEnvironmentVariable(UnityLinkerAdditionalArgumentsEnvironmentVariable, arguments));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cleanup strips pre-existing linker args

Medium Severity

OnPostprocessBuild always runs RemoveLinkSymbolsArgument, so any pre-existing --link-symbols in UNITYLINKER_ADDITIONAL_ARGS is removed even when Sentry did not add it—for example when the flag was already set, line-number support is off, or the build is not IL2CPP. The previous implementation restored the original value only when it had changed the variable.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8b55488. Configure here.

}

logger?.LogDebug("Removing additional UnityLinker argument '{0}'.", LinkSymbolsArgument);
setArguments.Invoke(arguments.Replace(LinkSymbolsArgument, "").Trim());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The use of string.Contains and string.Replace for build argument manipulation is not robust and can fail if another argument shares the same prefix, like --link-symbols-extended.
Severity: LOW

Suggested Fix

Instead of using string manipulation, parse the arguments string by splitting it by spaces. Check for the existence of the exact --link-symbols argument in the resulting list of tokens. To remove it, filter it out from the list and then rejoin the tokens with spaces.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/Sentry.Unity.Editor/SentryUnityLinkerProcessor.cs#L76

Potential issue: The code in `SentryUnityLinkerProcessor.cs` uses
`arguments.Contains(LinkSymbolsArgument)` and `arguments.Replace(LinkSymbolsArgument,
"")` to manage the `--link-symbols` build argument. This substring-based matching is
fragile. If a future Unity version introduces a related argument like
`--link-symbols-extended`, the current logic would fail. The `AddLinkSymbolsArgument`
function would incorrectly skip adding the argument, and `RemoveLinkSymbolsArgument`
would corrupt the existing argument by removing the `--link-symbols` prefix, leaving an
invalid `"-extended"` fragment. This could lead to silent build configuration errors.

Also affects:

  • src/Sentry.Unity.Editor/SentryUnityLinkerProcessor.cs:52~52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant