Recent

Author Topic: GDB hang, find the reason but dont know why  (Read 948 times)

calebs

  • Full Member
  • ***
  • Posts: 136
GDB hang, find the reason but dont know why
« on: August 04, 2020, 05:17:14 am »
Hello all, i've encountered an error with the debugger (gdb).
Im using lazarus 2.0.10.r63526 win32 on win 10x64.
When i try to compile and run a program with the next code lazarus stalls and in a while gives an error with gdb (never have seen an error like this)
"error del depurador Uuuups, el depurador entro en estado de error guarda tu trabajo ahora! pulsa stop y espera lo mejor.
No se puede enviar un comando a gdb
El proceso GDB ha dejado de funcionar"
The code is

Code: Pascal  [Select][+][-]
  1. Procedure tform1.cargararticulos;
  2. var
  3. //  nitem : tlistitem;
  4.   costo, util1, prlista1, prlista2, prlista3, prlista4, prlista1n, prlista2n, prlista3n, prlista4n, iva , coston: real;
  5.   cad, cad2 , stb, stm, ru, sru: string;
  6.   contador : integer;
  7.  
  8. Begin
  9.   Screen.Cursor:=crHourGlass;
  10.   StaticText1.Caption:='ESPERE UN MOMENTO. CARGANDO ARTICULOS';
  11.   StaticText1.Visible:=true;
  12.   Application.ProcessMessages;
  13.   ru:=devolverultimoparametro(combobox2.Text);
  14.   sru:=devolverultimoparametro(combobox3.Text);
  15.   cad:='SELECT aru.codigo AS ruc, aru.descripcion AS rud , ars.codigo AS src, ars.descripcion AS srd, art.codigo AS arc, art.descripcion AS ard, art.costoi, ';
  16.   cad:=cad+'art.costoant, art.prlista1, art.prlista2, art.prlista3, art.prlista4, art.idar ';
  17.   cad:=cad+'FROM articulosrubros aru, articulossubrubros ars, articulos art, articulosdeproveedor ard ';
  18.   cad:=cad+'WHERE art.rubro = aru.idr AND art.subrubro = ars.idsr AND art.idar = ard.idarticulo AND art.eliminado=0 AND ard.idproveedor = '+devolverultimoparametro(LabeledEdit1.Text)+' ';
  19.   if combobox2.ItemIndex>0 then
  20.     cad:=cad+'AND art.rubro = '+devolverultimoparametro(combobox2.Text)+' ';
  21.   if combobox3.ItemIndex>0 then
  22.     cad:=cad+'AND art.subrubro = '+devolverultimoparametro(combobox3.Text)+' ';
  23.   cad:=cad+'ORDER BY ';
  24.   case combobox1.ItemIndex of
  25.     0 : cad:=cad+'art.codigo';
  26.     1 : cad:=cad+'art.rubro';
  27.     2 : cad:=cad+'art.subrubro';
  28.     3 : cad:=cad+'art.descripcion';
  29.     4 : cad:=cad+'art.costoi';
  30.     5 : cad:=cad+'art.prlista1';
  31.     6 : cad:=cad+'art.prlista2';
  32.     7 : cad:=cad+'art.prlista3';
  33.     8 : cad:=cad+'art.prlista4';
  34.   end;
  35.   dbi.bpqsl.SQL.Text:=cad;
  36.   dbi.bpqsl.Open;
  37.   listapantalla.Clear;
  38.   contador:=0;
  39.   while not dbi.bpqsl.EOF do begin
  40.     cad2:=dbi.bpqsl.FieldByName('arc').AsString+'|'+dbi.bpqsl.FieldByName('ruc').AsString+'('+dbi.bpqsl.FieldByName('rud').AsString+')|'+dbi.bpqsl.FieldByName('src').AsString;
  41.     cad2:=cad2+'('+dbi.bpqsl.FieldByName('srd').AsString+')|'+dbi.bpqsl.FieldByName('srd').AsString+'|'+floattostrf(dbi.bpqsl.FieldByName('costoi').AsFloat,ffFixed,8,2)+'|';
  42.     cad2:=cad2+floattostrf(dbi.bpqsl.FieldByName('costoant').AsFloat,ffFixed,8,2)+'|'+floattostrf(dbi.bpqsl.FieldByName('prlista1').AsFloat,ffFixed,8,2)+'|';
  43.     cad2:=cad2+floattostrf(dbi.bpqsl.FieldByName('prlista2').AsFloat,ffFixed,8,2)+'|'+floattostrf(dbi.bpqsl.FieldByName('prlista3').AsFloat,ffFixed,8,2)+'|';
  44.     cad2:=cad2+floattostrf(dbi.bpqsl.FieldByName('prlista4').AsFloat,ffFixed,8,2)+'|'+floattostrf(dbi.bpqsl.FieldByName('idar').AsFloat,ffFixed,8,2);
  45.     listapantalla.Add(cad2);                                    // this line is causing the trouble
  46.     dbi.bpqsl.Next;
  47.     inc(contador);
  48.   end;
  49.   if listapantalla.Count=0 then begin
  50.     StaticText1.Caption:='No se encuentran articulos con esos datos';
  51.     StaticText1.Font.Color:=clYellow;
  52.     StaticText1.Visible:=true;
  53.     Timer1.Enabled:=true;
  54.   end;
  55.   listview1.Items.Count:=contador;
  56.   dbi.bpqsl.Close;
  57.   StaticText1.Visible:=false;
  58.   Screen.Cursor:=crDefault;
  59.   listview1.Repaint;
  60.   Application.ProcessMessages;
  61. end;
  62.  

