gdb.pas 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. cobjects,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_PSYM = 160;
  41. N_SourceFile = $64;
  42. N_IncludeFile = $84;
  43. N_BINCL = $82;
  44. N_EINCL = $A2;
  45. N_EXCL = $C2;
  46. type
  47. pai_stabs = ^tai_stabs;
  48. tai_stabs = object(tai)
  49. str : pchar;
  50. constructor init(_str : pchar);
  51. destructor done; virtual;
  52. end;
  53. pai_stabn = ^tai_stabn;
  54. tai_stabn = object(tai)
  55. str : pchar;
  56. constructor init(_str : pchar);
  57. destructor done; virtual;
  58. end;
  59. { insert a cut to split into several smaller files }
  60. pai_force_line = ^tai_force_line;
  61. tai_force_line = object(tai)
  62. constructor init;
  63. end;
  64. pai_stab_function_name = ^tai_stab_function_name;
  65. tai_stab_function_name = object(tai)
  66. str : pchar;
  67. constructor init(_str : pchar);
  68. destructor done; virtual;
  69. end;
  70. const
  71. DBX_counter : plongint = nil;
  72. do_count_dbx : boolean = false;
  73. {$ifdef i386}
  74. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
  75. "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  76. { this is the register order for GDB }
  77. GDB_i386index : array[tregister] of shortint =(-1,
  78. 0,1,2,3,4,5,6,7,0,1,2,3,4,5,7,0,1,2,3,0,1,2,3,
  79. -1,10,12,13,14,15,11,
  80. -1,-1,-1,-1,-1,-1,-1,-1,-1,
  81. -1,-1,-1,-1,-1,-1,
  82. -1,-1,-1,-1,
  83. -1,-1,-1,-1,-1,
  84. { I think, GDB doesn't know MMX (FK) }
  85. -1,-1,-1,-1,-1,-1,-1,-1,
  86. -1,-1,-1,-1,-1,-1,-1,-1
  87. );
  88. {$endif i386}
  89. implementation
  90. { to use N_EXCL we have to count the character in the stabs for
  91. N_BINCL to N_EINCL
  92. Code comes from stabs.c for ld
  93. if (type == N_BINCL)
  94. (
  95. bfd_vma val;
  96. int nest;
  97. bfd_byte *incl_sym;
  98. struct stab_link_includes_entry *incl_entry;
  99. struct stab_link_includes_totals *t;
  100. struct stab_excl_list *ne;
  101. val = 0;
  102. nest = 0;
  103. for (incl_sym = sym + STABSIZE;
  104. incl_sym < symend;
  105. incl_sym += STABSIZE)
  106. (
  107. int incl_type;
  108. incl_type = incl_sym[TYPEOFF];
  109. if (incl_type == 0)
  110. break;
  111. else if (incl_type == N_EINCL)
  112. (
  113. if (nest == 0)
  114. break;
  115. --nest;
  116. )
  117. else if (incl_type == N_BINCL)
  118. ++nest;
  119. else if (nest == 0)
  120. (
  121. const char *str;
  122. str = ((char *) stabstrbuf
  123. + stroff
  124. + bfd_get_32 (abfd, incl_sym + STRDXOFF));
  125. for (; *str != '\0'; str++)
  126. (
  127. val += *str;
  128. if *str == '('
  129. (
  130. Skip the file number.
  131. ++str;
  132. while (isdigit ((unsigned char) *str))
  133. ++str;
  134. --str;
  135. )
  136. )
  137. )
  138. ) }
  139. procedure count_dbx(st : pchar);
  140. var i : longint;
  141. do_count : boolean;
  142. begin
  143. do_count := false;
  144. if assigned(dbx_counter) then
  145. begin
  146. {$IfDef ExtDebugDbx }
  147. Comment(V_Info,'Counting '+st);
  148. Comment(V_Info,'count = '+tostr(dbx_counter^));
  149. Comment(V_Info,'addr = '+tostr(longint(dbx_counter)));
  150. {$EndIf ExtDebugDbx }
  151. i:=0;
  152. while i<=strlen(st) do
  153. begin
  154. if st[i] = '"' then
  155. if do_count then exit
  156. else do_count := true
  157. else
  158. if do_count then
  159. begin
  160. dbx_counter^ := dbx_counter^+byte(st[i]);
  161. { skip file number }
  162. if st[i] = '(' then
  163. begin
  164. inc(i);
  165. while st[i] in ['0'..'9'] do inc(i);
  166. dec(i);
  167. end;
  168. end;
  169. inc(i);
  170. end;
  171. end;
  172. end;
  173. constructor tai_stabs.init(_str : pchar);
  174. begin
  175. inherited init;
  176. typ:=ait_stabs;
  177. str:=_str;
  178. if do_count_dbx then
  179. begin
  180. count_dbx(str);
  181. end;
  182. end;
  183. destructor tai_stabs.done;
  184. begin
  185. strdispose(str);
  186. inherited done;
  187. end;
  188. constructor tai_stabn.init(_str : pchar);
  189. begin
  190. inherited init;
  191. typ:=ait_stabn;
  192. str:=_str;
  193. end;
  194. destructor tai_stabn.done;
  195. begin
  196. strdispose(str);
  197. inherited done;
  198. end;
  199. constructor tai_force_line.init;
  200. begin
  201. inherited init;
  202. typ:=ait_force_line;
  203. end;
  204. constructor tai_stab_function_name.init(_str : pchar);
  205. begin
  206. inherited init;
  207. typ:=ait_stab_function_name;
  208. str:=_str;
  209. end;
  210. destructor tai_stab_function_name.done;
  211. begin
  212. strdispose(str);
  213. inherited done;
  214. end;
  215. end.
  216. {
  217. $Log$
  218. Revision 1.4 2000-11-29 00:30:30 florian
  219. * unused units removed from uses clause
  220. * some changes for widestrings
  221. Revision 1.3 2000/09/24 15:06:16 peter
  222. * use defines.inc
  223. Revision 1.2 2000/07/13 11:32:41 michael
  224. + removed logs
  225. }