gdb.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This units contains special support for the GDB
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit gdb;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. strings,
  22. globtype,
  23. aasmtai;
  24. {stab constants }
  25. Const
  26. N_GSYM = $20;
  27. N_STSYM = 38; {initialized const }
  28. N_LCSYM = 40; {non initialized variable}
  29. N_Function = $24; {function or const }
  30. N_TextLine = $44;
  31. N_DataLine = $46;
  32. N_BssLine = $48;
  33. N_RSYM = $40; { register variable }
  34. N_LSYM = $80;
  35. N_tsym = 160;
  36. N_SourceFile = $64;
  37. N_IncludeFile = $84;
  38. N_BINCL = $82;
  39. N_EINCL = $A2;
  40. N_EXCL = $C2;
  41. type
  42. tai_stabs = class(tai)
  43. str : pchar;
  44. constructor Create(_str : pchar);
  45. destructor Destroy;override;
  46. end;
  47. tai_stabn = class(tai)
  48. str : pchar;
  49. constructor Create(_str : pchar);
  50. destructor Destroy;override;
  51. end;
  52. { insert a cut to split into several smaller files }
  53. tai_force_line = class(tailineinfo)
  54. constructor Create;
  55. end;
  56. tai_stab_function_name = class(tai)
  57. str : pchar;
  58. constructor create(_str : pchar);
  59. destructor destroy;override;
  60. end;
  61. const
  62. DBX_counter : plongint = nil;
  63. do_count_dbx : boolean = false;
  64. implementation
  65. uses fmodule;
  66. { to use N_EXCL we have to count the character in the stabs for
  67. N_BINCL to N_EINCL
  68. Code comes from stabs.c for ld
  69. if (type == N_BINCL)
  70. (
  71. bfd_vma val;
  72. int nest;
  73. bfd_byte *incl_sym;
  74. struct stab_link_includes_entry *incl_entry;
  75. struct stab_link_includes_totals *t;
  76. struct stab_excl_list *ne;
  77. val = 0;
  78. nest = 0;
  79. for (incl_sym = sym + STABSIZE;
  80. incl_sym < symend;
  81. incl_sym += STABSIZE)
  82. (
  83. int incl_type;
  84. incl_type = incl_sym[TYPEOFF];
  85. if (incl_type == 0)
  86. break;
  87. else if (incl_type == N_EINCL)
  88. (
  89. if (nest == 0)
  90. break;
  91. --nest;
  92. )
  93. else if (incl_type == N_BINCL)
  94. ++nest;
  95. else if (nest == 0)
  96. (
  97. const char *str;
  98. str = ((char *) stabstrbuf
  99. + stroff
  100. + bfd_get_32 (abfd, incl_sym + STRDXOFF));
  101. for (; *str != '\0'; str++)
  102. (
  103. val += *str;
  104. if *str == '('
  105. (
  106. Skip the file number.
  107. ++str;
  108. while (isdigit ((unsigned char) *str))
  109. ++str;
  110. --str;
  111. )
  112. )
  113. )
  114. ) }
  115. procedure count_dbx(st : pchar);
  116. var i : longint;
  117. do_count : boolean;
  118. begin
  119. do_count := false;
  120. if assigned(dbx_counter) then
  121. begin
  122. {$IfDef ExtDebugDbx }
  123. Comment(V_Info,'Counting '+st);
  124. Comment(V_Info,'count = '+tostr(dbx_counter^));
  125. Comment(V_Info,'addr = '+tostr(longint(dbx_counter)));
  126. {$EndIf ExtDebugDbx }
  127. i:=0;
  128. while i<=strlen(st) do
  129. begin
  130. if st[i] = '"' then
  131. if do_count then exit
  132. else do_count := true
  133. else
  134. if do_count then
  135. begin
  136. dbx_counter^ := dbx_counter^+byte(st[i]);
  137. { skip file number }
  138. if st[i] = '(' then
  139. begin
  140. inc(i);
  141. while st[i] in ['0'..'9'] do inc(i);
  142. dec(i);
  143. end;
  144. end;
  145. inc(i);
  146. end;
  147. end;
  148. end;
  149. constructor tai_stabs.create(_str : pchar);
  150. begin
  151. inherited create;
  152. typ:=ait_stabs;
  153. if current_module.modulename^='NCNV' then
  154. current_module:=current_module;
  155. str:=_str;
  156. if do_count_dbx then
  157. begin
  158. count_dbx(str);
  159. end;
  160. end;
  161. destructor tai_stabs.destroy;
  162. begin
  163. strdispose(str);
  164. inherited destroy;
  165. end;
  166. constructor tai_stabn.create(_str : pchar);
  167. begin
  168. inherited create;
  169. typ:=ait_stabn;
  170. str:=_str;
  171. end;
  172. destructor tai_stabn.destroy;
  173. begin
  174. strdispose(str);
  175. inherited destroy;
  176. end;
  177. constructor tai_force_line.create;
  178. begin
  179. inherited create;
  180. typ:=ait_force_line;
  181. end;
  182. constructor tai_stab_function_name.create(_str : pchar);
  183. begin
  184. inherited create;
  185. typ:=ait_stab_function_name;
  186. str:=_str;
  187. end;
  188. destructor tai_stab_function_name.destroy;
  189. begin
  190. strdispose(str);
  191. inherited destroy;
  192. end;
  193. end.