Selaa lähdekoodia

* i386 uses dwarf cfi info on linux/win32, so even when omitting the stack frame, trace backs in gdb are correct

git-svn-id: trunk@2316 -
florian 19 vuotta sitten
vanhempi
commit
f5d790f9b6

+ 27 - 8
compiler/dwarf.pas

@@ -80,6 +80,7 @@ interface
       public
         constructor create;
         procedure generate_code(list:taasmoutput);
+        procedure generate_initial_instructions(list:taasmoutput);virtual;
         { operations }
         procedure start_frame(list:taasmoutput);
         procedure end_frame(list:taasmoutput);
@@ -247,9 +248,32 @@ implementation
         FFrameEndLabel:=nil;
         FLastLocLabel:=nil;
         code_alignment_factor:=1;
-        data_alignment_factor:=-1;
+        data_alignment_factor:=-4;
       end;
 
+{$ifdef i386}
+    { if more cpu dependend stuff is implemented, this needs more refactoring }
+    procedure tdwarfcfi.generate_initial_instructions(list:taasmoutput);
+      begin
+        list.concat(tai_const.create_8bit(DW_CFA_def_cfa));
+        list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_STACK_POINTER_REG)));
+        list.concat(tai_const.create_uleb128bit(sizeof(aint)));
+        list.concat(tai_const.create_8bit(DW_CFA_offset_extended));
+        list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_RETURN_ADDRESS_REG)));
+        list.concat(tai_const.create_uleb128bit((-sizeof(aint)) div data_alignment_factor));
+      end;
+{$else i386}
+    { if more cpu dependend stuff is implemented, this needs more refactoring }
+    procedure tdwarfcfi.generate_initial_instructions(list:taasmoutput);
+      begin
+        list.concat(tai_const.create_8bit(DW_CFA_def_cfa));
+        list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_STACK_POINTER_REG)));
+        list.concat(tai_const.create_uleb128bit(sizeof(aint)));
+        list.concat(tai_const.create_8bit(DW_CFA_offset_extended));
+        list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_RETURN_ADDRESS_REG)));
+        list.concat(tai_const.create_uleb128bit((-sizeof(aint)) div data_alignment_factor));
+      end;
+{$endif i386}
 
     procedure tdwarfcfi.generate_code(list:taasmoutput);
       var
@@ -286,13 +310,8 @@ implementation
             def_cfa(stackpointer,sizeof(aint))
             cfa_offset_extended(returnaddres,-sizeof(aint))
         }
-{$warning TODO This needs to be target dependent}
-        list.concat(tai_const.create_8bit(DW_CFA_def_cfa));
-        list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_STACK_POINTER_REG)));
-        list.concat(tai_const.create_uleb128bit(sizeof(aint)));
-        list.concat(tai_const.create_8bit(DW_CFA_offset_extended));
-        list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_RETURN_ADDRESS_REG)));
-        list.concat(tai_const.create_uleb128bit((-sizeof(aint)) div data_alignment_factor));
+        generate_initial_instructions(list);
+
         list.concat(cai_align.create_zeros(4));
         list.concat(tai_label.create(lenendlabel));
         lenstartlabel:=nil;

+ 2 - 1
compiler/systems/i_linux.pas

@@ -50,7 +50,8 @@ unit i_linux;
 {$ifdef segment_threadvars}
                             tf_section_threadvars,
 {$endif segment_threadvars}
-                            tf_needs_symbol_type,tf_files_case_sensitive,tf_use_function_relative_addresses];
+                            tf_needs_symbol_type,tf_files_case_sensitive,tf_use_function_relative_addresses,
+                            tf_needs_dwarf_cfi];
             cpu          : cpu_i386;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX';

+ 1 - 1
compiler/systems/i_win.pas

@@ -33,7 +33,7 @@ unit i_win;
             name         : 'Win32 for i386';
             shortname    : 'Win32';
             flags        : [tf_files_case_aware,tf_has_dllscanner,tf_use_function_relative_addresses
-                            {,tf_smartlink_sections}{,tf_section_threadvars}];
+                            {,tf_smartlink_sections}{,tf_section_threadvars},tf_needs_dwarf_cfi];
             cpu          : cpu_i386;
             unit_env     : 'WIN32UNITS';
             extradefines : 'MSWINDOWS;WINDOWS';

+ 1 - 1
compiler/x86/agx86att.pas

@@ -258,7 +258,7 @@ interface
             asmbin : 'as';
             asmcmd : '-o $OBJ $ASM';
             supported_target : system_any;
-            flags : [af_allowdirect,af_needar,af_smartlink_sections];
+            flags : [af_allowdirect,af_needar,af_smartlink_sections,af_supports_dwarf];
             labelprefix : '.L';
             comment : '# ';
           );

+ 3 - 1
compiler/x86/cgx86.pas

@@ -1841,7 +1841,7 @@ unit cgx86;
         if not nostackframe then
           begin
             list.concat(tai_regalloc.alloc(current_procinfo.framepointer,nil));
-            if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
+            if current_procinfo.framepointer=NR_STACK_POINTER_REG then
               CGmessage(cg_d_stackframe_omited)
             else
               begin
@@ -1858,6 +1858,8 @@ unit cgx86;
             if localsize<>0 then
               begin
                 cg.g_stackpointer_alloc(list,localsize);
+                if current_procinfo.framepointer=NR_STACK_POINTER_REG then
+                  dwarfcfi.cfa_def_cfa_offset(list,localsize+sizeof(aint));
               end;
           end;
       end;