2
0

ogmap.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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,cfileutils,
  48. globals,verbose;
  49. {****************************************************************************
  50. TExeMap
  51. ****************************************************************************}
  52. constructor TExeMap.Create(const s:string);
  53. begin
  54. Assign(t,FixFileName(s));
  55. Rewrite(t);
  56. FImageBase:=0;
  57. end;
  58. destructor TExeMap.Destroy;
  59. begin
  60. Close(t);
  61. end;
  62. procedure TExeMap.Add(const s:string);
  63. begin
  64. writeln(t,s);
  65. end;
  66. procedure TExeMap.AddHeader(const s:string);
  67. begin
  68. Add('');
  69. Add(s);
  70. end;
  71. procedure TExeMap.AddCommonSymbolsHeader;
  72. begin
  73. AddHeader('Allocating common symbols');
  74. Add('Common symbol size file');
  75. Add('');
  76. end;
  77. procedure TExeMap.AddCommonSymbol(p:TObjSymbol);
  78. var
  79. s : string;
  80. begin
  81. { Common symbol size file }
  82. s:=p.name;
  83. if length(s)>20 then
  84. begin
  85. writeln(t,p.name);
  86. s:='';
  87. end;
  88. Add(PadSpace(s,20)+'0x'+PadSpace(hexstr(p.size,1),16)+p.objsection.objdata.name);
  89. end;
  90. procedure TExeMap.AddMemoryMapHeader(abase:aint);
  91. var
  92. imagebasestr : string;
  93. begin
  94. FImageBase:=abase;
  95. if FImageBase<>0 then
  96. imagebasestr:=' (ImageBase='+HexStr(FImageBase,sizeof(aint)*2)+')'
  97. else
  98. imagebasestr:='';
  99. AddHeader('Memory map'+imagebasestr);
  100. Add('');
  101. end;
  102. procedure TExeMap.AddMemoryMapExeSection(p:texesection);
  103. begin
  104. { .text 0x000018a8 0xd958 }
  105. Add(PadSpace(p.name,19)+PadSpace(' 0x'+HexStr(p.mempos+Fimagebase,sizeof(aint)*2),12)+
  106. ' 0x'+HexStr(p.size,sizeof(aint)));
  107. end;
  108. procedure TExeMap.AddMemoryMapObjectSection(p:TObjSection);
  109. var
  110. secname : string;
  111. begin
  112. { .text 0x000018a8 0xd958 object.o }
  113. secname:=p.name;
  114. if Length(secname)>18 then
  115. begin
  116. Add(' '+secname);
  117. secname:='';
  118. end;
  119. Add(' '+PadSpace(secname,18)+PadSpace(' 0x'+HexStr(p.mempos+FImageBase,sizeof(aint)*2),12)+
  120. ' 0x'+HexStr(p.size,sizeof(aint))+' '+p.objdata.name);
  121. end;
  122. procedure TExeMap.AddMemoryMapSymbol(p:TObjSymbol);
  123. begin
  124. { 0x00001e30 setup_screens }
  125. Add(Space(20)+PadSpace('0x'+HexStr(p.address+Fimagebase,sizeof(aint)*2),25)+' '+p.name);
  126. end;
  127. end.