gdb.pas 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. {
  2. $Id$
  3. Copyright (c) 1996-98 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. interface
  20. uses
  21. globtype,
  22. {$ifdef i386}
  23. {$ifdef AG386BIN}
  24. i386base,
  25. {$else}
  26. i386,
  27. {$endif}
  28. {$endif i386}
  29. strings,cobjects,globals,aasm;
  30. {stab constants }
  31. Const
  32. N_GSYM = $20;
  33. N_STSYM = 38; {initialized const }
  34. N_LCSYM = 40; {non initialized variable}
  35. N_Function = $24; {function or const }
  36. N_TextLine = $44;
  37. N_DataLine = $46;
  38. N_BssLine = $48;
  39. N_RSYM = $40; { register variable }
  40. N_LSYM = $80;
  41. N_PSYM = 160;
  42. N_SourceFile = $64;
  43. N_IncludeFile = $84;
  44. N_BINCL = $82;
  45. N_EINCL = $A2;
  46. N_EXCL = $C2;
  47. type
  48. pai_stabs = ^tai_stabs;
  49. tai_stabs = object(tai)
  50. str : pchar;
  51. constructor init(_str : pchar);
  52. destructor done; virtual;
  53. end;
  54. pai_stabn = ^tai_stabn;
  55. tai_stabn = object(tai)
  56. str : pchar;
  57. constructor init(_str : pchar);
  58. destructor done; virtual;
  59. end;
  60. { insert a cut to split into several smaller files }
  61. pai_force_line = ^tai_force_line;
  62. tai_force_line = object(tai)
  63. constructor init;
  64. end;
  65. pai_stab_function_name = ^tai_stab_function_name;
  66. tai_stab_function_name = object(tai)
  67. str : pchar;
  68. constructor init(_str : pchar);
  69. destructor done; virtual;
  70. end;
  71. const
  72. DBX_counter : plongint = nil;
  73. do_count_dbx : boolean = false;
  74. {$ifdef i386}
  75. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
  76. "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  77. { this is the register order for GDB }
  78. GDB_i386index : array[tregister] of shortint =(-1,
  79. 0,1,2,3,4,5,6,7,0,1,2,3,4,5,7,0,1,2,3,0,1,2,3,
  80. -1,10,12,13,14,15,11,
  81. -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  82. {$ifdef AG386BIN}
  83. -1,-1,-1,-1,-1,-1,
  84. -1,-1,-1,-1,
  85. -1,-1,-1,-1,-1,
  86. {$endif}
  87. { I think, GDB doesn't know MMX (FK) }
  88. -1,-1,-1,-1,-1,-1,-1,-1,
  89. -1,-1,-1,-1,-1,-1,-1,-1
  90. );
  91. {$endif i386}
  92. implementation
  93. {$IfDef DBX}
  94. { to use N_EXCL we have to count the character in the stabs for
  95. N_BINCL to N_EINCL
  96. Code comes from stabs.c for ld
  97. if (type == N_BINCL)
  98. (
  99. bfd_vma val;
  100. int nest;
  101. bfd_byte *incl_sym;
  102. struct stab_link_includes_entry *incl_entry;
  103. struct stab_link_includes_totals *t;
  104. struct stab_excl_list *ne;
  105. val = 0;
  106. nest = 0;
  107. for (incl_sym = sym + STABSIZE;
  108. incl_sym < symend;
  109. incl_sym += STABSIZE)
  110. (
  111. int incl_type;
  112. incl_type = incl_sym[TYPEOFF];
  113. if (incl_type == 0)
  114. break;
  115. else if (incl_type == N_EINCL)
  116. (
  117. if (nest == 0)
  118. break;
  119. --nest;
  120. )
  121. else if (incl_type == N_BINCL)
  122. ++nest;
  123. else if (nest == 0)
  124. (
  125. const char *str;
  126. str = ((char *) stabstrbuf
  127. + stroff
  128. + bfd_get_32 (abfd, incl_sym + STRDXOFF));
  129. for (; *str != '\0'; str++)
  130. (
  131. val += *str;
  132. if (*str == '(')
  133. (
  134. Skip the file number.
  135. ++str;
  136. while (isdigit ((unsigned char) *str))
  137. ++str;
  138. --str;
  139. )
  140. )
  141. )
  142. ) }
  143. procedure count_dbx(st : pchar);
  144. var i : longint;
  145. do_count : boolean;
  146. begin
  147. do_count := false;
  148. if dbx_counter = nil then
  149. else
  150. begin
  151. {$IfDef ExtDebug }
  152. Comment(V_Info,'Counting '+st);
  153. Comment(V_Info,'count = '+tostr(dbx_counter^));
  154. Comment(V_Info,'addr = '+tostr(longint(dbx_counter)));
  155. {$EndIf ExtDebug }
  156. for i:=0 to strlen(st) do
  157. begin
  158. if st[i] = '"' then
  159. if do_count then exit
  160. else do_count := true
  161. else
  162. if do_count then
  163. begin
  164. dbx_counter^ := dbx_counter^+byte(st[i]);
  165. { skip file number }
  166. if st[i] = '(' then
  167. begin
  168. inc(i);
  169. while st[i] in ['0'..'9'] do inc(i);
  170. dec(i);
  171. end;
  172. end;
  173. end;
  174. end;
  175. end;
  176. {$EndIf DBX}
  177. constructor tai_stabs.init(_str : pchar);
  178. begin
  179. inherited init;
  180. typ:=ait_stabs;
  181. str:=_str;
  182. {$IfDef DBX}
  183. if do_count_dbx then
  184. begin
  185. count_dbx(str);
  186. do_count_dbx := false;
  187. end;
  188. {$EndIf DBX}
  189. end;
  190. destructor tai_stabs.done;
  191. begin
  192. strdispose(str);
  193. inherited done;
  194. end;
  195. constructor tai_stabn.init(_str : pchar);
  196. begin
  197. inherited init;
  198. typ:=ait_stabn;
  199. str:=_str;
  200. end;
  201. destructor tai_stabn.done;
  202. begin
  203. strdispose(str);
  204. inherited done;
  205. end;
  206. constructor tai_force_line.init;
  207. begin
  208. inherited init;
  209. typ:=ait_force_line;
  210. end;
  211. constructor tai_stab_function_name.init(_str : pchar);
  212. begin
  213. inherited init;
  214. typ:=ait_stab_function_name;
  215. str:=_str;
  216. end;
  217. destructor tai_stab_function_name.done;
  218. begin
  219. strdispose(str);
  220. inherited done;
  221. end;
  222. end.
  223. {
  224. $Log$
  225. Revision 1.7 1999-03-02 02:56:12 peter
  226. + stabs support for binary writers
  227. * more fixes and missing updates from the previous commit :(
  228. Revision 1.6 1999/01/08 12:39:23 florian
  229. Changes of Alexander Stohr integrated:
  230. + added KNI opcodes
  231. + added KNI registers
  232. + added 3DNow! opcodes
  233. + added 64 bit and 128 bit register flags
  234. * translated a few comments into english
  235. Revision 1.5 1998/12/11 00:03:16 peter
  236. + globtype,tokens,version unit splitted from globals
  237. Revision 1.4 1998/11/12 11:19:45 pierre
  238. * fix for first line of function break
  239. Revision 1.3 1998/09/22 17:13:45 pierre
  240. + browsing updated and developed
  241. records and objects fields are also stored
  242. Revision 1.2 1998/07/10 08:31:38 pierre
  243. * Just the N_FNAME to N_FUN substitution for stabs of functions
  244. thanks again Daniel !!
  245. Revision 1.1.1.1 1998/03/25 11:18:13 root
  246. * Restored version
  247. Revision 1.5 1998/03/10 01:17:18 peter
  248. * all files have the same header
  249. * messages are fully implemented, EXTDEBUG uses Comment()
  250. + AG... files for the Assembler generation
  251. Revision 1.4 1998/03/02 01:48:33 peter
  252. * renamed target_DOS to target_GO32V1
  253. + new verbose system, merged old errors and verbose units into one new
  254. verbose.pas, so errors.pas is obsolete
  255. Revision 1.3 1998/02/13 10:35:01 daniel
  256. * Made Motorola version compilable.
  257. * Fixed optimizer
  258. Revision 1.2 1997/11/28 18:14:32 pierre
  259. working version with several bug fixes
  260. Revision 1.1.1.1 1997/11/27 08:32:56 michael
  261. FPC Compiler CVS start
  262. }