Index
- Introduction
- Build configurations
- Precompiler directives
- Program database files and symbols aka PDB
- References
Introduction
This post is part of a series of post to help you prepare the MCSD certification, particularly the certification exam 70-483, based on the book:You will find all the code available in the following GitHub repository. Lets talk a little bit about threads and how they work using a .Net development environment.
Build configurations
Default build configurations:
- Release mode: code is fully optimized and no extra information for debugging is created
- Debug mode: the compiler inserts extra no-operations (NOP: create a variable that's never used) instructions and branch instructions (a conditional piece of code that's never executed).
An scenario where you can see a big different in the behavior of these two configurations it's when using Timers. This particular class can be scheduled to run again after a period of time but if we trigger the GC this behavior can be prevented.
Precompiler directives
C# doesn't have an specialized preprocessor (applies some changes to your code before handling it off to the compiler), but it supports preprocessor compiler directives:
- #if: this directive uses the default logical operators as in C# (==, !=, &&, || and !) and evaluates the condition in order to run or not a piece of code. Ex:
- #if DEBUG {SOME CODE} #endif
- #if !WINRT {CODE FOR NO WINRT PLATFORMS} #endif
- #define: we can declare our own variables and use them within my #if 's
- #undef: used to remove debug symbols
- #warning: message that appears in the output
- #error: message that appears in the output
- #line: it modifies the compiler's line number and the file name
- #line 200: sets the following line to 200.
- #line default: sets back to the original line number.
- #line hidden: to hide lines of code, so you can skip pieces of your code
- #pragma warning disable: starting point of a disabled piece of code
- #pragma warning restore: finish point of a disabled piece of code
The ConditionalAttribute (Ex: [Conditional("DEBUG")] ) is a more handy way to attach behavior to your methods instead of using preprocessor directives, which it's inconvenient. But for types that don't override ToString, the default implementation shows the name of the type. A solution for that is the DebuggerDisplayAttribute (Ex: [DebuggerDisplay(Name = "SomeText"] ).
Program database files and symbols aka PDB
When running a build process you can specify a full debug or debug with pdb files. First option creates a pdb file and the assembly contains debug information, second option the assembly is not modified and the pdb is created as well (used in release mode). PDB contains:
- Source file names and their lines
- Local variable names
None of these are stored within assemblies but it will be useful for our debugging process. This helps Visual Studio to provide the following data when you are debugging:
- modules: libraries required to run your app
- call stack: calls between classes. Workflow.
- debug previous versions of your applications: using Symbol Server (Tools/options/Debuggins/General) you can easily tell your VS to take PDB from previous version of your code that are stored by your TFS.
- PDBCopy.exe: helps you split the private data from the public data within your assemblies when you deliver app to the outside world.
0 comments:
Post a Comment