Forum > FPC development

Tutorial for debugging compiler?

(1/2) > >>

prabhav:
Hello,
I'm new to FPC but would like to help by working on the compiler but I'm unable to find any documentation on how to debug it through Lazarus to get a better understanding of the flow, its function etc. I've saw that there are defines that enable different writeln but that's not my favourite way of debugging things especially if its something complicated :-X
Is there any howto for that for beginners? %)

Thanks :)

marcov:
- Place a breakpoint in lazarus? A .lpi is in the compiler/ directory
- like gcc there are some verbosity options to show internal representations like -vp -vv,

Jonas Maebe:
Also, a useful procedure to place a breakpoint in is GenerateError. It's called for any kind of compilation error (syntax error, type error, assembler reader error, internal error, ...).

Bi0T1N:
Someone started a wiki page and I've just added a simple step-by-step tutorial. Hope that will help :)
However, I don't think it will work like this once you added something new to the compiler itself (e.g. add new intrinsics) as you need to recompile the compiler and then recompile the provided units. Maybe someone who knows how to do that from within Lazarus could add the needed information? I would also appreciate that ;)

ccrause:
In theory, debugging of the compiler is exactly the same as any other program (just like marcov already said).  My experience is that in practice you need to know what behaviour you want to debug (e.g. procedure overload selection) and where to find it in the source to put a break point in approximately the right place.  Just stepping through the compiler from the start hoping to find something specific requires an enormous amount of time and patience.

An easier situation is when you want to investigate what goes wrong when the compiler spits out an internal error code - in this case search for the error code in the source folder (I use rgrep a lot on Linux), then place a break point on the internalerror call and look at the stack trace to see the call history leading up to this point.

Another situation could be when you want to analyze the compiler code that leads to an error/warning.  In this case search for the error/warning code (or a short text snippet of the message) in the compiler/msg folder.  The English messages will be in the errore.msg file.  Locate the constant name of message (first part of message before "=") and search for this constant in the compiler source.

When using one of the existing ppcX.lpi projects in Lazarus, an executable called pp will be created in the target specific folder (X= target CPU).  This executable can be used just like a normal compiler to perform simple testing with. You can also recompile the RTL using this compiler, it saves the time to bootstrap the new compiler (if you are working on the 64 bit version of the compiler):

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---make rtl PP=compiler/x86_64/pp
Just some random thoughts from my side.  Please ask if there is anything more specific you would like to investigate.

Navigation

[0] Message Index

[#] Next page

Go to full version