og386dbg.pas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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.8 2000-02-09 13:22:54 peter
  155. * log truncated
  156. Revision 1.7 2000/01/07 01:14:27 peter
  157. * updated copyright to 2000
  158. Revision 1.6 1999/11/02 15:06:57 peter
  159. * import library fixes for win32
  160. * alignment works again
  161. Revision 1.5 1999/08/04 00:23:06 florian
  162. * renamed i386asm and i386base to cpuasm and cpubase
  163. }