Posts

Showing posts with the label cdb windbg

Dumping the method descriptor for a System.Action (delegate)

In my previous post I needed to figure out what method descriptor a System.Action points to. This is painful so I wrote a small debugger script to automate it.  To use the script, copy  this code  to dumpMDForAction.dbg. Many thanks to Alois Kraos  for posting how to do this. Without further ado, fire up cdb and  find a System.Action: 0:000> !do 0000003de7023078 Name: System.Action MethodTable: 000007f9d26b9a68 EEClass: 000007f9d2071c10 Size: 64(0x40) bytes File: C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll Fields: MT Field Offset Type VT Attr Value Name 000007f9d26c1ac8 400002d 8 System.Object 0 instance 0000003de7023078 _target 000007f9d26c1ac8 400002e 10 System.Object 0 instance 0000003de7028800 _methodBase 000007f9d26c60d8 400002f 18 System.IntPtr 1 instance 3de52e0...

Run time costs of small operations in C#.

Image
Thank you smart people that helped me understand this:  Vance Morrison ; Kevin Frei; Dave Detlefs; Jan Kotas; Sean Selitrennikoff; Nathan Iarovich; Dave Driver. One of my colleagues read this post and pointed out for really small operations e.g  {i++ } the cost of the measurement system is exceeding the cost of the operations. I agree completely,  and recommend using  measure it  and reading the help if you need to measure small things. My colleague also noticed something interesting; in this code    (full  code  here , proof of concept in linqpad using measureit .) : class Program { static int interlocked = 0; static int staticInt = 0; static void DoNop() { } static void IncrementStaticInt() { staticInt++; } // This is an array to make it easier to debug in cdb. static NamedAction[] namedActions; static void Main(string[] args) { int loc...

Using WinDBG/CDB and SOS to find a thread given a ManagedThreadId

CDB and SOS have more power than most people realize, I’ll use this post to show some some handy cdb/sos tricks while at the same answering the simple question of which thread a ManagedThreadId maps to. At the end of this post you’ll be able to: Map a ManagedThreadId to the correct thread ordinal Use CDB to convert from decimal to hex Pipe CDB commands through pipeline commands like findstr Full source for the simple app below can be found here . In the below app we want to figure which thread we’re running on so we can inspect the stack. internal class Program { private static void SleepForever() { Thread.Sleep(Int32.MaxValue); } static void Main(string[] args) { const int countThreadsToStart = 20; foreach (var unused in Enumerable.Range(0, countThreadsToStart)) { // Instantiate thread that prints and stores its ManagedThreadId. new Thread(() => {...

Use cdb to see what files your application is opening.

In this post I'll show you how to use CDB to intercept CreateFile and see what files your application is opening. For this problem, Process Monitor is often a better tool, but the techniques I demonstrate work for any API you should learn them. This won't take much time, so if you've never done this before I recommend you follow along. First Load CDB against cmd: C:\Program Files\Debugging Tools for Windows (x64)>cdb.exe cmd.exe Microsoft (R) Windows Debugger Version 6.12.0000.526 AMD64 Copyright (c) Microsoft Corporation. All rights reserved. CommandLine: cmd.exe Symbol search path is: *** Invalid *** **************************************************************************** * Symbol loading may be unreliable without a symbol search path. * * Use .symfix to have the debugger choose a symbol path. * * After setting your symbol path, use .reload to refresh symbol locations. * ******************...

Finding CLR exceptions without visual studio

(If you want to understand what exception code 0xe0434352 is, read this post ) Often exceptions are thrown and caught and you don't see them. You probably know how to debug this in Visual Studio, so let me show you how to do it in cdb. Sample Code: class Program { static void Main(string[] args) { foreach (var x in Enumerable.Range(0,2000)) { Thread.Sleep(TimeSpan.FromSeconds(1)); Console.WriteLine("Hello World"); ThrowAndCatchException(); } } private static void ThrowAndCatchException() { try { throw new NotImplementedException(); } catch(Exception) { } } } Output of the application: Hello World Hello World Hello World Nothing about an exception, but you're sure it's happening behind the covers -- fire up cdb: C:\Program Files\Debugging Tools for Windows (x64)>cdb -pn consoleapplication3.exe <SNIP> ModLoad: 000007fe`f7e90000 000007fe`f7eb4000 C:\Windows\Mi...

How to attach to an already running debugger target using cdb.

For the last year when I wanted to attach to a process using cdb, I'd attach by PID. This meant i'd need to the following dance: C:\Program Files\Debugging Tools for Windows (x64)>tlist |findstr firefox 9128 cmd.exe findstr firefox 276 firefox.exe Restore Session - Vimperator C:\Program Files\Debugging Tools for Windows (x64)>cdb -p 276 It turns out you can just do: C:\Program Files\Debugging Tools for Windows (x64)>cdb -pn firefox.exe Microsoft (R) Windows Debugger Version 6.11.0001.404 AMD64 Copyright (c) Microsoft Corporation. All rights reserved. If there are multiple instances of your process, you'll still need to use tlist to find the PID you're interested in.