Questions tagged [debugging]

Debugging is a methodical process of finding and fixing bugs in a computer program. **IMPORTANT NOTE:** This tag is ONLY for questions about debugging techniques or the process of debugging itself, NOT for requesting help debugging your code.

Debugging is a methodical process of finding and fixing bugs in a computer program or a piece of electronic hardware, thus making it behave as expected.

Debugging tends to be harder when various subsystems are tightly coupled, as changes in one may cause bugs to emerge in another. Many books have been written about debugging, as it involves numerous aspects, including interactive debugging, control flow, integration testing, log files, monitoring (application, system), memory dumps, profiling, Statistical Process Control, and special design tactics to improve detection while simplifying changes.

Four key techniques for debugging are syntax checking, adding comments, stepping and using breakpoints.

Syntax checking

Many good tools exist, including online-only tools, to check the syntax of your code. Checking the syntax means checking your code obeys the basic rules of the programming language or tool being used (e.g., missing end brackets, no end to an if statement). Syntax checking is done automatically in compiled languages (eg, C, C++, pascal) but not in interpreted or scripted languages (eg, javascript, perl, HTML). Some code editors include syntax highlighting or validation. Syntax checks can also be carried out for some data files or stylesheets, for example the JSON or CSS that your code uses.

Syntax checks will quickly help find spelling mistakes, missing or repeated statements, invalid expressions, and may also give warnings or suggested improvements. Syntax checkers are also known as linters, or code validators. Checking for valid syntax before running can identify errors quickly.

Stepping

Program stepping refers to using a tool to running your code line by line or a section at a time, examining the results including variables, the result of expressions, and the order that the program's steps are executed in. This is particularly useful in programs which do not give an error, or contain infinite loops.

Breakpoints

Breakpoints are particular places in your code in which you want to temporarily stop the code in order to check if it is running correctly so far, for example to check whether a value typed in was correctly stored in a variable you would add a breakpoint immediately after that line, then check the result. Using several different breakpoints allows you to very quickly find the area of the code which is causing the problem.

Breakpoints can be created using a debugging tool, or manually a very simple form of breakpoint could be adding a pop-up messages that waits for you to respond with OK, and can display a message containing program information (e.g., line number, function's name, values of variables).

Using comments

Adding comment to your code is good practice and allows you to describe the purpose of a short piece of code in human-readable form. Programming languages ignore all lines containing comments, but they can help you later to update your code or resolve problems if you add them as you first begin coding.

Applications and Tools for Debugging:

Learning Sources:

Books:

Tutorials:

51830 questions
25
votes
4 answers

DOM attribute change debugging

Somehow somewhere in my code one of the elements on the page gets a style attribute which I don't expect it to get. Namely, it gets style="position:fixed". I can see this happening in HTML tab in Firebug, but can't find it in the code. The…
Maxim Sloyko
  • 15,176
  • 9
  • 43
  • 49
25
votes
2 answers

Visual patterns in memory?

Started up remote debugging a C++ project today on a Win 7 machine running in VMWare and was astonished to see the following pattern on a random memory location: Who might code this (it's not me!) and for what reason?? Just curious if anyone has…
Isso
  • 1,285
  • 11
  • 23
25
votes
2 answers

How to print Core Data debug values?

How can I print the values being sent to the sqlite database while using Core Data SQL Debug? Using the "-com.apple.CoreData.SQLDebug 1" in my "Arguments Passed on Launch" debug options prints the SQL structure just fine (you can check see how to…
Felipe Sabino
  • 17,825
  • 6
  • 78
  • 112
25
votes
1 answer

Chrome Developer Tools: missing Script tab

Web browser - chrome Version 21.0.1180.82 and Version 23.0.1244.0 canary OS - mac osx 10.8 What it should look like: In my view the "Script" tab within the tab navigator is replace by an icon saying "Sources". This is causing me problems as I…
user1256378
  • 712
  • 2
  • 12
  • 31
25
votes
11 answers

Why does my C# debugger skip breakpoints?

My C# debugger is not working properly. It skips break points and line of codes sometimes. I have checked the configuration manager. I have even tried adding my projects to new solution files. Can someone please help me?
Yasar
25
votes
6 answers

How to set name to the thread?

Is there a way to set a friendly name to a thread in code? For example, I want the thread with name Thread-11 on the image was named something like 'MyImportThread'.
Prizoff
  • 4,486
  • 4
  • 41
  • 69
25
votes
2 answers

`DummyExecutor` for Python's `futures`

Python's futures package allows us to enjoy ThreadPoolExecutor and ProcessPoolExecutor for doing tasks in parallel. However, for debugging it is sometimes useful to temporarily replace the true parallelism with a dummy one, which carries out the…
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
24
votes
5 answers

Is there Valgrind Memcheck like tool for windows to debug use after free errors?

Durring my work I regulary face rather common programming error - using some object which has already been freed. This invokes UB in C++. On linux, this kind of problems are usually resolved by using Valgrind tool Memcheck. From Memcheck…
ks1322
  • 33,961
  • 14
  • 109
  • 164
24
votes
6 answers

How do I attach a process to the debugger in Visual Studio?

I know I can start a process in code with Process.Start(). Is it also possible to attach the debugger to that process? Not from code per se , but just a way to do it?
Bertvan
  • 4,943
  • 5
  • 40
  • 61
24
votes
6 answers

Debugging Node.js processes with cluster.fork()

I've got some code that looks very much like the sample in the Cluster documentation at http://nodejs.org/docs/v0.6.0/api/cluster.html, to wit: var cluster = require('cluster'); var server = require('./mycustomserver'); var numCPUs =…
Chris
  • 405
  • 2
  • 5
  • 13
24
votes
8 answers

How can I visualise the memory (SRAM) usage of an AVR program?

I have encountered a problem in a C program running on an AVR microcontroller (ATMega328P). I believe it is due to a stack/heap collision but I'd like to be able to confirm this. Is there any way I can visualise SRAM usage by the stack and the…
Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
24
votes
5 answers

How to change background color of line highlighting during debug process in Netbeans?

how to change background color of line highlighting during debug process in Netbeans? Tried to change "Highlight Caret Row". No success. It only changes bg color of line where cursor blinks, but not debugging line:
heron
  • 3,611
  • 25
  • 80
  • 148
24
votes
4 answers

How do you pass script arguments to pdb (Python)?

I've got python script (ala #! /usr/bin/python) and I want to debug it with pdb. How can I pass arguments to the script? I have a python script and would like to debug it with pdb. Is there a way that I can pass arguments to the scripts?
Glenn
24
votes
9 answers

Why is console.log() considered better than alert()?

I've always been told that when debugging an application, JavaScript's console.log() method is preferred over simply using an alert() method. Why is this? Is there a good example someone can point me to where console.log() is obviously the better…
Daniel Szabo
  • 7,181
  • 6
  • 48
  • 65
24
votes
0 answers

what's the difference between C# compilation setting "/debug:pdbonly" and "/debug:full"?

According to msdn http://msdn.microsoft.com/en-us/library/8cw0bt21.aspx , both compilation setting "/debug:pdbonly" and "/debug:full" will make .pdb (Program Database) files be generated. However, what is the difference? The page says: "One…
athos
  • 6,120
  • 5
  • 51
  • 95
1 2 3
99
100