[fpc-devel] LineInfo unit seems broken in 2.5.1

Graeme Geldenhuys graemeg.lists at gmail.com
Sat Aug 21 17:19:29 CEST 2010


Hi,

Not sure if this affects 2.4.x as well (I haven't tested yet). DUnit2
unit testing framework tries to report the line number and method that
caused a unit test failure. Under 64-bit systems, the method name
information is unknown (always blank) - it at least works under 32-bit
systems.  And under both 64-bit and 32-bit, the line number
information is total rubbish. It reports line numbers that aren't even
close to where the information (caller method) occurs.

I'm pretty sure if I use fpcunit, I'll probably get the same results
because the code I use in DUnit2 is near identical to FPCUnit's. I
tried with DUnit2, and with a stand-alone app that requests line info
when entering and exiting a method/procedure/function. Every time the
results are as described above.

Below is my standalone test application...



----------------[  lineinfotest1.pas ]--------------------------
program testlineinfo1;
{$ifdef FPC}{$mode objfpc}{$h+}{$endif}
{$ifdef mswindows}{$apptype console}{$endif}
uses
 sysutils;

type
  MyClass = class(TObject)
  public
    procedure Run;
    procedure RunTwo;
  end;

procedure ReportLineInfo(position: string; frame_pointer: pointer);
var
  caller_addr: Pointer;
  func, source: shortstring;
  line: longint;
  sline: string;
begin
  func := '';
  source := '';
  line := 0;
  caller_addr := get_caller_addr(frame_pointer);
  GetLineInfo(ptruint(caller_addr), func, source, line);
  str(line, sline);
  Writeln(position, ' ', func, ' ', source, ' ', sline);
end;

procedure MyClass.Run;
begin
  ReportLineInfo('MyClass.Run [32] >', get_frame);
  writeln('inside MyClass.Run...');
  RunTwo;
  ReportLineInfo('MyClass.Run [35] <', get_frame);
end;

procedure MyClass.RunTwo;
begin
  ReportLineInfo('MyClass.RunTwo [40] >', get_frame);
  writeln('inside MyClass.RunTwo...');
  ReportLineInfo('MyClass.RunTwo [42] <', get_frame);
end;

var
  c: MyClass;
begin
  ReportLineInfo('main [48]', get_frame);

  c := MyClass.Create;
  c.Run;
  c.Free;

  ReportLineInfo('main [54]', get_frame);
end.

-------------------------------------------------------------------


Command line to compile above application:

  /home/graemeg/programming/fpc-2.5.1/bin/ppc386 -otestlineinfo1.elf32
-l -Mobjfpc -Sh -gl -O- testlineinfo1.pas


And here is the console output on my 32-bit system. I only have a
64-bit system at work, so can only post that output on Monday.
But in this output you can already see the line number information
being completely rubbish. In square brackets is the real line numbers
I typed myself in the first parameter to ReportLineInfo() which is
just reference information to compare with LineInfo unit information.

$ ./testlineinfo1.elf32
main [48]   0
MyClass.Run [32] > main testlineinfo1.pas 51
inside MyClass.Run...
MyClass.RunTwo [40] > MYCLASS__RUN testlineinfo1.pas 34
inside MyClass.RunTwo...
MyClass.RunTwo [42] < MYCLASS__RUN testlineinfo1.pas 34
MyClass.Run [35] < main testlineinfo1.pas 51
main [54]  0



-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-devel mailing list