Browse Source

* move stabs generation to a single procedure call from pmodules

git-svn-id: trunk@1358 -
peter 20 years ago
parent
commit
51b8a4a132

+ 6 - 8
compiler/aasmtai.pas

@@ -593,15 +593,14 @@ interface
          information in the .o file. The stabs for the types must be defined
          information in the .o file. The stabs for the types must be defined
          before they can be referenced and therefor they need to be written
          before they can be referenced and therefor they need to be written
          first (PFV) }
          first (PFV) }
-       Tasmlist=(al_debugstart,
-                 al_debugtypes,
+       Tasmlist=(al_stabsstart,
+                 al_stabs,
                  al_procedures,
                  al_procedures,
                  al_globals,
                  al_globals,
                  al_const,
                  al_const,
                  al_typedconsts,
                  al_typedconsts,
                  al_rotypedconsts,
                  al_rotypedconsts,
                  al_threadvars,
                  al_threadvars,
-                 al_withdebug,
                  al_imports,
                  al_imports,
                  al_exports,
                  al_exports,
                  al_resources,
                  al_resources,
@@ -609,18 +608,17 @@ interface
                  al_dwarf,
                  al_dwarf,
                  al_picdata,
                  al_picdata,
                  al_resourcestrings,
                  al_resourcestrings,
-                 al_debugend);
+                 al_stabsend);
     const
     const
        TasmlistStr : array[tasmlist] of string[24] =(
        TasmlistStr : array[tasmlist] of string[24] =(
-           'al_debugstart',
-           'al_debugtypes',
+           'al_stabsstart',
+           'al_stabs',
            'al_procedures',
            'al_procedures',
            'al_globals',
            'al_globals',
            'al_const',
            'al_const',
            'al_typedconsts',
            'al_typedconsts',
            'al_rotypedconsts',
            'al_rotypedconsts',
            'al_threadvars',
            'al_threadvars',
-           'al_withdebug',
            'al_imports',
            'al_imports',
            'al_exports',
            'al_exports',
            'al_resources',
            'al_resources',
@@ -628,7 +626,7 @@ interface
            'al_dwarf',
            'al_dwarf',
            'al_picdata',
            'al_picdata',
            'al_resourcestrings',
            'al_resourcestrings',
-           'al_debugend');
+           'al_stabsend');
 
 
       regallocstr : array[tregalloctype] of string[10]=('allocated','released','sync','resized');
       regallocstr : array[tregalloctype] of string[10]=('allocated','released','sync','resized');
       tempallocstr : array[boolean] of string[10]=('released','allocated');
       tempallocstr : array[boolean] of string[10]=('released','allocated');

+ 0 - 2
compiler/assemble.pas

@@ -1408,8 +1408,6 @@ Implementation
 
 
       begin
       begin
         to_do:=[low(Tasmlist)..high(Tasmlist)];
         to_do:=[low(Tasmlist)..high(Tasmlist)];
-        if not(cs_debuginfo in aktmoduleswitches) then
-          exclude(to_do,al_debugtypes);
         if usedeffileforexports then
         if usedeffileforexports then
           exclude(to_do,al_exports);
           exclude(to_do,al_exports);
         {$warning TODO internal writer support for dwarf}
         {$warning TODO internal writer support for dwarf}

+ 4 - 40
compiler/dbgbase.pas

@@ -34,14 +34,8 @@ interface
     type
     type
       TDebugInfo=class
       TDebugInfo=class
         constructor Create;virtual;
         constructor Create;virtual;
-        procedure insertvmt(list:taasmoutput;objdef:tobjectdef);virtual;
-        procedure insertsym(list:taasmoutput;sym:tsym);virtual;
-        procedure insertdef(list:taasmoutput;def:tdef);virtual;
-        procedure insertmoduletypes(list:taasmoutput);virtual;
-        procedure insertprocstart(list:taasmoutput);virtual;
-        procedure insertprocend(list:taasmoutput);virtual;
-        procedure insertmodulestart(list:taasmoutput);virtual;
-        procedure insertmoduleend(list:taasmoutput);virtual;
+        procedure inserttypeinfo;virtual;
+        procedure insertmoduleinfo;virtual;
         procedure insertlineinfo(list:taasmoutput);virtual;
         procedure insertlineinfo(list:taasmoutput);virtual;
         procedure referencesections(list:taasmoutput);virtual;
         procedure referencesections(list:taasmoutput);virtual;
       end;
       end;
@@ -67,42 +61,12 @@ implementation
       end;
       end;
 
 
 
 
-    procedure tdebuginfo.insertvmt(list:taasmoutput;objdef:tobjectdef);
+    procedure tdebuginfo.insertmoduleinfo;
       begin
       begin
       end;
       end;
 
 
 
 
-    procedure tdebuginfo.insertsym(list:taasmoutput;sym:tsym);
-      begin
-      end;
-
-
-    procedure tdebuginfo.insertdef(list:taasmoutput;def:tdef);
-      begin
-      end;
-
-
-    procedure tdebuginfo.insertmoduletypes(list:taasmoutput);
-      begin
-      end;
-
-
-    procedure tdebuginfo.insertprocstart(list:taasmoutput);
-      begin
-      end;
-
-
-    procedure tdebuginfo.insertprocend(list:taasmoutput);
-      begin
-      end;
-
-
-    procedure tdebuginfo.insertmodulestart(list:taasmoutput);
-      begin
-      end;
-
-
-    procedure tdebuginfo.insertmoduleend(list:taasmoutput);
+    procedure tdebuginfo.inserttypeinfo;
       begin
       begin
       end;
       end;
 
 

