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

Excluding specific namespaces from disassembly #911

Closed
Warpten opened this issue Oct 14, 2018 · 4 comments
Closed

Excluding specific namespaces from disassembly #911

Warpten opened this issue Oct 14, 2018 · 4 comments
Assignees
Labels
Milestone

Comments

@Warpten
Copy link

Warpten commented Oct 14, 2018

This is something that may seem suspicious at first but I thought it'd be interesting to share since I'm planning to use it for my personal use cases.

Long story short, I just found out about the DisassemblyDiagnoser and figued it'd be a great way to easily take a look at the inner methods I'm testing. This requires using the recursiveDepth parameter to DisassemblyDiagnoserAttribute, but for my use case, it has the downside of pulling in a good chunk of the code from System.Collections.Generic.List<T>. This isn't exactly useful, nor of interest to me, so I figured a good compromise would be to exclude given namespaces.

A couple considerations:

  • This is not exactly pretty in the sense that it is done in such a way that "exclusion does not prevent traversal": Methods within the excluded namespaces are still processed, in case they call in namespaces that are not excluded, but they are simply not added to the output list for XML serialization by the disassemblers.
  • This is an opt-in feature; by default, no namespace is excluded.
  • Namespace detection is done through IL whenever applicable. If not, I chose to resort to signature parsing, which is not exactly pretty, but does a good enough job. I'm open to suggestions in regards to improving this.
  • The benchmarks themselves are placed in a pseudo null namespace, which acts as a wildcard "process me" value.

Known possible improvements:

  • Pattern matching. Would easily exclude System.*. Or go full regex.

I would have provided this as a pull request from the start but I think it's better to discuss it first - I'm also having trouble getting NuGet to restore all the packages. I have really crappy internet so that might be on my end - which means I also can't currently test any of this. Excerpt from nuget log:

The feed 'api.nuget.org [https://api.nuget.org/v3/index.json]' lists package 'System.Diagnostics.Debug.4.0.11-rc2-24027'  but multiple attempts to download the nupkg have failed.

Anyways, the patch:

https://gist.github.com/Warpten/c8f0d809f346684401df89ab85139cd9

@Warpten Warpten changed the title Excluding certain namespaces from disassembly Excluding specific namespaces from disassembly Oct 14, 2018
@adamsitnik
Copy link
Member

Hi @Warpten

I am afraid that this feature would be used by a very few people and would definitely increase the complexity of DissasemblyDiagnoser which already is quite high.

I think that we can make WindowsDisassembler public and you can just reuse it in your code and filter the DisassemblyResult which it produces. So you should be able to write your own diagnoser that does that with 10-20 lines of code. Is that OK?

@Warpten
Copy link
Author

Warpten commented Oct 15, 2018

That sounds fine, actually. And a substancially less complex amount of work indeed!

@adamsitnik
Copy link
Member

@Warpten I made the WindowsDisassembler type and methods public. You should be able to write your own diagnoser now and reuse it. Please let me know if something is missing or just send a PR.

@AndreyAkinshin AndreyAkinshin added this to the v0.11.2 milestone Oct 17, 2018
@Warpten
Copy link
Author

Warpten commented Oct 17, 2018

@adamsitnik I'll look into it this weekend, thank you!

( I still need to figure out why NuGet is failing )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants