All Topics  
Debugging

 

   Email Print
   Bookmark   Link






 

Debugging



 
 
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
 or a piece of electronic hardware
Electronic hardware

Electronic hardware refers to interconnected Electronics components which perform analog circuit and/or logic operations on received and locally stored information to produce as output and/or store resulting new information and/or to provide control for output actuator mechanisms....
 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.

e is some controversy over the origin of the term "debugging."

The terms "bug" and "debugging" are both popularly attributed to Admiral Grace Hopper in the 1940s.






Discussion
Ask a question about 'Debugging'
Start a new discussion about 'Debugging'
Answer questions from other users
Full Discussion Forum



Encyclopedia


H96566k
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
 or a piece of electronic hardware
Electronic hardware

Electronic hardware refers to interconnected Electronics components which perform analog circuit and/or logic operations on received and locally stored information to produce as output and/or store resulting new information and/or to provide control for output actuator mechanisms....
 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.

Origin

There is some controversy over the origin of the term "debugging."

The terms "bug" and "debugging" are both popularly attributed to Admiral Grace Hopper in the 1940s. While she was working on a Mark II Computer at Harvard University, her associates discovered a moth stuck in a relay and thereby impeding operation, whereupon she remarked that they were "debugging" the system. However the term "bug" in the meaning of technical error dates back at least to 1878 and Thomas Edison
Thomas Edison

Thomas Alva Edison was an American inventor and businessman who developed many devices that greatly influenced life around the world, including the phonograph and the long-lasting, practical electric light bulb....
 (see the Software bug
Software bug

A software bug is an error, flaw, mistake, failure, or fault in a computer program that prevents it from behaving as intended . Most bugs arise from mistakes and errors made by people in either a program's source code or its software architecture, and a few are caused by compilers producing incorrect code....
 article for a full discussion), and "debugging" seems to have been used as a term in aeronautics before entering the world of computers. Indeed, in an interview Grace Hopper remarked that she was not coining the term. The moth fit the already existing terminology, so she saved it.

The Oxford English Dictionary
Oxford English Dictionary

The Oxford English Dictionary , published by the Oxford University Press , is a comprehensive dictionary of the English language. Two fully-bound print editions of the OED have been published under its current name, in 1928 and 1989; as of December 2008 the dictionary's current editors have completed a quarter of the third edition....
 entry for "debug" quotes the term "debugging" used in reference to airplane engine testing in a 1945 article in the Journal of the Royal Aeronautical Society, Hopper's bug was found 9 September 1947. The term was not adopted by computer programmers until the early 1950s. The seminal article by Gill in 1951 is the earliest in-depth discussion of programming errors, but it does not use the term "bug" or "debugging". In the ACM
Association for Computing Machinery

The Association for Computing Machinery, or ACM, was founded in 1947 as the world's first scientific and educational computing society. Its membership was approximately 83,000 as of 2007....
's digital library, the term "debugging" is first used in three papers from 1952 ACM National Meetings. Two of the three use the term in quotation marks. By 1963, "debugging" was a common enough term to be mentioned in passing without explanation on page 1 of the CTSS manual.

Kidwell's article Stalking the Elusive Computer Bug discusses the etymology of "bug" and "debug" in greater detail.

Tools

Debugging is, in general, a lengthy and tiresome task. The debugging skill of the programmer is probably the biggest factor in the ability to debug a problem, but the difficulty of software debugging varies greatly with the programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 used and the available tools, such as debugger
Debugger

A debugger is a computer program that is used to test and debug other programs. The code to be examined might alternatively be running on an Instruction Set Simulator, a technique that allows great power in its ability to halt when specific conditions are encountered but which will typically be much slower than executing the code directly on...
s
. Debuggers are software tools which enable the programmer
Programmer

A programmer is someone who writes computer software. The term computer programmer can refer to a specialist in one area of computer programming or to a generalist who writes code for many kinds of software....
 to monitor the execution
Execution (computers)

Execution in computer engineering and software engineering is the Process by which a computer or a virtual machine carries out the instructions of a computer program....
 of a program, stop it, re-start it, set breakpoint
Breakpoint

A breakpoint, in software development, is an intentional stopping or pausing place in a computer program, put in place for debugging purposes. More generally, a breakpoint is a means of acquiring knowledge about a program during its execution....
s, change values in memory and even, in some cases, go back in time. The term debugger can also refer to the person who is doing the debugging.

Generally, high-level programming language
High-level programming language

