Recent

Author Topic: How to find "Range check error" quickly?  (Read 6297 times)

stephanweber

  • New Member
  • *
  • Posts: 46
How to find "Range check error" quickly?
« on: June 24, 2019, 12:37:47 pm »
Hi,

in my Lazarus project I get this runtime error, because I have this check active in my proj options (-Cr). I have also set "Show debug info (-vd).


However, how can I also get the code line in which this error happens, best wo. debugger. This is because currently I have not yet a debugger installed, and installations are always a bit difficult in my current Linux setup.
In Delphi I remember something like "goto error" or "find error".

Also with "Show line numbers" or "Show all procs on error" I get no more hints. The program recovers, because the error pops only up if I make an integer variable larger than 32K. But also changing the suspious variables to Int64 does not help.

Bye Stephan

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: How to find "Range check error" quickly?
« Reply #1 on: June 24, 2019, 12:52:37 pm »
If you know where is the line (say #num26) that throws this exception, one method might be to frame it like that, with a "defensive Exception management", just long enough to understand and correct you bug:

Code: Pascal  [Select][+][-]
  1. Try
  2.   your-buggy-line #num26 of code, here
  3. Except
  4.   on E: EOutOfRange do Application.processmessages; (* <-- you set a breakpoint there, and you'll inspect your numerical variables, i, strings[j], ...,
  5. which are used by your line #num26, and understand the one that exceeds its boundary.
  6. Once the bug will be fixed, you'll delete the try...except *)
  7. end;
« Last Edit: June 24, 2019, 12:56:11 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: How to find "Range check error" quickly?
« Reply #2 on: June 24, 2019, 01:10:20 pm »
-vd will not help at all

You should include "debugger info" (preferably of type "dwarf"):  -gw

You can add  -gl 
then when your running executable hits the error, it should print a stacktrace with line numbers.
(Run your app from a console, so you see the output / or try the "view" > "debug windows" > "console output")


I am not sure what your problem is to install a debugger. GDB is usually easily available for linux.

If your system is intel/amd based, then install the package LazDebuggerFp.
This gives you a debugger that does NOT need gdb.

stephanweber

  • New Member
  • *
  • Posts: 46
Re: How to find "Range check error" quickly?
« Reply #3 on: June 25, 2019, 03:13:38 pm »
Thanks. I found the problem with some statements like "Showmessage('here we are: begin of blablabla');"
Now I have to find an infinite loop, which seems to be triggered randomly (there is indeed a random number generation involved).

Bye Stephan

Thaddy

  • Hero Member
  • *****
  • Posts: 14215
  • Probably until I exterminate Putin.
Re: How to find "Range check error" quickly?
« Reply #4 on: June 26, 2019, 10:12:38 am »
If your two issues are related (as they seem to me) use RandomFrom or RandomRange instead of system.Random.
Also, precisely define define a range as type ( e.g. type myrange i= 3..9 ). That combination will prevent you from making range errors at run-time.
See: defensive programming in the wiki. https://wiki.freepascal.org/Defensive_programming_techniques

(reminder to self: upload the rest, finally, lazy b*sta*rd)
« Last Edit: June 26, 2019, 11:57:14 am by Thaddy »
Specialize a type, not a var.

stephanweber

  • New Member
  • *
  • Posts: 46
Re: How to find "Range check error" quickly?
« Reply #5 on: June 27, 2019, 02:16:32 pm »
This was very helpful now:

you should include "debugger info" (preferably of type "dwarf"):  -gw

You can add  -gl 
then when your running executable hits the error, it should print a stacktrace with line numbers.
Run your app from a console!!!

Thanks a lot!!

 

TinyPortal © 2005-2018