Setting Breakpoints in Visual Studio .NET

Printing QR Code 2d barcode in Visual Studio .NET Setting Breakpoints
Setting Breakpoints
Making QR Code ISO/IEC18004 In Visual Studio .NET
Using Barcode maker for .NET Control to generate, create QR Code JIS X 0510 image in VS .NET applications.
bp = new Breakpoint(); bpAddAndPrint(100, 50); } public void AddAndPrint(int a, int b) { int res = a + b; ConsoleWriteLine("Adding {0}+{1}={2}", a, b, res); } } }
Denso QR Bar Code Reader In .NET Framework
Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
The source code and binary for Listing 3-8 can be found in the following folders:
Print Barcode In VS .NET
Using Barcode maker for .NET framework Control to generate, create bar code image in Visual Studio .NET applications.
Source code: C:\ADND\3\Breakpoint Binary: C:\ADNDBin\03breakpointexe
Barcode Scanner In .NET Framework
Using Barcode scanner for VS .NET Control to read, scan read, scan image in VS .NET applications.
Setting Breakpoints on JIT Compiled Functions
Drawing QR Code ISO/IEC18004 In Visual C#.NET
Using Barcode maker for VS .NET Control to generate, create QR Code JIS X 0510 image in .NET framework applications.
As discussed earlier, a function is compiled by the just in time compiler and placed in memory If we knew the address of where the JIT compiler places the machine code, we can use the debugger s bp command to set a breakpoint Let s use the 03breakpointexe application discussed previously and see if we can set a breakpoint on the AddAndPrint function More specifically, we d like to set a breakpoint on the second invocation of the function to investigate a potential bug in it Begin by starting 03breakpointexe under the debugger and resume execution until the first prompt is shown asking you to press any key Press any key and wait until the second prompt to press any key At this point, break into the debugger using CTRL-C This is the starting point of setting a breakpoint in the second AddAndPrint function The first task is to figure out whether the function has been compiled by the JIT compiler The key to finding this out is to use the SOS command called name2ee The name2ee command takes the following form:
QR-Code Creator In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create QR Code image in ASP.NET applications.
3 BASIC DEBUGGING TASKS
Generating Quick Response Code In VB.NET
Using Barcode creation for Visual Studio .NET Control to generate, create QR Code image in .NET applications.
!name2ee <module name> <type or method name>
Barcode Generation In .NET Framework
Using Barcode maker for VS .NET Control to generate, create bar code image in .NET framework applications.
The module name parameter is the module of interest and the type or method name (fully qualified) is the name of the type or method that you want to get information about In our case, the module name is 03breakpointexe and the type name is AdvancedNETDebugging3BreakpointAddAndPrint
Data Matrix 2d Barcode Generator In .NET
Using Barcode creator for .NET framework Control to generate, create Data Matrix image in .NET applications.
3
Barcode Generation In VS .NET
Using Barcode creation for .NET framework Control to generate, create barcode image in Visual Studio .NET applications.
Basic Debugging Tasks
UCC - 12 Encoder In .NET Framework
Using Barcode maker for .NET Control to generate, create UPC Symbol image in VS .NET applications.
0:004> !name2ee 03breakpointexe AdvancedNETDebugging3BreakpointAddAndPrint Module: 00112d8c (03Breakpointexe) Token: 0x06000002 MethodDesc: 00113178 Name: AdvancedNETDebugging3BreakpointAddAndPrint(Int32, Int32) JITTED Code Address: 003e0178 0:004>
Identcode Maker In .NET
Using Barcode encoder for .NET framework Control to generate, create Identcode image in Visual Studio .NET applications.
As you can see, the last line of the output states that the method has been JITTED (another term for just in time compiled) and that the address of the compiled code is 003e0178 We can do a brief sanity check on this code by using the U command (discussed in more detail later), as shown in Listing 3-9 Listing 3-9 Sanity checking the JIT address by disassembling the JIT generated code
Generating Barcode In Visual C#.NET
Using Barcode printer for Visual Studio .NET Control to generate, create bar code image in Visual Studio .NET applications.
0:004> !U 003e0178 Normal JIT generated code AdvancedNETDebugging3BreakpointAddAndPrint(Int32, Int32) Begin 003e0178, size 80 >>> 003e0178 57 push edi 003e0179 56 push esi 003e017a 53 push ebx 003e017b 55 push ebp 003e017c 83ec08 sub esp,8 003e017f 890c24 mov dword ptr [esp],ecx 003e0182 8bfa mov edi,edx 003e0184 833d582f110000 cmp dword ptr ds:[112F58h],0 003e018b 7405 je 003e0192 003e018d e8b581d479 call mscorwks!JIT_DbgIsJustMyCode (7a128347) 003e0192 33d2 xor edx,edx 003e0194 89542404 mov dword ptr [esp+4],edx 003e0198 90 nop 003e0199 8b44241c mov eax,dword ptr [esp+1Ch] 003e019d 03c7 add eax,edi 003e019f 89442404 mov dword ptr [esp+4],eax 003e01a3 8b1d4c30c602 mov ebx,dword ptr ds:[2C6304Ch] ("Adding {0}+{1}={2}") 003e01e2 8bd5 mov edx,ebp 003e01e4 8bcb mov ecx,ebx 003e01e6 e8359c0079 call mscorlib_ni+0x329e20 (793e9e20) (SystemConsoleWriteLine (SystemString, SystemObject, SystemObject, SystemObject), mdToken: 060007c8) 003e01eb 90 nop 003e01ec 90 nop
Printing Data Matrix 2d Barcode In Visual Basic .NET
Using Barcode encoder for .NET Control to generate, create DataMatrix image in VS .NET applications.
Setting Breakpoints
Making Bar Code In Java
Using Barcode creation for Java Control to generate, create barcode image in Java applications.
003e01ed 003e01ee 003e01f1 003e01f2 003e01f3 003e01f4 003e01f5 0:004>
Making Barcode In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create barcode image in ASP.NET applications.
90 83c408 5d 5b 5e 5f c20400
Bar Code Drawer In Visual Basic .NET
Using Barcode generation for VS .NET Control to generate, create bar code image in Visual Studio .NET applications.
nop add pop pop pop pop ret
EAN128 Creator In Java
Using Barcode drawer for Java Control to generate, create GS1 128 image in Java applications.
esp,8 ebp ebx esi edi 4
Encode Code39 In Java
Using Barcode creation for Java Control to generate, create Code39 image in Java applications.
The first part of the disassembly gives a good indication of the correctness of the address passed in to the U command We can see that the U command tells us that the code located on that address is Normal JIT generated code In addition, the next line also tells us the full name of the method that the code corresponds to (in our case, AdvancedNETDebugging3BreakpointAddAndPrint) Finally, the third line tells us the starting address (003e0178) and the size of the generated code (80) After the initial set of information, the disassembled instructions are shown We have now located the proper address for the dynamically generated code and set a breakpoint on it If we resume execution (don t forget to press a key to start the second call), we very quickly hit the breakpoint, as shown in the following:
Code 128A Generation In Visual C#.NET
Using Barcode encoder for Visual Studio .NET Control to generate, create Code 128 image in .NET framework applications.
0:003> g Breakpoint 0 hit eax=01cdbed8 ebx=0025f0fc ecx=01cdbed8 edx=00000064 esi=01cdbed8 edi=01cdbed8 eip=003f0178 esp=0025f09c ebp=0025f0e0 iopl=0 nv up ei ng nz ac pe cy cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000297 003f0178 57 push edi 0:000> !ClrStack OS Thread Id: 0xf7c (0) ESP EIP 0025f09c 003f0178 AdvancedNETDebugging3BreakpointAddAndPrint(Int32, Int32) 0025f0a4 003f0105 AdvancedNETDebugging3BreakpointMain(SystemString[]) 0025f2f0 79e7c74b [GCFrame: 0025f2f0]
After the breakpoint hits, we use the ClrStack command to ensure that we have hit the correct code location Initially, we said we wanted to set a breakpoint on the second invocation of AddAndPrint due to a potential bug related to that particular invocation I m sure by now you ve figured out that the reason for setting a breakpoint on the second invocation is due to the easy nature of setting a breakpoint on a function that has already been JIT compiled (prior invocation of the same function caused it to be JIT compiled) Simply use the name2ee command to find out the address of the JIT compiled code and use the bp command