gdb.pas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. uses fmodule;
  71. { to use N_EXCL we have to count the character in the stabs for
  72. N_BINCL to N_EINCL
  73. Code comes from stabs.c for ld
  74. if (type == N_BINCL)
  75. (
  76. bfd_vma val;
  77. int nest;
  78. bfd_byte *incl_sym;
  79. struct stab_link_includes_entry *incl_entry;
  80. struct stab_link_includes_totals *t;
  81. struct stab_excl_list *ne;
  82. val = 0;
  83. nest = 0;
  84. for (incl_sym = sym + STABSIZE;
  85. incl_sym < symend;
  86. incl_sym += STABSIZE)
  87. (
  88. int incl_type;
  89. incl_type = incl_sym[TYPEOFF];
  90. if (incl_type == 0)
  91. break;
  92. else if (incl_type == N_EINCL)
  93. (
  94. if (nest == 0)
  95. break;
  96. --nest;
  97. )
  98. else if (incl_type == N_BINCL)
  99. ++nest;
  100. else if (nest == 0)
  101. (
  102. const char *str;
  103. str = ((char *) stabstrbuf
  104. + stroff
  105. + bfd_get_32 (abfd, incl_sym + STRDXOFF));
  106. for (; *str != '\0'; str++)
  107. (
  108. val += *str;
  109. if *str == '('
  110. (
  111. Skip the file number.
  112. ++str;
  113. while (isdigit ((unsigned char) *str))
  114. ++str;
  115. --str;
  116. )
  117. )
  118. )
  119. ) }
  120. procedure count_dbx(st : pchar);
  121. var i : longint;
  122. do_count : boolean;
  123. begin
  124. do_count := false;
  125. if assigned(dbx_counter) then
  126. begin
  127. {$IfDef ExtDebugDbx }
  128. Comment(V_Info,'Counting '+st);
  129. Comment(V_Info,'count = '+tostr(dbx_counter^));
  130. Comment(V_Info,'addr = '+tostr(longint(dbx_counter)));
  131. {$EndIf ExtDebugDbx }
  132. i:=0;
  133. while i<=strlen(st) do
  134. begin
  135. if st[i] = '"' then
  136. if do_count then exit
  137. else do_count := true
  138. else
  139. if do_count then
  140. begin
  141. dbx_counter^ := dbx_counter^+byte(st[i]);
  142. { skip file number }
  143. if st[i] = '(' then
  144. begin
  145. inc(i);
  146. while st[i] in ['0'..'9'] do inc(i);
  147. dec(i);
  148. end;
  149. end;
  150. inc(i);
  151. end;
  152. end;
  153. end;
  154. constructor tai_stabs.create(_str : pchar);
  155. begin
  156. inherited create;
  157. typ:=ait_stabs;
  158. if current_module.modulename^='NCNV' then
  159. current_module:=current_module;
  160. str:=_str;
  161. if do_count_dbx then
  162. begin
  163. count_dbx(str);
  164. end;
  165. end;
  166. destructor tai_stabs.destroy;
  167. begin
  168. strdispose(str);
  169. inherited destroy;
  170. end;
  171. constructor tai_stabn.create(_str : pchar);
  172. begin
  173. inherited create;
  174. typ:=ait_stabn;
  175. str:=_str;
  176. end;
  177. destructor tai_stabn.destroy;
  178. begin
  179. strdispose(str);
  180. inherited destroy;
  181. end;
  182. constructor tai_force_line.create;
  183. begin
  184. inherited create;
  185. typ:=ait_force_line;
  186. end;
  187. constructor tai_stab_function_name.create(_str : pchar);
  188. begin
  189. inherited create;
  190. typ:=ait_stab_function_name;
  191. str:=_str;
  192. end;
  193. destructor tai_stab_function_name.destroy;
  194. begin
  195. strdispose(str);
  196. inherited destroy;
  197. end;
  198. end.
  199. {
  200. $Log$
  201. Revision 1.19 2004-06-20 08:55:29 florian
  202. * logs truncated
  203. Revision 1.18 2004/03/08 22:07:46 peter
  204. * stabs updates to write stabs for def for all implictly used
  205. units
  206. }