Debugging With Visual Studio

Sunday, October 16, 2005

A basic introduction of the debugger features for those new to the F5 key.

The debugger in Visual Studio 2005 is an amazing piece of software. You can debug C# and C++, Visual Basic and VBScript. Step over managed code, native code, mobile code, and T-SQL code. You can debug locally, or you can debug remotely. You can debug assemblies hosted by SQL Server, and JavaScript hosted by Internet Explorer. There is just-in-time debugging and Just My Code debugging. You can step into XML web services and into XSL transformations. The debugger has data tips, and data visualizers, breakpoints and tracepoints. You can inspect threads, modules, memory, and call stacks; you can view both local and global variables.

If you have a bug you can’t track down with Visual Studio, you’ve got yourself a real sticky problem.

Read more...


Comments
Jason Haley Sunday, October 16, 2005
Nice article (as always). How do you crank out so much content? I was wanting to write something for DILE like this article, but decided to take the quick way out and just describe it.

Have you checked DILE out yet?
scott Sunday, October 16, 2005
In this case I wrote most of the article on an airplane ride - makes the time go by a little quicker :).

DILE is something I want to check out - I'll make some time this afternoon.
Milan Negovan Monday, October 17, 2005
How do you feel about breakpoint conditions? In 2003 they were a much coveted, but non-functional feature, imho.
scott Tuesday, October 18, 2005
I've used breakpoint conditions a few times - but not as much as I needed to use memory breakpoints in C++ to track down buffer overflow conditions :) I've mostly found them useful inside of a loop when I knew there was a certain value that was causing a problem.
Keyvan Nayyeri Thursday, October 20, 2005
I'm looking for a way to debug assemblies on run time.
+ Thank you for your kindness ;)
Scott Allen Friday, October 21, 2005
Hi Keyvan:

Are you looking to debug a production app? Take a look at : msdn.microsoft.com/.../default.asp
Keyvan Nayyeri Tuesday, October 25, 2005
Dear Scott;
Thank you for that link. It was very helpful ;)
Rakesh Jain Tuesday, November 8, 2005
Hi,
Thanks for a very nice article. I am trying to debug classic ASP pages with 2005 .Net IDE and have no luck I just see a triangle at the break point which says "The break point will not currently be hit. The Specified module has not been loaded."

I would appreciate any help.

Thanks
Rakesh
scott Friday, November 11, 2005
Hi Rakesh:

I'm afraid I have not tried any ASP debugging in quite some time.

Do you have debugging enabled in the virutal directory properties? In the MMC go to the virtual directory properties -> configuration -> debugging and check "Enable ASP server side debugging".
Andy S Tuesday, November 22, 2005
In VS 2003 Prior to clicking F10 I was able to place a breakpoint on the left margin inside the script tags for debugging javascript. In VS 2005 when I try that I get a message that a breakpoint cannot be placed at that point. Why?
scott Wednesday, November 23, 2005
Andy: does IE allow script debugging in Tools -> Options -> Advanced?
Andy S Thursday, December 1, 2005
Scott: Yes the script debugging is turned on. I have VS2003 side by side with VS2005. I converted a 2003 project to 2005 and I try to place a breakpoint at the same location (file/line etc) in both, it works in 03 but not 05???
Ian B Friday, December 23, 2005
That was a very useful and interesting article. I would have liked to see options that are available for remote debugging on a user machine, for example when an app crashes on a remote machine that the developer does not have access to.
Max Wednesday, December 28, 2005
I was looking for ways to debug a vbscript through Visual Studio. I am running my vbscript from the command prompt by passing the command: cscript myvbscript.vbs /X
Now i press enter it starts running. I go to my Visual Studio attach to cmd.exe process and specify debug type as only 'Script', bu when i go back to my running documents i do not see the vbscript. Why is this happening? What do i need to do?
scott Wednesday, December 28, 2005
Max:

