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
449
votes
11 answers

How can I inspect the file system of a failed `docker build`?

I'm trying to build a new Docker image for our development process, using cpanm to install a bunch of Perl modules as a base image for various projects. While developing the Dockerfile, cpanm returns a failure code because some of the modules did…
Altreus
  • 5,759
  • 4
  • 27
  • 27
449
votes
6 answers

How do I print the full value of a long string in gdb?

I want to print the full length of a C-string in GDB. By default it's being abbreviated, how do I force GDB to print the whole string?
John Carter
  • 53,924
  • 26
  • 111
  • 144
443
votes
15 answers

How do you launch the JavaScript debugger in Google Chrome?

When using Google Chrome, I want to debug some JavaScript code. How can I do that?
Kevin Driedger
  • 51,492
  • 15
  • 48
  • 55
428
votes
7 answers

Print current call stack from a method in code

In Python, how can I print the current call stack from within a method (for debugging purposes).
oneself
  • 38,641
  • 34
  • 96
  • 120
418
votes
22 answers

JavaScript console.log causes error: "Synchronous XMLHttpRequest on the main thread is deprecated..."

I have been adding logs to the console to check the status of different variables without using the Firefox debugger. However, in many places in which I add a console.log in my main.js file, I receive the following error instead of my lovely little…
Nathan Basanese
  • 8,475
  • 10
  • 37
  • 66
404
votes
30 answers

How can I write to the console in PHP?

Is it possible write a string or log into the console? What I mean Just like in JSP, if we print something like system.out.println("some"), it will be there at the console, not at a page.
Labeeb Panampullan
  • 34,521
  • 28
  • 94
  • 112
402
votes
30 answers

How do you debug PHP scripts?

How do you debug PHP scripts? I am aware of basic debugging such as using the Error Reporting. The breakpoint debugging in PHPEclipse is also quite useful. What is the best (in terms of fast and easy) way to debug in phpStorm or any other IDE?
Marcel
  • 6,143
  • 15
  • 46
  • 52
398
votes
42 answers

Eclipse - Unable to install breakpoint due to missing line number attributes

I am getting this strange error in Eclipse while trying to set a breakpoint. Unable to insert breakpoint Absent Line Number Information I ticked the checkbox from Compiler options but no luck.
chandrajeet
  • 8,833
  • 6
  • 23
  • 15
393
votes
29 answers

Showing the stack trace from a running Python application

I have this Python application that gets stuck from time to time and I can't find out where. Is there any way to signal Python interpreter to show you the exact code that's running? Some kind of on-the-fly stacktrace? Related questions: Print…
Seb
  • 17,141
  • 7
  • 38
  • 27
391
votes
9 answers

How can I see the entire HTTP request that's being sent by my Python application?

In my case, I'm using the requests library to call PayPal's API over HTTPS. Unfortunately, I'm getting an error from PayPal, and PayPal support cannot figure out what the error is or what's causing it. They want me to "Please provide the entire…
Chris B.
  • 85,731
  • 25
  • 98
  • 139
390
votes
6 answers

Is there "Break on Exception" in IntelliJ?

Is there feature that will automatically break debugging on first exception occurrence? So we start application do something that throw exception got IntelliJ popped up highlighted line where exception occurred.
Mike Chaliy
  • 25,801
  • 18
  • 67
  • 105
388
votes
9 answers

What are Java command line options to set to allow JVM to be remotely debugged?

I know there's some JAVA_OPTS to set to remotely debug a Java program. What are they and what do they mean ?
paulgreg
  • 18,493
  • 18
  • 46
  • 56
368
votes
4 answers

Debugging iframes with Chrome developer tools

I'd like to use the Chrome developer console to look at variables and DOM elements in my app, but the app exists inside an iframe (since it's an OpenSocial app). So the situation is: