Forráskód Böngészése

Merged revisions 9425-9427,9429,9447 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r9425 | jonas | 2007-12-10 23:09:12 +0100 (Mon, 10 Dec 2007) | 5 lines

* finish the lineinfo table with a DW_LNE_set_address of the last
instruction of the function, like in the example in the dwarf2
specifications appendix 3 and as done by gcc (expected by Apple's
dsymutil)

........
r9426 | jonas | 2007-12-11 14:10:39 +0100 (Tue, 11 Dec 2007) | 5 lines

* dsymutil under darwin "smart links" dwarf info -> make sure we
use the DW_TAG_typedef entries, because without them a type is
only locally visible in the file where it is declared (see
comments)

........
r9427 | jonas | 2007-12-11 19:55:48 +0100 (Tue, 11 Dec 2007) | 4 lines

* write name of "self" as "this", so you can use plain field names inside
methods in gdb without having to write "self.fieldname" (self is also
still recognised by gdb, that's built in)

........
r9429 | jonas | 2007-12-11 20:40:00 +0100 (Tue, 11 Dec 2007) | 2 lines

* fixed vmt format type definition

........
r9447 | jonas | 2007-12-14 19:00:35 +0100 (Fri, 14 Dec 2007) | 4 lines

* always let mangled names start with an underscore on Mac OS X, because
otherwise the linker does not generate the necessary debug map
information for global variables when using dwarf

........

git-svn-id: branches/fixes_2_2@9462 -

Jonas Maebe 18 éve
szülő
commit
e102e9c113
3 módosított fájl, 91 hozzáadás és 14 törlés
  1. 77 9
      compiler/dbgdwarf.pas
  2. 9 3
      compiler/psystem.pas
  3. 5 2
      compiler/symdef.pas

+ 77 - 9
compiler/dbgdwarf.pas

@@ -1532,6 +1532,52 @@ implementation
         else
           current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
 
+        if (target_info.system in systems_darwin) then
+          begin
+            { On Darwin, dwarf info is not linked in the final binary,
+              but kept in the individual object files. This allows for
+              faster linking, but means that you have to keep the object
+              files for debugging and also that gdb only loads in the
+              debug info of a particular object file once you step into
+              or over a procedure in it.
+              
+              To solve this, there is a tool called dsymutil which can
+              extract all the dwarf info from a program's object files.
+              This utility however performs "smart linking" on the dwarf
+              info and throws away all unreferenced dwarf entries. Since
+              variables' types always point to the dwarfino for a tdef
+              and never to that for a typesym, this means all debug
+              entries generated for typesyms are thrown away.
+              
+              The problem with that is that we translate typesyms into
+              DW_TAG_typedef, and gdb's dwarf-2 reader only makes types
+              globally visibly if they are defined using a DW_TAG_typedef.
+              So as a result, before running dsymutil types only become
+              available once you stepped into/over a function in the object
+              file where they are declared, and after running dsymutil they
+              are all gone (printng variables still works because the
+              tdef dwarf info is still available, but you cannot typecast
+              anything outside the declaring units because the type names
+              are not known there).
+              
+              The solution: if a tdef has an associated typesym, let the
+              debug label for the tdef point to a DW_TAG_typedef instead
+              of directly to the tdef itself. And don't write anything
+              special for the typesym itself.
+            }
+          if assigned(def.typesym) and
+             not(df_generic in def.defoptions) then
+            begin
+              current_asmdata.getaddrlabel(TAsmLabel(pointer(labsym)));
+              append_entry(DW_TAG_typedef,false,[
+                DW_AT_name,DW_FORM_string,symname(def.typesym)+#0
+              ]);
+              append_labelentry_ref(DW_AT_type,labsym);
+              finish_entry;
+              current_asmdata.asmlists[al_dwarf_info].concat(tai_symbol.create(labsym,0));
+            end;
+          end;
+
         case def.typ of
           stringdef :
             appenddef_string(tstringdef(def));
@@ -2006,14 +2052,20 @@ implementation
 
       procedure TDebugInfoDwarf.appendsym_type(sym: ttypesym);
         begin
-          if not(df_generic in sym.typedef.defoptions) then
+          if not (target_info.system in systems_darwin) then
             begin
-              append_entry(DW_TAG_typedef,false,[
-                DW_AT_name,DW_FORM_string,symname(sym)+#0
-              ]);
-              append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.typedef));
-            end;
-          finish_entry;
+              if not(df_generic in sym.typedef.defoptions) then
+                begin
+                  append_entry(DW_TAG_typedef,false,[
+                    DW_AT_name,DW_FORM_string,symname(sym)+#0
+                  ]);
+                  append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.typedef));
+                end;
+              finish_entry;
+            end
+          else
+            { just queue the def if needed }
+            def_dwarf_lab(sym.typedef);
 
           (* Moved fom append sym, do we need this (MWE)
           { For object types write also the symtable entries }
@@ -2486,7 +2538,11 @@ implementation
 
     function TDebugInfoDwarf.symname(sym: tsym): String;
       begin
-        result := sym.Name;
+        if (sym.typ=paravarsym) and
+           (vo_is_self in tlocalvarsym(sym).varoptions) then
+          result:='this'
+        else
+          result := sym.Name;
       end;
 
 
@@ -2496,7 +2552,7 @@ implementation
         lastfileinfo : tfileposinfo;
         currfuncname : pshortstring;
         currsectype  : TAsmSectiontype;
-        hp : tai;
+        hp, hpend : tai;
         infile : tinputfile;
         prevcolumn,
         diffline,
@@ -2619,9 +2675,21 @@ implementation
                 lastfileinfo:=currfileinfo;
               end;
 
+            hpend:=hp;
             hp:=tai(hp.next);
           end;
 
+        if assigned(hpend) then
+          begin
+           { set address for end (see appendix 3 of dwarf 2 specs) }
+            current_asmdata.getlabel(currlabel, alt_dbgline);
+            list.insertafter(tai_label.create(currlabel), hpend);
+            asmline.concat(tai_const.create_8bit(DW_LNS_extended_op));
+            asmline.concat(tai_const.create_uleb128bit(1+sizeof(aint)));
+            asmline.concat(tai_const.create_8bit(DW_LNE_set_address));
+            asmline.concat(tai_const.create_sym(currlabel));
+          end;
+
         { end sequence }
         asmline.concat(tai_const.Create_8bit(DW_LNS_extended_op));
         asmline.concat(tai_const.Create_8bit(1));

+ 9 - 3
compiler/psystem.pas

@@ -306,10 +306,16 @@ implementation
           type is not available. The rtti for pvmt will be written implicitly
           by thev tblarray below }
         systemunit.insert(ttypesym.create('$pvmt',pvmttype));