+ 192 - 159
compiler/dbgstabs.pas

@@ -52,19 +52,16 @@ interface
         procedure field_write_defs(p:Tnamedindexitem;arg:pointer);
         procedure field_write_defs(p:Tnamedindexitem;arg:pointer);
         procedure method_write_defs(p :tnamedindexitem;arg:pointer);
         procedure method_write_defs(p :tnamedindexitem;arg:pointer);
         procedure write_symtable_defs(list:taasmoutput;st:tsymtable);
         procedure write_symtable_defs(list:taasmoutput;st:tsymtable);
+        procedure insertsym(list:taasmoutput;sym:tsym);
+        procedure insertdef(list:taasmoutput;def:tdef);
       public
       public
-        procedure insertsym(list:taasmoutput;sym:tsym);override;
-        procedure insertdef(list:taasmoutput;def:tdef);override;
-        procedure insertvmt(list:taasmoutput;objdef:tobjectdef);override;
-        procedure insertmoduletypes(list:taasmoutput);override;
-        procedure insertprocstart(list:taasmoutput);override;
-        procedure insertprocend(list:taasmoutput);override;
-        procedure insertmodulestart(list:taasmoutput);override;
-        procedure insertmoduleend(list:taasmoutput);override;
+        procedure inserttypeinfo;override;
+        procedure insertmoduleinfo;override;
         procedure insertlineinfo(list:taasmoutput);override;
         procedure insertlineinfo(list:taasmoutput);override;
         procedure referencesections(list:taasmoutput);override;
         procedure referencesections(list:taasmoutput);override;
       end;
       end;
 
 
+
 implementation
 implementation
 
 
     uses
     uses
@@ -739,8 +736,14 @@ implementation
         stabchar : string[2];
         stabchar : string[2];
         ss,st,su : pchar;
         ss,st,su : pchar;
       begin
       begin
-        { procdefs require a different stabs style, handle them separately }
-        if def.deftype<>procdef then
+        { procdefs require a different stabs style without type prefix }
+        if def.deftype=procdef then
+          begin
+            st:=def_stabstr(def);
+            { add to list }
+            list.concat(Tai_stab.create(stab_stabs,st));
+          end
+        else
           begin
           begin
             { type prefix }
             { type prefix }
             if def.deftype in tagtypes then
             if def.deftype in tagtypes then
@@ -762,11 +765,9 @@ implementation
             reallocmem(st,strlen(st)+1);
             reallocmem(st,strlen(st)+1);
             strdispose(ss);
             strdispose(ss);
             strdispose(su);
             strdispose(su);
-          end
-        else
-          st:=def_stabstr(def);
-        { add to list }
-        list.concat(Tai_stab.create(stab_stabs,st));
+            { add to list }
+            list.concat(Tai_stab.create(stab_stabs,st));
+          end;
       end;
       end;
 
 
 
 
@@ -877,22 +878,38 @@ implementation
           end
           end
         else
         else
 *)
 *)
-        { classes require special code to write the record and the invisible pointer }
-          if is_class(def) then
+        case def.deftype of
+          objectdef :
             begin
             begin
-              { Write the record class itself }
-              tobjectdef(def).writing_class_record_stab:=true;
-              write_def_stabstr(list,def);
-              tobjectdef(def).writing_class_record_stab:=false;
-              { Write the invisible pointer class }
-              oldtypesym:=def.typesym;
-              def.typesym:=nil;
-              write_def_stabstr(list,def);
-              def.typesym:=oldtypesym;
-            end
-        { normal def }
-        else
-          write_def_stabstr(list,def);
+              { classes require special code to write the record and the invisible pointer }
+              if is_class(def) then
+                begin
+                  { Write the record class itself }
+                  tobjectdef(def).writing_class_record_stab:=true;
+                  write_def_stabstr(list,def);
+                  tobjectdef(def).writing_class_record_stab:=false;
+                  { Write the invisible pointer class }
+                  oldtypesym:=def.typesym;
+                  def.typesym:=nil;
+                  write_def_stabstr(list,def);
+                  def.typesym:=oldtypesym;
+                end
+              else
+                write_def_stabstr(list,def);
+              { VMT symbol }
+              if (oo_has_vmt in tobjectdef(def).objectoptions) and
+                 assigned(def.owner) and
+                 assigned(def.owner.name) then
+                list.concat(Tai_stab.create(stab_stabs,strpnew('"vmt_'+def.owner.name^+tobjectdef(def).name+':S'+
+                       def_stab_number(vmttype.def)+'",'+tostr(N_STSYM)+',0,0,'+tobjectdef(def).vmt_mangledname)));
+            end;
+          procdef :
+            begin
+              { procdefs are handled separatly }
+            end;
+          else
+            write_def_stabstr(list,def);
+        end;
 
 
         def.stab_state := stab_state_written;
         def.stab_state := stab_state_written;
       end;
       end;
