Recent

Author Topic: Help on how to debug inherited Destroy;  (Read 401 times)

nadavvin

  • New member
  • *
  • Posts: 23
Help on how to debug inherited Destroy;
« on: November 30, 2018, 07:39:01 pm »
Hello
I am porting Heidisql to lazarus and while until now I could comment code that cause crashing, it now failed on Destroy and the call stack does not display any useful information like where it really happen.

https://imgur.com/Bil0t3Ql.png

A little more info on manul debuging:
I fall on "inherited Destroy;" on the project source. step in lead to:
scrollingwincontrol.inc TScrollingWinControl.Destroy; step in lead to:
TCustomControl.Destroy; step in lead to:
TWinControl.Destroy
TControl.Destroy;
TLCLComponent.Destroy;

Then step in of "inherited Destroy;" of TLCLComponent.Destroy; lead to raised exception
Project heidisql raised exception class 'External: SIGSEGV'.

 At address 42CE65

What can I do?

Thanks

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4938
    • wiki
Re: Help on how to debug inherited Destroy;
« Reply #1 on: November 30, 2018, 08:20:40 pm »
At some time "inherited Destroy" steps into the RTL (part of fpc). This usually has no debug info. You need to compile your own fpc with debug info, if you really need to debug there. (fpupdeluxe can help).

The same applies to fpc_ansistr_*, part of the rtl.

But I doubt that stepping in there will get you closer to your problem.
Crashes in fpc_ansistr_* are 99.999% due to memory corruption, or accessing already free'd objects (including double free).

I suspect, that you may be destroying (or otherwise access) an object, that was already destroyed before. The memory of this object is then filled with whatever random data got there in the meantime, and that can cause any sort of bad effect.

In general, finding such bugs is extremely hard.
If you are an linux, the ultimate tool is "valgrind". But using it requires some background knowlegde.

The first steps that you should do, if you have not yet:
compile with
   -gh -gt

You may want to set the the environment HEAPTRC=keepreleased in Run > Run Parmeter.

When you are in destroy, check the various fields of "self". If they have strange values (55555555 or AAAAAAAA or BAADF00D) then your object was destroyed before. (Even if the values are not the listed ones, check if they make sense)
In that case, you must find where the destroy had happened.

« Last Edit: November 30, 2018, 08:22:11 pm by Martin_fr »

nadavvin

  • New member
  • *
  • Posts: 23
Re: Help on how to debug inherited Destroy;
« Reply #2 on: December 08, 2018, 08:42:30 pm »
Thanks for your replay, since then the project crash on run time in different so I fought it because it lazarus trunv version I use but in the end it was my code...

I try use valgrind and while I can see how many calls there are to each function, I still need to learn how to use it it above it.

I try to compile lazarus and fpc with debugging but I still cannot step in to the fpc sources.

fpc have a DEBUG option but it still contain in the compiling the flags for not debug of -Xs -O2
When I set FPCOPT=" -gh -gt" it add the the compiling but with the -Xs -O2 and the build failed
For example part of the log (not full line):
Code: Pascal  [Select]
  1. /usr/bin/ppcx64 -gh -gt -gl -Ur -Xs -O2 -n -FE. -FUunits/x86_64-linux -Cg -dx86_64 -dDEBUG -dRELEASE -gl -Ur -Xs -O2 -n -FE. -FUunits/x86_64-linux -Cg -dx86_64 -dDEBUG -dRELEASE -gl -Ur -Xs -O2 -n -Fux86_64
  2.  

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4938
    • wiki
Re: Help on how to debug inherited Destroy;
« Reply #3 on: December 08, 2018, 08:50:09 pm »
In the fpc svn checkout do
Code: Pascal  [Select]
  1. make all OPT=" -O- -gw"
  2. make install

you may want to specify where to install, and make sure all dependencies are fulfilled. Google the fpc "buildfaq".

You may prefer building fpc with fpcup deluxe. Search the forum.

In either case, once rebuild, make sure the new ppu are used. Install them, or adapt the fpc.cfg.
Compile your project with -va to see for each ppu where it comes from.

---
Also, maybe the crash happens in FreeInstance. Which is called *after* the destructor finishes. Not sure how normal stepping handles this, but you can use asm stepping.

---
On valgrind the tool you want to use is "memcheck"
Getting function caller info sounds like you used "callgrind"
« Last Edit: December 08, 2018, 08:55:58 pm by Martin_fr »

nadavvin

  • New member
  • *
  • Posts: 23
Re: Help on how to debug inherited Destroy;
« Reply #4 on: December 08, 2018, 09:26:02 pm »
Thanks! and I found where is the double free
« Last Edit: December 08, 2018, 09:28:46 pm by nadavvin »