+        hrecst.insertfield(tfieldvarsym.create('$length',vs_value,ptrsinttype,[]));
+        hrecst.insertfield(tfieldvarsym.create('$mlength',vs_value,ptrsinttype,[]));
         hrecst.insertfield(tfieldvarsym.create('$parent',vs_value,pvmttype,[]));
-        hrecst.insertfield(tfieldvarsym.create('$length',vs_value,s32inttype,[]));
-        hrecst.insertfield(tfieldvarsym.create('$mlength',vs_value,s32inttype,[]));
-        vmtarraytype:=tarraydef.create(0,1,s32inttype);
+        { it seems vmttype is used both for TP objects and Delphi classes,
+          so the next entry could either be the first virtual method (vm1)
+          (object) or the class name (class). We can't easily create separate
+          vtable formats for both, as gdb is hard coded to search for
+          __vtbl_ptr_type in all cases (JM) }
+        hrecst.insertfield(tfieldvarsym.create('$vm1_or_classname',vs_value,tpointerdef.create(cshortstringtype),[]));
+        vmtarraytype:=tarraydef.create(0,0,s32inttype);
         tarraydef(vmtarraytype).elementdef:=voidpointertype;
         hrecst.insertfield(tfieldvarsym.create('$__pfn',vs_value,vmtarraytype,[]));
         addtype('$__vtbl_ptr_type',vmttype);

+ 5 - 2
compiler/symdef.pas

@@ -815,8 +815,11 @@ implementation
         if suffix<>'' then
           result:=result+'_'+suffix;
         { the Darwin assembler assumes that all symbols starting with 'L' are local }
-        if (target_info.system in systems_darwin) and
-           (result[1] = 'L') then
+        { Further, the Mac OS X 10.5 linker does not consider symbols which do not  }
+        { start with '_' as regular symbols (it does not generate N_GSYM entries    }
+        { those in the debug map, leading to troubles with dsymutil). So always     }
+        { add an underscore on darwin.                                              }
+        if (target_info.system in systems_darwin) then
           result := '_' + result;
       end;