Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's your favorite way to debug your program in Visual Studio? [closed]

These day I come up with a large software.

I have to debug in Visual Studio 2008.

The steps I take are:

  1. Using callstack window to find the code blocks that I i thinks it may have bugs.

  2. Using Immediate windows to call some local functions to see whether the data structures in this blocks are correct.

  3. When I got the result in step 2,I have to go to step 1 to find the source of the bug using callstack again.

What is your favorite method to debug large or small program in Visual Studio?

I don't think to run whole the program and watch all the related data structure is good way to debug.

like image 896
MainID Avatar asked Feb 28 '23 23:02

MainID


1 Answers

I prefer unit tests over using the immediate window, mostly because it means I can run the code over and over again extremely simply (and indeed from a build script).

If you find the problem using the immediate window and fix it without adding any tests, you don't have anything warning you if the same problem comes back again. With a unit test, you have a constant companion to make sure that any future changes don't reintroduce the bug.

Personally I don't like having to step through code - I find it frustrating compared with unit testing. It's too easy to accidentally step over something you wanted to step into etc. It's sometimes necessary, but it's often a sign that your code is too complicated. I particularly dislike having to debug a whole application rather than just stepping through a unit test in the debugger. It's usually orders of magnitude slower.

like image 132
Jon Skeet Avatar answered May 03 '23 05:05

Jon Skeet