Hi,

I am using FPC (3.0.4 and the fixes_3_0 branch) to create a shared library for Linux x86_64. When it comes to debugging (with gdb) or profiling, I always had problems getting valuable stacktraces from withing the pascal functions. I now tracked this problem down to the .debug_frame section generated by the -gw option of fpc.


In my opinion fpc (fixes_3_0 branch) generates a mix-up of the 32-bit DWARF format and the 64-bit DWARF format (which only exists for DWARF version 3 and later). The generated initial length fields are 32 bit (32-bit DWARF) and not 96 bit (64-bit DWARF) and the CID_id fields in the CIEs are 32 bit (32-bit DWARF) and not 64 bit (64-bit DWARF) but the CIE_pointer fields in the FDEs are 64 bit (64-bit DWARF) and not 32 bit (32-bit DWARF).

The attached patch (for the fixes_3_0 branch) fixes the CIE_pointer length to be 32 bit. In addition I had to change the alignment of .debug_frame sections to 4 bytes. Otherwise the concatenation of multiple .debug_frame sections would result in corrupt entries.

During my investigations I stumbled over the calling convention DW_CC_GNU_borland_fastcall_i386. I think this is a bit weird on a non-i386 platform. Therefore the patch changes this to DW_CC_normal on the other platforms.

Please give this patch a thorough review as I am neither a DWARF nor a compiler expert. But for me (on Linux x86_64) the debugging and profiling situation is much better now.

Markus
Index: compiler/cfidwarf.pas
===================================================================
--- compiler/cfidwarf.pas	(Revision 38114)
+++ compiler/cfidwarf.pas	(Arbeitskopie)
@@ -332,7 +332,10 @@
                   tc:=tai_const.create_sym(cielabel);
                   { force label offset to secrel32 for windows systems }
                   if (target_info.system in systems_windows+systems_wince) then
-                    tc.consttype:=aitconst_secrel32_symbol;
+                    tc.consttype:=aitconst_secrel32_symbol
+	          else
+                    { we generate 32 bit DWARF }
+                    tc.consttype:=aitconst_32bit;
                   list.concat(tc);
                   list.concat(tai_const.create_sym(hp.oper[0].beginsym));
                   list.concat(tai_const.create_rel_sym(aitconst_ptr,hp.oper[0].beginsym,hp.oper[0].endsym));
Index: compiler/dbgdwarf.pas
===================================================================
--- compiler/dbgdwarf.pas	(Revision 38114)
+++ compiler/dbgdwarf.pas	(Arbeitskopie)
@@ -2053,7 +2053,11 @@
         begin
           case def.proccalloption of
             pocall_register:
+{$if defined(i386)}
               result:=DW_CC_GNU_borland_fastcall_i386;
+{$else}
+              result:=DW_CC_normal;
+{$endif}
             pocall_cdecl,
             pocall_stdcall,
             pocall_cppdecl,
Index: compiler/ogbase.pas
===================================================================
--- compiler/ogbase.pas	(Revision 38114)
+++ compiler/ogbase.pas	(Arbeitskopie)
@@ -1105,7 +1105,7 @@
             in a corrupt idata section.
             Same story with .pdata, it has 4-byte elements which should
             be packed without gaps. }
-          sec_idata2,sec_idata4,sec_idata5,sec_idata6,sec_idata7,sec_pdata:
+          sec_idata2,sec_idata4,sec_idata5,sec_idata6,sec_idata7,sec_pdata,sec_debug_frame:
             result:=4;
           else
             result:=sizeof(pint);
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to