RAD Studio C++ IDE has a lot of features and one of the feature is Breakpoints, so you can break and check all the things at that time.
Table of Contents
What is a breakpoint in C++?
Breakpoints pause program execution at a certain location or when a particular condition occurs. Generally breakpoints are used to stop application at a step when running, thus developer is able to check changes in application, variables, memory, files, cpu, and task states. At this time you can also watch the changes in variables. You can continue or if you see there is a problem you can stop your application before it may cause an unwanted things. We can set source breakpoints and module load breakpoints in the Code Editor before and during a debugging session. We can set data breakpoints and address breakpoints only when the application is running in debug mode (F9).
Since the first version of the C++ Builder, there have been many changes in setting and modifying breakpoints. Setting and Modifying Breakpoints are explained well in the DocWiki of Embarcadero. Let’s see these,
What kind of breakpoints does C++ Builder have?
RAD Studio has a lot of advanced options about different kind of breakpoints. It has 5 kind of Breakpoints,
- Simple Breakpoint ( One Click Source Breakpoint )
- Source Breakpoint
- Address Breakpoint
- Data Breakpoint
- Module Load BreakPoint
Now let’s see how we can create these breakpoints
How to create a simple breakpoint in C++ Builder?
Creating a breakpoint at a code line in RAD Studio is very easy. To create a breakpoint, just click the left blank side of the code line that you want to break. This clickable area is in the code window and at the left side of the code line. When you click that area it will create a breakpoint that shown with a red icon as below. For example, as in this example we want to stop before the line that has “ShowMessage(“ok2″)”; we click the point where is the normally blank as in shown with a red dot below,
How to run and debug a C++ Builder Application using breakpoints?
If you run your application in Debug mode (F9) it will break at that break points, to continue press Run in Debug mode again or press F9. When you run your application break point at that time will be shown in different background colored line as shown in image above.
What is the meaning of breakpoint icons and colors in C++ Builder?
During a debugging session, any line of code that is eligible for a breakpoint is marked with a blue dot in the left gutter of the Code Editor.
You can also set breakpoints on frames displayed in the Call Stack window. The breakpoint icons in the Call Stack window are similar to those in the Code Editor, except that the blue dot in the Call Stack indicates only that debug information is available for the frame, not whether a breakpoint can be set on that frame.
Breakpoints are displayed in the Breakpoint List window, available by selecting View > Debug windows > Breakpoints.
You can drag breakpoint icons and drop them in the Code Editor window; a moved breakpoint retains the settings of the original breakpoint. The following icons are used to represent breakpoints in the Code Editor gutter.
How can I set a source breakpoint in C++ Builder?
RAD Studio has a lot of breakpoint options for the professional usage.
- To prefill the line number in the dialog box, click the line of source in the Code Editor at the point where you want to stop execution.
- Choose Run > Add Breakpoint > Source Breakpoint to display the Add Source Breakpoint dialog box
.Tip: To change the Code Editor gutter, choose Tools > Options > Editor Options > Display and adjust the Gutter width option.
3. In the Add Source Breakpoint dialog box, the file name is prefilled with the name of the file, and Pass count is set to 0 (meaning that the breakpoint fires on the first pass). In the Line number field, enter the line in the Code Editor where you want to set the breakpoint.
4. To apply a condition to the address breakpoint, enter a conditional expression in the Condition field. The conditional expression is evaluated each time the breakpoint is encountered, and program execution stops when the expression evaluates to True.
5. To associate the source breakpoint with a breakpoint group, enter the name of a group or select from the Group drop-down list.
To set any of the Advanced options, see the Add Address Breakpoint or Add Data Breakpoint for the Add Address Breakpoint or Add Data Breakpoint dialog box. Note: To quickly set a breakpoint on a line of source code, click the left gutter of the Code Editor next to the line of code where you want to pause execution.
How to set an address breakpoint in C++ Builder?
- Run your application in Debug mode (for example, use F9, F8, F7, or F4).
- Choose Run > Add Breakpoint > Address Breakpoint to display the Add Address Breakpoint dialog box.
- In the Address field, enter the address in memory (such as $00011111) at which you want to set the breakpoint.
- To apply a condition to the address breakpoint, enter a conditional expression in the Condition field. The conditional expression is evaluated each time the breakpoint is encountered, and program execution stops when the expression evaluates to true.
- To specify that the address breakpoint will only fire after a number of passes, enter the number in the Pass count field.
- To associate the address breakpoint with an existing breakpoint group, enter the group name in the Group field, or select the name of an existing group from the drop-down list.
- To set any of the Advanced options, see the Add Address Breakpoint or Add Data Breakpoint for the Add Address Breakpoint or Add Data Breakpoint dialog box.
Note: You can also set an address breakpoint in the CPU view or the Disassembly view by clicking in the gutter.
How can I set a data breakpoint in C++ Builder?
- Run your application in Debug mode (for example, use F9, F8, F7, or F4).
- Choose Run > Add Breakpoint > Data Breakpoint to display the Add Data Breakpoint dialog box.
- In the Address field, enter the address of the data you want to function as the data breakpoint.
- In the Length field, specify the length of the data operand that is to constitute the breakpoint. Note that a warning is displayed for the following issues:
- The length of the data breakpoint should not cross an even-byte boundary. (A data breakpoint with a 1-byte length has no alignment problems, but 2-byte and 4-byte data breakpoints might cover more or fewer addresses than you intend.)
- The data breakpoint should not be set on a stack location. (The breakpoint might be hit so often that the program cannot run properly.)
- To apply a condition to the breakpoint, enter a conditional expression in the Condition field. The conditional expression is evaluated each time the breakpoint is encountered, and program execution stops when the expression evaluates to True.
- To specify that the breakpoint only fires after a number of passes, enter the number in the Pass count field.
- To associate the data breakpoint with an existing breakpoint group, enter the group name in the Group field, or select the name of an existing group from the drop-down list.
- To set any of the Advanced options, see Add Address Breakpoint or Add Data Breakpoint.
How can I set a module load breakpoint in C++ Builder?
- Choose Run > Add Breakpoint > Module Load Breakpoint to display the Add Module Load Breakpoint dialog box.
- Do either of the following:
- In the Module name field, enter the name of the DLL, package, or other module type that you want to monitor, or select a name from the drop-down list, and click OK.
- Click Browse to open the Select Module dialog box and browse modules from another target platform. Click the Modules dropdown next to the File Name field, and select the type of modules you want to see:
- Modules (*.dll, *.ocx, *.bpl, *.exe, *.dylib) {both Windows and Mac modules}
- Windows Modules (*.dll, *.ocx, *.bpl, *.exe) {only Windows modules}
- macOS Modules (*.dylib) {only Mac modules}
- Any file *.*Click Open to open the module you want. The name is automatically inserted in the Add or Edit Module Load Breakpoint dialog box.
Note: You can also use the Modules Window to set a module load breakpoint.
When the module you specify is loaded during program execution, the module load breakpoint is hit, and program execution pauses.
How to persist C++ Builder breakpoints from session to session?
If you set the Autosave Project desktop option, breakpoints you set for a project will persist from session to session.
- Set the breakpoints (and watches) that you want to keep from session to session.
- Select Tools > Options > Environment Options.
- Enable Autosave Project desktop. When you exit the product or close your project, your desktop settings are saved to a .dsk file. When you reopen your project, the product reads the .dsk file and restores your saved desktop, breakpoints, watches, and open files.
You need to delete the .dsk file when you no longer want the saved set of breakpoints to persist in your project (or any other items controlled by the Autosave Project desktop option).
How to modify a C++ breakpoint?
- Open the Breakpoint List Window by selecting View > Debug Windows > Breakpoints. Right-click the icon for the breakpoint you want to modify. For a source breakpoint, you can right-click the breakpoint icon in the Code Editor gutter, and choose Breakpoint Properties.
- Set the options in the Breakpoint Properties dialog box to modify the breakpoint. For example, you can set a condition, create a breakpoint group, or specify an action that is to occur when execution reaches the breakpoint.
- Click Help for more information about the options in the dialog box.
- Click OK.
How to create a C++ Builder breakpoint group?
- Open the Breakpoints List by choosing View > Debug Windows > Breakpoints .
- Right-click the breakpoint and choose Breakpoint Properties.
- To create a breakpoint group, enter a group name in the Group field. To add the breakpoint to an existing group, select a name from the drop-down list box.
- Click OK.
How to enable or disable a C++ Builder breakpoint or a breakpoint group?
- Right-click the breakpoint icon in either the Code Editor or the Breakpoint List Window and choose Enabled to toggle between enabled and disabled. In the Breakpoint List, you can click the checkbox at the left of the icon.
- To enable or disable all breakpoints, right-click a blank area (not on a breakpoint) in the Breakpoint List window and choose Enable All or Disable All.
- To enable or disable a breakpoint group, right-click a blank area (not on a breakpoint) in the Breakpoint List window and choose Enable Group or Disable Group.
Tip: You can use either of the following shortcuts to enable/disable breakpoints:
Ctrl+Click
the breakpoint symbol in the Code Editor gutter.An enabled breakpoint symbol, such as , changes to a disabled breakpoint symbol, such as , when you useCtrl+Click
to toggle between enabled and disabled.- Press
F5
.The breakpoint symbol is removed when you pressF5
on an enabled breakpoint, but the breakpoint symbol reappears and is enabled when you pressF5
again.
Disabling a breakpoint or breakpoint group prevents it from pausing execution, but retains the breakpoint settings, so that you can enable it later.
How can I create a conditional breakpoint in C++ Builder?
- Choose Run > Add Breakpoint and select the type of breakpoint you want from the submenu.
- Complete the fields in the dialog box as described in the procedure given earlier for that breakpoint type.
- In the Condition field, enter a conditional expression to be evaluated each time this breakpoint is encountered during program execution. The breakpoint pauses execution when the expression evaluates to True.
- Complete other fields as appropriate.
- Click OK.
Conditional breakpoints are useful when you want to see how your program behaves when a variable falls into a certain range or what happens when a particular flag is set.
If the conditional expression evaluates to True (or not zero), the debugger pauses the program at the breakpoint location. If the expression evaluates to False (or zero), the debugger does not stop at the breakpoint location.
How to set a breakpoint on a specific thread in C++ Builder?
- Choose Run > Add Breakpoint and select the type of breakpoint you want from the submenu.
- Complete the fields in the dialog box as described in the procedure given earlier for that breakpoint type.
- In the Thread field, enter or select the thread number (for numbered threads) or thread name (for named threads).
- Complete other fields as appropriate.
- Click OK.
How to associate actions with a C++ Builder breakpoint?
- On the Breakpoint List Window, right-click the breakpoint and choose Breakpoint Properties.
- Click Advanced to display additional options.
- Check the actions that you want to occur when the breakpoint is encountered. For example, you can specify an expression to be evaluated and write the result of the evaluation to the Event Log.
- Click OK.
How to change the color of the text at the execution point or the color of breakpoints in C++ Builder?
- Choose Tools > Options > Editor Options > Color.
- In the code sample window, select the appropriate language tab. For example, to change the breakpoint color for Delphi code, select the Delphi tab.
- Scroll the code sample window to display the execution and breakpoint icons in the left gutter of the window.
- Click anywhere on the execution point or breakpoint line that you want to change.
- Use the Foreground Color and Background Color drop-down lists to change the colors associated with the selected execution point or breakpoint.
- Click OK.
Note: You can also set breakpoints in the Breakpoint List, the CPU window (and the Disassembly view), the Call Stack view, and the Modules window.
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.
There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.
Design. Code. Compile. Deploy.
Start Free Trial
Free C++Builder Community Edition