Recent

Author Topic: Lazarus crash trying this simple code  (Read 1023 times)

kaedusoft

  • New Member
  • *
  • Posts: 12
Lazarus crash trying this simple code
« on: February 16, 2023, 09:56:18 pm »
This simple code makes Lazarus Debugger crash:
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. function readNumber(): boolean;
  4. var
  5.   c: char;
  6.   text: string[60];
  7.  
  8. begin
  9.   write('Type a value: ');
  10.   readln(text);
  11.   if text= '' then begin
  12.       result:= false;
  13.       exit;
  14.    end;
  15.  
  16.    for c in text do begin
  17.      if (c < '0') or (c > '9') then begin
  18.        result:= false;
  19.        exit;
  20.      end;
  21.    end;
  22.    result:= true;
  23. end;
  24.  
  25. begin
  26.    while not readNumber() do begin
  27.       write('ERROR: ');
  28.    end;
  29.  
  30.    readln;
  31.  
  32. end.  

I attach a screencapture.
The code compiles well and the exe file runs correctly.

This is a 64 bits Lazarus version on Win10 64 bits.
I don't know what is the problem.
« Last Edit: February 16, 2023, 09:59:35 pm by kaedusoft »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus crash trying this simple code
« Reply #1 on: February 16, 2023, 10:29:44 pm »
The error message means the debugger has problems to start up.
There are various reasons why that may be...

But before that, Lazarus comes with 2 debuggers:
- the older gdb based (that you are using)
- the newer "FpDebug", that you could set in menu: Tools > Options: Debugger > Debugger Backend

Anyway with the gdb based debugger
1) In Project > Project Options: check under Compiler > Debug, that you have "generate debug info" enabled, and set to "dwarf 2 with sets"
   When using GDB, do not use "Dwarf 3"
2) Have you saved the project? Does the full path (all containing folders/dirs and the project name) contain spaces or chars other than a-z,0-9,_ ? GDB can get confused.

If you need gdb, then you can also try to download an alternative version of gdb
https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Alternative%20GDB/
Unfortunately there is no single good gdb. Each can have diff issues, or work real good.


In any case, most likely you will be best off if you switch to FpDebug (and then you can use Dwarf3, but other Dwarf are fine too)

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: Lazarus crash trying this simple code
« Reply #2 on: February 16, 2023, 10:32:21 pm »
This simple code makes Lazarus Debugger crash: <snip, the code seems fine>

I attach a screencapture.
The code compiles well and the exe file runs correctly.

This is a 64 bits Lazarus version on Win10 64 bits.
I don't know what is the problem.

Are you able to debug other programs in Lazarus with GDB? I executed all paths of your program (not in GDB), including lines < 60 characters and lines > 60 characters (they get clipped at 60), it seems fine.

kaedusoft

  • New Member
  • *
  • Posts: 12
Re: Lazarus crash trying this simple code
« Reply #3 on: February 16, 2023, 10:40:46 pm »
The error message means the debugger has problems to start up.
There are various reasons why that may be...

But before that, Lazarus comes with 2 debuggers:
- the older gdb based (that you are using)
- the newer "FpDebug", that you could set in menu: Tools > Options: Debugger > Debugger Backend

Anyway with the gdb based debugger
1) In Project > Project Options: check under Compiler > Debug, that you have "generate debug info" enabled, and set to "dwarf 2 with sets"
   When using GDB, do not use "Dwarf 3"
2) Have you saved the project? Does the full path (all containing folders/dirs and the project name) contain spaces or chars other than a-z,0-9,_ ? GDB can get confused.

If you need gdb, then you can also try to download an alternative version of gdb
https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Alternative%20GDB/
Unfortunately there is no single good gdb. Each can have diff issues, or work real good.


In any case, most likely you will be best off if you switch to FpDebug (and then you can use Dwarf3, but other Dwarf are fine too)

Thanks, I changed to fpDebug and works fine.

 

TinyPortal © 2005-2018