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:

47496 questions
22
votes
7 answers

I need to inspect the view hierarchy on an iPhone program

How do I determine what the view structure on my iPhone program while running on the simulator?
Chris
  • 399
  • 1
  • 2
  • 8
22
votes
7 answers

Why Eclipse doesn't show local variables values when I debug class file from JDK?

I want to debug .class files. For example some from the JDK. I downloaded the sources and attached them. public File[] listFiles(FilenameFilter paramFilenameFilter) { String[] arrayOfString = list(); // now we here if (arrayOfString == null)…
gstackoverflow
  • 31,683
  • 83
  • 267
  • 574
22
votes
4 answers

What is the non-standard HTTP verb "DEBUG" used for in ASP.NET/IIS?

I am reading a report from a "web application security" company, whom have been scanning a few websites of the company I am working for. It appears from the report - which seems written without any human involvement - that several attempts where…
Jørn Schou-Rode
  • 35,883
  • 13
  • 81
  • 120
22
votes
3 answers

How to debug a non-exported function?

There's a definitive guide for how to view the source code for a function, but how do you debug a function that's not exported from a package, without manually stepping through the source code that you've found? library(plm) > predict.plm Error:…
Ari B. Friedman
  • 66,857
  • 33
  • 169
  • 226
22
votes
7 answers

Why does Java code slow down in debugger?

Some CPU intensive routines get dramatically slower when run through a debugger. Why is this? Currently I'm just using IntelliJ to step through code running in JBoss. When I start JBoss, I use these options: set JAVA_OPTS=-Xms512m -Xmx1024m…
Marcus Leon
  • 50,921
  • 112
  • 279
  • 413
22
votes
7 answers

How to see all available variables in handlebars template

I'm working on my first Ember.js app and am having some trouble connecting all the dots. It would be really helpful if I could just see all the variables available within a given handlebars template. There is a related question, but you have to…
doub1ejack
  • 9,047
  • 15
  • 60
  • 110
22
votes
2 answers

Python logging typeerror

Could you please help me, whats wrong. import logging if (__name__ == "__main__"): logging.basicConfig(format='[%(asctime)s] %(levelname)s::%(module)s::%(funcName)s() %(message)s', level=logging.DEBUG) logging.INFO("test") And I can't…
FrUh
  • 445
  • 1
  • 3
  • 7
22
votes
3 answers

How use Instruments and display the console in Command Lines applications

I'm using Xcode on OSX to develop command line C applications. I would also like to use Instruments to profile and find memory leaks. However, I couldn't find a way to display the console when launching the application from within Instruments. I'm…
Hugo Sereno Ferreira
  • 8,665
  • 6
  • 41
  • 88
22
votes
3 answers

Debugging error "The Type 'xx' is defined in an assembly that is not referenced"

The full error is as follows: The type 'System.Windows.Forms.Control' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows.Forms, Version=2.0.0.0,…
Abel
  • 52,738
  • 19
  • 137
  • 227
22
votes
2 answers

Is there a way in the Eclipse debugger to be notified when the state of a Java object changes?

I'm debugging some legacy code where we have a cached object that appears to be changed externally. If I know the object identifier for it (while debugging), is there some way to "watch" it so that if some other code in the same thread or another…
Uri
  • 84,589
  • 46
  • 214
  • 312
22
votes
2 answers

IntelliJ Idea (debugging) conditional breakpoint dependent on other breakpoints

I want to set a debug breakpoint in IntelliJ Idea that is only active, if another previous breakpoint was activated. For example i have a breakpoint B1 on line 10, and another breakpoint B2 on line 20. Even if B2s condition is true, the debugger…
klingt.net
  • 1,699
  • 3
  • 15
  • 19
22
votes
5 answers

Unable to detect application ABI's when trying to debug NDK

I'm trying to debug an Android application with native code using ADT 20.0.3 on Eclipse and it's giving me this error: [2012-10-04 12:09:12 - ndk_android] Unknown Application ABI: [2012-10-04 12:09:12 - ndk_android] [2012-10-04 12:09:12 -…
gninja
  • 333
  • 1
  • 2
  • 10
22
votes
4 answers

No output from DebugView

I've installed DebugView 4.79 on Windows 7 and Windows 8 64 bit machines and a Windows 7 32 bit machine. On all of them I see no output from DebugView when starting it as Administrator. I'm trying to debug an application that uses a CLI/C++…
DaveO
  • 1,753
  • 4
  • 25
  • 59
22
votes
5 answers

Compiling python modules with DEBUG defined on MSVC

Python rather stupidly has a pragma directive in its include files that forces a link against python26_d.lib when the DEBUG preprocessor variable is defined. This is a problem because the python installer doesn't come with python26_d.lib! So I can't…
DaedalusFall
  • 7,677
  • 5
  • 28
  • 42
22
votes
4 answers

How to get source code line from stack trace in obj-c / ios

I use NSSetUncaughtExceptionHandler to print the stack trace to local file in iPhone, which will be sent to our server next time the app launches. Then I can examine the exception data and fix the bug. In some crashes I have the module name and the…
1 2 3
99
100