gdb.pas 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This units contains special support for the GDB
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit gdb;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. {$ifdef delphi}
  23. sysutils,
  24. {$else}
  25. strings,
  26. {$endif}
  27. globtype,cpubase,
  28. globals,aasm;
  29. {stab constants }
  30. Const
  31. N_GSYM = $20;
  32. N_STSYM = 38; {initialized const }
  33. N_LCSYM = 40; {non initialized variable}
  34. N_Function = $24; {function or const }
  35. N_TextLine = $44;
  36. N_DataLine = $46;
  37. N_BssLine = $48;
  38. N_RSYM = $40; { register variable }
  39. N_LSYM = $80;
  40. N_tsym = 160;
  41. N_SourceFile = $64;
  42. N_IncludeFile = $84;
  43. N_BINCL = $82;
  44. N_EINCL = $A2;
  45. N_EXCL = $C2;
  46. type
  47. tai_stabs = class(tai)
  48. str : pchar;
  49. constructor Create(_str : pchar);
  50. destructor Destroy;override;
  51. end;
  52. tai_stabn = class(tai)
  53. str : pchar;
  54. constructor Create(_str : pchar);
  55. destructor Destroy;override;
  56. end;
  57. { insert a cut to split into several smaller files }
  58. tai_force_line = class(tai)
  59. constructor Create;
  60. end;
  61. tai_stab_function_name = class(tai)
  62. str : pchar;
  63. constructor create(_str : pchar);
  64. destructor destroy;override;
  65. end;
  66. const
  67. DBX_counter : plongint = nil;
  68. do_count_dbx : boolean = false;
  69. {$ifdef i386}
  70. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
  71. "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  72. { this is the register order for GDB }
  73. GDB_i386index : array[tregister] of shortint =(-1,
  74. 0,1,2,3,4,5,6,7,0,1,2,3,4,5,7,0,1,2,3,0,1,2,3,
  75. -1,10,12,13,14,15,11,
  76. -1,-1,-1,-1,-1,-1,-1,-1,-1,
  77. -1,-1,-1,-1,-1,-1,
  78. -1,-1,-1,-1,
  79. -1,-1,-1,-1,-1,
  80. { I think, GDB doesn't know MMX (FK) }
  81. -1,-1,-1,-1,-1,-1,-1,-1,
  82. -1,-1,-1,-1,-1,-1,-1,-1
  83. );
  84. {$endif i386}
  85. {$ifdef m68k}
  86. { "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
  87. "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
  88. "ps", "pc", "fp0", "fp1", "fp2", "fp3", "fp4" ,
  89. "fp5", "fp6", "fp7", "fpcontrol", "fpstatus",
  90. "fpiaddr","fpcode","fpflags"
  91. }
  92. { this is the register order for GDB }
  93. GDB_m68kindex : array[tregister] of shortint =
  94. (-1, { R_NO }
  95. 0,1,2,3,4,5,6,7, { R_D0..R_D7 }
  96. 8,9,10,11,12,13,14,15, { R_A0..R_A7 }
  97. -1,-1,-1, { R_SPPUSH, R_SPPULL, R_CCR }
  98. 18,19,20,21,22,23,24,25, { R_FP0..R_FP7 }
  99. -1,-1,-1,-1,-1,-1,-1,-1
  100. );
  101. {$endif}
  102. implementation
  103. { to use N_EXCL we have to count the character in the stabs for
  104. N_BINCL to N_EINCL
  105. Code comes from stabs.c for ld
  106. if (type == N_BINCL)
  107. (
  108. bfd_vma val;
  109. int nest;
  110. bfd_byte *incl_sym;
  111. struct stab_link_includes_entry *incl_entry;
  112. struct stab_link_includes_totals *t;
  113. struct stab_excl_list *ne;
  114. val = 0;
  115. nest = 0;
  116. for (incl_sym = sym + STABSIZE;
  117. incl_sym < symend;
  118. incl_sym += STABSIZE)
  119. (
  120. int incl_type;
  121. incl_type = incl_sym[TYPEOFF];
  122. if (incl_type == 0)
  123. break;
  124. else if (incl_type == N_EINCL)
  125. (
  126. if (nest == 0)
  127. break;
  128. --nest;
  129. )
  130. else if (incl_type == N_BINCL)
  131. ++nest;
  132. else if (nest == 0)
  133. (
  134. const char *str;
  135. str = ((char *) stabstrbuf
  136. + stroff
  137. + bfd_get_32 (abfd, incl_sym + STRDXOFF));
  138. for (; *str != '\0'; str++)
  139. (
  140. val += *str;
  141. if *str == '('
  142. (
  143. Skip the file number.
  144. ++str;
  145. while (isdigit ((unsigned char) *str))
  146. ++str;
  147. --str;
  148. )
  149. )
  150. )
  151. ) }
  152. procedure count_dbx(st : pchar);
  153. var i : longint;
  154. do_count : boolean;
  155. begin
  156. do_count := false;
  157. if assigned(dbx_counter) then
  158. begin
  159. {$IfDef ExtDebugDbx }
  160. Comment(V_Info,'Counting '+st);
  161. Comment(V_Info,'count = '+tostr(dbx_counter^));
  162. Comment(V_Info,'addr = '+tostr(longint(dbx_counter)));
  163. {$EndIf ExtDebugDbx }
  164. i:=0;
  165. while i<=strlen(st) do
  166. begin
  167. if st[i] = '"' then
  168. if do_count then exit
  169. else do_count := true
  170. else
  171. if do_count then
  172. begin
  173. dbx_counter^ := dbx_counter^+byte(st[i]);
  174. { skip file number }
  175. if st[i] = '(' then
  176. begin
  177. inc(i);
  178. while st[i] in ['0'..'9'] do inc(i);
  179. dec(i);
  180. end;
  181. end;
  182. inc(i);
  183. end;
  184. end;
  185. end;
  186. constructor tai_stabs.create(_str : pchar);
  187. begin
  188. inherited create;
  189. typ:=ait_stabs;
  190. str:=_str;
  191. if do_count_dbx then
  192. begin
  193. count_dbx(str);
  194. end;
  195. end;
  196. destructor tai_stabs.destroy;
  197. begin
  198. strdispose(str);
  199. inherited destroy;
  200. end;
  201. constructor tai_stabn.create(_str : pchar);
  202. begin
  203. inherited create;
  204. typ:=ait_stabn;
  205. str:=_str;
  206. end;
  207. destructor tai_stabn.destroy;
  208. begin
  209. strdispose(str);
  210. inherited destroy;
  211. end;
  212. constructor tai_force_line.create;
  213. begin
  214. inherited create;
  215. typ:=ait_force_line;
  216. end;
  217. constructor tai_stab_function_name.create(_str : pchar);
  218. begin
  219. inherited create;
  220. typ:=ait_stab_function_name;
  221. str:=_str;
  222. end;
  223. destructor tai_stab_function_name.destroy;
  224. begin
  225. strdispose(str);
  226. inherited destroy;
  227. end;
  228. end.
  229. {
  230. $Log$
  231. Revision 1.7 2001-04-21 12:03:11 peter
  232. * m68k updates merged from fixes branch
  233. Revision 1.6 2001/04/13 01:22:07 peter
  234. * symtable change to classes
  235. * range check generation and errors fixed, make cycle DEBUG=1 works
  236. * memory leaks fixed
  237. Revision 1.5 2000/12/25 00:07:26 peter
  238. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  239. tlinkedlist objects)
  240. Revision 1.4 2000/11/29 00:30:30 florian
  241. * unused units removed from uses clause
  242. * some changes for widestrings
  243. Revision 1.3 2000/09/24 15:06:16 peter
  244. * use defines.inc
  245. Revision 1.2 2000/07/13 11:32:41 michael
  246. + removed logs
  247. }