Attach a Debugger When a Process Starts

October 28, 2009

You can ask Windows to launch another process (typically a debugger) when launching a process of your choice. One use of this feature is to configure Calculator to launch whenever you launch Notepad, or configure Excel to launch whenever you launch Word. This is a great way to drive a colleague crazy. Another use of this feature is to attach a debugger to the startup sequence of a process that can’t be easily started from within the debugger. For example, if you’re debugging the startup of a Windows service, you can’t start it from the debugger; the...
3 comments

Wait Chain Traversal Debugging Extension for WinDbg

October 24, 2009

Wait Chain Traversal is a set of APIs introduced in Windows Vista that can be used to display diagnostic information about the wait chains of application threads. A wait chain is an alternating sequence of THREAD, RESOURCE nodes where a THREAD element describes a thread that holds an instance of a resource and a RESOURCE element describes a resource that a thread waits for. For example, the sequence T1 –> M1 –> T2 –> M2 –> T1 (where T1, T2 are threads and M1, M2 are mutex objects) describes a classic deadlock because effectively T1 is waiting...
no comments

Template Template Parameters

October 22, 2009

Here’s a good interview question or riddle for seasoned C++ developers. You’re asked to design a set of template functions for automatic conversion of data from one type to another. First of all, you’re expected to have a function called scalar_convert<T> for converting values of type T to values of another type that depends on T. Part of the assignment is to come up with a mapping between T and the target type without requiring the caller to pass it along as a template parameter. Next, you’re expected to have a function called vector_convert for converting containers...
tags:
one comment

Parallelism in Visual Studio 2010: Demos Updated to Beta 2

October 20, 2009

As you probably know, Visual Studio 2010 has reached the Beta 2 milestone, with a go-live license available to start coding your production applications using this release. There have been some minor changes around the System.Threading.Tasks namespace and classes, with the most significant change being around the cancellation model for tasks. Instead of explicitly reaching out for a Task object and then calling its Cancel method (which has been removed, along with the static Task.Current property), cancellation now requires a CancellationTokenSource object to be created, its Token property should be passed to the methods that create a task,...
2 comments

Configuring Automatic Crash Dumps

October 19, 2009

This post is meant to serve as a simple reference for configuring automatic crash dumps for managed and native applications. These configuration steps can be performed on any machine which has Debugging Tools for Windows installed, and they do not require Visual Studio. Although the subsequent steps are configured to capture a crash dump and nothing more, cdb is a fairly sophisticated debugger and so you can perform much more than just capture a dump—you can pass any commands of your choice to the debugger and they will be executed when the application crashes. (E.g. run an external...
tags:
3 comments

What I Learned About Writing Unit Tests: Dependency Injection Mess With Mocks

October 18, 2009

Armed with some experience, I embraced dependency injection in all its might. I started writing subsystems and components that interact only through well-defined interfaces, which was relatively easy for me because my previous infrastructure project relied heavily on dynamically-generated proxies that worked only with interfaces. This allowed me to abstract away and stub away everything a component needed under a test. And then my tests had the following shape and form (I’m not using any specific mock framework syntax, for illustration purposes): public void LoggingFramework_LogToDB_Works() ...
4 comments

Analyzing Monitor-Based Deadlocks with SOS.dll

October 17, 2009

Over a year ago, I blogged about the SOSEX debugging extension (which has been updated since!) and how its !dlk command can be used to diagnose a managed deadlock that involves Monitor locks. There’s also the obvious question of what to do when SOSEX can’t be used for this purpose, i.e. how to diagnose this kind of deadlock with SOS alone. First of all, you need to see the sync blocks involved. The SOS !syncblk command (and the !dumpheap -thinlock command) will show you information about the sync blocks in the debugged process or dump. (Sync blocks...
one comment

What I Learned About Writing Unit Tests: Test Infrastructure

October 10, 2009

In the previous installment I mentioned that I wasn’t satisfied with tests that check whether a single constructor throws a single exception. Over the years I started looking for something with a little more value, a test that I could show developers writing code for my framework and tell them that’s the way to use my APIs. Naturally, the next thing I started doing was writing infrastructure frameworks for writing tests for my framework. This means I would have all kinds of TestHelper and ContextHelper and TestSetupReflector classes that would take care of everything necessary to make the...
one comment

What I Learned About Writing Unit Tests: My First Tests

October 7, 2009

Over the last 4 years, I embraced the idea of writing unit tests for my software. Most of what I’ve written during these years has been software frameworks, with very high reliability and stability guarantees and explicit needs for backwards compatibility—all perfectly ripe for a good unit test suite. In the following short series of posts, I will try to share the story of what I learned from writing unit tests, and why the tests I write today are nothing like the tests I wrote 4 years ago. The first unit tests I’ve written were taken straight from...
3 comments

Learning from Feedback as a Public Speaker

October 1, 2009

Over the last three years, I’ve had lots of experiences as a speaker at conferences, courses, private presentations and other opportunities. Among them, I had the chance to present at the Microsoft Developers Academy, TechEd and IDCC; I taught 54 courses for Sela, including Windows Internals, .NET Debugging, .NET Performance, C++/CLI and many others; and I lectured at short half-day MSDN events on Windows 7, Windows Server 2008, performance, debugging and concurrency. Almost every training session, every course, every conference concluded with audience feedback. (If you ever filled an evaluation form for my presentation or course, thank you...
no comments