Are you using two slashes (cscript //X)? When I do that it prompts me to start a debugger.
Sarah Thursday, January 12, 2006
Scott,

Usually when I hit F5, VS will show autos, locals, and watch under the same window in different tabs docked on the left hand side of the screen. Output, call stack, breakpoints windows are on another window with different tabs docked on the right hand side of the screen. This is the default setting, and I like it.
The past few days, after I debug several times, VS undock all of the above windows and show some additional windows (Memory 1, memory 2, watch 1, watch 2, etc) everywhere on the screen. I have to close most of the windows and dock the necessary windows which slows me down. I have tried to delete the current.vssettings file, but the problem still persists. Would you please advise me on how to fix this problem? Thank you.
Philip Morrison Thursday, January 12, 2006
Scott,
For VisualStudio 2005, do you need to install IIS or some other web server to debug web applications locally? I know you need to do so for VisualStudio 2003. Our security folks are balking at allowing IIS installation on our machines due to the hacker risk.
Philip Morrison (Philip.Morrison@ncmail.net)
scott Friday, January 13, 2006
Sarah:

As a last resort, I would run visual studio from the command line like so:

devenv /resetuserdata

This command should let you start clean. I'm not sure why it behaves that way for you.
scott Friday, January 13, 2006
Philip:

You don't have to have IIS installed with VS2005. VS2005 comes with a little personal web server called WebDev (formerly Cassini). It only serves requests from the local machine.

There are some things IIS can do that WebDev can't. You might talk to your IT department about how to lock down IIS. It can run in a least priviledge account, and you could also configure IIS to only accept requests from the local machine or your network's sub.
Vladimir Wednesday, March 1, 2006
Dear Scott;
Thank you for your article. May be I did not understand ALL the text but I have very simple question. Now I debug single .vbs file in VS2005 by opening it first in Sapien Primal Script program and choosing VS2005 as a debugging tool.
How can I debug single .vbs file in VS2005 without any another program?

scott Sunday, March 5, 2006
Vladimir: I'm not familiar with the Sapien tool, sorry.
Vladimir Monday, March 6, 2006
Dear Scott,
My previous question was not about Sapien tool. The question is very simple:
Is any way to open .vbs-file from an Visual Studio 2005 Interface (or create any project - Which one) and debug it within Visual Studioo as it is possible for another types of files - such as .cpp?


Scott Allen Monday, March 6, 2006
Ah, yes. For .vbs files I typically start the script host with //X. For example:

cscript //X test.vbs

The //X command will launch the JIT debugging menu. Select VS2005 as the debugger to use and step right through the script code.
Vladimir Friday, March 10, 2006
Dear Scott,
Your explanation is true but I can't modify code and restart debugging without using any other (that Visual Studio 2005) editor (notepad, for example).
The key question is: is any way to debug single .vbs file within Visual Studio 2005 environment by modifying code and restart debugging with saved breakpoints as I can do this with any other (except vbs and js) source files?
Thank you very much for you attempting to help us.
Robert Monday, March 13, 2006
In Studio 2005, while Step Over is visible in the Debug menu and toolbar, Step Into is not on either. Why? Is there an option to turn it on/off? In Studio 2003 both were available.
scott Tuesday, March 14, 2006
Opps, I was deleting comment spam and it looks like I deleted a couple comments I left here.

Vladimir: the only thing I can think of to do is to create a blank solution and add your vbs files. Perhaps that will give Visual Studio a place to store settings. Sorry I can't be more helpful.

Robert: VS2005 "customizes" the menus according to the developer type you picked during install. The good news is you can add those commands back in. Go to Tools -> Customize. In the "Categories" list box chose "Debug", then find the "Step Into" in the list on the right. Drag the command onto the menu where you want the command to appear.
Make sense?
Ranv Tuesday, May 2, 2006
Great article, it gets straight to the point and explains everything clearly. Thanks!
prashant gandhi Friday, August 25, 2006
hi,
i went through your website. its quite useful. i am a software engineer by profession and recently started using visual studio 2005 for c++ project. I have a question about breakpoint. I accidentally closed the complete session which had 60 breakpoints all over my project files. I opened the same project again by start->program files -> visual studio 2005... route. All of my breakpoints are gone!! Is there anyway to retrieve them? I don't want to go through entire code again and put them where I was in need of. Are these breakpoints session-based even in same project?

Frustrating... my email address is: ppgandhi11@hotmail.com I will appreciate if you can put me at ease by answering it asap. thanks.

prashant-
scott Saturday, August 26, 2006
Prashant: I don't know what happened to your breakpoints. They should be saved between sessions.
Pat Tuesday, August 29, 2006
When using the VS2005 debugger for C/C++ programs, strings (ie. char szPat[10])does NOT show the correct value. The data is 4 bytes off. Anybody know how to fix this?
Abhijit Monday, January 22, 2007
My executable uses a library (.dll) of my own. While debugging my executable, I want to step into the code of my library as well. I have configured the _NT_SYMBOL_PATH environment variable to point to the dir containing the .pdb file of the library, but the Visual Studio 2005 debugger does not pick it up. Can you give me some pointers about how I could get the .pdb of my library loaded?
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!