Recent

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

nadavvin

  • New Member
  • *
  • Posts: 28
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: 9792
  • Debugger - SynEdit - and more
    • 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: 28
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: 9792
  • Debugger - SynEdit - and more
    • 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: 28
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 »

nadavvin

  • New Member
  • *
  • Posts: 28
Re: Help on how to debug inherited Destroy;
« Reply #5 on: December 10, 2018, 11:53:17 pm »
Hello

I'm trying to install proper fpc, lazarus so units will take from the right place.

fpcup deluxe failed to do it and it always failed on building fpc on "fpcupdeluxe: Got an unexpected exception ... don't know what to do unfortunately."

I create fpc.cfg and it use it but lazarus failed to compile on:
Code: Pascal  [Select][+][-]
  1. /usr/bin/ld: icocurtypes.pp:(.debug_info+0x334): undefined reference to `DBG_$SYSTEM_$$_LONGWORD'
  2. Error: Error while linking
  3. Fatal: There were 1 errors compiling module, stopping
  4.  
  5.  

My compiling script is:
Code: Pascal  [Select][+][-]
  1. #!/bin/bash
  2. export DEBUG=1
  3. export OPT=" -O- -gw"
  4. export PATH=$HOME/Projects/fpc/usr/bin:$PATH
  5. export PPC_CONFIG_PATH=$HOME/Projects/fpc/usr/bin/
  6. export FPC_DIR=$HOME/Projects/fpc
  7. export PP=$HOME/Projects/fpc/usr/bin/fpc
  8. rm -f $HOME/Projects/fpc/usr/bin/fpc.cfg
  9. cp $HOME/Projects/fpc.cfg $HOME/Projects/fpc/usr/bin/
  10. cd $HOME/Projects/lazarus
  11. svn up --accept theirs-full
  12. svn cleanup --remove-unversioned --remove-ignored
  13. svn status|grep '^M'|cut -d ' ' -f 8|xargs svn revert
  14. make clean all bigidecomponents FPC_DIR=$HOME/Projects/fpc PP=$HOME/Projects/fpc/usr/bin/fpc
  15. rm -rf ~/.lazarus2
  16. ./lazarus --pcp=~/.lazarus2 --setup
  17.  
« Last Edit: December 11, 2018, 07:27:45 am by nadavvin »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Help on how to debug inherited Destroy;
« Reply #6 on: December 11, 2018, 12:17:55 am »
Just a few hints...

1) Under linux, *every* fpc install will look at /etc/fcp.cfg
So if you have that, it will be used.
There may be further locations, that are used by more than one fpc

2) look at the output generated, when compiling with -va
You will see every path that is searched. So you can find what goes wrong.

This will also tell you where you can place your fpc.cfg

3) buildfaq.pdf

4) If you do not want to set the path, and fpc cannot find the correct ppc, then configure the IDE to call ppc directly (will not work for cross compile)

 

TinyPortal © 2005-2018