gdb.pas 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. i386,
  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 DBX_counter : plongint = nil;
  68. do_count_dbx : boolean = false;
  69. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
  70. "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  71. { this is the register order for GDB }
  72. {$ifdef i386}
  73. {tregister = (R_NO,R_EAX,R_ECX,R_EDX,R_EBX,R_ESP,R_EBP,R_ESI,R_EDI,
  74. R_AX,R_CX,R_DX,R_BX,R_SP,R_BP,R_SI,R_DI,
  75. R_AL,R_CL,R_DL,R_BL,R_AH,R_CH,R_BH,R_DH,
  76. for an easier assembler generation
  77. R_DEFAULT_SEG,R_CS,R_DS,R_ES,R_FS,R_GS,R_SS,
  78. R_ST,R_ST0,R_ST1,R_ST2,R_ST3,R_ST4,R_ST5,R_ST6,R_ST7); }
  79. GDB_i386index : array[tregister] of shortint =
  80. (-1,0,1,2,3,4,5,6,7,0,1,2,3,4,5,7,0,1,2,3,0,1,2,3,
  81. -1,10,12,13,14,15,11,
  82. -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  83. { I think, GDB doesn't know MMX (FK) }
  84. -1,-1,-1,-1,-1,-1,-1,-1);
  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.5 1998-12-11 00:03:16 peter
  220. + globtype,tokens,version unit splitted from globals
  221. Revision 1.4 1998/11/12 11:19:45 pierre
  222. * fix for first line of function break
  223. Revision 1.3 1998/09/22 17:13:45 pierre
  224. + browsing updated and developed
  225. records and objects fields are also stored
  226. Revision 1.2 1998/07/10 08:31:38 pierre
  227. * Just the N_FNAME to N_FUN substitution for stabs of functions
  228. thanks again Daniel !!
  229. Revision 1.1.1.1 1998/03/25 11:18:13 root
  230. * Restored version
  231. Revision 1.5 1998/03/10 01:17:18 peter
  232. * all files have the same header
  233. * messages are fully implemented, EXTDEBUG uses Comment()
  234. + AG... files for the Assembler generation
  235. Revision 1.4 1998/03/02 01:48:33 peter
  236. * renamed target_DOS to target_GO32V1
  237. + new verbose system, merged old errors and verbose units into one new
  238. verbose.pas, so errors.pas is obsolete
  239. Revision 1.3 1998/02/13 10:35:01 daniel
  240. * Made Motorola version compilable.
  241. * Fixed optimizer
  242. Revision 1.2 1997/11/28 18:14:32 pierre
  243. working version with several bug fixes
  244. Revision 1.1.1.1 1997/11/27 08:32:56 michael
  245. FPC Compiler CVS start
  246. }