Configure the IDE
In order to be able to debug your projects, you need to make sure the IDE is correctly configured.
These settings do not usually change. You need to make them only once after you installed Lazarus, or if you changed/updated your installation
The image shows where to find the option dialog in Lazarus 0.9.31 and up. In previous versions the entry is in the "Environment" menu.
- Make sure that the option "GNU debugger (GDB)" is selected.
- The path to gdb.exe may differ:
- On Linux/Unix based systems it may be something like "/usr/bin/gdb"
- On Windows it should be in a folder called "mingw\bin\" under the directory in which Lazarus is installed.
Lazarus 2.0 and up: On Windows 64 find the option "FixIncorrectStepOver" in the property grid and set it to enabled (true).
- On MacOS, with Lazarus 2.0 or higher
- Select "LLDB (with fpdebug)"
- Set the path to: /usr/bin/lldb
In order to debug your project, you need to tell the IDE to compile it in a special way, which provides additional information required by the debugger.
The required settings are made in the "Project Options" dialog:
- You must enable the "Generate Debug Info for GDB"
- On Windows/Linux 32 bit it is highly recommended to use "Dwarf"
- If using the LLDB debugger, you are not allowed to use "Stabs". You can choose any of the Dwarf settings. Best to set this explicitly, as "automatic" depends on your FPC version.
- Dwarf 2: this is the minimum. It has no advantages. E.g., it can not display watches for "set of". IMHO, no reason to use at all.
- Dwarf 2 with sets: Use this if:
- you work with variants (not yet avail in Dwarf 3, will be fixed at some point) - you need to often switch between the new FpDebug and the old GDB -> pro: GDB currently has the better disassembler, and gdb currently often has better stack WHILE your app is in the Win-Kernel -> contra: GDB occasionally crashes.
- Dwarf 3: Best setting, unless one of the above condition applies to you.
The main differences between the three settings are the display of some types. For example, AnsiString may be displayed as PChar when using "dwarf 2 with/without". (though this may be OS dependent)
As for the big issues, like "property" inspection => all 3 are equal.
- You must not use any of the following
GDB 7.5 requires Lazarus 1.4 or higher.
GDB 7.7.1 seems to work well with Lazarus 1.2.4.
On macOS: lldb is part of the Apple developer tools
- IDE Options / Configuration
- Project Option / Command line args, Environment, and launcher app: Run -> Run Parameters
- The FAQ for the default "GNU Debugger" in Lazarus: GDB Debugger Tips
- Alternative debuggers in Lazarus: Debugger Status Includes a feature map and default-key-strokes