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