og386dbg.pas 5.1 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. {$i defines.inc}
  23. interface
  24. uses
  25. systems,aasm,cpubase,og386;
  26. type
  27. pdbgoutput = ^tdbgoutput;
  28. tdbgoutput = object(tobjectoutput)
  29. nsyms : longint;
  30. rawidx : longint;
  31. constructor init(smart:boolean);
  32. destructor done;virtual;
  33. procedure initwriting(Aplace:tcutplace);virtual;
  34. procedure donewriting;virtual;
  35. procedure writebytes(var data;len:longint);virtual;
  36. procedure writealloc(len:longint);virtual;
  37. procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);virtual;
  38. procedure writesymbol(p:pasmsymbol);virtual;
  39. procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual;
  40. end;
  41. implementation
  42. {****************************************************************************
  43. Tdbgoutput
  44. ****************************************************************************}
  45. constructor tdbgoutput.init(smart:boolean);
  46. begin
  47. inherited init(smart);
  48. rawidx:=-1;
  49. nsyms:=0;
  50. end;
  51. destructor tdbgoutput.done;
  52. begin
  53. end;
  54. procedure tdbgoutput.initwriting(Aplace:tcutplace);
  55. begin
  56. inherited initwriting(Aplace);
  57. writeln('initwriting '+Objfile);
  58. end;
  59. procedure tdbgoutput.donewriting;
  60. begin
  61. if rawidx<>-1 then
  62. begin
  63. writeln;
  64. rawidx:=-1;
  65. end;
  66. writeln('donewriting');
  67. end;
  68. procedure tdbgoutput.writesymbol(p:pasmsymbol);
  69. begin
  70. if rawidx<>-1 then
  71. begin
  72. writeln;
  73. rawidx:=-1;
  74. end;
  75. p^.idx:=nsyms;
  76. write('symbol [',nsyms,'] '+p^.name+' (',target_asm.secnames[p^.section],',',p^.address,',',p^.size,',');
  77. case p^.bind of
  78. AB_LOCAL :
  79. writeln('local)');
  80. AB_GLOBAL :
  81. writeln('global)');
  82. AB_EXTERNAL :
  83. writeln('extern)');
  84. else
  85. writeln('unknown)');
  86. end;
  87. inc(nsyms);
  88. end;
  89. procedure tdbgoutput.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);
  90. begin
  91. if rawidx<>-1 then
  92. begin
  93. writeln;
  94. rawidx:=-1;
  95. end;
  96. if assigned(p) then
  97. write('reloc: ',data,' [',target_asm.secnames[p^.section],',',p^.address,']')
  98. else
  99. write('reloc: ',data);
  100. case relative of
  101. relative_true : writeln(' relative');
  102. relative_false: writeln(' not relative');
  103. relative_rva : writeln(' relative virtual address');
  104. end;
  105. end;
  106. procedure tdbgoutput.writebytes(var data;len:longint);
  107. function hexstr(val : longint;cnt : byte) : string;
  108. const
  109. HexTbl : array[0..15] of char='0123456789ABCDEF';
  110. var
  111. i : longint;
  112. begin
  113. hexstr[0]:=char(cnt);
  114. for i:=cnt downto 1 do
  115. begin
  116. hexstr[i]:=hextbl[val and $f];
  117. val:=val shr 4;
  118. end;
  119. end;
  120. var
  121. p : pchar;
  122. i : longint;
  123. begin
  124. if len=0 then
  125. exit;
  126. p:=@data;
  127. if rawidx=-1 then
  128. begin
  129. write('raw: ');
  130. rawidx:=0;
  131. end;
  132. for i:=1to len do
  133. begin
  134. if rawidx>=16 then
  135. begin
  136. writeln;
  137. write('raw: ');
  138. rawidx:=0;
  139. end;
  140. write(hexstr(ord(p[i-1]),2),' ');
  141. inc(rawidx);
  142. end;
  143. end;
  144. procedure tdbgoutput.writealloc(len:longint);
  145. begin
  146. writeln('alloc: ',len);
  147. end;
  148. procedure tdbgoutput.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);
  149. begin
  150. writeln('stabs: ',line,',',nidx,'"',p,'"');
  151. end;
  152. end.
  153. {
  154. $Log$
  155. Revision 1.4 2000-09-24 15:06:20 peter
  156. * use defines.inc
  157. Revision 1.3 2000/07/13 12:08:26 michael
  158. + patched to 1.1.0 with former 1.09patch from peter
  159. Revision 1.2 2000/07/13 11:32:43 michael
  160. + removed logs
  161. }