View Issue Details

IDProjectCategoryView StatusLast Update
0028245FPC-public2015-06-05 15:10
ReporterDenis Kozlov Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionduplicate 
PlatformWindows 
Summary0028245: Exceptions in TApplication.OnException have no line info
DescriptionI am trying to produce exception call stack with line information for exceptions raised in a GUI app.

I assign an event handler for TApplication.OnException. Inside the event handler procedure, I display the call stack using a slightly modified version of DumpExceptionCallStack function (http://wiki.freepascal.org/Logging_exceptions). Basically, it iterates through ExceptFrames and calls BackTraceStrFunc function.

Unfortunately, BackTraceStrFunc function never produces any line info (line number and source file name). The example project is created using the built-in application template, with "Generate debugging info" and "Display line numbers" enabled by default.

Do exception frames get corrupted somehow, line info retrieval is broken, or am I missing something?

Another strangeness is that if exception is thrown and caught (using try...except), then BackTraceStrFunc function does produce line info BUT only for the first thrown exception, while further exceptions result in the same call stack but without line info.

Tested on Lazarus 1.2.4 and 1.5 r49263, FPC 2.6.4.
Additional Informationfunction GetExceptionCallStack(E: Exception): String;
var
  I: Integer;
  Frames: PPointer;
begin
  Result := '';
  if E <> nil then
  begin
    Result := Result +
      'Exception class: ' + E.ClassName + LineEnding +
      'Message: ' + E.Message + LineEnding;
  end;
  Result := Result + BackTraceStrFunc(ExceptAddr);
  Frames := ExceptFrames;
  for I := 0 to ExceptFrameCount - 1 do
  begin
    Result := Result + LineEnding + BackTraceStrFunc(Frames[I]);
  end;
end;
TagsBackTraceStrFunc, ExceptFrames, Exception, OnException
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Relationships

duplicate of 0013518 resolvedMichael Van Canneyt Only first backtrace in big program has attached source nad line information 

Activities

Denis Kozlov

2015-06-04 18:14

reporter  

Andrey Zubarev

2015-06-04 18:28

reporter   ~0084253

Last edited: 2015-06-04 18:30

View 3 revisions

I confirm in trunk Lazarus\FPC
Lineinfo can be obtained only once, and if did it standard exceptions handler (DumpExceptionBackTrace), nothing can be done already. Even repeat calling DumpExceptionBackTrace generates only addresses((.

Workaround:
In formcreate replace BackTraceStrFunc:
...
MyStoreBackTraceStrFunc:=BackTraceStrFunc;
BackTraceStrFunc:=@SysBackTraceStr;
...

And restore it in your handler before receiving lineinfo:
...
BackTraceStrFunc:=MyStoreBackTraceStrFunc;
...

Maybe this is FPC issue?

Maxim Ganetsky

2015-06-04 22:37

reporter   ~0084255

> Maybe this is FPC issue?

It looks so, yes.

Denis Kozlov

2015-06-05 12:44

reporter   ~0084262

Just to clarify, the above mentioned pseudo-workaround with replacement of BackTraceStrFunc function only works for the first call, consequent calls have no line info.

Denis Kozlov

2015-06-05 13:42

reporter  

Denis Kozlov

2015-06-05 13:45

reporter   ~0084263

Last edited: 2015-06-05 15:01

View 4 revisions

I have uploaded a sample Console app project, to test pure FPC without Lazarus.

Everything works fine. I tried raising multiple exceptions and dumping call stack multiple times per exception. Line info is displayed in every case.

This doesn't rule out that it may still be an FPC issue. This only suggested that circumstances of how exceptions/callstack are treated in basic procedural code and in full Lazarus GUI mode are different.

Issue History

Date Modified Username Field Change
2015-06-04 18:12 Denis Kozlov New Issue
2015-06-04 18:13 Denis Kozlov Tag Attached: Exception
2015-06-04 18:13 Denis Kozlov Tag Attached: BackTraceStrFunc
2015-06-04 18:13 Denis Kozlov Tag Attached: ExceptFrames
2015-06-04 18:13 Denis Kozlov Tag Attached: OnException
2015-06-04 18:14 Denis Kozlov File Added: example-application-on-exception-line-info.zip
2015-06-04 18:28 Andrey Zubarev Note Added: 0084253
2015-06-04 18:29 Andrey Zubarev Note Edited: 0084253 View Revisions
2015-06-04 18:30 Andrey Zubarev Note Edited: 0084253 View Revisions
2015-06-04 22:37 Maxim Ganetsky Note Added: 0084255
2015-06-04 22:37 Maxim Ganetsky Project Lazarus => FPC
2015-06-05 12:44 Denis Kozlov Note Added: 0084262
2015-06-05 13:42 Denis Kozlov File Added: example-console-exception-line-info.zip
2015-06-05 13:45 Denis Kozlov Note Added: 0084263
2015-06-05 13:53 Denis Kozlov Note Edited: 0084263 View Revisions
2015-06-05 14:04 Denis Kozlov Note Edited: 0084263 View Revisions
2015-06-05 15:01 Denis Kozlov Note Edited: 0084263 View Revisions
2015-06-05 15:10 Jonas Maebe Relationship added duplicate of 0013518
2015-06-05 15:10 Jonas Maebe Status new => resolved
2015-06-05 15:10 Jonas Maebe Resolution open => duplicate
2015-06-05 15:10 Jonas Maebe Assigned To => Jonas Maebe