-
Notifications
You must be signed in to change notification settings - Fork 399
Forward ICLRSymbolProvider calls to a host-supplied symbol resolver #5877
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
Open
max-charlamb
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
max-charlamb:max-charlamb/symbol-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+335
−10
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
src/Microsoft.Diagnostics.DebugServices.Implementation/HostSymbolProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using Microsoft.Diagnostics.Runtime; | ||
|
|
||
| namespace Microsoft.Diagnostics.DebugServices.Implementation | ||
| { | ||
| /// <summary> | ||
| /// Adapter exposing the host's <see cref="IModuleService"/> / | ||
| /// <see cref="IModuleSymbols"/> through ClrMD's | ||
| /// <see cref="IClrSymbolProvider"/> contract. | ||
| /// </summary> | ||
| [ServiceExport(Type = typeof(IClrSymbolProvider), Scope = ServiceScope.Target)] | ||
| public sealed class HostSymbolProvider : IClrSymbolProvider | ||
| { | ||
| private readonly IModuleService _moduleService; | ||
| private readonly ulong _signExtensionMask; | ||
|
|
||
| public HostSymbolProvider(IModuleService moduleService, IMemoryService memoryService) | ||
| { | ||
| _moduleService = moduleService ?? throw new ArgumentNullException(nameof(moduleService)); | ||
| _signExtensionMask = memoryService?.SignExtensionMask() ?? ulong.MaxValue; | ||
| } | ||
|
|
||
| public bool TryGetSymbolName(ulong address, out string symbolName, out ulong displacement) | ||
| { | ||
| symbolName = null; | ||
| displacement = 0; | ||
|
|
||
| address &= _signExtensionMask; | ||
|
|
||
| IModule module; | ||
| try | ||
| { | ||
| module = _moduleService.GetModuleFromAddress(address); | ||
| } | ||
| catch (DiagnosticsException) | ||
| { | ||
| return false; | ||
| } | ||
| if (module is null) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| IModuleSymbols symbols = module.Services.GetService<IModuleSymbols>(); | ||
| if (symbols is null) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (!symbols.TryGetSymbolName(address, out string bareName, out displacement) | ||
| || string.IsNullOrEmpty(bareName)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // Strip any module! qualifier the lower-level service might have | ||
| // prepended — the new contract returns bare names only. | ||
| int bang = bareName.IndexOf('!'); | ||
| symbolName = bang >= 0 && bang + 1 < bareName.Length ? bareName.Substring(bang + 1) : bareName; | ||
| return true; | ||
| } | ||
|
|
||
| public bool TryGetSymbolAddress(ulong moduleBase, string name, out ulong address) | ||
| { | ||
| address = 0; | ||
| if (string.IsNullOrEmpty(name)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| moduleBase &= _signExtensionMask; | ||
|
|
||
| // moduleBase != 0 restricts the search to a single module. | ||
| if (moduleBase != 0) | ||
| { | ||
| IModule scopedModule; | ||
| try | ||
| { | ||
| scopedModule = _moduleService.GetModuleFromBaseAddress(moduleBase); | ||
| } | ||
| catch (DiagnosticsException) | ||
| { | ||
| return false; | ||
| } | ||
| if (scopedModule is null) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| IModuleSymbols scopedSymbols = scopedModule.Services.GetService<IModuleSymbols>(); | ||
| if (scopedSymbols is null) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (scopedSymbols.TryGetSymbolAddress(name, out ulong scopedAddr) && scopedAddr != 0) | ||
| { | ||
| address = scopedAddr; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| foreach (IModule module in _moduleService.EnumerateModules()) | ||
| { | ||
| IModuleSymbols symbols = module.Services.GetService<IModuleSymbols>(); | ||
| if (symbols is null) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| if (symbols.TryGetSymbolAddress(name, out ulong addr) && addr != 0) | ||
| { | ||
| address = addr; | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.Diagnostics.DebugServices | ||
| { | ||
| /// <summary> | ||
| /// Implemented by extension assemblies to perform process-wide initialization | ||
| /// (for example registering an <c>IClrInfoProvider</c>) when the extension | ||
| /// is loaded. | ||
| /// | ||
| /// Implementations must have a public parameterless constructor. Every | ||
| /// concrete <see cref="IHostExtension"/> implementation discovered in an | ||
| /// extension assembly is instantiated and its <see cref="Initialize"/> | ||
| /// method invoked once during <see cref="IServiceManager"/> assembly | ||
| /// registration, before any other service or provider exports from the | ||
| /// assembly are consumed. An assembly may contain multiple | ||
| /// implementations; invocation order across implementations is | ||
| /// unspecified. | ||
| /// </summary> | ||
| public interface IHostExtension | ||
| { | ||
| /// <summary> | ||
| /// Performs one-time initialization for the extension. | ||
| /// </summary> | ||
| void Initialize(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even want to support
moduleBase == 0? To scan everything? Once we reach here this is going to grind the entire debugger to an absolute halt, and with no cancellation token possible across com, this is going to be pure pain.