gdb.pas 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. pai_stab_function_name = ^tai_stab_function_name;
  56. tai_stab_function_name = object(tai)
  57. str : pchar;
  58. constructor init(_str : pchar);
  59. destructor done; virtual;
  60. end;
  61. const DBX_counter : plongint = nil;
  62. do_count_dbx : boolean = false;
  63. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
  64. "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  65. { this is the register order for GDB }
  66. {$ifdef i386}
  67. {tregister = (R_NO,R_EAX,R_ECX,R_EDX,R_EBX,R_ESP,R_EBP,R_ESI,R_EDI,
  68. R_AX,R_CX,R_DX,R_BX,R_SP,R_BP,R_SI,R_DI,
  69. R_AL,R_CL,R_DL,R_BL,R_AH,R_CH,R_BH,R_DH,
  70. for an easier assembler generation
  71. R_DEFAULT_SEG,R_CS,R_DS,R_ES,R_FS,R_GS,R_SS,
  72. R_ST,R_ST0,R_ST1,R_ST2,R_ST3,R_ST4,R_ST5,R_ST6,R_ST7); }
  73. GDB_i386index : array[tregister] of shortint =
  74. (-1,0,1,2,3,4,5,6,7,0,1,2,3,4,5,7,0,1,2,3,0,1,2,3,
  75. -1,10,12,13,14,15,11,
  76. -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  77. { I think, GDB doesn't know MMX (FK) }
  78. -1,-1,-1,-1,-1,-1,-1,-1);
  79. {$endif i386}
  80. implementation
  81. {$IfDef DBX}
  82. { to use N_EXCL we have to count the character in the stabs for
  83. N_BINCL to N_EINCL
  84. Code comes from stabs.c for ld
  85. if (type == N_BINCL)
  86. (
  87. bfd_vma val;
  88. int nest;
  89. bfd_byte *incl_sym;
  90. struct stab_link_includes_entry *incl_entry;
  91. struct stab_link_includes_totals *t;
  92. struct stab_excl_list *ne;
  93. val = 0;
  94. nest = 0;
  95. for (incl_sym = sym + STABSIZE;
  96. incl_sym < symend;
  97. incl_sym += STABSIZE)
  98. (
  99. int incl_type;
  100. incl_type = incl_sym[TYPEOFF];
  101. if (incl_type == 0)
  102. break;
  103. else if (incl_type == N_EINCL)
  104. (
  105. if (nest == 0)
  106. break;
  107. --nest;
  108. )
  109. else if (incl_type == N_BINCL)
  110. ++nest;
  111. else if (nest == 0)
  112. (
  113. const char *str;
  114. str = ((char *) stabstrbuf
  115. + stroff
  116. + bfd_get_32 (abfd, incl_sym + STRDXOFF));
  117. for (; *str != '\0'; str++)
  118. (
  119. val += *str;
  120. if (*str == '(')
  121. (
  122. Skip the file number.
  123. ++str;
  124. while (isdigit ((unsigned char) *str))
  125. ++str;
  126. --str;
  127. )
  128. )
  129. )
  130. ) }
  131. procedure count_dbx(st : pchar);
  132. var i : longint;
  133. do_count : boolean;
  134. begin
  135. do_count := false;
  136. if dbx_counter = nil then
  137. else
  138. begin
  139. {$IfDef ExtDebug }
  140. Comment(V_Info,'Counting '+st);
  141. Comment(V_Info,'count = '+tostr(dbx_counter^));
  142. Comment(V_Info,'addr = '+tostr(longint(dbx_counter)));
  143. {$EndIf ExtDebug }
  144. for i:=0 to strlen(st) do
  145. begin
  146. if st[i] = '"' then
  147. if do_count then exit
  148. else do_count := true
  149. else
  150. if do_count then
  151. begin
  152. dbx_counter^ := dbx_counter^+byte(st[i]);
  153. { skip file number }
  154. if st[i] = '(' then
  155. begin
  156. inc(i);
  157. while st[i] in ['0'..'9'] do inc(i);
  158. dec(i);
  159. end;
  160. end;
  161. end;
  162. end;
  163. end;
  164. {$EndIf DBX}
  165. constructor tai_stabs.init(_str : pchar);
  166. begin
  167. inherited init;
  168. typ:=ait_stabs;
  169. str:=_str;
  170. {$IfDef DBX}
  171. if do_count_dbx then
  172. begin
  173. count_dbx(str);
  174. do_count_dbx := false;
  175. end;
  176. {$EndIf DBX}
  177. end;
  178. destructor tai_stabs.done;
  179. begin
  180. strdispose(str);
  181. inherited done;
  182. end;
  183. constructor tai_stabn.init(_str : pchar);
  184. begin
  185. inherited init;
  186. typ:=ait_stabn;
  187. str:=_str;
  188. end;
  189. destructor tai_stabn.done;
  190. begin
  191. strdispose(str);
  192. inherited done;
  193. end;
  194. constructor tai_stab_function_name.init(_str : pchar);
  195. begin
  196. inherited init;
  197. typ:=ait_stab_function_name;
  198. str:=_str;
  199. end;
  200. destructor tai_stab_function_name.done;
  201. begin
  202. strdispose(str);
  203. inherited done;
  204. end;
  205. end.
  206. {
  207. $Log$
  208. Revision 1.3 1998-09-22 17:13:45 pierre
  209. + browsing updated and developed
  210. records and objects fields are also stored
  211. Revision 1.2 1998/07/10 08:31:38 pierre
  212. * Just the N_FNAME to N_FUN substitution for stabs of functions
  213. thanks again Daniel !!
  214. Revision 1.1.1.1 1998/03/25 11:18:13 root
  215. * Restored version
  216. Revision 1.5 1998/03/10 01:17:18 peter
  217. * all files have the same header
  218. * messages are fully implemented, EXTDEBUG uses Comment()
  219. + AG... files for the Assembler generation
  220. Revision 1.4 1998/03/02 01:48:33 peter
  221. * renamed target_DOS to target_GO32V1
  222. + new verbose system, merged old errors and verbose units into one new
  223. verbose.pas, so errors.pas is obsolete
  224. Revision 1.3 1998/02/13 10:35:01 daniel
  225. * Made Motorola version compilable.
  226. * Fixed optimizer
  227. Revision 1.2 1997/11/28 18:14:32 pierre
  228. working version with several bug fixes
  229. Revision 1.1.1.1 1997/11/27 08:32:56 michael
  230. FPC Compiler CVS start
  231. }