School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,417 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,562 people online right now. Registration is fast and FREE... Join Now!




Debugging

 
Reply to this topicStart new topic

> Debugging, How to use the tools

AdamSpeight2008
Group Icon



post 20 Mar, 2009 - 02:26 PM
Post #1


Debugging Skills

So coded your application and you have no errors but when you run it has an error or runs not like you expected.
This is a Logical Error where it debugging skills help.

The most important one is the use of breakpoints, these stop the execution of the program and allows you examine things to are occurring within your program;-
like the contents of variable
The stack.

To examine the contents of a variable you can hover over the variable name and a box appears with contents, but when you move the mouse it disappears.
For something a little more permanent you can right-click over the variable and add a watch, this allow you to view the contents as you step through the code.

Stepping Through Your Code
To Step Through your code there are three types of stepping
Step InTo F8 where the stepping, steps into subroutines, function, methods etc.
Step Over Shift + F8 where the stepping steps overs subroutines, function, methods etc.
Step Out Ctrl + Shift + F8 where the stepping, steps out of the current subroutines, function, methods etc.
On to the next code line directly over the call.

The Stack Ctrl + L
Another important tool is the stack visualizer, where you can see the depth of the function call.
Click on a level and the debugger takes to where in your code the function call was made.
[External Code] is code that was used by your program but you are unable access it because it likely to be OS / CLR operation.

These simple skills will help you become code debugging code-ninja ph34r.gif
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

AdamSpeight2008
Group Icon



post 24 Mar, 2009 - 07:15 AM
Post #2
The code for this example was written by Tocon (See: Tocon's Original Posting).
They have kindly have allowed me to use their code as for an example of how debugging skills can help to find the cause of the problem.
Some how when it comes to display the contents of the array the program crash.


Attached Image
Added a Breakpoint to the start of the displayArray subroutine.

Attached Image
Added a Breakpoint to the For Loop, so that every time around the loop the program stops to let us examine things.

Attached Image
Having run the program and in a student, then click on the List by Students button.
The Program has pause at the first breakpoint. Underneath the code window you see the stack window.
Which says you're in the displayArray subroutine, and you got here via the clicking on the ButtonList Button on MainForm1

Attached Image
Let watch the contents of the array called "theArray", by highlight the variable then right click to bring up the menu the selecting Add Watch
Attached Image
This is the expanded view of the contents of theArray, (Warning: Do this on large array may cause Visual Studio to become unresponsive).

Stepping through the array F8, eventually the program throw the error message below
Attached Image

By examining i you'll see that it is 0 (Zero) and the contents of theArray at position 0 is Nothing, which is the cause of the problem.

Just say again thank you to Tocon for allowing the use of their code for this example.
Go to the top of the page
+Quote Post

juunas
**



post 28 Apr, 2009 - 12:37 AM
Post #3
Oh my god, thank you! I've always just used some kind of labels to see the contents of a variable. This will be a big help!
Go to the top of the page
+Quote Post


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/7/09 11:35PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month