]>
Commit | Line | Data |
---|---|---|
37ba3390 | 1 | /* Output sdb-format symbol table information from GNU compiler. |
c913b6f1 | 2 | Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
5f996627 | 3 | 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
37ba3390 | 4 | |
1322177d | 5 | This file is part of GCC. |
37ba3390 | 6 | |
1322177d LB |
7 | GCC is free software; you can redistribute it and/or modify it under |
8 | the terms of the GNU General Public License as published by the Free | |
9 | Software Foundation; either version 2, or (at your option) any later | |
10 | version. | |
37ba3390 | 11 | |
1322177d LB |
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
37ba3390 RS |
16 | |
17 | You should have received a copy of the GNU General Public License | |
1322177d | 18 | along with GCC; see the file COPYING. If not, write to the Free |
366ccddb KC |
19 | Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA |
20 | 02110-1301, USA. */ | |
37ba3390 RS |
21 | |
22 | /* mike@tredysvr.Tredydev.Unisys.COM says: | |
23 | I modified the struct.c example and have a nm of a .o resulting from the | |
24 | AT&T C compiler. From the example below I would conclude the following: | |
25 | ||
26 | 1. All .defs from structures are emitted as scanned. The example below | |
27 | clearly shows the symbol table entries for BoxRec2 are after the first | |
28 | function. | |
29 | ||
30 | 2. All functions and their locals (including statics) are emitted as scanned. | |
31 | ||
32 | 3. All nested unnamed union and structure .defs must be emitted before | |
33 | the structure in which they are nested. The AT&T assembler is a | |
34 | one pass beast as far as symbolics are concerned. | |
35 | ||
36 | 4. All structure .defs are emitted before the typedefs that refer to them. | |
37 | ||
38 | 5. All top level static and external variable definitions are moved to the | |
6dc42e49 | 39 | end of file with all top level statics occurring first before externs. |
37ba3390 RS |
40 | |
41 | 6. All undefined references are at the end of the file. | |
42 | */ | |
43 | ||
44 | #include "config.h" | |
e2500fed | 45 | #include "system.h" |
4977bab6 ZW |
46 | #include "coretypes.h" |
47 | #include "tm.h" | |
e2500fed GK |
48 | #include "debug.h" |
49 | #include "tree.h" | |
50 | #include "ggc.h" | |
21d13d83 | 51 | #include "varray.h" |
e2500fed GK |
52 | |
53 | static GTY(()) tree anonymous_types; | |
37ba3390 | 54 | |
a8d0467e EB |
55 | /* Counter to generate unique "names" for nameless struct members. */ |
56 | ||
57 | static GTY(()) int unnamed_struct_number; | |
58 | ||
21d13d83 ZW |
59 | /* Declarations whose debug info was deferred till end of compilation. */ |
60 | ||
61 | static GTY(()) varray_type deferred_global_decls; | |
62 | ||
16edbbf0 ZW |
63 | /* The C front end may call sdbout_symbol before sdbout_init runs. |
64 | We save all such decls in this list and output them when we get | |
65 | to sdbout_init. */ | |
66 | ||
67 | static GTY(()) tree preinit_symbols; | |
68 | static GTY(()) bool sdbout_initialized; | |
69 | ||
37ba3390 RS |
70 | #ifdef SDB_DEBUGGING_INFO |
71 | ||
37ba3390 | 72 | #include "rtl.h" |
37ba3390 RS |
73 | #include "regs.h" |
74 | #include "flags.h" | |
75 | #include "insn-config.h" | |
76 | #include "reload.h" | |
e016950d KG |
77 | #include "output.h" |
78 | #include "toplev.h" | |
d0af450d | 79 | #include "tm_p.h" |
37ba3390 | 80 | #include "gsyms.h" |
43577e6b | 81 | #include "langhooks.h" |
4977bab6 | 82 | #include "target.h" |
37ba3390 RS |
83 | |
84 | /* 1 if PARM is passed to this function in memory. */ | |
85 | ||
86 | #define PARM_PASSED_IN_MEMORY(PARM) \ | |
3c0cb5de | 87 | (MEM_P (DECL_INCOMING_RTL (PARM))) |
37ba3390 RS |
88 | |
89 | /* A C expression for the integer offset value of an automatic variable | |
90 | (C_AUTO) having address X (an RTX). */ | |
91 | #ifndef DEBUGGER_AUTO_OFFSET | |
92 | #define DEBUGGER_AUTO_OFFSET(X) \ | |
93 | (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0) | |
94 | #endif | |
95 | ||
96 | /* A C expression for the integer offset value of an argument (C_ARG) | |
97 | having address X (an RTX). The nominal offset is OFFSET. */ | |
98 | #ifndef DEBUGGER_ARG_OFFSET | |
99 | #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET) | |
100 | #endif | |
101 | ||
102 | /* Line number of beginning of current function, minus one. | |
103 | Negative means not in a function or not using sdb. */ | |
104 | ||
f4dc8d96 | 105 | int sdb_begin_function_line = -1; |
37ba3390 | 106 | |
37ba3390 RS |
107 | |
108 | extern FILE *asm_out_file; | |
109 | ||
110 | extern tree current_function_decl; | |
111 | ||
76ead72b | 112 | #include "sdbout.h" |
37ba3390 | 113 | |
cef2bd3e AJ |
114 | static void sdbout_init (const char *); |
115 | static void sdbout_finish (const char *); | |
116 | static void sdbout_start_source_file (unsigned int, const char *); | |
117 | static void sdbout_end_source_file (unsigned int); | |
118 | static void sdbout_begin_block (unsigned int, unsigned int); | |
119 | static void sdbout_end_block (unsigned int, unsigned int); | |
120 | static void sdbout_source_line (unsigned int, const char *); | |
121 | static void sdbout_end_epilogue (unsigned int, const char *); | |
122 | static void sdbout_global_decl (tree); | |
653e276c | 123 | #ifndef MIPS_DEBUGGING_INFO |
cef2bd3e | 124 | static void sdbout_begin_prologue (unsigned int, const char *); |
653e276c | 125 | #endif |
cef2bd3e AJ |
126 | static void sdbout_end_prologue (unsigned int, const char *); |
127 | static void sdbout_begin_function (tree); | |
128 | static void sdbout_end_function (unsigned int); | |
129 | static void sdbout_toplevel_data (tree); | |
130 | static void sdbout_label (rtx); | |
131 | static char *gen_fake_label (void); | |
132 | static int plain_type (tree); | |
133 | static int template_name_p (tree); | |
134 | static void sdbout_record_type_name (tree); | |
135 | static int plain_type_1 (tree, int); | |
136 | static void sdbout_block (tree); | |
137 | static void sdbout_syms (tree); | |
7bdb32b9 | 138 | #ifdef SDB_ALLOW_FORWARD_REFERENCES |
cef2bd3e AJ |
139 | static void sdbout_queue_anonymous_type (tree); |
140 | static void sdbout_dequeue_anonymous_types (void); | |
7bdb32b9 | 141 | #endif |
cef2bd3e AJ |
142 | static void sdbout_type (tree); |
143 | static void sdbout_field_types (tree); | |
144 | static void sdbout_one_type (tree); | |
145 | static void sdbout_parms (tree); | |
146 | static void sdbout_reg_parms (tree); | |
147 | static void sdbout_global_decl (tree); | |
37ba3390 | 148 | |
cef2bd3e | 149 | /* Random macros describing parts of SDB data. */ |
37ba3390 RS |
150 | |
151 | /* Default value of delimiter is ";". */ | |
152 | #ifndef SDB_DELIM | |
153 | #define SDB_DELIM ";" | |
154 | #endif | |
155 | ||
156 | /* Maximum number of dimensions the assembler will allow. */ | |
157 | #ifndef SDB_MAX_DIM | |
158 | #define SDB_MAX_DIM 4 | |
159 | #endif | |
160 | ||
161 | #ifndef PUT_SDB_SCL | |
162 | #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM) | |
163 | #endif | |
164 | ||
165 | #ifndef PUT_SDB_INT_VAL | |
e016950d KG |
166 | #define PUT_SDB_INT_VAL(a) \ |
167 | do { \ | |
90ff44cf KG |
168 | fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \ |
169 | (HOST_WIDE_INT) (a), SDB_DELIM); \ | |
e016950d KG |
170 | } while (0) |
171 | ||
37ba3390 RS |
172 | #endif |
173 | ||
174 | #ifndef PUT_SDB_VAL | |
175 | #define PUT_SDB_VAL(a) \ | |
176 | ( fputs ("\t.val\t", asm_out_file), \ | |
177 | output_addr_const (asm_out_file, (a)), \ | |
178 | fprintf (asm_out_file, SDB_DELIM)) | |
179 | #endif | |
180 | ||
181 | #ifndef PUT_SDB_DEF | |
182 | #define PUT_SDB_DEF(a) \ | |
183 | do { fprintf (asm_out_file, "\t.def\t"); \ | |
cef2bd3e | 184 | assemble_name (asm_out_file, a); \ |
37ba3390 RS |
185 | fprintf (asm_out_file, SDB_DELIM); } while (0) |
186 | #endif | |
187 | ||
188 | #ifndef PUT_SDB_PLAIN_DEF | |
189 | #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM) | |
190 | #endif | |
191 | ||
192 | #ifndef PUT_SDB_ENDEF | |
193 | #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file) | |
194 | #endif | |
195 | ||
196 | #ifndef PUT_SDB_TYPE | |
197 | #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM) | |
198 | #endif | |
199 | ||
200 | #ifndef PUT_SDB_SIZE | |
e016950d KG |
201 | #define PUT_SDB_SIZE(a) \ |
202 | do { \ | |
90ff44cf KG |
203 | fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \ |
204 | (HOST_WIDE_INT) (a), SDB_DELIM); \ | |
e016950d | 205 | } while(0) |
37ba3390 RS |
206 | #endif |
207 | ||
208 | #ifndef PUT_SDB_START_DIM | |
209 | #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t") | |
210 | #endif | |
211 | ||
212 | #ifndef PUT_SDB_NEXT_DIM | |
213 | #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a) | |
214 | #endif | |
215 | ||
216 | #ifndef PUT_SDB_LAST_DIM | |
217 | #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM) | |
218 | #endif | |
219 | ||
220 | #ifndef PUT_SDB_TAG | |
221 | #define PUT_SDB_TAG(a) \ | |
222 | do { fprintf (asm_out_file, "\t.tag\t"); \ | |
800a6a0c | 223 | assemble_name (asm_out_file, a); \ |
37ba3390 RS |
224 | fprintf (asm_out_file, SDB_DELIM); } while (0) |
225 | #endif | |
226 | ||
227 | #ifndef PUT_SDB_BLOCK_START | |
228 | #define PUT_SDB_BLOCK_START(LINE) \ | |
229 | fprintf (asm_out_file, \ | |
230 | "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \ | |
231 | SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM) | |
232 | #endif | |
233 | ||
234 | #ifndef PUT_SDB_BLOCK_END | |
235 | #define PUT_SDB_BLOCK_END(LINE) \ | |
236 | fprintf (asm_out_file, \ | |
237 | "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \ | |
238 | SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM) | |
239 | #endif | |
240 | ||
241 | #ifndef PUT_SDB_FUNCTION_START | |
242 | #define PUT_SDB_FUNCTION_START(LINE) \ | |
243 | fprintf (asm_out_file, \ | |
244 | "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \ | |
245 | SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM) | |
246 | #endif | |
247 | ||
248 | #ifndef PUT_SDB_FUNCTION_END | |
249 | #define PUT_SDB_FUNCTION_END(LINE) \ | |
250 | fprintf (asm_out_file, \ | |
251 | "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \ | |
252 | SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM) | |
253 | #endif | |
254 | ||
37ba3390 | 255 | /* Return the sdb tag identifier string for TYPE |
6d2f8887 | 256 | if TYPE has already been defined; otherwise return a null pointer. */ |
37ba3390 | 257 | |
6fb2e346 | 258 | #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type) |
37ba3390 RS |
259 | |
260 | /* Set the sdb tag identifier string for TYPE to NAME. */ | |
261 | ||
262 | #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \ | |
0334ef47 | 263 | TYPE_SYMTAB_POINTER (TYPE) = (char *)(NAME) |
37ba3390 RS |
264 | |
265 | /* Return the name (a string) of the struct, union or enum tag | |
266 | described by the TREE_LIST node LINK. This is 0 for an anonymous one. */ | |
267 | ||
268 | #define TAG_NAME(link) \ | |
269 | (((link) && TREE_PURPOSE ((link)) \ | |
270 | && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \ | |
271 | ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0) | |
272 | ||
273 | /* Ensure we don't output a negative line number. */ | |
274 | #define MAKE_LINE_SAFE(line) \ | |
5197bd50 RK |
275 | if ((int) line <= sdb_begin_function_line) \ |
276 | line = sdb_begin_function_line + 1 | |
cc694a81 DE |
277 | |
278 | /* Perform linker optimization of merging header file definitions together | |
279 | for targets with MIPS_DEBUGGING_INFO defined. This won't work without a | |
280 | post 960826 version of GAS. Nothing breaks with earlier versions of GAS, | |
281 | the optimization just won't be done. The native assembler already has the | |
282 | necessary support. */ | |
283 | ||
284 | #ifdef MIPS_DEBUGGING_INFO | |
285 | ||
cc694a81 DE |
286 | /* ECOFF linkers have an optimization that does the same kind of thing as |
287 | N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the | |
288 | executable. To achieve this, GCC must output a .file for each file | |
289 | name change. */ | |
290 | ||
291 | /* This is a stack of input files. */ | |
292 | ||
293 | struct sdb_file | |
294 | { | |
295 | struct sdb_file *next; | |
df07dc5b | 296 | const char *name; |
cc694a81 DE |
297 | }; |
298 | ||
299 | /* This is the top of the stack. */ | |
300 | ||
301 | static struct sdb_file *current_file; | |
302 | ||
303 | #endif /* MIPS_DEBUGGING_INFO */ | |
cef2bd3e | 304 | |
7f905405 | 305 | /* The debug hooks structure. */ |
54b6670a | 306 | const struct gcc_debug_hooks sdb_debug_hooks = |
a51d908e | 307 | { |
6097b0c3 DP |
308 | sdbout_init, /* init */ |
309 | sdbout_finish, /* finish */ | |
310 | debug_nothing_int_charstar, /* define */ | |
311 | debug_nothing_int_charstar, /* undef */ | |
312 | sdbout_start_source_file, /* start_source_file */ | |
313 | sdbout_end_source_file, /* end_source_file */ | |
314 | sdbout_begin_block, /* begin_block */ | |
315 | sdbout_end_block, /* end_block */ | |
316 | debug_true_tree, /* ignore_block */ | |
317 | sdbout_source_line, /* source_line */ | |
653e276c NB |
318 | #ifdef MIPS_DEBUGGING_INFO |
319 | /* Defer on MIPS systems so that parameter descriptions follow | |
320 | function entry. */ | |
6097b0c3 DP |
321 | debug_nothing_int_charstar, /* begin_prologue */ |
322 | sdbout_end_prologue, /* end_prologue */ | |
653e276c | 323 | #else |
6097b0c3 DP |
324 | sdbout_begin_prologue, /* begin_prologue */ |
325 | debug_nothing_int_charstar, /* end_prologue */ | |
653e276c | 326 | #endif |
6097b0c3 DP |
327 | sdbout_end_epilogue, /* end_epilogue */ |
328 | sdbout_begin_function, /* begin_function */ | |
329 | sdbout_end_function, /* end_function */ | |
330 | debug_nothing_tree, /* function_decl */ | |
331 | sdbout_global_decl, /* global_decl */ | |
1729e46c | 332 | sdbout_symbol, /* type_decl */ |
6097b0c3 DP |
333 | debug_nothing_tree_tree, /* imported_module_or_decl */ |
334 | debug_nothing_tree, /* deferred_inline_function */ | |
335 | debug_nothing_tree, /* outlining_inline_function */ | |
336 | sdbout_label, /* label */ | |
014a1138 | 337 | debug_nothing_int, /* handle_pch */ |
9e9945c5 | 338 | debug_nothing_rtx, /* var_location */ |
87c8b4be | 339 | debug_nothing_void, /* switch_text_section */ |
9e9945c5 | 340 | 0 /* start_end_main_source_file */ |
a51d908e | 341 | }; |
37ba3390 RS |
342 | |
343 | /* Return a unique string to name an anonymous type. */ | |
344 | ||
345 | static char * | |
cef2bd3e | 346 | gen_fake_label (void) |
37ba3390 RS |
347 | { |
348 | char label[10]; | |
349 | char *labelstr; | |
37bf6443 | 350 | sprintf (label, ".%dfake", unnamed_struct_number); |
37ba3390 | 351 | unnamed_struct_number++; |
6d9f628e | 352 | labelstr = xstrdup (label); |
37ba3390 RS |
353 | return labelstr; |
354 | } | |
cef2bd3e | 355 | |
37ba3390 RS |
356 | /* Return the number which describes TYPE for SDB. |
357 | For pointers, etc., this function is recursive. | |
358 | Each record, union or enumeral type must already have had a | |
359 | tag number output. */ | |
360 | ||
361 | /* The number is given by d6d5d4d3d2d1bbbb | |
362 | where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array. | |
363 | Thus, char *foo () has bbbb=T_CHAR | |
364 | d1=D_FCN | |
365 | d2=D_PTR | |
366 | N_BTMASK= 017 1111 basic type field. | |
367 | N_TSHIFT= 2 derived type shift | |
368 | N_BTSHFT= 4 Basic type shift */ | |
369 | ||
370 | /* Produce the number that describes a pointer, function or array type. | |
371 | PREV is the number describing the target, value or element type. | |
372 | DT_type describes how to transform that type. */ | |
aa7a5913 | 373 | #define PUSH_DERIVED_LEVEL(DT_type,PREV) \ |
cf403648 KH |
374 | ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \ |
375 | | ((int) DT_type << (int) N_BTSHFT) \ | |
376 | | ((PREV) & (int) N_BTMASK)) | |
37ba3390 RS |
377 | |
378 | /* Number of elements used in sdb_dims. */ | |
379 | static int sdb_n_dims = 0; | |
380 | ||
381 | /* Table of array dimensions of current type. */ | |
382 | static int sdb_dims[SDB_MAX_DIM]; | |
383 | ||
384 | /* Size of outermost array currently being processed. */ | |
385 | static int sdb_type_size = -1; | |
386 | ||
387 | static int | |
cef2bd3e | 388 | plain_type (tree type) |
37ba3390 | 389 | { |
1a625283 | 390 | int val = plain_type_1 (type, 0); |
37ba3390 RS |
391 | |
392 | /* If we have already saved up some array dimensions, print them now. */ | |
393 | if (sdb_n_dims > 0) | |
394 | { | |
395 | int i; | |
396 | PUT_SDB_START_DIM; | |
397 | for (i = sdb_n_dims - 1; i > 0; i--) | |
398 | PUT_SDB_NEXT_DIM (sdb_dims[i]); | |
399 | PUT_SDB_LAST_DIM (sdb_dims[0]); | |
400 | sdb_n_dims = 0; | |
401 | ||
402 | sdb_type_size = int_size_in_bytes (type); | |
403 | /* Don't kill sdb if type is not laid out or has variable size. */ | |
404 | if (sdb_type_size < 0) | |
405 | sdb_type_size = 0; | |
406 | } | |
407 | /* If we have computed the size of an array containing this type, | |
408 | print it now. */ | |
409 | if (sdb_type_size >= 0) | |
410 | { | |
411 | PUT_SDB_SIZE (sdb_type_size); | |
412 | sdb_type_size = -1; | |
413 | } | |
414 | return val; | |
415 | } | |
416 | ||
4be2397b | 417 | static int |
cef2bd3e | 418 | template_name_p (tree name) |
4be2397b | 419 | { |
b3694847 | 420 | const char *ptr = IDENTIFIER_POINTER (name); |
4be2397b RS |
421 | while (*ptr && *ptr != '<') |
422 | ptr++; | |
423 | ||
424 | return *ptr != '\0'; | |
425 | } | |
426 | ||
37ba3390 | 427 | static void |
cef2bd3e | 428 | sdbout_record_type_name (tree type) |
37ba3390 | 429 | { |
bb93b973 | 430 | const char *name = 0; |
37ba3390 RS |
431 | int no_name; |
432 | ||
433 | if (KNOWN_TYPE_TAG (type)) | |
434 | return; | |
435 | ||
436 | if (TYPE_NAME (type) != 0) | |
437 | { | |
438 | tree t = 0; | |
bb93b973 | 439 | |
37ba3390 RS |
440 | /* Find the IDENTIFIER_NODE for the type name. */ |
441 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
95b2ff8b | 442 | t = TYPE_NAME (type); |
12357e42 | 443 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) |
37ba3390 RS |
444 | { |
445 | t = DECL_NAME (TYPE_NAME (type)); | |
4be2397b RS |
446 | /* The DECL_NAME for templates includes "<>", which breaks |
447 | most assemblers. Use its assembler name instead, which | |
448 | has been mangled into being safe. */ | |
449 | if (t && template_name_p (t)) | |
450 | t = DECL_ASSEMBLER_NAME (TYPE_NAME (type)); | |
37ba3390 | 451 | } |
37ba3390 RS |
452 | |
453 | /* Now get the name as a string, or invent one. */ | |
4be2397b | 454 | if (t != NULL_TREE) |
37ba3390 RS |
455 | name = IDENTIFIER_POINTER (t); |
456 | } | |
457 | ||
458 | no_name = (name == 0 || *name == 0); | |
459 | if (no_name) | |
460 | name = gen_fake_label (); | |
461 | ||
462 | SET_KNOWN_TYPE_TAG (type, name); | |
463 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
464 | if (no_name) | |
465 | sdbout_queue_anonymous_type (type); | |
466 | #endif | |
467 | } | |
468 | ||
1a625283 JW |
469 | /* Return the .type value for type TYPE. |
470 | ||
471 | LEVEL indicates how many levels deep we have recursed into the type. | |
472 | The SDB debug format can only represent 6 derived levels of types. | |
473 | After that, we must output inaccurate debug info. We deliberately | |
474 | stop before the 7th level, so that ADA recursive types will not give an | |
475 | infinite loop. */ | |
476 | ||
37ba3390 | 477 | static int |
cef2bd3e | 478 | plain_type_1 (tree type, int level) |
37ba3390 RS |
479 | { |
480 | if (type == 0) | |
481 | type = void_type_node; | |
1a625283 | 482 | else if (type == error_mark_node) |
37ba3390 | 483 | type = integer_type_node; |
1a625283 JW |
484 | else |
485 | type = TYPE_MAIN_VARIANT (type); | |
37ba3390 RS |
486 | |
487 | switch (TREE_CODE (type)) | |
488 | { | |
489 | case VOID_TYPE: | |
490 | return T_VOID; | |
a0587d56 | 491 | case BOOLEAN_TYPE: |
37ba3390 RS |
492 | case INTEGER_TYPE: |
493 | { | |
494 | int size = int_size_in_bytes (type) * BITS_PER_UNIT; | |
aed0ae9b JW |
495 | |
496 | /* Carefully distinguish all the standard types of C, | |
497 | without messing up if the language is not C. | |
498 | Note that we check only for the names that contain spaces; | |
499 | other names might occur by coincidence in other languages. */ | |
500 | if (TYPE_NAME (type) != 0 | |
501 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
502 | && DECL_NAME (TYPE_NAME (type)) != 0 | |
503 | && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) | |
504 | { | |
83182544 | 505 | const char *const name |
ebb13e7e | 506 | = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); |
aed0ae9b | 507 | |
c85f7c16 JL |
508 | if (!strcmp (name, "char")) |
509 | return T_CHAR; | |
aed0ae9b JW |
510 | if (!strcmp (name, "unsigned char")) |
511 | return T_UCHAR; | |
512 | if (!strcmp (name, "signed char")) | |
513 | return T_CHAR; | |
c85f7c16 JL |
514 | if (!strcmp (name, "int")) |
515 | return T_INT; | |
aed0ae9b JW |
516 | if (!strcmp (name, "unsigned int")) |
517 | return T_UINT; | |
518 | if (!strcmp (name, "short int")) | |
519 | return T_SHORT; | |
520 | if (!strcmp (name, "short unsigned int")) | |
521 | return T_USHORT; | |
522 | if (!strcmp (name, "long int")) | |
523 | return T_LONG; | |
524 | if (!strcmp (name, "long unsigned int")) | |
525 | return T_ULONG; | |
526 | } | |
527 | ||
c85f7c16 | 528 | if (size == INT_TYPE_SIZE) |
8df83eae | 529 | return (TYPE_UNSIGNED (type) ? T_UINT : T_INT); |
37ba3390 | 530 | if (size == CHAR_TYPE_SIZE) |
8df83eae | 531 | return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR); |
37ba3390 | 532 | if (size == SHORT_TYPE_SIZE) |
8df83eae | 533 | return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT); |
580b8ee2 | 534 | if (size == LONG_TYPE_SIZE) |
8df83eae | 535 | return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG); |
7726fc45 | 536 | if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */ |
8df83eae | 537 | return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG); |
37ba3390 RS |
538 | return 0; |
539 | } | |
540 | ||
541 | case REAL_TYPE: | |
542 | { | |
64c6526a JW |
543 | int precision = TYPE_PRECISION (type); |
544 | if (precision == FLOAT_TYPE_SIZE) | |
37ba3390 | 545 | return T_FLOAT; |
64c6526a | 546 | if (precision == DOUBLE_TYPE_SIZE) |
37ba3390 | 547 | return T_DOUBLE; |
64c6526a JW |
548 | #ifdef EXTENDED_SDB_BASIC_TYPES |
549 | if (precision == LONG_DOUBLE_TYPE_SIZE) | |
550 | return T_LNGDBL; | |
e5e809f4 JL |
551 | #else |
552 | if (precision == LONG_DOUBLE_TYPE_SIZE) | |
553 | return T_DOUBLE; /* better than nothing */ | |
64c6526a | 554 | #endif |
37ba3390 RS |
555 | return 0; |
556 | } | |
557 | ||
558 | case ARRAY_TYPE: | |
559 | { | |
560 | int m; | |
1a625283 JW |
561 | if (level >= 6) |
562 | return T_VOID; | |
563 | else | |
564 | m = plain_type_1 (TREE_TYPE (type), level+1); | |
37ba3390 RS |
565 | if (sdb_n_dims < SDB_MAX_DIM) |
566 | sdb_dims[sdb_n_dims++] | |
567 | = (TYPE_DOMAIN (type) | |
665f2503 RK |
568 | && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0 |
569 | && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0 | |
570 | && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0) | |
571 | && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) | |
572 | ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0) | |
573 | - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1) | |
37ba3390 | 574 | : 0); |
665f2503 | 575 | |
37ba3390 RS |
576 | return PUSH_DERIVED_LEVEL (DT_ARY, m); |
577 | } | |
578 | ||
579 | case RECORD_TYPE: | |
580 | case UNION_TYPE: | |
c1b98a95 | 581 | case QUAL_UNION_TYPE: |
37ba3390 RS |
582 | case ENUMERAL_TYPE: |
583 | { | |
584 | char *tag; | |
585 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
586 | sdbout_record_type_name (type); | |
587 | #endif | |
588 | #ifndef SDB_ALLOW_UNKNOWN_REFERENCES | |
589 | if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0) | |
590 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
591 | || TYPE_MODE (type) != VOIDmode | |
592 | #endif | |
593 | ) | |
594 | #endif | |
595 | { | |
596 | /* Output the referenced structure tag name | |
597 | only if the .def has already been finished. | |
598 | At least on 386, the Unix assembler | |
599 | cannot handle forward references to tags. */ | |
0f41302f MS |
600 | /* But the 88100, it requires them, sigh... */ |
601 | /* And the MIPS requires unknown refs as well... */ | |
37ba3390 RS |
602 | tag = KNOWN_TYPE_TAG (type); |
603 | PUT_SDB_TAG (tag); | |
604 | /* These 3 lines used to follow the close brace. | |
605 | However, a size of 0 without a tag implies a tag of 0, | |
606 | so if we don't know a tag, we can't mention the size. */ | |
607 | sdb_type_size = int_size_in_bytes (type); | |
608 | if (sdb_type_size < 0) | |
609 | sdb_type_size = 0; | |
610 | } | |
611 | return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT | |
612 | : (TREE_CODE (type) == UNION_TYPE) ? T_UNION | |
c1b98a95 | 613 | : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION |
37ba3390 RS |
614 | : T_ENUM); |
615 | } | |
616 | case POINTER_TYPE: | |
617 | case REFERENCE_TYPE: | |
618 | { | |
1a625283 JW |
619 | int m; |
620 | if (level >= 6) | |
621 | return T_VOID; | |
622 | else | |
623 | m = plain_type_1 (TREE_TYPE (type), level+1); | |
37ba3390 RS |
624 | return PUSH_DERIVED_LEVEL (DT_PTR, m); |
625 | } | |
626 | case FUNCTION_TYPE: | |
627 | case METHOD_TYPE: | |
628 | { | |
1a625283 JW |
629 | int m; |
630 | if (level >= 6) | |
631 | return T_VOID; | |
632 | else | |
633 | m = plain_type_1 (TREE_TYPE (type), level+1); | |
37ba3390 RS |
634 | return PUSH_DERIVED_LEVEL (DT_FCN, m); |
635 | } | |
636 | default: | |
637 | return 0; | |
638 | } | |
639 | } | |
cef2bd3e | 640 | |
37ba3390 | 641 | /* Output the symbols defined in block number DO_BLOCK. |
37ba3390 RS |
642 | |
643 | This function works by walking the tree structure of blocks, | |
644 | counting blocks until it finds the desired block. */ | |
645 | ||
646 | static int do_block = 0; | |
647 | ||
37ba3390 | 648 | static void |
cef2bd3e | 649 | sdbout_block (tree block) |
37ba3390 RS |
650 | { |
651 | while (block) | |
652 | { | |
653 | /* Ignore blocks never expanded or otherwise marked as real. */ | |
654 | if (TREE_USED (block)) | |
655 | { | |
656 | /* When we reach the specified block, output its symbols. */ | |
18c038b9 MM |
657 | if (BLOCK_NUMBER (block) == do_block) |
658 | sdbout_syms (BLOCK_VARS (block)); | |
37ba3390 RS |
659 | |
660 | /* If we are past the specified block, stop the scan. */ | |
18c038b9 | 661 | if (BLOCK_NUMBER (block) > do_block) |
37ba3390 RS |
662 | return; |
663 | ||
37ba3390 RS |
664 | /* Scan the blocks within this block. */ |
665 | sdbout_block (BLOCK_SUBBLOCKS (block)); | |
666 | } | |
667 | ||
668 | block = BLOCK_CHAIN (block); | |
669 | } | |
670 | } | |
cef2bd3e | 671 | |
37ba3390 RS |
672 | /* Call sdbout_symbol on each decl in the chain SYMS. */ |
673 | ||
674 | static void | |
cef2bd3e | 675 | sdbout_syms (tree syms) |
37ba3390 RS |
676 | { |
677 | while (syms) | |
678 | { | |
5b7f1820 RS |
679 | if (TREE_CODE (syms) != LABEL_DECL) |
680 | sdbout_symbol (syms, 1); | |
37ba3390 RS |
681 | syms = TREE_CHAIN (syms); |
682 | } | |
683 | } | |
684 | ||
685 | /* Output SDB information for a symbol described by DECL. | |
686 | LOCAL is nonzero if the symbol is not file-scope. */ | |
687 | ||
688 | void | |
cef2bd3e | 689 | sdbout_symbol (tree decl, int local) |
37ba3390 | 690 | { |
37ba3390 RS |
691 | tree type = TREE_TYPE (decl); |
692 | tree context = NULL_TREE; | |
693 | rtx value; | |
694 | int regno = -1; | |
ebb13e7e | 695 | const char *name; |
37ba3390 | 696 | |
16edbbf0 ZW |
697 | /* If we are called before sdbout_init is run, just save the symbol |
698 | for later. */ | |
699 | if (!sdbout_initialized) | |
700 | { | |
701 | preinit_symbols = tree_cons (0, decl, preinit_symbols); | |
702 | return; | |
703 | } | |
704 | ||
16d90796 RS |
705 | sdbout_one_type (type); |
706 | ||
37ba3390 RS |
707 | switch (TREE_CODE (decl)) |
708 | { | |
709 | case CONST_DECL: | |
710 | /* Enum values are defined by defining the enum type. */ | |
711 | return; | |
712 | ||
713 | case FUNCTION_DECL: | |
714 | /* Don't mention a nested function under its parent. */ | |
715 | context = decl_function_context (decl); | |
716 | if (context == current_function_decl) | |
717 | return; | |
b01a1fdb JW |
718 | /* Check DECL_INITIAL to distinguish declarations from definitions. |
719 | Don't output debug info here for declarations; they will have | |
720 | a DECL_INITIAL value of 0. */ | |
721 | if (! DECL_INITIAL (decl)) | |
37ba3390 | 722 | return; |
3c0cb5de | 723 | if (!MEM_P (DECL_RTL (decl)) |
37ba3390 RS |
724 | || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF) |
725 | return; | |
726 | PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
727 | PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0)); | |
728 | PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT); | |
729 | break; | |
730 | ||
731 | case TYPE_DECL: | |
732 | /* Done with tagged types. */ | |
733 | if (DECL_NAME (decl) == 0) | |
734 | return; | |
16d90796 RS |
735 | if (DECL_IGNORED_P (decl)) |
736 | return; | |
7fe63418 DS |
737 | /* Don't output intrinsic types. GAS chokes on SDB .def |
738 | statements that contain identifiers with embedded spaces | |
739 | (eg "unsigned long"). */ | |
740 | if (DECL_IS_BUILTIN (decl)) | |
741 | return; | |
37ba3390 RS |
742 | |
743 | /* Output typedef name. */ | |
4be2397b RS |
744 | if (template_name_p (DECL_NAME (decl))) |
745 | PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
746 | else | |
747 | PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl))); | |
37ba3390 RS |
748 | PUT_SDB_SCL (C_TPDEF); |
749 | break; | |
750 | ||
751 | case PARM_DECL: | |
752 | /* Parm decls go in their own separate chains | |
753 | and are output by sdbout_reg_parms and sdbout_parms. */ | |
41374e13 | 754 | gcc_unreachable (); |
37ba3390 RS |
755 | |
756 | case VAR_DECL: | |
757 | /* Don't mention a variable that is external. | |
758 | Let the file that defines it describe it. */ | |
216d5cdd | 759 | if (DECL_EXTERNAL (decl)) |
37ba3390 RS |
760 | return; |
761 | ||
16d90796 RS |
762 | /* Ignore __FUNCTION__, etc. */ |
763 | if (DECL_IGNORED_P (decl)) | |
764 | return; | |
765 | ||
37ba3390 RS |
766 | /* If there was an error in the declaration, don't dump core |
767 | if there is no RTL associated with the variable doesn't | |
768 | exist. */ | |
d975d8c3 | 769 | if (!DECL_RTL_SET_P (decl)) |
37ba3390 RS |
770 | return; |
771 | ||
786de7eb | 772 | SET_DECL_RTL (decl, |
d975d8c3 | 773 | eliminate_regs (DECL_RTL (decl), 0, NULL_RTX)); |
bf1e8c4d | 774 | #ifdef LEAF_REG_REMAP |
54ff41b7 | 775 | if (current_function_uses_only_leaf_regs) |
bf1e8c4d RS |
776 | leaf_renumber_regs_insn (DECL_RTL (decl)); |
777 | #endif | |
778 | value = DECL_RTL (decl); | |
37ba3390 RS |
779 | |
780 | /* Don't mention a variable at all | |
781 | if it was completely optimized into nothingness. | |
782 | ||
783 | If DECL was from an inline function, then its rtl | |
784 | is not identically the rtl that was used in this | |
785 | particular compilation. */ | |
f8cfc6aa | 786 | if (REG_P (value)) |
37ba3390 | 787 | { |
69deb6e0 | 788 | regno = REGNO (value); |
37ba3390 | 789 | if (regno >= FIRST_PSEUDO_REGISTER) |
37ba3390 RS |
790 | return; |
791 | } | |
bf1e8c4d | 792 | else if (GET_CODE (value) == SUBREG) |
37ba3390 | 793 | { |
37ba3390 | 794 | while (GET_CODE (value) == SUBREG) |
ddef6bc7 | 795 | value = SUBREG_REG (value); |
f8cfc6aa | 796 | if (REG_P (value)) |
37ba3390 | 797 | { |
ddef6bc7 | 798 | if (REGNO (value) >= FIRST_PSEUDO_REGISTER) |
bf1e8c4d | 799 | return; |
37ba3390 | 800 | } |
69deb6e0 RK |
801 | regno = REGNO (alter_subreg (&value)); |
802 | SET_DECL_RTL (decl, value); | |
37ba3390 | 803 | } |
39eae9f4 RS |
804 | /* Don't output anything if an auto variable |
805 | gets RTL that is static. | |
806 | GAS version 2.2 can't handle such output. */ | |
3c0cb5de | 807 | else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0)) |
39eae9f4 RS |
808 | && ! TREE_STATIC (decl)) |
809 | return; | |
37ba3390 RS |
810 | |
811 | /* Emit any structure, union, or enum type that has not been output. | |
812 | This occurs for tag-less structs (et al) used to declare variables | |
813 | within functions. */ | |
814 | if (TREE_CODE (type) == ENUMERAL_TYPE | |
815 | || TREE_CODE (type) == RECORD_TYPE | |
c1b98a95 RK |
816 | || TREE_CODE (type) == UNION_TYPE |
817 | || TREE_CODE (type) == QUAL_UNION_TYPE) | |
37ba3390 | 818 | { |
d0f062fb | 819 | if (COMPLETE_TYPE_P (type) /* not a forward reference */ |
37ba3390 RS |
820 | && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */ |
821 | sdbout_one_type (type); | |
822 | } | |
823 | ||
824 | /* Defer SDB information for top-level initialized variables! */ | |
825 | if (! local | |
3c0cb5de | 826 | && MEM_P (value) |
37ba3390 RS |
827 | && DECL_INITIAL (decl)) |
828 | return; | |
829 | ||
ed5f8355 RS |
830 | /* C++ in 2.3 makes nameless symbols. That will be fixed later. |
831 | For now, avoid crashing. */ | |
832 | if (DECL_NAME (decl) == NULL_TREE) | |
833 | return; | |
834 | ||
37ba3390 | 835 | /* Record the name for, starting a symtab entry. */ |
4eadbbd5 RK |
836 | if (local) |
837 | name = IDENTIFIER_POINTER (DECL_NAME (decl)); | |
838 | else | |
839 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
37ba3390 | 840 | |
3c0cb5de | 841 | if (MEM_P (value) |
37ba3390 RS |
842 | && GET_CODE (XEXP (value, 0)) == SYMBOL_REF) |
843 | { | |
844 | PUT_SDB_DEF (name); | |
845 | if (TREE_PUBLIC (decl)) | |
846 | { | |
847 | PUT_SDB_VAL (XEXP (value, 0)); | |
786de7eb | 848 | PUT_SDB_SCL (C_EXT); |
37ba3390 RS |
849 | } |
850 | else | |
851 | { | |
852 | PUT_SDB_VAL (XEXP (value, 0)); | |
786de7eb | 853 | PUT_SDB_SCL (C_STAT); |
37ba3390 RS |
854 | } |
855 | } | |
856 | else if (regno >= 0) | |
857 | { | |
858 | PUT_SDB_DEF (name); | |
859 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno)); | |
860 | PUT_SDB_SCL (C_REG); | |
861 | } | |
3c0cb5de JQ |
862 | else if (MEM_P (value) |
863 | && (MEM_P (XEXP (value, 0)) | |
f8cfc6aa | 864 | || (REG_P (XEXP (value, 0)) |
d8a0edf4 | 865 | && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM |
5b7f1820 | 866 | && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM))) |
37ba3390 RS |
867 | /* If the value is indirect by memory or by a register |
868 | that isn't the frame pointer | |
869 | then it means the object is variable-sized and address through | |
870 | that register or stack slot. COFF has no way to represent this | |
871 | so all we can do is output the variable as a pointer. */ | |
872 | { | |
873 | PUT_SDB_DEF (name); | |
f8cfc6aa | 874 | if (REG_P (XEXP (value, 0))) |
37ba3390 RS |
875 | { |
876 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0)))); | |
877 | PUT_SDB_SCL (C_REG); | |
878 | } | |
879 | else | |
880 | { | |
881 | /* DECL_RTL looks like (MEM (MEM (PLUS (REG...) | |
882 | (CONST_INT...)))). | |
883 | We want the value of that CONST_INT. */ | |
884 | /* Encore compiler hates a newline in a macro arg, it seems. */ | |
885 | PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET | |
886 | (XEXP (XEXP (value, 0), 0))); | |
887 | PUT_SDB_SCL (C_AUTO); | |
888 | } | |
889 | ||
a51a5234 JL |
890 | /* Effectively do build_pointer_type, but don't cache this type, |
891 | since it might be temporary whereas the type it points to | |
892 | might have been saved for inlining. */ | |
893 | /* Don't use REFERENCE_TYPE because dbx can't handle that. */ | |
894 | type = make_node (POINTER_TYPE); | |
895 | TREE_TYPE (type) = TREE_TYPE (decl); | |
37ba3390 | 896 | } |
3c0cb5de | 897 | else if (MEM_P (value) |
6d55e0ab | 898 | && ((GET_CODE (XEXP (value, 0)) == PLUS |
f8cfc6aa | 899 | && REG_P (XEXP (XEXP (value, 0), 0)) |
6d55e0ab JW |
900 | && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT) |
901 | /* This is for variables which are at offset zero from | |
902 | the frame pointer. This happens on the Alpha. | |
903 | Non-frame pointer registers are excluded above. */ | |
f8cfc6aa | 904 | || (REG_P (XEXP (value, 0))))) |
37ba3390 | 905 | { |
6d55e0ab JW |
906 | /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))) |
907 | or (MEM (REG...)). We want the value of that CONST_INT | |
908 | or zero. */ | |
37ba3390 RS |
909 | PUT_SDB_DEF (name); |
910 | PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0))); | |
911 | PUT_SDB_SCL (C_AUTO); | |
912 | } | |
913 | else | |
914 | { | |
915 | /* It is something we don't know how to represent for SDB. */ | |
916 | return; | |
917 | } | |
918 | break; | |
1d300e19 KG |
919 | |
920 | default: | |
921 | break; | |
37ba3390 RS |
922 | } |
923 | PUT_SDB_TYPE (plain_type (type)); | |
924 | PUT_SDB_ENDEF; | |
925 | } | |
cef2bd3e | 926 | |
37ba3390 RS |
927 | /* Output SDB information for a top-level initialized variable |
928 | that has been delayed. */ | |
929 | ||
e1772ac0 | 930 | static void |
cef2bd3e | 931 | sdbout_toplevel_data (tree decl) |
37ba3390 RS |
932 | { |
933 | tree type = TREE_TYPE (decl); | |
934 | ||
5e32e83b RS |
935 | if (DECL_IGNORED_P (decl)) |
936 | return; | |
937 | ||
41374e13 NS |
938 | gcc_assert (TREE_CODE (decl) == VAR_DECL); |
939 | gcc_assert (MEM_P (DECL_RTL (decl))); | |
940 | gcc_assert (DECL_INITIAL (decl)); | |
37ba3390 RS |
941 | |
942 | PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
943 | PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0)); | |
944 | if (TREE_PUBLIC (decl)) | |
945 | { | |
946 | PUT_SDB_SCL (C_EXT); | |
947 | } | |
948 | else | |
949 | { | |
950 | PUT_SDB_SCL (C_STAT); | |
951 | } | |
952 | PUT_SDB_TYPE (plain_type (type)); | |
953 | PUT_SDB_ENDEF; | |
954 | } | |
cef2bd3e | 955 | |
37ba3390 RS |
956 | #ifdef SDB_ALLOW_FORWARD_REFERENCES |
957 | ||
0f41302f | 958 | /* Machinery to record and output anonymous types. */ |
37ba3390 | 959 | |
37ba3390 | 960 | static void |
cef2bd3e | 961 | sdbout_queue_anonymous_type (tree type) |
37ba3390 | 962 | { |
1f8f4a0b | 963 | anonymous_types = tree_cons (NULL_TREE, type, anonymous_types); |
37ba3390 RS |
964 | } |
965 | ||
966 | static void | |
cef2bd3e | 967 | sdbout_dequeue_anonymous_types (void) |
37ba3390 | 968 | { |
b3694847 | 969 | tree types, link; |
37ba3390 RS |
970 | |
971 | while (anonymous_types) | |
972 | { | |
973 | types = nreverse (anonymous_types); | |
974 | anonymous_types = NULL_TREE; | |
975 | ||
976 | for (link = types; link; link = TREE_CHAIN (link)) | |
977 | { | |
b3694847 | 978 | tree type = TREE_VALUE (link); |
37ba3390 | 979 | |
c325abbd | 980 | if (type && ! TREE_ASM_WRITTEN (type)) |
37ba3390 RS |
981 | sdbout_one_type (type); |
982 | } | |
983 | } | |
984 | } | |
985 | ||
986 | #endif | |
cef2bd3e | 987 | |
37ba3390 RS |
988 | /* Given a chain of ..._TYPE nodes, all of which have names, |
989 | output definitions of those names, as typedefs. */ | |
990 | ||
991 | void | |
cef2bd3e | 992 | sdbout_types (tree types) |
37ba3390 | 993 | { |
b3694847 | 994 | tree link; |
37ba3390 RS |
995 | |
996 | for (link = types; link; link = TREE_CHAIN (link)) | |
997 | sdbout_one_type (link); | |
998 | ||
999 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
1000 | sdbout_dequeue_anonymous_types (); | |
1001 | #endif | |
1002 | } | |
1003 | ||
1004 | static void | |
cef2bd3e | 1005 | sdbout_type (tree type) |
37ba3390 | 1006 | { |
37ba3390 RS |
1007 | if (type == error_mark_node) |
1008 | type = integer_type_node; | |
1009 | PUT_SDB_TYPE (plain_type (type)); | |
1010 | } | |
1011 | ||
1012 | /* Output types of the fields of type TYPE, if they are structs. | |
1013 | ||
1014 | Formerly did not chase through pointer types, since that could be circular. | |
1015 | They must come before TYPE, since forward refs are not allowed. | |
1016 | Now james@bigtex.cactus.org says to try them. */ | |
1017 | ||
1018 | static void | |
cef2bd3e | 1019 | sdbout_field_types (tree type) |
37ba3390 RS |
1020 | { |
1021 | tree tail; | |
e5e809f4 | 1022 | |
37ba3390 | 1023 | for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail)) |
1270a9b3 LB |
1024 | /* This condition should match the one for emitting the actual |
1025 | members below. */ | |
0dbb7a10 | 1026 | if (TREE_CODE (tail) == FIELD_DECL |
1270a9b3 LB |
1027 | && DECL_NAME (tail) |
1028 | && DECL_SIZE (tail) | |
1029 | && host_integerp (DECL_SIZE (tail), 1) | |
1030 | && host_integerp (bit_position (tail), 0)) | |
0dbb7a10 JM |
1031 | { |
1032 | if (POINTER_TYPE_P (TREE_TYPE (tail))) | |
1033 | sdbout_one_type (TREE_TYPE (TREE_TYPE (tail))); | |
1034 | else | |
1035 | sdbout_one_type (TREE_TYPE (tail)); | |
1036 | } | |
37ba3390 RS |
1037 | } |
1038 | ||
1039 | /* Use this to put out the top level defined record and union types | |
1040 | for later reference. If this is a struct with a name, then put that | |
1041 | name out. Other unnamed structs will have .xxfake labels generated so | |
1042 | that they may be referred to later. | |
1043 | The label will be stored in the KNOWN_TYPE_TAG slot of a type. | |
1044 | It may NOT be called recursively. */ | |
1045 | ||
1046 | static void | |
cef2bd3e | 1047 | sdbout_one_type (tree type) |
37ba3390 | 1048 | { |
509b12e0 JW |
1049 | if (current_function_decl != NULL_TREE |
1050 | && DECL_SECTION_NAME (current_function_decl) != NULL_TREE) | |
1051 | ; /* Don't change section amid function. */ | |
1052 | else | |
d6b5193b | 1053 | switch_to_section (text_section); |
37ba3390 RS |
1054 | |
1055 | switch (TREE_CODE (type)) | |
1056 | { | |
1057 | case RECORD_TYPE: | |
1058 | case UNION_TYPE: | |
c1b98a95 | 1059 | case QUAL_UNION_TYPE: |
37ba3390 RS |
1060 | case ENUMERAL_TYPE: |
1061 | type = TYPE_MAIN_VARIANT (type); | |
1062 | /* Don't output a type twice. */ | |
1063 | if (TREE_ASM_WRITTEN (type)) | |
1064 | /* James said test TREE_ASM_BEING_WRITTEN here. */ | |
1065 | return; | |
1066 | ||
1067 | /* Output nothing if type is not yet defined. */ | |
d0f062fb | 1068 | if (!COMPLETE_TYPE_P (type)) |
37ba3390 RS |
1069 | return; |
1070 | ||
1071 | TREE_ASM_WRITTEN (type) = 1; | |
cef2bd3e | 1072 | |
37ba3390 | 1073 | /* This is reputed to cause trouble with the following case, |
638e2294 | 1074 | but perhaps checking TYPE_SIZE above will fix it. */ |
37ba3390 | 1075 | |
7ef0daad | 1076 | /* Here is a testcase: |
37ba3390 RS |
1077 | |
1078 | struct foo { | |
1079 | struct badstr *bbb; | |
1080 | } forwardref; | |
1081 | ||
1082 | typedef struct intermediate { | |
1083 | int aaaa; | |
1084 | } intermediate_ref; | |
1085 | ||
1086 | typedef struct badstr { | |
1087 | int ccccc; | |
1088 | } badtype; */ | |
1089 | ||
37ba3390 RS |
1090 | /* This change, which ought to make better output, |
1091 | used to make the COFF assembler unhappy. | |
1092 | Changes involving KNOWN_TYPE_TAG may fix the problem. */ | |
1093 | /* Before really doing anything, output types we want to refer to. */ | |
1094 | /* Note that in version 1 the following two lines | |
1095 | are not used if forward references are in use. */ | |
1096 | if (TREE_CODE (type) != ENUMERAL_TYPE) | |
1097 | sdbout_field_types (type); | |
37ba3390 RS |
1098 | |
1099 | /* Output a structure type. */ | |
1100 | { | |
1101 | int size = int_size_in_bytes (type); | |
a544cfd2 | 1102 | int member_scl = 0; |
37ba3390 RS |
1103 | tree tem; |
1104 | ||
1105 | /* Record the type tag, but not in its permanent place just yet. */ | |
1106 | sdbout_record_type_name (type); | |
1107 | ||
1108 | PUT_SDB_DEF (KNOWN_TYPE_TAG (type)); | |
1109 | ||
1110 | switch (TREE_CODE (type)) | |
1111 | { | |
1112 | case UNION_TYPE: | |
c1b98a95 | 1113 | case QUAL_UNION_TYPE: |
37ba3390 RS |
1114 | PUT_SDB_SCL (C_UNTAG); |
1115 | PUT_SDB_TYPE (T_UNION); | |
1116 | member_scl = C_MOU; | |
1117 | break; | |
1118 | ||
1119 | case RECORD_TYPE: | |
1120 | PUT_SDB_SCL (C_STRTAG); | |
1121 | PUT_SDB_TYPE (T_STRUCT); | |
1122 | member_scl = C_MOS; | |
1123 | break; | |
1124 | ||
1125 | case ENUMERAL_TYPE: | |
1126 | PUT_SDB_SCL (C_ENTAG); | |
1127 | PUT_SDB_TYPE (T_ENUM); | |
1128 | member_scl = C_MOE; | |
1129 | break; | |
1d300e19 KG |
1130 | |
1131 | default: | |
1132 | break; | |
37ba3390 RS |
1133 | } |
1134 | ||
1135 | PUT_SDB_SIZE (size); | |
1136 | PUT_SDB_ENDEF; | |
1137 | ||
5b7f1820 RS |
1138 | /* Print out the base class information with fields |
1139 | named after the types they hold. */ | |
684d9f3b | 1140 | /* This is only relevant to aggregate types. TYPE_BINFO is used |
46fb0d7d JW |
1141 | for other purposes in an ENUMERAL_TYPE, so we must exclude that |
1142 | case. */ | |
fa743e8c | 1143 | if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type)) |
5b7f1820 | 1144 | { |
fa743e8c NS |
1145 | int i; |
1146 | tree binfo, child; | |
1147 | ||
1148 | for (binfo = TYPE_BINFO (type), i = 0; | |
1149 | BINFO_BASE_ITERATE (binfo, i, child); i++) | |
ee3e2d3d | 1150 | { |
46fb0d7d JW |
1151 | tree child_type = BINFO_TYPE (child); |
1152 | tree child_type_name; | |
fa743e8c | 1153 | |
46fb0d7d JW |
1154 | if (TYPE_NAME (child_type) == 0) |
1155 | continue; | |
1156 | if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE) | |
1157 | child_type_name = TYPE_NAME (child_type); | |
1158 | else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL) | |
1159 | { | |
1160 | child_type_name = DECL_NAME (TYPE_NAME (child_type)); | |
1161 | if (child_type_name && template_name_p (child_type_name)) | |
1162 | child_type_name | |
1163 | = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type)); | |
1164 | } | |
1165 | else | |
1166 | continue; | |
1167 | ||
46fb0d7d | 1168 | PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name)); |
665f2503 | 1169 | PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child), 0)); |
46fb0d7d JW |
1170 | PUT_SDB_SCL (member_scl); |
1171 | sdbout_type (BINFO_TYPE (child)); | |
1172 | PUT_SDB_ENDEF; | |
ee3e2d3d | 1173 | } |
5b7f1820 RS |
1174 | } |
1175 | ||
e0a21ab9 | 1176 | /* Output the individual fields. */ |
37ba3390 RS |
1177 | |
1178 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
bf5e8d0c | 1179 | { |
2d49ce67 | 1180 | for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem)) |
bf5e8d0c AJ |
1181 | if (host_integerp (TREE_VALUE (tem), 0)) |
1182 | { | |
1183 | PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem))); | |
1184 | PUT_SDB_INT_VAL (tree_low_cst (TREE_VALUE (tem), 0)); | |
1185 | PUT_SDB_SCL (C_MOE); | |
1186 | PUT_SDB_TYPE (T_MOE); | |
1187 | PUT_SDB_ENDEF; | |
1188 | } | |
1189 | } | |
37ba3390 RS |
1190 | else /* record or union type */ |
1191 | for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem)) | |
1192 | /* Output the name, type, position (in bits), size (in bits) | |
1193 | of each field. */ | |
1194 | ||
1195 | /* Omit here the nameless fields that are used to skip bits. | |
1196 | Also omit fields with variable size or position. | |
1197 | Also omit non FIELD_DECL nodes that GNU C++ may put here. */ | |
1198 | if (TREE_CODE (tem) == FIELD_DECL | |
1270a9b3 LB |
1199 | && DECL_NAME (tem) |
1200 | && DECL_SIZE (tem) | |
665f2503 RK |
1201 | && host_integerp (DECL_SIZE (tem), 1) |
1202 | && host_integerp (bit_position (tem), 0)) | |
37ba3390 | 1203 | { |
ebb13e7e | 1204 | const char *name; |
0eb111c2 | 1205 | |
4eadbbd5 | 1206 | name = IDENTIFIER_POINTER (DECL_NAME (tem)); |
0eb111c2 | 1207 | PUT_SDB_DEF (name); |
37ba3390 RS |
1208 | if (DECL_BIT_FIELD_TYPE (tem)) |
1209 | { | |
665f2503 | 1210 | PUT_SDB_INT_VAL (int_bit_position (tem)); |
37ba3390 RS |
1211 | PUT_SDB_SCL (C_FIELD); |
1212 | sdbout_type (DECL_BIT_FIELD_TYPE (tem)); | |
665f2503 | 1213 | PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem), 1)); |
37ba3390 RS |
1214 | } |
1215 | else | |
1216 | { | |
665f2503 | 1217 | PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT); |
37ba3390 RS |
1218 | PUT_SDB_SCL (member_scl); |
1219 | sdbout_type (TREE_TYPE (tem)); | |
1220 | } | |
1221 | PUT_SDB_ENDEF; | |
1222 | } | |
e0a21ab9 | 1223 | /* Output end of a structure,union, or enumeral definition. */ |
37ba3390 RS |
1224 | |
1225 | PUT_SDB_PLAIN_DEF ("eos"); | |
1226 | PUT_SDB_INT_VAL (size); | |
1227 | PUT_SDB_SCL (C_EOS); | |
1228 | PUT_SDB_TAG (KNOWN_TYPE_TAG (type)); | |
1229 | PUT_SDB_SIZE (size); | |
1230 | PUT_SDB_ENDEF; | |
1231 | break; | |
1d300e19 KG |
1232 | |
1233 | default: | |
1234 | break; | |
37ba3390 RS |
1235 | } |
1236 | } | |
1237 | } | |
cef2bd3e | 1238 | |
37ba3390 RS |
1239 | /* The following two functions output definitions of function parameters. |
1240 | Each parameter gets a definition locating it in the parameter list. | |
1241 | Each parameter that is a register variable gets a second definition | |
1242 | locating it in the register. | |
1243 | ||
1244 | Printing or argument lists in gdb uses the definitions that | |
1245 | locate in the parameter list. But reference to the variable in | |
1246 | expressions uses preferentially the definition as a register. */ | |
1247 | ||
1248 | /* Output definitions, referring to storage in the parmlist, | |
1249 | of all the parms in PARMS, which is a chain of PARM_DECL nodes. */ | |
1250 | ||
1251 | static void | |
cef2bd3e | 1252 | sdbout_parms (tree parms) |
37ba3390 RS |
1253 | { |
1254 | for (; parms; parms = TREE_CHAIN (parms)) | |
1255 | if (DECL_NAME (parms)) | |
1256 | { | |
1257 | int current_sym_value = 0; | |
ebb13e7e | 1258 | const char *name = IDENTIFIER_POINTER (DECL_NAME (parms)); |
37ba3390 RS |
1259 | |
1260 | if (name == 0 || *name == 0) | |
1261 | name = gen_fake_label (); | |
1262 | ||
1263 | /* Perform any necessary register eliminations on the parameter's rtl, | |
1264 | so that the debugging output will be accurate. */ | |
db3cf6fb | 1265 | DECL_INCOMING_RTL (parms) |
1914f5da | 1266 | = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX); |
d975d8c3 MM |
1267 | SET_DECL_RTL (parms, |
1268 | eliminate_regs (DECL_RTL (parms), 0, NULL_RTX)); | |
37ba3390 RS |
1269 | |
1270 | if (PARM_PASSED_IN_MEMORY (parms)) | |
1271 | { | |
1272 | rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0); | |
1273 | tree type; | |
1274 | ||
1275 | /* ??? Here we assume that the parm address is indexed | |
1276 | off the frame pointer or arg pointer. | |
1277 | If that is not true, we produce meaningless results, | |
1278 | but do not crash. */ | |
1279 | if (GET_CODE (addr) == PLUS | |
1280 | && GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
1281 | current_sym_value = INTVAL (XEXP (addr, 1)); | |
1282 | else | |
1283 | current_sym_value = 0; | |
1284 | ||
f8cfc6aa | 1285 | if (REG_P (DECL_RTL (parms)) |
37ba3390 RS |
1286 | && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) |
1287 | type = DECL_ARG_TYPE (parms); | |
1288 | else | |
1289 | { | |
1290 | int original_sym_value = current_sym_value; | |
1291 | ||
1292 | /* This is the case where the parm is passed as an int or | |
1293 | double and it is converted to a char, short or float | |
1294 | and stored back in the parmlist. In this case, describe | |
1295 | the parm with the variable's declared type, and adjust | |
1296 | the address if the least significant bytes (which we are | |
1297 | using) are not the first ones. */ | |
f76b9db2 ILT |
1298 | if (BYTES_BIG_ENDIAN |
1299 | && TREE_TYPE (parms) != DECL_ARG_TYPE (parms)) | |
37ba3390 RS |
1300 | current_sym_value += |
1301 | (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms))) | |
1302 | - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))); | |
f76b9db2 | 1303 | |
3c0cb5de | 1304 | if (MEM_P (DECL_RTL (parms)) |
37ba3390 RS |
1305 | && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS |
1306 | && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) | |
1307 | == CONST_INT) | |
1308 | && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) | |
1309 | == current_sym_value)) | |
1310 | type = TREE_TYPE (parms); | |
1311 | else | |
1312 | { | |
1313 | current_sym_value = original_sym_value; | |
1314 | type = DECL_ARG_TYPE (parms); | |
1315 | } | |
1316 | } | |
1317 | ||
1318 | PUT_SDB_DEF (name); | |
1319 | PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr)); | |
1320 | PUT_SDB_SCL (C_ARG); | |
1321 | PUT_SDB_TYPE (plain_type (type)); | |
1322 | PUT_SDB_ENDEF; | |
1323 | } | |
f8cfc6aa | 1324 | else if (REG_P (DECL_RTL (parms))) |
37ba3390 RS |
1325 | { |
1326 | rtx best_rtl; | |
1327 | /* Parm passed in registers and lives in registers or nowhere. */ | |
1328 | ||
1329 | /* If parm lives in a register, use that register; | |
1330 | pretend the parm was passed there. It would be more consistent | |
1331 | to describe the register where the parm was passed, | |
1332 | but in practice that register usually holds something else. */ | |
770ae6cc | 1333 | if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) |
37ba3390 RS |
1334 | best_rtl = DECL_RTL (parms); |
1335 | /* If the parm lives nowhere, | |
1336 | use the register where it was passed. */ | |
1337 | else | |
1338 | best_rtl = DECL_INCOMING_RTL (parms); | |
1339 | ||
1340 | PUT_SDB_DEF (name); | |
1341 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl))); | |
1342 | PUT_SDB_SCL (C_REGPARM); | |
21abd7a6 | 1343 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms))); |
37ba3390 RS |
1344 | PUT_SDB_ENDEF; |
1345 | } | |
3c0cb5de | 1346 | else if (MEM_P (DECL_RTL (parms)) |
37ba3390 RS |
1347 | && XEXP (DECL_RTL (parms), 0) != const0_rtx) |
1348 | { | |
1349 | /* Parm was passed in registers but lives on the stack. */ | |
1350 | ||
1351 | /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))), | |
1352 | in which case we want the value of that CONST_INT, | |
1353 | or (MEM (REG ...)) or (MEM (MEM ...)), | |
1354 | in which case we use a value of zero. */ | |
f8cfc6aa | 1355 | if (REG_P (XEXP (DECL_RTL (parms), 0)) |
3c0cb5de | 1356 | || MEM_P (XEXP (DECL_RTL (parms), 0))) |
37ba3390 RS |
1357 | current_sym_value = 0; |
1358 | else | |
1359 | current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)); | |
1360 | ||
1361 | /* Again, this assumes the offset is based on the arg pointer. */ | |
1362 | PUT_SDB_DEF (name); | |
1363 | PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, | |
1364 | XEXP (DECL_RTL (parms), 0))); | |
1365 | PUT_SDB_SCL (C_ARG); | |
21abd7a6 | 1366 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms))); |
37ba3390 RS |
1367 | PUT_SDB_ENDEF; |
1368 | } | |
1369 | } | |
1370 | } | |
1371 | ||
1372 | /* Output definitions for the places where parms live during the function, | |
1373 | when different from where they were passed, when the parms were passed | |
1374 | in memory. | |
1375 | ||
1376 | It is not useful to do this for parms passed in registers | |
1377 | that live during the function in different registers, because it is | |
1378 | impossible to look in the passed register for the passed value, | |
1379 | so we use the within-the-function register to begin with. | |
1380 | ||
1381 | PARMS is a chain of PARM_DECL nodes. */ | |
1382 | ||
1383 | static void | |
cef2bd3e | 1384 | sdbout_reg_parms (tree parms) |
37ba3390 RS |
1385 | { |
1386 | for (; parms; parms = TREE_CHAIN (parms)) | |
1387 | if (DECL_NAME (parms)) | |
1388 | { | |
ebb13e7e | 1389 | const char *name = IDENTIFIER_POINTER (DECL_NAME (parms)); |
37ba3390 RS |
1390 | |
1391 | /* Report parms that live in registers during the function | |
1392 | but were passed in memory. */ | |
f8cfc6aa | 1393 | if (REG_P (DECL_RTL (parms)) |
37ba3390 RS |
1394 | && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER |
1395 | && PARM_PASSED_IN_MEMORY (parms)) | |
1396 | { | |
1397 | if (name == 0 || *name == 0) | |
1398 | name = gen_fake_label (); | |
1399 | PUT_SDB_DEF (name); | |
1400 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)))); | |
1401 | PUT_SDB_SCL (C_REG); | |
21abd7a6 | 1402 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms))); |
37ba3390 RS |
1403 | PUT_SDB_ENDEF; |
1404 | } | |
1405 | /* Report parms that live in memory but not where they were passed. */ | |
3c0cb5de | 1406 | else if (MEM_P (DECL_RTL (parms)) |
37ba3390 RS |
1407 | && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS |
1408 | && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT | |
1409 | && PARM_PASSED_IN_MEMORY (parms) | |
1410 | && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms))) | |
1411 | { | |
1412 | #if 0 /* ??? It is not clear yet what should replace this. */ | |
1413 | int offset = DECL_OFFSET (parms) / BITS_PER_UNIT; | |
1414 | /* A parm declared char is really passed as an int, | |
1415 | so it occupies the least significant bytes. | |
1416 | On a big-endian machine those are not the low-numbered ones. */ | |
f76b9db2 ILT |
1417 | if (BYTES_BIG_ENDIAN |
1418 | && offset != -1 | |
1419 | && TREE_TYPE (parms) != DECL_ARG_TYPE (parms)) | |
37ba3390 RS |
1420 | offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms))) |
1421 | - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))); | |
37ba3390 RS |
1422 | if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...} |
1423 | #endif | |
1424 | { | |
1425 | if (name == 0 || *name == 0) | |
1426 | name = gen_fake_label (); | |
1427 | PUT_SDB_DEF (name); | |
1428 | PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET | |
1429 | (XEXP (DECL_RTL (parms), 0))); | |
1430 | PUT_SDB_SCL (C_AUTO); | |
1431 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms))); | |
1432 | PUT_SDB_ENDEF; | |
1433 | } | |
1434 | } | |
1435 | } | |
1436 | } | |
cef2bd3e | 1437 | |
2b85879e NB |
1438 | /* Output debug information for a global DECL. Called from toplev.c |
1439 | after compilation proper has finished. */ | |
1440 | ||
1441 | static void | |
cef2bd3e | 1442 | sdbout_global_decl (tree decl) |
2b85879e NB |
1443 | { |
1444 | if (TREE_CODE (decl) == VAR_DECL | |
3914abb4 NB |
1445 | && !DECL_EXTERNAL (decl) |
1446 | && DECL_RTL_SET_P (decl)) | |
2b85879e NB |
1447 | { |
1448 | /* The COFF linker can move initialized global vars to the end. | |
3914abb4 NB |
1449 | And that can screw up the symbol ordering. Defer those for |
1450 | sdbout_finish (). */ | |
1451 | if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl)) | |
2b85879e | 1452 | sdbout_symbol (decl, 0); |
21d13d83 ZW |
1453 | else |
1454 | VARRAY_PUSH_TREE (deferred_global_decls, decl); | |
2b85879e NB |
1455 | |
1456 | /* Output COFF information for non-global file-scope initialized | |
1457 | variables. */ | |
3c0cb5de | 1458 | if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl))) |
2b85879e NB |
1459 | sdbout_toplevel_data (decl); |
1460 | } | |
1461 | } | |
3914abb4 NB |
1462 | |
1463 | /* Output initialized global vars at the end, in the order of | |
1464 | definition. See comment in sdbout_global_decl. */ | |
1465 | ||
1466 | static void | |
cef2bd3e | 1467 | sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED) |
3914abb4 | 1468 | { |
16edbbf0 | 1469 | size_t i; |
3914abb4 | 1470 | |
21d13d83 ZW |
1471 | for (i = 0; i < VARRAY_ACTIVE_SIZE (deferred_global_decls); i++) |
1472 | sdbout_symbol (VARRAY_TREE (deferred_global_decls, i), 0); | |
3914abb4 | 1473 | } |
cef2bd3e | 1474 | |
37ba3390 RS |
1475 | /* Describe the beginning of an internal block within a function. |
1476 | Also output descriptions of variables defined in this block. | |
1477 | ||
1478 | N is the number of the block, by order of beginning, counting from 1, | |
1479 | and not counting the outermost (function top-level) block. | |
1480 | The blocks match the BLOCKs in DECL_INITIAL (current_function_decl), | |
1481 | if the count starts at 0 for the outermost one. */ | |
1482 | ||
a5a42b92 | 1483 | static void |
cef2bd3e | 1484 | sdbout_begin_block (unsigned int line, unsigned int n) |
37ba3390 RS |
1485 | { |
1486 | tree decl = current_function_decl; | |
1487 | MAKE_LINE_SAFE (line); | |
9f27ca8b JW |
1488 | |
1489 | /* The SCO compiler does not emit a separate block for the function level | |
1490 | scope, so we avoid it here also. However, mips ECOFF compilers do emit | |
1491 | a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */ | |
1492 | #ifndef MIPS_DEBUGGING_INFO | |
1493 | if (n != 1) | |
1494 | #endif | |
1495 | PUT_SDB_BLOCK_START (line - sdb_begin_function_line); | |
1496 | ||
37ba3390 RS |
1497 | if (n == 1) |
1498 | { | |
1499 | /* Include the outermost BLOCK's variables in block 1. */ | |
18c038b9 | 1500 | do_block = BLOCK_NUMBER (DECL_INITIAL (decl)); |
37ba3390 RS |
1501 | sdbout_block (DECL_INITIAL (decl)); |
1502 | } | |
1503 | /* If -g1, suppress all the internal symbols of functions | |
1504 | except for arguments. */ | |
1505 | if (debug_info_level != DINFO_LEVEL_TERSE) | |
1506 | { | |
37ba3390 RS |
1507 | do_block = n; |
1508 | sdbout_block (DECL_INITIAL (decl)); | |
1509 | } | |
1510 | ||
1511 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
1512 | sdbout_dequeue_anonymous_types (); | |
1513 | #endif | |
1514 | } | |
1515 | ||
1516 | /* Describe the end line-number of an internal block within a function. */ | |
1517 | ||
e2a12aca | 1518 | static void |
cef2bd3e | 1519 | sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED) |
37ba3390 RS |
1520 | { |
1521 | MAKE_LINE_SAFE (line); | |
9f27ca8b JW |
1522 | |
1523 | /* The SCO compiler does not emit a separate block for the function level | |
1524 | scope, so we avoid it here also. However, mips ECOFF compilers do emit | |
1525 | a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */ | |
1526 | #ifndef MIPS_DEBUGGING_INFO | |
1527 | if (n != 1) | |
1528 | #endif | |
37ba3390 RS |
1529 | PUT_SDB_BLOCK_END (line - sdb_begin_function_line); |
1530 | } | |
1531 | ||
a8d0467e EB |
1532 | /* Output a line number symbol entry for source file FILENAME and line |
1533 | number LINE. */ | |
1534 | ||
e2a12aca | 1535 | static void |
bf9d3c27 | 1536 | sdbout_source_line (unsigned int line, const char *filename ATTRIBUTE_UNUSED) |
e2a12aca | 1537 | { |
e2a12aca | 1538 | /* COFF relative line numbers must be positive. */ |
5197bd50 | 1539 | if ((int) line > sdb_begin_function_line) |
e2a12aca | 1540 | { |
3e487b21 ZW |
1541 | #ifdef SDB_OUTPUT_SOURCE_LINE |
1542 | SDB_OUTPUT_SOURCE_LINE (asm_out_file, line); | |
e2a12aca NB |
1543 | #else |
1544 | fprintf (asm_out_file, "\t.ln\t%d\n", | |
1545 | ((sdb_begin_function_line > -1) | |
1546 | ? line - sdb_begin_function_line : 1)); | |
1547 | #endif | |
1548 | } | |
1549 | } | |
1550 | ||
37ba3390 RS |
1551 | /* Output sdb info for the current function name. |
1552 | Called from assemble_start_function. */ | |
1553 | ||
653e276c | 1554 | static void |
cef2bd3e | 1555 | sdbout_begin_function (tree decl ATTRIBUTE_UNUSED) |
37ba3390 RS |
1556 | { |
1557 | sdbout_symbol (current_function_decl, 0); | |
1558 | } | |
1559 | ||
653e276c NB |
1560 | /* Called at beginning of function body (before or after prologue, |
1561 | depending on MIPS_DEBUGGING_INFO). Record the function's starting | |
1562 | line number, so we can output relative line numbers for the other | |
1563 | lines. Describe beginning of outermost block. Also describe the | |
1564 | parameter list. */ | |
37ba3390 | 1565 | |
653e276c NB |
1566 | #ifndef MIPS_DEBUGGING_INFO |
1567 | static void | |
cef2bd3e | 1568 | sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED) |
653e276c | 1569 | { |
702ada3d | 1570 | sdbout_end_prologue (line, file); |
653e276c NB |
1571 | } |
1572 | #endif | |
1573 | ||
1574 | static void | |
bf9d3c27 | 1575 | sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED) |
37ba3390 RS |
1576 | { |
1577 | sdb_begin_function_line = line - 1; | |
1578 | PUT_SDB_FUNCTION_START (line); | |
1579 | sdbout_parms (DECL_ARGUMENTS (current_function_decl)); | |
1580 | sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl)); | |
1581 | } | |
1582 | ||
1583 | /* Called at end of function (before epilogue). | |
1584 | Describe end of outermost block. */ | |
1585 | ||
e2a12aca | 1586 | static void |
cef2bd3e | 1587 | sdbout_end_function (unsigned int line) |
37ba3390 RS |
1588 | { |
1589 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
1590 | sdbout_dequeue_anonymous_types (); | |
1591 | #endif | |
1592 | ||
1593 | MAKE_LINE_SAFE (line); | |
1594 | PUT_SDB_FUNCTION_END (line - sdb_begin_function_line); | |
1595 | ||
1596 | /* Indicate we are between functions, for line-number output. */ | |
1597 | sdb_begin_function_line = -1; | |
1598 | } | |
1599 | ||
1600 | /* Output sdb info for the absolute end of a function. | |
1601 | Called after the epilogue is output. */ | |
1602 | ||
e2a12aca | 1603 | static void |
cef2bd3e AJ |
1604 | sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED, |
1605 | const char *file ATTRIBUTE_UNUSED) | |
37ba3390 | 1606 | { |
e59f7d3d | 1607 | const char *const name ATTRIBUTE_UNUSED |
e2a12aca NB |
1608 | = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)); |
1609 | ||
1610 | #ifdef PUT_SDB_EPILOGUE_END | |
1611 | PUT_SDB_EPILOGUE_END (name); | |
1612 | #else | |
1613 | fprintf (asm_out_file, "\t.def\t"); | |
1614 | assemble_name (asm_out_file, name); | |
1615 | fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n", | |
1616 | SDB_DELIM, SDB_DELIM, SDB_DELIM); | |
1617 | #endif | |
37ba3390 RS |
1618 | } |
1619 | ||
1620 | /* Output sdb info for the given label. Called only if LABEL_NAME (insn) | |
1621 | is present. */ | |
1622 | ||
e1772ac0 | 1623 | static void |
cef2bd3e | 1624 | sdbout_label (rtx insn) |
37ba3390 RS |
1625 | { |
1626 | PUT_SDB_DEF (LABEL_NAME (insn)); | |
1627 | PUT_SDB_VAL (insn); | |
1628 | PUT_SDB_SCL (C_LABEL); | |
1629 | PUT_SDB_TYPE (T_NULL); | |
1630 | PUT_SDB_ENDEF; | |
1631 | } | |
1632 | ||
cc694a81 DE |
1633 | /* Change to reading from a new source file. */ |
1634 | ||
7f905405 | 1635 | static void |
cef2bd3e AJ |
1636 | sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED, |
1637 | const char *filename ATTRIBUTE_UNUSED) | |
cc694a81 DE |
1638 | { |
1639 | #ifdef MIPS_DEBUGGING_INFO | |
703ad42b | 1640 | struct sdb_file *n = xmalloc (sizeof *n); |
cc694a81 DE |
1641 | |
1642 | n->next = current_file; | |
1643 | n->name = filename; | |
1644 | current_file = n; | |
3e487b21 | 1645 | output_file_directive (asm_out_file, filename); |
cc694a81 DE |
1646 | #endif |
1647 | } | |
1648 | ||
1649 | /* Revert to reading a previous source file. */ | |
1650 | ||
7f905405 | 1651 | static void |
cef2bd3e | 1652 | sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED) |
cc694a81 DE |
1653 | { |
1654 | #ifdef MIPS_DEBUGGING_INFO | |
1655 | struct sdb_file *next; | |
1656 | ||
1657 | next = current_file->next; | |
1658 | free (current_file); | |
1659 | current_file = next; | |
3e487b21 | 1660 | output_file_directive (asm_out_file, current_file->name); |
cc694a81 DE |
1661 | #endif |
1662 | } | |
1663 | ||
4eadbbd5 RK |
1664 | /* Set up for SDB output at the start of compilation. */ |
1665 | ||
a51d908e | 1666 | static void |
cef2bd3e | 1667 | sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED) |
4eadbbd5 | 1668 | { |
16edbbf0 ZW |
1669 | tree t; |
1670 | ||
4eadbbd5 | 1671 | #ifdef MIPS_DEBUGGING_INFO |
703ad42b | 1672 | current_file = xmalloc (sizeof *current_file); |
4eadbbd5 RK |
1673 | current_file->next = NULL; |
1674 | current_file->name = input_file_name; | |
1675 | #endif | |
21d13d83 ZW |
1676 | |
1677 | VARRAY_TREE_INIT (deferred_global_decls, 12, "deferred_global_decls"); | |
16edbbf0 ZW |
1678 | |
1679 | /* Emit debug information which was queued by sdbout_symbol before | |
1680 | we got here. */ | |
1681 | sdbout_initialized = true; | |
1682 | ||
1683 | for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t)) | |
1684 | sdbout_symbol (TREE_VALUE (t), 0); | |
1685 | preinit_symbols = 0; | |
4eadbbd5 RK |
1686 | } |
1687 | ||
e2500fed GK |
1688 | #else /* SDB_DEBUGGING_INFO */ |
1689 | ||
1690 | /* This should never be used, but its address is needed for comparisons. */ | |
1691 | const struct gcc_debug_hooks sdb_debug_hooks; | |
1692 | ||
37ba3390 | 1693 | #endif /* SDB_DEBUGGING_INFO */ |
e2500fed GK |
1694 | |
1695 | #include "gt-sdbout.h" |