og386dbg.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Peter Vreman
  4. Contains the 386 binary writer for debugging purposes
  5. * This code was inspired by the NASM sources
  6. The Netwide Assembler is copyright (C) 1996 Simon Tatham and
  7. Julian Hall. All rights reserved.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. ****************************************************************************
  20. }
  21. unit og386dbg;
  22. interface
  23. uses
  24. systems,aasm,cpubase,og386;
  25. type
  26. pdbgoutput = ^tdbgoutput;
  27. tdbgoutput = object(tobjectoutput)
  28. nsyms : longint;
  29. rawidx : longint;
  30. constructor init(smart:boolean);
  31. destructor done;virtual;
  32. procedure initwriting(Aplace:tcutplace);virtual;
  33. procedure donewriting;virtual;
  34. procedure writebytes(var data;len:longint);virtual;
  35. procedure writealloc(len:longint);virtual;
  36. procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);virtual;
  37. procedure writesymbol(p:pasmsymbol);virtual;
  38. procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual;
  39. end;
  40. implementation
  41. {****************************************************************************
  42. Tdbgoutput
  43. ****************************************************************************}
  44. constructor tdbgoutput.init(smart:boolean);
  45. begin
  46. inherited init(smart);
  47. rawidx:=-1;
  48. nsyms:=0;
  49. end;
  50. destructor tdbgoutput.done;
  51. begin
  52. end;
  53. procedure tdbgoutput.initwriting(Aplace:tcutplace);
  54. begin
  55. inherited initwriting(Aplace);
  56. writeln('initwriting '+Objfile);
  57. end;
  58. procedure tdbgoutput.donewriting;
  59. begin
  60. if rawidx<>-1 then
  61. begin
  62. writeln;
  63. rawidx:=-1;
  64. end;
  65. writeln('donewriting');
  66. end;
  67. procedure tdbgoutput.writesymbol(p:pasmsymbol);
  68. begin
  69. if rawidx<>-1 then
  70. begin
  71. writeln;
  72. rawidx:=-1;
  73. end;
  74. p^.idx:=nsyms;
  75. write('symbol [',nsyms,'] '+p^.name+' (',target_asm.secnames[p^.section],',',p^.address,',',p^.size,',');
  76. case p^.typ of
  77. AS_LOCAL :
  78. writeln('local)');
  79. AS_GLOBAL :
  80. writeln('global)');
  81. AS_EXTERNAL :
  82. writeln('extern)');
  83. else
  84. writeln('unknown)');
  85. end;
  86. inc(nsyms);
  87. end;
  88. procedure tdbgoutput.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);
  89. begin
  90. if rawidx<>-1 then
  91. begin
  92. writeln;
  93. rawidx:=-1;
  94. end;
  95. if assigned(p) then
  96. write('reloc: ',data,' [',target_asm.secnames[p^.section],',',p^.address,']')
  97. else
  98. write('reloc: ',data);
  99. case relative of
  100. relative_true : writeln(' relative');
  101. relative_false: writeln(' not relative');
  102. relative_rva : writeln(' relative virtual address');
  103. end;
  104. end;
  105. procedure tdbgoutput.writebytes(var data;len:longint);
  106. function hexstr(val : longint;cnt : byte) : string;
  107. const
  108. HexTbl : array[0..15] of char='0123456789ABCDEF';
  109. var
  110. i : longint;
  111. begin
  112. hexstr[0]:=char(cnt);
  113. for i:=cnt downto 1 do
  114. begin
  115. hexstr[i]:=hextbl[val and $f];
  116. val:=val shr 4;
  117. end;
  118. end;
  119. var
  120. p : pchar;
  121. i : longint;
  122. begin
  123. if len=0 then
  124. exit;
  125. p:=@data;
  126. if rawidx=-1 then
  127. begin
  128. write('raw: ');
  129. rawidx:=0;
  130. end;
  131. for i:=1to len do
  132. begin
  133. if rawidx>=16 then
  134. begin
  135. writeln;
  136. write('raw: ');
  137. rawidx:=0;
  138. end;
  139. write(hexstr(ord(p[i-1]),2),' ');
  140. inc(rawidx);
  141. end;
  142. end;
  143. procedure tdbgoutput.writealloc(len:longint);
  144. begin
  145. writeln('alloc: ',len);
  146. end;
  147. procedure tdbgoutput.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);
  148. begin
  149. writeln('stabs: ',line,',',nidx,'"',p,'"');
  150. end;
  151. end.
  152. {
  153. $Log$
  154. Revision 1.7 2000-01-07 01:14:27 peter
  155. * updated copyright to 2000
  156. Revision 1.6 1999/11/02 15:06:57 peter
  157. * import library fixes for win32
  158. * alignment works again
  159. Revision 1.5 1999/08/04 00:23:06 florian
  160. * renamed i386asm and i386base to cpuasm and cpubase
  161. Revision 1.4 1999/07/03 00:29:53 peter
  162. * new link writing to the ppu, one .ppu is needed for all link types,
  163. static (.o) is now always created also when smartlinking is used
  164. Revision 1.3 1999/05/05 17:34:32 peter
  165. * output is more like as 2.9.1
  166. * stabs really working for go32v2
  167. Revision 1.2 1999/05/02 22:41:55 peter
  168. * moved section names to systems
  169. * fixed nasm,intel writer
  170. Revision 1.1 1999/05/01 13:24:24 peter
  171. * merged nasm compiler
  172. * old asm moved to oldasm/
  173. Revision 1.6 1999/03/10 13:41:11 pierre
  174. + partial implementation for win32 !
  175. winhello works but pp still does not !
  176. Revision 1.5 1999/03/08 14:51:10 peter
  177. + smartlinking for ag386bin
  178. Revision 1.4 1999/03/05 13:09:53 peter
  179. * first things for tai_cut support for ag386bin
  180. Revision 1.3 1999/03/02 02:56:28 peter
  181. + stabs support for binary writers
  182. * more fixes and missing updates from the previous commit :(
  183. Revision 1.2 1999/02/25 21:03:11 peter
  184. * ag386bin updates
  185. + coff writer
  186. Revision 1.1 1999/02/16 17:59:39 peter
  187. + initial files
  188. }