og386dbg.pas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. {
  2. $Id$
  3. Copyright (c) 1999 by Florian Klaempfl
  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,i386base,
  25. aasm,
  26. og386;
  27. type
  28. pdbgoutput = ^tdbgoutput;
  29. tdbgoutput = object(tobjectoutput)
  30. nsyms : longint;
  31. rawidx : longint;
  32. constructor init;
  33. destructor done;virtual;
  34. procedure initwriting;virtual;
  35. procedure donewriting;virtual;
  36. procedure writebytes(var data;len:longint);virtual;
  37. procedure writealloc(len:longint);virtual;
  38. procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);virtual;
  39. procedure writesymbol(p:pasmsymbol);virtual;
  40. procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual;
  41. end;
  42. implementation
  43. {****************************************************************************
  44. Tdbgoutput
  45. ****************************************************************************}
  46. constructor tdbgoutput.init;
  47. begin
  48. inherited init;
  49. rawidx:=-1;
  50. nsyms:=0;
  51. end;
  52. destructor tdbgoutput.done;
  53. begin
  54. end;
  55. procedure tdbgoutput.initwriting;
  56. begin
  57. inherited initwriting;
  58. writeln('initwriting '+Objfile);
  59. end;
  60. procedure tdbgoutput.donewriting;
  61. begin
  62. if rawidx<>-1 then
  63. begin
  64. writeln;
  65. rawidx:=-1;
  66. end;
  67. writeln('donewriting');
  68. end;
  69. procedure tdbgoutput.writesymbol(p:pasmsymbol);
  70. begin
  71. if rawidx<>-1 then
  72. begin
  73. writeln;
  74. rawidx:=-1;
  75. end;
  76. p^.idx:=nsyms;
  77. write('symbol [',nsyms,'] '+p^.name+' (',target_asm.secnames[p^.section],',',p^.address,',',p^.size,',');
  78. case p^.typ of
  79. AS_LOCAL :
  80. writeln('local)');
  81. AS_GLOBAL :
  82. writeln('global)');
  83. AS_EXTERNAL :
  84. writeln('extern)');
  85. else
  86. writeln('unknown)');
  87. end;
  88. inc(nsyms);
  89. end;
  90. procedure tdbgoutput.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);
  91. begin
  92. if rawidx<>-1 then
  93. begin
  94. writeln;
  95. rawidx:=-1;
  96. end;
  97. if assigned(p) then
  98. write('reloc: ',data,' [',target_asm.secnames[p^.section],',',p^.address,']')
  99. else
  100. write('reloc: ',data);
  101. case relative of
  102. relative_true : writeln(' relative');
  103. relative_false: writeln(' not relative');
  104. relative_rva : writeln(' relative virtual address');
  105. end;
  106. end;
  107. procedure tdbgoutput.writebytes(var data;len:longint);
  108. function hexstr(val : longint;cnt : byte) : string;
  109. const
  110. HexTbl : array[0..15] of char='0123456789ABCDEF';
  111. var
  112. i : longint;
  113. begin
  114. hexstr[0]:=char(cnt);
  115. for i:=cnt downto 1 do
  116. begin
  117. hexstr[i]:=hextbl[val and $f];
  118. val:=val shr 4;
  119. end;
  120. end;
  121. var
  122. p : pchar;
  123. i : longint;
  124. begin
  125. if len=0 then
  126. exit;
  127. p:=@data;
  128. if rawidx=-1 then
  129. begin
  130. write('raw: ');
  131. rawidx:=0;
  132. end;
  133. for i:=1to len do
  134. begin
  135. if rawidx>=16 then
  136. begin
  137. writeln;
  138. write('raw: ');
  139. rawidx:=0;
  140. end;
  141. write(hexstr(ord(p[i-1]),2),' ');
  142. inc(rawidx);
  143. end;
  144. end;
  145. procedure tdbgoutput.writealloc(len:longint);
  146. begin
  147. writeln('alloc: ',len);
  148. end;
  149. procedure tdbgoutput.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);
  150. begin
  151. writeln('stabs: ',line,',',nidx,'"',p,'"');
  152. end;
  153. end.
  154. {
  155. $Log$
  156. Revision 1.3 1999-05-05 17:34:32 peter
  157. * output is more like as 2.9.1
  158. * stabs really working for go32v2
  159. Revision 1.2 1999/05/02 22:41:55 peter
  160. * moved section names to systems
  161. * fixed nasm,intel writer
  162. Revision 1.1 1999/05/01 13:24:24 peter
  163. * merged nasm compiler
  164. * old asm moved to oldasm/
  165. Revision 1.6 1999/03/10 13:41:11 pierre
  166. + partial implementation for win32 !
  167. winhello works but pp still does not !
  168. Revision 1.5 1999/03/08 14:51:10 peter
  169. + smartlinking for ag386bin
  170. Revision 1.4 1999/03/05 13:09:53 peter
  171. * first things for tai_cut support for ag386bin
  172. Revision 1.3 1999/03/02 02:56:28 peter
  173. + stabs support for binary writers
  174. * more fixes and missing updates from the previous commit :(
  175. Revision 1.2 1999/02/25 21:03:11 peter
  176. * ag386bin updates
  177. + coff writer
  178. Revision 1.1 1999/02/16 17:59:39 peter
  179. + initial files
  180. }