Friday, June 15, 2007

The #line Directive - Part2 (Intresting Fact)

The .pdb file generated by the compiler contains line number information to allow the debugger to step through source code. In this for blocks of IL code the corresponding source file and line number information is stored. The #line directive makes the compiler change the line number information it puts into this file. There is an understanding between the debugger and the compiler that if the line number of a block of IL is set as 16707566 ( 0xFeeFee) then the debugger will simply step over this block of code. This is utilized in #line hidden and the compiler translates hidden to 0xFeeFee You can try out the following code to see this in action

using System;
namespace LinePreProcDirective
{
class Program
{
static void foo()
{
Console.WriteLine("foo");
#line 16707566
Console.WriteLine("bar");
#line default
}
static void Main(string[] args)
{
foo();
}
}
}

The code marked in bold will be skipped over if you try to step through this code in the debugger.

namaste!

No comments: