ogmap.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. {
  2. Copyright (c) 2001-2002 by Peter Vreman
  3. Contains the class for generating a map file
  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 ogmap;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,globtype,systems,
  23. { object writer }
  24. aasmbase,ogbase
  25. ;
  26. type
  27. texemap = class
  28. private
  29. t : text;
  30. FImageBase : aint;
  31. public
  32. constructor Create(const s:string);
  33. destructor Destroy;override;
  34. procedure Add(const s:string);
  35. procedure AddHeader(const s:string);
  36. procedure AddCommonSymbolsHeader;
  37. procedure AddCommonSymbol(p:TObjSymbol);
  38. procedure AddMemoryMapHeader(abase:aint);
  39. procedure AddMemoryMapExeSection(p:texesection);
  40. procedure AddMemoryMapObjectSection(p:TObjSection);
  41. procedure AddMemoryMapSymbol(p:TObjSymbol);
  42. end;
  43. var
  44. exemap : texemap;
  45. implementation
  46. uses
  47. cutils,globals,verbose;
  48. {****************************************************************************
  49. TExeMap
  50. ****************************************************************************}
  51. constructor TExeMap.Create(const s:string);
  52. begin
  53. Assign(t,FixFileName(s));
  54. Rewrite(t);
  55. FImageBase:=0;
  56. end;
  57. destructor TExeMap.Destroy;
  58. begin
  59. Close(t);
  60. end;
  61. procedure TExeMap.Add(const s:string);
  62. begin
  63. writeln(t,s);
  64. end;
  65. procedure TExeMap.AddHeader(const s:string);
  66. begin
  67. Add('');
  68. Add(s);
  69. end;
  70. procedure TExeMap.AddCommonSymbolsHeader;
  71. begin
  72. AddHeader('Allocating common symbols');
  73. Add('Common symbol size file');
  74. Add('');
  75. end;
  76. procedure TExeMap.AddCommonSymbol(p:TObjSymbol);
  77. var
  78. s : string;
  79. begin
  80. { Common symbol size file }
  81. s:=p.name;
  82. if length(s)>20 then
  83. begin
  84. writeln(t,p.name);
  85. s:='';
  86. end;
  87. Add(PadSpace(s,20)+'0x'+PadSpace(hexstr(p.size,1),16)+p.objsection.objdata.name);
  88. end;
  89. procedure TExeMap.AddMemoryMapHeader(abase:aint);
  90. var
  91. imagebasestr : string;
  92. begin
  93. FImageBase:=abase;
  94. if FImageBase<>0 then
  95. imagebasestr:=' (ImageBase='+HexStr(FImageBase,sizeof(aint)*2)+')'
  96. else
  97. imagebasestr:='';
  98. AddHeader('Memory map'+imagebasestr);
  99. Add('');
  100. end;
  101. procedure TExeMap.AddMemoryMapExeSection(p:texesection);
  102. begin
  103. { .text 0x000018a8 0xd958 }
  104. Add(PadSpace(p.name,19)+PadSpace(' 0x'+HexStr(p.mempos+Fimagebase,sizeof(aint)*2),12)+
  105. ' 0x'+HexStr(p.size,sizeof(aint)));
  106. end;
  107. procedure TExeMap.AddMemoryMapObjectSection(p:TObjSection);
  108. var
  109. secname : string;
  110. begin
  111. { .text 0x000018a8 0xd958 object.o }
  112. secname:=p.name;
  113. if Length(secname)>18 then
  114. begin
  115. Add(' '+secname);
  116. secname:='';
  117. end;
  118. Add(' '+PadSpace(secname,18)+PadSpace(' 0x'+HexStr(p.mempos+FImageBase,sizeof(aint)*2),12)+
  119. ' 0x'+HexStr(p.size,sizeof(aint))+' '+p.objdata.name);
  120. end;
  121. procedure TExeMap.AddMemoryMapSymbol(p:TObjSymbol);
  122. begin
  123. { 0x00001e30 setup_screens }
  124. Add(Space(20)+PadSpace('0x'+HexStr(p.address+Fimagebase,sizeof(aint)*2),25)+' '+p.name);
  125. end;
  126. end.