.NET DEBUGGING
OOPSOOADSOLIDDPDSSQLXMLFAQ
Module 17 - Console Application
Breakpoint Method Descriptor
Managed Breakpoint at Method Descriptor
For Instance Index, Location etc.
How To
Set Managed Breakpoint1) RUN@ cmd.exe

2) CMD@ TYPE NUL > C:\Source\MyProgram.cs

3) CMD@ notepad.exe C:\Source\MyProgram.cs

4) PAD@ Type the Following C# Code :

/*
File : MyProgram.cs
*/

namespace MyNamespace
{
class MyClass
{
static void Main(string[] myParameters)
{
// Write to Console
System.Console.WriteLine("Hello, World");
}
}
}

5) PAD@ Save (Ctrl+S) and Exit (Ctrl+W)

6) CMD@ csc.exe /target:exe /platform:x64 /debug+ /pdb:C:\Symbol\MyApplication.pdb /out:C:\Executable\MyApplication.exe C:\Source\MyProgram.cs

Microsoft (R) Visual C# Compiler version 4.8.9232.0
for C# 5

...

7) CMD@ cdb.exe -o C:\Executable\MyApplication.exe

Microsoft (R) Windows Debugger Version 10.0.22621.2428 AMD64
...

ntdll!LdrpDoDebuggerBreak+0x30:
...

8) CDB@ sxe ld clr

9) CDB@ g

...

... clr.dll

ntdll!NtMapViewOfSection+0x14:
...

10) CDB@ .loadby SOS clr

11) CDB@ .chain

...

Extension DLL chain:

... SOS.dll: ...

[path: ... SOS.dll]
...

12) CDB@ sxe ld clrjit

13) CDB@ g

...

... clrjit.dll

ntdll!NtMapViewOfSection+0x14:
...

14) CDB@ .reload

Reloading current modules
...

15) CDB@ !SOS.Name2EE MyApplication.exe MyNamespace.MyClass.Main

...

MethodDesc: 00007ffcfe725a70

Name: MyNamespace.MyClass.Main(System.String[])

Not JITTED yet. Use !bpmd -md 00007ffcfe725a70 to break on run.
...

16) CDB@ !SOS.BPMD -md 00007ffcfe725a70

MethodDesc = 00007ffcfe725a70

Adding pending breakpoints...
...

17) CDB@ !SOS.BPMD -list

...

Breakpoint index - Location, ModuleID, Method Token

1 - C:\Executable\MyApplication.exe!MyNamespace.MyClass.Main(System.String[])+0, 0x00007ffcfe7241b8, 0x06000001
...

18) CDB@ g

...

JITTED MyApplication!MyNamespace.MyClass.Main(System.String[])

Setting breakpoint: bp 00007FFCFE8308AC [MyNamespace.MyClass.Main(System.String[])]

Breakpoint 0 hit
...

19) CDB@ qd
cmd.exe : Program, Command Processor

TYPE NUL > : Command, To Create C# Source File

C:\Source\MyProgram.cs : Parameter, C# Source File Name and Extension

notepad.exe : Program, Notepad

csc.exe : Program, C# Command Line Compiler

/target : Option, Specifies Build Type

/platform : Option, Specifies Platform Type

/debug : Option, Specifies Debugging Information

/pdb : Option, Specifies PDB File Name and Extension

/out : Option, Specifies Output File Name and Extension

cdb.exe : Program, CUI Symbolic Debugger

-o : Switch, Specifies Target Application

C:\Executable\MyApplication.exe : Parameter, Console Application

sxe ld : Standard Command, To Break on Module Load

g : Standard Command, To Go Execution

.loadby : Meta Command, To Load Extension DLL

.chain : Meta Command, To List Loaded Extension DLL

.reload : Meta Command, To Reload Module Symbol

!SOS.Name2EE : Extension Command, To Turn Method Name to Method Descriptor

00007ffcfe725a70 : Output, Method Descriptor Address

!SOS.BPMD : Extension Command, To Set Managed Breakpoint

-md : Option, Specifies Method Descriptor

-list : Option, Specifies List of Breakpoint

1 : Output, Breakpoint Index

C:\Executable\MyApplication.exe!MyNamespace.MyClass.Main(System.String[])+0 : Output, Breakpoint Location

qd : Standard Command, To Quit and Detach
Alternatively, RUN@ cmd.exe → TYPE NUL > C:\Source\MyProgram.cs → notepad.exe C:\Source\MyProgram.cs → PAD@ Type C# Code, Save and Exit → RUN@ windbg.exe -o C:\Executable\MyApplication.exe → View → Command (Alt+1) → g; sxe ld clr; g; .loadby SOS clr; .chain; sxe ld clrjit; g; .reload; !SOS.Name2EE <Module Name> <Method Name>; !SOS.BPMD -md <Method Descriptor>; !SOS.BPMD -list; qd
AMD
Advanced Micro Devices

BP
Breakpoint

CDB
Console Debugger

CLR
Common Language Runtime

CMD
Command

CS
C Sharp

CSC
C Sharp Compiler

CUI
Character User Interface

DBG
Debugger

DLL
Dynamic Link Library

EE
Execution Engine

EXE
Executable

G
Go

ID
Identifier

JIT
Just In Time

LD
Load

LDR
Loader

MD
Method Descriptor

NT
New Technology

NUL
NULL

PDB
Program Database

QD
Quit Detach

SOS
Son Of Strike

SXE
Set Exception Enabled

WIN
Windows

x64
64-Bit CPU Architecture