gdb.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. strings,
  23. globtype,
  24. aasmtai;
  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_tsym = 160;
  37. N_SourceFile = $64;
  38. N_IncludeFile = $84;
  39. N_BINCL = $82;
  40. N_EINCL = $A2;
  41. N_EXCL = $C2;
  42. type
  43. tai_stabs = class(tai)
  44. str : pchar;
  45. constructor Create(_str : pchar);
  46. destructor Destroy;override;
  47. end;
  48. tai_stabn = class(tai)
  49. str : pchar;
  50. constructor Create(_str : pchar);
  51. destructor Destroy;override;
  52. end;
  53. { insert a cut to split into several smaller files }
  54. tai_force_line = class(tailineinfo)
  55. constructor Create;
  56. end;
  57. tai_stab_function_name = class(tai)
  58. str : pchar;
  59. constructor create(_str : pchar);
  60. destructor destroy;override;
  61. end;
  62. const
  63. DBX_counter : plongint = nil;
  64. do_count_dbx : boolean = false;
  65. implementation
  66. uses fmodule;
  67. { to use N_EXCL we have to count the character in the stabs for
  68. N_BINCL to N_EINCL
  69. Code comes from stabs.c for ld
  70. if (type == N_BINCL)
  71. (
  72. bfd_vma val;
  73. int nest;
  74. bfd_byte *incl_sym;
  75. struct stab_link_includes_entry *incl_entry;
  76. struct stab_link_includes_totals *t;
  77. struct stab_excl_list *ne;
  78. val = 0;
  79. nest = 0;
  80. for (incl_sym = sym + STABSIZE;
  81. incl_sym < symend;
  82. incl_sym += STABSIZE)
  83. (
  84. int incl_type;
  85. incl_type = incl_sym[TYPEOFF];
  86. if (incl_type == 0)
  87. break;
  88. else if (incl_type == N_EINCL)
  89. (
  90. if (nest == 0)
  91. break;
  92. --nest;
  93. )
  94. else if (incl_type == N_BINCL)
  95. ++nest;
  96. else if (nest == 0)
  97. (
  98. const char *str;
  99. str = ((char *) stabstrbuf
  100. + stroff
  101. + bfd_get_32 (abfd, incl_sym + STRDXOFF));
  102. for (; *str != '\0'; str++)
  103. (
  104. val += *str;
  105. if *str == '('
  106. (
  107. Skip the file number.
  108. ++str;
  109. while (isdigit ((unsigned char) *str))
  110. ++str;
  111. --str;
  112. )
  113. )
  114. )
  115. ) }
  116. procedure count_dbx(st : pchar);
  117. var i : longint;
  118. do_count : boolean;
  119. begin
  120. do_count := false;
  121. if assigned(dbx_counter) then
  122. begin
  123. {$IfDef ExtDebugDbx }
  124. Comment(V_Info,'Counting '+st);
  125. Comment(V_Info,'count = '+tostr(dbx_counter^));
  126. Comment(V_Info,'addr = '+tostr(longint(dbx_counter)));
  127. {$EndIf ExtDebugDbx }
  128. i:=0;
  129. while i<=strlen(st) do
  130. begin
  131. if st[i] = '"' then
  132. if do_count then exit
  133. else do_count := true
  134. else
  135. if do_count then
  136. begin
  137. dbx_counter^ := dbx_counter^+byte(st[i]);
  138. { skip file number }
  139. if st[i] = '(' then
  140. begin
  141. inc(i);
  142. while st[i] in ['0'..'9'] do inc(i);
  143. dec(i);
  144. end;
  145. end;
  146. inc(i);
  147. end;
  148. end;
  149. end;
  150. constructor tai_stabs.create(_str : pchar);
  151. begin
  152. inherited create;
  153. typ:=ait_stabs;
  154. if current_module.modulename^='NCNV' then
  155. current_module:=current_module;
  156. str:=_str;
  157. if do_count_dbx then
  158. begin
  159. count_dbx(str);
  160. end;
  161. end;
  162. destructor tai_stabs.destroy;
  163. begin
  164. strdispose(str);
  165. inherited destroy;
  166. end;
  167. constructor tai_stabn.create(_str : pchar);
  168. begin
  169. inherited create;
  170. typ:=ait_stabn;
  171. str:=_str;
  172. end;
  173. destructor tai_stabn.destroy;
  174. begin
  175. strdispose(str);
  176. inherited destroy;
  177. end;
  178. constructor tai_force_line.create;
  179. begin
  180. inherited create;
  181. typ:=ait_force_line;
  182. end;
  183. constructor tai_stab_function_name.create(_str : pchar);
  184. begin
  185. inherited create;
  186. typ:=ait_stab_function_name;
  187. str:=_str;
  188. end;
  189. destructor tai_stab_function_name.destroy;
  190. begin
  191. strdispose(str);
  192. inherited destroy;
  193. end;
  194. end.
  195. {
  196. $Log$
  197. Revision 1.21 2005-02-14 17:13:06 peter
  198. * truncate log
  199. }