-
Notifications
You must be signed in to change notification settings - Fork 389
Skip instrumentation for external pdb with no local sources #538
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
MarcoRossignoli
merged 5 commits into
coverlet-coverage:master
from
MarcoRossignoli:externalpdb
Sep 13, 2019
Merged
Changes from all 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Coverlet.Core.Abstracts | ||
{ | ||
internal interface IFileSystem | ||
{ | ||
bool Exists(string path); | ||
} | ||
} | ||
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,13 @@ | ||
using Coverlet.Core.Abstracts; | ||
using System.IO; | ||
|
||
namespace Coverlet.Core.Helpers | ||
{ | ||
internal class FileSystem : IFileSystem | ||
{ | ||
public bool Exists(string path) | ||
{ | ||
return File.Exists(path); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -9,18 +9,21 @@ | |
using System.Reflection.PortableExecutable; | ||
using System.Text.RegularExpressions; | ||
using Coverlet.Core.Abstracts; | ||
using Coverlet.Core.Logging; | ||
|
||
namespace Coverlet.Core.Helpers | ||
{ | ||
internal class InstrumentationHelper : IInstrumentationHelper | ||
{ | ||
private readonly ConcurrentDictionary<string, string> _backupList = new ConcurrentDictionary<string, string>(); | ||
private readonly IRetryHelper _retryHelper; | ||
private readonly IFileSystem _fileSystem; | ||
|
||
public InstrumentationHelper(IProcessExitHandler processExitHandler, IRetryHelper retryHelper) | ||
public InstrumentationHelper(IProcessExitHandler processExitHandler, IRetryHelper retryHelper, IFileSystem fileSystem) | ||
{ | ||
processExitHandler.Add((s, e) => RestoreOriginalModules()); | ||
_retryHelper = retryHelper; | ||
_fileSystem = fileSystem; | ||
} | ||
|
||
public string[] GetCoverableModules(string module, string[] directories, bool includeTestAssembly) | ||
|
@@ -93,8 +96,9 @@ public bool HasPdb(string module, out bool embedded) | |
} | ||
} | ||
|
||
public bool EmbeddedPortablePdbHasLocalSource(string module) | ||
public bool EmbeddedPortablePdbHasLocalSource(string module, out string firstNotFoundDocument) | ||
{ | ||
firstNotFoundDocument = ""; | ||
using (FileStream moduleStream = File.OpenRead(module)) | ||
using (var peReader = new PEReader(moduleStream)) | ||
{ | ||
|
@@ -115,6 +119,7 @@ public bool EmbeddedPortablePdbHasLocalSource(string module) | |
// Btw check for all possible extension could be weak approach | ||
if (!File.Exists(docName)) | ||
{ | ||
firstNotFoundDocument = docName; | ||
return false; | ||
} | ||
} | ||
|
@@ -128,6 +133,41 @@ public bool EmbeddedPortablePdbHasLocalSource(string module) | |
return true; | ||
} | ||
|
||
public bool PortablePdbHasLocalSource(string module, out string firstNotFoundDocument) | ||
{ | ||
firstNotFoundDocument = ""; | ||
using (var moduleStream = File.OpenRead(module)) | ||
using (var peReader = new PEReader(moduleStream)) | ||
{ | ||
foreach (var entry in peReader.ReadDebugDirectory()) | ||
{ | ||
if (entry.Type == DebugDirectoryEntryType.CodeView) | ||
{ | ||
var codeViewData = peReader.ReadCodeViewDebugDirectoryData(entry); | ||
using FileStream pdbStream = new FileStream(codeViewData.Path, FileMode.Open); | ||
using MetadataReaderProvider metadataReaderProvider = MetadataReaderProvider.FromPortablePdbStream(pdbStream); | ||
MetadataReader metadataReader = metadataReaderProvider.GetMetadataReader(); | ||
foreach (DocumentHandle docHandle in metadataReader.Documents) | ||
{ | ||
Document document = metadataReader.GetDocument(docHandle); | ||
string docName = metadataReader.GetString(document.Name); | ||
|
||
// We verify all docs and return false if not all are present in local | ||
// We could have false negative if doc is not a source | ||
// Btw check for all possible extension could be weak approach | ||
if (!_fileSystem.Exists(docName)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like embedded one we check for all docs |
||
{ | ||
firstNotFoundDocument = docName; | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public void BackupOriginalModule(string module, string identifier) | ||
{ | ||
var backupPath = GetBackupPath(module, identifier); | ||
|
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 |
---|---|---|
|
@@ -4,4 +4,6 @@ | |
"2e5bb58a827a3c46c2f959318327ad30d1b52e918321ffbd847fb21565b8576d2a3a24562a93e8" + | ||
"6c77a298b564a0f1b98f63d7a1441a3a8bcc206da3ed09d5dacc76e122a109a9d3ac608e21a054" + | ||
"d667a2bae98510a1f0f653c0e6f58f42b4b3934f6012f5ec4a09b3dfd3e14d437ede1424bdb722" + | ||
"aead64ad")] | ||
"aead64ad")] | ||
// Needed to mock internal type https://github.com/Moq/moq4/wiki/Quickstart#advanced-features | ||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to mock internal IFileSystem for testing we need to allow access from dynamic proxy, it's signed. |
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
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.
for the moment I wrapped only needed method