Advanced Debugging in Visual Studio. Introduction. Many of us developers do not look beyond the basic F9, F1. F1. 1, F5 and Watch windows while debugging in Visual Studio. Due to this we end up wasting hours debugging an issue or simulating a condition which ideally could have been achieved in a matter of minutes if we utilized the rich debugging features available out of the box in Visual Studio. Advanced debugging tips are scattered all over the web but I thought that a consolidated list would be very useful for developers to embrace and start using the techniques.
I am having a Visual studio 2015 with WDK 8.1, I am running a *post build* operation which involved the.cat file generated by inf2cat. When using WDK8.1 everything works perfectly fine. To step from Visual Studio code into a stored procedure, you must enable SQL Debugging in the Project Properties on the Debugging page. To step through stored procedure code, you must set a.
Environment. The tips in this article should work. Visual Studio 2. 00. Many of these might still be valid for the next. Visual Studio. Tip List. To make going through this article easier, I am breaking it into six different tips which I will present with the help of sample code and screenshots.
I use the same technique as you are trying Jon, without the /assembly flag, i.e. Start External Program: C:\Program Files\NUnit 2.4.8\bin\nunit.exe Command line arguments: '<path>\bin\Debug\Quotes.Domain.Tests.dll' Does. Hello, Some times ago I already posted a question about Android device. But this situation is not fixed yet. If I select Android or iOS project in Visual Studio, I cannot select any device or emulator/simulator. Developing workflows are more interesting with Visual Studio 2012, WF 4.5 and Workflow Manger 1.0.The method of debugging the workflow with the Workflow Manager is different from using other workflow hosting approaches. IE is crashing randomly - I receive the following msg.: Microsoft Visual C++ Debug Library Debug Assertion Failed Program:c:\programfiles\internetexplorer\iexplore.exe File: dbgheap.c I have a similar problem! Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436.
Attach to process - using macro. Immediate Window - Calling functions directly - Setting and Displaying variables. Debugging a Windows Service. Having fun with breakpoints - Trace Points- Condition- Hit Count- Filter- Changing breakpoint location. Locals/Auto/ Call Stack. Bonus Tip! Enable Sound when Breakpoint is hit.
Magic of “Make Object Id”Sometimes we want to track an object even after it went out of the scope. We may need this ability to debug an issue which requires us to track the object until it is garbage collected. This ability is provided with the Object Id feature in Visual Studio debugger. Follow the below steps to try it yourself. Set a Breakpoint on a line of code which uses a variable your want to track as shown below.
Run your application in debug mode and let it stop at the Breakpoint. Right Click on str and click Add Watch. In your Watch 1 window, right- click the object variable str and choose .
Makes sense as value types will get stored on the stack and will get popped out as soon as the scope ends. So they would ideally not depend the Garbage Collector to get cleaned up. Attach to process – using macro. There are many tasks that we do in Visual Studio that are repetitive. One such example is attaching to process.
Having the ability to debug an existing running process (Ex. Process of a . net console application exe) is a common requirement. The usual. way would be using the Attach To Process window from Debug - > Attach To. Process in Visual Studio. But this can become cumbersome and irritating if.
This is where. macros come to our rescue. Create a simple console. Main method and a method Test. Attach. To. Process.
Macro shown. below. Make a call to this method from the Main function.
Build the console application. This will generate the. Double click and start the application using this. The first break point shown in the code above will not. We want to debug from the second breakpoint by attaching. Now we start recording our macro in 5 simple steps –i.
Click. Record Temporary. Macro from the Tool - > Macros menu as shown below: ii. Now perform. the necessary actions to attach to the process as below: Click Debug - > Attach to Process. In the popup below find your process. Attach. iii. Stop recording the macro using. Tools - > Macros as below: iv. Save the macro using Tools - >.
Macros as below: v. Upon saving, the macro will appear. Macro Explorer. I have named it Attach. To. My. Program. 5. Lastly we can also place a shortcut to this macro on the. Debug toolbar to make things even simpler.
Go to Tools - > Customize - > Commands. Toolbar dropdown select Debug as below: ii. Hit the Add Command button and on.
Categories and Attach. To. My. Program under. Now from under the Modify. Selection rename the command as shown below: iv. Now the Attach. To. My. Program shortcut.
Debug toolbar as shown below: 6. Now close the console application and start again. We. will again see the “I am started” message. Now simply hit the Attach. To. My. Process shortcut on the Debug bar and press any key in the console application window.
You are in the debug session and the second breakpoint is hit. Now you. can easily attach to your process with a click of a button. Immediate window.
So many times we write a function and wish to debug just. Many. of us have been running the entire application in effort to reach that function. Well, that’s unnecessary. This is where the Immediate. You can open it using the keyboard shortcut Ctrl + Alt +. I. And this is how it works: Calling functions directly. Let us try to call the below function directly from the Immediate.
We can call this function from Immediate window directly as. Upon hitting enter in Immediate window, the breakpoint in. Test. Immediate. Window. On proceeding you get the output in the Immediate window. You can play around with the . Debugging a Windows Service. Debugging the windows service can become a daunting task if you are not aware about this tip.
You would build and deploy the service and start it. Then from Visual Studio you would use Attach to Process to start debugging.
Even then if you need to debug what happens in the On. Startmethod, then you would have to do a Thread. Sleep() or something so that the On. Startmethod waits for you while you attach to the process.
We can avoid all the pain by this simple tip. Step 1: Set the Output type of the Windows Service to Console Application: Step 2: Next get rid of the Program. Service file which inherits from Service. Base. Now you can run the windows service in debug and it will run as a console application.
Or you can deploy as usual and it will function as a windows service. My. Service : Service. Base. . Having fun with breakpoints. You. can use below variations of breakpoints in isolation or combine them together. Trace Points (When Hit.)Sometimes. Doing this by setting a normal breakpoint can be very time. So we usually use Console.
Write. Line to print the value. Instead if it’s. a temporary check using Trace. Points is better. It serves the same purpose as a Console. Write. Linewould.
The advantage is that you don’t have to disturb the. Console. Write. Line and risk forgetting to remove it when.
Better still, this way you can utilize other features of breakpoint by. Trace. Point. Lets. Set. a break point at call to Reverse. String function as shown below. Then. right click and click . The. breakpoint will get converted into a Trace.
Point (diamond shaped) as shown below. Now whenever the breakpoint is hit, it does not break in. Me. variable at each hit as below in the output window: Condition. Condition. breakpoints can be used to avoid having to write extra if/ else conditions in.
Right. click the tracepoint we set above and click Condition from under Breakpoints. Also you can choose when you want break at the breakpoint. Change the Condition breakpoint to i > 4. Then Right. Click - > Breakpoint - > Hit Count.
Now the breakpoint will be hit after every 5 iterations. Notice. below output is effect of both the Condition and the Hit Count breakpoint. The hit count shown below says that the breakpoint was hit. Filter. Useful for multi threaded applications.
If multiple threads. Right Click - > Breakpoint - > Filter.
Changing Breakpoint Location. If. you wish to move the breakpoint to a different line then use this option. Locals/ Autos/ Call Stack. The. following three windows can come in handy while debugging. You can access them. Go to Debug - > Windows in the Visual Studio menu.
The Autos window displays variables used in the current statement and the. Helps you concentrate only on the variables being used in. For. Visual Basic.
Net, it displays variables in the current statement and three. LOCALS. The Locals window displays variables local to the current context. You can observe. values of local variables in a function here.
Note that class level variable. CALL. STACK: The Call Stack displays the entire tree of function calls leading. Can help you trace back the culprit!
Bonus Tip! Enable. Sound when Breakpoint is hit. Go to Control Panel - > Sounds and Audio Devices (Windows XP).
Its Control Panel - > Sound in Windows 7. Find and Select “Breakpoint Hit” under Program events in. Sounds tab. Choose the sound of your choice and click OK. Now when a breakpoint is hit, you will hear the sound! History. 18th January 2.
Incorporated Blaise's suggestion to add Debugger. Launch() option in Tip no. January 2. 01. 2: Added a note at the end of tip 1 - Make Object Id; as per suggestion by. Shivprasad Koirala.