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
24
votes
3 answers

Debugging "Maximum call stack size exceeded"

I have a server that I can cause to die with the following output: events.js:38 EventEmitter.prototype.emit = function(type) { ^ RangeError: Maximum call stack size exceeded However, without a stack dump or trace,…
OrangeDog
  • 36,653
  • 12
  • 122
  • 207
24
votes
5 answers

Is there a lint for Common Lisp or Chicken Scheme?

Is there a lint for Common Lisp or Chicken Scheme? Possibly something akin to C's splint, Haskell's HLint, Perl's B::Lint, etc.?
mcandre
  • 22,868
  • 20
  • 88
  • 147
24
votes
8 answers

How do I "run until this variable changes" when debugging?

When debugging my C#, I often want to know when a variable's value changes and then investigate the state of the program. Currently, I do it like this: Watch-list the offending variable. Physically spam F10 (shortcut for Step Over) until I see the…
24
votes
7 answers

How do I debug SwiftUI AttributeGraph cycle warnings?

I'm getting a lot of AttributeGraph cycle warnings in my app that uses SwiftUI. Is there any way to debug what's causing it? This is what shows up in the console: === AttributeGraph: cycle detected through attribute 11640 === === AttributeGraph:…
Sindre Sorhus
  • 62,972
  • 39
  • 168
  • 232
24
votes
2 answers

visual studio 2010 debugger find goto current line stopped at shortcut key

1) I put a breakpoint, VS breaks where I put the breakpoint. 2) I then start browsing around the code normally to put another breakpoint somewhere down the execution path. (maybe in another class in some other cs file) 3) I would now like to return…
Gullu
  • 3,477
  • 7
  • 43
  • 70
24
votes
3 answers

How to view JavaScript function calls as they occur

Is it possible to view JavaScript function calls in the browser's JavaScript console? I know you can view XHR, but can you view function calls? For example, I hover my mouse over some element on a page and a div pops up. I know there was a…
styfle
  • 22,361
  • 27
  • 86
  • 128
24
votes
11 answers

How do you debug heavily templated code in c++?

I find it very hard to figure out what is wrong with my code when using C++ template meta-programming. It might be that I am just not very good at understanding the error messages, but as far as I'm aware I can't resort to putting in print…
Dan
  • 33,953
  • 24
  • 61
  • 87
24
votes
5 answers

Debugging infinite loops in Haskell programs with GHCi

For the first time I've encountered an infinite loop in a Haskell program I'm writing. I've narrowed it down to a quite specific section of code, but I cannot seem to pinpoint exactly where I have a non-terminating recursive definition. I'm vaguely…
gspr
  • 11,144
  • 3
  • 41
  • 74
24
votes
3 answers

Remote debugging: No connection to Wildfly 14 on OpenJDK 11 at port 8787

I'm trying to connect my debugger to Wildlfy running on Open JDK 11. Despite Wildfly says: Listening for transport dt_socket at address: 8787 My IDE (IntelliJ IDEA CE 2018.1) claims that it doesn't get any connection: Unable to open debugger…
Sebastian S
  • 4,420
  • 4
  • 34
  • 63
24
votes
5 answers

The application has stopped unexpectedly: How to Debug?

Please note, unlike many other questions having the subject title "application has stopped unexpectedly", I am not asking for troubleshooting a particular problem. Rather, I am asking for an outline of the best strategy for an Android/Eclipse/Java…
Android Eve
  • 14,864
  • 26
  • 71
  • 96
24
votes
3 answers

Stepping into Qt sources in Qt Creator (in Ubuntu Linux)

I'm using Qt Creator in Ubuntu. It's installed from the repositories but as it is now, there is no way to step into the Qt sources when debugging. How can I enable that?
sashoalm
  • 75,001
  • 122
  • 434
  • 781
24
votes
3 answers

"unreachable code after return statement" error in Google Analytics JS code on Firefox - is this my fault?

I'm using the current Google Analytics tracking code, and on Firefox 59 I get this error in console: unreachable code after return statement On this javascript: https://www.googletagmanager.com/gtag/js?id=UA-my-tracking-code:formatted Since this…
24
votes
5 answers

How to change string representation of objects in Nodejs debug console view

How do I change the string representation of an object instance in nodejs debug console. Is there a method (like toString() in .NET) I can override? Consider the following code: class SomeObject{ constructor(){ this._varA = "some…
Leo
  • 5,013
  • 1
  • 28
  • 65
24
votes
4 answers

How to view the full path of a file in GDB?

When I stop at a break point in gdb, it just shows the filename.cpp. How can I view the full pathname of this file?
aaa
  • 243
  • 1
  • 2
  • 4
24
votes
3 answers

How to debug code running from terminal in pycharm

I am running my code in Pycharm from Terminal. Is it possible to debug the code and put breakpoints inside the code during a run from terminal?
MSepehr
  • 890
  • 2
  • 13
  • 36
1 2 3
99
100