in Uncategorized

ScriptCs.ClrMD – Enabling rich, programmatic .NET Diagnostics

I’ve been tweeting about this for a little over a week now, but I figured it would make for a good subject for my first blog post since saying I was going to try for a comeback in 2013 which, otherwise, hasn’t been going so well thus far. 😉

Ok, so if you haven’t already heard about it, a couple of weeks ago the .NET team released an awesome managed library wrapper around the internal CLR debugger APIs which they’ve nicknamed “ClrMD” (CLR Managed Debugger). They’ve made this library available as a NuGet Package so that anyone can take grab it and take advantage of its awesome power. If you’ve ever done any serious .NET debugging, odds are you’re familiar with the SOS debuagging extensions, well then you’re already familiar with the kinds of rich detail that can be gathered by the CLR debugger APIs.

The other half of the technology involved here is ScriptCS. Surely heard about that by now, but, if not, you definitely need to take 15 minutes to check it out. It’s a powerful tool that, at it’s most basic, allows you to write scripts using the C# language. More recently the project has added a REPL implementation that is shaping up quite nicely. One of the other features that ScriptCS provides is an extensibility point called “Script Packs”. At a high level Script Packs provide the ability for their authors to expose a set of functionality that a script writer can then easily import and leverage with just a few lines of code to create effective solutions very quickly. There is already a quickly growing list of Script Packs that expose technologies like WebAPI, Nancy and WPF just to name a few.

So, with that, ScriptCs.ClrMD is a Script Pack that brings the power of the ClrMD APIs to ScriptCs. The goal of the project is to ultimately provide all the functionality that someone who is familiar with SOS is used to having under their tool belt to the ScriptCs environment. At it’s most basic right now you are able to attach to a running process and call various “DumpXXX” methods which aim to provide the same kind of diagnostic output that you get when using SOS in WinDbg. This works best when using ScriptCs in REPL mode and there’s a quick intro do doing this here in the ScriptCs.ClrMD Wiki. Where things get more powerful though is that you can get a hold of the ClrRuntime instance from the ClrMD APIs and then, since you’re working with the full power of C# in ScriptCS, you can start writing your own logic that can pull whatever diagnostic information your heart desires out of the process.

It’s early goings right now and both of the technologies on which this is based are fluctuating themselves. There are bound to be rapid and, sometimes, breaking changes to the way things work as this all evolves and gels together into something useful. I welcome any feedback and encourage everyone to participate in the evolution via the ScriptCS.ClrMD GitHub repo. Feel free to open issues with bugs and feature requests or, better yet, fork it and send me a PR. You can also usually find me on JabbR in the ScriptCS room if you want to discuss anything in real-time.

Leave a comment

Comment

Webmentions

  • PSClrMD – A PowerShell module for CLR Memory Diagnostics | Jason Stangroome

    […] there is also a scriptcs Script Pack for ClrMD if PowerShell is not your […]