[Lazarus] Building a project with generics in libraries Laz1.9, FPC 3.0.2.

Donald Ziesig donald at ziesig.org
Mon May 22 18:35:53 CEST 2017


Hi All!

I have a rather large project that I have been refactoring from an 
earlier version that works. It is implemented in Laz 1.6.2. The new 
version takes considerable advantage of generics (which I learned first 
from Ada in the 1970s, then from C++ in the 1980s). The resulting code 
is much smaller and cleaner than the old code.

During the development process I noticed some strangeness while 
debugging.  Frequently I will step through code and the debugger behaves 
as if recent changes have not been made (even though the source shows 
the changes).  This has cost me days of debugging before the problem 
/miraculously /seems to be cured.  In other words I could not figure out 
why all of my earlier edits seemed to take effect without my doing 
anything explicitly to fix the problem.  (One other side effect is that 
gdb will occasionally crash when I let the mouse hover over certain 
identifiers after a breakpoint).

I have finally discovered the apparent cause and a magic (but annoying) 
workaround.

The steps in the cause:

A)

a1) Edit a library routine that contains generic code.

a2) Run with or without Debug.  (The IDE recompiles the library first).  
The code executes as if the edits never were made.

or

B)

b1) Edit a library routine that contains generic code.

b2) Compile the library using the Library Inspector.

b3) Run with or without Debug.  The code executes as if the edits never 
were made.


The magic workaround is very simple:

C)

c1) Edit a library routine that contains generic code.

c2) Compile the library using the Library Inspector.

*c3) Build the program using "Run | Cleanup and build..." or sometimes 
just "Run | Build"*  (I haven't found a pattern to decide which needs to 
be used so I currently use the Cleanup and build option).

c4) Run with or without Debug.  The edited code executes as written.


Note that the workaround is only necessary if the library's generic code 
is edited.  If the generic code is in the main code tree, the normal 
process of edit, run, debug, ... builds and runs correctly.

I think the problem is that the modules in the main source tree that 
instantiate the generics are not being updated unless the project is 
re-built explicitly (why? I don't know).

I will try to submit a bug report with a sample project after my current 
refactoring job is done (tight schedule, needs to be installed by the 
end of June).

Don Ziesig



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170522/5865989f/attachment-0001.html>


More information about the Lazarus mailing list