Recent

Author Topic: How to find out why the compiler hangs ?  (Read 8198 times)

Nitorami

  • Sr. Member
  • ****
  • Posts: 481
How to find out why the compiler hangs ?
« on: January 09, 2018, 09:03:06 pm »
Today I encountered an issue I never had before. Normally my program compiles within two seconds, then I made a small modification to the Class hierarchy in a bottom unit, and when I now try to build, the compiler keeps hanging in an endless loop, after having compiled all except the topmost unit. It says "Compiling - press ESC to cancel", but does not react to ESC nor anything else. Processor load is at 60% permanently.

I reverted the code change and it compiles, I can live with that, that is not the issue. But this should be reported, only, I cannot possibly submit the entire program for diagnosis.

Have tried many other compiler settings, target processors etc. but to no avail. Tried changing from objfpc to delphi mode; well, the compiler then does not hang but throws a lot of error messages because my code is not delphi compatible. Have deleted the old .o and .ppu files, and the fp.ini, fp.dsk, fp.cfg, but nothing helps. I shuffled the order of units in the "uses" section but no sucess either.
How can I narrow down such a problem ? Each time I try a new compilation with modified settings or whatever, I'll have to kill the IDE and start a new command processor. Getting tired of that.

I am using the textmode IDE with FPC3.0.2 and win32. Don't think anything is wrong with my installation, as only this specific code change causes the problem. Will try FPC 3.0.4 next but am not too optimistic.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to find out why the compiler hangs ?
« Reply #1 on: January 09, 2018, 09:16:33 pm »
That's one kind of hard to reproduce problem. The compiler might be trapped in an infinite loop somehow (well, it's not in anyway magical). Still, a small source that can reproduce the behavior is expected. If it's hard to write one, then I guess you can help by debugging the compiler yourself, using your project source code. There's a .lpi in the compiler source directory, you can use that for debugging the compiler in lazarus. Maybe it will help if you at least mention what changes to the source code trigger this behavior so a compiler dev can point where to put breakpoint closer to the problem source.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: How to find out why the compiler hangs ?
« Reply #2 on: January 09, 2018, 09:26:28 pm »
As TS is not using lazarus and the problem seems related to text mode ide (internal compiler) TS could perhaps try to compile sources using only the commandline compiler. IF you do not have it it would be a separate installation.

That would be able to better pinpoint if it is compiler or (only) textmode related.

@Nitorami, be aware that compiling generics can take a (very) long while. for instance compiling the delphi generics collection took ages, and it gets worse when there is  something actually wrong in the code. But seeing that when you revert it compiles fine, would probably indicate something else is amiss.

Something that is able to tell you where things go wrong is using verbose all option, but i take it that this only points to compiling the unit that contains the problematic code. if not, then please dump that log for us to see. Perhaps the compiler gets stuck somewhere else.

Other than that: make a copy of your current code and then start chopping away to see if you are able to reproduce with a smaller example code.

Nitorami

  • Sr. Member
  • ****
  • Posts: 481
Re: How to find out why the compiler hangs ?
« Reply #3 on: January 09, 2018, 10:01:23 pm »
Yes, certainly the compiler is trapped in an endless loop. I don't use generics so that cannot be the reason for long compilation times.

The verbose option seemed like a good idea but as the compiler hangs, the messages are lost :D But when I compile the units individually, the messages do not seem to indicate anything unusual.

Another funny thing is, if I insert a typo at the end of the main program, the compiler complains, but when I correct it and recompile, it hangs. The issue may be close to the linker stage.

The textmode IDE displays a compiler progress window, informing about the currently compiled unit and line number. I hoped that this might be useful, but the text is different on each try. I guess the window content is only loosely synchronised to the compilation process.

Recompiling and debugging the sources is somewhat beyond my skills I fear. I'll try the "chopping" approach and see whether I can reproduce the issue with much less code.


Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to find out why the compiler hangs ?
« Reply #4 on: January 09, 2018, 10:19:24 pm »
Another funny thing is, if I insert a typo at the end of the main program, the compiler complains, but when I correct it and recompile, it hangs. The issue may be close to the linker stage.
I'm not too sure about it, if you make a typo that would be on parsing stage. But if the source is syntactically valid, the infinite loop can be anywhere inside the compiler (sub)processes. Also, did you use any options related to code generation (e.g. -O, -Oo, -Op, -Cp, -Cf)?

Nitorami

  • Sr. Member
  • ****
  • Posts: 481