If i change the line

Code: Pascal  [Select][+][-]
  1. if listapantalla.Count=0 then begin            

with

Code: Pascal  [Select][+][-]
  1.   if contador=0 then begin  

The program compiles and runs as expected.

I don't really know what seems to be the problem here but i would like to know before it happens again in another place that i cant trace what is the problem (or why).

If anybody needs more info about other parts of the code that were needed i'll gladly post them

Thanks!

PS: the code is very diry, i know... sorry

440bx

  • Hero Member
  • *****
  • Posts: 1988
Re: GDB hang, find the reason but dont know why
« Reply #1 on: August 04, 2020, 06:22:16 am »
I suggest you create a "minimal" program that uses whatever units are required in order to have access to "listapantalla" and then have the statement "if listapantalla.Count=0 then begin end;" by itself.

That would, at least, give some clue if the problem is in "listapantalla" or may be caused by something else in the program which eventually causes that statement to fail.

HTH.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6592
    • wiki
Re: GDB hang, find the reason but dont know why
« Reply #2 on: August 04, 2020, 12:23:55 pm »
There are several bugs in gdb that can lead to this.

Could you please make a log file? https://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session

calebs

  • Full Member
  • ***
  • Posts: 136
Re: GDB hang, find the reason but dont know why
« Reply #3 on: August 04, 2020, 09:26:48 pm »
Hello, sorry for the lack of info.
After the correction i've used last time, worked ok but then again, added a few short procedures (bitbtn17 to bitbtn26 all equal minus an sql line).
Tested with a few and worked ok but when i added all started to fail again.
Ive activated the log options martin suggested and attached to this post (of this new program, not the previous one).
I ve also attach the unit that fails to debug.

I have not this kind of errors with all previous version of lazarus, dont know if its why a new version of gdb or the new fpc sources.

Thanks

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6592
    • wiki
Re: GDB hang, find the reason but dont know why
« Reply #4 on: August 04, 2020, 09:54:16 pm »
Thats a strange one. GDB crashes so hard it does not even print an error.

But there are several things you could try:

1) Tools > Options > Debugger: in the grid: "Internal Start Break" set to gdsbMain alternative gdsbEntry or gdsbMainAddr

2) Try a newer GDB https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2032%20bits/Alternative%20GDB/
You can try gdb 8.2 from that list.

ASerge

  • Hero Member
  • *****
  • Posts: 1665
Re: GDB hang, find the reason but dont know why
« Reply #5 on: August 04, 2020, 10:03:06 pm »
You can try gdb 8.2 from that list.
By the way, Lazarus 2.0.10 win32 comes with GDB version 7.7.1, but Lazarus 2.0.10 win64 already with GDB version 8.2.

calebs

  • Full Member
  • ***
  • Posts: 136
Re: GDB hang, find the reason but dont know why
« Reply #6 on: August 04, 2020, 10:18:44 pm »
Hello again!
It seems the problem has something to do with accessing the listview component.
i've changed some lines of the code and now compiles and debug normally

