dbgdwarf.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. {
  2. Copyright (c) 2003-2004 by Peter Vreman and Florian Klaempfl
  3. This units contains support for DWARF 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 dbgdwarf;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. aasmtai,
  22. DbgBase;
  23. type
  24. TDebugInfoDwarf=class(TDebugInfo)
  25. procedure insertlineinfo(list:taasmoutput);override;
  26. end;
  27. implementation
  28. uses
  29. Systems;
  30. const
  31. dbg_dwarf_info : tdbginfo =
  32. (
  33. id : dbg_dwarf;
  34. idtxt : 'DWARF';
  35. );
  36. procedure tdebuginfodwarf.insertlineinfo(list:taasmoutput);
  37. begin
  38. end;
  39. {
  40. var
  41. currfileinfo,
  42. lastfileinfo : tfileposinfo;
  43. currfuncname : pstring;
  44. currsectype : tasmsectiontype;
  45. hlabel : tasmlabel;
  46. hp : tai;
  47. infile : tinputfile;
  48. begin
  49. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  50. currfuncname:=nil;
  51. currsectype:=sec_code;
  52. hp:=Tai(list.first);
  53. while assigned(hp) do
  54. begin
  55. case hp.typ of
  56. ait_section :
  57. currsectype:=tai_section(hp).sectype;
  58. ait_function_name :
  59. currfuncname:=tai_function_name(hp).funcname;
  60. ait_force_line :
  61. lastfileinfo.line:=-1;
  62. end;
  63. if (currsectype=sec_code) and
  64. (hp.typ=ait_instruction) then
  65. begin
  66. currfileinfo:=tailineinfo(hp).fileinfo;
  67. { file changed ? (must be before line info) }
  68. if (currfileinfo.fileindex<>0) and
  69. (lastfileinfo.fileindex<>currfileinfo.fileindex) then
  70. begin
  71. infile:=current_module.sourcefiles.get_file(currfileinfo.fileindex);
  72. if assigned(infile) then
  73. begin
  74. objectlibrary.getlabel(hlabel,alt_dbgfile);
  75. { emit stabs }
  76. if (infile.path^<>'') then
  77. list.insertbefore(Tai_stab.Create_str(stab_stabs,'"'+BsToSlash(FixPath(infile.path^,false))+'",'+tostr(n_includefile)+
  78. ',0,0,'+hlabel.name),hp);
  79. list.insertbefore(Tai_stab.Create_str(stab_stabs,'"'+FixFileName(infile.name^)+'",'+tostr(n_includefile)+
  80. ',0,0,'+hlabel.name),hp);
  81. list.insertbefore(tai_label.create(hlabel),hp);
  82. { force new line info }
  83. lastfileinfo.line:=-1;
  84. end;
  85. end;
  86. { line changed ? }
  87. if (lastfileinfo.line<>currfileinfo.line) and (currfileinfo.line<>0) then
  88. begin
  89. if assigned(currfuncname) and
  90. (tf_use_function_relative_addresses in target_info.flags) then
  91. begin
  92. objectlibrary.getlabel(hlabel,alt_dbgline);
  93. list.insertbefore(Tai_stab.Create_str(stab_stabn,tostr(n_textline)+',0,'+tostr(currfileinfo.line)+','+
  94. hlabel.name+' - '+{$IFDEF POWERPC64}'.'+{$ENDIF POWERPC64}currfuncname^),hp);
  95. list.insertbefore(tai_label.create(hlabel),hp);
  96. end
  97. else
  98. list.insertbefore(Tai_stab.Create_str(stab_stabd,tostr(n_textline)+',0,'+tostr(currfileinfo.line)),hp);
  99. end;
  100. lastfileinfo:=currfileinfo;
  101. end;
  102. hp:=tai(hp.next);
  103. end;
  104. end;
  105. }
  106. initialization
  107. RegisterDebugInfo(dbg_dwarf_info,TDebugInfoDwarf);
  108. end.