/compiler/jvm/dbgjasm.pas

https://github.com/slibre/freepascal · Pascal · 202 lines · 134 code · 33 blank · 35 comment · 9 complexity · 8d4cd1db5f8fb41946032e936586f79a MD5 · raw file

  1. {
  2. Copyright (c) 2003-2006 by Peter Vreman, Florian Klaempfl, and Jonas Maebe
  3. This units contains support for Jasmin 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 dbgjasm;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,globtype,
  22. aasmbase,aasmtai,aasmdata,
  23. symbase,symconst,symtype,symdef,symsym,
  24. finput,
  25. DbgBase;
  26. type
  27. { TDebugInfoJasmin }
  28. TDebugInfoJasmin=class(TDebugInfo)
  29. protected
  30. fcurrprocstart,
  31. fcurrprocend: tasmsymbol;
  32. procedure appendsym_localsym(list: TAsmList; sym: tabstractnormalvarsym);
  33. procedure appendsym_paravar(list:TAsmList;sym:tparavarsym);override;
  34. procedure appendsym_localvar(list:TAsmList;sym:tlocalvarsym);override;
  35. procedure beforeappenddef(list:TAsmList;def:tdef);override;
  36. procedure appendprocdef(list:TAsmList;def:tprocdef);override;
  37. public
  38. procedure inserttypeinfo;override;
  39. procedure insertlineinfo(list:TAsmList);override;
  40. end;
  41. implementation
  42. uses
  43. sysutils,cutils,cfileutl,constexp,
  44. version,globals,verbose,systems,
  45. cpubase,cpuinfo,cgbase,paramgr,
  46. fmodule,
  47. defutil,symtable,jvmdef,ppu
  48. ;
  49. {****************************************************************************
  50. TDebugInfoJasmin
  51. ****************************************************************************}
  52. procedure TDebugInfoJasmin.appendsym_localsym(list: TAsmList; sym: tabstractnormalvarsym);
  53. var
  54. jvar: tai_jvar;
  55. proc: tprocdef;
  56. begin
  57. if tdef(sym.owner.defowner).typ<>procdef then
  58. exit;
  59. if not(sym.localloc.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  60. exit;
  61. proc:=tprocdef(sym.owner.defowner);
  62. jvar:=tai_jvar.create(sym.localloc.reference.offset,jvmmangledbasename(sym,true),fcurrprocstart,fcurrprocend);
  63. proc.exprasmlist.InsertAfter(jvar,proc.procstarttai);
  64. end;
  65. procedure TDebugInfoJasmin.appendsym_paravar(list: TAsmList; sym: tparavarsym);
  66. begin
  67. appendsym_localsym(list,sym);
  68. end;
  69. procedure TDebugInfoJasmin.appendsym_localvar(list: TAsmList; sym: tlocalvarsym);
  70. begin
  71. appendsym_localsym(list,sym);
  72. end;
  73. procedure TDebugInfoJasmin.beforeappenddef(list: TAsmList; def: tdef);
  74. begin
  75. end;
  76. procedure TDebugInfoJasmin.appendprocdef(list: TAsmList; def: tprocdef);
  77. var
  78. procstartlabel,
  79. procendlabel : tasmlabel;
  80. begin
  81. { insert debug information for local variables and parameters, but only
  82. for routines implemented in the Pascal code }
  83. if not assigned(def.procstarttai) then
  84. exit;
  85. current_asmdata.getlabel(procstartlabel,alt_dbgtype);
  86. current_asmdata.getlabel(procendlabel,alt_dbgtype);
  87. def.exprasmlist.insertafter(tai_label.create(procstartlabel),def.procstarttai);
  88. def.exprasmlist.insertbefore(tai_label.create(procendlabel),def.procendtai);
  89. fcurrprocstart:=procstartlabel;
  90. fcurrprocend:=procendlabel;
  91. write_symtable_parasyms(list,def.paras);
  92. { not assigned for unit init }
  93. if assigned(def.localst) then
  94. write_symtable_syms(list,def.localst);
  95. end;
  96. procedure TDebugInfoJasmin.inserttypeinfo;
  97. begin
  98. { write all procedures and methods }
  99. if assigned(current_module.globalsymtable) then
  100. write_symtable_procdefs(nil,current_module.globalsymtable);
  101. if assigned(current_module.localsymtable) then
  102. write_symtable_procdefs(nil,current_module.localsymtable);
  103. end;
  104. procedure TDebugInfoJasmin.insertlineinfo(list: TAsmList);
  105. var
  106. currfileinfo,
  107. lastfileinfo : tfileposinfo;
  108. nolineinfolevel : Integer;
  109. currfuncname : pshortstring;
  110. hp : tai;
  111. begin
  112. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  113. hp:=Tai(list.first);
  114. nolineinfolevel:=0;
  115. while assigned(hp) do
  116. begin
  117. case hp.typ of
  118. ait_function_name :
  119. begin
  120. currfuncname:=tai_function_name(hp).funcname;
  121. list.concat(tai_comment.Create(strpnew('function: '+currfuncname^)));
  122. end;
  123. ait_force_line :
  124. begin
  125. lastfileinfo.line:=-1;
  126. end;
  127. ait_marker :
  128. begin
  129. case tai_marker(hp).kind of
  130. mark_NoLineInfoStart:
  131. inc(nolineinfolevel);
  132. mark_NoLineInfoEnd:
  133. dec(nolineinfolevel);
  134. end;
  135. end;
  136. end;
  137. { Java does not support multiple source files }
  138. if (hp.typ=ait_instruction) and
  139. (nolineinfolevel=0) and
  140. (tailineinfo(hp).fileinfo.fileindex=main_module.unit_index) then
  141. begin
  142. currfileinfo:=tailineinfo(hp).fileinfo;
  143. { line changed ? }
  144. if (lastfileinfo.line<>currfileinfo.line) and (currfileinfo.line<>0) then
  145. begin
  146. { line directive }
  147. list.insertbefore(tai_directive.Create(asd_jline,tostr(currfileinfo.line)),hp);
  148. end;
  149. lastfileinfo:=currfileinfo;
  150. end;
  151. hp:=tai(hp.next);
  152. end;
  153. end;
  154. {****************************************************************************
  155. ****************************************************************************}
  156. const
  157. dbg_jasmin_info : tdbginfo =
  158. (
  159. id : dbg_jasmin;
  160. idtxt : 'JASMIN';
  161. );
  162. initialization
  163. RegisterDebugInfo(dbg_jasmin_info,TDebugInfoJasmin);
  164. end.