2
0

dbgbase.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. {
  2. Copyright (c) 2003-2006 by Peter Vreman and Florian Klaempfl
  3. This units contains the base class for debug info generation
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit dbgbase;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. systems,
  23. symconst,symbase,symdef,symtype,symsym,symtable,
  24. fmodule,
  25. aasmtai,aasmdata;
  26. type
  27. TDebugInfo=class
  28. constructor Create;virtual;
  29. procedure reset_unit_type_info;
  30. procedure inserttypeinfo;virtual;
  31. procedure insertmoduleinfo;virtual;
  32. procedure insertlineinfo(list:TAsmList);virtual;
  33. procedure referencesections(list:TAsmList);virtual;
  34. procedure insertdef(list:TAsmList;def:tdef);virtual;abstract;
  35. procedure write_symtable_defs(list:TAsmList;st:TSymtable);virtual;abstract;
  36. procedure write_used_unit_type_info(list:TAsmList;hp:tmodule);
  37. procedure field_write_defs(p:TObject;arg:pointer);
  38. procedure method_write_defs(p:TObject;arg:pointer);
  39. end;
  40. TDebugInfoClass=class of TDebugInfo;
  41. var
  42. CDebugInfo : array[tdbg] of TDebugInfoClass;
  43. DebugInfo : TDebugInfo;
  44. procedure InitDebugInfo;
  45. procedure DoneDebugInfo;
  46. procedure RegisterDebugInfo(const r:tdbginfo;c:TDebugInfoClass);
  47. implementation
  48. uses
  49. verbose;
  50. constructor tdebuginfo.Create;
  51. begin
  52. end;
  53. procedure tdebuginfo.insertmoduleinfo;
  54. begin
  55. end;
  56. procedure tdebuginfo.inserttypeinfo;
  57. begin
  58. end;
  59. procedure tdebuginfo.insertlineinfo(list:TAsmList);
  60. begin
  61. end;
  62. procedure tdebuginfo.referencesections(list:TAsmList);
  63. begin
  64. end;
  65. procedure tdebuginfo.reset_unit_type_info;
  66. var
  67. hp : tmodule;
  68. begin
  69. hp:=tmodule(loaded_units.first);
  70. while assigned(hp) do
  71. begin
  72. hp.is_dbginfo_written:=false;
  73. hp:=tmodule(hp.next);
  74. end;
  75. end;
  76. procedure TDebugInfo.field_write_defs(p:TObject;arg:pointer);
  77. begin
  78. if (Tsym(p).typ=fieldvarsym) and
  79. not(sp_static in Tsym(p).symoptions) then
  80. insertdef(TAsmList(arg),tfieldvarsym(p).vardef);
  81. end;
  82. procedure TDebugInfo.method_write_defs(p:TObject;arg:pointer);
  83. var
  84. i : longint;
  85. pd : tprocdef;
  86. begin
  87. if tsym(p).typ<>procsym then
  88. exit;
  89. for i:=0 to tprocsym(p).ProcdefList.Count-1 do
  90. begin
  91. pd:=tprocdef(tprocsym(p).ProcdefList[i]);
  92. insertdef(TAsmList(arg),pd.returndef);
  93. if (po_virtualmethod in pd.procoptions) then
  94. insertdef(TAsmList(arg),pd._class);
  95. if assigned(pd.parast) then
  96. write_symtable_defs(TAsmList(arg),pd.parast);
  97. if assigned(pd.localst) then
  98. write_symtable_defs(TAsmList(arg),pd.localst);
  99. end;
  100. end;
  101. procedure TDebugInfo.write_used_unit_type_info(list:TAsmList;hp:tmodule);
  102. var
  103. pu : tused_unit;
  104. begin
  105. pu:=tused_unit(hp.used_units.first);
  106. while assigned(pu) do
  107. begin
  108. if not pu.u.is_dbginfo_written then
  109. begin
  110. { prevent infinte loop for circular dependencies }
  111. pu.u.is_dbginfo_written:=true;
  112. { write type info from used units, use a depth first
  113. strategy to reduce the recursion in writing all
  114. dependent stabs }
  115. write_used_unit_type_info(list,pu.u);
  116. if assigned(pu.u.globalsymtable) then
  117. write_symtable_defs(list,pu.u.globalsymtable);
  118. end;
  119. pu:=tused_unit(pu.next);
  120. end;
  121. end;
  122. procedure InitDebugInfo;
  123. begin
  124. if not assigned(CDebugInfo[target_dbg.id]) then
  125. begin
  126. Comment(V_Fatal,'cg_f_debuginfo_output_not_supported');
  127. exit;
  128. end;
  129. DebugInfo:=CDebugInfo[target_dbg.id].Create;
  130. end;
  131. procedure DoneDebugInfo;
  132. begin
  133. if assigned(DebugInfo) then
  134. begin
  135. DebugInfo.Free;
  136. DebugInfo:=nil;
  137. end;
  138. end;
  139. procedure RegisterDebugInfo(const r:tdbginfo;c:TDebugInfoClass);
  140. var
  141. t : tdbg;
  142. begin
  143. t:=r.id;
  144. if assigned(dbginfos[t]) then
  145. writeln('Warning: DebugInfo is already registered!')
  146. else
  147. Getmem(dbginfos[t],sizeof(tdbginfo));
  148. dbginfos[t]^:=r;
  149. CDebugInfo[t]:=c;
  150. end;
  151. const
  152. dbg_none_info : tdbginfo =
  153. (
  154. id : dbg_none;
  155. idtxt : 'NONE';
  156. );
  157. initialization
  158. RegisterDebugInfo(dbg_none_info,tdebuginfo);
  159. end.