Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-03

SIGSEGV with Debug only

13 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Daniel Simoes de Ameida

Hi All

I have a strange issue...

I'm currently using Lazarus 0.9.31 (update from SVN) with FPC 2.6.0 When I compile my application with debug information, I always get a SIGSEGV when closing one of my forms,on line 4805 of control.inc This Image shows the error.

However, when compiling without debug information, the errors do not occur (better this way) ..

I'm using Debug Info as Auto?(-g) and Display Line numbers (-gl), Heaptrace Unit is also active (-gh)in Debug mode ...

Any hints ?

[]s Daniel

Conhe?a o Projeto ACBr - Automa?ao Comercial Brasil DJSystem a Loja Patrocinadora do ACBr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120329/20089920/attachment-0001.html>

Reply by email

Martin Schreiber
to Daniel Simoes de Ameida
Daniel Simoes de Ameida wrote 18 lines
Hi All I have a strange issue... I'm currently using Lazarus 0.9.31 (update from SVN) with FPC 2.6.0 When I compile my application with debug information, I always get a SIGSEGV when closing one of my forms,on line 4805 of control.inc This Image <http://imagebin.org/205899>shows the error. However, when compiling without debug information, the errors do not occur (better this way) .. I'm using Debug Info as Auto (-g) and Display Line numbers (-gl), Heaptrace Unit is also active (-gh)in Debug mode ... Any hints ?

Heaptrace fills freed memory with garbage. CurAnchorSide probably is in a object which already has been destroyed.

Martin

Reply by email

Daniel Simoes de Ameida
to Martin Schreiber: Heaptrace fills freed memory with garbage. CurAnchorSide probably is in a object which…

Bingo...

Is the HeapTrace.. I just removed HeapTrace Unit from Linking and the problem has gone...

Thanks Martin
?

[]s Daniel

Conhe?a o Projeto ACBr - Automa?ao Comercial Brasil DJSystem a Loja Patrocinadora do ACBr

Show quoted text 38 lines
________________________________ De: Martin Schreiber Para: Enviadas: Sexta-feira, 30 de Mar?o de 2012 5:28 Assunto: Re: [Lazarus] SIGSEGV with Debug only Am 30.03.2012 02:06, schrieb Daniel Simoes de Ameida: > Hi All > > I have a strange issue... > > I'm currently using Lazarus 0.9.31 (update from SVN) with FPC 2.6.0 > > When I compile my application with debug information, I always get a > SIGSEGV when closing one of my forms,on line 4805 of control.inc > This Image <http://imagebin.org/205899>shows the error. > > However, when compiling without debug information, the errors do not > occur (better this way) .. > > I'm using Debug Info as Auto (-g) and Display Line numbers (-gl), > Heaptrace Unit is also active (-gh)in Debug mode ... > > Any hints ? > Heaptrace fills freed memory with garbage. CurAnchorSide probably is in a object which already has been destroyed. Martin -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120330/01017b59/attachment-0001.html>

Reply by email

José Mejuto
to Daniel Simoes de Ameida

Hello Lazarus-List,

Friday, March 30, 2012, 5:11:07 PM, you wrote:

DSdA> Bingo...
DSdA> Is the HeapTrace.. I just removed HeapTrace Unit from DSdA> Linking and the problem has gone...

Removing heaptrace hide the error not fix the bug. The heaptrace is showing you a bug that otherwise you will not be aware of it in most situations like:

var
 a: TSomething;
begin
 a:=TSomething.Create;
 a.Method;
 a.Free;
 a.Method; //This is a bug that will be showed by heaptrace.
end;
Best regards, Jos?

Reply by email

Martin
to Daniel Simoes de Ameida: Bingo... Is the HeapTrace.. I just removed HeapTrace Unit from Linking and the problem…
Daniel Simoes de Ameida wrote
Bingo... Is the HeapTrace.. I just removed HeapTrace Unit from Linking and the problem has gone...

No it has not gone.

It is only hidden. That means you lowered the likelihood of it happening.

The code still accesses an object that does not exist. That means random memory.
Without heaptrc, you simple got better likelihood, that this random memory contains data, that does not cause a crash. But the bug is still there. It may still crash...

Since it happens at form close, maybe you freed some component in your code? Changed owner of a component (moving to other form)? -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120330/80e853ba/attachment.html>

Reply by email

Daniel Simoes de Ameida
to Martin

Martin,

I use a Tab Style interface... (TDI)... so, I change the Owner/Parent in this function:

