Sign in Join

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

Mailing lists / lazarus / 2012-01

Help debugging

16 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Kjow

Hi all,

I have a "random" crash that I can't debug on my program.

I have a class that contains some other classes, variables, etc. On some point of execution the program creates the object class and in an other point it frees this object.

I need to do this some times in the "timeline", e.g.:

On class:
"
procedure TBody.InitOtherThings;
...
obj2:= TSomeThing.create(nil);
obj2.moveto(obj1);
...
var2:= var1;
...
"

On "timeline":
"
...
body:= TBody.create;
body.obj1:= Form1.obj1; //I need something like this body.var1:= 123;
body.InitOtherThings;
...
"

On "timeline+2":
"
...
if assigned(body) Then
body.free;
"

On "timeline+3":
"
...
body:= TBody.create;
body.obj1:= Form1.obj1; //I need something like this body.var1:= 123;
body.InitOtherThings;
...
"

On "timeline+4":
"
...
if assigned(body) Then
body.free;
"

Of course, I'm sorry about this example... I wrote it as stupid example, without copy anything of original code (too complex).

Anyway, everything works right, but after sometimes I create/free, I get a "SYSTEM_TOBJECT_$_FREE (18)" error, but I can't get the row in my source code where the error is generated. In attachment the window with the error.

Thank you in advance.
Kjow

PS generally the crash happens after the third time I free the object. (Sometime it never happens)

Reply by email

Antonio Fortuny
to Kjow: I have a "random" crash that I can't debug on my program. I have a class that contains…

Le 11/01/2012 16:01, Kjow a ?crit :

Show quoted text 35 lines
Hi all, I have a "random" crash that I can't debug on my program. I have a class that contains some other classes, variables, etc. On some point of execution the program creates the object class and in an other point it frees this object. I need to do this some times in the "timeline", e.g.: On class: " procedure TBody.InitOtherThings; ... obj2:= TSomeThing.create(nil); obj2.moveto(obj1); ... var2:= var1; ... " On "timeline": " ... body:= TBody.create; body.obj1:= Form1.obj1; //I need something like this body.var1:= 123; body.InitOtherThings; ... " On "timeline+2": " ... if assigned(body) Then

instead of

  body.free;

do
FreeAndNil(body)

!! without this, the pointer to the object still contains the original pointer value.>:o
Do the same for other creations.
Common issue when reusing object pointers

Show quoted text 40 lines
" On "timeline+3": " ... body:= TBody.create; body.obj1:= Form1.obj1; //I need something like this body.var1:= 123; body.InitOtherThings; ... " On "timeline+4": " ... if assigned(body) Then body.free; " Of course, I'm sorry about this example... I wrote it as stupid example, without copy anything of original code (too complex). Anyway, everything works right, but after sometimes I create/free, I get a "SYSTEM_TOBJECT_$_FREE (18)" error, but I can't get the row in my source code where the error is generated. In attachment the window with the error. Thank you in advance. Kjow PS generally the crash happens after the third time I free the object. (Sometime it never happens) -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Kjow
to Antonio Fortuny: Le 11/01/2012 16:01, Kjow a ?crit : instead of body.free; do FreeAndNil(body) !! without…

2012/1/11 Antonio Fortuny :

Show quoted text 9 lines
instead of ?body.free; do ?FreeAndNil(body) !! without this, the pointer to the object still contains the original pointer value.>:o Do the same for other creations. Common issue when reusing object pointers

Thank you!

Well, now after the third time i get this error:
<<The debugger experienced an unknow condition. [...] Exception: EListError.with message "Duplicate ID: FFFFFFFFFFFFFF61" Abort / Ignore>>

Ummm...

Kjow

Reply by email

Kjow
to Martin: Chek your debugger is set up. Also make sure our project is compiled with debug info…

2012/1/11 Martin :

Show quoted text 7 lines
Chek your debugger is set up. Also make sure our project is compiled with debug info http://wiki.lazarus.freepascal.org/Debugger_Setup Then open the stack widow: Menu "View" > "Debug windows"

I already have gbd in "Debugger" (and generally it tells me where is the problem, but not with this error...)
BTW, in "options" i only have "OverrideRTLCallingConvention -> ccDefault"

Kjow

Reply by email

Antonio Fortuny
to Kjow: 2012/1/11 Antonio Fortuny : Thank you! Well, now after the third time i get this error:…

Le 11/01/2012 16:31, Kjow a ?crit :

Show quoted text 16 lines
2012/1/11 Antonio Fortuny: > instead of > body.free; > do > FreeAndNil(body) > > !! without this, the pointer to the object still contains the original > pointer value.>:o > Do the same for other creations. > Common issue when reusing object pointers Thank you! Well, now after the third time i get this error: <<The debugger experienced an unknow condition. [...] Exception: EListError.with message "Duplicate ID: FFFFFFFFFFFFFF61" Abort / Ignore>>

Because gdb does not help in this case neither you could maybe setup some kind of output debug lines so we can focus on the line(s) which apper to disturb the debugger.

