SELA Developer Practice: December 2011

October 30, 2011

I’m interrupting our scheduled programming for an important announcement: we will be hosting the SELA Developer Practice at the Crown Plaza hotel (Tel Aviv) and the SELA headquarters on December 4-8, 2011! The format is (again) slightly different—we will be having a day full of keynote sessions on Windows 8 and other //build announcements, including Visual Studio 11 and .NET Framework 4.5. Then, we will host 22 full-day tutorials on a wide variety of topics—old and new—parallel programming, Windows 8 development, TFS, Windows Phone Mango, HTML 5, .NET debugging, and many others. The speakers are...
no comments

Lap Around Roslyn CTP: Syntax Analysis and Flow Analysis

October 27, 2011

How many times have you seen in code reviews a piece of code that calls a method, say Dictionary<K,V>.TryGetValue, and ignores the return value? We are going on a quest to find all such invocations and produce a warning. We’re going to derive from SyntaxWalker (and not SyntaxRewriter), because we won’t be doing any rewriting—just issue detection*. There are two major cases we need to consider: The method is invoked without storing its result in a local variable or using it as part of an expression. Two examples: ...
no comments

Lap Around Roslyn CTP: Syntax Rewriting with Symbol Information

October 25, 2011

Last time around, we were replacing the 42 numeric literal with 43. This time let’s pretend to do something more useful. Suppose you really don’t like developers calling the Console.Write method and insist on using Console.WriteLine instead. You might be slightly reluctant to use find-and-replace, because—just like last time—you don’t want to modify Console.Write calls within comments, within string literals, or—and this is vicious—calls to the Console.Write method on something that is not the System.Console class from the mscorlib assembly, like maybe a property called Console! The C# parser, which we met in its SyntaxTree incarnation, doesn’t bind...
no comments

Lap Around Roslyn CTP: Syntax Rewriting

October 23, 2011

To start doing something useful with Roslyn, we’re going to inspect a syntax tree, locate something interesting—and then modify it! The complex structure of a C# program’s syntax tree (SyntaxTree class) is exposed through a fairly intuitive object model, featuring three types of entities: Nodes are the major elements of the language; for example, an IfStatementSyntax is a node representing an “if” statement and a LiteralExpressionSyntax is a node representing a literal expression. Tokens are secondary elements—which are nonetheless very important—such as identifiers, string literals, and numeric literals. Tokens are always attached to a node. For...
no comments

Lap Around Roslyn CTP: Introduction

October 21, 2011

The Roslyn project is the Microsoft implementation of C# and VB compilers-as-a-service. Roslyn provides a transparent view into the inner workings of the compiler, including syntax tree inspection and modification. An initial CTP of Roslyn has been released for download a couple of days ago—it requires Visual Studio 2010 SP1 and the VS2010 SP1 SDK. ...
no comments

Capture, Transfer, and Rethrow Exceptions with ExceptionDispatchInfo [.NET 4.5]

October 19, 2011

.NET 4.5 has a little hidden gem up its sleeve – the ExceptionDispatchInfo class. It’s used by the Task Parallel Library to capture and rethrow exceptions when they are not aggregated – specifically, to support the await keyword. Luckily, the class is public and can be used by anyone to capture an exception that occurred in one context – say, a thread – and then rethrow it (selectively) in another context – say, on another thread, while maintaining the full fidelity of the original stack trace and exception information. First, let’s take a look at a stack trace...
one comment

SIMD-Optimized C++ Code in Visual Studio 11

October 17, 2011

The C++ compiler in Visual Studio 11 has another neat optimization feature up its sleeve. Unlike intrusive features, such as running code on the GPU using the AMP extensions, this one requires no additional compilation switches and no changes – even the slightest – to the code. The new compiler will use SIMD (Single Instruction Multiple Data) instructions from the SSE/SSE2 and AVX family to "parallelize" loops. This is not the standard, thread-level parallelism, which runs certain iterations of the loop in parallel. This is the processor’s inherent ability to execute operations on individual parts of large data...

Open Kernel Crash Dumps in Visual Studio 11

October 14, 2011

A dream is coming true. A dream where all the debugging you’ll ever do on your developer box is going to be in a single tool – Visual Studio. In a later post, I will discuss device driver development in Visual Studio 11, which is another dream come true. For now, let’s take a look at how Visual Studio can open kernel crash dumps and perform crash analysis with all the comfy tool windows and UI that we know and love. To perform kernel crash analysis in Visual Studio 11, you will need to install the Windows...

Debugging Optimized Code in Visual Studio 11

October 12, 2011

Executive summary: When using the Windows debugger engine to debug optimized C++ code compiled with Visual Studio 11 you can step into inline functions and see local variables that are stored in CPU registers. The current (Visual Studio 2010 compiler) state of affairs is that compiler optimizations are way smarter than the debugger engine, which lacks the information necessary to map a fully optimized binary back to the source code in a reliable manner. This is why C++ developers don’t like debugging optimized code: as if the compiler-introduced reorderings which take you from one line to a completely...

Windows 8 Refresh and Reset

October 11, 2011

We are all so used to reformatting Windows boxes every couple of years, especially for not-so-technically-savvy relatives’ machines infested with malware. Refresh your PC is a refreshing feature of Windows 8 that maintains all the files and settings you have on your machine, but removes all applications (other than Windows Store apps). A couple of days ago I had to perform a refresh on my Samsung Developer Tablet, after connecting to it a ZTE USB modem caused all Metro apps to fail at the splash screen. And there’s really not so much to it – a...
no comments