changed
Code: Pascal  [Select][+][-]
  1.    for nro:=0 to listview1.Items.Count-1 do begin      

with

Code: Pascal  [Select][+][-]
  1.  nro2:=listview1.Items.Count-1;
  2.       for nro:=0 to nro2 do begin                    

declaring nro2 as integer variable

Could be the listview is using ownerdata true?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6592
    • wiki
Re: GDB hang, find the reason but dont know why
« Reply #7 on: August 04, 2020, 10:19:33 pm »
You can try gdb 8.2 from that list.

The 8.2 for 64 bit was reverted, as the 8.2 build does not support utf8 environment values to be set. (which affects home path, and defaults for save/open dialog)

For all I know this is a build issue, not a version issue.
But I have not yet figured out how to build a new gdb with utf8 support. (probably cygwin needed)

The 32bit version fails too (but afaik also 7.7). Not yet found a working build.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6592
    • wiki
Re: GDB hang, find the reason but dont know why
« Reply #8 on: August 04, 2020, 10:27:34 pm »
Gdb crashing when and where it crashed in your logfile is unlikely to be related....

But, you may want to set the checkbox "Reset debugger after each run" (Tools >Options > Debugger).

Otherwise it is possible that a previous debug session (that may have been/seemed all ok) affects your next debug. So the crash could be from anything you did.



Just to be sure:
- You do create 32bit apps
- You installed a 32 bit IDE 

Because using the 64bit IDE with 32bit add-on can make troubles (fixed in trunk only)



It is possible that watching certain variables can upset gdb.
With certain setting  (eg dwarf-3)"var PtrString: ^ansistring" can crash gdb. And there are others, but no full list. But that is ONLY if you evaluate the variable.

You may want to check in project options what debug info is used.
It is recommanded to use "dwarf (with sets)"

Sometimes packages have different settings. You can add an entry in "addition and overrides" that specifies  -gw 



If you keep having troubles with gdb, try fpdebug

Install the package LazDebuggerFp
Then under Tools > Options > Debugger, change the debugger type to fpdebug



Do you run any 3rd party antivirus?
« Last Edit: August 04, 2020, 10:32:05 pm by Martin_fr »

calebs

  • Full Member
  • ***
  • Posts: 136
Re: GDB hang, find the reason but dont know why
« Reply #9 on: August 05, 2020, 12:20:18 am »
Thats a strange one. GDB crashes so hard it does not even print an error.

But there are several things you could try:

1) Tools > Options > Debugger: in the grid: "Internal Start Break" set to gdsbMain alternative gdsbEntry or gdsbMainAddr

2) Try a newer GDB https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2032%20bits/Alternative%20GDB/
You can try gdb 8.2 from that list.

executing gdb --version gives me 9.1
thats the retail lazarus instalation gdb, i didn't upgrade it or manually instaled

calebs

  • Full Member
  • ***
  • Posts: 136
Re: GDB hang, find the reason but dont know why
« Reply #10 on: August 05, 2020, 12:26:14 am »
Gdb crashing when and where it crashed in your logfile is unlikely to be related....

But, you may want to set the checkbox "Reset debugger after each run" (Tools >Options > Debugger).

Otherwise it is possible that a previous debug session (that may have been/seemed all ok) affects your next debug. So the crash could be from anything you did.



Just to be sure:
- You do create 32bit apps
- You installed a 32 bit IDE 

Because using the 64bit IDE with 32bit add-on can make troubles (fixed in trunk only)



It is possible that watching certain variables can upset gdb.
With certain setting  (eg dwarf-3)"var PtrString: ^ansistring" can crash gdb. And there are others, but no full list. But that is ONLY if you evaluate the variable.

You may want to check in project options what debug info is used.
It is recommanded to use "dwarf (with sets)"

Sometimes packages have different settings. You can add an entry in "addition and overrides" that specifies  -gw 



If you keep having troubles with gdb, try fpdebug

Install the package LazDebuggerFp
Then under Tools > Options > Debugger, change the debugger type to fpdebug



Do you run any 3rd party antivirus?

i've enabled the option and will keep trying
i use winx64 but lazarus is x86 with no 64 bit addon

debugger in my projects is always the default (-g), never had to change it for anything, i will try with other options if it fails again.
The problem is that the program doesn't execute.
is compiled but don't even start, neither get to any breakpoint in the program.
I think it hangs evaluating the executable BEFORE runing it ??