In computing, a high-level programming language is a programming language with strong Abstraction from the details of the computer. In comparison to low-level programming languages, it may use natural language elements, be easier to use, or more Porting across platforms....
s, such as Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
, make debugging easier, because they have features such as exception handling
Exception handling

Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions - special conditions that change the normal flow of execution....
 that make real sources of erratic behaviour easier to spot. In lower-level programming languages such as C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
 or assembly
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
, bugs may cause silent problems such as memory corruption
Memory corruption

Memory corruption happens when the contents of a memory location are unintentionally modified due to programming errors. When the corrupted memory contents are used later in the computer program, it leads either to program crash or to strange and bizarre program behavior....
, and it is often difficult to see where the initial problem happened. In those cases, memory debugger tools may be needed.

In certain situations, general purpose software tools that are language specific in nature can be very useful. These take the form of static code analysis tools
List of tools for static code analysis

This is a list of significant tools for static code analysis....
. These tools look for a very specific set of known problems, some common and some rare, within the source code. All such issues detected by these tools would rarely be picked up by a compiler or interpreter, thus they are not syntax checkers, but more semantic checkers. Some tools claim to be able to detect 300+ unique problems. Both commercial and free tools exist in various languages. These tools can be extremely useful when checking very large source trees, where it is impractical to do code walkthroughs. A typical example of a problem detected would be a variable dereference that occurs before the variable is assigned a value. Another example would be to perform strong type checking when the language does not require such. Thus, they are better at locating likely errors, versus actual errors. As a result, these tools have a reputation of false positives. The old Unix lint
Lint programming tool

In computer programming, lint was the name originally given to a particular program that flagged suspicious and non-portable constructs in C source code....
 program is an early example.

For debugging electronic hardware (e.g., computer hardware
Computer hardware

A personal computer is made up of computer hardware, multiple physical components onto which can be loaded into a multitude of software that perform the functions of the computer....
) as well as low-level software (e.g., BIOS
BIOS

In computing, the Basic Input/Output System , also known as the System BIOS, is a de facto standard defining a firmware interface for IBM PC Compatible computers....
es, device driver
Device driver

In computing, a device driver or software driver is a computer program allowing higher-level computer programs to interact with a hardware device....
s) and firmware
Firmware

Firmware is a term sometimes used to denote the fixed, usually rather small, programs that internally control various electronic devices. Typical examples range from end user products such as remote controls or calculators, via computer parts and devices like harddisks, keyboard s, TFT screens or memory cards, all the way to scientific instr...
, instruments such as oscilloscope
Oscilloscope

An oscilloscope is a type of electronic test instrument that allows signal voltages to be viewed, usually as a two-dimensional graph of one or more electrical potential differences plotted as a function of time or of some other voltage ....
s, logic analyzer
Logic analyzer

A logic analyzer is an electronic instrument that displays signals in a digital circuit that are too fast to be observed and presents it to a user so that the user can more easily check correct operation of the digital system....
s or in-circuit emulators (ICEs)
In-circuit emulator

An in-circuit emulator is a hardware device used to debugger the software of an embedded system. It is usually in the form of bond-out processor which has many internal signals brought out for the purpose of debugging....
 are often used, alone or in combination. An ICE may perform many of the typical software debugger's tasks on low-level software and firmware
Firmware

Firmware is a term sometimes used to denote the fixed, usually rather small, programs that internally control various electronic devices. Typical examples range from end user products such as remote controls or calculators, via computer parts and devices like harddisks, keyboard s, TFT screens or memory cards, all the way to scientific instr...
.

Debugging process


Print debugging is the act of watching (live or recorded) trace statements, or print statements, that indicate the flow of execution of a process.

Often the first step in debugging is to attempt reproduce the problem. This can be a non-trivial task, for example in case of parallel processes or some unusual software bugs. Also specific user environment and usage history can make it difficult to reproduce the problem.

After the bug is reproduced, the input of the program needs to be simplified to make it easier to debug. For example, a bug in a compiler can make it crash
Crash (computing)

A crash or in computing is a condition where a program stops performing its expected function and also stops responding to other parts of the system....
 when parsing some large source file. However, after simplification of the test case, only few lines from the original source file can be sufficient to reproduce the same crash. Such simplification can be made manually, using divide-and-conquer
Divide and conquer algorithm

In computer science, divide and conquer is an important algorithm design paradigm based on multi-branched recursion. A divide and conquer algorithm works by recursively breaking down a problem into two or more sub-problems of the same type, until these become simple enough to be solved directly....
 approach. The programmer will try to remove some parts of original test case and check if the problem still exists. When debugging the problem in GUI
Graphical user interface

A graphical user interface is a type of user interface which allows people to human-computer interaction such as computers; hand-held devices such as MP3 Players, Portable Media Players or Gaming devices; household appliances and office equipment....
, the programmer will try to skip some user interaction from the original problem description and check if remaining actions are sufficient for bug to appear. To automate test case simplification, delta debugging
Delta Debugging

