Recent

Author Topic: Debug - stack trace  (Read 14171 times)

faber

  • Guest
Debug - stack trace
« on: September 03, 2010, 11:25:24 am »
Can someone tell me where can I find some information (to learn) how to read stack trace (exception adresses with out line numbers) ?

Chronos

  • Sr. Member
  • ****
  • Posts: 255
    • PascalClassLibrary
Re: Debug - stack trace
« Reply #1 on: September 03, 2010, 01:32:14 pm »
http://wiki.lazarus.freepascal.org/Logging_exceptions

Not yet complete summary but it would be.

faber

  • Guest
Re: Debug - stack trace
« Reply #2 on: September 03, 2010, 04:49:41 pm »
Wow, really nice!
Thanks for info

faber

  • Guest
Re: Debug - stack trace
« Reply #3 on: September 03, 2010, 06:05:03 pm »
I've last question,
can I get map file with line info ? like:

  Stack trace:
  $00439E86
  $00439E33
  $004D47C4  TCONTROL__CLICK,  line 2251 of ./include/control.inc
  $0050391F  TBUTTONCONTROL__CLICK,  line 62 of ./include/buttoncontrol.inc
  $00503E46  TCUSTOMBUTTON__CLICK,  line 174 of ./include/buttons.inc
  $005043A1  TBUTTON__CLICK,  line 341 of ./include/buttons.inc
...

in other words how to find in what line of my files exception occurred ?

faber

  • Guest
Re: Debug - stack trace
« Reply #4 on: September 03, 2010, 09:52:21 pm »
Ok, I can use gdb for that.

There is a mistake on this wiki page, that code:
Code: [Select]
  for I := 0 to ExceptFrameCount - 1 do
    Report := Report + NewLine + BackTraceStrFunc(Frames);

should look like:

Code: [Select]
  for I := 0 to ExceptFrameCount - 1 do
    Report := Report + NewLine + BackTraceStrFunc(Frames[I]);

Chronos

  • Sr. Member
  • ****
  • Posts: 255
    • PascalClassLibrary
Re: Debug - stack trace
« Reply #5 on: September 04, 2010, 12:04:02 am »
Function for get exception backtrace corrected on wiki.
Added function for dumping current call stack.

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Debug - stack trace
« Reply #6 on: September 06, 2010, 08:12:37 pm »
Sorry, but in the example it would be a good idea to use LineEnding constant intead of creating a new one (NewLine). LineEnding is cross platform.

Chronos

  • Sr. Member
  • ****
  • Posts: 255
    • PascalClassLibrary
Re: Debug - stack trace
« Reply #7 on: September 06, 2010, 09:26:56 pm »
You are welcome to update wiki pages. I have replaced NewLine by LineEnding.
http://wiki.lazarus.freepascal.org/Logging_exceptions


garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Debug - stack trace
« Reply #8 on: September 07, 2010, 06:24:47 pm »
Can you explain how to redefine InitExceptions?

Quote
System ExceptProc

If unhandled exception occurs than ExceptProc procedure variable is executed. Default behavior initialized by procedure InitExceptions in unit System can be redefine to custom handler. As example implementation default procedure CatchUnhandledException can be taken.

Chronos

  • Sr. Member
  • ****
  • Posts: 255
    • PascalClassLibrary
Re: Debug - stack trace
« Reply #9 on: September 07, 2010, 10:24:11 pm »
Simply by assigning custom handler to procedure variable ExceptProc in your program. You have only to ensure that assignment is done after system unit initialization which should be anywhere in events like TCustomApplication.DoRun conosle application run or TForm.OnFormCreate or OnFormShow. Good example is in file application.inc:

Code: [Select]
procedure TApplication.SetCaptureExceptions(const AValue: boolean);
begin
  if FCaptureExceptions=AValue then exit;
  FCaptureExceptions:=AValue;
  if FCaptureExceptions then begin
    // capture exceptions
    // store old exceptproc
    if FOldExceptProc=nil then
      FOldExceptProc:=ExceptProc;
    ExceptProc:=@ExceptionOccurred;
  end else begin
    // do not capture exceptions
    if ExceptProc=@ExceptionOccurred then begin
      // restore old exceptproc
      ExceptProc:=FOldExceptProc;
      FOldExceptProc:=nil;
    end;
  end;
end;   

So you can let InitExceptions do it's job and redefine ExceptProc later.

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Debug - stack trace
« Reply #10 on: September 08, 2010, 09:22:26 pm »
Now I get it!! THANK YOU VERY MUCH!!! it couldn't be clearer.

Now it's time to shed some light in the darkness of misterious errors that never appears when you're watching, and the ones that saw it can't tell you much about it! (they're scared to death. LOL).

 

TinyPortal © 2005-2018