@@ -927,14 +944,22 @@ implementation
       var
       var
         old_writing_def_stabs : boolean;
         old_writing_def_stabs : boolean;
       begin
       begin
-        if st.symtabletype=globalsymtable then
-          list.concat(tai_comment.Create(strpnew('Begin unit '+st.name^+' has index '+tostr(st.moduleid))));
+        case st.symtabletype of
+          staticsymtable :
+            list.concat(tai_comment.Create(strpnew('Defs - Begin Staticsymtable')));
+          globalsymtable :
+            list.concat(tai_comment.Create(strpnew('Defs - Begin unit '+st.name^+' has index '+tostr(st.moduleid))));
+        end;
         old_writing_def_stabs:=writing_def_stabs;
         old_writing_def_stabs:=writing_def_stabs;
         writing_def_stabs:=true;
         writing_def_stabs:=true;
         dowritestabs(list,st);
         dowritestabs(list,st);
         writing_def_stabs:=old_writing_def_stabs;
         writing_def_stabs:=old_writing_def_stabs;
-        if st.symtabletype=globalsymtable then
-          list.concat(tai_comment.Create(strpnew('End unit '+st.name^+' has index '+tostr(st.moduleid))));
+        case st.symtabletype of
+          staticsymtable :
+            list.concat(tai_comment.Create(strpnew('Defs - End Staticsymtable')));
+          globalsymtable :
+            list.concat(tai_comment.Create(strpnew('Defs - End unit '+st.name^+' has index '+tostr(st.moduleid))));
+        end;
       end;
       end;
 
 
 
 
@@ -1081,8 +1106,8 @@ implementation
                   else
                   else
                     internalerror(2003091815);
                     internalerror(2003091815);
                 end;
                 end;
