]>
Commit | Line | Data |
---|---|---|
37ba3390 | 1 | /* Output sdb-format symbol table information from GNU compiler. |
d1e082c2 | 2 | Copyright (C) 1988-2013 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 AJ |
121 | static void sdbout_end_epilogue (unsigned int, const char *); |
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); | |
128 | static void sdbout_label (rtx); | |
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); | |
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 */ |
9e9945c5 | 305 | debug_nothing_rtx, /* 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 | ||
786de7eb | 742 | SET_DECL_RTL (decl, |
270d1bcd | 743 | eliminate_regs (DECL_RTL (decl), VOIDmode, NULL_RTX)); |
bf1e8c4d | 744 | #ifdef LEAF_REG_REMAP |
416ff32e | 745 | if (crtl->uses_only_leaf_regs) |
bf1e8c4d RS |
746 | leaf_renumber_regs_insn (DECL_RTL (decl)); |
747 | #endif | |
748 | value = DECL_RTL (decl); | |
37ba3390 RS |
749 | |
750 | /* Don't mention a variable at all | |
751 | if it was completely optimized into nothingness. | |
752 | ||
753 | If DECL was from an inline function, then its rtl | |
754 | is not identically the rtl that was used in this | |
755 | particular compilation. */ | |
f8cfc6aa | 756 | if (REG_P (value)) |
37ba3390 | 757 | { |
69deb6e0 | 758 | regno = REGNO (value); |
37ba3390 | 759 | if (regno >= FIRST_PSEUDO_REGISTER) |
37ba3390 RS |
760 | return; |
761 | } | |
bf1e8c4d | 762 | else if (GET_CODE (value) == SUBREG) |
37ba3390 | 763 | { |
37ba3390 | 764 | while (GET_CODE (value) == SUBREG) |
ddef6bc7 | 765 | value = SUBREG_REG (value); |
f8cfc6aa | 766 | if (REG_P (value)) |
37ba3390 | 767 | { |
ddef6bc7 | 768 | if (REGNO (value) >= FIRST_PSEUDO_REGISTER) |
bf1e8c4d | 769 | return; |
37ba3390 | 770 | } |
55a2c322 | 771 | regno = REGNO (alter_subreg (&value, true)); |
69deb6e0 | 772 | SET_DECL_RTL (decl, value); |
37ba3390 | 773 | } |
39eae9f4 RS |
774 | /* Don't output anything if an auto variable |
775 | gets RTL that is static. | |
776 | GAS version 2.2 can't handle such output. */ | |
3c0cb5de | 777 | else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0)) |
39eae9f4 RS |
778 | && ! TREE_STATIC (decl)) |
779 | return; | |
37ba3390 RS |
780 | |
781 | /* Emit any structure, union, or enum type that has not been output. | |
782 | This occurs for tag-less structs (et al) used to declare variables | |
783 | within functions. */ | |
784 | if (TREE_CODE (type) == ENUMERAL_TYPE | |
785 | || TREE_CODE (type) == RECORD_TYPE | |
c1b98a95 RK |
786 | || TREE_CODE (type) == UNION_TYPE |
787 | || TREE_CODE (type) == QUAL_UNION_TYPE) | |
37ba3390 | 788 | { |
d0f062fb | 789 | if (COMPLETE_TYPE_P (type) /* not a forward reference */ |
37ba3390 RS |
790 | && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */ |
791 | sdbout_one_type (type); | |
792 | } | |
793 | ||
794 | /* Defer SDB information for top-level initialized variables! */ | |
795 | if (! local | |
3c0cb5de | 796 | && MEM_P (value) |
37ba3390 RS |
797 | && DECL_INITIAL (decl)) |
798 | return; | |
799 | ||
ed5f8355 RS |
800 | /* C++ in 2.3 makes nameless symbols. That will be fixed later. |
801 | For now, avoid crashing. */ | |
802 | if (DECL_NAME (decl) == NULL_TREE) | |
803 | return; | |
804 | ||
37ba3390 | 805 | /* Record the name for, starting a symtab entry. */ |
4eadbbd5 RK |
806 | if (local) |
807 | name = IDENTIFIER_POINTER (DECL_NAME (decl)); | |
808 | else | |
809 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
37ba3390 | 810 | |
3c0cb5de | 811 | if (MEM_P (value) |
37ba3390 RS |
812 | && GET_CODE (XEXP (value, 0)) == SYMBOL_REF) |
813 | { | |
814 | PUT_SDB_DEF (name); | |
815 | if (TREE_PUBLIC (decl)) | |
816 | { | |
817 | PUT_SDB_VAL (XEXP (value, 0)); | |
786de7eb | 818 | PUT_SDB_SCL (C_EXT); |
37ba3390 RS |
819 | } |
820 | else | |
821 | { | |
822 | PUT_SDB_VAL (XEXP (value, 0)); | |
786de7eb | 823 | PUT_SDB_SCL (C_STAT); |
37ba3390 RS |
824 | } |
825 | } | |
826 | else if (regno >= 0) | |
827 | { | |
828 | PUT_SDB_DEF (name); | |
829 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno)); | |
830 | PUT_SDB_SCL (C_REG); | |
831 | } | |
3c0cb5de JQ |
832 | else if (MEM_P (value) |
833 | && (MEM_P (XEXP (value, 0)) | |
f8cfc6aa | 834 | || (REG_P (XEXP (value, 0)) |
d8a0edf4 | 835 | && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM |
5b7f1820 | 836 | && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM))) |
37ba3390 RS |
837 | /* If the value is indirect by memory or by a register |
838 | that isn't the frame pointer | |
839 | then it means the object is variable-sized and address through | |
840 | that register or stack slot. COFF has no way to represent this | |
841 | so all we can do is output the variable as a pointer. */ | |
842 | { | |
843 | PUT_SDB_DEF (name); | |
f8cfc6aa | 844 | if (REG_P (XEXP (value, 0))) |
37ba3390 RS |
845 | { |
846 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0)))); | |
847 | PUT_SDB_SCL (C_REG); | |
848 | } | |
849 | else | |
850 | { | |
851 | /* DECL_RTL looks like (MEM (MEM (PLUS (REG...) | |
852 | (CONST_INT...)))). | |
853 | We want the value of that CONST_INT. */ | |
854 | /* Encore compiler hates a newline in a macro arg, it seems. */ | |
855 | PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET | |
856 | (XEXP (XEXP (value, 0), 0))); | |
857 | PUT_SDB_SCL (C_AUTO); | |
858 | } | |
859 | ||
a51a5234 JL |
860 | /* Effectively do build_pointer_type, but don't cache this type, |
861 | since it might be temporary whereas the type it points to | |
862 | might have been saved for inlining. */ | |
863 | /* Don't use REFERENCE_TYPE because dbx can't handle that. */ | |
864 | type = make_node (POINTER_TYPE); | |
865 | TREE_TYPE (type) = TREE_TYPE (decl); | |
37ba3390 | 866 | } |
3c0cb5de | 867 | else if (MEM_P (value) |
6d55e0ab | 868 | && ((GET_CODE (XEXP (value, 0)) == PLUS |
f8cfc6aa | 869 | && REG_P (XEXP (XEXP (value, 0), 0)) |
481683e1 | 870 | && CONST_INT_P (XEXP (XEXP (value, 0), 1))) |
6d55e0ab JW |
871 | /* This is for variables which are at offset zero from |
872 | the frame pointer. This happens on the Alpha. | |
873 | Non-frame pointer registers are excluded above. */ | |
f8cfc6aa | 874 | || (REG_P (XEXP (value, 0))))) |
37ba3390 | 875 | { |
6d55e0ab JW |
876 | /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))) |
877 | or (MEM (REG...)). We want the value of that CONST_INT | |
878 | or zero. */ | |
37ba3390 RS |
879 | PUT_SDB_DEF (name); |
880 | PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0))); | |
881 | PUT_SDB_SCL (C_AUTO); | |
882 | } | |
883 | else | |
884 | { | |
885 | /* It is something we don't know how to represent for SDB. */ | |
886 | return; | |
887 | } | |
888 | break; | |
1d300e19 KG |
889 | |
890 | default: | |
891 | break; | |
37ba3390 RS |
892 | } |
893 | PUT_SDB_TYPE (plain_type (type)); | |
894 | PUT_SDB_ENDEF; | |
895 | } | |
cef2bd3e | 896 | |
37ba3390 RS |
897 | /* Output SDB information for a top-level initialized variable |
898 | that has been delayed. */ | |
899 | ||
e1772ac0 | 900 | static void |
cef2bd3e | 901 | sdbout_toplevel_data (tree decl) |
37ba3390 RS |
902 | { |
903 | tree type = TREE_TYPE (decl); | |
904 | ||
5e32e83b RS |
905 | if (DECL_IGNORED_P (decl)) |
906 | return; | |
907 | ||
41374e13 NS |
908 | gcc_assert (TREE_CODE (decl) == VAR_DECL); |
909 | gcc_assert (MEM_P (DECL_RTL (decl))); | |
910 | gcc_assert (DECL_INITIAL (decl)); | |
37ba3390 RS |
911 | |
912 | PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
913 | PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0)); | |
914 | if (TREE_PUBLIC (decl)) | |
915 | { | |
916 | PUT_SDB_SCL (C_EXT); | |
917 | } | |
918 | else | |
919 | { | |
920 | PUT_SDB_SCL (C_STAT); | |
921 | } | |
922 | PUT_SDB_TYPE (plain_type (type)); | |
923 | PUT_SDB_ENDEF; | |
924 | } | |
cef2bd3e | 925 | |
37ba3390 RS |
926 | #ifdef SDB_ALLOW_FORWARD_REFERENCES |
927 | ||
0f41302f | 928 | /* Machinery to record and output anonymous types. */ |
37ba3390 | 929 | |
37ba3390 | 930 | static void |
cef2bd3e | 931 | sdbout_queue_anonymous_type (tree type) |
37ba3390 | 932 | { |
1f8f4a0b | 933 | anonymous_types = tree_cons (NULL_TREE, type, anonymous_types); |
37ba3390 RS |
934 | } |
935 | ||
936 | static void | |
cef2bd3e | 937 | sdbout_dequeue_anonymous_types (void) |
37ba3390 | 938 | { |
b3694847 | 939 | tree types, link; |
37ba3390 RS |
940 | |
941 | while (anonymous_types) | |
942 | { | |
943 | types = nreverse (anonymous_types); | |
944 | anonymous_types = NULL_TREE; | |
945 | ||
946 | for (link = types; link; link = TREE_CHAIN (link)) | |
947 | { | |
b3694847 | 948 | tree type = TREE_VALUE (link); |
37ba3390 | 949 | |
c325abbd | 950 | if (type && ! TREE_ASM_WRITTEN (type)) |
37ba3390 RS |
951 | sdbout_one_type (type); |
952 | } | |
953 | } | |
954 | } | |
955 | ||
956 | #endif | |
cef2bd3e | 957 | |
37ba3390 RS |
958 | /* Given a chain of ..._TYPE nodes, all of which have names, |
959 | output definitions of those names, as typedefs. */ | |
960 | ||
961 | void | |
cef2bd3e | 962 | sdbout_types (tree types) |
37ba3390 | 963 | { |
b3694847 | 964 | tree link; |
37ba3390 RS |
965 | |
966 | for (link = types; link; link = TREE_CHAIN (link)) | |
967 | sdbout_one_type (link); | |
968 | ||
969 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
970 | sdbout_dequeue_anonymous_types (); | |
971 | #endif | |
972 | } | |
973 | ||
974 | static void | |
cef2bd3e | 975 | sdbout_type (tree type) |
37ba3390 | 976 | { |
37ba3390 RS |
977 | if (type == error_mark_node) |
978 | type = integer_type_node; | |
979 | PUT_SDB_TYPE (plain_type (type)); | |
980 | } | |
981 | ||
982 | /* Output types of the fields of type TYPE, if they are structs. | |
983 | ||
984 | Formerly did not chase through pointer types, since that could be circular. | |
985 | They must come before TYPE, since forward refs are not allowed. | |
986 | Now james@bigtex.cactus.org says to try them. */ | |
987 | ||
988 | static void | |
cef2bd3e | 989 | sdbout_field_types (tree type) |
37ba3390 RS |
990 | { |
991 | tree tail; | |
e5e809f4 | 992 | |
37ba3390 | 993 | for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail)) |
1270a9b3 LB |
994 | /* This condition should match the one for emitting the actual |
995 | members below. */ | |
0dbb7a10 | 996 | if (TREE_CODE (tail) == FIELD_DECL |
1270a9b3 LB |
997 | && DECL_NAME (tail) |
998 | && DECL_SIZE (tail) | |
cc269bb6 | 999 | && tree_fits_uhwi_p (DECL_SIZE (tail)) |
9541ffee | 1000 | && tree_fits_shwi_p (bit_position (tail))) |
0dbb7a10 JM |
1001 | { |
1002 | if (POINTER_TYPE_P (TREE_TYPE (tail))) | |
1003 | sdbout_one_type (TREE_TYPE (TREE_TYPE (tail))); | |
1004 | else | |
1005 | sdbout_one_type (TREE_TYPE (tail)); | |
1006 | } | |
37ba3390 RS |
1007 | } |
1008 | ||
1009 | /* Use this to put out the top level defined record and union types | |
1010 | for later reference. If this is a struct with a name, then put that | |
1011 | name out. Other unnamed structs will have .xxfake labels generated so | |
1012 | that they may be referred to later. | |
1013 | The label will be stored in the KNOWN_TYPE_TAG slot of a type. | |
1014 | It may NOT be called recursively. */ | |
1015 | ||
1016 | static void | |
cef2bd3e | 1017 | sdbout_one_type (tree type) |
37ba3390 | 1018 | { |
509b12e0 JW |
1019 | if (current_function_decl != NULL_TREE |
1020 | && DECL_SECTION_NAME (current_function_decl) != NULL_TREE) | |
1021 | ; /* Don't change section amid function. */ | |
1022 | else | |
731aefac | 1023 | switch_to_section (current_function_section ()); |
37ba3390 RS |
1024 | |
1025 | switch (TREE_CODE (type)) | |
1026 | { | |
1027 | case RECORD_TYPE: | |
1028 | case UNION_TYPE: | |
c1b98a95 | 1029 | case QUAL_UNION_TYPE: |
37ba3390 RS |
1030 | case ENUMERAL_TYPE: |
1031 | type = TYPE_MAIN_VARIANT (type); | |
1032 | /* Don't output a type twice. */ | |
1033 | if (TREE_ASM_WRITTEN (type)) | |
1034 | /* James said test TREE_ASM_BEING_WRITTEN here. */ | |
1035 | return; | |
1036 | ||
1037 | /* Output nothing if type is not yet defined. */ | |
d0f062fb | 1038 | if (!COMPLETE_TYPE_P (type)) |
37ba3390 RS |
1039 | return; |
1040 | ||
1041 | TREE_ASM_WRITTEN (type) = 1; | |
cef2bd3e | 1042 | |
37ba3390 | 1043 | /* This is reputed to cause trouble with the following case, |
638e2294 | 1044 | but perhaps checking TYPE_SIZE above will fix it. */ |
37ba3390 | 1045 | |
7ef0daad | 1046 | /* Here is a testcase: |
37ba3390 RS |
1047 | |
1048 | struct foo { | |
1049 | struct badstr *bbb; | |
1050 | } forwardref; | |
1051 | ||
1052 | typedef struct intermediate { | |
1053 | int aaaa; | |
1054 | } intermediate_ref; | |
1055 | ||
1056 | typedef struct badstr { | |
1057 | int ccccc; | |
1058 | } badtype; */ | |
1059 | ||
37ba3390 RS |
1060 | /* This change, which ought to make better output, |
1061 | used to make the COFF assembler unhappy. | |
1062 | Changes involving KNOWN_TYPE_TAG may fix the problem. */ | |
1063 | /* Before really doing anything, output types we want to refer to. */ | |
1064 | /* Note that in version 1 the following two lines | |
1065 | are not used if forward references are in use. */ | |
1066 | if (TREE_CODE (type) != ENUMERAL_TYPE) | |
1067 | sdbout_field_types (type); | |
37ba3390 RS |
1068 | |
1069 | /* Output a structure type. */ | |
1070 | { | |
1071 | int size = int_size_in_bytes (type); | |
a544cfd2 | 1072 | int member_scl = 0; |
37ba3390 RS |
1073 | tree tem; |
1074 | ||
1075 | /* Record the type tag, but not in its permanent place just yet. */ | |
1076 | sdbout_record_type_name (type); | |
1077 | ||
1078 | PUT_SDB_DEF (KNOWN_TYPE_TAG (type)); | |
1079 | ||
1080 | switch (TREE_CODE (type)) | |
1081 | { | |
1082 | case UNION_TYPE: | |
c1b98a95 | 1083 | case QUAL_UNION_TYPE: |
37ba3390 RS |
1084 | PUT_SDB_SCL (C_UNTAG); |
1085 | PUT_SDB_TYPE (T_UNION); | |
1086 | member_scl = C_MOU; | |
1087 | break; | |
1088 | ||
1089 | case RECORD_TYPE: | |
1090 | PUT_SDB_SCL (C_STRTAG); | |
1091 | PUT_SDB_TYPE (T_STRUCT); | |
1092 | member_scl = C_MOS; | |
1093 | break; | |
1094 | ||
1095 | case ENUMERAL_TYPE: | |
1096 | PUT_SDB_SCL (C_ENTAG); | |
1097 | PUT_SDB_TYPE (T_ENUM); | |
1098 | member_scl = C_MOE; | |
1099 | break; | |
1d300e19 KG |
1100 | |
1101 | default: | |
1102 | break; | |
37ba3390 RS |
1103 | } |
1104 | ||
1105 | PUT_SDB_SIZE (size); | |
1106 | PUT_SDB_ENDEF; | |
1107 | ||
5b7f1820 RS |
1108 | /* Print out the base class information with fields |
1109 | named after the types they hold. */ | |
684d9f3b | 1110 | /* This is only relevant to aggregate types. TYPE_BINFO is used |
46fb0d7d JW |
1111 | for other purposes in an ENUMERAL_TYPE, so we must exclude that |
1112 | case. */ | |
fa743e8c | 1113 | if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type)) |
5b7f1820 | 1114 | { |
fa743e8c NS |
1115 | int i; |
1116 | tree binfo, child; | |
1117 | ||
1118 | for (binfo = TYPE_BINFO (type), i = 0; | |
1119 | BINFO_BASE_ITERATE (binfo, i, child); i++) | |
ee3e2d3d | 1120 | { |
46fb0d7d JW |
1121 | tree child_type = BINFO_TYPE (child); |
1122 | tree child_type_name; | |
b8698a0f | 1123 | |
46fb0d7d JW |
1124 | if (TYPE_NAME (child_type) == 0) |
1125 | continue; | |
1126 | if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE) | |
1127 | child_type_name = TYPE_NAME (child_type); | |
1128 | else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL) | |
1129 | { | |
1130 | child_type_name = DECL_NAME (TYPE_NAME (child_type)); | |
1131 | if (child_type_name && template_name_p (child_type_name)) | |
1132 | child_type_name | |
1133 | = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type)); | |
1134 | } | |
1135 | else | |
1136 | continue; | |
1137 | ||
46fb0d7d | 1138 | PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name)); |
9439e9a1 | 1139 | PUT_SDB_INT_VAL (tree_to_shwi (BINFO_OFFSET (child))); |
46fb0d7d JW |
1140 | PUT_SDB_SCL (member_scl); |
1141 | sdbout_type (BINFO_TYPE (child)); | |
1142 | PUT_SDB_ENDEF; | |
ee3e2d3d | 1143 | } |
5b7f1820 RS |
1144 | } |
1145 | ||
e0a21ab9 | 1146 | /* Output the individual fields. */ |
37ba3390 RS |
1147 | |
1148 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
bf5e8d0c | 1149 | { |
2d49ce67 | 1150 | for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem)) |
a4a4f775 KT |
1151 | { |
1152 | tree value = TREE_VALUE (tem); | |
1153 | ||
1154 | if (TREE_CODE (value) == CONST_DECL) | |
1155 | value = DECL_INITIAL (value); | |
1156 | ||
9541ffee | 1157 | if (tree_fits_shwi_p (value)) |
a4a4f775 KT |
1158 | { |
1159 | PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem))); | |
9439e9a1 | 1160 | PUT_SDB_INT_VAL (tree_to_shwi (value)); |
a4a4f775 KT |
1161 | PUT_SDB_SCL (C_MOE); |
1162 | PUT_SDB_TYPE (T_MOE); | |
1163 | PUT_SDB_ENDEF; | |
1164 | } | |
1165 | } | |
bf5e8d0c | 1166 | } |
37ba3390 RS |
1167 | else /* record or union type */ |
1168 | for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem)) | |
1169 | /* Output the name, type, position (in bits), size (in bits) | |
1170 | of each field. */ | |
1171 | ||
1172 | /* Omit here the nameless fields that are used to skip bits. | |
1173 | Also omit fields with variable size or position. | |
1174 | Also omit non FIELD_DECL nodes that GNU C++ may put here. */ | |
1175 | if (TREE_CODE (tem) == FIELD_DECL | |
1270a9b3 LB |
1176 | && DECL_NAME (tem) |
1177 | && DECL_SIZE (tem) | |
cc269bb6 | 1178 | && tree_fits_uhwi_p (DECL_SIZE (tem)) |
9541ffee | 1179 | && tree_fits_shwi_p (bit_position (tem))) |
37ba3390 | 1180 | { |
ebb13e7e | 1181 | const char *name; |
0eb111c2 | 1182 | |
4eadbbd5 | 1183 | name = IDENTIFIER_POINTER (DECL_NAME (tem)); |
0eb111c2 | 1184 | PUT_SDB_DEF (name); |
37ba3390 RS |
1185 | if (DECL_BIT_FIELD_TYPE (tem)) |
1186 | { | |
665f2503 | 1187 | PUT_SDB_INT_VAL (int_bit_position (tem)); |
37ba3390 RS |
1188 | PUT_SDB_SCL (C_FIELD); |
1189 | sdbout_type (DECL_BIT_FIELD_TYPE (tem)); | |
ae7e9ddd | 1190 | PUT_SDB_SIZE (tree_to_uhwi (DECL_SIZE (tem))); |
37ba3390 RS |
1191 | } |
1192 | else | |
1193 | { | |
665f2503 | 1194 | PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT); |
37ba3390 RS |
1195 | PUT_SDB_SCL (member_scl); |
1196 | sdbout_type (TREE_TYPE (tem)); | |
1197 | } | |
1198 | PUT_SDB_ENDEF; | |
1199 | } | |
e0a21ab9 | 1200 | /* Output end of a structure,union, or enumeral definition. */ |
37ba3390 RS |
1201 | |
1202 | PUT_SDB_PLAIN_DEF ("eos"); | |
1203 | PUT_SDB_INT_VAL (size); | |
1204 | PUT_SDB_SCL (C_EOS); | |
1205 | PUT_SDB_TAG (KNOWN_TYPE_TAG (type)); | |
1206 | PUT_SDB_SIZE (size); | |
1207 | PUT_SDB_ENDEF; | |
1208 | break; | |
1209 | } | |
b6d83244 RO |
1210 | |
1211 | default: | |
1212 | break; | |
37ba3390 RS |
1213 | } |
1214 | } | |
cef2bd3e | 1215 | |
37ba3390 RS |
1216 | /* The following two functions output definitions of function parameters. |
1217 | Each parameter gets a definition locating it in the parameter list. | |
1218 | Each parameter that is a register variable gets a second definition | |
1219 | locating it in the register. | |
1220 | ||
1221 | Printing or argument lists in gdb uses the definitions that | |
1222 | locate in the parameter list. But reference to the variable in | |
1223 | expressions uses preferentially the definition as a register. */ | |
1224 | ||
1225 | /* Output definitions, referring to storage in the parmlist, | |
1226 | of all the parms in PARMS, which is a chain of PARM_DECL nodes. */ | |
1227 | ||
1228 | static void | |
cef2bd3e | 1229 | sdbout_parms (tree parms) |
37ba3390 RS |
1230 | { |
1231 | for (; parms; parms = TREE_CHAIN (parms)) | |
1232 | if (DECL_NAME (parms)) | |
1233 | { | |
1234 | int current_sym_value = 0; | |
ebb13e7e | 1235 | const char *name = IDENTIFIER_POINTER (DECL_NAME (parms)); |
37ba3390 RS |
1236 | |
1237 | if (name == 0 || *name == 0) | |
1238 | name = gen_fake_label (); | |
1239 | ||
1240 | /* Perform any necessary register eliminations on the parameter's rtl, | |
1241 | so that the debugging output will be accurate. */ | |
db3cf6fb | 1242 | DECL_INCOMING_RTL (parms) |
270d1bcd | 1243 | = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX); |
d975d8c3 | 1244 | SET_DECL_RTL (parms, |
270d1bcd | 1245 | eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX)); |
37ba3390 RS |
1246 | |
1247 | if (PARM_PASSED_IN_MEMORY (parms)) | |
1248 | { | |
1249 | rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0); | |
1250 | tree type; | |
1251 | ||
1252 | /* ??? Here we assume that the parm address is indexed | |
1253 | off the frame pointer or arg pointer. | |
1254 | If that is not true, we produce meaningless results, | |
1255 | but do not crash. */ | |
1256 | if (GET_CODE (addr) == PLUS | |
481683e1 | 1257 | && CONST_INT_P (XEXP (addr, 1))) |
37ba3390 RS |
1258 | current_sym_value = INTVAL (XEXP (addr, 1)); |
1259 | else | |
1260 | current_sym_value = 0; | |
1261 | ||
f8cfc6aa | 1262 | if (REG_P (DECL_RTL (parms)) |
37ba3390 RS |
1263 | && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) |
1264 | type = DECL_ARG_TYPE (parms); | |
1265 | else | |
1266 | { | |
1267 | int original_sym_value = current_sym_value; | |
1268 | ||
1269 | /* This is the case where the parm is passed as an int or | |
1270 | double and it is converted to a char, short or float | |
1271 | and stored back in the parmlist. In this case, describe | |
1272 | the parm with the variable's declared type, and adjust | |
1273 | the address if the least significant bytes (which we are | |
1274 | using) are not the first ones. */ | |
f76b9db2 ILT |
1275 | if (BYTES_BIG_ENDIAN |
1276 | && TREE_TYPE (parms) != DECL_ARG_TYPE (parms)) | |
37ba3390 RS |
1277 | current_sym_value += |
1278 | (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms))) | |
1279 | - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))); | |
f76b9db2 | 1280 | |
3c0cb5de | 1281 | if (MEM_P (DECL_RTL (parms)) |
37ba3390 RS |
1282 | && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS |
1283 | && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) | |
1284 | == CONST_INT) | |
1285 | && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) | |
1286 | == current_sym_value)) | |
1287 | type = TREE_TYPE (parms); | |
1288 | else | |
1289 | { | |
1290 | current_sym_value = original_sym_value; | |
1291 | type = DECL_ARG_TYPE (parms); | |
1292 | } | |
1293 | } | |
1294 | ||
1295 | PUT_SDB_DEF (name); | |
1296 | PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr)); | |
1297 | PUT_SDB_SCL (C_ARG); | |
1298 | PUT_SDB_TYPE (plain_type (type)); | |
1299 | PUT_SDB_ENDEF; | |
1300 | } | |
f8cfc6aa | 1301 | else if (REG_P (DECL_RTL (parms))) |
37ba3390 RS |
1302 | { |
1303 | rtx best_rtl; | |
1304 | /* Parm passed in registers and lives in registers or nowhere. */ | |
1305 | ||
1306 | /* If parm lives in a register, use that register; | |
1307 | pretend the parm was passed there. It would be more consistent | |
1308 | to describe the register where the parm was passed, | |
1309 | but in practice that register usually holds something else. */ | |
770ae6cc | 1310 | if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) |
37ba3390 RS |
1311 | best_rtl = DECL_RTL (parms); |
1312 | /* If the parm lives nowhere, | |
1313 | use the register where it was passed. */ | |
1314 | else | |
1315 | best_rtl = DECL_INCOMING_RTL (parms); | |
1316 | ||
1317 | PUT_SDB_DEF (name); | |
1318 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl))); | |
1319 | PUT_SDB_SCL (C_REGPARM); | |
21abd7a6 | 1320 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms))); |
37ba3390 RS |
1321 | PUT_SDB_ENDEF; |
1322 | } | |
3c0cb5de | 1323 | else if (MEM_P (DECL_RTL (parms)) |
37ba3390 RS |
1324 | && XEXP (DECL_RTL (parms), 0) != const0_rtx) |
1325 | { | |
1326 | /* Parm was passed in registers but lives on the stack. */ | |
1327 | ||
1328 | /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))), | |
1329 | in which case we want the value of that CONST_INT, | |
1330 | or (MEM (REG ...)) or (MEM (MEM ...)), | |
1331 | in which case we use a value of zero. */ | |
f8cfc6aa | 1332 | if (REG_P (XEXP (DECL_RTL (parms), 0)) |
3c0cb5de | 1333 | || MEM_P (XEXP (DECL_RTL (parms), 0))) |
37ba3390 RS |
1334 | current_sym_value = 0; |
1335 | else | |
1336 | current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)); | |
1337 | ||
1338 | /* Again, this assumes the offset is based on the arg pointer. */ | |
1339 | PUT_SDB_DEF (name); | |
1340 | PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, | |
1341 | XEXP (DECL_RTL (parms), 0))); | |
1342 | PUT_SDB_SCL (C_ARG); | |
21abd7a6 | 1343 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms))); |
37ba3390 RS |
1344 | PUT_SDB_ENDEF; |
1345 | } | |
1346 | } | |
1347 | } | |
1348 | ||
1349 | /* Output definitions for the places where parms live during the function, | |
1350 | when different from where they were passed, when the parms were passed | |
1351 | in memory. | |
1352 | ||
1353 | It is not useful to do this for parms passed in registers | |
1354 | that live during the function in different registers, because it is | |
1355 | impossible to look in the passed register for the passed value, | |
1356 | so we use the within-the-function register to begin with. | |
1357 | ||
1358 | PARMS is a chain of PARM_DECL nodes. */ | |
1359 | ||
1360 | static void | |
cef2bd3e | 1361 | sdbout_reg_parms (tree parms) |
37ba3390 RS |
1362 | { |
1363 | for (; parms; parms = TREE_CHAIN (parms)) | |
1364 | if (DECL_NAME (parms)) | |
1365 | { | |
ebb13e7e | 1366 | const char *name = IDENTIFIER_POINTER (DECL_NAME (parms)); |
37ba3390 RS |
1367 | |
1368 | /* Report parms that live in registers during the function | |
1369 | but were passed in memory. */ | |
f8cfc6aa | 1370 | if (REG_P (DECL_RTL (parms)) |
37ba3390 RS |
1371 | && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER |
1372 | && PARM_PASSED_IN_MEMORY (parms)) | |
1373 | { | |
1374 | if (name == 0 || *name == 0) | |
1375 | name = gen_fake_label (); | |
1376 | PUT_SDB_DEF (name); | |
1377 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)))); | |
1378 | PUT_SDB_SCL (C_REG); | |
21abd7a6 | 1379 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms))); |
37ba3390 RS |
1380 | PUT_SDB_ENDEF; |
1381 | } | |
1382 | /* Report parms that live in memory but not where they were passed. */ | |
3c0cb5de | 1383 | else if (MEM_P (DECL_RTL (parms)) |
37ba3390 | 1384 | && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS |
481683e1 | 1385 | && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1)) |
37ba3390 RS |
1386 | && PARM_PASSED_IN_MEMORY (parms) |
1387 | && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms))) | |
1388 | { | |
1389 | #if 0 /* ??? It is not clear yet what should replace this. */ | |
1390 | int offset = DECL_OFFSET (parms) / BITS_PER_UNIT; | |
1391 | /* A parm declared char is really passed as an int, | |
1392 | so it occupies the least significant bytes. | |
1393 | On a big-endian machine those are not the low-numbered ones. */ | |
f76b9db2 ILT |
1394 | if (BYTES_BIG_ENDIAN |
1395 | && offset != -1 | |
1396 | && TREE_TYPE (parms) != DECL_ARG_TYPE (parms)) | |
37ba3390 RS |
1397 | offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms))) |
1398 | - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))); | |
37ba3390 RS |
1399 | if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...} |
1400 | #endif | |
1401 | { | |
1402 | if (name == 0 || *name == 0) | |
1403 | name = gen_fake_label (); | |
1404 | PUT_SDB_DEF (name); | |
1405 | PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET | |
1406 | (XEXP (DECL_RTL (parms), 0))); | |
1407 | PUT_SDB_SCL (C_AUTO); | |
1408 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms))); | |
1409 | PUT_SDB_ENDEF; | |
1410 | } | |
1411 | } | |
1412 | } | |
1413 | } | |
cef2bd3e | 1414 | |
2b85879e NB |
1415 | /* Output debug information for a global DECL. Called from toplev.c |
1416 | after compilation proper has finished. */ | |
1417 | ||
1418 | static void | |
cef2bd3e | 1419 | sdbout_global_decl (tree decl) |
2b85879e NB |
1420 | { |
1421 | if (TREE_CODE (decl) == VAR_DECL | |
3914abb4 NB |
1422 | && !DECL_EXTERNAL (decl) |
1423 | && DECL_RTL_SET_P (decl)) | |
2b85879e NB |
1424 | { |
1425 | /* The COFF linker can move initialized global vars to the end. | |
3914abb4 NB |
1426 | And that can screw up the symbol ordering. Defer those for |
1427 | sdbout_finish (). */ | |
1428 | if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl)) | |
2b85879e | 1429 | sdbout_symbol (decl, 0); |
21d13d83 | 1430 | else |
9771b263 | 1431 | vec_safe_push (deferred_global_decls, decl); |
2b85879e NB |
1432 | |
1433 | /* Output COFF information for non-global file-scope initialized | |
1434 | variables. */ | |
3c0cb5de | 1435 | if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl))) |
2b85879e NB |
1436 | sdbout_toplevel_data (decl); |
1437 | } | |
1438 | } | |
3914abb4 NB |
1439 | |
1440 | /* Output initialized global vars at the end, in the order of | |
1441 | definition. See comment in sdbout_global_decl. */ | |
1442 | ||
1443 | static void | |
cef2bd3e | 1444 | sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED) |
3914abb4 | 1445 | { |
16edbbf0 | 1446 | size_t i; |
b6feb796 | 1447 | tree decl; |
3914abb4 | 1448 | |
9771b263 | 1449 | FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl) |
b6feb796 | 1450 | sdbout_symbol (decl, 0); |
3914abb4 | 1451 | } |
cef2bd3e | 1452 | |
37ba3390 RS |
1453 | /* Describe the beginning of an internal block within a function. |
1454 | Also output descriptions of variables defined in this block. | |
1455 | ||
1456 | N is the number of the block, by order of beginning, counting from 1, | |
1457 | and not counting the outermost (function top-level) block. | |
1458 | The blocks match the BLOCKs in DECL_INITIAL (current_function_decl), | |
1459 | if the count starts at 0 for the outermost one. */ | |
1460 | ||
a5a42b92 | 1461 | static void |
cef2bd3e | 1462 | sdbout_begin_block (unsigned int line, unsigned int n) |
37ba3390 RS |
1463 | { |
1464 | tree decl = current_function_decl; | |
1465 | MAKE_LINE_SAFE (line); | |
9f27ca8b JW |
1466 | |
1467 | /* The SCO compiler does not emit a separate block for the function level | |
7c17f335 RO |
1468 | scope, so we avoid it here also. */ |
1469 | PUT_SDB_BLOCK_START (line - sdb_begin_function_line); | |
9f27ca8b | 1470 | |
37ba3390 RS |
1471 | if (n == 1) |
1472 | { | |
1473 | /* Include the outermost BLOCK's variables in block 1. */ | |
18c038b9 | 1474 | do_block = BLOCK_NUMBER (DECL_INITIAL (decl)); |
37ba3390 RS |
1475 | sdbout_block (DECL_INITIAL (decl)); |
1476 | } | |
1477 | /* If -g1, suppress all the internal symbols of functions | |
1478 | except for arguments. */ | |
1479 | if (debug_info_level != DINFO_LEVEL_TERSE) | |
1480 | { | |
37ba3390 RS |
1481 | do_block = n; |
1482 | sdbout_block (DECL_INITIAL (decl)); | |
1483 | } | |
1484 | ||
1485 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
1486 | sdbout_dequeue_anonymous_types (); | |
1487 | #endif | |
1488 | } | |
1489 | ||
1490 | /* Describe the end line-number of an internal block within a function. */ | |
1491 | ||
e2a12aca | 1492 | static void |
cef2bd3e | 1493 | sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED) |
37ba3390 RS |
1494 | { |
1495 | MAKE_LINE_SAFE (line); | |
9f27ca8b JW |
1496 | |
1497 | /* The SCO compiler does not emit a separate block for the function level | |
7c17f335 | 1498 | scope, so we avoid it here also. */ |
9f27ca8b | 1499 | if (n != 1) |
7c17f335 | 1500 | PUT_SDB_BLOCK_END (line - sdb_begin_function_line); |
37ba3390 RS |
1501 | } |
1502 | ||
a8d0467e EB |
1503 | /* Output a line number symbol entry for source file FILENAME and line |
1504 | number LINE. */ | |
1505 | ||
e2a12aca | 1506 | static void |
6c52e687 | 1507 | sdbout_source_line (unsigned int line, const char *filename ATTRIBUTE_UNUSED, |
ed5ef2e4 CC |
1508 | int discriminator ATTRIBUTE_UNUSED, |
1509 | bool is_stmt ATTRIBUTE_UNUSED) | |
e2a12aca | 1510 | { |
e2a12aca | 1511 | /* COFF relative line numbers must be positive. */ |
5197bd50 | 1512 | if ((int) line > sdb_begin_function_line) |
e2a12aca | 1513 | { |
3e487b21 ZW |
1514 | #ifdef SDB_OUTPUT_SOURCE_LINE |
1515 | SDB_OUTPUT_SOURCE_LINE (asm_out_file, line); | |
e2a12aca NB |
1516 | #else |
1517 | fprintf (asm_out_file, "\t.ln\t%d\n", | |
1518 | ((sdb_begin_function_line > -1) | |
1519 | ? line - sdb_begin_function_line : 1)); | |
1520 | #endif | |
1521 | } | |
1522 | } | |
1523 | ||
37ba3390 RS |
1524 | /* Output sdb info for the current function name. |
1525 | Called from assemble_start_function. */ | |
1526 | ||
653e276c | 1527 | static void |
cef2bd3e | 1528 | sdbout_begin_function (tree decl ATTRIBUTE_UNUSED) |
37ba3390 RS |
1529 | { |
1530 | sdbout_symbol (current_function_decl, 0); | |
1531 | } | |
1532 | ||
7c17f335 RO |
1533 | /* Called at beginning of function body after prologue. Record the |
1534 | function's starting line number, so we can output relative line numbers | |
1535 | for the other lines. Describe beginning of outermost block. Also | |
1536 | describe the parameter list. */ | |
37ba3390 | 1537 | |
653e276c | 1538 | static void |
cef2bd3e | 1539 | sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED) |
653e276c | 1540 | { |
702ada3d | 1541 | sdbout_end_prologue (line, file); |
653e276c | 1542 | } |
653e276c NB |
1543 | |
1544 | static void | |
bf9d3c27 | 1545 | sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED) |
37ba3390 RS |
1546 | { |
1547 | sdb_begin_function_line = line - 1; | |
1548 | PUT_SDB_FUNCTION_START (line); | |
1549 | sdbout_parms (DECL_ARGUMENTS (current_function_decl)); | |
1550 | sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl)); | |
1551 | } | |
1552 | ||
1553 | /* Called at end of function (before epilogue). | |
1554 | Describe end of outermost block. */ | |
1555 | ||
e2a12aca | 1556 | static void |
cef2bd3e | 1557 | sdbout_end_function (unsigned int line) |
37ba3390 RS |
1558 | { |
1559 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
1560 | sdbout_dequeue_anonymous_types (); | |
1561 | #endif | |
1562 | ||
1563 | MAKE_LINE_SAFE (line); | |
1564 | PUT_SDB_FUNCTION_END (line - sdb_begin_function_line); | |
1565 | ||
1566 | /* Indicate we are between functions, for line-number output. */ | |
1567 | sdb_begin_function_line = -1; | |
1568 | } | |
1569 | ||
1570 | /* Output sdb info for the absolute end of a function. | |
1571 | Called after the epilogue is output. */ | |
1572 | ||
e2a12aca | 1573 | static void |
cef2bd3e AJ |
1574 | sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED, |
1575 | const char *file ATTRIBUTE_UNUSED) | |
37ba3390 | 1576 | { |
e59f7d3d | 1577 | const char *const name ATTRIBUTE_UNUSED |
e2a12aca NB |
1578 | = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)); |
1579 | ||
1580 | #ifdef PUT_SDB_EPILOGUE_END | |
1581 | PUT_SDB_EPILOGUE_END (name); | |
1582 | #else | |
1583 | fprintf (asm_out_file, "\t.def\t"); | |
1584 | assemble_name (asm_out_file, name); | |
1585 | fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n", | |
1586 | SDB_DELIM, SDB_DELIM, SDB_DELIM); | |
1587 | #endif | |
37ba3390 RS |
1588 | } |
1589 | ||
1590 | /* Output sdb info for the given label. Called only if LABEL_NAME (insn) | |
1591 | is present. */ | |
1592 | ||
e1772ac0 | 1593 | static void |
cef2bd3e | 1594 | sdbout_label (rtx insn) |
37ba3390 RS |
1595 | { |
1596 | PUT_SDB_DEF (LABEL_NAME (insn)); | |
1597 | PUT_SDB_VAL (insn); | |
1598 | PUT_SDB_SCL (C_LABEL); | |
1599 | PUT_SDB_TYPE (T_NULL); | |
1600 | PUT_SDB_ENDEF; | |
1601 | } | |
1602 | ||
cc694a81 DE |
1603 | /* Change to reading from a new source file. */ |
1604 | ||
7f905405 | 1605 | static void |
cef2bd3e AJ |
1606 | sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED, |
1607 | const char *filename ATTRIBUTE_UNUSED) | |
cc694a81 | 1608 | { |
cc694a81 DE |
1609 | } |
1610 | ||
1611 | /* Revert to reading a previous source file. */ | |
1612 | ||
7f905405 | 1613 | static void |
cef2bd3e | 1614 | sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED) |
cc694a81 | 1615 | { |
cc694a81 DE |
1616 | } |
1617 | ||
4eadbbd5 RK |
1618 | /* Set up for SDB output at the start of compilation. */ |
1619 | ||
a51d908e | 1620 | static void |
cef2bd3e | 1621 | sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED) |
4eadbbd5 | 1622 | { |
16edbbf0 ZW |
1623 | tree t; |
1624 | ||
9771b263 | 1625 | vec_alloc (deferred_global_decls, 12); |
16edbbf0 ZW |
1626 | |
1627 | /* Emit debug information which was queued by sdbout_symbol before | |
1628 | we got here. */ | |
1629 | sdbout_initialized = true; | |
1630 | ||
1631 | for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t)) | |
1632 | sdbout_symbol (TREE_VALUE (t), 0); | |
1633 | preinit_symbols = 0; | |
4eadbbd5 RK |
1634 | } |
1635 | ||
37ba3390 | 1636 | #endif /* SDB_DEBUGGING_INFO */ |
e2500fed GK |
1637 | |
1638 | #include "gt-sdbout.h" |