Delta Debugging automates the scientific method of debugging. The Delta Debugging algorithm isolates failure causes automatically - by systematically narrowing down failure-inducing circumstances until a minimal set remains....
 methods can be used.

After the test case is sufficiently simplified, a programmer can use debugger
Debugger

A debugger is a computer program that is used to test and debug other programs. The code to be examined might alternatively be running on an Instruction Set Simulator, a technique that allows great power in its ability to halt when specific conditions are encountered but which will typically be much slower than executing the code directly on...
 to examine program states (values of variables, call stack
Call stack

In computer science, a call stack is a dynamic Stack data structure that stores information about the active subroutines of a computer program....
) and track down the origin of the problem. Alternatively a tracing
Tracing (software)

In software engineering, tracing is a specialized use of Data logging to record information about a program's execution. This information is typically used by programmers for debugging purposes, and additionally, depending on the type and detail of information contained in a trace log, by experienced system administrators or technical suppor...
 can be used. In simple case the tracing is just a few print statements, which print out the values of variables in certain points of program execution.

Remote Debugging is the process of debugging a program running on a system different than the debugger. To start remote debugging, debugger connects to a remote system over a network. Once connected, debugger can control the execution of the program on the remote system and retrieve information about its state .

Post-Mortem Debugging is the act of debugging the (core) dump of process. The dump of the process space may be obtained automatically by the system, or manually by the interactive user. crash
Crash (computing)

A crash or in computing is a condition where a program stops performing its expected function and also stops responding to other parts of the system....
 dumps (core dumps) are often generated after a process has terminated due to an unhandled exception .

Anti-debugging

Anti-debugging is "the implementation of one or more techniques within computer code that hinders attempts at reverse engineering or debugging a target process". The types of technique are:
  • API-based: check for the existence of a debugger using system information
  • Exception-based: check to see if exceptions are interfered with
  • Process and thread blocks: check whether process and thread blocks have been manipulated
  • Modified code: check for code modifications made by a debugger handling software breakpoints
  • Hardware- and register-based: check for hardware breakpoints and CPU registers
  • Timing and latency: check the time taken for the execution of instructions
Debugging can be inhibited by using one or more of the above techniques. There are enough anti-debugging techniques available to sufficiently protect software against most threats.

See also

  • Software bug
    Software bug

    A software bug is an error, flaw, mistake, failure, or fault in a computer program that prevents it from behaving as intended . Most bugs arise from mistakes and errors made by people in either a program's source code or its software architecture, and a few are caused by compilers producing incorrect code....
  • Magic debug values
    Magic number (programming)

    In computer programming, the term magic number has multiple meanings. It could refer to one or more of the following:* a constant used to identify a file format or protocol;...
  • Assertion (computing)
    Assertion (computing)

    In computer programming, an assertion is a First-order logic placed in a program to indicate that the developer thinks that the predicate is always true at that place....
  • Software testing
    Software testing

    Software Testing is an empirical investigation conducted to provide stakeholders with information about the quality of the product or service under test , with respect to the context in which it is intended to operate....


Further reading

  • David J. Agans: Debugging: The Nine Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems, AMACOM, 2002. ISBN 0-8144-7168-4
  • Bill Blunden: Software Exorcism: A Handbook for Debugging and Optimizing Legacy Code, APress, 2003. ISBN 1-59059-234-4
  • Ann R. Ford, Toby J. Teorey: Practical Debugging in C++, Prentice Hall, 2002. ISBN 0-13-065394-2
  • Thorsten Grötker, Ulrich Holtmann, Holger Keding, Markus Wloka, The Developer's Guide to Debugging, Springer, 2008. ISBN 1-40205-539-0
  • Robert C. Metzger: Debugging by Thinking : A Multidisciplinary Approach, Digital Press, 2003. ISBN 1-55558-307-5
  • Glenford J Myers: *The Art of Software Testing, John Wiley & Sons inc, 2004. ISBN 0-471-04328-1
  • John Robbins: Debugging Applications, Microsoft Press, 2000. ISBN 0-7356-0886-5
  • Matthew A. Telles, Yuan Hsieh: The Science of Debugging, The Coriolis Group, 2001. ISBN 1-57610-917-8
  • Dmitry Vostokov: Memory Dump Analysis Anthology, Volume 1, OpenTask, 2008. ISBN 978-0-9558328-0-2


External links

  • - extensive collection of links to debugging tools and methods
  • - In-depth articles on analyzing and finding bugs in crash dumps