i will try to use fpdebug if these problems keep appearing.

thanks!

ps: only windows defender... no antivirus nor antimalware apps

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6592
    • wiki
Re: GDB hang, find the reason but dont know why
« Reply #11 on: August 05, 2020, 12:51:03 am »
executing gdb --version gives me 9.1
thats the retail lazarus instalation gdb, i didn't upgrade it or manually instaled
From your logfile
Code: Text  [Select][+][-]
  1.   >> TCmdLineDebugger.SendCmdLn "-gdb-version"
  2.   << TCmdLineDebugger.ReadLn "~"GNU gdb (GDB) 7.7.1\n""
  3.  


Quote
The problem is that the program doesn't execute.
is compiled but don't even start, neither get to any breakpoint in the program.
I think it hangs evaluating the executable BEFORE runing it ??

gdb crashes immediately after it start your app (and gdb will take your app down with it).
Code: Text  [Select][+][-]
  1.   << TCmdLineDebugger.ReadLn "=thread-group-started,id="i1",pid="14020""
  2.   << TCmdLineDebugger.ReadLn "=thread-created,id="1",group-id="i1""
  3.   << TCmdLineDebugger.ReadLn "~"[New Thread 14020.0x2360]\n""
  4.   << TCmdLineDebugger.ReadLn "^running"
  5.   << TCmdLineDebugger.ReadLn "*running,thread-id="all""
  6.   << TCmdLineDebugger.ReadLn "(gdb) "
  7.   PeekNamedPipe failed, GetLastError is 109
  8.   [TCmdLineDebugger.Getoutput] Error waiting
  9.   << TCmdLineDebugger.ReadLn ""
  10.   >> TCmdLineDebugger.SendCmdLn "-break-delete 2"
  11.   [TCmdLineDebugger.SendCmdLn] Unable to send <-break-delete 2>. No process running.
  12.  
Gdb confirms the process was created, next that process should hit an internal breakpoint (before any form or anything).  But that never happens. "109" means the pipe between IDE and gdb went dead, and its then confirmed gdb simply exited (aka gdb crashed).

Or gdb was killed by an antivirus (though its a long time since I seen that.)

I don't know the internals of gdb. But the chances that this is related to a particular unit, or a specific line of code is extremely low. Maybe code in an initialization section, but even that is unlikely.

One more idea though that comes to mind. Double check you do NOT do smart linking: no -XX  ("smart linkable -CX" is ok)

calebs

  • Full Member
  • ***
  • Posts: 136
Re: GDB hang, find the reason but dont know why
« Reply #12 on: August 05, 2020, 07:15:22 am »
Hello again.
I'm started another program and i was working fine, debugging fine (it is more simple than the previous one), but when i add several similar procedures that interacts with listviews gdb started to crash again.
This time listviews are not ownerdata, just couple of options changed from defaults (hideselection, multiselect, readonly, rowselect)
It seems gdb doesn't like listviews (or me).
I attach the log from the gdb and the unit.
Thanks for the support.

calebs

  • Full Member
  • ***
  • Posts: 136
Re: GDB hang, find the reason but dont know why
« Reply #13 on: August 05, 2020, 04:06:42 pm »
Hello all again, i have a virtualbox vm with ubuntu mate 20.04 x86 with lazarus 2.0.10 installed on it that i use for develop and compile also. Opened this same project and compiled and runned fine. No gdb errors at all. Double check again on windows and keeps failing with the same project.
I still didn't try another version of gdb or fpdebug, i will try later.
thanks!

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6592
    • wiki
Re: GDB hang, find the reason but dont know why
« Reply #14 on: August 05, 2020, 06:50:21 pm »
I don't think the listview was actually accessed at the time of the crash.

The only think that could somehow be relevant is that the unit ComCtrls is included.
1) It has some initialization code. But if that failed gdb should not crash.
2) Maybe the pre-compiled ppu/o file has somehow gotten corrupted debug info (I really do not think so, but...)

You could recompile the IDE. Tools > Configure build Lazarus // and ensure to check "clean all"

In that dialog you can also specify -gw to get dwarf debug info for the LCL and other packages.



I tested here on Win10 with a clean install of 2.0.10 32 bit. TListView on a form, starts with on issue.

 

TinyPortal © 2005-2018