dbgbase.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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;
  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:taasmoutput);virtual;
  33. procedure referencesections(list:taasmoutput);virtual;
  34. procedure insertdef(list:taasmoutput;def:tdef);virtual;abstract;
  35. procedure write_symtable_defs(list:taasmoutput;st:tsymtable);virtual;abstract;
  36. procedure write_used_unit_type_info(list:taasmoutput;hp:tmodule);
  37. procedure field_write_defs(p:Tnamedindexitem;arg:pointer);
  38. procedure method_write_defs(p :tnamedindexitem;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:taasmoutput);
  60. begin
  61. end;
  62. procedure tdebuginfo.referencesections(list:taasmoutput);
  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:Tnamedindexitem;arg:pointer);
  77. begin
  78. if (Tsym(p).typ=fieldvarsym) and
  79. not(sp_static in Tsym(p).symoptions) then
  80. insertdef(taasmoutput(arg),tfieldvarsym(p).vartype.def);
  81. end;
  82. procedure TDebugInfo.method_write_defs(p :tnamedindexitem;arg:pointer);
  83. var
  84. pd : tprocdef;
  85. begin
  86. if tsym(p).typ=procsym then
  87. begin
  88. pd:=tprocsym(p).first_procdef;
  89. insertdef(taasmoutput(arg),pd.rettype.def);
  90. end;
  91. end;
  92. procedure TDebugInfo.write_used_unit_type_info(list:taasmoutput;hp:tmodule);
  93. var
  94. pu : tused_unit;
  95. begin
  96. pu:=tused_unit(hp.used_units.first);
  97. while assigned(pu) do
  98. begin
  99. if not pu.u.is_dbginfo_written then
  100. begin
  101. { prevent infinte loop for circular dependencies }
  102. pu.u.is_dbginfo_written:=true;
  103. { write type info from used units, use a depth first
  104. strategy to reduce the recursion in writing all
  105. dependent stabs }
  106. write_used_unit_type_info(list,pu.u);
  107. if assigned(pu.u.globalsymtable) then
  108. write_symtable_defs(list,pu.u.globalsymtable);
  109. end;
  110. pu:=tused_unit(pu.next);
  111. end;
  112. end;
  113. procedure InitDebugInfo;
  114. begin
  115. if not assigned(CDebugInfo[target_dbg.id]) then
  116. begin
  117. Comment(V_Fatal,'cg_f_debuginfo_output_not_supported');
  118. exit;
  119. end;
  120. DebugInfo:=CDebugInfo[target_dbg.id].Create;
  121. end;
  122. procedure DoneDebugInfo;
  123. begin
  124. if assigned(DebugInfo) then
  125. begin
  126. DebugInfo.Free;
  127. DebugInfo:=nil;
  128. end;
  129. end;
  130. procedure RegisterDebugInfo(const r:tdbginfo;c:TDebugInfoClass);
  131. var
  132. t : tdbg;
  133. begin
  134. t:=r.id;
  135. if assigned(dbginfos[t]) then
  136. writeln('Warning: DebugInfo is already registered!')
  137. else
  138. Getmem(dbginfos[t],sizeof(tdbginfo));
  139. dbginfos[t]^:=r;
  140. CDebugInfo[t]:=c;
  141. end;
  142. const
  143. dbg_none_info : tdbginfo =
  144. (
  145. id : dbg_none;
  146. idtxt : 'NONE';
  147. );
  148. initialization
  149. RegisterDebugInfo(dbg_none_info,tdebuginfo);
  150. end.