Lazarus

Programming => General => Topic started by: Milsa on September 27, 2020, 10:36:17 pm

Title: My application crashes without any reason
Post by: Milsa on September 27, 2020, 10:36:17 pm
Problem code is in filesthreadclass.pas in lines 52-71.
Press Find in application and it will crash.
Remove these lines and application is without problem.
Where is the problem?
Title: Re: My application crashes without any reason
Post by: Blaazen on September 27, 2020, 10:57:28 pm
Are you on Linux? Threads were not enabled. I added
Code: Pascal  [Select][+][-]
  1. {$define UseCThreads}
to deduplicator.lpr and pressing Find does not crash app but opens some grids.
Title: Re: My application crashes without any reason
Post by: Milsa on September 27, 2020, 11:17:59 pm
Windows 10 64-bit 19041
Title: Re: My application crashes without any reason
Post by: Milsa on September 27, 2020, 11:22:09 pm
Application does not crash to system. It shows any error without any line in stack dump.

Sometimes application works correctly (in 10 % cases).
Title: Re: My application crashes without any reason
Post by: trev on September 28, 2020, 03:36:26 am
Your application does not "crash" at all! You might like to fix your post title.

You have a "list index out of bounds" run-time error. This means that there is something wrong with your code - specifically you have tried to access a list index of 6 which is bigger than you allow for in your list.
Title: Re: My application crashes without any reason
Post by: Martin_fr on September 28, 2020, 04:09:41 am
Check the Stack window: Menu > View > Debug Windows > Callstack

If there are no line numbers there, then your project is not setup for debugging: https://wiki.lazarus.freepascal.org/Debugger_Setup

Follow the steps for the setup, and when you press "break" on the error, the IDE should take you to the error line. (Though sometimes, you need to use the stack window, and try the top 3 or 4 entries)

See, if that gives you some more info.


I did a quick run with this. And it gives me an error line (though I needed to go down a few entries in the stack).

procedure TFormMain.TimerShowTimer(Sender: TObject);
....
    begin
      StatusBar.Panels[6].Text := '2/2: ' + IntToStr(AppData.CountSort);
    end;
Title: Re: My application crashes without any reason
Post by: Milsa on September 28, 2020, 08:35:17 am
I change optimization by your instructions to 0 (I had 1 - debugger friendly).
I do not understand why I have this call stack always.
How did you find the error line?
Title: Re: My application crashes without any reason
Post by: jamie on September 28, 2020, 01:27:45 pm
Are u removing items from the list in the main thread while this thread is looping through the list?

Using the for loop control can lead to issues where as once the loop counter is set in range it assumes the reference source is constant, not being depupulated in the loop.

U may need to use a critical section to stop this action in the main thread
Title: Re: My application crashes without any reason
Post by: rvk on September 28, 2020, 01:42:45 pm
There are several places in your code like this:
Code: Pascal  [Select][+][-]
  1. for i := 0 to AppConfig.BlockList.Count - 1 do
Now guess what happens when AppConfig.BlockList.Count  is zero?
 :o
Nothing, because for := 0 to -1 won't even go into the for-loop.
(you should know that)
Title: Re: My application crashes without any reason
Post by: Martin_fr on September 28, 2020, 02:21:17 pm
I change optimization by your instructions to 0 (I had 1 - debugger friendly).
I do not understand why I have this call stack always.
How did you find the error line?

How did you install Lazarus/FPC?

The stack you posted shows an error in TFpList, which can be part of TList. (That matches the index out of bound)
It is normal that for such an error, the actual exception happens in either FPC or LCL (or other supplied) code.
Also there may be other packages (LCL) between that TFpList, and your code. Then that package could also be the culprit.

It is possible that your fpc is build with optimization. That can in some cases prevent the stack to be completely shown.

-----------------
You have seen my last post, and that I got an error accessing status panel index 6 (the 7th panel, but there are only 6).
Title: Re: My application crashes without any reason
Post by: Milsa on September 28, 2020, 02:27:27 pm
My installation is standard with "secondary" option during installation. I use 32 and 64 bit installation together in other directory and other config directory.
Title: Re: My application crashes without any reason
Post by: Martin_fr on September 28, 2020, 03:15:02 pm
My installation is standard with "secondary" option during installation. I use 32 and 64 bit installation together in other directory and other config directory.

OK. I went to test with the official release myself. Indeed the "GDB" included has a problem in case of that error.

"GDB" => is a standalone debugger. It is used by the Lazarus (and many other open source IDE) as helper to do debugging. But it comes with some flaws....

