gdb.pas 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. {$ifdef delphi}
  23. sysutils,
  24. {$else}
  25. strings,
  26. {$endif}
  27. globtype,
  28. aasmtai;
  29. {stab constants }
  30. Const
  31. N_GSYM = $20;
  32. N_STSYM = 38; {initialized const }
  33. N_LCSYM = 40; {non initialized variable}
  34. N_Function = $24; {function or const }
  35. N_TextLine = $44;
  36. N_DataLine = $46;
  37. N_BssLine = $48;
  38. N_RSYM = $40; { register variable }
  39. N_LSYM = $80;
  40. N_tsym = 160;
  41. N_SourceFile = $64;
  42. N_IncludeFile = $84;
  43. N_BINCL = $82;
  44. N_EINCL = $A2;
  45. N_EXCL = $C2;
  46. type
  47. tai_stabs = class(tai)
  48. str : pchar;
  49. constructor Create(_str : pchar);
  50. destructor Destroy;override;
  51. end;
  52. tai_stabn = class(tai)
  53. str : pchar;
  54. constructor Create(_str : pchar);
  55. destructor Destroy;override;
  56. end;
  57. { insert a cut to split into several smaller files }
  58. tai_force_line = class(tailineinfo)
  59. constructor Create;
  60. end;
  61. tai_stab_function_name = class(tai)
  62. str : pchar;
  63. constructor create(_str : pchar);
  64. destructor destroy;override;
  65. end;
  66. const
  67. DBX_counter : plongint = nil;
  68. do_count_dbx : boolean = false;
  69. implementation
  70. { to use N_EXCL we have to count the character in the stabs for
  71. N_BINCL to N_EINCL
  72. Code comes from stabs.c for ld
  73. if (type == N_BINCL)
  74. (
  75. bfd_vma val;
  76. int nest;
  77. bfd_byte *incl_sym;
  78. struct stab_link_includes_entry *incl_entry;
  79. struct stab_link_includes_totals *t;
  80. struct stab_excl_list *ne;
  81. val = 0;
  82. nest = 0;
  83. for (incl_sym = sym + STABSIZE;
  84. incl_sym < symend;
  85. incl_sym += STABSIZE)
  86. (
  87. int incl_type;
  88. incl_type = incl_sym[TYPEOFF];
  89. if (incl_type == 0)
  90. break;
  91. else if (incl_type == N_EINCL)
  92. (
  93. if (nest == 0)
  94. break;
  95. --nest;
  96. )
  97. else if (incl_type == N_BINCL)
  98. ++nest;
  99. else if (nest == 0)
  100. (
  101. const char *str;
  102. str = ((char *) stabstrbuf
  103. + stroff
  104. + bfd_get_32 (abfd, incl_sym + STRDXOFF));
  105. for (; *str != '\0'; str++)
  106. (
  107. val += *str;
  108. if *str == '('
  109. (
  110. Skip the file number.
  111. ++str;
  112. while (isdigit ((unsigned char) *str))
  113. ++str;
  114. --str;
  115. )
  116. )
  117. )
  118. ) }
  119. procedure count_dbx(st : pchar);
  120. var i : longint;
  121. do_count : boolean;
  122. begin
  123. do_count := false;
  124. if assigned(dbx_counter) then
  125. begin
  126. {$IfDef ExtDebugDbx }
  127. Comment(V_Info,'Counting '+st);
  128. Comment(V_Info,'count = '+tostr(dbx_counter^));
  129. Comment(V_Info,'addr = '+tostr(longint(dbx_counter)));
  130. {$EndIf ExtDebugDbx }
  131. i:=0;
  132. while i<=strlen(st) do
  133. begin
  134. if st[i] = '"' then
  135. if do_count then exit
  136. else do_count := true
  137. else
  138. if do_count then
  139. begin
  140. dbx_counter^ := dbx_counter^+byte(st[i]);
  141. { skip file number }
  142. if st[i] = '(' then
  143. begin
  144. inc(i);
  145. while st[i] in ['0'..'9'] do inc(i);
  146. dec(i);
  147. end;
  148. end;
  149. inc(i);
  150. end;
  151. end;
  152. end;
  153. constructor tai_stabs.create(_str : pchar);
  154. begin
  155. inherited create;
  156. typ:=ait_stabs;
  157. str:=_str;
  158. if do_count_dbx then
  159. begin
  160. count_dbx(str);
  161. end;
  162. end;
  163. destructor tai_stabs.destroy;
  164. begin
  165. strdispose(str);
  166. inherited destroy;
  167. end;
  168. constructor tai_stabn.create(_str : pchar);
  169. begin
  170. inherited create;
  171. typ:=ait_stabn;
  172. str:=_str;
  173. end;
  174. destructor tai_stabn.destroy;
  175. begin
  176. strdispose(str);
  177. inherited destroy;
  178. end;
  179. constructor tai_force_line.create;
  180. begin
  181. inherited create;
  182. typ:=ait_force_line;
  183. end;
  184. constructor tai_stab_function_name.create(_str : pchar);
  185. begin
  186. inherited create;
  187. typ:=ait_stab_function_name;
  188. str:=_str;
  189. end;
  190. destructor tai_stab_function_name.destroy;
  191. begin
  192. strdispose(str);
  193. inherited destroy;
  194. end;
  195. end.
  196. {
  197. $Log$
  198. Revision 1.17 2003-10-22 15:22:33 peter
  199. * fixed unitsym-globalsymtable relation so the uses of a unit
  200. is counted correctly
  201. Revision 1.16 2002/11/17 16:31:56 carl
  202. * memory optimization (3-4%) : cleanup of tai fields,
  203. cleanup of tdef and tsym fields.
  204. * make it work for m68k
  205. Revision 1.15 2002/08/12 15:08:39 carl
  206. + stab register indexes for powerpc (moved from gdb to cpubase)
  207. + tprocessor enumeration moved to cpuinfo
  208. + linker in target_info is now a class
  209. * many many updates for m68k (will soon start to compile)
  210. - removed some ifdef or correct them for correct cpu
  211. Revision 1.14 2002/07/01 18:46:22 peter
  212. * internal linker
  213. * reorganized aasm layer
  214. Revision 1.13 2002/05/18 13:34:08 peter
  215. * readded missing revisions
  216. Revision 1.12 2002/05/16 19:46:36 carl
  217. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  218. + try to fix temp allocation (still in ifdef)
  219. + generic constructor calls
  220. + start of tassembler / tmodulebase class cleanup
  221. Revision 1.10 2002/05/06 19:49:26 carl
  222. + added more patches from Mazen for SPARC port
  223. }