Breakpoint

In software development, a breakpoint is an intentional stopping or pausing place in a program, put in place for debugging purposes. It is also sometimes simply referred to as a pause.
More generally, a breakpoint is a means of acquiring knowledge about a program during its execution. During the
, etc.) to find out whether the program is functioning as expected. In practice, a breakpoint consists of one or more conditions that determine when a program's execution should be interrupted.History
Breakpoints were invented for ENIAC, one of the earliest digital computers, by programmer Betty Holberton.[1] In the initial design of ENIAC, program flow was set by plugging cables from one unit to another. To make the program stop at a certain point, a cable was removed, called a breakpoint.[2]
Types of breakpoints
Machine breakpoints
Early mainframe computers, such as the
Non-interactive breakpoints
Programmers have used machine code patches to implement single destructive breakpoints to cause a core dump since the early days of computers. The core dump provided the state of the registers and memory at the exact moment of the deliberate "crash".
Interactive breakpoints
The advent of
Conditional breakpoints
Breakpoints are most commonly used to interrupt a running program immediately before the execution of a programmer-specified
Other kinds of conditions can also be used, such as the reading, writing, or modification of a specific location in an area of memory. This is often referred to as a data breakpoint, or a watchpoint. Many systems also support breakpoints that are only active if a condition is met (such as a variable having a certain value), usually referred to as conditional breakpoint.[3]
Inspection tools
When a breakpoint is hit, various tools are used to inspect the state of the program or alter it.
Logpoints
A logpoint is a type of breakpoint that only prints (or "logs") information instead of interrupting execution. Usually the developer can specify a message and/or values of variables to print when execution reaches a specific point.[4] Logpoints are an alternative to putting logging statements into the program being debugged (sometimes called printf debugging), and particularly helpful when changing the program is not practical (for example when debugging an external library called by the program).
Implementations
Hardware
Many
Software
Without hardware support (and in multitasking environments), debuggers have to implement breakpoints in software. For instruction breakpoints, this is a comparatively simple task of replacing the instruction at the location of the breakpoint by either:
- an instruction that calls the debugger directly (e.g. a system call, or int3 in case of x86) or
- an invalid instruction that causes a deliberate program interrupt (that is then intercepted/handled by the debugger)
This technique may be more difficult to implement in multitasking systems using shared program storage (the interrupt may occur on a different thread, requiring resurrection of the original instruction for that thread). Also, if the program resides in protected memory, overwriting of instructions may be prevented.
Alternatively,
- an program cycle – that also naturally allows non-invasive breakpoints (on read-onlyprograms for instance).
- Interpreted languagescan effectively use the same concept as above in their program cycle.
- exception handlers. "Debug" options exist on some compilers to implement this technique semi-transparently.
Some debuggers allow registers or program variables in memory to be modified before resuming, effectively allowing the introduction of "hand-coded" temporary assignments for test purposes. Similarly, program instructions can often be skipped to determine the effect of changes to the program logic – enabling questions about program execution to be answered in a direct way (i.e. without assumptions or guesswork). In many cases it may be the only practical method of testing obscure "event-driven" error subroutines that rarely, if ever, get executed – without the added risk of leaving temporary source changes. Manually changing the resume location within a paused program can be used to enter an otherwise rarely executed section of code (such as a specific hardware condition handler).
Implementing data breakpoints in software however, can greatly reduce the performance of the application being debugged – since it is using additional resources on the same processor.
Some programming language implementations
AT
statement, which was originally intended to act as an instruction breakpoint.
Python implements a debugger accessible from a Python program.[6]
These facilities can be and are[7] abused to act like the COMEFROM statement.
See also
References
- ISBN 9780262018067
- ISBN 978-0-262-03398-5.
- ^ "FAQ How do I set a conditional breakpoint?". Eclipse Wiki. Retrieved 2023-04-19.
- ^ Walsh, David (2021-03-22). "Use Logpoints!". David Walsh Blog. Retrieved 2023-04-19.
- ^ GDB Internals Archived November 29, 2011, at the Wayback Machine
- ^ Python Library Reference: The Python Debugger Archived September 13, 2008, at the Wayback Machine
- ^ entrian.com – goto and comefrom for Python