procedure TFormDJ_Main.ShowFormInPage(const AForm : TForm ;
? const ImageIndex : Integer) ;
var
?? APage?? : TFormPage ;
begin
? nbForms.Visible??? := True ;??? { Shows NoteBook }
? FecharAba1.Enabled := True ;??? { Habilita Op?o no Menu Principal }
{$IFDEF MSWINDOWS}
? btFechaAba.Visible := True ;??? { Shows Close Buttom on TopRight }
{$ENDIF}
? //Create a new Page
? APage??????????? := TFormPage.Create(nbForms) ;? // This will call TFormPage.SetAForm
? APage.ImageIndex := ImageIndex;
? APage.AForm????? := AForm;
? //activate the Page
? nbForms.ActivePage := APage;
end;
procedure TFormPage.SetAForm(const AValue : TForm) ;
begin
? fsAForm := AValue ;
? Caption := fsAForm.Caption;
? Color?? := fsAForm.Color;
? fsAForm.BorderStyle := bsNone ;??????
? fsAForm.Align?????? := alClient ;?
? // Change? Aform Owner and Parent
? fsAForm.Parent := Self;
? ChangeOwner(fsAForm, Self);
? //? AForm.FreeNotification(APage);
? fsAForm.Visible := True ;
end;

Thanks for your help

[]s Daniel

Conhe?a o Projeto ACBr - Automa?ao Comercial Brasil DJSystem a Loja Patrocinadora do ACBr

Show quoted text 11 lines
________________________________ De: Martin Para: Daniel Simoes de Ameida ; Lazarus mailing list Enviadas: Sexta-feira, 30 de Mar?o de 2012 12:55 Assunto: Re: [Lazarus] SIGSEGV with Debug only On 30/03/2012 16:11, Daniel Simoes de Ameida wrote: Bingo... > >Is the HeapTrace.. I just removed HeapTrace Unit from Linking

and the problem has gone...

> No it has not gone. It is only hidden. That means you lowered the likelihood of it

happening.

The code still accesses an object that does not exist. That means

random memory.

Without heaptrc, you simple got better likelihood, that this random

memory contains data, that does not cause a crash.

But the bug is still there. It may still crash... Since it happens at form close, maybe you freed some component in

your code?

Changed owner of a component (moving to other form)?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120330/495e4e61/attachment.html>

Reply by email

Martin
to Daniel Simoes de Ameida
Daniel Simoes de Ameida wrote 6 lines
Martin, I use a Tab Style interface <http://blog.djsystem.com.br/>... (TDI)... so, I change the Owner/Parent in this function:

....

APage := TFormPage.Create(nbForms) ; // This will call TFormPage.SetAForm

....

Show quoted text 16 lines
procedure TFormPage.SetAForm(const AValue : TForm) ; begin fsAForm := AValue ; Caption := fsAForm.Caption; Color := fsAForm.Color; fsAForm.BorderStyle := bsNone ; fsAForm.Align := alClient ; // Change Aform Owner and Parent fsAForm.Parent := Self; ChangeOwner(fsAForm, Self); // AForm.FreeNotification(APage);

I can't tell you 100% certain if this is related, but there is a chance it is to do with http://bugs.freepascal.org/view.php?id=21458

Setting the Owner of a component, does call Notify with opRemove and that breaks the FreeNotification system.

Whenever the LCL sets a component to know about another it uses FreeNotification. So if one of the 2 is destroyed, the other one is informed and wiss not attempt to access the destroyed component.

That also happens for anchors(since the 2 anchored components know about each other, they need to know, if one is destroyed)

Due to the bug I mentioned, if you chang the owner, those notifications may no longer work. Depending on the order of calls and who knows whom, that can cause such a crash.

Do you need to change the owner, or can you live with changing the parent only?

The parent should be enough for displaying it.

One of the things the owner will do, is clean up: if the owner is destroyed, so is the owned component.
Maybe you can own things by the application?

      APage            := TFormPage.Create(Application) ;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120330/c7f46094/attachment.html>

Reply by email

Daniel Simoes de Ameida
to Martin

Martin,

Even doesn't changing the Owner, the problem still..

O forgot to mention the content of ChangeOwner function

?procedure ChangeOwner(AComponente, NewOwner: TComponent);
?begin
??? AComponente.Owner.RemoveComponent(AComponente);
??? NewOwner.InsertComponent(AComponente);
?end;

I suppose this function will handle all Notification changes, isn't ?

?
[]s Daniel

Conhe?a o Projeto ACBr - Automa?ao Comercial Brasil DJSystem a Loja Patrocinadora do ACBr

Show quoted text 16 lines
________________________________ De: Martin Para: Daniel Simoes de Ameida ; Lazarus mailing list Enviadas: Sexta-feira, 30 de Mar?o de 2012 13:49 Assunto: Re: [Lazarus] SIGSEGV with Debug only On 30/03/2012 17:14, Daniel Simoes de Ameida wrote: > >Martin, > > >I use a Tab Style interface... (TDI)... so, I change the Owner/Parent in this function: > >

....

? APage??????????? := TFormPage.Create(nbForms) ;? // This will call TFormPage.SetAForm >

....

