DWARF
│
English (en) │
suomi (fi) │
About
DWARF (Debugging With Attributed Record Formats) is a debugging data format. Dwarf is needed when debugging with FpDebug.
Debugging information is generated by the compiler together with the machine code. Debugging information is read by the debugger. Debugging information is a representation of the relationship between the executable program and the original source code. This information is encoded into a pre-defined format and stored alongside the machine code.
The FPC provides the following DWARF-compatible debugging information with command line parameters:
- -gw Generate DWARFv2 debug information (same as -gw2)
- -gw2 Generate DWARFv2 debug information
- -gw2 -godwarfsets Generate DWARFv2 debug information, but include DWARFv3 description for sets ("set of SomeEnum").
- -gw3 Generate DWARFv3 debug information
- -gw4 Generate DWARFv4 debug information
Choosing a DWARF version for Debugging
Missing dwarf-style debugging-data-format will result in a message:
The Debugger Status page has as overview which versions are supported and recommended: Debugger_Status#Debug_Info_Support
If a project switches between several Debugger Backends, settings should either be adapted or the lowest recommended version should be used.
Differences between versions
Fpc encodes some data types differently depending on the version of DWARF used. This comprises:
- dynamic arrays
- short and long strings
- TObjects
- variants
Especially the info for Long/ShortString may affect how different debugger backends display those types. Long/ShortString do not have their own encoding, they are described as either record, array of char or pchar.
DWARFv2 (with/without sets)
For GDB "DWARFv2 with sets" is the best option. Testing shows that, if using other (v3 and up) DWARF (as generated by FPC) then GDB is more likely to crash.
- debugger may not be able to distinguish between PChar and AnsiString
- All identifiers (e.g. field-names) returned by the debugger are upper-cased
- ... other diffs
DWARF 2 (the one **without** "with sets") does not display sets "type TMySet = set of (v1,v2,v3)" correctly.
DWARFv3
DWARFv3 and up, encodes identifiers keeping their case. Instead of "TMYFOOCLASS" the debugger can display "TMyFooClass".
- debugger should be able to distinguish between PChar and AnsiString
- Identifiers (e.g. field-names) returned by the debugger are kept as declared (not upper-cased)
- ... other diffs
DWARF version comparison
The following list is still under construction.
The exact extend to which feature are available depends on the version of FPC, the version of DWARF, the debugger type (gdb, fpdebug, ...) and debugger version.
| DWARF support by version | ||||||||
|---|---|---|---|---|---|---|---|---|
| Feature | DWARF-2 | DWARF-3 | DWARF-4 | Comments
| ||||
Preserve case in identifiers MyVariable vs MYVARIABLE
|
N | Y | Y | |||||
Inspect sets type TSomeFlags = set of TFlag;
|
N Works with DWARF-2 with sets |
Y | Y |
| ||||
| Detect Longstring (AnsiString) vs PChar Display the correct result for StringOrPChar[n]
|
N | Y | Y | DWARF-2 will display 2 results. One as if it was PChar, the other as if it was String. String containing #0 may be cut off in DWARF-2
| ||||
support old stype object type TFoo = object
|
Y | Only FPC 3.3.1 up | Only FPC 3.3.1 up |
| ||||
| Backend compatibility | ||||||||
| - | DWARF-2 | DWARF-3 | DWARF-4 | Comments | ||||
| FpDebug | Y | Y | Y Requires FCP 3.2.3 or higher |
|||||
| GDB based backends | Y | N | N | GDB does understand DWARF-3, 4 and higher. However many versions of GDB crash with the DWARF-3 (and up) as generated by FPC. Specifying -godwarfcpp may help, but has not been tested. | ||||
| GDB with FpDebug | Y | Y | (Y) | In combined GDB + FpDebug backend, GDB is less exposed to the DWARF info that it does not understand. It may work with higher DWARF versions, but had very little testing. | ||||
| LLDB with FpDebug | Y | (Y) | (Y) | LLDB may issue some warnings with higher DWARF versions However it seems to work well with at least DWARF-3 It had little testing with DWARF-4
| ||||
Different DWARF versions in a single project
Linux
On Linux if different parts of a project (project, packages, RTL) are compiled with different DWARF versions, compilation may fail with a linker error.
