SharePoint Saturday Belgium 2014 All about OneDrive for Business and OneDrive
SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications
-
Upload
biwug -
Category
Technology
-
view
353 -
download
1
description
Transcript of SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications
![Page 1: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/1.jpg)
Production debugging of SharePoint applications
#SPSBEUKWouter van VugtApril 26th, 2014
![Page 2: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/2.jpg)
Thanks to our sponsors!
Gold
Silver
![Page 3: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/3.jpg)
Agenda• .NET and CLR primer• Optimizing code and the effect on debuggers• Debugging third party code
![Page 4: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/4.jpg)
.NET and CLR primer
![Page 5: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/5.jpg)
.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
![Page 6: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/6.jpg)
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
![Page 7: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/7.jpg)
Type Safety• 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
![Page 8: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/8.jpg)
Circumventing type safetyDemo
![Page 9: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/9.jpg)
Creating .NET Applications
C#, C++, VB.NET,
F#.... (40+)
Module
PDB
Compile LinkAssembly
PDB
![Page 10: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/10.jpg)
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
![Page 11: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/11.jpg)
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
Console metadata
static void WriteLine(string)
JIT Compiler Address
static void WriteLine()
JIT Compiler Address
Native CPU Instruction
s
Native Address
![Page 12: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/12.jpg)
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 Instruction
s
![Page 13: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/13.jpg)
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 …
![Page 14: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/14.jpg)
Running non optimized code
• Breakpoints • Edit and continue
![Page 15: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/15.jpg)
C# Compiler – Variable Generation
![Page 16: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/16.jpg)
C# Compiler – Variable GenerationDebug Release
![Page 17: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/17.jpg)
C# Compiler – Inserting NOP
![Page 18: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/18.jpg)
C# Compiler – Inserting NOP
Debug Release
![Page 19: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/19.jpg)
C# Compiler – Branching
![Page 20: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/20.jpg)
C# Compiler – Branching
Debug Release
![Page 21: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/21.jpg)
Compile time optimizationsDemo
![Page 22: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/22.jpg)
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 switch C# IL Code Quality JIT Native Code Quality
/optimize- /debug- Unoptimized Optimized
/optimize- /debug+ Unoptimized Unoptimized
/optimize+ /debug+ Optimized Optimized
![Page 23: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/23.jpg)
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”
![Page 24: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/24.jpg)
JIT - Local variable eliminationUser user = GetUser(3);PrintUser(user);
PrintUser(GetUser(3));
Before
After
![Page 25: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/25.jpg)
JIT – Range check eliminationstatic 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
![Page 26: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/26.jpg)
JIT – Method Inliningpublic 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
![Page 27: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/27.jpg)
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);}
![Page 28: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/28.jpg)
Native NGEN images are hard to debugRemove the NGEN image
Or, prevent NGEN image from loading
Loading non-precompiled assemblies
C:\> SET COMPLUS_ZAPDISABLE=1
C:\> NGEN uninstall MyAssembly
![Page 29: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/29.jpg)
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=1AllowOptimize=0
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.EnableEditAndContinue | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.Default)]
![Page 30: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/30.jpg)
Debugging optimized codeDemo
![Page 31: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/31.jpg)
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
![Page 32: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/32.jpg)
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
![Page 33: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/33.jpg)
Symbol Servers• Central repository for storing debug symbols• File system based technology• Integrated into Team Foundation and Visual
Studio
![Page 34: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/34.jpg)
Locating debug symbols
• PDB files are located Same directory as module Hardcoded path in module Symbol server cache Symbol server
MyAssembly.dll MyAssembly.pdb
GUID GUIDEqual
![Page 35: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/35.jpg)
Dumpbin.exe• Use to peek inside PE files
![Page 36: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/36.jpg)
Prevent loading all PDBs
![Page 37: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/37.jpg)
Visual Studio Source Server support• Allows Visual Studio to download relevant source
files automatically from a repository.
![Page 38: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/38.jpg)
Configuring Symbol Locations
![Page 39: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/39.jpg)
PDB alternate streams• Used by TFS to store server path to sources
![Page 40: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/40.jpg)
SYMBOL SERVERS, SOURCE SERVERS AND SOURCE INDEXING
Demo
![Page 41: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/41.jpg)
Working with break points
![Page 42: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/42.jpg)
Setting breakpoints on automatic properties• Use ‘Break at function’ and enter get_name
![Page 43: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/43.jpg)
Breakpoints on automatic properties• Inspect callstack / locals window
![Page 44: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/44.jpg)
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
![Page 45: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/45.jpg)
Enabling remote debugging• Run Remote Debugging x86 or x64• Give permissions• Connect
![Page 46: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/46.jpg)
Debugging SharePointDemo
![Page 47: SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applications](https://reader036.fdocuments.net/reader036/viewer/2022062617/54be8bbf4a7959480b8b4603/html5/thumbnails/47.jpg)
Thank you!