Debugging Production SharePoint Applications Wouter van Vugt.

Slides:



Advertisements
Similar presentations
Ahead of Time Dynamic Translation PreJit/NGEN by any other name George Bosworth Microsoft MRE04 March 21, 2004.
Advertisements

By Sam Nasr September 28, 2004 Understanding MSIL.
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Introduction to .NET Framework
.NET Framework Overview
Tahir Nawaz Introduction to.NET Framework. .NET – What Is It? Software platform Language neutral In other words:.NET is not a language (Runtime and a.
History of.Net Introduced by Microsoft Earlier technology was VC++ and VB VC++ comes with so many library and VB was so easy to use and not flexible to.
.NET Framework Overview Pingping Ma Nov 16 th, 2006.
COSC 120 Computer Programming
1/50 Project Management. 2/50 StumbleUpon 3/50 Overview Customize? Why, what, how?.NET Framework overview & fundamentals Class libraries, namespaces,
Introducing the Common Language Runtime for.NET. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution.
Introducing the Common Language Runtime. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution engine.
OllyDbg Debuger.
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Creating and Running Your First C# Program Telerik Software Academy Telerik School Academy.
A Free sample background from © 2001 By Default!Slide 1.NET Overview BY: Pinkesh Desai.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
Lecture Roger Sutton CO530 Automation Tools 5: Class Libraries and Assemblies 1.
Introduction to .Net Framework
An Introduction to ASP.NET Ed Dunhill blogs.msdn.com/edunhill SLIDE7.
Introduction to Programming
Module 1: Introduction to C# Module 2: Variables and Data Types
.NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
CIS NET Applications1 Chapter 2 –.NET Component- Oriented Programming Essentials.
.NET Framework & C#.
Introduction to .NET Framework
Understanding Code Compilation and Deployment Lesson 4.
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Compiling and Executing Code in.Net Microsoft Intermediate Language and Common Language Runtime.
.NET Framework Overview
Lecture 1 Programming in C# Introducing C# Writing a C# Program.
Component-Based Software Engineering Introduction to.NET Paul Krause.
.NET Framework Danish Sami UG Lead.NetFoundry
Programming in C#. I. Introduction C# (or C-Sharp) is a programming language. C# is used to write software that runs on the.NET Framework. Although C#
Week 1: THE C# LANGUAGE Chapter 1: Variables and Expressions ➤ Included in Visual Studio.NET ➤ What the.NET Framework is and what it contains ➤ How.NET.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. WEB.
Java Virtual Machine Case Study on the Design of JikesRVM.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
1.NET FRAMEWORK CE-105 Spring 2007 Engr. Faisal ur Rehman.
tom perkins1 XML Web Services -.NET FRAMEWORK – Part 1 CHAPTER 1.1 – 1.3.
Module 6: Debugging a Windows CE Image.  Overview Debug Zones IDE Debug Setup IDE Debug Commands Platform Builder Integrated Kernel Debugger Other Debugging.
PRIOR TO WEB SERVICES THE OTHER TECHNOLOGIES ARE:.
Msdevcon.ru#msdevcon. ИЗ ПЕРВЫХ РУК: ДИАГНОСТИКА ПРИЛОЖЕНИЙ С ПОМОЩЮ ИНСТРУМЕНТОВ VISUAL STUDIO 2012 MAXIM GOLDIN Senior Developer, Microsoft.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
Module 1 Introducing C# and the.NET Framework. Module Overview Introduction to the.NET Framework 4 Creating Projects Within Visual Studio 2010 Writing.
The Execution System1. 2 Introduction Managed code and managed data qualify code or data that executes in cooperation with the execution engine The execution.
Text Introduction to.NET Framework. CONFIDENTIAL Agenda .NET Training – Purpose  What is.NET?  Why.NET?  Advantages  Architecture  Components: CLR,
.NET Framework, CLR, MSIL, Assemblies, CTS, etc..
Sung-Dong Kim Dept. of Computer Engineering, Hansung University Chapter 3 Programming Tools.
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
Just-In-Time Compilation. Introduction Just-in-time compilation (JIT), also known as dynamic translation, is a method to improve the runtime performance.
Building C# Applications
Introduction to .NET framework
Introduction to .NET Framework
Foundations of .Net Programming with C#
Debugging with gdb gdb is the GNU debugger on our CS machines.
C# and the .NET Framework
CE-105 Spring 2007 Engr. Faisal ur Rehman
2.1. Compilers and Interpreters
.NET and .NET Core 2. .NET Runtimes Pan Wuming 2017.
CS360 Windows Programming
Module 1: Getting Started
Introduction to C# AKEEL AHMED.
Programming in C# CHAPTER 1
.NET and .NET Core: Languages, Cloud, Mobile and AI
Introduction to System Programming
Compiler Code Optimizations
IS 135 Business Programming
Presentation transcript:

Debugging Production SharePoint Applications Wouter van Vugt

Agenda How.NET and the CLR work Optimizing code and the effect on debuggers Debugging third party code

HOW.NET AND THE CLR WORK

.NET Applications Written in any language Executed in a runtime called CLR – Shield code from hardware specifics Java: One language, multi OS.NET: Many languages, one OS (and Mono) – Allows various types of preprocessing of code OS CLR App

Common Language Runtime Operation Memory management Thread synchronization Error handling Type Safety Security Code Access Security Data Execution Prevention (OS) Address Space Layout Randomization (OS) Execution Intermediate Language

Type Safety – A pointer of a specific type can never point to an object which is not of that type! – Checked at compile AND runtime! – Knowing the actual type enables Reading its data  Quite useful in debugging Calling its functions Car c = new Person() ‘Pointer type’ Pointer Object type

TRY AND CIRCUMVENT TYPE SAFETY Demo

Creating.NET Applications C#, C++, VB.NET, F#.... (40+) Module PDB CompileLink Assembly PDB

Executing code Assemblies contain mostly IL code – IL is the ‘Machine code’ for.NET – Compiled to native instructions at runtime through the JIT Compiler – Enough information remains to decompile back to source! C# Machine Code Language richness compared IL

Executing code with JIT Compilation Console.WriteLine("Hi"); Console.WriteLine("There"); JIT Compiler -Lookup IL for method -Compile IL to native -Modify metadata to point to compiled code -Jump to compiled code JIT Compiler -Lookup IL for method -Compile IL to native -Modify metadata to point to compiled code -Jump to compiled code Console metadata static void WriteLine(string) JIT Compiler Address static void WriteLine() JIT Compiler Address Native CPU Instructions Native Address

Executing code with JIT Compilation Console.WriteLine("Hi"); Console.WriteLine("There"); Console metadata static void WriteLine(string) JIT Compiler -Lookup IL for method -Compile IL to native -Modify metadata to point to compiled code -Jump to compiled code Native Address static void WriteLine() JIT Compiler Address Native CPU Instructions

Code optimization Compile-time – Constant value folding – Remove Branch to next instruction and NOP instructions used to break on control flow, {, }, EndIf etc – Overflow checking – … During JIT – Eliminate local variables – Range check elimination – Method inlining – Tail call optimization – Common subexpression elimination – Dead code elimination – Loop unrolling – …

Running non optimized code Breakpoints Edit and continue

C# Compiler – Variable Generation

DebugRelease

C# Compiler – Inserting NOP

DebugRelease

C# Compiler – Branching

DebugRelease

COMPILE TIME OPTIMIZATIONS Demo

Just In Time Compilation Transformation of MSIL to native x86 / x64 / ARM etc Can optimize code – Mathematically ensured correctness Takes a small performance hit during startup Compiler switchC# IL Code QualityJIT Native Code Quality /optimize- /debug-UnoptimizedOptimized /optimize- /debug+Unoptimized /optimize+ /debug+Optimized

NGEN.exe JIT Compilation incurs a runtime cost NGEN pre-compiles MSIL assemblies to machine code Runs as a service in the background Also used by the “.NET Runtime Optimization Service”

JIT - Local variable elimination User user = GetUser(3); PrintUser(user); PrintUser(GetUser(3)); Before After

JIT – Range check elimination static int[] _array = new int[10]; static volatile int _i; static void Main(string[] args) { for (int i = 0; i < _array.Length; ++i) _i += _array[i]; } static int[] _array = new int[10]; static volatile int _i; static void Main(string[] args) { int[] localRef = _array; for (int i = 0; i < localRef.Length; ++i) _i += localRef[i]; } Before After

JIT – Method Inlining public class Program { public static int And(int first, int second) { return first & second; } static void Main(string[] args) { int i = And(5, 4); } public class Program { static void Main(string[] args) { int i = 5 & 4; } Before After

JIT – Tail Call Optimization static void Main(string[] args) { TestTailCallOptimization(); } public static void TestTailCallOptimization() { string s = "Test"; TailCall1(s); } static void TailCall1(string s) { Console.WriteLine(s); TailCall2(s); } static void TailCall2(string s) { Console.WriteLine(s + s); }

Loading non-precompiled assemblies Native NGEN images are hard to debug – Remove the NGEN image – Or, prevent NGEN image from loading C:\> SET COMPLUS_ZAPDISABLE=1 C:\> NGEN uninstall MyAssembly

Preventing JIT optimization Creating debug builds – JIT prevented through compile time attributes INI file MyAssembly.ini In Visual Studio, on module load after attach [.NET Framework Debugging Control] GenerateTrackingInfo=1 AllowOptimize=0 [assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.EnableEditAndContinue | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.Default)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.EnableEditAndContinue | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.Default)]

DEBUGGING OPTIMIZED CODE Demo

Debugging code PDB files are as essential as code! Breakpoints can do way more than break Tracing is cheaper than debugging IntelliTrace can run in production

PDB Files Contain vital debugging information No PDB? Severely limited debugging experience! Minimal investment: Symbol server Managed PDB files contain – Source file names / line numbers – Local variable names – Alternate streams  Used by TFS

Symbol Servers Central repository for storing debug symbols File system based technology Integrated into Team Foundation and Visual Studio

Locating debug symbols PDB files are located – Same directory as module – Hardcoded path in module – Symbol server cache – Symbol server MyAssembly.dllMyAssembly.pdb GUID Equal

Dumpbin.exe Use to peek inside PE files

Prevent loading all PDBs

Visual Studio Source Server support Allows Visual Studio to download relevant source files automatically from a repository.

Configuring Symbol Locations

PDB alternate streams Used by TFS to store server path to sources

SYMBOL SERVERS, SOURCE SERVERS AND SOURCE INDEXING Demo

Working with break points

Setting breakpoints on automatic properties Use ‘Break at function’ and enter get_name

Setting breakpoints on automatic properties Inspect callstack / locals window

Debugging third party code Red Gate.NET Reflector PRO – Decompile assemblies into source code – Generate PDB file from assembly + source – Enables debugging third party code

Enabling remote debugging Run Remote Debugging x86 or x64 Give permissions Connect

DEBUGGING SHAREPOINT Demo