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
14 answers

"No symbols loaded for the current document" while debugging JavaScript in Visual Studio

I'm working on a .NET 3.5 website, with three projects under one solution. I'm using jQuery in this project. I'd like to use the Visual Studio JavaScript debugger to step through my JavaScript code. If I set a breakpoint in any of the .js files I…
Randy L
  • 13,549
  • 12
  • 41
  • 72
22
votes
4 answers

Opening source code from debug view edits .class after Android R18 update

When I'm debugging my code in Eclipse, I get annoyed when I open up the editor to find out I cant edit it because I'm actually viewing the source of the .class file. How do I get Eclipse to open up the .java file instead of the .class file when in…
tango whiskey double
  • 17,662
  • 15
  • 86
  • 132
22
votes
5 answers

Why fork() twice

Nagios lets me configure child_processes_fork_twice=<0/1>. The documentation says This option determines whether or not Nagios will fork() child processes twice when it executes host and service checks. By default, Nagios fork()s twice. However,…
DerMike
  • 13,362
  • 12
  • 45
  • 60
22
votes
4 answers

Hot swap debugging with Android

1) Is there any special setting/configuration required to enable hot swap debugging on Android? Example case: Add breakpoint just after entering activity's onCreate method. Add new line on the fly after the breakpoint (dummy "if (1==1) return;"…
pilcrowpipe
  • 2,358
  • 5
  • 25
  • 40
22
votes
3 answers

Win32 Console app vs. CLR Console app

I'm working on a C++ project that I don't intend to develop or deploy using .NET libraries or tools, which means it would make sense for me to create it using a Visual Studio Win32 Console application. However, I've heard that the debugging…
bsofman
  • 255
  • 1
  • 3
  • 9
21
votes
4 answers

How to access environment variables inside .gdbinit and inside gdb itself?

I am looking to set up the path for the source code when debugging with gdb. I chose to do that with a .gdbinit file. Basically, it contains a command: directory="/path/to/src". However, I would like to be able to specify that command…
user1284631
  • 4,038
  • 30
  • 58
21
votes
3 answers

move up a frame, debug R environment

When debugging a function, I would like to move up to the parent frame and look at some variables there. How do I do this? Here is a sample: f <- function() { x <-1 g(x+1) } g <- function(z) { y = z+2 return(y) } I then debug both…
Alex
  • 17,745
  • 33
  • 112
  • 182
21
votes
3 answers

Thread id in Qt

How to print the thread id using qDebug() on windows environment of Qt.
Suresh
  • 9,187
  • 14
  • 45
  • 62
21
votes
3 answers

eclipse - search value of variable during debugging

Does eclipse have a way, while debugging, to find variable when I know only its value? Or are there any plugins for this? Thanks. Sometimes I do not know where the variable is, but I know the value of the variable. If it is an object, I do not know…
Dan
  • 565
  • 2
  • 6
  • 12
21
votes
2 answers

Where do you configure Eclipse Java compiler (javac) flags?

Ex. javac -g ButtMonkey.java Where do you configure the -g flag when Eclipse compiles Java source? (Using Ganymede but I doubt that has changed in later versions so any answer probably helps.) What I need is: -g Generate all debugging…
Mifune
  • 355
  • 1
  • 4
  • 14
21
votes
1 answer

error code (-11):: what are all possible reasons of getting error "cl_build_program_failure" in OpenCL?

I am using ATI RV770 graphics card, OpenCl 1.0 and ati-stream-sdk-v2.3-lnx64 on linux. While running my host code which includes following two sections to build kernel program, i am getting error code (-11) i.e. cl_build_program_failure. Does it…
Gopal
  • 735
  • 1
  • 7
  • 16
21
votes
1 answer

What are the advantages of LLDB over GDB in iOS development?

In Xcode 4.3, now you can enable using LLDB as the debugger for iOS targets. What advantages does it have over using the good old GDB? GDB still works with LLVM and I cannot see any obvious differences in "everyday" debugging tasks.
Imre Kelényi
  • 21,863
  • 5
  • 31
  • 44
21
votes
2 answers

Debugging and counting breakpoint hits

Sometimes when I examine a code I didn’t write, I launch eclipse in debug mode and use figures to understand a program. For example, if they are n items retrieved from the DB, it can be interesting to know that there’re n processed items in a…
21
votes
4 answers

Eclipse open console apps in separate window

Is there a way to configure eclipse to open console apps in a new window rather than it's own console when you run/debug them? I'm debugging a client/server application and I'd like to see the output of both apps at once and not have to switch…
Omar Kooheji
  • 50,943
  • 65
  • 176
  • 234
21
votes
2 answers

How to debug/break in codedom compiled code

I have an application which loads up c# source files dynamically and runs them as plugins. When I am running the main application in debug mode, is it possible to debug into the dynamic assembly? Obviously setting breakpoints is problematic, since…
Jason Coyne
  • 6,179
  • 7
  • 35
  • 64
1 2 3
99
100