Depends what exactly you need.
In all and any cases (well one exception) you must have the exe with debug info (that will make the exe rather large)
If you want the line number inside the exception handler of your own code, then search the fpc code for
dump_stack and BackTraceStrFunc
You will most likely have dwarf debug info (except maybe on some embedded targets), so you must include the unit LNfoDwarf. (or use -gl).
----
If you just want to debug, run in the debugger.
----
If you want to ship a release, but get meaningful error reports from your users (here is the exception / kind of)
build your app with debug info (dwarf), but WITHOUT -gl
EDIT: Build it with -gl
- Then you have the big exe (with debug info).
- Make a copy
- Use strip to remove debug info from the copy
- ship that
When you get a trace, it will be addresses only.
In the IDE menu: View > Leaks And traces
- paste the trace with the addresses
- press resolve
- select the big exe with debug info (the one before the copy).
- That must be the exact one, before the copy
- This will NOT work if you later build it again
And the IDE computes the line numbers.
Test it, before you use it
EDIT:
Originally I wrote without -gl.
But that is wrong (well it can be done, but would be an unnecessary bother)
The important part is to make the copy, and strip the copy. Then -gl on the stripped copy only prints addresses when it prints the trace for an exception.