Re: How to find out why the compiler hangs ?
« Reply #5 on: January 09, 2018, 10:32:21 pm »
Quote
Also, did you use any options related to code generation (e.g. -O, -Oo, -Op, -Cp, -Cf)?
Maybe not all of them but definitely tried the most conservative of all settings, no optimisation, 80386 processor etc.

I just found that compilation from the commandline with fpc.exe works. Surprise. I am not familiar with the commandline switches and it took me a while to put something together, but got it compiled after all. Maybe some switches are still different than in the IDE.. not sure.

It also compiles with Lazarus, but my installation is 64bit and does not compare.

So - the issue might really be related to the textmode IDE only. I am used to it and still love it, but I think it gets little care from the developers. Maybe I should switch to Lazarus, finally  :'(

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: How to find out why the compiler hangs ?
« Reply #6 on: January 09, 2018, 10:55:34 pm »
I just found that compilation from the commandline with fpc.exe works. Surprise. I am not familiar with the commandline switches and it took me a while to put something together, but got it compiled after all. Maybe some switches are still different than in the IDE.. not sure.

Pass -s in the Options >> Compiler >> Additional compiler args (I guess).

It should generate a batch file PPAS.BAT (and link.res)

Nitorami

  • Sr. Member
  • ****
  • Posts: 481
Re: How to find out why the compiler hangs ?
« Reply #7 on: January 09, 2018, 11:12:51 pm »
I understand -s means "do not call assembler and linker". Still hangs, and does not generate the said files.

Tried again with a hello world program, and it does generate a link.res, but also an exe file...1000kB size - what ? Don't understand this - if no assembler and linker is called, how can an exe file be generated ? 


EDIT - sorry, had "Call linker after" ticked. Without that, the hello world program has reasonable size, and the said files are generated. But compiling my program still hangs.
« Last Edit: January 09, 2018, 11:17:05 pm by Nitorami »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: How to find out why the compiler hangs ?
« Reply #8 on: January 09, 2018, 11:15:45 pm »
What about passing -Cn instead?

Nitorami

  • Sr. Member
  • ****
  • Posts: 481
Re: How to find out why the compiler hangs ?
« Reply #9 on: January 09, 2018, 11:22:28 pm »
Same. Hangs.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: How to find out why the compiler hangs ?
« Reply #10 on: January 09, 2018, 11:23:54 pm »
Ah, I see, you edited your answer.

Can you share the change that sparked the problem?

Nitorami

  • Sr. Member
  • ****
  • Posts: 481
Re: How to find out why the compiler hangs ?
« Reply #11 on: January 09, 2018, 11:30:14 pm »
I could share that, but don't think it helps, as the unit with the change compiles ok on its own. The issue only appears when compiling the entire program, or at least a high level unit.



Nitorami

  • Sr. Member
  • ****
  • Posts: 481
Re: How to find out why the compiler hangs ?
« Reply #12 on: January 10, 2018, 11:17:44 am »
Update: Same issue on an office PC at win7 (rather than my home win 10).

I found the problem is related to the generation of debug information. It compiles ok without generating debug information, but the -g option reliably reproduces the freeze.

When compiling from the command line, I can at least interrupt the process by hitting Ctrl-C, but the IDE hangs.

Thaddy

  • Hero Member
  • *****
  • Posts: 14215
  • Probably until I exterminate Putin.
Re: How to find out why the compiler hangs ?
« Reply #13 on: January 10, 2018, 11:29:57 am »
Try specifying -B which forces a total rebuild of your project. If you change a base class (in a separate unit from derived classes) that might be the issue.
You can not simply change a base class and expect derived classes to work. In any compiled language...

If I am right, then kindly hit yourself firmly with a baseball bat...slap on the wrist is also ok...
« Last Edit: January 10, 2018, 11:31:47 am by Thaddy »
Specialize a type, not a var.

Nitorami

  • Sr. Member
  • ****
  • Posts: 481
Re: How to find out why the compiler hangs ?
« Reply #14 on: January 10, 2018, 11:43:01 am »
No need to hit myself over the head unfortunately, I already deleted all .o and .ppu and did fpc -g -B.
The compiler hangs on generating the debug information for a full build. When it finds precompiled units, the issue may not occur. I.e.

fpc -B myprogram.pas
fpc -g myprogram.pas
is ok.

But
fpc -g -B myprogram.pas
hangs.

EDIT: Found a workaround. It works when using the DWARF debug format fpc -B -gw. Only I have no idea what dwarf and stabs mean, and whether I can use the debug features in the IDE in the same way when switching to dwarf.
« Last Edit: January 10, 2018, 11:58:41 am by Nitorami »

 

TinyPortal © 2005-2018