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