Recent

Author Topic: Finding source code line from error address  (Read 1225 times)

sporex

  • New Member
  • *
  • Posts: 12
Finding source code line from error address
« on: January 03, 2021, 12:37:00 pm »
Sorry if this has been asked earlier.

I am running a console app under a LINUX OS. (not under the control of Lazarus)
An EConvertError with the corresponding error address occurs.
Code: Pascal  [Select][+][-]
  1. An unhandled exception occurred at $000390C0 :
  2. EConvertError : "2;" is an invalid integer

Is there an IDE function to identify the line in the source code that generates this error?
In Turbo Pascal (long time) this was a very simple affair.

Perhaps you could also tell me whether I need to compile with special debugger settings. (I am compiling with the default build mode)

LAZ version : 1.2.4+dfsg2-1 FPC version : 2.6.4
Thx in advance

PascalDragon

  • Hero Member
  • *****
  • Posts: 3191
  • Compiler Developer
Re: Finding source code line from error address
« Reply #1 on: January 03, 2021, 12:52:34 pm »
You could wrap your main program code like this:

Code: Pascal  [Select][+][-]
  1. begin
  2.   try
  3.     // ...
  4.   except
  5.     on e: Exception do begin
  6.       Writeln('Unhandled exception of type ', e.ClassName, ': ', e.Message);
  7.       DumpExceptionBacktrace(Output);
  8.     end;
  9.   end;
  10. end.

Now if you have compiled with -glw you should see an exception backtrace that should also show the right file and line.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7293
  • Debugger - SynEdit - and more
    • wiki
Re: Finding source code line from error address
« Reply #2 on: January 03, 2021, 01:01:31 pm »
In "Project Options" page debugging, set  "generate debug info" to true, and choose "dwarf with sets"

Then run your code in the debugger (by default F9 does this).

The debugger should show the location of the error. Also check the "stack window" (view > debug windows)

https://wiki.lazarus.freepascal.org/Debugger_Setup

sporex

  • New Member
  • *
  • Posts: 12
Re: Finding source code line from error address
« Reply #3 on: January 03, 2021, 01:06:41 pm »
You could wrap your main program code like this:

Code: Pascal  [Select][+][-]
  1. begin
  2.   try
  3.     // ...
  4.   except
  5.     on e: Exception do begin
  6.       Writeln('Unhandled exception of type ', e.ClassName, ': ', e.Message);
  7.       DumpExceptionBacktrace(Output);
  8.     end;
  9.   end;
  10. end.

Now if you have compiled with -glw you should see an exception backtrace that should also show the right file and line.

Thank you a lot.
If I got you right I can run the modified code without LAZ and get an Exception Dump on the console output with the errored sourc code line?

PascalDragon

  • Hero Member
  • *****
  • Posts: 3191
  • Compiler Developer
Re: Finding source code line from error address
« Reply #4 on: January 03, 2021, 02:36:27 pm »
Thank you a lot.
If I got you right I can run the modified code without LAZ and get an Exception Dump on the console output with the errored sourc code line?

If it works correctly that should indeed be the case then, yes.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7293
  • Debugger - SynEdit - and more
    • wiki
Re: Finding source code line from error address
« Reply #5 on: January 03, 2021, 03:10:42 pm »
If I got you right I can run the modified code without LAZ and get an Exception Dump on the console output with the errored sourc code line?

You should, yes....
Though, IIRC it may not work on Mac cocoa... (not tested lately, just thinking I read it somewhere)

If you want to ship a release, and generate a client-side error report that the client can send back to you, then there is another way. In case you do not want the client to see your unit names. https://forum.lazarus.freepascal.org/index.php/topic,52676.msg388766.html#msg388766

Soner

  • Full Member
  • ***
  • Posts: 240
Re: Finding source code line from error address
« Reply #6 on: January 03, 2021, 03:35:32 pm »
I am using Dump_exception_call_stack from wiki in my application. You get very usefull informations.

sporex

  • New Member
  • *
  • Posts: 12
Re: Finding source code line from error address
« Reply #7 on: January 04, 2021, 01:58:06 pm »
Thank you for all the valuable answers.

Cheers

 

TinyPortal © 2005-2018