gdb.pas 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. {$ifdef i386}
  22. i386,
  23. {$endif i386}
  24. strings,cobjects,globals,aasm;
  25. {stab constants }
  26. Const
  27. N_GSYM = $20;
  28. N_STSYM = 38; {initialized const }
  29. N_LCSYM = 40; {non initialized variable}
  30. N_Function = $24; {function or const }
  31. N_TextLine = $44;
  32. N_DataLine = $46;
  33. N_BssLine = $48;
  34. N_RSYM = $40; { register variable }
  35. N_LSYM = $80;
  36. N_PSYM = 160;
  37. N_SourceFile = $64;
  38. N_IncludeFile = $84;
  39. N_BINCL = $82;
  40. N_EINCL = $A2;
  41. N_EXCL = $C2;
  42. type
  43. pai_stabs = ^tai_stabs;
  44. tai_stabs = object(tai)
  45. str : pchar;
  46. constructor init(_str : pchar);
  47. destructor done; virtual;
  48. end;
  49. pai_stabn = ^tai_stabn;
  50. tai_stabn = object(tai)
  51. str : pchar;
  52. constructor init(_str : pchar);
  53. destructor done; virtual;
  54. end;
  55. { insert a cut to split into several smaller files }
  56. pai_force_line = ^tai_force_line;
  57. tai_force_line = object(tai)
  58. constructor init;
  59. end;
  60. pai_stab_function_name = ^tai_stab_function_name;
  61. tai_stab_function_name = object(tai)
  62. str : pchar;
  63. constructor init(_str : pchar);
  64. destructor done; virtual;
  65. end;
  66. const DBX_counter : plongint = nil;
  67. do_count_dbx : boolean = false;
  68. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
  69. "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  70. { this is the register order for GDB }
  71. {$ifdef i386}
  72. {tregister = (R_NO,R_EAX,R_ECX,R_EDX,R_EBX,R_ESP,R_EBP,R_ESI,R_EDI,
  73. R_AX,R_CX,R_DX,R_BX,R_SP,R_BP,R_SI,R_DI,
  74. R_AL,R_CL,R_DL,R_BL,R_AH,R_CH,R_BH,R_DH,
  75. for an easier assembler generation
  76. R_DEFAULT_SEG,R_CS,R_DS,R_ES,R_FS,R_GS,R_SS,
  77. R_ST,R_ST0,R_ST1,R_ST2,R_ST3,R_ST4,R_ST5,R_ST6,R_ST7); }
  78. GDB_i386index : array[tregister] of shortint =
  79. (-1,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. { I think, GDB doesn't know MMX (FK) }
  83. -1,-1,-1,-1,-1,-1,-1,-1);
  84. {$endif i386}
  85. implementation
  86. {$IfDef DBX}
  87. { to use N_EXCL we have to count the character in the stabs for
  88. N_BINCL to N_EINCL
  89. Code comes from stabs.c for ld
  90. if (type == N_BINCL)
  91. (
  92. bfd_vma val;
  93. int nest;
  94. bfd_byte *incl_sym;
  95. struct stab_link_includes_entry *incl_entry;
  96. struct stab_link_includes_totals *t;
  97. struct stab_excl_list *ne;
  98. val = 0;
  99. nest = 0;
  100. for (incl_sym = sym + STABSIZE;
  101. incl_sym < symend;
  102. incl_sym += STABSIZE)
  103. (
  104. int incl_type;
  105. incl_type = incl_sym[TYPEOFF];
  106. if (incl_type == 0)
  107. break;
  108. else if (incl_type == N_EINCL)
  109. (
  110. if (nest == 0)
  111. break;
  112. --nest;
  113. )
  114. else if (incl_type == N_BINCL)
  115. ++nest;
  116. else if (nest == 0)
  117. (
  118. const char *str;
  119. str = ((char *) stabstrbuf
  120. + stroff
  121. + bfd_get_32 (abfd, incl_sym + STRDXOFF));
  122. for (; *str != '\0'; str++)
  123. (
  124. val += *str;
  125. if (*str == '(')
  126. (
  127. Skip the file number.
  128. ++str;
  129. while (isdigit ((unsigned char) *str))
  130. ++str;
  131. --str;
  132. )
  133. )
  134. )
  135. ) }
  136. procedure count_dbx(st : pchar);
  137. var i : longint;
  138. do_count : boolean;
  139. begin
  140. do_count := false;
  141. if dbx_counter = nil then
  142. else
  143. begin
  144. {$IfDef ExtDebug }
  145. Comment(V_Info,'Counting '+st);
  146. Comment(V_Info,'count = '+tostr(dbx_counter^));
  147. Comment(V_Info,'addr = '+tostr(longint(dbx_counter)));
  148. {$EndIf ExtDebug }
  149. for i:=0 to strlen(st) do
  150. begin
  151. if st[i] = '"' then
  152. if do_count then exit
  153. else do_count := true
  154. else
  155. if do_count then
  156. begin
  157. dbx_counter^ := dbx_counter^+byte(st[i]);
  158. { skip file number }
  159. if st[i] = '(' then
  160. begin
  161. inc(i);
  162. while st[i] in ['0'..'9'] do inc(i);
  163. dec(i);
  164. end;
  165. end;
  166. end;
  167. end;
  168. end;
  169. {$EndIf DBX}
  170. constructor tai_stabs.init(_str : pchar);
  171. begin
  172. inherited init;
  173. typ:=ait_stabs;
  174. str:=_str;
  175. {$IfDef DBX}
  176. if do_count_dbx then
  177. begin
  178. count_dbx(str);
  179. do_count_dbx := false;
  180. end;
  181. {$EndIf DBX}
  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 1998-11-12 11:19:45 pierre
  219. * fix for first line of function break
  220. Revision 1.3 1998/09/22 17:13:45 pierre
  221. + browsing updated and developed
  222. records and objects fields are also stored
  223. Revision 1.2 1998/07/10 08:31:38 pierre
  224. * Just the N_FNAME to N_FUN substitution for stabs of functions
  225. thanks again Daniel !!
  226. Revision 1.1.1.1 1998/03/25 11:18:13 root
  227. * Restored version
  228. Revision 1.5 1998/03/10 01:17:18 peter
  229. * all files have the same header
  230. * messages are fully implemented, EXTDEBUG uses Comment()
  231. + AG... files for the Assembler generation
  232. Revision 1.4 1998/03/02 01:48:33 peter
  233. * renamed target_DOS to target_GO32V1
  234. + new verbose system, merged old errors and verbose units into one new
  235. verbose.pas, so errors.pas is obsolete
  236. Revision 1.3 1998/02/13 10:35:01 daniel
  237. * Made Motorola version compilable.
  238. * Fixed optimizer
  239. Revision 1.2 1997/11/28 18:14:32 pierre
  240. working version with several bug fixes
  241. Revision 1.1.1.1 1997/11/27 08:32:56 michael
  242. FPC Compiler CVS start
  243. }