-
Notifications
You must be signed in to change notification settings - Fork 387
Changes needed for clrmd 2.1 #3094
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 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
There are no files selected for viewing
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 |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| <RuleSet Name="Diagnostics Ruleset" | ||
| Description="Diagnostics Ruleset" | ||
| ToolsVersion="14.0"> | ||
|
|
||
| <!-- Define all the analyzer rule actions for this repo. --> | ||
| <Include Path="CodeAnalysis.Repository.ruleset" Action="Default" /> | ||
|
|
||
| <!-- This will override or define all rules needed values to be SDL compliant. --> | ||
| <Include Path="CodeAnalysis.Security.ruleset" Action="Default" /> | ||
| </RuleSet> | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <RuleSet Name="Diagnostics Ruleset" Description="Diagnostics Ruleset" ToolsVersion="14.0"> | ||
| <!-- Define all the analyzer rule actions for this repo. --> | ||
| <Include Path="CodeAnalysis.Repository.ruleset" Action="Default" /> | ||
| <!-- This will override or define all rules needed values to be SDL compliant. --> | ||
| <Include Path="CodeAnalysis.Security.ruleset" Action="Default" /> | ||
| <Rules AnalyzerId="Microsoft.CodeQuality.Analyzers" RuleNamespace="Microsoft.CodeQuality.Analyzers"> | ||
| <Rule Id="CA1069" Action="None" /> | ||
| </Rules> | ||
| </RuleSet> |
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
206 changes: 206 additions & 0 deletions
206
src/Microsoft.Diagnostics.DebugServices.Implementation/DataReader.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,206 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using Microsoft.Diagnostics.Runtime; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.Diagnostics; | ||
| using System.Linq; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Microsoft.Diagnostics.DebugServices.Implementation | ||
| { | ||
| /// <summary> | ||
| /// ClrMD runtime service implementation | ||
| /// </summary> | ||
| internal class DataReader : IDataReader | ||
| { | ||
| private readonly ITarget _target; | ||
| private IEnumerable<ModuleInfo> _modules; | ||
| private IModuleService _moduleService; | ||
| private IThreadService _threadService; | ||
| private IMemoryService _memoryService; | ||
|
|
||
| public DataReader(ITarget target) | ||
| { | ||
| _target = target; | ||
| target.OnFlushEvent.Register(() => _modules = null); | ||
| } | ||
|
|
||
| #region IDataReader | ||
|
|
||
| string IDataReader.DisplayName => ""; | ||
|
|
||
| bool IDataReader.IsThreadSafe => false; | ||
|
|
||
| OSPlatform IDataReader.TargetPlatform => _target.OperatingSystem; | ||
|
|
||
| Architecture IDataReader.Architecture => _target.Architecture; | ||
|
|
||
| int IDataReader.ProcessId => unchecked((int)_target.ProcessId.GetValueOrDefault()); | ||
|
|
||
| IEnumerable<ModuleInfo> IDataReader.EnumerateModules() => _modules ??= ModuleService.EnumerateModules().Select((module) => new DataReaderModule(module)).ToList(); | ||
|
|
||
| bool IDataReader.GetThreadContext(uint threadId, uint contextFlags, Span<byte> context) | ||
| { | ||
| try | ||
| { | ||
| byte[] registerContext = ThreadService.GetThreadFromId(threadId).GetThreadContext(); | ||
| context = new Span<byte>(registerContext); | ||
| return true; | ||
| } | ||
| catch (DiagnosticsException ex) | ||
| { | ||
| Trace.TraceError($"GetThreadContext: {threadId} exception {ex.Message}"); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| void IDataReader.FlushCachedData() | ||
| { | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| #region IMemoryReader | ||
|
|
||
| int IMemoryReader.PointerSize => MemoryService.PointerSize; | ||
|
|
||
| int IMemoryReader.Read(ulong address, Span<byte> buffer) | ||
| { | ||
| MemoryService.ReadMemory(address, buffer, out int bytesRead); | ||
| return bytesRead; | ||
| } | ||
|
|
||
| bool IMemoryReader.Read<T>(ulong address, out T value) | ||
| { | ||
| Span<byte> buffer = stackalloc byte[Marshal.SizeOf<T>()]; | ||
| if (((IMemoryReader)this).Read(address, buffer) == buffer.Length) | ||
| { | ||
| value = Unsafe.As<byte, T>(ref MemoryMarshal.GetReference(buffer)); | ||
| return true; | ||
| } | ||
| value = default; | ||
| return false; | ||
| } | ||
|
|
||
| T IMemoryReader.Read<T>(ulong address) | ||
| { | ||
| ((IMemoryReader)this).Read(address, out T result); | ||
| return result; | ||
| } | ||
|
|
||
| bool IMemoryReader.ReadPointer(ulong address, out ulong value) | ||
| { | ||
| return MemoryService.ReadPointer(address, out value); | ||
| } | ||
|
|
||
| ulong IMemoryReader.ReadPointer(ulong address) | ||
| { | ||
| MemoryService.ReadPointer(address, out ulong value); | ||
| return value; | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| private IModuleService ModuleService => _moduleService ??= _target.Services.GetService<IModuleService>(); | ||
|
|
||
| private IMemoryService MemoryService => _memoryService ??= _target.Services.GetService<IMemoryService>(); | ||
|
|
||
| private IThreadService ThreadService => _threadService ??= _target.Services.GetService<IThreadService>(); | ||
|
|
||
| private class DataReaderModule : ModuleInfo | ||
| { | ||
| private readonly IModule _module; | ||
|
|
||
| public DataReaderModule(IModule module) | ||
| : base(module.ImageBase, module.FileName) | ||
| { | ||
| _module = module; | ||
| } | ||
|
|
||
| public override long ImageSize => unchecked((long)_module.ImageSize); | ||
|
|
||
| public override int IndexFileSize => unchecked((int)_module.IndexFileSize.GetValueOrDefault(0)); | ||
|
|
||
| public override int IndexTimeStamp => unchecked((int)_module.IndexTimeStamp.GetValueOrDefault(0)); | ||
|
|
||
| public override Version Version | ||
| { | ||
| get | ||
| { | ||
| try | ||
| { | ||
| return _module.GetVersionData() ?? Utilities.EmptyVersion; | ||
| } | ||
| catch (DiagnosticsException ex) | ||
| { | ||
| Trace.TraceError($"ModuleInfo.Version: {_module.ImageBase:X16} exception {ex.Message}"); | ||
| } | ||
| return Utilities.EmptyVersion; | ||
| } | ||
| } | ||
|
|
||
| public override ImmutableArray<byte> BuildId | ||
| { | ||
| get | ||
| { | ||
| try | ||
| { | ||
| return _module.BuildId; | ||
| } | ||
| catch (DiagnosticsException ex) | ||
| { | ||
| Trace.TraceError($"ModuleInfo.BuildId: {_module.ImageBase:X16} exception {ex.Message}"); | ||
| } | ||
| return ImmutableArray<byte>.Empty; | ||
| } | ||
| } | ||
|
|
||
| public override PdbInfo Pdb | ||
| { | ||
| get | ||
| { | ||
| try | ||
| { | ||
| PdbFileInfo pdbFileInfo = _module.GetPdbFileInfos().Where((pdbFileInfo) => pdbFileInfo.IsPortable).LastOrDefault(); | ||
| if (pdbFileInfo is null) | ||
| { | ||
| pdbFileInfo = _module.GetPdbFileInfos().LastOrDefault(); | ||
| if (pdbFileInfo is null) | ||
| { | ||
| return default; | ||
| } | ||
| } | ||
| return new PdbInfo(pdbFileInfo.Path, pdbFileInfo.Guid, pdbFileInfo.Revision); | ||
| } | ||
| catch (DiagnosticsException ex) | ||
| { | ||
| Trace.TraceError($"ModuleInfo.Pdb: {_module.ImageBase:X16} exception {ex.Message}"); | ||
| } | ||
| return default; | ||
| } | ||
| } | ||
|
|
||
| public override bool IsManaged => _module.IsManaged; | ||
|
|
||
| public override ulong GetExportSymbolAddress(string symbol) | ||
| { | ||
| var exportSymbols = _module.Services.GetService<IExportSymbols>(); | ||
| if (exportSymbols is not null) | ||
| { | ||
| if (exportSymbols.TryGetSymbolAddress(symbol, out ulong offset)) | ||
| { | ||
| return offset; | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| public override IResourceNode ResourceRoot => base.ResourceRoot; | ||
| } | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.