Intro to Windows Debugger (Windbg) for .NET Developers and Concepts in C# Vijay Rodrigues (Vijayrod) Last Updated: 2011-11-30 I
Total Page:16
File Type:pdf, Size:1020Kb
Intro to Windows Debugger (WinDBG) for .NET Developers And Concepts in C# Vijay Rodrigues (VijayRod) Last Updated: 2011-11-30 I’ve written this content as part of driving .Net Academy. Most of content has been written at home in my spare time with a real slow internet connection. Due to its very nature of publicly available symbols, .Net and its debugging information is publicly available on the internet. Hence this content can be freely redistributed for non-commercial use. A lot of acknowledgements to Ranjan Bhattacharjee for this idea, to Xavier S Raj for valuable mentorship and for the logo, and to Rishi Maini for his guidance whenever required. We’ve also discussed this with multiple resources and got ideas from them. They’ve made a difference - Kane Conway, Satya Madhuri Krovvidi, Dhiraj H N, Durai Murugan, Varun Dhawan, Balmukund Lakhani, Anmol Bhasin, Tejas Shah, Ajith Krishnan, Shasank Prasad, Chandresh Hegde. If you have any new inputs or suggestion that will help this effort please let me know. Table of Contents Section i: Getting Started 1. To give a start 2. Introduction and Concepts 3. Learning - videos (and books) 4. Learning - Advantages of C# over VB.NET and vice versa 5. Practical guide to .Net debugging 6. Useful websites Section ii: Introduction 7. Introduction 8. Intro to WinDBG for .NET Developers - part II 9. Intro to WinDBG for .NET Developers - part III (Examining code and stacks) 10. Intro to WinDBG for .NET Developers - part IV (Examining code and stacks contd.) 11. Intro to WinDBG for .NET Developers - part V (still more on Examining code and stacks) 12. Intro to WinDBG for .NET Developers - part VI (Object Inspection) 13. Intro to WinDBG for .NET Developers - part VII (CLR internals) 14. Intro to WinDBG for .NET Developers - part VIII (more CLR internals - Application Domains) 15. Intro to WinDBG for .NET Developers - part IX (still more CLR internals - Memory Consumption) 16. Intro to WinDBG for .NET Developers - part X (still more CLR internals - Memory/VAS Fragmentation) 17. Intro to WinDBG for .NET Developers - part XI (still more CLR internals - Value types) 18. Intro to WinDBG for .NET Developers - part XII (still more CLR internals - String/Reference types) 19. Intro to WinDBG for .NET Developers - part XIII (still more CLR internals - Operators) 20. Intro to WinDBG for .NET Developers - part XIV (still more CLR internals - Arrays) 21. Intro to WinDBG for .NET Developers - part XV (still more CLR internals - Conditionals) 22. Intro to WinDBG for .NET Developers - part XVI (still more CLR internals - Loops) 23. Intro to WinDBG for .NET Developers - part XVII (still more CLR internals - Methods) 24. Intro to WinDBG for .NET Developers - part XVIII (still more CLR internals - Classes) 25. Intro to WinDBG for .NET Developers - part XIX (still more CLR internals - Inheritance) 26. Intro to WinDBG for .NET Developers - part XX (still more CLR internals - Method overriding) 27. Intro to WinDBG for .NET Developers - part XXI (still more CLR internals - Access Modifiers) 28. Intro to WinDBG for .NET Developers - part XXII (still more CLR internals - Static) 29. Intro to WinDBG for .NET Developers - part XXIII (still more CLR internals - Properties) 30. Intro to WinDBG for .NET Developers - part XXIV (still more CLR internals - Indexers) 31. Intro to WinDBG for .NET Developers - part XXV (still more CLR internals - Interface) To give a start Thanks to Tejas Shah for this sample! Have fun with this sample. And then try and figure out why the differences. ---------- Sample code---------- using System; using System.Collections.Generic; using System.Text; using System.Globalization; using System.Threading; namespace stringdctest { class Program { static void spanishTest() { CultureInfo myCItradES = new CultureInfo(0x040A, false); //Thats es- ES culture - same rules as Czech CultureInfo myCItradUS = new CultureInfo(0x0409, false); //Thats en- US culture - same rules as Czech string s1 = "cHa"; string s2 = "cha"; int result1 = String.Compare(s1, s2, true, myCItradUS); Console.WriteLine("\nWhen the CurrentCulture is \"en- US\",\nthe result of comparing {0} with {1} is: {2}", s1, s2, result1); result1 = String.Compare(s1, s2, true, myCItradES); Console.WriteLine("\nWhen the CurrentCulture is \"es- ES\",\nthe result of comparing {0} with {1} is: {2}", s1, s2, result1); } static void danishTest() { CultureInfo myCItraddn = new CultureInfo(0x0406, false); //Thats da- DK culture - same rules as Czech CultureInfo myCItradUS = new CultureInfo(0x0409, false); //Thats es- ES culture - same rules as Czech string s1 = "aab"; string s2 = "aAb"; int result1 = String.Compare(s1, s2, true, myCItradUS); Console.WriteLine("\nWhen the CurrentCulture is \"en- US\",\nthe result of comparing {0} with {1} is: {2}", s1, s2, result1); result1 = String.Compare(s1, s2, true, myCItraddn); Console.WriteLine("\nWhen the CurrentCulture is \"da- DK\",\nthe result of comparing {0} with {1} is: {2}", s1, s2, result1); } static void Main(string[] args) { spanishTest(); danishTest(); Console.Read(); } } } When the CurrentCulture is "en-US", the result of comparing cHa with cha is: 0 When the CurrentCulture is "es-ES", the result of comparing cHa with cha is: -1 When the CurrentCulture is "en-US", the result of comparing aab with aAb is: 0 When the CurrentCulture is "da-DK", the result of comparing aab with aAb is: 1 Answer Interesting sample. String class represents text as a series of Unicode characters so I did not have to check on code pages hence the difference appears to be due to Cultures. This is also a case insensitive comparison. Differences are due to using culture-sensitive operations when results should be independent of culture which can cause application code, like below sample, to return different results on cultures with Custom Case Mappings and Sorting Rules. For example, in the Danish language (da-DK in below sample), a case-insensitive comparison of the two-letter pairs "aA" and "AA" is not considered equal. Most .NET Framework methods that perform culture-sensitive string operations by default provide method overloads that allow you to explicitly specify the culture to use by passing a CultureInfo parameter or a System.Globalization.CompareOptions parameter. These overloads allow you to eliminate cultural variations in case mappings and sorting rules and guarantee culture-insensitive results. For example and depending on the desired behavior of the application, String.Compare can be used with the System.Globalization.CompareOptions parameter to avoid customer mappings and to avoid custom sorting rules, if required. using System; using System.Collections.Generic; using System.Text; using System.Globalization; using System.Threading; namespace stringdctest { class Program { static void spanishTest() { CultureInfo myCItradES = new CultureInfo(0x040A, false); //Thats es-ES culture - same rules as Czech CultureInfo myCItradUS = new CultureInfo(0x0409, false); //Thats en-US culture - same rules as Czech string s1 = "cHa"; string s2 = "cha"; int result1 = String.Compare(s1, s2, true, myCItradUS); Console.WriteLine("\nWhen the CurrentCulture is \"en-US\",\nthe result of comparing {0} with {1} is: {2}", s1, s2, result1); result1 = String.Compare(s1, s2, true, myCItradES); Console.WriteLine("\nWhen the CurrentCulture is \"es-ES\",\nthe result of comparing {0} with {1} is: {2}", s1, s2, result1); result1 = String.Compare(s1, s2, myCItradES, CompareOptions.OrdinalIgnoreCase); Console.WriteLine("\nWhen the CurrentCulture is \"es-ES\" AND using OrdinalIgnoreCase,\nthe result of comparing {0} with {1} is: {2}", s1, s2, result1); } static void danishTest() { CultureInfo myCItraddn = new CultureInfo(0x0406, false); //Thats da-DK culture - same rules as Czech CultureInfo myCItradUS = new CultureInfo(0x0409, false); //Thats en-US culture - same rules as Czech string s1 = "aab"; string s2 = "aAb"; int result1 = String.Compare(s1, s2, true, myCItradUS); Console.WriteLine("\nWhen the CurrentCulture is \"en-US\",\nthe result of comparing {0} with {1} is: {2}", s1, s2, result1); result1 = String.Compare(s1, s2, true, myCItraddn); Console.WriteLine("\nWhen the CurrentCulture is \"da-DK\",\nthe result of comparing {0} with {1} is: {2}", s1, s2, result1); result1 = String.Compare(s1, s2, myCItraddn, CompareOptions.OrdinalIgnoreCase); Console.WriteLine("\nWhen the CurrentCulture is \"da-DK\" AND using OrdinalIgnoreCase,\nthe result of comparing {0} with {1} is: {2}", s1, s2, result1); } static void Main(string[] args) { spanishTest(); danishTest(); Console.Read(); } } } When the CurrentCulture is "en-US", the result of comparing cHa with cha is: 0 When the CurrentCulture is "es-ES", the result of comparing cHa with cha is: -1 When the CurrentCulture is "es-ES" AND using OrdinalIgnoreCase, the result of comparing cHa with cha is: 0 When the CurrentCulture is "en-US", the result of comparing aab with aAb is: 0 When the CurrentCulture is "da-DK", the result of comparing aab with aAb is: 1 When the CurrentCulture is "da-DK" AND using OrdinalIgnoreCase, the result of comparing aab with aAb is: 0 More info: http://msdn.microsoft.com/en-us/xk2wykcz Custom Case Mappings and Sorting Rules http://msdn.microsoft.com/en-us/x15ca6w0 Performing Culture-Insensitive String Operations Learning - videos (and books) Some of us were discussing on quick and easy ways to learn C#/.NET. We wanted to list this so as to help go through this data during any free time. Our discussions seemed to be on “easy” or “videos” (or “books”) (I myself like reading but prefer quick