Show quoted text 22 lines
> > > >procedure TFormPage.SetAForm(const AValue : TForm) ; >begin >? fsAForm := AValue ; > >? Caption := fsAForm.Caption; >? Color?? := fsAForm.Color; > >? fsAForm.BorderStyle := bsNone ;?????? >? fsAForm.Align?????? := alClient ;? > >? // Change? Aform Owner and Parent >? fsAForm.Parent := Self; >? ChangeOwner(fsAForm, Self); >? //? AForm.FreeNotification(APage); > I can't tell you 100% certain if this is related, but there is a

chance it is to do with? http://bugs.freepascal.org/view.php?id=21458

Setting the Owner of a component, does call Notify with opRemove?

and that breaks the FreeNotification system.

Whenever the LCL sets a component to know about another it uses

FreeNotification. So if one of the 2 is destroyed, the other one is informed and wiss not attempt to access the destroyed component.

That also happens for anchors(since the 2 anchored components know

about each other, they need to know, if one is destroyed)

Due to the bug I mentioned, if you chang the owner, those

notifications may no longer work. Depending on the order of calls and who knows whom, that can cause such a crash.

Do you need to change the owner, or can you live with changing the

parent only?

The parent should be enough for displaying it. One of the things the owner will do, is clean up: if the owner is

destroyed, so is the owned component.

Show quoted text 7 lines
Maybe you can own things by the application? ?? ? APage??????????? := TFormPage.Create(Application) ;?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120330/af5f3c09/attachment.html>

Reply by email

Martin
to Daniel Simoes de Ameida
Daniel Simoes de Ameida wrote 14 lines
Martin, Even doesn't changing the Owner, the problem still.. O forgot to mention the content of ChangeOwner function procedure ChangeOwner(AComponente, NewOwner: TComponent); begin AComponente.Owner.RemoveComponent(AComponente); NewOwner.InsertComponent(AComponente); end; I suppose this function will handle all Notification changes, isn't ?

That is not that easy to answer. That depends on who owns what... Maybe even which classes are involved. To answer that I would have to read through some of the RTL/LCL rcode myself.
It is not even sure that the bug is related to this. Though with the bug in place, I would avoid changing owners. It is possible with workarounds, but I can't foresee all the pitfalls.

I had a quick look at the LCL code. Anchors to not seem to use FreeNotify

When the app crashes, use the debugger, open the stack and make sure the frame selected is pointing to the source you posted (it may already be) Then evaluate self and/or self.fname to see which components refers to the missing anchor.
That should help you find out which control the anchor pointed to.

Maybe that holds some clue.

Then you can debug again, and set breakpoints (in TControl.Destroy / wit condition on FName), and trying to find when the other control gets destroyed (if that is the problem, there are other possibilities...)

Sorry this answer may appear a bit vague. But tracking that kind of issue can be very hard.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120330/2e81277e/attachment-0001.html>

Reply by email

waldo kitty
to Martin Schreiber: Heaptrace fills freed memory with garbage. CurAnchorSide probably is in a object which…
Martin Schreiber wrote 8 lines
Am 30.03.2012 02:06, schrieb Daniel Simoes de Ameida: > I'm using Debug Info as Auto (-g) and Display Line numbers (-gl), > Heaptrace Unit is also active (-gh)in Debug mode ... > > Any hints ? > Heaptrace fills freed memory with garbage. CurAnchorSide probably is in a object which already has been destroyed.

ewww :( in my ancient mind, it would be better to fill with null for possible checks but then again ;) :P

Reply by email

Martin Schreiber
to waldo kitty
waldo kitty wrote 14 lines
On 3/30/2012 04:28, Martin Schreiber wrote: > Am 30.03.2012 02:06, schrieb Daniel Simoes de Ameida: >> I'm using Debug Info as Auto (-g) and Display Line numbers (-gl), >> Heaptrace Unit is also active (-gh)in Debug mode ... >> >> Any hints ? >> > Heaptrace fills freed memory with garbage. CurAnchorSide probably is > in a object > which already has been destroyed. ewww :( in my ancient mind, it would be better to fill with null for possible checks but then again ;) :P

Actually it is $F0. The purpose is that $F0F0F0F0 as pointer should throw a SIGSEGV. Another heaptrace signature is $DEADBEEF. If you see this address in a pointer of your data structs there probably is something wrong. ;-)

Martin Schreiber

Reply by email

Ludo Brands
to Martin Schreiber
Show quoted text 9 lines
> ewww :( in my ancient mind, it would be better to fill with null for > possible checks but then again ;) :P > Actually it is $F0. The purpose is that $F0F0F0F0 as pointer should throw a SIGSEGV. Another heaptrace signature is $DEADBEEF. If you see this address in a pointer of your data structs there probably is something wrong. ;-)

Another common one is $BAADF00D used by MS to indicate uninitialised memory.

Ludo

Reply by email