Recent

Author Topic: [SOLVED]SIGSEGV  (Read 1959 times)

Miflon

  • New Member
  • *
  • Posts: 10
[SOLVED]SIGSEGV
« on: November 19, 2019, 10:54:25 am »
Hi every body.
Windows 10
Lazarus 2.0.6
Dell Inspiron 15 Memory 4 GB
I intalled this new version of Lazarus to query a Postgresql database.
As usual, I dropped PQConnection, SQLQuery, SQLTransaction, DataSource and DBGrid on the form.
Everything goes OK when executed, the DBGrid shows correctly the datas. A left click on the system menu closes the form.
I create a OnClose event on the form and troubles appear. I get an External SIGSEGV in the file unite_alat.pas at line 52.
This corresponds to the line "begin" of the FormClose procedure.
The lines in the stack are :
Code: Pascal  [Select][+][-]
  1. 0 unite_alat.pas 52 FORMCLOSE(0x0,0x0, <error reading variable: Cannot acces memory at address 0x0>)
  2. 1 customform.inc(include\) 959 DOCLOSE(0x107370, CAFREE)
  3. 2 customform.inc(include\) 2196 CLOSE(0x107370)
  4. 3 unite_alat.pas 53 FORMCLOSE(0x107370, 0x107370, CAFREE)
  5. 4 customform.inc(include\) 959 DOCLOSE(0x107370, CAFREE)
  6. 5 customform.inc(include\) 2196 CLOSE(0x107370)
  7. 6 unite_alat.pas 53 FORMCLOSE(0x107370, 0x107370, CAFREE)
  8. 7 customform.inc(include\) 959 DOCLOSE(0x107370, CAFREE)
  9. 8 customform.inc(include\) 2196 CLOSE(0x107370)
  10. 9 unite_alat.pas 53 FORMCLOSE(0x107370, 0x107370, CAFREE)
The incriminated lines in the assembler window are :
Code: Pascal  [Select][+][-]
  1. unite_alat.pas:52                         begin
  2.   000000010002D300 55                       push   %rbp
  3.   000000010002D301 4889e5                   mov    %rsp,%rbp
  4.   000000010002D304 488d6424c0               lea    -0x40(%rsp),%rsp
  5. ->000000010002D309 48894de8                 mov    %rcx,-0x18(%rbp)
  6.   000000010002D30D 488955f84c8945f0         mov    %rdx,-0x8(%rbp)
  7. unite_alat.pas:53
When I execute the program directly from the exe file I get a "Stack overflow Press..." warning.
I would be gratefull if someone could help me, thanks in advance.
Michel
« Last Edit: November 20, 2019, 06:53:02 pm by Miflon »

Handoko

  • Hero Member
  • *****
  • Posts: 5130
  • My goal: build my own game engine using Lazarus
Re: SIGSEGV
« Reply #1 on: November 19, 2019, 11:19:57 am »
Hello Miflon,
Welcome to the forum.

There are lots of things can cause SIGSEGV and Stack Overflow error. When asking question related with the bug in the source code, you should show us the source code.

Can you provide us the source code? If you're not willing to publicize the it, you can write a demo project that can show the issue.

Create a new folder, copy and paste all the necessary files except: the binary (exe file), *.bak, lib and backup folders. Compress the folder and send the zip here.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: SIGSEGV
« Reply #2 on: November 19, 2019, 12:30:34 pm »
I execute the program directly from the exe file I get a "Stack overflow Press..." warning.
Hard to tell what the real problem may be from what you posted.  In addition to Handoko's good suggestion above, I suggest you compile your program with {$S+} or, what is the same, -Ct on the compiler command line.  This tells the compiler to generate stack checking code which might be helpful in this case.

