MohamedG's Log


Visual GCRoot via DGML

I was inspired by Lovett‘s post about Visualizing Runtime Object Graphs to create my first debugger extension that takes the output of !gcroot and creates a graph that one can interact with easily in Visual Studio 2010. So, what does my extension do? !vgcroot –? !vgcroot [/nostacks] [/do] <Object address> [<DGML output file>]   /nostacks… Read more

Tiny C++ Unit Test Framework

I was working on a small project for personal use that I wrote in C++ and I wanted to test it. Since it’s a tiny project, I didn’t bother installing a well-known test framework that ships with a plethora of features. I just wanted a simple test runner that can show me a failure when… Read more

ExtensionDataObject is not Marked as Serializable

If you use Data Contracts, then probably your classes implement the IExtensibleDataObject interface to allow (de)serialization of different versions of the data contract. I won’t go into details about the use of ExtensionDataObject, the type of the ExtensionData property you need to implement. I just want to point out a possible scenario, using sample code… Read more

How to: Create Interfaces with Static Methods via IL?

If you try to add a static member to an interface, you will get the following error: The modifier ‘static’ is not valid for this item In this case, you should create an abstract class instead of an interface, because interfaces are contracts and should not implement any methods. However, it’s still possible to do… Read more

On Testability

Acceptance testing is basically black-box testing done by the QA team to sign off. It’s very important to have clear pre-defined goals for acceptance testing as early as possible during the planning phase. In fact, the requirements specifications should define negative scenarios and expected failure behavior, not just positive scenarios and use cases. These requirements… Read more

How to: Use Locks and Prevent Deadlocks?

Multi-threading is used in almost all real-life applications. I summed up my thoughts on use of locks and deadlock prevention in the following related topics: Thread Safety From a thread safety perspective, resources (memory) is classified as either thread-exclusive, read-only, or lock-protected. Unsafe use Accessing static variables or heap-allocated memory after it is published (made… Read more

How to: Debug Deadlocks Using Windbg?

Attach the debugger to the process Load SOS ~* e !clrstack to view the CLR stack of all the threads and where they are Look for System.Threading.Monitor.Enter(System.Object) in the top frames Load SOSEX.dll from !dlk to detect deadlocks. The output looks like the following: Deadlock detected: CLR thread 5 holds sync block 0018f05c OBJ:010d909c[Microsoft.Sample.SampleEvent]… Read more