Initial revision
[AROS-Contrib.git] / development / compilers / freepascal / compiler / gdb.pas
blobdb7c4d30f41cf378a53c4deadd4fdffc13f8ac47
2 $Id$
3 Copyright (c) 1998-2000 by Florian Klaempfl
5 This units contains special support for the GDB
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 ****************************************************************************
23 unit gdb;
25 interface
27 uses
28 globtype,cpubase,
29 strings,cobjects,globals,aasm;
31 {stab constants }
32 Const
33 N_GSYM = $20;
34 N_STSYM = 38; {initialized const }
35 N_LCSYM = 40; {non initialized variable}
36 N_Function = $24; {function or const }
37 N_TextLine = $44;
38 N_DataLine = $46;
39 N_BssLine = $48;
40 N_RSYM = $40; { register variable }
41 N_LSYM = $80;
42 N_PSYM = 160;
43 N_SourceFile = $64;
44 N_IncludeFile = $84;
45 N_BINCL = $82;
46 N_EINCL = $A2;
47 N_EXCL = $C2;
49 type
50 pai_stabs = ^tai_stabs;
52 tai_stabs = object(tai)
53 str : pchar;
54 constructor init(_str : pchar);
55 destructor done; virtual;
56 end;
58 pai_stabn = ^tai_stabn;
60 tai_stabn = object(tai)
61 str : pchar;
62 constructor init(_str : pchar);
63 destructor done; virtual;
64 end;
66 { insert a cut to split into several smaller files }
67 pai_force_line = ^tai_force_line;
68 tai_force_line = object(tai)
69 constructor init;
70 end;
72 pai_stab_function_name = ^tai_stab_function_name;
74 tai_stab_function_name = object(tai)
75 str : pchar;
76 constructor init(_str : pchar);
77 destructor done; virtual;
78 end;
80 const
81 DBX_counter : plongint = nil;
82 do_count_dbx : boolean = false;
84 {$ifdef i386}
85 { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
86 "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
87 { this is the register order for GDB }
88 GDB_i386index : array[tregister] of shortint =(-1,
89 0,1,2,3,4,5,6,7,0,1,2,3,4,5,7,0,1,2,3,0,1,2,3,
90 -1,10,12,13,14,15,11,
91 -1,-1,-1,-1,-1,-1,-1,-1,-1,
92 -1,-1,-1,-1,-1,-1,
93 -1,-1,-1,-1,
94 -1,-1,-1,-1,-1,
95 { I think, GDB doesn't know MMX (FK) }
96 -1,-1,-1,-1,-1,-1,-1,-1,
97 -1,-1,-1,-1,-1,-1,-1,-1
99 {$endif i386}
101 implementation
103 uses
104 verbose;
105 { to use N_EXCL we have to count the character in the stabs for
106 N_BINCL to N_EINCL
107 Code comes from stabs.c for ld
108 if (type == N_BINCL)
110 bfd_vma val;
111 int nest;
112 bfd_byte *incl_sym;
113 struct stab_link_includes_entry *incl_entry;
114 struct stab_link_includes_totals *t;
115 struct stab_excl_list *ne;
117 val = 0;
118 nest = 0;
119 for (incl_sym = sym + STABSIZE;
120 incl_sym < symend;
121 incl_sym += STABSIZE)
123 int incl_type;
125 incl_type = incl_sym[TYPEOFF];
126 if (incl_type == 0)
127 break;
128 else if (incl_type == N_EINCL)
130 if (nest == 0)
131 break;
132 --nest;
134 else if (incl_type == N_BINCL)
135 ++nest;
136 else if (nest == 0)
138 const char *str;
140 str = ((char *) stabstrbuf
141 + stroff
142 + bfd_get_32 (abfd, incl_sym + STRDXOFF));
143 for (; *str != '\0'; str++)
145 val += *str;
146 if *str == '('
148 Skip the file number.
149 ++str;
150 while (isdigit ((unsigned char) *str))
151 ++str;
152 --str;
159 procedure count_dbx(st : pchar);
160 var i : longint;
161 do_count : boolean;
162 begin
163 do_count := false;
164 if assigned(dbx_counter) then
165 begin
166 {$IfDef ExtDebugDbx }
167 Comment(V_Info,'Counting '+st);
168 Comment(V_Info,'count = '+tostr(dbx_counter^));
169 Comment(V_Info,'addr = '+tostr(longint(dbx_counter)));
170 {$EndIf ExtDebugDbx }
171 i:=0;
172 while i<=strlen(st) do
173 begin
174 if st[i] = '"' then
175 if do_count then exit
176 else do_count := true
177 else
178 if do_count then
179 begin
180 dbx_counter^ := dbx_counter^+byte(st[i]);
181 { skip file number }
182 if st[i] = '(' then
183 begin
184 inc(i);
185 while st[i] in ['0'..'9'] do inc(i);
186 dec(i);
187 end;
188 end;
189 inc(i);
190 end;
191 end;
192 end;
195 constructor tai_stabs.init(_str : pchar);
197 begin
198 inherited init;
199 typ:=ait_stabs;
200 str:=_str;
201 if do_count_dbx then
202 begin
203 count_dbx(str);
204 end;
205 end;
207 destructor tai_stabs.done;
209 begin
210 strdispose(str);
211 inherited done;
212 end;
214 constructor tai_stabn.init(_str : pchar);
216 begin
217 inherited init;
218 typ:=ait_stabn;
219 str:=_str;
220 end;
222 destructor tai_stabn.done;
224 begin
225 strdispose(str);
226 inherited done;
227 end;
229 constructor tai_force_line.init;
231 begin
232 inherited init;
233 typ:=ait_force_line;
234 end;
236 constructor tai_stab_function_name.init(_str : pchar);
238 begin
239 inherited init;
240 typ:=ait_stab_function_name;
241 str:=_str;
242 end;
244 destructor tai_stab_function_name.done;
246 begin
247 strdispose(str);
248 inherited done;
249 end;
250 end.
253 $Log$
254 Revision 1.1 2002/02/19 08:22:20 sasu
255 Initial revision
257 Revision 1.1 2000/07/13 06:29:50 michael
258 + Initial import
260 Revision 1.17 2000/05/12 05:57:34 pierre
261 * * get it to compile with Delphi by Kovacs Attila Zoltan
263 Revision 1.16 2000/05/11 09:40:11 pierre
264 * some DBX changes but it still does not work !
266 Revision 1.15 2000/02/09 13:22:52 peter
267 * log truncated
269 Revision 1.14 2000/01/07 01:14:27 peter
270 * updated copyright to 2000
272 Revision 1.13 1999/11/09 23:51:25 pierre
273 * some DBX work
275 Revision 1.12 1999/08/04 00:23:01 florian
276 * renamed i386asm and i386base to cpuasm and cpubase