[fpc-devel] Debugger for FPC

Graeme Geldenhuys graemeg.lists at gmail.com
Wed Mar 11 09:24:53 CET 2009

Hi everybody,

I'm not sure where is the best place to post this message. If there is
a better location, please let me know so I can close this thread and
repost in the correct location. Recently there was a discussion about
how useless debugging is with FPC and especially inside the Lazarus
IDE. It seems that unknowing to most FPC and Lazarus developers, most
users tend to use 80's style debugging with FPC. writeln(...) and log
files seem to be the norm. I fall under the "log file" users category
- that goodness tiOPF has good logging support and 99% of my projects
are tiOPF based.

Anyway, it seems that decent debugger support is a *major* issue with
FPC. To be honest, I have no idea how debuggers work, but am willing
to learn. If I compare FPC with Delphi - yes I was a Delphi developer
for many years but moved over to FPC some 4-5 years ago. Anyway, if I
compare FPC to Delphi, the debugger support is *very* lacking compared
to Delphi. I am a strong believer that the debugger should be regarded
as highly as the compiler. You cannot (or should not) have one without
the other!!

About GDB - this seems to be the debugger of choice for the Free
Pascal project. It seems GDB was a great stop-gap for the Free Pascal
project, but GDB simply doesn't cut in anymore. Support the language
features like Properties in Object Pascal are simply non existent. So
some things are impossible to debug. GDB is primary designed for C/C++
languages after all.

Like I said, I don't know much about debugger internals - I only know
how to use them via a IDE like Lazarus or Delphi. I heard the words
"stabs", COFF and DWARF being thrown around. It seems the flavour of
the month regarding debug symbol formats is DWARF at the moment. Yet,
when I go to the DWARF web site [http://dwarfstd.org/], it describes
the format in their introduction paragraph as primarily for C/C++ and
Fortan languages.

Quoted from the website:
"It addresses the requirements of a number of procedural languages,
such as C, C++, and Fortran, and is designed to be extensible to other

Yes, the say extensible, but I do not see a single reference to Object
Pascal on there website or in the DWARF v2 or v3 pdf documents. Yes
the do mention "pascal", but as far as I can see it's in the context
of ISO Pascal dated back to 1983. Object Pascal has come a looooong
way since Pascal of the 80's! So if Free Pascal uses DWARF, surely it
can't support all required Object Pascal language features - yet

Anybody know what debug format does the Delphi compiler use? I would
guess they have there own format, for exactly the same reasons I
mention here. Should we rather not design and implement our own Object
Pascal debug format that at least supports all our language features.
Then build a debugger around that? On notify the DWARF guys there
there is a language called Object Pascal and that DWARF spec should be
updated accordingly - but who knows how long that route would take.

Just so we are on the same page.... When I talk about the debugger
being useless in Lazarus, I don't blame the Lazarus developers, as the
issue seems to lie with GDB not supporting Object Pascal very well.
Lazarus can only use information supplied by GDB and is thus severely
limited by that factor.

Simple things that worked in Delphi IDE and even Kylix IDE, but not in
FPC/Lazarus IDE:

* Breakpoints do not always break
* Tooltip evaluation of highlighted code gives "no such symbol in
context" errors
* Properties on objects cannot be debugged. You have to use the
underlying field variable if you have access to it, or you the
property uses access methods you are screwed.
* In most cases I cannot inspect local variables, due to "no such
symbol in context" errors
* debugging nested procedures are totally useless.

For a full list of complaints have a look in the Lazarus mailing list
at the thread titled "Debugger problems" with started on 18 Feb. The
issues are so important, that a dedicated wiki pages has even been
created for it:

Like I said, I am not very knowledgeable with debugger internals, but
I am willing to learn and help. Not having decent debugger support is
killing me - and I am clearly not alone, as the thread in the Lazarus
mailing list proves. The problem as far as I can see, is that the Free
Pascal project is trying to use existing debuggers that were NOT
designed to work with the Object Pascal language. So maybe we should
stop using those and implement our own debugging symbol format (if
that is required) and then continue with writing a debugger specific
to Free Pascal. I am more that willing to put in some effort if it
means we end up with a working debugger!

Your thoughts?

  - Graeme -

fpGUI - a cross-platform Free Pascal GUI toolkit

More information about the fpc-devel mailing list