The other suggestion is: determine if any of the parameters passed to FormClose are nil.  What you posted suggests that a nil pointer is being dereferenced (though the assembly code you posted doesn't show that.)

One question: do you have any recursive functions/procedures in your program ?... if yes, they may be the cause of the problem.

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Miflon

  • New Member
  • *
  • Posts: 10
Re: SIGSEGV
« Reply #3 on: November 19, 2019, 02:24:02 pm »
@440bx and Handoko thanks replying.
I use Lazarus out of the box. No change at all in the parameters.
This is my very basic code. All parameters of the componants come from design mode. Left click on the system menu closes the app normally :
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, pqconnection, sqldb, db, Forms, Controls, Graphics,
  9.   Dialogs, DBGrids;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     DataSource1: TDataSource;
  17.     DBGrid1: TDBGrid;
  18.     PQConnection1: TPQConnection;
  19.     SQLQuery1: TSQLQuery;
  20.     SQLTransaction1: TSQLTransaction;
  21.   private
  22.  
  23.   public
  24.  
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. end.
Then I add a onClose event on the form. I only type the word close in procedure obtained by double click on the event tab of the form :
Code: Pascal  [Select][+][-]
  1. TForm1 = class(TForm)
  2.     DataSource1: TDataSource;
  3.     ...
  4.     SQLTransaction1: TSQLTransaction;
  5.     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  6.  
  7. { TForm1 }
  8.  
  9. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  10. begin
  11.   Close;
  12. end;
  13.  
That's all. And then error raise.
Thanks again for your help.


MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: SIGSEGV
« Reply #4 on: November 19, 2019, 03:09:02 pm »
Let me guess: the form gets a close message so invokes the OnClose event, which does a Self.Close triggering the OnClose event...

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: SIGSEGV
« Reply #5 on: November 19, 2019, 03:46:12 pm »
In other words, you create a sort of circular loop of the same event:

         bntOnClick: Form1.Close;  ↓
┌ →    DoClose: if Assigned(FOnClose) Then FOnClose;  ↓
└ ←    OnClose: Self.Close;  // and it goes back for a new pseudo-loop ??!
                             
So, delete the "Close;" from the event;
« Last Edit: November 19, 2019, 03:51:02 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.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: SIGSEGV
« Reply #6 on: November 19, 2019, 04:35:22 pm »
Traditionally paraphrased as "Recursion: see recursion" :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: SIGSEGV
« Reply #7 on: November 19, 2019, 04:40:17 pm »
Yes. In fact, I'm very proud of my little arrows :D .

Btw @Miflon, you should add a button (named Button1) on your TForm with this code (if you want to close the TForm, other than just by clicking on its "cross system button"):

procedure TForm1.Button1Click(Sender: TObject);
begin
  Self.Close;
end;
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: SIGSEGV
« Reply #8 on: November 19, 2019, 07:30:25 pm »
@Miflon,

What @MarkMLI and @devEric69 mentioned sounds quite likely to be the source of the problem.

If you want to verify that is what is happening add
Code: Pascal  [Select][+][-]
  1. Beep(600, 300);
  2. Sleep(200);      // give your ears a break!
at the beginning of your FormClose.  That will cause an audible beep every time the function is called and, normally - no recursion - you should hear only one.

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Miflon

  • New Member
  • *
  • Posts: 10
Re: SIGSEGV
« Reply #9 on: November 19, 2019, 08:20:06 pm »
Thanks to all of you.
It's unforgivable that I did not see the recursion. Problem solved.
Best regards, Michel.
« Last Edit: November 19, 2019, 08:26:06 pm by Miflon »

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: SIGSEGV
« Reply #10 on: November 19, 2019, 08:28:57 pm »
Don't worry, everybody gets caught. What you did was assume that the default action of OnClose was to close the form, and that if you added an explicit handler you had to replicate that yourself.

It doesn't quite work like that, and while the documentation isn't exactly explicit it /does/ indicate that you can change what actually happens by having the handler modify the value of one of its parameters i.e. it doesn't (and shouldn't) try to implement some variant of Close() itself.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018