Anyway, there is a solution. And I tested it, but it takes a few extra steps. Sorry about that.
1) Menu: Tools > Options: Debugger > General.
  There is a drop down, that currently shows "gdb debugger (gdb)" => change it to "FpDebug, internal dwarf debugger (beta)".
2) When running your app, you may be asked to choose a "debug info type". Choose "Dwarf with sets"
   You can choose "Dwarf 3", which is better. But if you ever change back to "gdb" then you must go to project options, and change it to "dwarf with sets"



EDIT: I think FpDebug should be in the list by default. But I may have made changes to my release install of Lazarus.
If it is not there: menu > Packages > Install/Uninstall Packages > and install the package "LazDebuggerFp"
Title: Re: My application crashes without any reason
Post by: Milsa on September 28, 2020, 04:02:42 pm
I have fpdebug. But I set Dwarf3 and I got error after application start:

Debugger error.
Save your work etc.
GDB detected.

More    Stop

I translated it to english from slovak.
Title: Re: My application crashes without any reason
Post by: Martin_fr on September 28, 2020, 05:44:23 pm
I have fpdebug. But I set Dwarf3 and I got error after application start:

Debugger error.
Save your work etc.
GDB detected.

More    Stop

I translated it to english from slovak.

"gdb detected" is an error message by the "gdb debugger".
Please double check the settings under tools > options.

Note there is an "gdb debugger with fpdebug" (though I am not sure that is listed by default. You do NOT want this one.

If the setting is correct (in Tools > Options), restart the IDE.
It should work without the restart, but just in case.

---
The "FpDebug internal dwarf debugger" does not use gdb at all (even though the config still has the field for the path to gdb, but that is ignored).
Title: Re: My application crashes without any reason
Post by: Milsa on September 29, 2020, 09:24:36 pm
These is my options.
Title: Re: My application crashes without any reason
Post by: Martin_fr on September 29, 2020, 09:44:07 pm
Ok, then you need to go to the menu "Package" > "Install/Uninstall Packages..."

On the right side find and select "LazDebuggerFp" and then press "Install Selection". Next "Save and rebuild IDE"
Your IDE should compile and then restart.

Now you should see "FpDebug internal Dwarf debugger"
Title: Re: My application crashes without any reason
Post by: Milsa on September 30, 2020, 10:23:53 pm
Thank you very much.
lazarus has a number of settings that ordinary people have no idea about.
This needs wiki article.

I see an error line now in call stack!

Again, big thanks.

What is dwarf 2 or 3? I set 3.
Does exists situations when is better standard debugger?
Title: Re: My application crashes without any reason
Post by: Zoran on October 01, 2020, 11:48:26 am
This needs wiki article.

Martin have worked on FpDebug a lot recently and improved debugging options in the IDE. So, there are different wiki pages for stable and trunk.
Feel free to improve the wiki.

https://wiki.freepascal.org/Debugger_Status (https://wiki.freepascal.org/Debugger_Status)
https://wiki.freepascal.org/FpDebug (https://wiki.freepascal.org/FpDebug)
https://wiki.freepascal.org/LazDebuggerFp (https://wiki.freepascal.org/LazDebuggerFp)

https://wiki.freepascal.org/Debugger_Setup (https://wiki.freepascal.org/Debugger_Setup)

For trunk see: https://wiki.freepascal.org/IDE_Window:_DebuggerGeneralOptionsFrame (https://wiki.freepascal.org/IDE_Window:_DebuggerGeneralOptionsFrame)
  and https://wiki.freepascal.org/IDE_Window:_DebuggerClassOptionsFrame (https://wiki.freepascal.org/IDE_Window:_DebuggerClassOptionsFrame)

For stable Lazarus (v. 2.0.x): https://wiki.freepascal.org/IDE_Window:_Debugger_Options (https://wiki.freepascal.org/IDE_Window:_Debugger_Options)

Title: Re: My application crashes without any reason
Post by: Martin_fr on October 01, 2020, 12:46:39 pm
What is dwarf 2 or 3? I set 3.
Dwarf 3 is generally better. But gdb does not work well with it. (some gdb do work with it, but still some issues remain / note that the issues may be partly caused by fpc, not gdd)

Quote
Does exists situations when is better standard debugger?
FpDebug will hopefully at some point replace the gdb based debugger (except for certain cross compile targets)

At the moment, FpDebug is not yet feature complete. E.g., it can not modify variables while the app is running.
But FpDebug is way better at showing watches. (gdb will fail with some of them)

See the links in the post above.
FpDebug is very useable already. Quite a few people already use it as default.
TinyPortal © 2005-2018