og386dbg.pas 5.8 KB

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