dbgdwarf.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. {
  2. Copyright (c) 2003-2006 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. currfileidx : longint;
  26. procedure insertlineinfo(list:taasmoutput);override;
  27. end;
  28. implementation
  29. uses
  30. cutils,
  31. globals,
  32. Systems,
  33. aasmbase,
  34. finput,
  35. fmodule;
  36. const
  37. dbg_dwarf_info : tdbginfo =
  38. (
  39. id : dbg_dwarf;
  40. idtxt : 'DWARF';
  41. );
  42. procedure tdebuginfodwarf.insertlineinfo(list:taasmoutput);
  43. var
  44. currfileinfo,
  45. lastfileinfo : tfileposinfo;
  46. currfuncname : pstring;
  47. currsectype : tasmsectiontype;
  48. hlabel : tasmlabel;
  49. hp : tai;
  50. infile : tinputfile;
  51. begin
  52. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  53. currfuncname:=nil;
  54. currsectype:=sec_code;
  55. hp:=Tai(list.first);
  56. while assigned(hp) do
  57. begin
  58. case hp.typ of
  59. ait_section :
  60. currsectype:=tai_section(hp).sectype;
  61. ait_function_name :
  62. currfuncname:=tai_function_name(hp).funcname;
  63. ait_force_line :
  64. lastfileinfo.line:=-1;
  65. end;
  66. if (currsectype=sec_code) and
  67. (hp.typ=ait_instruction) then
  68. begin
  69. currfileinfo:=tailineinfo(hp).fileinfo;
  70. { file changed ? (must be before line info) }
  71. if (currfileinfo.fileindex<>0) and
  72. (lastfileinfo.fileindex<>currfileinfo.fileindex) then
  73. begin
  74. infile:=current_module.sourcefiles.get_file(currfileinfo.fileindex);
  75. if assigned(infile) then
  76. begin
  77. inc(currfileidx);
  78. if (infile.path^<>'') then
  79. list.insertbefore(tai_file.create(
  80. BsToSlash(FixPath(infile.path^,false)+FixFileName(infile.name^)),currfileidx
  81. ),hp)
  82. else
  83. list.insertbefore(tai_file.create(
  84. FixFileName(infile.name^),currfileidx),hp);
  85. { force new line info }
  86. lastfileinfo.line:=-1;
  87. end;
  88. end;
  89. { line changed ? }
  90. if (lastfileinfo.line<>currfileinfo.line) and (currfileinfo.line<>0) then
  91. list.insertbefore(tai_loc.create(
  92. currfileidx,currfileinfo.line,currfileinfo.column),hp);
  93. lastfileinfo:=currfileinfo;
  94. end;
  95. hp:=tai(hp.next);
  96. end;
  97. end;
  98. initialization
  99. RegisterDebugInfo(dbg_dwarf_info,TDebugInfoDwarf);
  100. end.