Computer Science

Breakpoints

Breakpoints are markers in a program's code that pause the execution of the program at a specific point. They are used by developers to debug and troubleshoot code by allowing them to inspect the state of the program at the point of the breakpoint. Breakpoints can be set in various programming languages and development environments.

Written by Perlego with AI-assistance

3 Key excerpts on "Breakpoints"

  • Definitive Guide to Arm Cortex-M23 and Cortex-M33 Processors
    • Joseph Yiu(Author)
    • 2020(Publication Date)
    • Newnes
      (Publisher)
    Similar to exceptions, debug events are either synchronous or asynchronous. For example:
    •  
      The execution of a breakpoint instruction, a “vector catch” or when a program execution hits a breakpoint set in the breakpoint unit, are all synchronous. When the breakpoint event is accepted, the processor stops the execution of the instruction and either enters halt mode or the debug monitor. The program counter visible to the debugger, or the stacked return address in the case of monitor mode debugging, is the same address as the breakpoint location, or is the first instruction of the exception handler for vector catch events.
    •  
      Data watchpoint events (including PC match and cycle counter match) and external debug request are asynchronous. This means that the processor might, before stopping, continue to execute additional instructions that are already in the pipeline.
    Debuggers must take account of these situations when handling debug operations. For example, to resume an operation after a breakpoint for halt mode debugging, the debugger needs to:
    1. (1)  Disable the breakpoint, then
    2. (2)  Use the single stepping feature to move the program counter to the next instruction, then
    3. (3)  Re-enable the breakpoint so that the processor can halt again if it subsequently executes to the same location, then
    4. (4)  Clear the halting request to resume the operation
    If the above steps are not carried out, when the software developer attempts to resume the program execution after the program is halted by a breakpoint, the processor would immediately hit the same breakpoint because the program counter would, as the instruction pointed to by the breakpoint had not been executed, still set to the breakpoint location (not the address after the breakpoint).

    16.2.6: Using the breakpoint instruction

    When writing software, the breakpoint instruction can be inserted to stop the program execution at points of interest. Unlike hardware breakpoint comparators, you can insert as many software Breakpoints as you like (subject, obviously, to the available memory size). The breakpoint instruction (BKPT #immed8) is a 16-bit Thumb® instruction and uses the encoding 0xBExx—only the upper 8 bits of 0xBE is decoded by the processor. The lower 8 bits of the instruction depend on the immediate data that is given following the instruction. If the debug tool supports semihosting, the immediate data can be used for requesting semihosting services. In this scenario, the debugger would have to extract the immediate data value from the program memory, or from the compiled program image if this was available and if the contents in the program memory was guaranteed to be identical to the current program image in the chip. For Arm development tools, the semihosting service usually uses the value 0xAB, the lower 8 bits in the BKPT instruction.
  • Professional Visual Studio 2010
    • Nick Randolph, David Gardner, Chris Anderson, Michael Minutillo(Authors)
    • 2010(Publication Date)
    • Wrox
      (Publisher)
    The call stack is generated using function addresses. As such, the breakpoint that is set is an address breakpoint. This type of breakpoint is only useful within a single debugging session, because function addresses are likely to change when an application is modified and rebuilt.
    Adding Break Conditions
    Though Breakpoints are useful for pausing an application at a given point to review variables and watch application flow, if you are looking for a particular scenario it may be necessary to break only when certain conditions are valid. Breakpoints can be tailored to search for particular conditions, to break after a number of iterations, or even be filtered based on process or machine name.
    Condition
    A breakpoint condition can be specified by selecting Condition from the Breakpoint item on the right-click context menu for the breakpoint. This brings up the Breakpoint Condition dialog shown in Figure 40-6 , which accepts a Boolean expression that determines whether the breakpoint will be hit. If the expression evaluates to false , the application continues past the breakpoint without breaking.
    FIGURE 40-6
    In the case of Figure 40-6 , which is for a breakpoint set within the Order class, the condition specifies that the order total must be greater than 1000. As with most debugging windows, the Condition field provides rich IntelliSense support to aid writing valid conditions. If an invalid condition is specified, the debugger throws an appropriate error message and the application will break the first time the breakpoint is reached.
    When a condition, or a hit count, as shown in the next section, is placed on a breakpoint, the breakpoint changes appearance. The solid red dot is replaced with a red dot with a white cross. When you move your mouse across this dot, the tooltip provides useful information about the breakpoint condition, as illustrated in Figure 40-7 .
    FIGURE 40-7
    Sometimes it is more relevant to know when this condition changes status, rather than when it is true. The Has Changed option breaks the application when the status of the condition changes. If this option is selected, the application will not break the first time the breakpoint is hit, because there is no previous status to compare against.
  • Professional Visual Studio 2017
    • Bruce Johnson(Author)
    • 2017(Publication Date)
    • Wrox
      (Publisher)
    Long gone are the days when debugging an application involved adding superfluous output statements to track down where an application was failing. Visual Studio 2017 provides a rich, interactive debugging experience that includes Breakpoints, tracepoints, and the Edit and Continue feature. This chapter covers how you can use these features to debug your application.

    Breakpoints

    A breakpoint is used to pause, or break, an application at a particular point of execution. An application that has been paused is in Break mode, causing a number of the Visual Studio 2017 windows to become active. For example, you can use the Watch window to view variable values. Figure 31-1 shows a breakpoint added to the constructor of the Customer class. The application breaks on this line if the Customer class constructor is called.
    FIGURE 31-1

    Setting a Breakpoint

    You can set Breakpoints either through the Debug menu, using the Toggle Breakpoint item from the right-click context menu, or by using the keyboard shortcut F9. The Visual Studio 2017 code editor also provides a shortcut for setting a breakpoint using a single mouse-click in the margin. An application can be paused only on a line of executing code. This means that a breakpoint set on either a comment or a variable declaration is repositioned to the next line of executable code when the application is run.
    Simple Breakpoints
    You can set a breakpoint on a line of code by placing the cursor on that line and enabling a breakpoint using any of the following methods:
    • Selecting Toggle Breakpoint from the Debug menu
    • Pressing F9
    • Clicking once in the margin of the code window with the mouse
    Once a breakpoint has been set for a line, additional details for the breakpoint can be specified through Settings. You can access Settings by right-clicking the content menu or hovering your mouse over the breakpoint icon in the margin and clicking on the gear image (see Figure 31-1 ). Both actions cause the Settings subwindow to appear (see Figure 31-2 ). In this window, you can see that the breakpoint is set at line 13 of the Customer.cs file. There is also a character number that indicates the character position in the line where the breakpoint is set. This is only really useful when multiple statements appear on a single line. Clicking on the link where that information appears changes the interface to allow for modification of the line and character position, as shown in Figure 31-3
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.