-                if (po_classmethod in current_procinfo.procdef.procoptions) or
-                   (po_staticmethod in current_procinfo.procdef.procoptions) then
+                if (po_classmethod in tabstractprocdef(sym.owner.defowner).procoptions) or
+                   (po_staticmethod in tabstractprocdef(sym.owner.defowner).procoptions) then
                   begin
                   begin
                     if (sym.localloc.loc=LOC_REFERENCE) then
                     if (sym.localloc.loc=LOC_REFERENCE) then
                       result:=sym_stabstr_evaluate(sym,'"pvmt:p$1",${N_TSYM},0,0,$2',
                       result:=sym_stabstr_evaluate(sym,'"pvmt:p$1",${N_TSYM},0,0,$2',
@@ -1093,16 +1118,16 @@ implementation
                     end
                     end
                 else
                 else
                   begin
                   begin
-                    if not(is_class(current_procinfo.procdef._class)) then
+                    if not(is_class(tprocdef(sym.owner.defowner)._class)) then
                       c:='v'
                       c:='v'
                     else
                     else
                       c:='p';
                       c:='p';
                     if (sym.localloc.loc=LOC_REFERENCE) then
                     if (sym.localloc.loc=LOC_REFERENCE) then
                       result:=sym_stabstr_evaluate(sym,'"$$t:$1",${N_TSYM},0,0,$2',
                       result:=sym_stabstr_evaluate(sym,'"$$t:$1",${N_TSYM},0,0,$2',
-                            [c+def_stab_number(current_procinfo.procdef._class),tostr(sym.localloc.reference.offset)]);
+                            [c+def_stab_number(tprocdef(sym.owner.defowner)._class),tostr(sym.localloc.reference.offset)]);
       (*            else
       (*            else
                       result:=sym_stabstr_evaluate(sym,'"$$t:r$1",${N_RSYM},0,0,$2',
                       result:=sym_stabstr_evaluate(sym,'"$$t:r$1",${N_RSYM},0,0,$2',
-                            [c+def_stab_number(current_procinfo.procdef._class),tostr(regstabs_table[regidx])]); *)
+                            [c+def_stab_number(tprocdef(sym.owner.defowner)._class),tostr(regstabs_table[regidx])]); *)
                   end;
                   end;
               end
               end
             else
             else
@@ -1182,6 +1207,85 @@ implementation
             result:=sym_stabstr_evaluate(sym,'"${name}:$1$2",${N_LSYM},0,${line},0',[stabchar,def_stab_number(sym.restype.def)]);
             result:=sym_stabstr_evaluate(sym,'"${name}:$1$2",${N_LSYM},0,${line},0',[stabchar,def_stab_number(sym.restype.def)]);
           end;
           end;
 
 
+
+        function procsym_stabstr(sym:tprocsym) : pchar;
+          var
+            i : longint;
+            pd : tprocdef;
+            templist : taasmoutput;
+            stabsendlabel : tasmlabel;
+            mangled_length : longint;
+            p : pchar;
+            hs : string;
+          begin
+            result:=nil;
+            { mark all procdefs }
+            for i:=1 to sym.procdef_count do
+              begin
+                pd:=sym.procdef[i];
+                if (pd.owner=sym.owner) and
+                   assigned(pd.procstarttai) then
+                  begin
+                    templist:=taasmoutput.create;
+                    { para types }
+                    write_def_stabstr(templist,pd);
+                    if assigned(pd.parast) then
+                      write_symtable_syms(templist,pd.parast);
+                    { local type defs and vars should not be written
+                      inside the main proc stab }
+                    if assigned(pd.localst) and
+                       (pd.localst.symtabletype=localsymtable) then
+                      write_symtable_syms(templist,pd.localst);
+                    asmlist[al_procedures].insertlistbefore(pd.procstarttai,templist);
+                    { end of procedure }
+                    objectlibrary.getlabel(stabsendlabel,alt_dbgtype);
+                    templist.concat(tai_label.create(stabsendlabel));
+                    if assigned(pd.funcretsym) and
+                       (tabstractnormalvarsym(pd.funcretsym).refs>0) then
+                      begin
+                        if tabstractnormalvarsym(pd.funcretsym).localloc.loc=LOC_REFERENCE then
+                          begin
+            {$warning Need to add gdb support for ret in param register calling}
+                            if paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
+                              hs:='X*'
+                            else
+                              hs:='X';
+                            templist.concat(Tai_stab.create(stab_stabs,strpnew(
+                               '"'+pd.procsym.name+':'+hs+def_stab_number(pd.rettype.def)+'",'+
+                               tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
+                            if (m_result in aktmodeswitches) then
+                              templist.concat(Tai_stab.create(stab_stabs,strpnew(
+                                 '"RESULT:'+hs+def_stab_number(pd.rettype.def)+'",'+
+                                 tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(pd.funcretsym).localloc.reference.offset))));
+                          end;
+                      end;
+                    mangled_length:=length(pd.mangledname);
+                    getmem(p,2*mangled_length+50);
+                    strpcopy(p,'192,0,0,');
+                    {$IFDEF POWERPC64}strpcopy(strend(p), '.');{$ENDIF POWERPC64}
+                    strpcopy(strend(p),pd.mangledname);
+                    if (target_info.use_function_relative_addresses) then
+                      begin
+                        strpcopy(strend(p),'-');
+                        {$IFDEF POWERPC64}strpcopy(strend(p), '.');{$ENDIF POWERPC64}
+                        strpcopy(strend(p),pd.mangledname);
+                      end;
+                    templist.concat(Tai_stab.Create(stab_stabn,strnew(p)));
+                    strpcopy(p,'224,0,0,'+stabsendlabel.name);
+                    if (target_info.use_function_relative_addresses) then
+                      begin
+                        strpcopy(strend(p),'-');
+                        {$IFDEF POWERPC64}strpcopy(strend(p), '.');{$ENDIF POWERPC64}
+                        strpcopy(strend(p),pd.mangledname);
+                      end;
+                    templist.concat(Tai_stab.Create(stab_stabn,strnew(p)));
+                    freemem(p,2*mangled_length+50);
+                    asmlist[al_procedures].insertlistbefore(pd.procendtai,templist);
+                    templist.free;
+                  end;
+              end;
+          end;
+
       var
       var
         stabstr : Pchar;
         stabstr : Pchar;
       begin
       begin
@@ -1190,7 +1294,7 @@ implementation
           labelsym :
           labelsym :
             stabstr:=sym_stabstr_evaluate(sym,'"${name}",${N_LSYM},0,${line},0',[]);
             stabstr:=sym_stabstr_evaluate(sym,'"${name}",${N_LSYM},0,${line},0',[]);
           procsym :
           procsym :
-            internalerror(200111171);
+            stabstr:=procsym_stabstr(tprocsym(sym));
           fieldvarsym :
           fieldvarsym :
             stabstr:=fieldvarsym_stabstr(tfieldvarsym(sym));
             stabstr:=fieldvarsym_stabstr(tfieldvarsym(sym));
           globalvarsym :
           globalvarsym :
@@ -1217,33 +1321,33 @@ implementation
       var
       var
         p : tsym;
         p : tsym;
       begin
       begin
+        case st.symtabletype of
+          staticsymtable :
+            list.concat(tai_comment.Create(strpnew('Syms - Begin Staticsymtable')));
+          globalsymtable :
+            list.concat(tai_comment.Create(strpnew('Syms - Begin unit '+st.name^+' has index '+tostr(st.moduleid))));
+        end;
         p:=tsym(st.symindex.first);
         p:=tsym(st.symindex.first);
         while assigned(p) do
         while assigned(p) do
           begin
           begin
-            { Procsym and typesym are already written }
-            if not(Tsym(p).typ in [procsym,typesym]) then
-              begin
-                if not Tsym(p).isstabwritten then
-                  insertsym(list,tsym(p));
-              end;
+            if (not p.isstabwritten) and
+               not(p.typ in [typesym]) then
+              insertsym(list,p);
             p:=tsym(p.indexnext);
             p:=tsym(p.indexnext);
           end;
           end;
+        case st.symtabletype of
+          staticsymtable :
+            list.concat(tai_comment.Create(strpnew('Syms - End Staticsymtable')));
+          globalsymtable :
+            list.concat(tai_comment.Create(strpnew('Syms - End unit '+st.name^+' has index '+tostr(st.moduleid))));
+        end;
       end;
       end;
 
 
 {****************************************************************************
 {****************************************************************************
                              Proc/Module support
                              Proc/Module support
 ****************************************************************************}
 ****************************************************************************}
 
 
-    procedure tdebuginfostabs.insertvmt(list:taasmoutput;objdef:tobjectdef);
-      begin
-        if assigned(objdef.owner) and
-           assigned(objdef.owner.name) then
-          list.concat(Tai_stab.create(stab_stabs,strpnew('"vmt_'+objdef.owner.name^+objdef.name+':S'+
-                 def_stab_number(vmttype.def)+'",'+tostr(N_STSYM)+',0,0,'+objdef.vmt_mangledname)));
-      end;
-
-
-    procedure tdebuginfostabs.insertmoduletypes(list:taasmoutput);
+    procedure tdebuginfostabs.inserttypeinfo;
 
 
        procedure reset_unit_type_info;
        procedure reset_unit_type_info;
        var
        var
@@ -1280,15 +1384,19 @@ implementation
        end;
        end;
 
 
       var
       var
-        temptypestabs : taasmoutput;
-        storefilepos : tfileposinfo;
+        stabsvarlist,
+        stabstypelist : taasmoutput;
+        storefilepos  : tfileposinfo;
         st : tsymtable;
         st : tsymtable;
       begin
       begin
-        global_stab_number:=0;
-
         storefilepos:=aktfilepos;
         storefilepos:=aktfilepos;
         aktfilepos:=current_module.mainfilepos;
         aktfilepos:=current_module.mainfilepos;
-        { include symbol that will be referenced from the program to be sure to
+
+        global_stab_number:=0;
+        stabsvarlist:=taasmoutput.create;
+        stabstypelist:=taasmoutput.create;
+
+        { include symbol that will be referenced from the main to be sure to
           include this debuginfo .o file }
           include this debuginfo .o file }
         if current_module.is_unit then
         if current_module.is_unit then
           begin
           begin
@@ -1297,27 +1405,31 @@ implementation
           end
           end
         else
         else
           st:=current_module.localsymtable;
           st:=current_module.localsymtable;
-        new_section(list,sec_data,st.name^,0);
-        list.concat(tai_symbol.Createname_global(make_mangledname('DEBUGINFO',st,''),AT_DATA,0));
-        { first write all global/local symbols again to a temp list. This will flag
-          all required tdefs. After that the temp list can be removed since the debuginfo is already
-          written to the stabs when the variables/consts were written }
-{$warning Hack to get all needed types}
-        temptypestabs:=taasmoutput.create;
+        new_section(asmlist[al_stabs],sec_data,st.name^,0);
+        asmlist[al_stabs].concat(tai_symbol.Createname_global(make_mangledname('DEBUGINFO',st,''),AT_DATA,0));
+
+        { first write all global/local symbols. This will flag all required tdefs  }
         if assigned(current_module.globalsymtable) then
         if assigned(current_module.globalsymtable) then
-          write_symtable_syms(temptypestabs,current_module.globalsymtable);
+          write_symtable_syms(stabsvarlist,current_module.globalsymtable);
         if assigned(current_module.localsymtable) then
         if assigned(current_module.localsymtable) then
-          write_symtable_syms(temptypestabs,current_module.localsymtable);
-        temptypestabs.free;
+          write_symtable_syms(stabsvarlist,current_module.localsymtable);
+
         { reset unit type info flag }
         { reset unit type info flag }
         reset_unit_type_info;
         reset_unit_type_info;
+
         { write used types from the used units }
         { write used types from the used units }
-        write_used_unit_type_info(list,current_module);
+        write_used_unit_type_info(stabstypelist,current_module);
         { last write the types from this unit }
         { last write the types from this unit }
         if assigned(current_module.globalsymtable) then
         if assigned(current_module.globalsymtable) then
-          write_symtable_defs(list,current_module.globalsymtable);
+          write_symtable_defs(stabstypelist,current_module.globalsymtable);
         if assigned(current_module.localsymtable) then
         if assigned(current_module.localsymtable) then
-          write_symtable_defs(list,current_module.localsymtable);
+          write_symtable_defs(stabstypelist,current_module.localsymtable);
+
+        asmlist[al_stabs].concatlist(stabstypelist);
+        asmlist[al_stabs].concatlist(stabsvarlist);
+
+        stabsvarlist.free;
+        stabstypelist.free;
         aktfilepos:=storefilepos;
         aktfilepos:=storefilepos;
       end;
       end;
 
 
@@ -1393,84 +1505,13 @@ implementation
       end;
       end;
 
 
 
 
-    procedure tdebuginfostabs.insertprocstart(list:taasmoutput);
-      begin
-        insertdef(list,current_procinfo.procdef);
-        Tprocsym(current_procinfo.procdef.procsym).isstabwritten:=true;
-        { write local symtables }
-        if not(po_external in current_procinfo.procdef.procoptions) then
-          begin
-            if assigned(current_procinfo.procdef.parast) then
-              write_symtable_syms(list,current_procinfo.procdef.parast);
-            { local type defs and vars should not be written
-              inside the main proc stab }
-            if assigned(current_procinfo.procdef.localst) and
-               (current_procinfo.procdef.localst.symtabletype=localsymtable) then
-              write_symtable_syms(list,current_procinfo.procdef.localst);
-          end;
-      end;
-
-
-    procedure tdebuginfostabs.insertprocend(list:taasmoutput);
-      var
-        stabsendlabel : tasmlabel;
-        mangled_length : longint;
-        p : pchar;
-        hs : string;
-      begin
-        objectlibrary.getlabel(stabsendlabel,alt_dbgtype);
-        list.concat(tai_label.create(stabsendlabel));
-
-        if assigned(current_procinfo.procdef.funcretsym) and
-           (tabstractnormalvarsym(current_procinfo.procdef.funcretsym).refs>0) then
-          begin
-            if tabstractnormalvarsym(current_procinfo.procdef.funcretsym).localloc.loc=LOC_REFERENCE then
-              begin
-{$warning Need to add gdb support for ret in param register calling}
-                if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
-                  hs:='X*'
-                else
-                  hs:='X';
-                list.concat(Tai_stab.create(stab_stabs,strpnew(
-                   '"'+current_procinfo.procdef.procsym.name+':'+hs+def_stab_number(current_procinfo.procdef.rettype.def)+'",'+
-                   tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
-                if (m_result in aktmodeswitches) then
-                  list.concat(Tai_stab.create(stab_stabs,strpnew(
-                     '"RESULT:'+hs+def_stab_number(current_procinfo.procdef.rettype.def)+'",'+
-                     tostr(N_tsym)+',0,0,'+tostr(tabstractnormalvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
-              end;
-          end;
-        mangled_length:=length(current_procinfo.procdef.mangledname);
-        getmem(p,2*mangled_length+50);
-        strpcopy(p,'192,0,0,');
-        {$IFDEF POWERPC64}strpcopy(strend(p), '.');{$ENDIF POWERPC64}
-        strpcopy(strend(p),current_procinfo.procdef.mangledname);
-        if (target_info.use_function_relative_addresses) then
-          begin
-            strpcopy(strend(p),'-');
-            {$IFDEF POWERPC64}strpcopy(strend(p), '.');{$ENDIF POWERPC64}
-            strpcopy(strend(p),current_procinfo.procdef.mangledname);
-          end;
-        list.concat(Tai_stab.Create(stab_stabn,strnew(p)));
-        strpcopy(p,'224,0,0,'+stabsendlabel.name);
-        if (target_info.use_function_relative_addresses) then
-          begin
-            strpcopy(strend(p),'-');
-            {$IFDEF POWERPC64}strpcopy(strend(p), '.');{$ENDIF POWERPC64}
-            strpcopy(strend(p),current_procinfo.procdef.mangledname);
-          end;
-        list.concat(Tai_stab.Create(stab_stabn,strnew(p)));
-        freemem(p,2*mangled_length+50);
-      end;
-
-
-    procedure tdebuginfostabs.insertmodulestart(list:taasmoutput);
+    procedure tdebuginfostabs.insertmoduleinfo;
       var
       var
         hlabel : tasmlabel;
         hlabel : tasmlabel;
         infile : tinputfile;
         infile : tinputfile;
-        templist:taasmoutput;
+        templist : taasmoutput;
       begin
       begin
-        { emit main source n_sourcefile }
+        { emit main source n_sourcefile for start of module }
         objectlibrary.getlabel(hlabel,alt_dbgfile);
         objectlibrary.getlabel(hlabel,alt_dbgfile);
         infile:=current_module.sourcefiles.get_file(1);
         infile:=current_module.sourcefiles.get_file(1);
         templist:=taasmoutput.create;
         templist:=taasmoutput.create;
@@ -1481,23 +1522,15 @@ implementation
         templist.concat(Tai_stab.Create_str(stab_stabs,'"'+FixFileName(infile.name^)+'",'+tostr(n_sourcefile)+
         templist.concat(Tai_stab.Create_str(stab_stabs,'"'+FixFileName(infile.name^)+'",'+tostr(n_sourcefile)+
                     ',0,0,'+hlabel.name));
                     ',0,0,'+hlabel.name));
         templist.concat(tai_label.create(hlabel));
         templist.concat(tai_label.create(hlabel));
-        list.insertlist(templist);
+        asmlist[al_stabsstart].insertlist(templist);
         templist.free;
         templist.free;
-      end;
-
-
-    procedure tdebuginfostabs.insertmoduleend(list:taasmoutput);
-      var
-        hlabel : tasmlabel;
-        templist:taasmoutput;
-      begin
-        { emit empty n_sourcefile }
+        { emit empty n_sourcefile for end of module }
         objectlibrary.getlabel(hlabel,alt_dbgfile);
         objectlibrary.getlabel(hlabel,alt_dbgfile);
         templist:=taasmoutput.create;
         templist:=taasmoutput.create;
         new_section(templist,sec_code,'',0);
         new_section(templist,sec_code,'',0);
         templist.concat(Tai_stab.Create_str(stab_stabs,'"",'+tostr(n_sourcefile)+',0,0,'+hlabel.name));
         templist.concat(Tai_stab.Create_str(stab_stabs,'"",'+tostr(n_sourcefile)+',0,0,'+hlabel.name));
         templist.concat(tai_label.create(hlabel));
         templist.concat(tai_label.create(hlabel));
-        list.insertlist(templist);
+        asmlist[al_stabsend].insertlist(templist);
         templist.free;
         templist.free;
       end;
       end;
 
 

+ 3 - 16
compiler/ncgutil.pas

@@ -1627,18 +1627,6 @@ implementation
       var
       var
         hs : string;
         hs : string;
       begin
       begin
-        { add symbol entry point as well as debug information                 }
-        { will be inserted in front of the rest of this list.                 }
-        { Insert alignment and assembler names }
-        { Align, gprof uses 16 byte granularity }
-        if (cs_profile in aktmoduleswitches) then
-          list.concat(Tai_align.create(16))
-        else
-          list.concat(Tai_align.create(aktalignment.procalign));
-
-        if (cs_debuginfo in aktmoduleswitches) then
-          debuginfo.insertprocstart(list);
-
         repeat
         repeat
           hs:=current_procinfo.procdef.aliasnames.getfirst;
           hs:=current_procinfo.procdef.aliasnames.getfirst;
           if hs='' then
           if hs='' then
@@ -1651,6 +1639,8 @@ implementation
           if target_info.use_function_relative_addresses then
           if target_info.use_function_relative_addresses then
             list.concat(Tai_function_name.create(hs));
             list.concat(Tai_function_name.create(hs));
         until false;
         until false;
+
+        current_procinfo.procdef.procstarttai:=tai(list.last);
       end;
       end;
 
 
 
 
@@ -1674,8 +1664,7 @@ implementation
 
 
         list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
         list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
 
 
-        if (cs_debuginfo in aktmoduleswitches) then
-          debuginfo.insertprocend(list);
+        current_procinfo.procdef.procendtai:=tai(list.last);
       end;
       end;
 
 
 
 
@@ -1841,8 +1830,6 @@ implementation
         varalign:=var_align(l);
         varalign:=var_align(l);
         maybe_new_object_file(list);
         maybe_new_object_file(list);
         new_section(list,sectype,lower(sym.mangledname),varalign);
         new_section(list,sectype,lower(sym.mangledname),varalign);
-        if (cs_debuginfo in aktmoduleswitches) then
-          debuginfo.insertsym(list,sym);
         if (sym.owner.symtabletype=globalsymtable) or
         if (sym.owner.symtabletype=globalsymtable) or
            maybe_smartlink_symbol or
            maybe_smartlink_symbol or
            DLLSource or
            DLLSource or

+ 0 - 2
compiler/nobj.pas

@@ -1278,8 +1278,6 @@ implementation
         { write debug info }
         { write debug info }
         maybe_new_object_file(asmlist[al_globals]);
         maybe_new_object_file(asmlist[al_globals]);
         new_section(asmlist[al_globals],sec_rodata,_class.vmt_mangledname,const_align(sizeof(aint)));
         new_section(asmlist[al_globals],sec_rodata,_class.vmt_mangledname,const_align(sizeof(aint)));
-        if (cs_debuginfo in aktmoduleswitches) then
-          debuginfo.insertvmt(asmlist[al_globals],_class);
         asmlist[al_globals].concat(Tai_symbol.Createname_global(_class.vmt_mangledname,AT_DATA,0));
         asmlist[al_globals].concat(Tai_symbol.Createname_global(_class.vmt_mangledname,AT_DATA,0));
 
 
          { determine the size with symtable.datasize, because }
          { determine the size with symtable.datasize, because }

+ 4 - 7
compiler/pmodules.pas

@@ -87,14 +87,11 @@ implementation
            KeepShared.Free;
            KeepShared.Free;
          end;
          end;
 
 
-        { Start and end of debuginfo, at least required for stabs
+        { Start and end module debuginfo, at least required for stabs
           to insert n_sourcefile lines }
           to insert n_sourcefile lines }
         if (cs_debuginfo in aktmoduleswitches) or
         if (cs_debuginfo in aktmoduleswitches) or
            (cs_use_lineinfo in aktglobalswitches) then
            (cs_use_lineinfo in aktglobalswitches) then
-          begin
-            debuginfo.insertmodulestart(asmlist[al_debugstart]);
-            debuginfo.insertmoduleend(asmlist[al_debugend]);
-          end;
+          debuginfo.insertmoduleinfo;
 
 
         { create the .s file and assemble it }
         { create the .s file and assemble it }
         GenerateAsm(false);
         GenerateAsm(false);
@@ -1163,7 +1160,7 @@ implementation
 
 
          { generate debuginfo }
          { generate debuginfo }
          if (cs_debuginfo in aktmoduleswitches) then
          if (cs_debuginfo in aktmoduleswitches) then
-           debuginfo.insertmoduletypes(asmlist[al_debugtypes]);
+           debuginfo.inserttypeinfo;
 
 
          { generate wrappers for interfaces }
          { generate wrappers for interfaces }
          gen_intf_wrappers(asmlist[al_procedures],current_module.globalsymtable);
          gen_intf_wrappers(asmlist[al_procedures],current_module.globalsymtable);
@@ -1483,7 +1480,7 @@ implementation
 
 
          { generate debuginfo }
          { generate debuginfo }
          if (cs_debuginfo in aktmoduleswitches) then
          if (cs_debuginfo in aktmoduleswitches) then
-           debuginfo.insertmoduletypes(asmlist[al_debugtypes]);
+           debuginfo.inserttypeinfo;
 
 
          { generate wrappers for interfaces }
          { generate wrappers for interfaces }
          gen_intf_wrappers(asmlist[al_procedures],current_module.localsymtable);
          gen_intf_wrappers(asmlist[al_procedures],current_module.localsymtable);

+ 8 - 1
compiler/psub.pas

@@ -610,6 +610,7 @@ implementation
         oldfilepos : tfileposinfo;
         oldfilepos : tfileposinfo;
         templist : Taasmoutput;
         templist : Taasmoutput;
         headertai : tai;
         headertai : tai;
+        curralign : longint;
       begin
       begin
         { the initialization procedure can be empty, then we
         { the initialization procedure can be empty, then we
           don't need to generate anything. When it was an empty
           don't need to generate anything. When it was an empty
@@ -860,9 +861,15 @@ implementation
                (cs_use_lineinfo in aktglobalswitches) then
                (cs_use_lineinfo in aktglobalswitches) then
               debuginfo.insertlineinfo(aktproccode);
               debuginfo.insertlineinfo(aktproccode);
 
 
+            { gprof uses 16 byte granularity }
+            if (cs_profile in aktmoduleswitches) then
+              curralign:=16
+            else
+              curralign:=aktalignment.procalign;
+
             { add the procedure to the al_procedures }
             { add the procedure to the al_procedures }
             maybe_new_object_file(asmlist[al_procedures]);
             maybe_new_object_file(asmlist[al_procedures]);
-            new_section(asmlist[al_procedures],sec_code,lower(procdef.mangledname),aktalignment.procalign);
+            new_section(asmlist[al_procedures],sec_code,lower(procdef.mangledname),curralign);
             asmlist[al_procedures].concatlist(aktproccode);
             asmlist[al_procedures].concatlist(aktproccode);
             { save local data (casetable) also in the same file }
             { save local data (casetable) also in the same file }
             if assigned(aktlocaldata) and
             if assigned(aktlocaldata) and

+ 8 - 0
compiler/symdef.pas

@@ -502,6 +502,9 @@ interface
 {$ifdef oldregvars}
 {$ifdef oldregvars}
           regvarinfo: pregvarinfo;
           regvarinfo: pregvarinfo;
 {$endif oldregvars}
 {$endif oldregvars}
+          { position in aasmoutput list }
+          procstarttai,
+          procendtai   : tai;
           constructor create(level:byte);
           constructor create(level:byte);
           constructor ppuload(ppufile:tcompilerppufile);
           constructor ppuload(ppufile:tcompilerppufile);
           destructor  destroy;override;
           destructor  destroy;override;
@@ -924,6 +927,11 @@ implementation
           trttisym(inittablesym).lab := nil;
           trttisym(inittablesym).lab := nil;
         localrttilab[initrtti]:=nil;
         localrttilab[initrtti]:=nil;
         localrttilab[fullrtti]:=nil;
         localrttilab[fullrtti]:=nil;
+        if deftype=procdef then
+          begin
+            tprocdef(self).procstarttai:=nil;
+            tprocdef(self).procendtai:=nil;
+          end;
       end;
       end;
 
 
 
 

+ 1 - 1
compiler/symsym.pas

@@ -35,7 +35,7 @@ interface
        ppu,
        ppu,
        cclasses,symnot,
        cclasses,symnot,
        { aasm }
        { aasm }
-       aasmbase,aasmtai,
+       aasmbase,
        cpuinfo,cpubase,cgbase,cgutils,parabase
        cpuinfo,cpubase,cgbase,cgutils,parabase
        ;
        ;
 
 

+ 0 - 6
compiler/systems/t_win.pas

@@ -327,9 +327,6 @@ implementation
                     asmlist[al_imports].concat(Taicpu.Op_ref(A_JMP,S_NO,href));
                     asmlist[al_imports].concat(Taicpu.Op_ref(A_JMP,S_NO,href));
                     asmlist[al_imports].concat(Tai_align.Create_op(4,$90));
                     asmlist[al_imports].concat(Tai_align.Create_op(4,$90));
                   {$endif ARM}
                   {$endif ARM}
-                    if (cs_debuginfo in aktmoduleswitches) and
-                       assigned(hp2.procdef) then
-                      debuginfo.insertdef(asmlist[al_imports],hp2.procdef);
                   end;
                   end;
                  { create head link }
                  { create head link }
                  new_section(asmlist[al_imports],sec_idata7,'',0);
                  new_section(asmlist[al_imports],sec_idata7,'',0);
@@ -489,9 +486,6 @@ implementation
                       asmlist[al_imports].concat(Taicpu.Op_ref(A_JMP,S_NO,href));
                       asmlist[al_imports].concat(Taicpu.Op_ref(A_JMP,S_NO,href));
                       asmlist[al_imports].concat(Tai_align.Create_op(4,$90));
                       asmlist[al_imports].concat(Tai_align.Create_op(4,$90));
                     {$endif ARM}
                     {$endif ARM}
-                      if (cs_debuginfo in aktmoduleswitches) and
-                         assigned(hp2.procdef) then
-                        debuginfo.insertdef(asmlist[al_imports],hp2.procdef);
                       { add jump field to al_imports }
                       { add jump field to al_imports }
                       new_section(asmlist[al_imports],sec_idata5,'',0);
                       new_section(asmlist[al_imports],sec_idata5,'',0);
                       if (cs_debuginfo in aktmoduleswitches) then
                       if (cs_debuginfo in aktmoduleswitches) then