When compiling the following program:
------------------------------
program project1;
uses
Classes;var
i : pinteger;begin
i := nil;
i^ := 0;end.
------------------------------
with the default compiler options lazarus gives a new program: /usr/local/bin/fpc -MObjFPC -Scgi -O1 -gl -vewnhi -l -Fu. -oproject1 project1.lpr
and then running it, I get:
$ ./project1
An unhandled exception occurred at $080480B2 :
EAccessViolation : Access violation
$080480B2 main, line 10 of project1.lpr
Note the line number in the output.
For another example, here's a "DumpStack" routine you can use to dump the stack backtrace during runtime:
------------------------------
program project1;
uses
Classes,
SysUtils; procedure DumpStack ();
Var
i : longint;
begin
writeln('Exception at $' +
HexStr(Ptrint(ExceptAddr),sizeof(PtrInt)*2) + ':');
if ExceptObject is Exception then begin
writeln(Exception(ExceptObject).ClassName+':
'+Exception(ExceptObject).Message);
end else begin
writeln('Exception object ' + ExceptObject.ClassName + ' is not
of class Exception.');
end;
writeln(BackTraceStrFunc(ExceptAddr));
if (ExceptFrameCount > 0) then begin
for i:=0 to ExceptFrameCount-1 do begin
writeln(BackTraceStrFunc(ExceptFrames[i]));
end;
end;
end;
var
i : pinteger;
begin
try
i := nil;
i^ := 0;
except
on E : Exception do begin
DumpStack();
end;
end;
writeln('recovered!');
end.
------------------------------I think you must just not be putting the write compiler options (-g and -gl) in to get the line numbers in the backtrace, because I rely on it quite heavily and it "works for me."
-SG
