gdb.pas 8.2 KB

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