Show quoted text 11 lines
Ummm... Kjow -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Martin
to Kjow: 2012/1/11 Martin : I already have gbd in "Debugger" (and generally it tells me where is…
Kjow wrote 10 lines
2012/1/11 Martin: > Chek your debugger is set up. > > Also make sure our project is compiled with debug info > > http://wiki.lazarus.freepascal.org/Debugger_Setup > > Then open the stack widow: Menu "View"> "Debug windows" I already have gbd in "Debugger" (and generally it tells me where is the problem, but not with this error...)

This is a diff case.

which lazarus version?

Also "debug output" window, please.
http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Reporting_Bugs

BTW, in "options" i only have "OverrideRTLCallingConvention -> ccDefault"

Normally you do not need to change those, so leave those settings.

Reply by email

Kjow
to Martin

2012/1/11 Martin :

This is a diff case. which lazarus version?

Laz: 0.9.30.3 r34706M
FPC 2.4.5
(both, via svn, every mornings)

*stopped,reason="signal-received",signal-name="SIGSEGV",signal-meaning="Segmentation fault",thread-id="1",frame={addr="0x0040beef",func="SYSTEM_TOBJECT_$__FREE",args=[]} (gdb)
<info program>
&"info program\n"
~"\tUsing the running image of child thread 5020.0x1d4c.\n" ~"Program stopped at 0x40beef.\n"
~"It stopped with signal SIGSEGV, Segmentation fault.\n" ~"Type \"info stack\" or \"info registers\" for more information.\n" ^done
(gdb)
<-data-disassemble -s 4243140 -e 4243141 -- 0>
...
[cut]
...
(gdb)
<-stack-info-depth>
^done,depth="12"
(gdb)

Normally you do not need to change those, so leave those settings.

ok!

Kjow

Reply by email

Martin
to Kjow

That is for the unknown situation?

We are looking at 2 things now:
- "dbg unknown state" (needs that info) / and start IDE with --debug-log=C:\laz.log
- your app's crash

Does your app use threads?

Kjow wrote 14 lines
2012/1/11 Martin: > This is a diff case. > > which lazarus version? Laz: 0.9.30.3 r34706M FPC 2.4.5 (both, via svn, every mornings) > Also "debug output" window, please. > http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Reporting_Bugs (gdb) <-stack-info-depth> ^done,depth="12" (gdb)

nothing after that? strange, it should try to get the stack content

Reply by email

Kjow
to Martin

2012/1/11 Martin :

Show quoted text 6 lines
That is for the unknown situation? We are looking at 2 things now: - "dbg unknown state" (needs that info) / and start IDE with --debug-log=C:\laz.log - your app's crash

in attachment laz.log

Does your app use threads?

yes, through GLScene.

nothing after that? strange, it should try to get the stack content

Pressing "run" two times again:

...
(gdb)
<-stack-info-depth>
^done,depth="12"
(gdb)
<-exec-continue>
^running
(gdb)
*stopped,reason="exited",exit-code="030000000005"
(gdb)
<-break-delete 7>
^done
(gdb)
<-break-delete 8>
^done
(gdb)
<-break-delete 9>
^done
(gdb)
<-file-exec-and-symbols >
^done
(gdb)

___
Kjow
-------------- next part --------------
A non-text attachment was scrubbed...
Name: laz.log
Type: application/octet-stream
Size: 23704 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120111/db22c689/attachment-0001.obj>

Reply by email

Kjow
to Martin: That is for the unknown situation? We are looking at 2 things now: - "dbg unknown state"…

2012/1/11 Martin :

- your app's crash

Maybe I found the problem!

I freed the object in two different places, one with "body.destroy" (this was just a test that I lost in time... )
Using the only one I need, the problem seems to fixed.

This was a misprint... a test that I forgot to remove...

I'm sorry about time waste and Thank You very much for help. I appreciate it!

Best Regards,
Kjow

Reply by email

Martin
to Kjow
Kjow wrote 12 lines
2012/1/11 Martin: > - your app's crash Maybe I found the problem! I freed the object in two different places, one with "body.destroy" (this was just a test that I lost in time... ) Using the only one I need, the problem seems to fixed. This was a misprint... a test that I forgot to remove... I'm sorry about time waste and Thank You very much for help. I appreciate it!

No problem

still strange you did not get a stack.
----

1) If you get the "Ooops debugger entered error state". Then the log file (if you do have it for that run) may be helpful. But don't worry to much, it may well be fixed in trunc (0.9.31) already, since lot's has changed

2) threads
0.9.31 has a thread list for the debugger
but you need to decide for yourself, if it is worth the upgrade ....

according to one of your logs, you did crash in the main thread, so it would not have made a difference.

Reply by email

Kjow
to Martin

2012/1/11 Martin :

Show quoted text 17 lines
No problem still strange you did not get a stack. ---- 1) If you get the "Ooops debugger entered error state". Then the log file (if you do have it for that run) may be helpful. But don't worry to much, it may well be fixed in trunc (0.9.31) already, since lot's has changed 2) threads 0.9.31 has a thread list for the debugger but you need to decide for yourself, if it is worth the upgrade .... according to one of your logs, you did crash in the main thread, so it would not have made a difference.

Thanks for all,

about threads: your question (if my program is multithread) turned on a light bulb over my head, the problem was that I freed the same object in two different threads... (main thread and "cadencer") and I think that it should behave something like:

"
if assigned(MyObj) Then
  begin
    freeandnil(MyObj);
    MyObj.Destroy;
  end;
"

instead of:

"
if assigned(MyObj) Then
  freeandnil(MyObj);
if assigned(MyObj) Then
  MyObj.Destroy; //of course this was wrong anyway.
"

Best Regards,
Kjow

Reply by email

Martin
to Kjow
Kjow wrote 12 lines
about threads: your question (if my program is multithread) turned on a light bulb over my head, the problem was that I freed the same object in two different threads... (main thread and "cadencer") and I think that it should behave something like: " if assigned(MyObj) Then begin freeandnil(MyObj); MyObj.Destroy; end; "

The above will free it twice => always crash.

Show quoted text 11 lines
instead of: " if assigned(MyObj) Then freeandnil(MyObj); if assigned(MyObj) Then MyObj.Destroy; //of course this was wrong anyway. "

accessing a variable like that, requires a critical section. Or any other kind of lock ...

also no other thread must be inside any method of this object, as then "self" is a local copy of the pointer (self does not get nil, but yet the object will be gone)

same for any other local copy....

Reply by email