]>
Commit | Line | Data |
---|---|---|
00fe048c | 1 | /* Output dbx-format symbol table information from GNU compiler. |
7adcbafe | 2 | Copyright (C) 1987-2022 Free Software Foundation, Inc. |
00fe048c | 3 | |
1322177d | 4 | This file is part of GCC. |
00fe048c | 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. |
00fe048c | 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. | |
00fe048c 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/>. */ | |
00fe048c RS |
19 | |
20 | ||
21 | /* Output dbx-format symbol table data. | |
22 | This consists of many symbol table entries, each of them | |
23 | a .stabs assembler pseudo-op with four operands: | |
24 | a "name" which is really a description of one symbol and its type, | |
25 | a "code", which is a symbol defined in stab.h whose name starts with N_, | |
26 | an unused operand always 0, | |
27 | and a "value" which is an address or an offset. | |
28 | The name is enclosed in doublequote characters. | |
29 | ||
30 | Each function, variable, typedef, and structure tag | |
31 | has a symbol table entry to define it. | |
32 | The beginning and end of each level of name scoping within | |
33 | a function are also marked by special symbol table entries. | |
34 | ||
35 | The "name" consists of the symbol name, a colon, a kind-of-symbol letter, | |
36 | and a data type number. The data type number may be followed by | |
37 | "=" and a type definition; normally this will happen the first time | |
38 | the type number is mentioned. The type definition may refer to | |
39 | other types by number, and those type numbers may be followed | |
40 | by "=" and nested definitions. | |
41 | ||
42 | This can make the "name" quite long. | |
43 | When a name is more than 80 characters, we split the .stabs pseudo-op | |
44 | into two .stabs pseudo-ops, both sharing the same "code" and "value". | |
45 | The first one is marked as continued with a double-backslash at the | |
46 | end of its "name". | |
47 | ||
48 | The kind-of-symbol letter distinguished function names from global | |
49 | variables from file-scope variables from parameters from auto | |
50 | variables in memory from typedef names from register variables. | |
51 | See `dbxout_symbol'. | |
52 | ||
53 | The "code" is mostly redundant with the kind-of-symbol letter | |
54 | that goes in the "name", but not entirely: for symbols located | |
55 | in static storage, the "code" says which segment the address is in, | |
56 | which controls how it is relocated. | |
57 | ||
58 | The "value" for a symbol in static storage | |
59 | is the core address of the symbol (actually, the assembler | |
60 | label for the symbol). For a symbol located in a stack slot | |
61 | it is the stack offset; for one in a register, the register number. | |
62 | For a typedef symbol, it is zero. | |
63 | ||
64 | If DEBUG_SYMS_TEXT is defined, all debugging symbols must be | |
65 | output while in the text section. | |
66 | ||
67 | For more on data type definitions, see `dbxout_type'. */ | |
68 | ||
e9a25f70 | 69 | #include "config.h" |
670ee920 | 70 | #include "system.h" |
4977bab6 | 71 | #include "coretypes.h" |
957060b5 AM |
72 | #include "target.h" |
73 | #include "function.h" | |
957060b5 | 74 | #include "rtl.h" |
00fe048c | 75 | #include "tree.h" |
4d0cdd0c | 76 | #include "memmodel.h" |
957060b5 AM |
77 | #include "tm_p.h" |
78 | #include "stringpool.h" | |
957060b5 | 79 | #include "insn-config.h" |
957060b5 AM |
80 | #include "emit-rtl.h" |
81 | #include "cgraph.h" | |
82 | #include "diagnostic-core.h" | |
40e23961 | 83 | #include "fold-const.h" |
d8a2d370 DN |
84 | #include "varasm.h" |
85 | #include "stor-layout.h" | |
00fe048c | 86 | #include "reload.h" |
3e487b21 | 87 | #include "output.h" |
76ead72b | 88 | #include "dbxout.h" |
487a6e06 | 89 | #include "toplev.h" |
a51d908e | 90 | #include "debug.h" |
677f3fa8 | 91 | #include "common/common-target.h" |
3ac88239 | 92 | #include "langhooks.h" |
9bfa80fb | 93 | #include "expr.h" |
7365279f | 94 | #include "file-prefix-map.h" /* remap_debug_filename() */ |
66168f96 | 95 | #include "flags.h" |
00fe048c | 96 | |
b372168c | 97 | #ifdef XCOFF_DEBUGGING_INFO |
95f2ba07 | 98 | #include "xcoffout.h" |
b372168c MM |
99 | #endif |
100 | ||
00fe048c | 101 | #ifndef ASM_STABS_OP |
93a27b7b ZW |
102 | # ifdef XCOFF_DEBUGGING_INFO |
103 | # define ASM_STABS_OP "\t.stabx\t" | |
104 | # else | |
105 | # define ASM_STABS_OP "\t.stabs\t" | |
106 | # endif | |
00fe048c RS |
107 | #endif |
108 | ||
109 | #ifndef ASM_STABN_OP | |
0a3e1f45 | 110 | #define ASM_STABN_OP "\t.stabn\t" |
00fe048c RS |
111 | #endif |
112 | ||
93a27b7b ZW |
113 | #ifndef ASM_STABD_OP |
114 | #define ASM_STABD_OP "\t.stabd\t" | |
115 | #endif | |
116 | ||
01e2750c RS |
117 | #ifndef DBX_TYPE_DECL_STABS_CODE |
118 | #define DBX_TYPE_DECL_STABS_CODE N_LSYM | |
b372168c MM |
119 | #endif |
120 | ||
121 | #ifndef DBX_STATIC_CONST_VAR_CODE | |
122 | #define DBX_STATIC_CONST_VAR_CODE N_FUN | |
123 | #endif | |
124 | ||
125 | #ifndef DBX_REGPARM_STABS_CODE | |
126 | #define DBX_REGPARM_STABS_CODE N_RSYM | |
127 | #endif | |
128 | ||
129 | #ifndef DBX_REGPARM_STABS_LETTER | |
130 | #define DBX_REGPARM_STABS_LETTER 'P' | |
131 | #endif | |
132 | ||
8768c655 RH |
133 | #ifndef NO_DBX_FUNCTION_END |
134 | #define NO_DBX_FUNCTION_END 0 | |
135 | #endif | |
136 | ||
5d865dac EB |
137 | #ifndef NO_DBX_BNSYM_ENSYM |
138 | #define NO_DBX_BNSYM_ENSYM 0 | |
139 | #endif | |
140 | ||
93a27b7b ZW |
141 | #ifndef NO_DBX_MAIN_SOURCE_DIRECTORY |
142 | #define NO_DBX_MAIN_SOURCE_DIRECTORY 0 | |
143 | #endif | |
144 | ||
3e487b21 ZW |
145 | #ifndef DBX_BLOCKS_FUNCTION_RELATIVE |
146 | #define DBX_BLOCKS_FUNCTION_RELATIVE 0 | |
147 | #endif | |
148 | ||
149 | #ifndef DBX_LINES_FUNCTION_RELATIVE | |
150 | #define DBX_LINES_FUNCTION_RELATIVE 0 | |
151 | #endif | |
152 | ||
93a27b7b ZW |
153 | #ifndef DBX_CONTIN_LENGTH |
154 | #define DBX_CONTIN_LENGTH 80 | |
155 | #endif | |
156 | ||
157 | #ifndef DBX_CONTIN_CHAR | |
158 | #define DBX_CONTIN_CHAR '\\' | |
159 | #endif | |
160 | ||
00fe048c RS |
161 | enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED}; |
162 | ||
4bcaafd9 ILT |
163 | /* Structure recording information about a C data type. |
164 | The status element says whether we have yet output | |
165 | the definition of the type. TYPE_XREF says we have | |
166 | output it as a cross-reference only. | |
167 | The file_number and type_number elements are used if DBX_USE_BINCL | |
168 | is defined. */ | |
169 | ||
d1b38208 | 170 | struct GTY(()) typeinfo { |
4bcaafd9 | 171 | enum typestatus status; |
4bcaafd9 ILT |
172 | int file_number; |
173 | int type_number; | |
4bcaafd9 ILT |
174 | }; |
175 | ||
176 | /* Vector recording information about C data types. | |
00fe048c RS |
177 | When we first notice a data type (a tree node), |
178 | we assign it a number using next_type_number. | |
4bcaafd9 | 179 | That is its index in this vector. */ |
00fe048c | 180 | |
17211ab5 | 181 | static GTY ((length ("typevec_len"))) struct typeinfo *typevec; |
00fe048c RS |
182 | |
183 | /* Number of elements of space allocated in `typevec'. */ | |
184 | ||
17211ab5 | 185 | static GTY(()) int typevec_len; |
00fe048c RS |
186 | |
187 | /* In dbx output, each type gets a unique number. | |
188 | This is the number for the next type output. | |
189 | The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */ | |
190 | ||
17211ab5 | 191 | static GTY(()) int next_type_number; |
4bcaafd9 | 192 | |
21d13d83 ZW |
193 | /* The C front end may call dbxout_symbol before dbxout_init runs. |
194 | We save all such decls in this list and output them when we get | |
195 | to dbxout_init. */ | |
196 | ||
197 | static GTY(()) tree preinit_symbols; | |
198 | ||
33e9d2aa DP |
199 | enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED}; |
200 | ||
4bcaafd9 ILT |
201 | /* When using N_BINCL in dbx output, each type number is actually a |
202 | pair of the file number and the type number within the file. | |
203 | This is a stack of input files. */ | |
204 | ||
047c6eac | 205 | struct dbx_file |
4bcaafd9 ILT |
206 | { |
207 | struct dbx_file *next; | |
208 | int file_number; | |
209 | int next_type_number; | |
047c6eac GK |
210 | enum binclstatus bincl_status; /* Keep track of lazy bincl. */ |
211 | const char *pending_bincl_name; /* Name of bincl. */ | |
212 | struct dbx_file *prev; /* Chain to traverse all pending bincls. */ | |
4bcaafd9 ILT |
213 | }; |
214 | ||
b8698a0f L |
215 | /* This is the top of the stack. |
216 | ||
047c6eac GK |
217 | This is not saved for PCH, because restoring a PCH should not change it. |
218 | next_file_number does have to be saved, because the PCH may use some | |
219 | file numbers; however, just before restoring a PCH, next_file_number | |
220 | should always be 0 because we should not have needed any file numbers | |
221 | yet. */ | |
4bcaafd9 | 222 | |
e139ff5b AS |
223 | #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \ |
224 | && defined (DBX_USE_BINCL) | |
047c6eac | 225 | static struct dbx_file *current_file; |
a37336cf | 226 | #endif |
4bcaafd9 ILT |
227 | |
228 | /* This is the next file number to use. */ | |
229 | ||
17211ab5 GK |
230 | static GTY(()) int next_file_number; |
231 | ||
33b49800 | 232 | /* A counter for dbxout_function_end. */ |
c1b50e49 | 233 | |
33b49800 | 234 | static GTY(()) int scope_labelno; |
c1b50e49 | 235 | |
a8d0467e EB |
236 | /* A counter for dbxout_source_line. */ |
237 | ||
238 | static GTY(()) int dbxout_source_line_counter; | |
239 | ||
17211ab5 GK |
240 | /* Number for the next N_SOL filename stabs label. The number 0 is reserved |
241 | for the N_SO filename stabs label. */ | |
242 | ||
33b49800 GK |
243 | static GTY(()) int source_label_number = 1; |
244 | ||
245 | /* Last source file name mentioned in a NOTE insn. */ | |
246 | ||
247 | static GTY(()) const char *lastfile; | |
248 | ||
b8cb3096 JJ |
249 | /* Last line number mentioned in a NOTE insn. */ |
250 | ||
251 | static GTY(()) unsigned int lastlineno; | |
252 | ||
33b49800 GK |
253 | /* Used by PCH machinery to detect if 'lastfile' should be reset to |
254 | base_input_file. */ | |
255 | static GTY(()) int lastfile_is_base; | |
256 | ||
257 | /* Typical USG systems don't have stab.h, and they also have | |
258 | no use for DBX-format debugging info. */ | |
259 | ||
260 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) | |
261 | ||
8837d828 AS |
262 | #ifdef DBX_USE_BINCL |
263 | /* If zero then there is no pending BINCL. */ | |
264 | static int pending_bincls = 0; | |
265 | #endif | |
266 | ||
33b49800 GK |
267 | /* The original input file name. */ |
268 | static const char *base_input_file; | |
269 | ||
17211ab5 | 270 | #ifdef DEBUG_SYMS_TEXT |
d6b5193b | 271 | #define FORCE_TEXT switch_to_section (current_function_section ()) |
17211ab5 GK |
272 | #else |
273 | #define FORCE_TEXT | |
274 | #endif | |
275 | ||
276 | #include "gstab.h" | |
277 | ||
17211ab5 GK |
278 | /* 1 if PARM is passed to this function in memory. */ |
279 | ||
280 | #define PARM_PASSED_IN_MEMORY(PARM) \ | |
3c0cb5de | 281 | (MEM_P (DECL_INCOMING_RTL (PARM))) |
4bcaafd9 | 282 | |
17211ab5 GK |
283 | /* A C expression for the integer offset value of an automatic variable |
284 | (N_LSYM) having address X (an RTX). */ | |
285 | #ifndef DEBUGGER_AUTO_OFFSET | |
286 | #define DEBUGGER_AUTO_OFFSET(X) \ | |
287 | (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0) | |
288 | #endif | |
289 | ||
290 | /* A C expression for the integer offset value of an argument (N_PSYM) | |
3d07b7cd LCW |
291 | having address X (an RTX). The nominal offset is OFFSET. |
292 | Note that we use OFFSET + 0 here to avoid the self-assign warning | |
293 | when the macro is called in a context like | |
294 | number = DEBUGGER_ARG_OFFSET(number, X) */ | |
17211ab5 | 295 | #ifndef DEBUGGER_ARG_OFFSET |
3d07b7cd | 296 | #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET + 0) |
17211ab5 GK |
297 | #endif |
298 | ||
93a27b7b ZW |
299 | /* This obstack holds the stab string currently being constructed. We |
300 | build it up here, then write it out, so we can split long lines up | |
301 | properly (see dbxout_finish_complex_stabs). */ | |
302 | static struct obstack stabstr_ob; | |
303 | static size_t stabstr_last_contin_point; | |
00fe048c | 304 | |
5ec3a5a7 | 305 | #ifdef DBX_USE_BINCL |
33e9d2aa DP |
306 | static void emit_bincl_stab (const char *c); |
307 | static void emit_pending_bincls (void); | |
f23b9d52 | 308 | #endif |
33e9d2aa DP |
309 | static inline void emit_pending_bincls_if_required (void); |
310 | ||
7080f735 | 311 | static void dbxout_init (const char *); |
b8698a0f | 312 | |
7080f735 AJ |
313 | static void dbxout_finish (const char *); |
314 | static void dbxout_start_source_file (unsigned, const char *); | |
315 | static void dbxout_end_source_file (unsigned); | |
316 | static void dbxout_typedefs (tree); | |
7080f735 | 317 | static void dbxout_type_index (tree); |
7080f735 AJ |
318 | static void dbxout_args (tree); |
319 | static void dbxout_type_fields (tree); | |
93a27b7b | 320 | static void dbxout_type_method_1 (tree); |
7080f735 | 321 | static void dbxout_type_methods (tree); |
84fb43a1 | 322 | static void dbxout_range_type (tree, tree, tree); |
7080f735 | 323 | static void dbxout_type (tree, int); |
84fb43a1 | 324 | static bool print_int_cst_bounds_in_octal_p (tree, tree, tree); |
7151ffbe | 325 | static bool is_fortran (void); |
7080f735 AJ |
326 | static void dbxout_type_name (tree); |
327 | static void dbxout_class_name_qualifiers (tree); | |
328 | static int dbxout_symbol_location (tree, tree, const char *, rtx); | |
329 | static void dbxout_symbol_name (tree, const char *, int); | |
dbb6088f | 330 | static void dbxout_common_name (tree, const char *, stab_code_type); |
7151ffbe | 331 | static const char *dbxout_common_check (tree, int *); |
d7438551 AH |
332 | static void dbxout_early_global_decl (tree); |
333 | static void dbxout_late_global_decl (tree); | |
8507c40a | 334 | static void dbxout_type_decl (tree, int); |
7080f735 | 335 | static void dbxout_handle_pch (unsigned); |
1ed13f83 | 336 | static void debug_free_queue (void); |
00fe048c | 337 | \f |
7f905405 | 338 | /* The debug hooks structure. */ |
a5a42b92 NB |
339 | #if defined (DBX_DEBUGGING_INFO) |
340 | ||
497b7c47 JJ |
341 | static void dbxout_source_line (unsigned int, unsigned int, const char *, |
342 | int, bool); | |
b8cb3096 | 343 | static void dbxout_switch_text_section (void); |
497b7c47 | 344 | static void dbxout_begin_prologue (unsigned int, unsigned int, const char *); |
93a27b7b | 345 | static void dbxout_source_file (const char *); |
847d0c08 | 346 | static void dbxout_function_end (tree); |
7080f735 AJ |
347 | static void dbxout_begin_function (tree); |
348 | static void dbxout_begin_block (unsigned, unsigned); | |
349 | static void dbxout_end_block (unsigned, unsigned); | |
350 | static void dbxout_function_decl (tree); | |
a5a42b92 | 351 | |
54b6670a | 352 | const struct gcc_debug_hooks dbx_debug_hooks = |
a51d908e NB |
353 | { |
354 | dbxout_init, | |
7f905405 | 355 | dbxout_finish, |
68317985 | 356 | debug_nothing_charstar, |
d7438551 | 357 | debug_nothing_void, |
7f905405 NB |
358 | debug_nothing_int_charstar, |
359 | debug_nothing_int_charstar, | |
360 | dbxout_start_source_file, | |
a5a42b92 NB |
361 | dbxout_end_source_file, |
362 | dbxout_begin_block, | |
e2a12aca | 363 | dbxout_end_block, |
9678086d | 364 | debug_true_const_tree, /* ignore_block */ |
6097b0c3 | 365 | dbxout_source_line, /* source_line */ |
e69ac020 | 366 | debug_nothing_int_int_charstar, /* set_ignored_loc */ |
8fa5469d | 367 | dbxout_begin_prologue, /* begin_prologue */ |
6097b0c3 | 368 | debug_nothing_int_charstar, /* end_prologue */ |
67ad2ae7 | 369 | debug_nothing_int_charstar, /* begin_epilogue */ |
6097b0c3 | 370 | debug_nothing_int_charstar, /* end_epilogue */ |
653e276c NB |
371 | #ifdef DBX_FUNCTION_FIRST |
372 | dbxout_begin_function, | |
373 | #else | |
6097b0c3 | 374 | debug_nothing_tree, /* begin_function */ |
653e276c | 375 | #endif |
6097b0c3 | 376 | debug_nothing_int, /* end_function */ |
881a5e60 | 377 | debug_nothing_tree, /* register_main_translation_unit */ |
2b85879e | 378 | dbxout_function_decl, |
d7438551 AH |
379 | dbxout_early_global_decl, /* early_global_decl */ |
380 | dbxout_late_global_decl, /* late_global_decl */ | |
21d13d83 | 381 | dbxout_type_decl, /* type_decl */ |
e071b767 | 382 | debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */ |
1ea85365 RB |
383 | debug_false_tree_charstarstar_uhwistar,/* die_ref_for_decl */ |
384 | debug_nothing_tree_charstar_uhwi, /* register_external_die */ | |
6097b0c3 DP |
385 | debug_nothing_tree, /* deferred_inline_function */ |
386 | debug_nothing_tree, /* outlining_inline_function */ | |
f630fc6a | 387 | debug_nothing_rtx_code_label, /* label */ |
014a1138 | 388 | dbxout_handle_pch, /* handle_pch */ |
f630fc6a | 389 | debug_nothing_rtx_insn, /* var_location */ |
102d484d | 390 | debug_nothing_tree, /* inline_entry */ |
986ccd21 | 391 | debug_nothing_tree, /* size_function */ |
b8cb3096 | 392 | dbxout_switch_text_section, /* switch_text_section */ |
a417cdd9 | 393 | debug_nothing_tree_tree, /* set_name */ |
c6a13190 ILT |
394 | 0, /* start_end_main_source_file */ |
395 | TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */ | |
a51d908e | 396 | }; |
a5a42b92 NB |
397 | #endif /* DBX_DEBUGGING_INFO */ |
398 | ||
399 | #if defined (XCOFF_DEBUGGING_INFO) | |
54b6670a | 400 | const struct gcc_debug_hooks xcoff_debug_hooks = |
a5a42b92 NB |
401 | { |
402 | dbxout_init, | |
403 | dbxout_finish, | |
8dd23f3e | 404 | debug_nothing_charstar, |
d7438551 | 405 | debug_nothing_void, |
a5a42b92 NB |
406 | debug_nothing_int_charstar, |
407 | debug_nothing_int_charstar, | |
408 | dbxout_start_source_file, | |
409 | dbxout_end_source_file, | |
410 | xcoffout_begin_block, | |
e2a12aca | 411 | xcoffout_end_block, |
9678086d | 412 | debug_true_const_tree, /* ignore_block */ |
e2a12aca | 413 | xcoffout_source_line, |
e69ac020 | 414 | debug_nothing_int_int_charstar, /* set_ignored_loc */ |
6097b0c3 DP |
415 | xcoffout_begin_prologue, /* begin_prologue */ |
416 | debug_nothing_int_charstar, /* end_prologue */ | |
67ad2ae7 | 417 | debug_nothing_int_charstar, /* begin_epilogue */ |
e2a12aca | 418 | xcoffout_end_epilogue, |
6097b0c3 | 419 | debug_nothing_tree, /* begin_function */ |
2b85879e | 420 | xcoffout_end_function, |
1b926144 | 421 | debug_nothing_tree, /* register_main_translation_unit */ |
6097b0c3 | 422 | debug_nothing_tree, /* function_decl */ |
d7438551 AH |
423 | dbxout_early_global_decl, /* early_global_decl */ |
424 | dbxout_late_global_decl, /* late_global_decl */ | |
21d13d83 | 425 | dbxout_type_decl, /* type_decl */ |
e071b767 | 426 | debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */ |
1ea85365 RB |
427 | debug_false_tree_charstarstar_uhwistar,/* die_ref_for_decl */ |
428 | debug_nothing_tree_charstar_uhwi, /* register_external_die */ | |
6097b0c3 DP |
429 | debug_nothing_tree, /* deferred_inline_function */ |
430 | debug_nothing_tree, /* outlining_inline_function */ | |
f630fc6a | 431 | debug_nothing_rtx_code_label, /* label */ |
014a1138 | 432 | dbxout_handle_pch, /* handle_pch */ |
f630fc6a | 433 | debug_nothing_rtx_insn, /* var_location */ |
102d484d | 434 | debug_nothing_tree, /* inline_entry */ |
986ccd21 | 435 | debug_nothing_tree, /* size_function */ |
87c8b4be | 436 | debug_nothing_void, /* switch_text_section */ |
58298177 | 437 | debug_nothing_tree_tree, /* set_name */ |
c6a13190 ILT |
438 | 0, /* start_end_main_source_file */ |
439 | TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */ | |
a5a42b92 NB |
440 | }; |
441 | #endif /* XCOFF_DEBUGGING_INFO */ | |
a51d908e | 442 | \f |
93a27b7b ZW |
443 | /* Numeric formatting helper macro. Note that this does not handle |
444 | hexadecimal. */ | |
445 | #define NUMBER_FMT_LOOP(P, NUM, BASE) \ | |
446 | do \ | |
447 | { \ | |
448 | int digit = NUM % BASE; \ | |
449 | NUM /= BASE; \ | |
450 | *--P = digit + '0'; \ | |
451 | } \ | |
452 | while (NUM > 0) | |
453 | ||
454 | /* Utility: write a decimal integer NUM to asm_out_file. */ | |
455 | void | |
456 | dbxout_int (int num) | |
457 | { | |
458 | char buf[64]; | |
459 | char *p = buf + sizeof buf; | |
460 | unsigned int unum; | |
461 | ||
462 | if (num == 0) | |
463 | { | |
464 | putc ('0', asm_out_file); | |
465 | return; | |
466 | } | |
467 | if (num < 0) | |
468 | { | |
469 | putc ('-', asm_out_file); | |
b5872261 | 470 | unum = -(unsigned int) num; |
93a27b7b ZW |
471 | } |
472 | else | |
473 | unum = num; | |
474 | ||
475 | NUMBER_FMT_LOOP (p, unum, 10); | |
476 | ||
477 | while (p < buf + sizeof buf) | |
478 | { | |
479 | putc (*p, asm_out_file); | |
480 | p++; | |
481 | } | |
482 | } | |
483 | ||
484 | \f | |
485 | /* Primitives for emitting simple stabs directives. All other stabs | |
486 | routines should use these functions instead of directly emitting | |
487 | stabs. They are exported because machine-dependent code may need | |
488 | to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition | |
489 | forwards to code in CPU.c. */ | |
490 | ||
491 | /* The following functions should all be called immediately after one | |
492 | of the dbxout_begin_stab* functions (below). They write out | |
493 | various things as the value of a stab. */ | |
494 | ||
495 | /* Write out a literal zero as the value of a stab. */ | |
496 | void | |
497 | dbxout_stab_value_zero (void) | |
498 | { | |
499 | fputs ("0\n", asm_out_file); | |
500 | } | |
501 | ||
502 | /* Write out the label LABEL as the value of a stab. */ | |
503 | void | |
504 | dbxout_stab_value_label (const char *label) | |
505 | { | |
506 | assemble_name (asm_out_file, label); | |
507 | putc ('\n', asm_out_file); | |
508 | } | |
509 | ||
510 | /* Write out the difference of two labels, LABEL - BASE, as the value | |
511 | of a stab. */ | |
512 | void | |
513 | dbxout_stab_value_label_diff (const char *label, const char *base) | |
514 | { | |
515 | assemble_name (asm_out_file, label); | |
516 | putc ('-', asm_out_file); | |
517 | assemble_name (asm_out_file, base); | |
518 | putc ('\n', asm_out_file); | |
519 | } | |
520 | ||
521 | /* Write out an internal label as the value of a stab, and immediately | |
522 | emit that internal label. This should be used only when | |
523 | dbxout_stabd will not work. STEM is the name stem of the label, | |
524 | COUNTERP is a pointer to a counter variable which will be used to | |
525 | guarantee label uniqueness. */ | |
526 | void | |
527 | dbxout_stab_value_internal_label (const char *stem, int *counterp) | |
528 | { | |
529 | char label[100]; | |
530 | int counter = counterp ? (*counterp)++ : 0; | |
531 | ||
532 | ASM_GENERATE_INTERNAL_LABEL (label, stem, counter); | |
533 | dbxout_stab_value_label (label); | |
534 | targetm.asm_out.internal_label (asm_out_file, stem, counter); | |
535 | } | |
536 | ||
537 | /* Write out the difference between BASE and an internal label as the | |
538 | value of a stab, and immediately emit that internal label. STEM and | |
539 | COUNTERP are as for dbxout_stab_value_internal_label. */ | |
540 | void | |
541 | dbxout_stab_value_internal_label_diff (const char *stem, int *counterp, | |
542 | const char *base) | |
543 | { | |
544 | char label[100]; | |
545 | int counter = counterp ? (*counterp)++ : 0; | |
546 | ||
547 | ASM_GENERATE_INTERNAL_LABEL (label, stem, counter); | |
548 | dbxout_stab_value_label_diff (label, base); | |
549 | targetm.asm_out.internal_label (asm_out_file, stem, counter); | |
550 | } | |
551 | ||
552 | /* The following functions produce specific kinds of stab directives. */ | |
553 | ||
554 | /* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file. */ | |
555 | void | |
556 | dbxout_stabd (int stype, int sdesc) | |
557 | { | |
558 | fputs (ASM_STABD_OP, asm_out_file); | |
559 | dbxout_int (stype); | |
560 | fputs (",0,", asm_out_file); | |
561 | dbxout_int (sdesc); | |
562 | putc ('\n', asm_out_file); | |
563 | } | |
564 | ||
565 | /* Write a .stabn directive with type STYPE. This function stops | |
566 | short of emitting the value field, which is the responsibility of | |
567 | the caller (normally it will be either a symbol or the difference | |
568 | of two symbols). */ | |
569 | ||
570 | void | |
571 | dbxout_begin_stabn (int stype) | |
572 | { | |
573 | fputs (ASM_STABN_OP, asm_out_file); | |
574 | dbxout_int (stype); | |
575 | fputs (",0,0,", asm_out_file); | |
576 | } | |
577 | ||
578 | /* Write a .stabn directive with type N_SLINE and desc LINE. As above, | |
579 | the value field is the responsibility of the caller. */ | |
580 | void | |
581 | dbxout_begin_stabn_sline (int lineno) | |
582 | { | |
583 | fputs (ASM_STABN_OP, asm_out_file); | |
584 | dbxout_int (N_SLINE); | |
585 | fputs (",0,", asm_out_file); | |
586 | dbxout_int (lineno); | |
587 | putc (',', asm_out_file); | |
588 | } | |
589 | ||
590 | /* Begin a .stabs directive with string "", type STYPE, and desc and | |
591 | other fields 0. The value field is the responsibility of the | |
592 | caller. This function cannot be used for .stabx directives. */ | |
593 | void | |
594 | dbxout_begin_empty_stabs (int stype) | |
595 | { | |
596 | fputs (ASM_STABS_OP, asm_out_file); | |
597 | fputs ("\"\",", asm_out_file); | |
598 | dbxout_int (stype); | |
599 | fputs (",0,0,", asm_out_file); | |
600 | } | |
601 | ||
602 | /* Begin a .stabs directive with string STR, type STYPE, and desc 0. | |
603 | The value field is the responsibility of the caller. */ | |
604 | void | |
605 | dbxout_begin_simple_stabs (const char *str, int stype) | |
606 | { | |
607 | fputs (ASM_STABS_OP, asm_out_file); | |
608 | output_quoted_string (asm_out_file, str); | |
609 | putc (',', asm_out_file); | |
610 | dbxout_int (stype); | |
611 | fputs (",0,0,", asm_out_file); | |
612 | } | |
613 | ||
614 | /* As above but use SDESC for the desc field. */ | |
615 | void | |
616 | dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc) | |
617 | { | |
618 | fputs (ASM_STABS_OP, asm_out_file); | |
619 | output_quoted_string (asm_out_file, str); | |
620 | putc (',', asm_out_file); | |
621 | dbxout_int (stype); | |
622 | fputs (",0,", asm_out_file); | |
623 | dbxout_int (sdesc); | |
624 | putc (',', asm_out_file); | |
625 | } | |
626 | ||
627 | /* The next set of functions are entirely concerned with production of | |
628 | "complex" .stabs directives: that is, .stabs directives whose | |
629 | strings have to be constructed piecemeal. dbxout_type, | |
630 | dbxout_symbol, etc. use these routines heavily. The string is queued | |
631 | up in an obstack, then written out by dbxout_finish_complex_stabs, which | |
632 | is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH. | |
633 | (You might think it would be more efficient to go straight to stdio | |
634 | when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns | |
635 | out not to be the case, and anyway this needs fewer #ifdefs.) */ | |
636 | ||
637 | /* Begin a complex .stabs directive. If we can, write the initial | |
638 | ASM_STABS_OP to the asm_out_file. */ | |
639 | ||
640 | static void | |
641 | dbxout_begin_complex_stabs (void) | |
642 | { | |
643 | emit_pending_bincls_if_required (); | |
644 | FORCE_TEXT; | |
645 | fputs (ASM_STABS_OP, asm_out_file); | |
646 | putc ('"', asm_out_file); | |
647 | gcc_assert (stabstr_last_contin_point == 0); | |
648 | } | |
649 | ||
859ee18f ZW |
650 | /* As above, but do not force text or emit pending bincls. This is |
651 | used by dbxout_symbol_location, which needs to do something else. */ | |
652 | static void | |
653 | dbxout_begin_complex_stabs_noforcetext (void) | |
654 | { | |
655 | fputs (ASM_STABS_OP, asm_out_file); | |
656 | putc ('"', asm_out_file); | |
657 | gcc_assert (stabstr_last_contin_point == 0); | |
658 | } | |
659 | ||
93a27b7b ZW |
660 | /* Add CHR, a single character, to the string being built. */ |
661 | #define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr) | |
662 | ||
663 | /* Add STR, a normal C string, to the string being built. */ | |
c3284718 | 664 | #define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen (str)) |
93a27b7b ZW |
665 | |
666 | /* Add the text of ID, an IDENTIFIER_NODE, to the string being built. */ | |
667 | #define stabstr_I(id) obstack_grow (&stabstr_ob, \ | |
668 | IDENTIFIER_POINTER (id), \ | |
669 | IDENTIFIER_LENGTH (id)) | |
670 | ||
671 | /* Add NUM, a signed decimal number, to the string being built. */ | |
672 | static void | |
673 | stabstr_D (HOST_WIDE_INT num) | |
674 | { | |
675 | char buf[64]; | |
676 | char *p = buf + sizeof buf; | |
b5872261 | 677 | unsigned HOST_WIDE_INT unum; |
93a27b7b ZW |
678 | |
679 | if (num == 0) | |
680 | { | |
681 | stabstr_C ('0'); | |
682 | return; | |
683 | } | |
684 | if (num < 0) | |
685 | { | |
686 | stabstr_C ('-'); | |
b5872261 | 687 | unum = -(unsigned HOST_WIDE_INT) num; |
93a27b7b ZW |
688 | } |
689 | else | |
690 | unum = num; | |
691 | ||
692 | NUMBER_FMT_LOOP (p, unum, 10); | |
693 | ||
694 | obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p); | |
695 | } | |
696 | ||
697 | /* Add NUM, an unsigned decimal number, to the string being built. */ | |
698 | static void | |
699 | stabstr_U (unsigned HOST_WIDE_INT num) | |
700 | { | |
701 | char buf[64]; | |
702 | char *p = buf + sizeof buf; | |
703 | if (num == 0) | |
704 | { | |
705 | stabstr_C ('0'); | |
706 | return; | |
707 | } | |
708 | NUMBER_FMT_LOOP (p, num, 10); | |
709 | obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p); | |
710 | } | |
711 | ||
712 | /* Add CST, an INTEGER_CST tree, to the string being built as an | |
713 | unsigned octal number. This routine handles values which are | |
714 | larger than a single HOST_WIDE_INT. */ | |
715 | static void | |
716 | stabstr_O (tree cst) | |
717 | { | |
807e902e KZ |
718 | int prec = TYPE_PRECISION (TREE_TYPE (cst)); |
719 | int res_pres = prec % 3; | |
720 | int i; | |
721 | unsigned int digit; | |
93a27b7b ZW |
722 | |
723 | /* Leading zero for base indicator. */ | |
724 | stabstr_C ('0'); | |
725 | ||
726 | /* If the value is zero, the base indicator will serve as the value | |
727 | all by itself. */ | |
8e6cdc90 | 728 | if (wi::to_wide (cst) == 0) |
93a27b7b ZW |
729 | return; |
730 | ||
807e902e KZ |
731 | /* GDB wants constants with no extra leading "1" bits, so |
732 | we need to remove any sign-extension that might be | |
733 | present. */ | |
734 | if (res_pres == 1) | |
93a27b7b | 735 | { |
8e6cdc90 | 736 | digit = wi::extract_uhwi (wi::to_wide (cst), prec - 1, 1); |
807e902e KZ |
737 | stabstr_C ('0' + digit); |
738 | } | |
739 | else if (res_pres == 2) | |
740 | { | |
8e6cdc90 | 741 | digit = wi::extract_uhwi (wi::to_wide (cst), prec - 2, 2); |
807e902e | 742 | stabstr_C ('0' + digit); |
93a27b7b ZW |
743 | } |
744 | ||
807e902e KZ |
745 | prec -= res_pres; |
746 | for (i = prec - 3; i >= 0; i = i - 3) | |
747 | { | |
8e6cdc90 | 748 | digit = wi::extract_uhwi (wi::to_wide (cst), i, 3); |
807e902e KZ |
749 | stabstr_C ('0' + digit); |
750 | } | |
93a27b7b ZW |
751 | } |
752 | ||
753 | /* Called whenever it is safe to break a stabs string into multiple | |
754 | .stabs directives. If the current string has exceeded the limit | |
755 | set by DBX_CONTIN_LENGTH, mark the current position in the buffer | |
756 | as a continuation point by inserting DBX_CONTIN_CHAR (doubled if | |
757 | it is a backslash) and a null character. */ | |
758 | static inline void | |
759 | stabstr_continue (void) | |
760 | { | |
761 | if (DBX_CONTIN_LENGTH > 0 | |
762 | && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point | |
763 | > DBX_CONTIN_LENGTH) | |
764 | { | |
765 | if (DBX_CONTIN_CHAR == '\\') | |
766 | obstack_1grow (&stabstr_ob, '\\'); | |
767 | obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR); | |
768 | obstack_1grow (&stabstr_ob, '\0'); | |
769 | stabstr_last_contin_point = obstack_object_size (&stabstr_ob); | |
770 | } | |
771 | } | |
772 | #define CONTIN stabstr_continue () | |
773 | ||
774 | /* Macro subroutine of dbxout_finish_complex_stabs, which emits | |
775 | all of the arguments to the .stabs directive after the string. | |
776 | Overridden by xcoffout.h. CODE is the stabs code for this symbol; | |
777 | LINE is the source line to write into the desc field (in extended | |
859ee18f | 778 | mode); SYM is the symbol itself. |
93a27b7b ZW |
779 | |
780 | ADDR, LABEL, and NUMBER are three different ways to represent the | |
781 | stabs value field. At most one of these should be nonzero. | |
782 | ||
783 | ADDR is used most of the time; it represents the value as an | |
784 | RTL address constant. | |
785 | ||
786 | LABEL is used (currently) only for N_CATCH stabs; it represents | |
787 | the value as a string suitable for assemble_name. | |
788 | ||
789 | NUMBER is used when the value is an offset from an implicit base | |
790 | pointer (e.g. for a stack variable), or an index (e.g. for a | |
791 | register variable). It represents the value as a decimal integer. */ | |
792 | ||
793 | #ifndef DBX_FINISH_STABS | |
859ee18f ZW |
794 | #define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER) \ |
795 | do { \ | |
93a27b7b ZW |
796 | int line_ = use_gnu_debug_info_extensions ? LINE : 0; \ |
797 | \ | |
798 | dbxout_int (CODE); \ | |
799 | fputs (",0,", asm_out_file); \ | |
800 | dbxout_int (line_); \ | |
801 | putc (',', asm_out_file); \ | |
802 | if (ADDR) \ | |
803 | output_addr_const (asm_out_file, ADDR); \ | |
804 | else if (LABEL) \ | |
805 | assemble_name (asm_out_file, LABEL); \ | |
806 | else \ | |
807 | dbxout_int (NUMBER); \ | |
808 | putc ('\n', asm_out_file); \ | |
809 | } while (0) | |
810 | #endif | |
811 | ||
812 | /* Finish the emission of a complex .stabs directive. When DBX_CONTIN_LENGTH | |
813 | is zero, this has only to emit the close quote and the remainder of | |
814 | the arguments. When it is nonzero, the string has been marshalled in | |
815 | stabstr_ob, and this routine is responsible for breaking it up into | |
816 | DBX_CONTIN_LENGTH-sized chunks. | |
817 | ||
818 | SYM is the DECL of the symbol under consideration; it is used only | |
819 | for its DECL_SOURCE_LINE. The other arguments are all passed directly | |
820 | to DBX_FINISH_STABS; see above for details. */ | |
b8698a0f | 821 | |
93a27b7b | 822 | static void |
dbb6088f | 823 | dbxout_finish_complex_stabs (tree sym, stab_code_type code, |
93a27b7b ZW |
824 | rtx addr, const char *label, int number) |
825 | { | |
12126025 | 826 | int line ATTRIBUTE_UNUSED; |
93a27b7b ZW |
827 | char *str; |
828 | size_t len; | |
829 | ||
12126025 | 830 | line = sym ? DECL_SOURCE_LINE (sym) : 0; |
93a27b7b ZW |
831 | if (DBX_CONTIN_LENGTH > 0) |
832 | { | |
833 | char *chunk; | |
834 | size_t chunklen; | |
835 | ||
836 | /* Nul-terminate the growing string, then get its size and | |
837 | address. */ | |
838 | obstack_1grow (&stabstr_ob, '\0'); | |
839 | ||
840 | len = obstack_object_size (&stabstr_ob); | |
7973fd2a | 841 | chunk = str = XOBFINISH (&stabstr_ob, char *); |
93a27b7b ZW |
842 | |
843 | /* Within the buffer are a sequence of NUL-separated strings, | |
844 | each of which is to be written out as a separate stab | |
845 | directive. */ | |
846 | for (;;) | |
847 | { | |
848 | chunklen = strlen (chunk); | |
849 | fwrite (chunk, 1, chunklen, asm_out_file); | |
850 | fputs ("\",", asm_out_file); | |
851 | ||
852 | /* Must add an extra byte to account for the NUL separator. */ | |
853 | chunk += chunklen + 1; | |
854 | len -= chunklen + 1; | |
855 | ||
856 | /* Only put a line number on the last stab in the sequence. */ | |
859ee18f ZW |
857 | DBX_FINISH_STABS (sym, code, len == 0 ? line : 0, |
858 | addr, label, number); | |
93a27b7b ZW |
859 | if (len == 0) |
860 | break; | |
861 | ||
862 | fputs (ASM_STABS_OP, asm_out_file); | |
863 | putc ('"', asm_out_file); | |
864 | } | |
865 | stabstr_last_contin_point = 0; | |
866 | } | |
867 | else | |
868 | { | |
869 | /* No continuations - we can put the whole string out at once. | |
870 | It is faster to augment the string with the close quote and | |
871 | comma than to do a two-character fputs. */ | |
872 | obstack_grow (&stabstr_ob, "\",", 2); | |
873 | len = obstack_object_size (&stabstr_ob); | |
7973fd2a | 874 | str = XOBFINISH (&stabstr_ob, char *); |
b8698a0f | 875 | |
93a27b7b | 876 | fwrite (str, 1, len, asm_out_file); |
859ee18f | 877 | DBX_FINISH_STABS (sym, code, line, addr, label, number); |
93a27b7b ZW |
878 | } |
879 | obstack_free (&stabstr_ob, str); | |
880 | } | |
881 | ||
96621ebf | 882 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
93a27b7b | 883 | |
f55dfa2f NF |
884 | /* When -gused is used, emit debug info for only used symbols. But in |
885 | addition to the standard intercepted debug_hooks there are some | |
886 | direct calls into this file, i.e., dbxout_symbol, dbxout_parms, and | |
887 | dbxout_reg_params. Those routines may also be called from a higher | |
888 | level intercepted routine. So to prevent recording data for an inner | |
889 | call to one of these for an intercept, we maintain an intercept | |
890 | nesting counter (debug_nesting). We only save the intercepted | |
891 | arguments if the nesting is 1. */ | |
892 | static int debug_nesting = 0; | |
893 | ||
894 | static tree *symbol_queue; | |
895 | static int symbol_queue_index = 0; | |
896 | static int symbol_queue_size = 0; | |
897 | ||
898 | #define DBXOUT_DECR_NESTING \ | |
899 | if (--debug_nesting == 0 && symbol_queue_index > 0) \ | |
900 | { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); } | |
901 | ||
902 | #define DBXOUT_DECR_NESTING_AND_RETURN(x) \ | |
903 | do {--debug_nesting; return (x);} while (0) | |
904 | ||
96621ebf TG |
905 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ |
906 | ||
907 | #if defined (DBX_DEBUGGING_INFO) | |
908 | ||
cf440348 | 909 | static void |
725730f2 | 910 | dbxout_function_end (tree decl ATTRIBUTE_UNUSED) |
cf440348 JL |
911 | { |
912 | char lscope_label_name[100]; | |
750054a2 | 913 | |
403f8503 ZW |
914 | /* The Lscope label must be emitted even if we aren't doing anything |
915 | else; dbxout_block needs it. */ | |
b8cb3096 | 916 | switch_to_section (current_function_section ()); |
b8698a0f | 917 | |
93a27b7b | 918 | /* Convert Lscope into the appropriate format for local labels in case |
cf440348 JL |
919 | the system doesn't insert underscores in front of user generated |
920 | labels. */ | |
e098f3a5 CD |
921 | ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno); |
922 | targetm.asm_out.internal_label (asm_out_file, "Lscope", scope_labelno); | |
cf440348 | 923 | |
4a22dcdd UW |
924 | /* The N_FUN tag at the end of the function is a GNU extension, |
925 | which may be undesirable, and is unnecessary if we do not have | |
926 | named sections. */ | |
927 | if (!use_gnu_debug_info_extensions | |
928 | || NO_DBX_FUNCTION_END | |
677f3fa8 | 929 | || !targetm_common.have_named_sections) |
4a22dcdd UW |
930 | return; |
931 | ||
cf440348 JL |
932 | /* By convention, GCC will mark the end of a function with an N_FUN |
933 | symbol and an empty string. */ | |
0b6bc904 | 934 | if (crtl->has_bb_partition) |
87c8b4be CT |
935 | { |
936 | dbxout_begin_empty_stabs (N_FUN); | |
b8cb3096 JJ |
937 | if (in_cold_section_p) |
938 | dbxout_stab_value_label_diff (crtl->subsections.cold_section_end_label, | |
939 | crtl->subsections.cold_section_label); | |
940 | else | |
941 | dbxout_stab_value_label_diff (crtl->subsections.hot_section_end_label, | |
942 | crtl->subsections.hot_section_label); | |
87c8b4be CT |
943 | } |
944 | else | |
945 | { | |
03471b3f CD |
946 | char begin_label[20]; |
947 | /* Reference current function start using LFBB. */ | |
e098f3a5 | 948 | ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno); |
87c8b4be | 949 | dbxout_begin_empty_stabs (N_FUN); |
03471b3f | 950 | dbxout_stab_value_label_diff (lscope_label_name, begin_label); |
87c8b4be | 951 | } |
8fa5469d | 952 | |
5d865dac | 953 | if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols) |
93a27b7b | 954 | dbxout_stabd (N_ENSYM, 0); |
cf440348 | 955 | } |
c3fb23f4 | 956 | #endif /* DBX_DEBUGGING_INFO */ |
cf440348 | 957 | |
0456cbf6 | 958 | /* Get lang description for N_SO stab. */ |
93a27b7b | 959 | static unsigned int ATTRIBUTE_UNUSED |
0456cbf6 DP |
960 | get_lang_number (void) |
961 | { | |
962 | const char *language_string = lang_hooks.name; | |
dcc97066 | 963 | if (lang_GNU_C ()) |
0456cbf6 | 964 | return N_SO_C; |
dcc97066 | 965 | else if (lang_GNU_CXX ()) |
0456cbf6 DP |
966 | return N_SO_CC; |
967 | else if (strcmp (language_string, "GNU F77") == 0) | |
968 | return N_SO_FORTRAN; | |
de3aebff | 969 | else if (lang_GNU_Fortran ()) |
0456cbf6 | 970 | return N_SO_FORTRAN90; /* CHECKME */ |
0456cbf6 DP |
971 | else if (strcmp (language_string, "GNU Objective-C") == 0) |
972 | return N_SO_OBJC; | |
6e955430 ZL |
973 | else if (strcmp (language_string, "GNU Objective-C++") == 0) |
974 | return N_SO_OBJCPLUS; | |
0456cbf6 DP |
975 | else |
976 | return 0; | |
977 | ||
978 | } | |
979 | ||
7151ffbe GH |
980 | static bool |
981 | is_fortran (void) | |
982 | { | |
983 | unsigned int lang = get_lang_number (); | |
984 | ||
985 | return (lang == N_SO_FORTRAN) || (lang == N_SO_FORTRAN90); | |
986 | } | |
987 | ||
00fe048c RS |
988 | /* At the beginning of compilation, start writing the symbol table. |
989 | Initialize `typevec' and output the standard data types of C. */ | |
990 | ||
a51d908e | 991 | static void |
7080f735 | 992 | dbxout_init (const char *input_file_name) |
00fe048c RS |
993 | { |
994 | char ltext_label_name[100]; | |
93a27b7b | 995 | bool used_ltext_label_name = false; |
ae2bcd98 | 996 | tree syms = lang_hooks.decls.getdecls (); |
c8aea42c | 997 | const char *mapped_name; |
00fe048c | 998 | |
00fe048c | 999 | typevec_len = 100; |
766090c2 | 1000 | typevec = ggc_cleared_vec_alloc<typeinfo> (typevec_len); |
00fe048c | 1001 | |
93a27b7b ZW |
1002 | /* stabstr_ob contains one string, which will be just fine with |
1003 | 1-byte alignment. */ | |
1004 | obstack_specify_allocation (&stabstr_ob, 0, 1, xmalloc, free); | |
1005 | ||
00fe048c RS |
1006 | /* Convert Ltext into the appropriate format for local labels in case |
1007 | the system doesn't insert underscores in front of user generated | |
1008 | labels. */ | |
1009 | ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0); | |
1010 | ||
1011 | /* Put the current working directory in an N_SO symbol. */ | |
93a27b7b | 1012 | if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY) |
b372168c | 1013 | { |
ac746f1d ZW |
1014 | static const char *cwd; |
1015 | ||
1016 | if (!cwd) | |
b372168c | 1017 | { |
ac746f1d ZW |
1018 | cwd = get_src_pwd (); |
1019 | if (cwd[0] == '\0') | |
1020 | cwd = "/"; | |
1021 | else if (!IS_DIR_SEPARATOR (cwd[strlen (cwd) - 1])) | |
1022 | cwd = concat (cwd, "/", NULL); | |
c8aea42c | 1023 | cwd = remap_debug_filename (cwd); |
ac746f1d | 1024 | } |
00fe048c | 1025 | #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY |
ac746f1d | 1026 | DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asm_out_file, cwd); |
00fe048c | 1027 | #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */ |
93a27b7b ZW |
1028 | dbxout_begin_simple_stabs_desc (cwd, N_SO, get_lang_number ()); |
1029 | dbxout_stab_value_label (ltext_label_name); | |
1030 | used_ltext_label_name = true; | |
00fe048c | 1031 | #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */ |
b372168c | 1032 | } |
00fe048c | 1033 | |
c8aea42c | 1034 | mapped_name = remap_debug_filename (input_file_name); |
00fe048c | 1035 | #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME |
c8aea42c | 1036 | DBX_OUTPUT_MAIN_SOURCE_FILENAME (asm_out_file, mapped_name); |
ad087b92 | 1037 | #else |
c8aea42c | 1038 | dbxout_begin_simple_stabs_desc (mapped_name, N_SO, get_lang_number ()); |
93a27b7b ZW |
1039 | dbxout_stab_value_label (ltext_label_name); |
1040 | used_ltext_label_name = true; | |
1041 | #endif | |
1042 | ||
1043 | if (used_ltext_label_name) | |
1044 | { | |
d6b5193b | 1045 | switch_to_section (text_section); |
93a27b7b ZW |
1046 | targetm.asm_out.internal_label (asm_out_file, "Ltext", 0); |
1047 | } | |
1048 | ||
ac746f1d ZW |
1049 | /* Emit an N_OPT stab to indicate that this file was compiled by GCC. |
1050 | The string used is historical. */ | |
93a27b7b ZW |
1051 | #ifndef NO_DBX_GCC_MARKER |
1052 | dbxout_begin_simple_stabs ("gcc2_compiled.", N_OPT); | |
1053 | dbxout_stab_value_zero (); | |
ad087b92 | 1054 | #endif |
01571284 | 1055 | |
33b49800 | 1056 | base_input_file = lastfile = input_file_name; |
00fe048c RS |
1057 | |
1058 | next_type_number = 1; | |
00fe048c | 1059 | |
4bcaafd9 | 1060 | #ifdef DBX_USE_BINCL |
5ed6ace5 | 1061 | current_file = XNEW (struct dbx_file); |
4bcaafd9 ILT |
1062 | current_file->next = NULL; |
1063 | current_file->file_number = 0; | |
1064 | current_file->next_type_number = 1; | |
1065 | next_file_number = 1; | |
33e9d2aa DP |
1066 | current_file->prev = NULL; |
1067 | current_file->bincl_status = BINCL_NOT_REQUIRED; | |
1068 | current_file->pending_bincl_name = NULL; | |
4bcaafd9 ILT |
1069 | #endif |
1070 | ||
47aa0df4 MM |
1071 | /* Get all permanent types that have typedef names, and output them |
1072 | all, except for those already output. Some language front ends | |
21d13d83 ZW |
1073 | put these declarations in the top-level scope; some do not; |
1074 | the latter are responsible for calling debug_hooks->type_decl from | |
1075 | their record_builtin_type function. */ | |
00fe048c | 1076 | dbxout_typedefs (syms); |
21d13d83 ZW |
1077 | |
1078 | if (preinit_symbols) | |
1079 | { | |
1080 | tree t; | |
1081 | for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t)) | |
1082 | dbxout_symbol (TREE_VALUE (t), 0); | |
1083 | preinit_symbols = 0; | |
1084 | } | |
00fe048c RS |
1085 | } |
1086 | ||
0ee55ad8 | 1087 | /* Output any typedef names for types described by TYPE_DECLs in SYMS. */ |
00fe048c RS |
1088 | |
1089 | static void | |
7080f735 | 1090 | dbxout_typedefs (tree syms) |
00fe048c | 1091 | { |
910ad8de | 1092 | for (; syms != NULL_TREE; syms = DECL_CHAIN (syms)) |
00fe048c | 1093 | { |
00fe048c RS |
1094 | if (TREE_CODE (syms) == TYPE_DECL) |
1095 | { | |
1096 | tree type = TREE_TYPE (syms); | |
1097 | if (TYPE_NAME (type) | |
1098 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
a354c7d6 | 1099 | && COMPLETE_OR_VOID_TYPE_P (type) |
00fe048c RS |
1100 | && ! TREE_ASM_WRITTEN (TYPE_NAME (type))) |
1101 | dbxout_symbol (TYPE_NAME (type), 0); | |
1102 | } | |
1103 | } | |
1104 | } | |
1105 | ||
f23b9d52 | 1106 | #ifdef DBX_USE_BINCL |
4ed43216 | 1107 | /* Emit BINCL stab using given name. */ |
33e9d2aa DP |
1108 | static void |
1109 | emit_bincl_stab (const char *name) | |
1110 | { | |
93a27b7b ZW |
1111 | dbxout_begin_simple_stabs (name, N_BINCL); |
1112 | dbxout_stab_value_zero (); | |
33e9d2aa DP |
1113 | } |
1114 | ||
1115 | /* If there are pending bincls then it is time to emit all of them. */ | |
1116 | ||
1117 | static inline void | |
7e51717c | 1118 | emit_pending_bincls_if_required (void) |
33e9d2aa | 1119 | { |
33e9d2aa DP |
1120 | if (pending_bincls) |
1121 | emit_pending_bincls (); | |
33e9d2aa DP |
1122 | } |
1123 | ||
1124 | /* Emit all pending bincls. */ | |
1125 | ||
1126 | static void | |
7e51717c | 1127 | emit_pending_bincls (void) |
33e9d2aa DP |
1128 | { |
1129 | struct dbx_file *f = current_file; | |
1130 | ||
1131 | /* Find first pending bincl. */ | |
1132 | while (f->bincl_status == BINCL_PENDING) | |
1133 | f = f->next; | |
1134 | ||
1135 | /* Now emit all bincls. */ | |
1136 | f = f->prev; | |
1137 | ||
1138 | while (f) | |
1139 | { | |
1140 | if (f->bincl_status == BINCL_PENDING) | |
1141 | { | |
1142 | emit_bincl_stab (f->pending_bincl_name); | |
1143 | ||
1144 | /* Update file number and status. */ | |
1145 | f->file_number = next_file_number++; | |
1146 | f->bincl_status = BINCL_PROCESSED; | |
1147 | } | |
1148 | if (f == current_file) | |
1149 | break; | |
1150 | f = f->prev; | |
1151 | } | |
1152 | ||
1153 | /* All pending bincls have been emitted. */ | |
1154 | pending_bincls = 0; | |
1155 | } | |
1156 | ||
f23b9d52 DE |
1157 | #else |
1158 | ||
1159 | static inline void | |
7e51717c | 1160 | emit_pending_bincls_if_required (void) {} |
f23b9d52 DE |
1161 | #endif |
1162 | ||
4bcaafd9 ILT |
1163 | /* Change to reading from a new source file. Generate a N_BINCL stab. */ |
1164 | ||
7f905405 | 1165 | static void |
7080f735 AJ |
1166 | dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED, |
1167 | const char *filename ATTRIBUTE_UNUSED) | |
4bcaafd9 ILT |
1168 | { |
1169 | #ifdef DBX_USE_BINCL | |
5ed6ace5 | 1170 | struct dbx_file *n = XNEW (struct dbx_file); |
4bcaafd9 ILT |
1171 | |
1172 | n->next = current_file; | |
4bcaafd9 | 1173 | n->next_type_number = 1; |
b8698a0f | 1174 | /* Do not assign file number now. |
33e9d2aa DP |
1175 | Delay it until we actually emit BINCL. */ |
1176 | n->file_number = 0; | |
1177 | n->prev = NULL; | |
1178 | current_file->prev = n; | |
1179 | n->bincl_status = BINCL_PENDING; | |
c8aea42c | 1180 | n->pending_bincl_name = remap_debug_filename (filename); |
33e9d2aa | 1181 | pending_bincls = 1; |
4bcaafd9 | 1182 | current_file = n; |
4bcaafd9 ILT |
1183 | #endif |
1184 | } | |
1185 | ||
1186 | /* Revert to reading a previous source file. Generate a N_EINCL stab. */ | |
1187 | ||
7f905405 | 1188 | static void |
7080f735 | 1189 | dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED) |
4bcaafd9 ILT |
1190 | { |
1191 | #ifdef DBX_USE_BINCL | |
33e9d2aa DP |
1192 | /* Emit EINCL stab only if BINCL is not pending. */ |
1193 | if (current_file->bincl_status == BINCL_PROCESSED) | |
93a27b7b ZW |
1194 | { |
1195 | dbxout_begin_stabn (N_EINCL); | |
1196 | dbxout_stab_value_zero (); | |
1197 | } | |
33e9d2aa | 1198 | current_file->bincl_status = BINCL_NOT_REQUIRED; |
17211ab5 | 1199 | current_file = current_file->next; |
4bcaafd9 ILT |
1200 | #endif |
1201 | } | |
1202 | ||
33b49800 GK |
1203 | /* Handle a few odd cases that occur when trying to make PCH files work. */ |
1204 | ||
1205 | static void | |
1206 | dbxout_handle_pch (unsigned at_end) | |
1207 | { | |
1208 | if (! at_end) | |
1209 | { | |
1210 | /* When using the PCH, this file will be included, so we need to output | |
1211 | a BINCL. */ | |
1212 | dbxout_start_source_file (0, lastfile); | |
1213 | ||
1214 | /* The base file when using the PCH won't be the same as | |
1215 | the base file when it's being generated. */ | |
1216 | lastfile = NULL; | |
1217 | } | |
1218 | else | |
1219 | { | |
71c0e7fc | 1220 | /* ... and an EINCL. */ |
33b49800 GK |
1221 | dbxout_end_source_file (0); |
1222 | ||
1223 | /* Deal with cases where 'lastfile' was never actually changed. */ | |
1224 | lastfile_is_base = lastfile == NULL; | |
1225 | } | |
1226 | } | |
1227 | ||
c3fb23f4 | 1228 | #if defined (DBX_DEBUGGING_INFO) |
b420396f | 1229 | |
b8cb3096 | 1230 | static bool dbxout_block (tree, int, tree, int); |
b420396f | 1231 | |
00fe048c RS |
1232 | /* Output debugging info to FILE to switch to sourcefile FILENAME. */ |
1233 | ||
e1772ac0 | 1234 | static void |
93a27b7b | 1235 | dbxout_source_file (const char *filename) |
00fe048c | 1236 | { |
33b49800 GK |
1237 | if (lastfile == 0 && lastfile_is_base) |
1238 | { | |
1239 | lastfile = base_input_file; | |
1240 | lastfile_is_base = 0; | |
1241 | } | |
1242 | ||
00fe048c RS |
1243 | if (filename && (lastfile == 0 || strcmp (filename, lastfile))) |
1244 | { | |
93a27b7b ZW |
1245 | /* Don't change section amid function. */ |
1246 | if (current_function_decl == NULL_TREE) | |
d6b5193b | 1247 | switch_to_section (text_section); |
93a27b7b | 1248 | |
c8aea42c | 1249 | dbxout_begin_simple_stabs (remap_debug_filename (filename), N_SOL); |
93a27b7b | 1250 | dbxout_stab_value_internal_label ("Ltext", &source_label_number); |
00fe048c RS |
1251 | lastfile = filename; |
1252 | } | |
1253 | } | |
1254 | ||
b8698a0f | 1255 | /* Output N_BNSYM, line number symbol entry, and local symbol at |
03471b3f | 1256 | function scope */ |
8fa5469d DP |
1257 | |
1258 | static void | |
497b7c47 JJ |
1259 | dbxout_begin_prologue (unsigned int lineno, |
1260 | unsigned int column ATTRIBUTE_UNUSED, | |
1261 | const char *filename) | |
8fa5469d | 1262 | { |
8768c655 RH |
1263 | if (use_gnu_debug_info_extensions |
1264 | && !NO_DBX_FUNCTION_END | |
5d865dac | 1265 | && !NO_DBX_BNSYM_ENSYM |
8768c655 | 1266 | && !flag_debug_only_used_symbols) |
93a27b7b | 1267 | dbxout_stabd (N_BNSYM, 0); |
8fa5469d | 1268 | |
e098f3a5 CD |
1269 | /* pre-increment the scope counter */ |
1270 | scope_labelno++; | |
1271 | ||
497b7c47 | 1272 | dbxout_source_line (lineno, 0, filename, 0, true); |
b8698a0f | 1273 | /* Output function begin block at function scope, referenced |
03471b3f CD |
1274 | by dbxout_block, dbxout_source_line and dbxout_function_end. */ |
1275 | emit_pending_bincls_if_required (); | |
1276 | targetm.asm_out.internal_label (asm_out_file, "LFBB", scope_labelno); | |
8fa5469d DP |
1277 | } |
1278 | ||
653e276c NB |
1279 | /* Output a line number symbol entry for source file FILENAME and line |
1280 | number LINENO. */ | |
674c724c | 1281 | |
e2a12aca | 1282 | static void |
497b7c47 JJ |
1283 | dbxout_source_line (unsigned int lineno, unsigned int column ATTRIBUTE_UNUSED, |
1284 | const char *filename, int discriminator ATTRIBUTE_UNUSED, | |
ed5ef2e4 | 1285 | bool is_stmt ATTRIBUTE_UNUSED) |
674c724c | 1286 | { |
93a27b7b | 1287 | dbxout_source_file (filename); |
674c724c | 1288 | |
3e487b21 | 1289 | #ifdef DBX_OUTPUT_SOURCE_LINE |
3e487b21 | 1290 | DBX_OUTPUT_SOURCE_LINE (asm_out_file, lineno, dbxout_source_line_counter); |
674c724c | 1291 | #else |
3e487b21 ZW |
1292 | if (DBX_LINES_FUNCTION_RELATIVE) |
1293 | { | |
03471b3f | 1294 | char begin_label[20]; |
93a27b7b | 1295 | dbxout_begin_stabn_sline (lineno); |
03471b3f | 1296 | /* Reference current function start using LFBB. */ |
b8698a0f | 1297 | ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno); |
93a27b7b | 1298 | dbxout_stab_value_internal_label_diff ("LM", &dbxout_source_line_counter, |
03471b3f | 1299 | begin_label); |
3e487b21 ZW |
1300 | } |
1301 | else | |
93a27b7b | 1302 | dbxout_stabd (N_SLINE, lineno); |
674c724c | 1303 | #endif |
b8cb3096 JJ |
1304 | lastlineno = lineno; |
1305 | } | |
1306 | ||
1307 | /* Unfortunately, at least when emitting relative addresses, STABS | |
1308 | has no way to express multiple partitions. Represent a function | |
1309 | as two functions in this case. */ | |
1310 | ||
1311 | static void | |
1312 | dbxout_switch_text_section (void) | |
1313 | { | |
1314 | /* The N_FUN tag at the end of the function is a GNU extension, | |
1315 | which may be undesirable, and is unnecessary if we do not have | |
1316 | named sections. */ | |
1317 | in_cold_section_p = !in_cold_section_p; | |
1318 | switch_to_section (current_function_section ()); | |
1319 | dbxout_block (DECL_INITIAL (current_function_decl), 0, | |
1320 | DECL_ARGUMENTS (current_function_decl), -1); | |
1321 | dbxout_function_end (current_function_decl); | |
1322 | in_cold_section_p = !in_cold_section_p; | |
1323 | ||
1324 | switch_to_section (current_function_section ()); | |
1325 | ||
1326 | tree context = decl_function_context (current_function_decl); | |
1327 | extern tree cold_function_name; | |
1328 | ||
1329 | dbxout_begin_complex_stabs (); | |
1330 | stabstr_I (cold_function_name); | |
1331 | stabstr_S (":f"); | |
1332 | ||
1333 | tree type = TREE_TYPE (current_function_decl); | |
1334 | if (TREE_TYPE (type)) | |
1335 | dbxout_type (TREE_TYPE (type), 0); | |
1336 | else | |
1337 | dbxout_type (void_type_node, 0); | |
1338 | ||
1339 | if (context != 0) | |
1340 | { | |
1341 | stabstr_C (','); | |
1342 | stabstr_I (cold_function_name); | |
1343 | stabstr_C (','); | |
1344 | stabstr_I (DECL_NAME (context)); | |
1345 | } | |
1346 | ||
1347 | dbxout_finish_complex_stabs (current_function_decl, N_FUN, 0, | |
1348 | crtl->subsections.cold_section_label, 0); | |
1349 | ||
1350 | /* pre-increment the scope counter */ | |
1351 | scope_labelno++; | |
1352 | ||
1353 | dbxout_source_line (lastlineno, 0, lastfile, 0, true); | |
1354 | /* Output function begin block at function scope, referenced | |
1355 | by dbxout_block, dbxout_source_line and dbxout_function_end. */ | |
1356 | emit_pending_bincls_if_required (); | |
1357 | targetm.asm_out.internal_label (asm_out_file, "LFBB", scope_labelno); | |
674c724c RS |
1358 | } |
1359 | ||
a5a42b92 NB |
1360 | /* Describe the beginning of an internal block within a function. */ |
1361 | ||
1362 | static void | |
7080f735 | 1363 | dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n) |
a5a42b92 | 1364 | { |
33e9d2aa | 1365 | emit_pending_bincls_if_required (); |
3e487b21 | 1366 | targetm.asm_out.internal_label (asm_out_file, "LBB", n); |
a5a42b92 NB |
1367 | } |
1368 | ||
1369 | /* Describe the end line-number of an internal block within a function. */ | |
1370 | ||
1371 | static void | |
7080f735 | 1372 | dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n) |
a5a42b92 | 1373 | { |
33e9d2aa | 1374 | emit_pending_bincls_if_required (); |
3e487b21 | 1375 | targetm.asm_out.internal_label (asm_out_file, "LBE", n); |
a5a42b92 NB |
1376 | } |
1377 | ||
2b85879e NB |
1378 | /* Output dbx data for a function definition. |
1379 | This includes a definition of the function name itself (a symbol), | |
1380 | definitions of the parameters (locating them in the parameter list) | |
1381 | and then output the block that makes up the function's body | |
1382 | (including all the auto variables of the function). */ | |
1383 | ||
1384 | static void | |
7080f735 | 1385 | dbxout_function_decl (tree decl) |
2b85879e | 1386 | { |
33e9d2aa | 1387 | emit_pending_bincls_if_required (); |
2b85879e NB |
1388 | #ifndef DBX_FUNCTION_FIRST |
1389 | dbxout_begin_function (decl); | |
1390 | #endif | |
b8cb3096 | 1391 | dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl), -1); |
847d0c08 | 1392 | dbxout_function_end (decl); |
2b85879e NB |
1393 | } |
1394 | ||
a5a42b92 NB |
1395 | #endif /* DBX_DEBUGGING_INFO */ |
1396 | ||
d7438551 AH |
1397 | static void |
1398 | dbxout_early_global_decl (tree decl ATTRIBUTE_UNUSED) | |
1399 | { | |
1400 | /* NYI for non-dwarf. */ | |
1401 | } | |
1402 | ||
e53b6e56 | 1403 | /* Debug information for a global DECL. Called from toplev.cc after |
440aabf8 NB |
1404 | compilation proper has finished. */ |
1405 | static void | |
d7438551 | 1406 | dbxout_late_global_decl (tree decl) |
440aabf8 | 1407 | { |
8813a647 | 1408 | if (VAR_P (decl) && !DECL_EXTERNAL (decl)) |
6a08f7b3 DP |
1409 | { |
1410 | int saved_tree_used = TREE_USED (decl); | |
1411 | TREE_USED (decl) = 1; | |
1412 | dbxout_symbol (decl, 0); | |
1413 | TREE_USED (decl) = saved_tree_used; | |
1414 | } | |
3a538a66 | 1415 | } |
440aabf8 | 1416 | |
21d13d83 ZW |
1417 | /* This is just a function-type adapter; dbxout_symbol does exactly |
1418 | what we want but returns an int. */ | |
1419 | static void | |
1420 | dbxout_type_decl (tree decl, int local) | |
1421 | { | |
1422 | dbxout_symbol (decl, local); | |
1423 | } | |
1424 | ||
00fe048c | 1425 | /* At the end of compilation, finish writing the symbol table. |
3e487b21 | 1426 | The default is to call debug_free_queue but do nothing else. */ |
00fe048c | 1427 | |
a51d908e | 1428 | static void |
7080f735 | 1429 | dbxout_finish (const char *filename ATTRIBUTE_UNUSED) |
00fe048c RS |
1430 | { |
1431 | #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END | |
3e487b21 ZW |
1432 | DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename); |
1433 | #elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END | |
1434 | { | |
d6b5193b | 1435 | switch_to_section (text_section); |
93a27b7b ZW |
1436 | dbxout_begin_empty_stabs (N_SO); |
1437 | dbxout_stab_value_internal_label ("Letext", 0); | |
3e487b21 ZW |
1438 | } |
1439 | #endif | |
6a08f7b3 | 1440 | debug_free_queue (); |
00fe048c RS |
1441 | } |
1442 | ||
4bcaafd9 ILT |
1443 | /* Output the index of a type. */ |
1444 | ||
1445 | static void | |
7080f735 | 1446 | dbxout_type_index (tree type) |
4bcaafd9 ILT |
1447 | { |
1448 | #ifndef DBX_USE_BINCL | |
93a27b7b | 1449 | stabstr_D (TYPE_SYMTAB_ADDRESS (type)); |
4bcaafd9 ILT |
1450 | #else |
1451 | struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)]; | |
93a27b7b ZW |
1452 | stabstr_C ('('); |
1453 | stabstr_D (t->file_number); | |
1454 | stabstr_C (','); | |
1455 | stabstr_D (t->type_number); | |
1456 | stabstr_C (')'); | |
4bcaafd9 ILT |
1457 | #endif |
1458 | } | |
1459 | ||
00fe048c | 1460 | \f |
1ed13f83 NF |
1461 | /* Generate the symbols for any queued up type symbols we encountered |
1462 | while generating the type info for some originally used symbol. | |
1463 | This might generate additional entries in the queue. Only when | |
1464 | the nesting depth goes to 0 is this routine called. */ | |
1465 | ||
1466 | static void | |
1467 | debug_flush_symbol_queue (void) | |
1468 | { | |
1469 | int i; | |
1470 | ||
1471 | /* Make sure that additionally queued items are not flushed | |
1472 | prematurely. */ | |
1473 | ||
1474 | ++debug_nesting; | |
1475 | ||
1476 | for (i = 0; i < symbol_queue_index; ++i) | |
1477 | { | |
1478 | /* If we pushed queued symbols then such symbols must be | |
1479 | output no matter what anyone else says. Specifically, | |
1480 | we need to make sure dbxout_symbol() thinks the symbol was | |
1481 | used and also we need to override TYPE_DECL_SUPPRESS_DEBUG | |
1482 | which may be set for outside reasons. */ | |
1483 | int saved_tree_used = TREE_USED (symbol_queue[i]); | |
1484 | int saved_suppress_debug = TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]); | |
1485 | TREE_USED (symbol_queue[i]) = 1; | |
1486 | TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = 0; | |
1487 | ||
1488 | #ifdef DBX_DEBUGGING_INFO | |
1489 | dbxout_symbol (symbol_queue[i], 0); | |
1490 | #endif | |
1491 | ||
1492 | TREE_USED (symbol_queue[i]) = saved_tree_used; | |
1493 | TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = saved_suppress_debug; | |
1494 | } | |
1495 | ||
1496 | symbol_queue_index = 0; | |
1497 | --debug_nesting; | |
1498 | } | |
1499 | ||
1500 | /* Queue a type symbol needed as part of the definition of a decl | |
1501 | symbol. These symbols are generated when debug_flush_symbol_queue() | |
1502 | is called. */ | |
93a27b7b | 1503 | |
1ed13f83 NF |
1504 | static void |
1505 | debug_queue_symbol (tree decl) | |
1506 | { | |
1507 | if (symbol_queue_index >= symbol_queue_size) | |
1508 | { | |
1509 | symbol_queue_size += 10; | |
1510 | symbol_queue = XRESIZEVEC (tree, symbol_queue, symbol_queue_size); | |
1511 | } | |
1512 | ||
1513 | symbol_queue[symbol_queue_index++] = decl; | |
1514 | } | |
1515 | ||
1516 | /* Free symbol queue. */ | |
1517 | static void | |
1518 | debug_free_queue (void) | |
1519 | { | |
1520 | if (symbol_queue) | |
1521 | { | |
1522 | free (symbol_queue); | |
1523 | symbol_queue = NULL; | |
1524 | symbol_queue_size = 0; | |
1525 | } | |
1526 | } | |
1527 | \f | |
93a27b7b ZW |
1528 | /* Used in several places: evaluates to '0' for a private decl, |
1529 | '1' for a protected decl, '2' for a public decl. */ | |
1530 | #define DECL_ACCESSIBILITY_CHAR(DECL) \ | |
6e57a01d | 1531 | (TREE_PRIVATE (DECL) ? '0' : TREE_PROTECTED (DECL) ? '1' : '2') |
93a27b7b | 1532 | |
6dc42e49 | 1533 | /* Subroutine of `dbxout_type'. Output the type fields of TYPE. |
00fe048c RS |
1534 | This must be a separate function because anonymous unions require |
1535 | recursive calls. */ | |
1536 | ||
1537 | static void | |
7080f735 | 1538 | dbxout_type_fields (tree type) |
00fe048c RS |
1539 | { |
1540 | tree tem; | |
665f2503 | 1541 | |
15a5b8a2 | 1542 | /* Output the name, type, position (in bits), size (in bits) of each |
665f2503 | 1543 | field that we can support. */ |
910ad8de | 1544 | for (tem = TYPE_FIELDS (type); tem; tem = DECL_CHAIN (tem)) |
00fe048c | 1545 | { |
666c27b9 KH |
1546 | /* If one of the nodes is an error_mark or its type is then |
1547 | return early. */ | |
b504a918 | 1548 | if (error_operand_p (tem)) |
975421be AP |
1549 | return; |
1550 | ||
00fe048c | 1551 | /* Omit here local type decls until we know how to support them. */ |
665f2503 | 1552 | if (TREE_CODE (tem) == TYPE_DECL |
d8a2f02e | 1553 | || TREE_CODE (tem) == TEMPLATE_DECL |
5aaa8fb4 NS |
1554 | /* Member functions emitted after fields. */ |
1555 | || TREE_CODE (tem) == FUNCTION_DECL | |
b8621d81 AH |
1556 | /* Omit here the nameless fields that are used to skip bits. */ |
1557 | || DECL_IGNORED_P (tem) | |
665f2503 RK |
1558 | /* Omit fields whose position or size are variable or too large to |
1559 | represent. */ | |
1560 | || (TREE_CODE (tem) == FIELD_DECL | |
9541ffee | 1561 | && (! tree_fits_shwi_p (bit_position (tem)) |
06ebf127 | 1562 | || ! DECL_SIZE (tem) |
cc269bb6 | 1563 | || ! tree_fits_uhwi_p (DECL_SIZE (tem))))) |
7b1f7d51 | 1564 | continue; |
665f2503 | 1565 | |
5b6e175e | 1566 | else if (TREE_CODE (tem) != CONST_DECL) |
00fe048c RS |
1567 | { |
1568 | /* Continue the line if necessary, | |
1569 | but not before the first field. */ | |
1570 | if (tem != TYPE_FIELDS (type)) | |
665f2503 | 1571 | CONTIN; |
00fe048c | 1572 | |
5b6e175e | 1573 | if (DECL_NAME (tem)) |
93a27b7b ZW |
1574 | stabstr_I (DECL_NAME (tem)); |
1575 | stabstr_C (':'); | |
00fe048c | 1576 | |
196cedd0 | 1577 | if (use_gnu_debug_info_extensions |
00fe048c RS |
1578 | && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem) |
1579 | || TREE_CODE (tem) != FIELD_DECL)) | |
1580 | { | |
93a27b7b ZW |
1581 | stabstr_C ('/'); |
1582 | stabstr_C (DECL_ACCESSIBILITY_CHAR (tem)); | |
00fe048c RS |
1583 | } |
1584 | ||
1585 | dbxout_type ((TREE_CODE (tem) == FIELD_DECL | |
1586 | && DECL_BIT_FIELD_TYPE (tem)) | |
deda4b76 | 1587 | ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0); |
00fe048c | 1588 | |
8813a647 | 1589 | if (VAR_P (tem)) |
00fe048c | 1590 | { |
196cedd0 | 1591 | if (TREE_STATIC (tem) && use_gnu_debug_info_extensions) |
00fe048c | 1592 | { |
02e3f1a8 RK |
1593 | tree name = DECL_ASSEMBLER_NAME (tem); |
1594 | ||
93a27b7b ZW |
1595 | stabstr_C (':'); |
1596 | stabstr_I (name); | |
1597 | stabstr_C (';'); | |
00fe048c RS |
1598 | } |
1599 | else | |
93a27b7b ZW |
1600 | /* If TEM is non-static, GDB won't understand it. */ |
1601 | stabstr_S (",0,0;"); | |
00fe048c | 1602 | } |
665f2503 | 1603 | else |
00fe048c | 1604 | { |
93a27b7b ZW |
1605 | stabstr_C (','); |
1606 | stabstr_D (int_bit_position (tem)); | |
1607 | stabstr_C (','); | |
ae7e9ddd | 1608 | stabstr_D (tree_to_uhwi (DECL_SIZE (tem))); |
93a27b7b | 1609 | stabstr_C (';'); |
00fe048c | 1610 | } |
00fe048c RS |
1611 | } |
1612 | } | |
1613 | } | |
1614 | \f | |
6dc42e49 | 1615 | /* Subroutine of `dbxout_type_methods'. Output debug info about the |
93a27b7b | 1616 | method described DECL. */ |
00fe048c RS |
1617 | |
1618 | static void | |
93a27b7b | 1619 | dbxout_type_method_1 (tree decl) |
00fe048c | 1620 | { |
00fe048c RS |
1621 | char c1 = 'A', c2; |
1622 | ||
1623 | if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE) | |
1624 | c2 = '?'; | |
1625 | else /* it's a METHOD_TYPE. */ | |
1626 | { | |
213ecac9 | 1627 | tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))); |
00fe048c RS |
1628 | /* A for normal functions. |
1629 | B for `const' member functions. | |
1630 | C for `volatile' member functions. | |
1631 | D for `const volatile' member functions. */ | |
1632 | if (TYPE_READONLY (TREE_TYPE (firstarg))) | |
1633 | c1 += 1; | |
1634 | if (TYPE_VOLATILE (TREE_TYPE (firstarg))) | |
1635 | c1 += 2; | |
1636 | ||
1637 | if (DECL_VINDEX (decl)) | |
1638 | c2 = '*'; | |
1639 | else | |
1640 | c2 = '.'; | |
1641 | } | |
1642 | ||
93a27b7b ZW |
1643 | /* ??? Output the mangled name, which contains an encoding of the |
1644 | method's type signature. May not be necessary anymore. */ | |
1645 | stabstr_C (':'); | |
1646 | stabstr_I (DECL_ASSEMBLER_NAME (decl)); | |
1647 | stabstr_C (';'); | |
1648 | stabstr_C (DECL_ACCESSIBILITY_CHAR (decl)); | |
1649 | stabstr_C (c1); | |
1650 | stabstr_C (c2); | |
665f2503 | 1651 | |
9541ffee | 1652 | if (DECL_VINDEX (decl) && tree_fits_shwi_p (DECL_VINDEX (decl))) |
00fe048c | 1653 | { |
9439e9a1 | 1654 | stabstr_D (tree_to_shwi (DECL_VINDEX (decl))); |
93a27b7b | 1655 | stabstr_C (';'); |
deda4b76 | 1656 | dbxout_type (DECL_CONTEXT (decl), 0); |
93a27b7b | 1657 | stabstr_C (';'); |
00fe048c RS |
1658 | } |
1659 | } | |
1660 | \f | |
5aaa8fb4 NS |
1661 | /* Subroutine of `dbxout_type'. Output debug info about the member |
1662 | functions defined in TYPE. */ | |
00fe048c RS |
1663 | |
1664 | static void | |
7080f735 | 1665 | dbxout_type_methods (tree type) |
00fe048c | 1666 | { |
5aaa8fb4 | 1667 | for (tree fndecl = TYPE_FIELDS (type); fndecl;) |
00fe048c | 1668 | { |
b1a86a99 JM |
1669 | int need_prefix = 1; |
1670 | ||
3a7587e4 RS |
1671 | /* Group together all the methods for the same operation. |
1672 | These differ in the types of the arguments. */ | |
5aaa8fb4 | 1673 | for (tree last = NULL_TREE; |
00fe048c | 1674 | fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last)); |
910ad8de | 1675 | fndecl = DECL_CHAIN (fndecl)) |
00fe048c RS |
1676 | /* Output the name of the field (after overloading), as |
1677 | well as the name of the field before overloading, along | |
1678 | with its parameter list */ | |
1679 | { | |
5aaa8fb4 | 1680 | /* Skip non-functions. */ |
92643fea MM |
1681 | if (TREE_CODE (fndecl) != FUNCTION_DECL) |
1682 | continue; | |
1683 | ||
5daf7c0a JM |
1684 | /* Also ignore abstract methods; those are only interesting to |
1685 | the DWARF backends. */ | |
00de328a | 1686 | if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT_P (fndecl)) |
3a7587e4 RS |
1687 | continue; |
1688 | ||
5aaa8fb4 NS |
1689 | CONTIN; |
1690 | ||
1691 | last = fndecl; | |
1692 | ||
b1a86a99 JM |
1693 | /* Redundantly output the plain name, since that's what gdb |
1694 | expects. */ | |
1695 | if (need_prefix) | |
1696 | { | |
93a27b7b ZW |
1697 | stabstr_I (DECL_NAME (fndecl)); |
1698 | stabstr_S ("::"); | |
b1a86a99 JM |
1699 | need_prefix = 0; |
1700 | } | |
1701 | ||
deda4b76 | 1702 | dbxout_type (TREE_TYPE (fndecl), 0); |
93a27b7b | 1703 | dbxout_type_method_1 (fndecl); |
00fe048c | 1704 | } |
b1a86a99 | 1705 | if (!need_prefix) |
93a27b7b | 1706 | stabstr_C (';'); |
00fe048c RS |
1707 | } |
1708 | } | |
b238f8de PB |
1709 | |
1710 | /* Emit a "range" type specification, which has the form: | |
1711 | "r<index type>;<lower bound>;<upper bound>;". | |
84fb43a1 | 1712 | TYPE is an INTEGER_TYPE, LOW and HIGH are the bounds. */ |
b238f8de PB |
1713 | |
1714 | static void | |
84fb43a1 | 1715 | dbxout_range_type (tree type, tree low, tree high) |
b238f8de | 1716 | { |
93a27b7b | 1717 | stabstr_C ('r'); |
6c73937e | 1718 | if (TREE_TYPE (type)) |
deda4b76 | 1719 | dbxout_type (TREE_TYPE (type), 0); |
d0310c53 | 1720 | else if (TREE_CODE (type) != INTEGER_TYPE) |
87677ac7 | 1721 | dbxout_type (type, 0); |
b238f8de PB |
1722 | else |
1723 | { | |
7ae6c858 PB |
1724 | /* Traditionally, we made sure 'int' was type 1, and builtin types |
1725 | were defined to be sub-ranges of int. Unfortunately, this | |
1726 | does not allow us to distinguish true sub-ranges from integer | |
1727 | types. So, instead we define integer (non-sub-range) types as | |
28144186 JW |
1728 | sub-ranges of themselves. This matters for Chill. If this isn't |
1729 | a subrange type, then we want to define it in terms of itself. | |
1730 | However, in C, this may be an anonymous integer type, and we don't | |
1731 | want to emit debug info referring to it. Just calling | |
1732 | dbxout_type_index won't work anyways, because the type hasn't been | |
1733 | defined yet. We make this work for both cases by checked to see | |
1734 | whether this is a defined type, referring to it if it is, and using | |
1735 | 'int' otherwise. */ | |
1736 | if (TYPE_SYMTAB_ADDRESS (type) != 0) | |
1737 | dbxout_type_index (type); | |
1738 | else | |
1739 | dbxout_type_index (integer_type_node); | |
b238f8de | 1740 | } |
665f2503 | 1741 | |
93a27b7b | 1742 | stabstr_C (';'); |
9541ffee | 1743 | if (low && tree_fits_shwi_p (low)) |
fb2c5c00 | 1744 | { |
84fb43a1 EB |
1745 | if (print_int_cst_bounds_in_octal_p (type, low, high)) |
1746 | stabstr_O (low); | |
39d658e3 | 1747 | else |
9439e9a1 | 1748 | stabstr_D (tree_to_shwi (low)); |
fb2c5c00 | 1749 | } |
b238f8de | 1750 | else |
93a27b7b | 1751 | stabstr_C ('0'); |
665f2503 | 1752 | |
93a27b7b | 1753 | stabstr_C (';'); |
9541ffee | 1754 | if (high && tree_fits_shwi_p (high)) |
fb2c5c00 | 1755 | { |
84fb43a1 EB |
1756 | if (print_int_cst_bounds_in_octal_p (type, low, high)) |
1757 | stabstr_O (high); | |
39d658e3 | 1758 | else |
9439e9a1 | 1759 | stabstr_D (tree_to_shwi (high)); |
93a27b7b | 1760 | stabstr_C (';'); |
fb2c5c00 | 1761 | } |
b238f8de | 1762 | else |
93a27b7b | 1763 | stabstr_S ("-1;"); |
b238f8de | 1764 | } |
00fe048c | 1765 | \f |
6a08f7b3 | 1766 | |
00fe048c RS |
1767 | /* Output a reference to a type. If the type has not yet been |
1768 | described in the dbx output, output its definition now. | |
1769 | For a type already defined, just refer to its definition | |
1770 | using the type number. | |
1771 | ||
1772 | If FULL is nonzero, and the type has been described only with | |
1773 | a forward-reference, output the definition now. | |
1774 | If FULL is zero in this case, just refer to the forward-reference | |
deda4b76 | 1775 | using the number previously allocated. */ |
00fe048c RS |
1776 | |
1777 | static void | |
7080f735 | 1778 | dbxout_type (tree type, int full) |
00fe048c | 1779 | { |
35571e38 | 1780 | static int anonymous_type_number = 0; |
84fb43a1 | 1781 | tree tem, main_variant, low, high; |
00fe048c | 1782 | |
84fb43a1 EB |
1783 | if (TREE_CODE (type) == INTEGER_TYPE) |
1784 | { | |
1785 | if (TREE_TYPE (type) == 0) | |
1786 | { | |
1787 | low = TYPE_MIN_VALUE (type); | |
1788 | high = TYPE_MAX_VALUE (type); | |
1789 | } | |
1790 | ||
1791 | else if (subrange_type_for_debug_p (type, &low, &high)) | |
1792 | ; | |
1793 | ||
1794 | /* If this is a subtype that should not be emitted as a subrange type, | |
1795 | use the base type. */ | |
1796 | else | |
1797 | { | |
1798 | type = TREE_TYPE (type); | |
1799 | low = TYPE_MIN_VALUE (type); | |
1800 | high = TYPE_MAX_VALUE (type); | |
1801 | } | |
1802 | } | |
1803 | ||
00fe048c RS |
1804 | /* If there was an input error and we don't really have a type, |
1805 | avoid crashing and write something that is at least valid | |
1806 | by assuming `int'. */ | |
1807 | if (type == error_mark_node) | |
1808 | type = integer_type_node; | |
5bfaaeda | 1809 | else |
00fe048c | 1810 | { |
00fe048c RS |
1811 | if (TYPE_NAME (type) |
1812 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
326af3bf | 1813 | && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type))) |
00fe048c RS |
1814 | full = 0; |
1815 | } | |
1816 | ||
821adc5e JM |
1817 | /* Try to find the "main variant" with the same name. */ |
1818 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
1819 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
1820 | main_variant = TREE_TYPE (TYPE_NAME (type)); | |
1821 | else | |
1822 | main_variant = TYPE_MAIN_VARIANT (type); | |
1823 | ||
1824 | /* If we are not using extensions, stabs does not distinguish const and | |
1825 | volatile, so there is no need to make them separate types. */ | |
1826 | if (!use_gnu_debug_info_extensions) | |
1827 | type = main_variant; | |
1828 | ||
00fe048c RS |
1829 | if (TYPE_SYMTAB_ADDRESS (type) == 0) |
1830 | { | |
1831 | /* Type has no dbx number assigned. Assign next available number. */ | |
1832 | TYPE_SYMTAB_ADDRESS (type) = next_type_number++; | |
1833 | ||
1834 | /* Make sure type vector is long enough to record about this type. */ | |
1835 | ||
1836 | if (next_type_number == typevec_len) | |
1837 | { | |
f883e0a7 | 1838 | typevec = GGC_RESIZEVEC (struct typeinfo, typevec, typevec_len * 2); |
703ad42b | 1839 | memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]); |
00fe048c RS |
1840 | typevec_len *= 2; |
1841 | } | |
4bcaafd9 ILT |
1842 | |
1843 | #ifdef DBX_USE_BINCL | |
33e9d2aa | 1844 | emit_pending_bincls_if_required (); |
e3da301d MS |
1845 | typevec[TYPE_SYMTAB_ADDRESS (type)].file_number |
1846 | = current_file->file_number; | |
1847 | typevec[TYPE_SYMTAB_ADDRESS (type)].type_number | |
1848 | = current_file->next_type_number++; | |
4bcaafd9 | 1849 | #endif |
00fe048c RS |
1850 | } |
1851 | ||
6a08f7b3 DP |
1852 | if (flag_debug_only_used_symbols) |
1853 | { | |
1854 | if ((TREE_CODE (type) == RECORD_TYPE | |
1855 | || TREE_CODE (type) == UNION_TYPE | |
1856 | || TREE_CODE (type) == QUAL_UNION_TYPE | |
1857 | || TREE_CODE (type) == ENUMERAL_TYPE) | |
1858 | && TYPE_STUB_DECL (type) | |
6615c446 | 1859 | && DECL_P (TYPE_STUB_DECL (type)) |
6a08f7b3 DP |
1860 | && ! DECL_IGNORED_P (TYPE_STUB_DECL (type))) |
1861 | debug_queue_symbol (TYPE_STUB_DECL (type)); | |
1862 | else if (TYPE_NAME (type) | |
1863 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) | |
1864 | debug_queue_symbol (TYPE_NAME (type)); | |
1865 | } | |
7080f735 | 1866 | |
00fe048c | 1867 | /* Output the number of this type, to refer to it. */ |
4bcaafd9 | 1868 | dbxout_type_index (type); |
00fe048c | 1869 | |
b372168c MM |
1870 | #ifdef DBX_TYPE_DEFINED |
1871 | if (DBX_TYPE_DEFINED (type)) | |
1872 | return; | |
1873 | #endif | |
1874 | ||
00fe048c RS |
1875 | /* If this type's definition has been output or is now being output, |
1876 | that is all. */ | |
1877 | ||
4bcaafd9 | 1878 | switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status) |
00fe048c RS |
1879 | { |
1880 | case TYPE_UNSEEN: | |
1881 | break; | |
1882 | case TYPE_XREF: | |
dad0145a RS |
1883 | /* If we have already had a cross reference, |
1884 | and either that's all we want or that's the best we could do, | |
1885 | don't repeat the cross reference. | |
1886 | Sun dbx crashes if we do. */ | |
d0f062fb | 1887 | if (! full || !COMPLETE_TYPE_P (type) |
dad0145a | 1888 | /* No way in DBX fmt to describe a variable size. */ |
cc269bb6 | 1889 | || ! tree_fits_uhwi_p (TYPE_SIZE (type))) |
00fe048c RS |
1890 | return; |
1891 | break; | |
1892 | case TYPE_DEFINED: | |
1893 | return; | |
1894 | } | |
1895 | ||
1896 | #ifdef DBX_NO_XREFS | |
1897 | /* For systems where dbx output does not allow the `=xsNAME:' syntax, | |
1898 | leave the type-number completely undefined rather than output | |
e65f61cf JW |
1899 | a cross-reference. If we have already used GNU debug info extensions, |
1900 | then it is OK to output a cross reference. This is necessary to get | |
1901 | proper C++ debug output. */ | |
1902 | if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE | |
1903 | || TREE_CODE (type) == QUAL_UNION_TYPE | |
1904 | || TREE_CODE (type) == ENUMERAL_TYPE) | |
1905 | && ! use_gnu_debug_info_extensions) | |
e8fca6ce JW |
1906 | /* We must use the same test here as we use twice below when deciding |
1907 | whether to emit a cross-reference. */ | |
1908 | if ((TYPE_NAME (type) != 0 | |
1909 | && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
1910 | && DECL_IGNORED_P (TYPE_NAME (type))) | |
1911 | && !full) | |
d0f062fb | 1912 | || !COMPLETE_TYPE_P (type) |
e8fca6ce | 1913 | /* No way in DBX fmt to describe a variable size. */ |
cc269bb6 | 1914 | || ! tree_fits_uhwi_p (TYPE_SIZE (type))) |
00fe048c | 1915 | { |
4bcaafd9 | 1916 | typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF; |
00fe048c RS |
1917 | return; |
1918 | } | |
1919 | #endif | |
1920 | ||
1921 | /* Output a definition now. */ | |
93a27b7b | 1922 | stabstr_C ('='); |
00fe048c RS |
1923 | |
1924 | /* Mark it as defined, so that if it is self-referent | |
1925 | we will not get into an infinite recursion of definitions. */ | |
1926 | ||
4bcaafd9 | 1927 | typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED; |
00fe048c | 1928 | |
821adc5e JM |
1929 | /* If this type is a variant of some other, hand off. Types with |
1930 | different names are usefully distinguished. We only distinguish | |
1931 | cv-qualified types if we're using extensions. */ | |
1932 | if (TYPE_READONLY (type) > TYPE_READONLY (main_variant)) | |
1933 | { | |
93a27b7b | 1934 | stabstr_C ('k'); |
821adc5e JM |
1935 | dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0); |
1936 | return; | |
1937 | } | |
1938 | else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant)) | |
1939 | { | |
93a27b7b | 1940 | stabstr_C ('B'); |
821adc5e JM |
1941 | dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0); |
1942 | return; | |
1943 | } | |
1944 | else if (main_variant != TYPE_MAIN_VARIANT (type)) | |
1945 | { | |
6a08f7b3 DP |
1946 | if (flag_debug_only_used_symbols) |
1947 | { | |
1948 | tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type)); | |
1949 | ||
7080f735 | 1950 | if ((TREE_CODE (orig_type) == RECORD_TYPE |
6a08f7b3 DP |
1951 | || TREE_CODE (orig_type) == UNION_TYPE |
1952 | || TREE_CODE (orig_type) == QUAL_UNION_TYPE | |
1953 | || TREE_CODE (orig_type) == ENUMERAL_TYPE) | |
1954 | && TYPE_STUB_DECL (orig_type) | |
1955 | && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type))) | |
1956 | debug_queue_symbol (TYPE_STUB_DECL (orig_type)); | |
1957 | } | |
821adc5e | 1958 | /* 'type' is a typedef; output the type it refers to. */ |
deda4b76 | 1959 | dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0); |
79afd906 PB |
1960 | return; |
1961 | } | |
821adc5e | 1962 | /* else continue. */ |
79afd906 | 1963 | |
00fe048c RS |
1964 | switch (TREE_CODE (type)) |
1965 | { | |
1966 | case VOID_TYPE: | |
1e85e720 | 1967 | case NULLPTR_TYPE: |
00fe048c | 1968 | case LANG_TYPE: |
6b91b3e9 | 1969 | case OPAQUE_TYPE: |
454ff5cb | 1970 | /* For a void type, just define it as itself; i.e., "5=5". |
00fe048c RS |
1971 | This makes us consider it defined |
1972 | without saying what it is. The debugger will make it | |
1973 | a void type when the reference is seen, and nothing will | |
1974 | ever override that default. */ | |
4bcaafd9 | 1975 | dbxout_type_index (type); |
00fe048c RS |
1976 | break; |
1977 | ||
1978 | case INTEGER_TYPE: | |
8df83eae | 1979 | if (type == char_type_node && ! TYPE_UNSIGNED (type)) |
4bcaafd9 ILT |
1980 | { |
1981 | /* Output the type `char' as a subrange of itself! | |
1982 | I don't understand this definition, just copied it | |
1983 | from the output of pcc. | |
1984 | This used to use `r2' explicitly and we used to | |
1985 | take care to make sure that `char' was type number 2. */ | |
93a27b7b | 1986 | stabstr_C ('r'); |
4bcaafd9 | 1987 | dbxout_type_index (type); |
93a27b7b | 1988 | stabstr_S (";0;127;"); |
4bcaafd9 | 1989 | } |
14a774a9 RK |
1990 | |
1991 | /* If this is a subtype of another integer type, always prefer to | |
1992 | write it as a subtype. */ | |
1993 | else if (TREE_TYPE (type) != 0 | |
3342b6fd | 1994 | && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE) |
3a538a66 | 1995 | { |
ea619b46 JB |
1996 | /* If the size is non-standard, say what it is if we can use |
1997 | GDB extensions. */ | |
1998 | ||
1999 | if (use_gnu_debug_info_extensions | |
2000 | && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node)) | |
2001 | { | |
93a27b7b ZW |
2002 | stabstr_S ("@s"); |
2003 | stabstr_D (TYPE_PRECISION (type)); | |
2004 | stabstr_C (';'); | |
ea619b46 JB |
2005 | } |
2006 | ||
84fb43a1 | 2007 | dbxout_range_type (type, low, high); |
3a538a66 | 2008 | } |
14a774a9 RK |
2009 | |
2010 | else | |
3a538a66 | 2011 | { |
14a774a9 RK |
2012 | /* If the size is non-standard, say what it is if we can use |
2013 | GDB extensions. */ | |
2014 | ||
2015 | if (use_gnu_debug_info_extensions | |
2016 | && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node)) | |
02e3f1a8 | 2017 | { |
93a27b7b ZW |
2018 | stabstr_S ("@s"); |
2019 | stabstr_D (TYPE_PRECISION (type)); | |
2020 | stabstr_C (';'); | |
02e3f1a8 | 2021 | } |
14a774a9 | 2022 | |
84fb43a1 | 2023 | if (print_int_cst_bounds_in_octal_p (type, low, high)) |
14a774a9 | 2024 | { |
93a27b7b | 2025 | stabstr_C ('r'); |
08b0f5f9 JB |
2026 | |
2027 | /* If this type derives from another type, output type index of | |
2028 | parent type. This is particularly important when parent type | |
2029 | is an enumerated type, because not generating the parent type | |
2030 | index would transform the definition of this enumerated type | |
2031 | into a plain unsigned type. */ | |
2032 | if (TREE_TYPE (type) != 0) | |
2033 | dbxout_type_index (TREE_TYPE (type)); | |
2034 | else | |
2035 | dbxout_type_index (type); | |
2036 | ||
93a27b7b | 2037 | stabstr_C (';'); |
84fb43a1 | 2038 | stabstr_O (low); |
93a27b7b | 2039 | stabstr_C (';'); |
84fb43a1 | 2040 | stabstr_O (high); |
93a27b7b | 2041 | stabstr_C (';'); |
14a774a9 RK |
2042 | } |
2043 | ||
2044 | else | |
2045 | /* Output other integer types as subranges of `int'. */ | |
84fb43a1 | 2046 | dbxout_range_type (type, low, high); |
3a538a66 | 2047 | } |
14a774a9 | 2048 | |
00fe048c RS |
2049 | break; |
2050 | ||
2051 | case REAL_TYPE: | |
325217ed | 2052 | case FIXED_POINT_TYPE: |
00fe048c RS |
2053 | /* This used to say `r1' and we used to take care |
2054 | to make sure that `int' was type number 1. */ | |
93a27b7b | 2055 | stabstr_C ('r'); |
4bcaafd9 | 2056 | dbxout_type_index (integer_type_node); |
93a27b7b ZW |
2057 | stabstr_C (';'); |
2058 | stabstr_D (int_size_in_bytes (type)); | |
2059 | stabstr_S (";0;"); | |
00fe048c RS |
2060 | break; |
2061 | ||
72db60c6 PB |
2062 | case BOOLEAN_TYPE: |
2063 | if (use_gnu_debug_info_extensions) | |
e003ca80 | 2064 | { |
93a27b7b ZW |
2065 | stabstr_S ("@s"); |
2066 | stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type)); | |
2067 | stabstr_S (";-16;"); | |
e003ca80 | 2068 | } |
72db60c6 | 2069 | else /* Define as enumeral type (False, True) */ |
93a27b7b | 2070 | stabstr_S ("eFalse:0,True:1,;"); |
15a5b8a2 RS |
2071 | break; |
2072 | ||
15a5b8a2 | 2073 | case COMPLEX_TYPE: |
3a7cbb76 ZW |
2074 | /* Differs from the REAL_TYPE by its new data type number. |
2075 | R3 is NF_COMPLEX. We don't try to use any of the other NF_* | |
2076 | codes since gdb doesn't care anyway. */ | |
15a5b8a2 RS |
2077 | |
2078 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) | |
2079 | { | |
93a27b7b ZW |
2080 | stabstr_S ("R3;"); |
2081 | stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type))); | |
2082 | stabstr_S (";0;"); | |
47cc012b RS |
2083 | } |
2084 | else | |
2085 | { | |
2086 | /* Output a complex integer type as a structure, | |
2087 | pending some other way to do it. */ | |
93a27b7b ZW |
2088 | stabstr_C ('s'); |
2089 | stabstr_D (int_size_in_bytes (type)); | |
02e3f1a8 | 2090 | |
93a27b7b | 2091 | stabstr_S ("real:"); |
deda4b76 | 2092 | dbxout_type (TREE_TYPE (type), 0); |
93a27b7b ZW |
2093 | stabstr_S (",0,"); |
2094 | stabstr_D (TYPE_PRECISION (TREE_TYPE (type))); | |
2095 | ||
2096 | stabstr_S (";imag:"); | |
deda4b76 | 2097 | dbxout_type (TREE_TYPE (type), 0); |
93a27b7b ZW |
2098 | stabstr_C (','); |
2099 | stabstr_D (TYPE_PRECISION (TREE_TYPE (type))); | |
2100 | stabstr_C (','); | |
2101 | stabstr_D (TYPE_PRECISION (TREE_TYPE (type))); | |
2102 | stabstr_S (";;"); | |
47cc012b | 2103 | } |
15a5b8a2 RS |
2104 | break; |
2105 | ||
00fe048c | 2106 | case ARRAY_TYPE: |
202fe2d6 DB |
2107 | /* Make arrays of packed bits look like bitstrings for chill. */ |
2108 | if (TYPE_PACKED (type) && use_gnu_debug_info_extensions) | |
2109 | { | |
93a27b7b ZW |
2110 | stabstr_S ("@s"); |
2111 | stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type)); | |
2112 | stabstr_S (";@S;S"); | |
deda4b76 | 2113 | dbxout_type (TYPE_DOMAIN (type), 0); |
202fe2d6 DB |
2114 | break; |
2115 | } | |
02e3f1a8 | 2116 | |
00fe048c RS |
2117 | /* Output "a" followed by a range type definition |
2118 | for the index type of the array | |
2119 | followed by a reference to the target-type. | |
b238f8de | 2120 | ar1;0;N;M for a C array of type M and size N+1. */ |
4042d440 | 2121 | /* Check if a character string type, which in Chill is |
0f41302f | 2122 | different from an array of characters. */ |
4042d440 PB |
2123 | if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions) |
2124 | { | |
93a27b7b | 2125 | stabstr_S ("@S;"); |
4042d440 | 2126 | } |
b238f8de PB |
2127 | tem = TYPE_DOMAIN (type); |
2128 | if (tem == NULL) | |
4bcaafd9 | 2129 | { |
93a27b7b | 2130 | stabstr_S ("ar"); |
4bcaafd9 | 2131 | dbxout_type_index (integer_type_node); |
93a27b7b | 2132 | stabstr_S (";0;-1;"); |
4bcaafd9 | 2133 | } |
b238f8de PB |
2134 | else |
2135 | { | |
93a27b7b | 2136 | stabstr_C ('a'); |
84fb43a1 | 2137 | dbxout_range_type (tem, TYPE_MIN_VALUE (tem), TYPE_MAX_VALUE (tem)); |
b238f8de | 2138 | } |
02e3f1a8 | 2139 | |
deda4b76 | 2140 | dbxout_type (TREE_TYPE (type), 0); |
00fe048c RS |
2141 | break; |
2142 | ||
cf6a4097 RG |
2143 | case VECTOR_TYPE: |
2144 | /* Make vectors look like an array. */ | |
2145 | if (use_gnu_debug_info_extensions) | |
2146 | stabstr_S ("@V;"); | |
2147 | ||
2148 | /* Output "a" followed by a range type definition | |
2149 | for the index type of the array | |
2150 | followed by a reference to the target-type. | |
2151 | ar1;0;N;M for a C array of type M and size N+1. */ | |
2152 | stabstr_C ('a'); | |
2153 | dbxout_range_type (integer_type_node, size_zero_node, | |
2154 | size_int (TYPE_VECTOR_SUBPARTS (type) - 1)); | |
2155 | ||
2156 | dbxout_type (TREE_TYPE (type), 0); | |
2157 | break; | |
2158 | ||
00fe048c RS |
2159 | case RECORD_TYPE: |
2160 | case UNION_TYPE: | |
c1b98a95 | 2161 | case QUAL_UNION_TYPE: |
00fe048c | 2162 | { |
fa743e8c | 2163 | tree binfo = TYPE_BINFO (type); |
00fe048c | 2164 | |
e8fca6ce JW |
2165 | /* Output a structure type. We must use the same test here as we |
2166 | use in the DBX_NO_XREFS case above. */ | |
b372168c MM |
2167 | if ((TYPE_NAME (type) != 0 |
2168 | && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
2169 | && DECL_IGNORED_P (TYPE_NAME (type))) | |
2170 | && !full) | |
d0f062fb | 2171 | || !COMPLETE_TYPE_P (type) |
3a7587e4 | 2172 | /* No way in DBX fmt to describe a variable size. */ |
cc269bb6 | 2173 | || ! tree_fits_uhwi_p (TYPE_SIZE (type))) |
00fe048c RS |
2174 | { |
2175 | /* If the type is just a cross reference, output one | |
2176 | and mark the type as partially described. | |
2177 | If it later becomes defined, we will output | |
2178 | its real definition. | |
2179 | If the type has a name, don't nest its definition within | |
2180 | another type's definition; instead, output an xref | |
2181 | and let the definition come when the name is defined. */ | |
93a27b7b | 2182 | stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu"); |
9dba4b55 PC |
2183 | if (TYPE_IDENTIFIER (type)) |
2184 | { | |
2185 | /* Note that the C frontend creates for anonymous variable | |
2186 | length records/unions TYPE_NAME with DECL_NAME NULL. */ | |
2187 | dbxout_type_name (type); | |
2188 | } | |
35571e38 | 2189 | else |
02e3f1a8 | 2190 | { |
93a27b7b ZW |
2191 | stabstr_S ("$$"); |
2192 | stabstr_D (anonymous_type_number++); | |
02e3f1a8 RK |
2193 | } |
2194 | ||
93a27b7b | 2195 | stabstr_C (':'); |
4bcaafd9 | 2196 | typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF; |
00fe048c RS |
2197 | break; |
2198 | } | |
00fe048c | 2199 | |
00fe048c | 2200 | /* Identify record or union, and print its size. */ |
93a27b7b ZW |
2201 | stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'); |
2202 | stabstr_D (int_size_in_bytes (type)); | |
00fe048c | 2203 | |
fa743e8c | 2204 | if (binfo) |
00fe048c | 2205 | { |
fa743e8c NS |
2206 | int i; |
2207 | tree child; | |
9771b263 | 2208 | vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo); |
b8698a0f | 2209 | |
196cedd0 | 2210 | if (use_gnu_debug_info_extensions) |
00fe048c | 2211 | { |
fa743e8c NS |
2212 | if (BINFO_N_BASE_BINFOS (binfo)) |
2213 | { | |
93a27b7b ZW |
2214 | stabstr_C ('!'); |
2215 | stabstr_U (BINFO_N_BASE_BINFOS (binfo)); | |
2216 | stabstr_C (','); | |
fa743e8c | 2217 | } |
00fe048c | 2218 | } |
fa743e8c | 2219 | for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++) |
00fe048c | 2220 | { |
9771b263 | 2221 | tree access = (accesses ? (*accesses)[i] : access_public_node); |
fa743e8c NS |
2222 | |
2223 | if (use_gnu_debug_info_extensions) | |
2224 | { | |
93a27b7b ZW |
2225 | stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0'); |
2226 | stabstr_C (access == access_public_node ? '2' : | |
2227 | access == access_protected_node | |
2228 | ? '1' :'0'); | |
fa743e8c | 2229 | if (BINFO_VIRTUAL_P (child) |
dcc97066 | 2230 | && (lang_GNU_CXX () |
f37d7c60 | 2231 | || strcmp (lang_hooks.name, "GNU Objective-C++") == 0)) |
fa743e8c NS |
2232 | /* For a virtual base, print the (negative) |
2233 | offset within the vtable where we must look | |
2234 | to find the necessary adjustment. */ | |
93a27b7b | 2235 | stabstr_D |
9439e9a1 | 2236 | (tree_to_shwi (BINFO_VPTR_FIELD (child)) |
fa743e8c NS |
2237 | * BITS_PER_UNIT); |
2238 | else | |
9439e9a1 | 2239 | stabstr_D (tree_to_shwi (BINFO_OFFSET (child)) |
93a27b7b ZW |
2240 | * BITS_PER_UNIT); |
2241 | stabstr_C (','); | |
fa743e8c | 2242 | dbxout_type (BINFO_TYPE (child), 0); |
93a27b7b | 2243 | stabstr_C (';'); |
fa743e8c NS |
2244 | } |
2245 | else | |
2246 | { | |
2247 | /* Print out the base class information with | |
2248 | fields which have the same names at the types | |
2249 | they hold. */ | |
2250 | dbxout_type_name (BINFO_TYPE (child)); | |
93a27b7b | 2251 | stabstr_C (':'); |
fa743e8c | 2252 | dbxout_type (BINFO_TYPE (child), full); |
93a27b7b | 2253 | stabstr_C (','); |
9439e9a1 | 2254 | stabstr_D (tree_to_shwi (BINFO_OFFSET (child)) |
93a27b7b ZW |
2255 | * BITS_PER_UNIT); |
2256 | stabstr_C (','); | |
2257 | stabstr_D | |
9439e9a1 | 2258 | (tree_to_shwi (TYPE_SIZE (BINFO_TYPE (child))) |
fa743e8c | 2259 | * BITS_PER_UNIT); |
93a27b7b | 2260 | stabstr_C (';'); |
fa743e8c | 2261 | } |
00fe048c RS |
2262 | } |
2263 | } | |
2264 | } | |
2265 | ||
00fe048c RS |
2266 | /* Write out the field declarations. */ |
2267 | dbxout_type_fields (type); | |
5aaa8fb4 NS |
2268 | if (use_gnu_debug_info_extensions) |
2269 | dbxout_type_methods (type); | |
665f2503 | 2270 | |
93a27b7b | 2271 | stabstr_C (';'); |
00fe048c | 2272 | |
196cedd0 | 2273 | if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE |
00fe048c RS |
2274 | /* Avoid the ~ if we don't really need it--it confuses dbx. */ |
2275 | && TYPE_VFIELD (type)) | |
2276 | { | |
00fe048c | 2277 | |
00fe048c RS |
2278 | /* We need to write out info about what field this class |
2279 | uses as its "main" vtable pointer field, because if this | |
2280 | field is inherited from a base class, GDB cannot necessarily | |
2281 | figure out which field it's using in time. */ | |
93a27b7b ZW |
2282 | stabstr_S ("~%"); |
2283 | dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0); | |
2284 | stabstr_C (';'); | |
00fe048c RS |
2285 | } |
2286 | break; | |
2287 | ||
2288 | case ENUMERAL_TYPE: | |
e8fca6ce JW |
2289 | /* We must use the same test here as we use in the DBX_NO_XREFS case |
2290 | above. We simplify it a bit since an enum will never have a variable | |
2291 | size. */ | |
2292 | if ((TYPE_NAME (type) != 0 | |
2293 | && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
2294 | && DECL_IGNORED_P (TYPE_NAME (type))) | |
2295 | && !full) | |
d0f062fb | 2296 | || !COMPLETE_TYPE_P (type)) |
00fe048c | 2297 | { |
93a27b7b | 2298 | stabstr_S ("xe"); |
00fe048c | 2299 | dbxout_type_name (type); |
4bcaafd9 | 2300 | typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF; |
93a27b7b | 2301 | stabstr_C (':'); |
00fe048c RS |
2302 | return; |
2303 | } | |
71b54b53 PB |
2304 | if (use_gnu_debug_info_extensions |
2305 | && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node)) | |
02e3f1a8 | 2306 | { |
93a27b7b ZW |
2307 | stabstr_S ("@s"); |
2308 | stabstr_D (TYPE_PRECISION (type)); | |
2309 | stabstr_C (';'); | |
02e3f1a8 RK |
2310 | } |
2311 | ||
93a27b7b | 2312 | stabstr_C ('e'); |
00fe048c RS |
2313 | for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem)) |
2314 | { | |
adf2edec DG |
2315 | tree value = TREE_VALUE (tem); |
2316 | ||
93a27b7b ZW |
2317 | stabstr_I (TREE_PURPOSE (tem)); |
2318 | stabstr_C (':'); | |
2319 | ||
adf2edec DG |
2320 | if (TREE_CODE (value) == CONST_DECL) |
2321 | value = DECL_INITIAL (value); | |
2322 | ||
807e902e | 2323 | if (cst_and_fits_in_hwi (value)) |
adf2edec | 2324 | stabstr_D (TREE_INT_CST_LOW (value)); |
71f15013 | 2325 | else |
adf2edec | 2326 | stabstr_O (value); |
02e3f1a8 | 2327 | |
93a27b7b | 2328 | stabstr_C (','); |
00fe048c | 2329 | if (TREE_CHAIN (tem) != 0) |
02e3f1a8 | 2330 | CONTIN; |
00fe048c | 2331 | } |
02e3f1a8 | 2332 | |
93a27b7b | 2333 | stabstr_C (';'); |
00fe048c RS |
2334 | break; |
2335 | ||
2336 | case POINTER_TYPE: | |
93a27b7b | 2337 | stabstr_C ('*'); |
deda4b76 | 2338 | dbxout_type (TREE_TYPE (type), 0); |
00fe048c RS |
2339 | break; |
2340 | ||
2341 | case METHOD_TYPE: | |
196cedd0 | 2342 | if (use_gnu_debug_info_extensions) |
00fe048c | 2343 | { |
93a27b7b | 2344 | stabstr_C ('#'); |
deda4b76 JM |
2345 | |
2346 | /* Write the argument types out longhand. */ | |
2347 | dbxout_type (TYPE_METHOD_BASETYPE (type), 0); | |
93a27b7b | 2348 | stabstr_C (','); |
deda4b76 JM |
2349 | dbxout_type (TREE_TYPE (type), 0); |
2350 | dbxout_args (TYPE_ARG_TYPES (type)); | |
93a27b7b | 2351 | stabstr_C (';'); |
00fe048c RS |
2352 | } |
2353 | else | |
02e3f1a8 RK |
2354 | /* Treat it as a function type. */ |
2355 | dbxout_type (TREE_TYPE (type), 0); | |
00fe048c RS |
2356 | break; |
2357 | ||
2358 | case OFFSET_TYPE: | |
196cedd0 | 2359 | if (use_gnu_debug_info_extensions) |
00fe048c | 2360 | { |
93a27b7b | 2361 | stabstr_C ('@'); |
deda4b76 | 2362 | dbxout_type (TYPE_OFFSET_BASETYPE (type), 0); |
93a27b7b | 2363 | stabstr_C (','); |
deda4b76 | 2364 | dbxout_type (TREE_TYPE (type), 0); |
00fe048c RS |
2365 | } |
2366 | else | |
02e3f1a8 RK |
2367 | /* Should print as an int, because it is really just an offset. */ |
2368 | dbxout_type (integer_type_node, 0); | |
00fe048c RS |
2369 | break; |
2370 | ||
2371 | case REFERENCE_TYPE: | |
196cedd0 | 2372 | if (use_gnu_debug_info_extensions) |
93a27b7b | 2373 | { |
93a27b7b ZW |
2374 | stabstr_C ('&'); |
2375 | } | |
2376 | else | |
2377 | stabstr_C ('*'); | |
deda4b76 | 2378 | dbxout_type (TREE_TYPE (type), 0); |
00fe048c RS |
2379 | break; |
2380 | ||
2381 | case FUNCTION_TYPE: | |
93a27b7b | 2382 | stabstr_C ('f'); |
deda4b76 | 2383 | dbxout_type (TREE_TYPE (type), 0); |
00fe048c RS |
2384 | break; |
2385 | ||
2386 | default: | |
cf6abd9d DE |
2387 | /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM |
2388 | named 'auto' in its type. | |
2389 | No debug info for TEMPLATE_TYPE_PARM type supported yet. */ | |
2390 | if (lang_GNU_CXX ()) | |
2391 | { | |
2392 | tree name = TYPE_IDENTIFIER (type); | |
2393 | if (name == get_identifier ("auto") | |
2394 | || name == get_identifier ("decltype(auto)")) | |
2395 | break; | |
2396 | } | |
2397 | ||
ced3f397 | 2398 | gcc_unreachable (); |
00fe048c RS |
2399 | } |
2400 | } | |
2401 | ||
6356f892 | 2402 | /* Return nonzero if the given type represents an integer whose bounds |
39d658e3 JB |
2403 | should be printed in octal format. */ |
2404 | ||
2405 | static bool | |
84fb43a1 | 2406 | print_int_cst_bounds_in_octal_p (tree type, tree low, tree high) |
39d658e3 JB |
2407 | { |
2408 | /* If we can use GDB extensions and the size is wider than a long | |
2409 | (the size used by GDB to read them) or we may have trouble writing | |
2410 | the bounds the usual way, write them in octal. Note the test is for | |
2411 | the *target's* size of "long", not that of the host. The host test | |
2412 | is just to make sure we can write it out in case the host wide int | |
2413 | is narrower than the target "long". | |
7080f735 | 2414 | |
39d658e3 JB |
2415 | For unsigned types, we use octal if they are the same size or larger. |
2416 | This is because we print the bounds as signed decimal, and hence they | |
2417 | can't span same size unsigned types. */ | |
2418 | ||
2419 | if (use_gnu_debug_info_extensions | |
84fb43a1 EB |
2420 | && low && TREE_CODE (low) == INTEGER_CST |
2421 | && high && TREE_CODE (high) == INTEGER_CST | |
39d658e3 JB |
2422 | && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node) |
2423 | || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) | |
8df83eae | 2424 | && TYPE_UNSIGNED (type)) |
39d658e3 JB |
2425 | || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT |
2426 | || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT | |
8df83eae | 2427 | && TYPE_UNSIGNED (type)))) |
39d658e3 JB |
2428 | return TRUE; |
2429 | else | |
2430 | return FALSE; | |
2431 | } | |
2432 | ||
00fe048c RS |
2433 | /* Output the name of type TYPE, with no punctuation. |
2434 | Such names can be set up either by typedef declarations | |
2435 | or by struct, enum and union tags. */ | |
2436 | ||
2437 | static void | |
7080f735 | 2438 | dbxout_type_name (tree type) |
00fe048c | 2439 | { |
ced3f397 | 2440 | tree t = TYPE_NAME (type); |
b8698a0f | 2441 | |
ced3f397 NS |
2442 | gcc_assert (t); |
2443 | switch (TREE_CODE (t)) | |
00fe048c | 2444 | { |
ced3f397 NS |
2445 | case IDENTIFIER_NODE: |
2446 | break; | |
2447 | case TYPE_DECL: | |
2448 | t = DECL_NAME (t); | |
2449 | break; | |
2450 | default: | |
2451 | gcc_unreachable (); | |
00fe048c | 2452 | } |
00fe048c | 2453 | |
93a27b7b | 2454 | stabstr_I (t); |
00fe048c | 2455 | } |
b0a93386 | 2456 | |
026c3cfd AH |
2457 | /* Output leading struct or class names needed for qualifying type |
2458 | whose scope is limited to a struct or class. */ | |
b0a93386 KB |
2459 | |
2460 | static void | |
7080f735 | 2461 | dbxout_class_name_qualifiers (tree decl) |
b0a93386 KB |
2462 | { |
2463 | tree context = decl_type_context (decl); | |
2464 | ||
7080f735 | 2465 | if (context != NULL_TREE |
c3284718 | 2466 | && TREE_CODE (context) == RECORD_TYPE |
7080f735 | 2467 | && TYPE_NAME (context) != 0 |
b0a93386 KB |
2468 | && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE |
2469 | || (DECL_NAME (TYPE_NAME (context)) != 0))) | |
2470 | { | |
2471 | tree name = TYPE_NAME (context); | |
2472 | ||
2473 | if (TREE_CODE (name) == TYPE_DECL) | |
2474 | { | |
2475 | dbxout_class_name_qualifiers (name); | |
2476 | name = DECL_NAME (name); | |
2477 | } | |
93a27b7b ZW |
2478 | stabstr_I (name); |
2479 | stabstr_S ("::"); | |
b0a93386 KB |
2480 | } |
2481 | } | |
00fe048c | 2482 | \f |
4e0e2698 RH |
2483 | /* This is a specialized subset of expand_expr for use by dbxout_symbol in |
2484 | evaluating DECL_VALUE_EXPR. In particular, we stop if we find decls that | |
fa10beec | 2485 | haven't been expanded, or if the expression is getting so complex we won't |
4e0e2698 RH |
2486 | be able to represent it in stabs anyway. Returns NULL on failure. */ |
2487 | ||
2488 | static rtx | |
2489 | dbxout_expand_expr (tree expr) | |
2490 | { | |
2491 | switch (TREE_CODE (expr)) | |
2492 | { | |
2493 | case VAR_DECL: | |
fcb9237b JW |
2494 | /* We can't handle emulated tls variables, because the address is an |
2495 | offset to the return value of __emutls_get_address, and there is no | |
2496 | way to express that in stabs. Also, there are name mangling issues | |
2497 | here. We end up with references to undefined symbols if we don't | |
2498 | disable debug info for these variables. */ | |
2499 | if (!targetm.have_tls && DECL_THREAD_LOCAL_P (expr)) | |
2500 | return NULL; | |
9166988f JJ |
2501 | if (TREE_STATIC (expr) |
2502 | && !TREE_ASM_WRITTEN (expr) | |
2503 | && !DECL_HAS_VALUE_EXPR_P (expr) | |
2504 | && !TREE_PUBLIC (expr) | |
2505 | && DECL_RTL_SET_P (expr) | |
2506 | && MEM_P (DECL_RTL (expr))) | |
2507 | { | |
2508 | /* If this is a var that might not be actually output, | |
2509 | return NULL, otherwise stabs might reference an undefined | |
2510 | symbol. */ | |
9041d2e6 | 2511 | varpool_node *node = varpool_node::get (expr); |
67348ccc | 2512 | if (!node || !node->definition) |
9166988f JJ |
2513 | return NULL; |
2514 | } | |
fcb9237b JW |
2515 | /* FALLTHRU */ |
2516 | ||
4e0e2698 | 2517 | case PARM_DECL: |
8dcfef8f | 2518 | case RESULT_DECL: |
4e0e2698 RH |
2519 | if (DECL_HAS_VALUE_EXPR_P (expr)) |
2520 | return dbxout_expand_expr (DECL_VALUE_EXPR (expr)); | |
2521 | /* FALLTHRU */ | |
2522 | ||
2523 | case CONST_DECL: | |
4e0e2698 RH |
2524 | return DECL_RTL_IF_SET (expr); |
2525 | ||
2526 | case INTEGER_CST: | |
2527 | return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER); | |
2528 | ||
2529 | case COMPONENT_REF: | |
2530 | case ARRAY_REF: | |
2531 | case ARRAY_RANGE_REF: | |
2532 | case BIT_FIELD_REF: | |
2533 | { | |
ef4bddc2 | 2534 | machine_mode mode; |
f37fac2b | 2535 | poly_int64 bitsize, bitpos; |
4e0e2698 | 2536 | tree offset, tem; |
ee45a32d | 2537 | int unsignedp, reversep, volatilep = 0; |
4e0e2698 RH |
2538 | rtx x; |
2539 | ||
ee45a32d | 2540 | tem = get_inner_reference (expr, &bitsize, &bitpos, &offset, &mode, |
25b75a48 | 2541 | &unsignedp, &reversep, &volatilep); |
4e0e2698 RH |
2542 | |
2543 | x = dbxout_expand_expr (tem); | |
2544 | if (x == NULL || !MEM_P (x)) | |
2545 | return NULL; | |
2546 | if (offset != NULL) | |
2547 | { | |
9541ffee | 2548 | if (!tree_fits_shwi_p (offset)) |
4e0e2698 | 2549 | return NULL; |
9439e9a1 | 2550 | x = adjust_address_nv (x, mode, tree_to_shwi (offset)); |
4e0e2698 | 2551 | } |
f37fac2b RS |
2552 | if (maybe_ne (bitpos, 0)) |
2553 | x = adjust_address_nv (x, mode, bits_to_bytes_round_down (bitpos)); | |
4e0e2698 RH |
2554 | |
2555 | return x; | |
2556 | } | |
2557 | ||
2558 | default: | |
2559 | return NULL; | |
2560 | } | |
2561 | } | |
2562 | ||
f629051e DJ |
2563 | /* Helper function for output_used_types. Queue one entry from the |
2564 | used types hash to be output. */ | |
2565 | ||
b086d530 TS |
2566 | bool |
2567 | output_used_types_helper (tree const &type, vec<tree> *types_p) | |
f629051e | 2568 | { |
f629051e DJ |
2569 | if ((TREE_CODE (type) == RECORD_TYPE |
2570 | || TREE_CODE (type) == UNION_TYPE | |
2571 | || TREE_CODE (type) == QUAL_UNION_TYPE | |
2572 | || TREE_CODE (type) == ENUMERAL_TYPE) | |
2573 | && TYPE_STUB_DECL (type) | |
2574 | && DECL_P (TYPE_STUB_DECL (type)) | |
2575 | && ! DECL_IGNORED_P (TYPE_STUB_DECL (type))) | |
9771b263 | 2576 | types_p->quick_push (TYPE_STUB_DECL (type)); |
f629051e DJ |
2577 | else if (TYPE_NAME (type) |
2578 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) | |
9771b263 | 2579 | types_p->quick_push (TYPE_NAME (type)); |
f629051e | 2580 | |
b086d530 | 2581 | return true; |
f629051e DJ |
2582 | } |
2583 | ||
88c4be5e DJ |
2584 | /* This is a qsort callback which sorts types and declarations into a |
2585 | predictable order (types, then declarations, sorted by UID | |
2586 | within). */ | |
2587 | ||
2daec0f0 DJ |
2588 | static int |
2589 | output_types_sort (const void *pa, const void *pb) | |
2590 | { | |
2591 | const tree lhs = *((const tree *)pa); | |
2592 | const tree rhs = *((const tree *)pb); | |
2593 | ||
2594 | if (TYPE_P (lhs)) | |
2595 | { | |
2596 | if (TYPE_P (rhs)) | |
2597 | return TYPE_UID (lhs) - TYPE_UID (rhs); | |
2598 | else | |
2599 | return 1; | |
2600 | } | |
2601 | else | |
2602 | { | |
2603 | if (TYPE_P (rhs)) | |
2604 | return -1; | |
2605 | else | |
2606 | return DECL_UID (lhs) - DECL_UID (rhs); | |
2607 | } | |
2608 | } | |
2609 | ||
2610 | ||
f629051e DJ |
2611 | /* Force all types used by this function to be output in debug |
2612 | information. */ | |
88c4be5e | 2613 | |
f629051e DJ |
2614 | static void |
2615 | output_used_types (void) | |
2616 | { | |
2617 | if (cfun && cfun->used_types_hash) | |
2daec0f0 | 2618 | { |
9771b263 | 2619 | vec<tree> types; |
2daec0f0 DJ |
2620 | int i; |
2621 | tree type; | |
2622 | ||
b086d530 TS |
2623 | types.create (cfun->used_types_hash->elements ()); |
2624 | cfun->used_types_hash->traverse<vec<tree> *, output_used_types_helper> | |
2625 | (&types); | |
2daec0f0 DJ |
2626 | |
2627 | /* Sort by UID to prevent dependence on hash table ordering. */ | |
9771b263 | 2628 | types.qsort (output_types_sort); |
2daec0f0 | 2629 | |
9771b263 | 2630 | FOR_EACH_VEC_ELT (types, i, type) |
2daec0f0 | 2631 | debug_queue_symbol (type); |
88c4be5e | 2632 | |
9771b263 | 2633 | types.release (); |
2daec0f0 | 2634 | } |
f629051e DJ |
2635 | } |
2636 | ||
00fe048c RS |
2637 | /* Output a .stabs for the symbol defined by DECL, |
2638 | which must be a ..._DECL node in the normal namespace. | |
2639 | It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL. | |
00262c8a ML |
2640 | LOCAL is nonzero if the scope is less than the entire file. |
2641 | Return 1 if a stabs might have been emitted. */ | |
00fe048c | 2642 | |
00262c8a | 2643 | int |
7080f735 | 2644 | dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED) |
00fe048c | 2645 | { |
00fe048c RS |
2646 | tree type = TREE_TYPE (decl); |
2647 | tree context = NULL_TREE; | |
00262c8a | 2648 | int result = 0; |
9bfa80fb | 2649 | rtx decl_rtl; |
00fe048c | 2650 | |
6a08f7b3 DP |
2651 | /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */ |
2652 | ++debug_nesting; | |
2653 | ||
00fe048c RS |
2654 | /* Ignore nameless syms, but don't ignore type tags. */ |
2655 | ||
2656 | if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL) | |
2657 | || DECL_IGNORED_P (decl)) | |
6a08f7b3 DP |
2658 | DBXOUT_DECR_NESTING_AND_RETURN (0); |
2659 | ||
e0bb17a8 | 2660 | /* If we are to generate only the symbols actually used then such |
aabcd309 | 2661 | symbol nodes are flagged with TREE_USED. Ignore any that |
fa10beec | 2662 | aren't flagged as TREE_USED. */ |
7080f735 | 2663 | |
21d13d83 ZW |
2664 | if (flag_debug_only_used_symbols |
2665 | && (!TREE_USED (decl) | |
8813a647 | 2666 | && (!VAR_P (decl) || !DECL_INITIAL (decl)))) |
21d13d83 ZW |
2667 | DBXOUT_DECR_NESTING_AND_RETURN (0); |
2668 | ||
2669 | /* If dbxout_init has not yet run, queue this symbol for later. */ | |
2670 | if (!typevec) | |
2671 | { | |
2672 | preinit_symbols = tree_cons (0, decl, preinit_symbols); | |
2673 | DBXOUT_DECR_NESTING_AND_RETURN (0); | |
2674 | } | |
2675 | ||
6a08f7b3 DP |
2676 | if (flag_debug_only_used_symbols) |
2677 | { | |
2678 | tree t; | |
2679 | ||
6a08f7b3 DP |
2680 | /* We now have a used symbol. We need to generate the info for |
2681 | the symbol's type in addition to the symbol itself. These | |
2682 | type symbols are queued to be generated after were done with | |
93a27b7b ZW |
2683 | the symbol itself (otherwise they would fight over the |
2684 | stabstr obstack). | |
6a08f7b3 DP |
2685 | |
2686 | Note, because the TREE_TYPE(type) might be something like a | |
2687 | pointer to a named type we need to look for the first name | |
2688 | we see following the TREE_TYPE chain. */ | |
2689 | ||
7080f735 | 2690 | t = type; |
6a08f7b3 DP |
2691 | while (POINTER_TYPE_P (t)) |
2692 | t = TREE_TYPE (t); | |
2693 | ||
2694 | /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE | |
2695 | need special treatment. The TYPE_STUB_DECL field in these | |
2696 | types generally represents the tag name type we want to | |
2697 | output. In addition there could be a typedef type with | |
2698 | a different name. In that case we also want to output | |
2699 | that. */ | |
2700 | ||
75917fc0 | 2701 | if (TREE_CODE (t) == RECORD_TYPE |
6a08f7b3 DP |
2702 | || TREE_CODE (t) == UNION_TYPE |
2703 | || TREE_CODE (t) == QUAL_UNION_TYPE | |
2704 | || TREE_CODE (t) == ENUMERAL_TYPE) | |
6a08f7b3 | 2705 | { |
75917fc0 AP |
2706 | if (TYPE_STUB_DECL (t) |
2707 | && TYPE_STUB_DECL (t) != decl | |
2708 | && DECL_P (TYPE_STUB_DECL (t)) | |
2709 | && ! DECL_IGNORED_P (TYPE_STUB_DECL (t))) | |
2710 | { | |
2711 | debug_queue_symbol (TYPE_STUB_DECL (t)); | |
2712 | if (TYPE_NAME (t) | |
2713 | && TYPE_NAME (t) != TYPE_STUB_DECL (t) | |
2714 | && TYPE_NAME (t) != decl | |
2715 | && DECL_P (TYPE_NAME (t))) | |
2716 | debug_queue_symbol (TYPE_NAME (t)); | |
2717 | } | |
2718 | } | |
6a08f7b3 DP |
2719 | else if (TYPE_NAME (t) |
2720 | && TYPE_NAME (t) != decl | |
6615c446 | 2721 | && DECL_P (TYPE_NAME (t))) |
6a08f7b3 DP |
2722 | debug_queue_symbol (TYPE_NAME (t)); |
2723 | } | |
00fe048c | 2724 | |
33e9d2aa DP |
2725 | emit_pending_bincls_if_required (); |
2726 | ||
00fe048c RS |
2727 | switch (TREE_CODE (decl)) |
2728 | { | |
2729 | case CONST_DECL: | |
2730 | /* Enum values are defined by defining the enum type. */ | |
2731 | break; | |
2732 | ||
2733 | case FUNCTION_DECL: | |
9bfa80fb RH |
2734 | decl_rtl = DECL_RTL_IF_SET (decl); |
2735 | if (!decl_rtl) | |
6a08f7b3 | 2736 | DBXOUT_DECR_NESTING_AND_RETURN (0); |
0924ddef | 2737 | if (DECL_EXTERNAL (decl)) |
00fe048c RS |
2738 | break; |
2739 | /* Don't mention a nested function under its parent. */ | |
2740 | context = decl_function_context (decl); | |
2741 | if (context == current_function_decl) | |
2742 | break; | |
b950a32e EB |
2743 | /* Don't mention an inline instance of a nested function. */ |
2744 | if (context && DECL_FROM_INLINE (decl)) | |
2745 | break; | |
9bfa80fb RH |
2746 | if (!MEM_P (decl_rtl) |
2747 | || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF) | |
00fe048c | 2748 | break; |
00fe048c | 2749 | |
f629051e DJ |
2750 | if (flag_debug_only_used_symbols) |
2751 | output_used_types (); | |
2752 | ||
93a27b7b ZW |
2753 | dbxout_begin_complex_stabs (); |
2754 | stabstr_I (DECL_ASSEMBLER_NAME (decl)); | |
2755 | stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f"); | |
00262c8a | 2756 | result = 1; |
00fe048c | 2757 | |
00fe048c | 2758 | if (TREE_TYPE (type)) |
deda4b76 | 2759 | dbxout_type (TREE_TYPE (type), 0); |
00fe048c | 2760 | else |
deda4b76 | 2761 | dbxout_type (void_type_node, 0); |
00fe048c RS |
2762 | |
2763 | /* For a nested function, when that function is compiled, | |
2764 | mention the containing function name | |
2765 | as well as (since dbx wants it) our own assembler-name. */ | |
2766 | if (context != 0) | |
93a27b7b ZW |
2767 | { |
2768 | stabstr_C (','); | |
2769 | stabstr_I (DECL_ASSEMBLER_NAME (decl)); | |
2770 | stabstr_C (','); | |
2771 | stabstr_I (DECL_NAME (context)); | |
2772 | } | |
00fe048c | 2773 | |
9bfa80fb | 2774 | dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0); |
00fe048c RS |
2775 | break; |
2776 | ||
2777 | case TYPE_DECL: | |
00fe048c RS |
2778 | /* Don't output the same typedef twice. |
2779 | And don't output what language-specific stuff doesn't want output. */ | |
3a83beef | 2780 | if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl)) |
6a08f7b3 | 2781 | DBXOUT_DECR_NESTING_AND_RETURN (0); |
00fe048c | 2782 | |
21d13d83 ZW |
2783 | /* Don't output typedefs for types with magic type numbers (XCOFF). */ |
2784 | #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER | |
2785 | { | |
2786 | int fundamental_type_number = | |
2787 | DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl); | |
2788 | ||
2789 | if (fundamental_type_number != 0) | |
2790 | { | |
2791 | TREE_ASM_WRITTEN (decl) = 1; | |
2792 | TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number; | |
2793 | DBXOUT_DECR_NESTING_AND_RETURN (0); | |
2794 | } | |
2795 | } | |
2796 | #endif | |
00fe048c | 2797 | FORCE_TEXT; |
00262c8a | 2798 | result = 1; |
a823f1d8 RS |
2799 | { |
2800 | int tag_needed = 1; | |
3b6c7a7d | 2801 | int did_output = 0; |
25bdb910 | 2802 | |
a823f1d8 RS |
2803 | if (DECL_NAME (decl)) |
2804 | { | |
2805 | /* Nonzero means we must output a tag as well as a typedef. */ | |
2806 | tag_needed = 0; | |
00fe048c | 2807 | |
edbe40ea RS |
2808 | /* Handle the case of a C++ structure or union |
2809 | where the TYPE_NAME is a TYPE_DECL | |
2810 | which gives both a typedef name and a tag. */ | |
bed7dc7a | 2811 | /* dbx requires the tag first and the typedef second. */ |
edbe40ea | 2812 | if ((TREE_CODE (type) == RECORD_TYPE |
c1b98a95 RK |
2813 | || TREE_CODE (type) == UNION_TYPE |
2814 | || TREE_CODE (type) == QUAL_UNION_TYPE) | |
edbe40ea | 2815 | && TYPE_NAME (type) == decl |
abdafc8e | 2816 | && !use_gnu_debug_info_extensions |
bed7dc7a RS |
2817 | && !TREE_ASM_WRITTEN (TYPE_NAME (type)) |
2818 | /* Distinguish the implicit typedefs of C++ | |
2819 | from explicit ones that might be found in C. */ | |
3a538a66 | 2820 | && DECL_ARTIFICIAL (decl) |
6a08f7b3 DP |
2821 | /* Do not generate a tag for incomplete records. */ |
2822 | && COMPLETE_TYPE_P (type) | |
3342b6fd | 2823 | /* Do not generate a tag for records of variable size, |
67914693 | 2824 | since this type cannot be properly described in the |
3342b6fd | 2825 | DBX format, and it confuses some tools such as objdump. */ |
cc269bb6 | 2826 | && tree_fits_uhwi_p (TYPE_SIZE (type))) |
edbe40ea | 2827 | { |
9dba4b55 | 2828 | tree name = TYPE_IDENTIFIER (type); |
edbe40ea | 2829 | |
93a27b7b ZW |
2830 | dbxout_begin_complex_stabs (); |
2831 | stabstr_I (name); | |
2832 | stabstr_S (":T"); | |
deda4b76 | 2833 | dbxout_type (type, 1); |
93a27b7b ZW |
2834 | dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, |
2835 | 0, 0, 0); | |
edbe40ea RS |
2836 | } |
2837 | ||
93a27b7b | 2838 | dbxout_begin_complex_stabs (); |
b0a93386 | 2839 | |
abdafc8e | 2840 | /* Output leading class/struct qualifiers. */ |
b0a93386 | 2841 | if (use_gnu_debug_info_extensions) |
93a27b7b | 2842 | dbxout_class_name_qualifiers (decl); |
b0a93386 | 2843 | |
a823f1d8 | 2844 | /* Output typedef name. */ |
93a27b7b ZW |
2845 | stabstr_I (DECL_NAME (decl)); |
2846 | stabstr_C (':'); | |
25bdb910 | 2847 | |
a823f1d8 RS |
2848 | /* Short cut way to output a tag also. */ |
2849 | if ((TREE_CODE (type) == RECORD_TYPE | |
c1b98a95 RK |
2850 | || TREE_CODE (type) == UNION_TYPE |
2851 | || TREE_CODE (type) == QUAL_UNION_TYPE) | |
37306b1e RK |
2852 | && TYPE_NAME (type) == decl |
2853 | /* Distinguish the implicit typedefs of C++ | |
2854 | from explicit ones that might be found in C. */ | |
3a538a66 | 2855 | && DECL_ARTIFICIAL (decl)) |
a823f1d8 | 2856 | { |
abdafc8e | 2857 | if (use_gnu_debug_info_extensions) |
a823f1d8 | 2858 | { |
93a27b7b | 2859 | stabstr_C ('T'); |
a823f1d8 RS |
2860 | TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1; |
2861 | } | |
a823f1d8 | 2862 | } |
00fe048c | 2863 | |
93a27b7b | 2864 | stabstr_C ('t'); |
deda4b76 | 2865 | dbxout_type (type, 1); |
93a27b7b ZW |
2866 | dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE, |
2867 | 0, 0, 0); | |
3b6c7a7d | 2868 | did_output = 1; |
a823f1d8 | 2869 | } |
00fe048c | 2870 | |
3342b6fd RK |
2871 | /* Don't output a tag if this is an incomplete type. This prevents |
2872 | the sun4 Sun OS 4.x dbx from crashing. */ | |
83a05a97 | 2873 | |
bf6ed040 RK |
2874 | if (tag_needed && TYPE_NAME (type) != 0 |
2875 | && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE | |
2876 | || (DECL_NAME (TYPE_NAME (type)) != 0)) | |
d0f062fb | 2877 | && COMPLETE_TYPE_P (type) |
a823f1d8 RS |
2878 | && !TREE_ASM_WRITTEN (TYPE_NAME (type))) |
2879 | { | |
2880 | /* For a TYPE_DECL with no name, but the type has a name, | |
2881 | output a tag. | |
2882 | This is what represents `struct foo' with no typedef. */ | |
2883 | /* In C++, the name of a type is the corresponding typedef. | |
2884 | In C, it is an IDENTIFIER_NODE. */ | |
9dba4b55 | 2885 | tree name = TYPE_IDENTIFIER (type); |
a823f1d8 | 2886 | |
93a27b7b ZW |
2887 | dbxout_begin_complex_stabs (); |
2888 | stabstr_I (name); | |
2889 | stabstr_S (":T"); | |
deda4b76 | 2890 | dbxout_type (type, 1); |
93a27b7b | 2891 | dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0); |
3b6c7a7d RS |
2892 | did_output = 1; |
2893 | } | |
2894 | ||
93a27b7b ZW |
2895 | /* If an enum type has no name, it cannot be referred to, but |
2896 | we must output it anyway, to record the enumeration | |
2897 | constants. */ | |
2898 | ||
3b6c7a7d RS |
2899 | if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE) |
2900 | { | |
93a27b7b | 2901 | dbxout_begin_complex_stabs (); |
a63067c2 | 2902 | /* Some debuggers fail when given NULL names, so give this a |
93a27b7b ZW |
2903 | harmless name of " " (Why not "(anon)"?). */ |
2904 | stabstr_S (" :T"); | |
deda4b76 | 2905 | dbxout_type (type, 1); |
93a27b7b | 2906 | dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0); |
a823f1d8 RS |
2907 | } |
2908 | ||
2909 | /* Prevent duplicate output of a typedef. */ | |
2910 | TREE_ASM_WRITTEN (decl) = 1; | |
2911 | break; | |
2912 | } | |
00fe048c RS |
2913 | |
2914 | case PARM_DECL: | |
ed3346c2 EB |
2915 | if (DECL_HAS_VALUE_EXPR_P (decl)) |
2916 | decl = DECL_VALUE_EXPR (decl); | |
2917 | ||
2918 | /* PARM_DECLs go in their own separate chain and are output by | |
2919 | dbxout_reg_parms and dbxout_parms, except for those that are | |
2920 | disguised VAR_DECLs like Out parameters in Ada. */ | |
8813a647 | 2921 | gcc_assert (VAR_P (decl)); |
ed3346c2 | 2922 | |
191816a3 | 2923 | /* fall through */ |
00fe048c RS |
2924 | |
2925 | case RESULT_DECL: | |
00fe048c | 2926 | case VAR_DECL: |
00fe048c RS |
2927 | /* Don't mention a variable that is external. |
2928 | Let the file that defines it describe it. */ | |
0924ddef | 2929 | if (DECL_EXTERNAL (decl)) |
00fe048c RS |
2930 | break; |
2931 | ||
2932 | /* If the variable is really a constant | |
93a27b7b ZW |
2933 | and not written in memory, inform the debugger. |
2934 | ||
2935 | ??? Why do we skip emitting the type and location in this case? */ | |
00fe048c RS |
2936 | if (TREE_STATIC (decl) && TREE_READONLY (decl) |
2937 | && DECL_INITIAL (decl) != 0 | |
9541ffee | 2938 | && tree_fits_shwi_p (DECL_INITIAL (decl)) |
00fe048c | 2939 | && ! TREE_ASM_WRITTEN (decl) |
1787f59e | 2940 | && (DECL_FILE_SCOPE_P (decl) |
d6b27b56 DP |
2941 | || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK |
2942 | || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL) | |
93a27b7b | 2943 | && TREE_PUBLIC (decl) == 0) |
00fe048c | 2944 | { |
93a27b7b | 2945 | /* The sun4 assembler does not grok this. */ |
665f2503 | 2946 | |
93a27b7b ZW |
2947 | if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE |
2948 | || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE) | |
2949 | { | |
eb1ce453 | 2950 | HOST_WIDE_INT ival = tree_to_shwi (DECL_INITIAL (decl)); |
93a27b7b ZW |
2951 | |
2952 | dbxout_begin_complex_stabs (); | |
d6b27b56 DP |
2953 | dbxout_symbol_name (decl, NULL, 'c'); |
2954 | stabstr_S ("=i"); | |
93a27b7b ZW |
2955 | stabstr_D (ival); |
2956 | dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0); | |
2957 | DBXOUT_DECR_NESTING; | |
2958 | return 1; | |
00fe048c | 2959 | } |
93a27b7b ZW |
2960 | else |
2961 | break; | |
00fe048c | 2962 | } |
93a27b7b | 2963 | /* else it is something we handle like a normal variable. */ |
00fe048c | 2964 | |
d6b27b56 DP |
2965 | decl_rtl = dbxout_expand_expr (decl); |
2966 | if (!decl_rtl) | |
2967 | DBXOUT_DECR_NESTING_AND_RETURN (0); | |
2968 | ||
146ca144 BS |
2969 | if (!is_global_var (decl)) |
2970 | decl_rtl = eliminate_regs (decl_rtl, VOIDmode, NULL_RTX); | |
00fe048c | 2971 | #ifdef LEAF_REG_REMAP |
416ff32e | 2972 | if (crtl->uses_only_leaf_regs) |
9bfa80fb | 2973 | leaf_renumber_regs_insn (decl_rtl); |
00fe048c RS |
2974 | #endif |
2975 | ||
9bfa80fb | 2976 | result = dbxout_symbol_location (decl, type, 0, decl_rtl); |
e9a25f70 | 2977 | break; |
3a538a66 | 2978 | |
e9a25f70 JL |
2979 | default: |
2980 | break; | |
47700802 | 2981 | } |
6a08f7b3 | 2982 | DBXOUT_DECR_NESTING; |
00262c8a | 2983 | return result; |
47700802 RS |
2984 | } |
2985 | \f | |
2986 | /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL. | |
2987 | Add SUFFIX to its name, if SUFFIX is not 0. | |
2988 | Describe the variable as residing in HOME | |
00262c8a ML |
2989 | (usually HOME is DECL_RTL (DECL), but not always). |
2990 | Returns 1 if the stab was really emitted. */ | |
47700802 | 2991 | |
00262c8a | 2992 | static int |
7080f735 | 2993 | dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home) |
47700802 RS |
2994 | { |
2995 | int letter = 0; | |
dbb6088f | 2996 | stab_code_type code; |
93a27b7b ZW |
2997 | rtx addr = 0; |
2998 | int number = 0; | |
47700802 | 2999 | int regno = -1; |
00fe048c | 3000 | |
47700802 RS |
3001 | /* Don't mention a variable at all |
3002 | if it was completely optimized into nothingness. | |
3a538a66 | 3003 | |
9ec36da5 | 3004 | If the decl was from an inline function, then its rtl |
47700802 RS |
3005 | is not identically the rtl that was used in this |
3006 | particular compilation. */ | |
c99fa40f | 3007 | if (GET_CODE (home) == SUBREG) |
47700802 RS |
3008 | { |
3009 | rtx value = home; | |
ddef6bc7 | 3010 | |
47700802 | 3011 | while (GET_CODE (value) == SUBREG) |
ddef6bc7 | 3012 | value = SUBREG_REG (value); |
f8cfc6aa | 3013 | if (REG_P (value)) |
00fe048c | 3014 | { |
ddef6bc7 | 3015 | if (REGNO (value) >= FIRST_PSEUDO_REGISTER) |
00262c8a | 3016 | return 0; |
00fe048c | 3017 | } |
55a2c322 | 3018 | home = alter_subreg (&home, true); |
c99fa40f | 3019 | } |
f8cfc6aa | 3020 | if (REG_P (home)) |
c99fa40f RH |
3021 | { |
3022 | regno = REGNO (home); | |
3023 | if (regno >= FIRST_PSEUDO_REGISTER) | |
3024 | return 0; | |
47700802 RS |
3025 | } |
3026 | ||
3027 | /* The kind-of-variable letter depends on where | |
3028 | the variable is and on the scope of its name: | |
3029 | G and N_GSYM for static storage and global scope, | |
3030 | S for static storage and file scope, | |
3031 | V for static storage and local scope, | |
3032 | for those two, use N_LCSYM if data is in bss segment, | |
3033 | N_STSYM if in data segment, N_FUN otherwise. | |
3034 | (We used N_FUN originally, then changed to N_STSYM | |
3035 | to please GDB. However, it seems that confused ld. | |
3036 | Now GDB has been fixed to like N_FUN, says Kingdon.) | |
3037 | no letter at all, and N_LSYM, for auto variable, | |
3038 | r and N_RSYM for register variable. */ | |
3039 | ||
93a27b7b | 3040 | if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF) |
47700802 RS |
3041 | { |
3042 | if (TREE_PUBLIC (decl)) | |
00fe048c | 3043 | { |
7151ffbe | 3044 | int offs; |
47700802 | 3045 | letter = 'G'; |
93a27b7b | 3046 | code = N_GSYM; |
01512446 | 3047 | if (dbxout_common_check (decl, &offs) != NULL) |
7151ffbe GH |
3048 | { |
3049 | letter = 'V'; | |
3050 | addr = 0; | |
3051 | number = offs; | |
3052 | } | |
00fe048c | 3053 | } |
47700802 | 3054 | else |
00fe048c | 3055 | { |
93a27b7b | 3056 | addr = XEXP (home, 0); |
00fe048c | 3057 | |
47700802 | 3058 | letter = decl_function_context (decl) ? 'V' : 'S'; |
00fe048c | 3059 | |
9ff93eb0 UW |
3060 | /* Some ports can transform a symbol ref into a label ref, |
3061 | because the symbol ref is too far away and has to be | |
3062 | dumped into a constant pool. Alternatively, the symbol | |
3063 | in the constant pool might be referenced by a different | |
3064 | symbol. */ | |
3065 | if (GET_CODE (addr) == SYMBOL_REF | |
3066 | && CONSTANT_POOL_ADDRESS_P (addr)) | |
3067 | { | |
3068 | bool marked; | |
3069 | rtx tmp = get_pool_constant_mark (addr, &marked); | |
3070 | ||
3071 | if (GET_CODE (tmp) == SYMBOL_REF) | |
3072 | { | |
3073 | addr = tmp; | |
3074 | if (CONSTANT_POOL_ADDRESS_P (addr)) | |
3075 | get_pool_constant_mark (addr, &marked); | |
3076 | else | |
3077 | marked = true; | |
3078 | } | |
3079 | else if (GET_CODE (tmp) == LABEL_REF) | |
3080 | { | |
3081 | addr = tmp; | |
3082 | marked = true; | |
3083 | } | |
3084 | ||
3085 | /* If all references to the constant pool were optimized | |
3086 | out, we just ignore the symbol. */ | |
3087 | if (!marked) | |
3088 | return 0; | |
3089 | } | |
3090 | ||
6c949b67 JW |
3091 | /* This should be the same condition as in assemble_variable, but |
3092 | we don't have access to dont_output_data here. So, instead, | |
3093 | we rely on the fact that error_mark_node initializers always | |
3094 | end up in bss for C++ and never end up in bss for C. */ | |
3095 | if (DECL_INITIAL (decl) == 0 | |
dcc97066 | 3096 | || (lang_GNU_CXX () |
6c949b67 | 3097 | && DECL_INITIAL (decl) == error_mark_node)) |
7151ffbe GH |
3098 | { |
3099 | int offs; | |
3100 | code = N_LCSYM; | |
01512446 | 3101 | if (dbxout_common_check (decl, &offs) != NULL) |
7151ffbe GH |
3102 | { |
3103 | addr = 0; | |
3104 | number = offs; | |
3105 | letter = 'V'; | |
3106 | code = N_GSYM; | |
3107 | } | |
3108 | } | |
dddfb74b | 3109 | else if (DECL_IN_TEXT_SECTION (decl)) |
47700802 RS |
3110 | /* This is not quite right, but it's the closest |
3111 | of all the codes that Unix defines. */ | |
93a27b7b | 3112 | code = DBX_STATIC_CONST_VAR_CODE; |
47700802 RS |
3113 | else |
3114 | { | |
3115 | /* Ultrix `as' seems to need this. */ | |
00fe048c | 3116 | #ifdef DBX_STATIC_STAB_DATA_SECTION |
d6b5193b | 3117 | switch_to_section (data_section); |
00fe048c | 3118 | #endif |
93a27b7b | 3119 | code = N_STSYM; |
00fe048c RS |
3120 | } |
3121 | } | |
47700802 RS |
3122 | } |
3123 | else if (regno >= 0) | |
3124 | { | |
3125 | letter = 'r'; | |
93a27b7b ZW |
3126 | code = N_RSYM; |
3127 | number = DBX_REGISTER_NUMBER (regno); | |
47700802 | 3128 | } |
3c0cb5de JQ |
3129 | else if (MEM_P (home) |
3130 | && (MEM_P (XEXP (home, 0)) | |
f8cfc6aa | 3131 | || (REG_P (XEXP (home, 0)) |
9571f69b MM |
3132 | && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM |
3133 | && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM | |
e3339d0f | 3134 | #if !HARD_FRAME_POINTER_IS_ARG_POINTER |
9571f69b MM |
3135 | && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM |
3136 | #endif | |
3137 | ))) | |
47700802 RS |
3138 | /* If the value is indirect by memory or by a register |
3139 | that isn't the frame pointer | |
3140 | then it means the object is variable-sized and address through | |
3141 | that register or stack slot. DBX has no way to represent this | |
3142 | so all we can do is output the variable as a pointer. | |
6de9cd9a | 3143 | If it's not a parameter, ignore it. */ |
47700802 | 3144 | { |
f8cfc6aa | 3145 | if (REG_P (XEXP (home, 0))) |
00fe048c RS |
3146 | { |
3147 | letter = 'r'; | |
93a27b7b | 3148 | code = N_RSYM; |
e9716dc5 JJ |
3149 | if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER) |
3150 | return 0; | |
93a27b7b | 3151 | number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0))); |
00fe048c | 3152 | } |
47700802 | 3153 | else |
00fe048c | 3154 | { |
93a27b7b | 3155 | code = N_LSYM; |
47700802 | 3156 | /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))). |
00fe048c | 3157 | We want the value of that CONST_INT. */ |
93a27b7b | 3158 | number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0)); |
b372168c | 3159 | } |
47700802 RS |
3160 | |
3161 | /* Effectively do build_pointer_type, but don't cache this type, | |
3162 | since it might be temporary whereas the type it points to | |
3163 | might have been saved for inlining. */ | |
3164 | /* Don't use REFERENCE_TYPE because dbx can't handle that. */ | |
3165 | type = make_node (POINTER_TYPE); | |
3166 | TREE_TYPE (type) = TREE_TYPE (decl); | |
3167 | } | |
3c0cb5de | 3168 | else if (MEM_P (home) |
f8cfc6aa | 3169 | && REG_P (XEXP (home, 0))) |
47700802 | 3170 | { |
93a27b7b ZW |
3171 | code = N_LSYM; |
3172 | number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0)); | |
47700802 | 3173 | } |
3c0cb5de | 3174 | else if (MEM_P (home) |
47700802 | 3175 | && GET_CODE (XEXP (home, 0)) == PLUS |
481683e1 | 3176 | && CONST_INT_P (XEXP (XEXP (home, 0), 1))) |
47700802 | 3177 | { |
93a27b7b | 3178 | code = N_LSYM; |
47700802 RS |
3179 | /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...))) |
3180 | We want the value of that CONST_INT. */ | |
93a27b7b | 3181 | number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0)); |
47700802 | 3182 | } |
3c0cb5de | 3183 | else if (MEM_P (home) |
47700802 RS |
3184 | && GET_CODE (XEXP (home, 0)) == CONST) |
3185 | { | |
3186 | /* Handle an obscure case which can arise when optimizing and | |
3187 | when there are few available registers. (This is *always* | |
3188 | the case for i386/i486 targets). The RTL looks like | |
3189 | (MEM (CONST ...)) even though this variable is a local `auto' | |
3190 | or a local `register' variable. In effect, what has happened | |
3191 | is that the reload pass has seen that all assignments and | |
3192 | references for one such a local variable can be replaced by | |
3193 | equivalent assignments and references to some static storage | |
3194 | variable, thereby avoiding the need for a register. In such | |
3195 | cases we're forced to lie to debuggers and tell them that | |
3196 | this variable was itself `static'. */ | |
7151ffbe | 3197 | int offs; |
93a27b7b | 3198 | code = N_LCSYM; |
47700802 | 3199 | letter = 'V'; |
01512446 | 3200 | if (dbxout_common_check (decl, &offs) == NULL) |
7151ffbe GH |
3201 | addr = XEXP (XEXP (home, 0), 0); |
3202 | else | |
3203 | { | |
3204 | addr = 0; | |
3205 | number = offs; | |
3206 | code = N_GSYM; | |
3207 | } | |
47700802 RS |
3208 | } |
3209 | else if (GET_CODE (home) == CONCAT) | |
3210 | { | |
02db7776 JO |
3211 | tree subtype; |
3212 | ||
3213 | /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE, | |
3214 | for example), then there is no easy way to figure out | |
3215 | what SUBTYPE should be. So, we give up. */ | |
3216 | if (TREE_CODE (type) != COMPLEX_TYPE) | |
3217 | return 0; | |
3218 | ||
3219 | subtype = TREE_TYPE (type); | |
47700802 RS |
3220 | |
3221 | /* If the variable's storage is in two parts, | |
3222 | output each as a separate stab with a modified name. */ | |
3223 | if (WORDS_BIG_ENDIAN) | |
3224 | dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0)); | |
00fe048c | 3225 | else |
47700802 | 3226 | dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0)); |
00fe048c | 3227 | |
47700802 RS |
3228 | if (WORDS_BIG_ENDIAN) |
3229 | dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1)); | |
3230 | else | |
3231 | dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1)); | |
00262c8a | 3232 | return 1; |
47700802 RS |
3233 | } |
3234 | else | |
3235 | /* Address might be a MEM, when DECL is a variable-sized object. | |
3236 | Or it might be const0_rtx, meaning previous passes | |
3237 | want us to ignore this variable. */ | |
00262c8a | 3238 | return 0; |
47700802 RS |
3239 | |
3240 | /* Ok, start a symtab entry and output the variable name. */ | |
859ee18f ZW |
3241 | emit_pending_bincls_if_required (); |
3242 | FORCE_TEXT; | |
b372168c MM |
3243 | |
3244 | #ifdef DBX_STATIC_BLOCK_START | |
93a27b7b | 3245 | DBX_STATIC_BLOCK_START (asm_out_file, code); |
b372168c MM |
3246 | #endif |
3247 | ||
859ee18f | 3248 | dbxout_begin_complex_stabs_noforcetext (); |
47700802 | 3249 | dbxout_symbol_name (decl, suffix, letter); |
deda4b76 | 3250 | dbxout_type (type, 0); |
93a27b7b | 3251 | dbxout_finish_complex_stabs (decl, code, addr, 0, number); |
b372168c MM |
3252 | |
3253 | #ifdef DBX_STATIC_BLOCK_END | |
93a27b7b | 3254 | DBX_STATIC_BLOCK_END (asm_out_file, code); |
b372168c | 3255 | #endif |
00262c8a | 3256 | return 1; |
47700802 RS |
3257 | } |
3258 | \f | |
3259 | /* Output the symbol name of DECL for a stabs, with suffix SUFFIX. | |
3260 | Then output LETTER to indicate the kind of location the symbol has. */ | |
3261 | ||
3262 | static void | |
7080f735 | 3263 | dbxout_symbol_name (tree decl, const char *suffix, int letter) |
47700802 | 3264 | { |
93a27b7b | 3265 | tree name; |
f9d99dd2 | 3266 | |
b8698a0f | 3267 | if (DECL_CONTEXT (decl) |
a4d8ec65 DP |
3268 | && (TYPE_P (DECL_CONTEXT (decl)) |
3269 | || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)) | |
3270 | /* One slight hitch: if this is a VAR_DECL which is a class member | |
3271 | or a namespace member, we must put out the mangled name instead of the | |
f9d99dd2 JM |
3272 | DECL_NAME. Note also that static member (variable) names DO NOT begin |
3273 | with underscores in .stabs directives. */ | |
93a27b7b | 3274 | name = DECL_ASSEMBLER_NAME (decl); |
f9d99dd2 JM |
3275 | else |
3276 | /* ...but if we're function-local, we don't want to include the junk | |
3277 | added by ASM_FORMAT_PRIVATE_NAME. */ | |
93a27b7b | 3278 | name = DECL_NAME (decl); |
f9d99dd2 | 3279 | |
93a27b7b ZW |
3280 | if (name) |
3281 | stabstr_I (name); | |
3282 | else | |
3283 | stabstr_S ("(anon)"); | |
47700802 | 3284 | |
93a27b7b ZW |
3285 | if (suffix) |
3286 | stabstr_S (suffix); | |
3287 | stabstr_C (':'); | |
02e3f1a8 | 3288 | if (letter) |
93a27b7b | 3289 | stabstr_C (letter); |
00fe048c RS |
3290 | } |
3291 | ||
7151ffbe GH |
3292 | |
3293 | /* Output the common block name for DECL in a stabs. | |
3294 | ||
3295 | Symbols in global common (.comm) get wrapped with an N_BCOMM/N_ECOMM pair | |
3296 | around each group of symbols in the same .comm area. The N_GSYM stabs | |
3297 | that are emitted only contain the offset in the common area. This routine | |
3298 | emits the N_BCOMM and N_ECOMM stabs. */ | |
3299 | ||
3300 | static void | |
dbb6088f | 3301 | dbxout_common_name (tree decl, const char *name, stab_code_type op) |
7151ffbe GH |
3302 | { |
3303 | dbxout_begin_complex_stabs (); | |
3304 | stabstr_S (name); | |
3305 | dbxout_finish_complex_stabs (decl, op, NULL_RTX, NULL, 0); | |
3306 | } | |
3307 | ||
3308 | /* Check decl to determine whether it is a VAR_DECL destined for storage in a | |
3309 | common area. If it is, the return value will be a non-null string giving | |
3310 | the name of the common storage block it will go into. If non-null, the | |
3311 | value is the offset into the common block for that symbol's storage. */ | |
3312 | ||
3313 | static const char * | |
3314 | dbxout_common_check (tree decl, int *value) | |
3315 | { | |
3316 | rtx home; | |
3317 | rtx sym_addr; | |
3318 | const char *name = NULL; | |
b8698a0f | 3319 | |
4d62b56a | 3320 | /* If the decl isn't a VAR_DECL, or if it isn't static, or if |
7151ffbe GH |
3321 | it does not have a value (the offset into the common area), or if it |
3322 | is thread local (as opposed to global) then it isn't common, and shouldn't | |
3323 | be handled as such. | |
b8698a0f | 3324 | |
7151ffbe GH |
3325 | ??? DECL_THREAD_LOCAL_P check prevents problems with improper .stabs |
3326 | for thread-local symbols. Can be handled via same mechanism as used | |
e53b6e56 | 3327 | in dwarf2out.cc. */ |
8813a647 | 3328 | if (!VAR_P (decl) |
c3284718 RS |
3329 | || !TREE_STATIC (decl) |
3330 | || !DECL_HAS_VALUE_EXPR_P (decl) | |
7151ffbe GH |
3331 | || DECL_THREAD_LOCAL_P (decl) |
3332 | || !is_fortran ()) | |
3333 | return NULL; | |
3334 | ||
b8698a0f | 3335 | home = DECL_RTL (decl); |
7151ffbe GH |
3336 | if (home == NULL_RTX || GET_CODE (home) != MEM) |
3337 | return NULL; | |
3338 | ||
3339 | sym_addr = dbxout_expand_expr (DECL_VALUE_EXPR (decl)); | |
3340 | if (sym_addr == NULL_RTX || GET_CODE (sym_addr) != MEM) | |
3341 | return NULL; | |
3342 | ||
3343 | sym_addr = XEXP (sym_addr, 0); | |
3344 | if (GET_CODE (sym_addr) == CONST) | |
3345 | sym_addr = XEXP (sym_addr, 0); | |
3346 | if ((GET_CODE (sym_addr) == SYMBOL_REF || GET_CODE (sym_addr) == PLUS) | |
3347 | && DECL_INITIAL (decl) == 0) | |
3348 | { | |
3349 | ||
3350 | /* We have a sym that will go into a common area, meaning that it | |
3351 | will get storage reserved with a .comm/.lcomm assembler pseudo-op. | |
3352 | ||
3353 | Determine name of common area this symbol will be an offset into, | |
3354 | and offset into that area. Also retrieve the decl for the area | |
3355 | that the symbol is offset into. */ | |
3356 | tree cdecl = NULL; | |
3357 | ||
3358 | switch (GET_CODE (sym_addr)) | |
3359 | { | |
3360 | case PLUS: | |
481683e1 | 3361 | if (CONST_INT_P (XEXP (sym_addr, 0))) |
7151ffbe GH |
3362 | { |
3363 | name = | |
c3284718 | 3364 | targetm.strip_name_encoding (XSTR (XEXP (sym_addr, 1), 0)); |
7151ffbe GH |
3365 | *value = INTVAL (XEXP (sym_addr, 0)); |
3366 | cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 1)); | |
3367 | } | |
3368 | else | |
3369 | { | |
3370 | name = | |
c3284718 | 3371 | targetm.strip_name_encoding (XSTR (XEXP (sym_addr, 0), 0)); |
7151ffbe GH |
3372 | *value = INTVAL (XEXP (sym_addr, 1)); |
3373 | cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 0)); | |
3374 | } | |
3375 | break; | |
3376 | ||
3377 | case SYMBOL_REF: | |
c3284718 | 3378 | name = targetm.strip_name_encoding (XSTR (sym_addr, 0)); |
7151ffbe GH |
3379 | *value = 0; |
3380 | cdecl = SYMBOL_REF_DECL (sym_addr); | |
3381 | break; | |
3382 | ||
3383 | default: | |
3384 | error ("common symbol debug info is not structured as " | |
3385 | "symbol+offset"); | |
3386 | } | |
3387 | ||
3388 | /* Check area common symbol is offset into. If this is not public, then | |
3389 | it is not a symbol in a common block. It must be a .lcomm symbol, not | |
3390 | a .comm symbol. */ | |
c3284718 | 3391 | if (cdecl == NULL || !TREE_PUBLIC (cdecl)) |
7151ffbe GH |
3392 | name = NULL; |
3393 | } | |
3394 | else | |
3395 | name = NULL; | |
3396 | ||
3397 | return name; | |
3398 | } | |
3399 | ||
cc2902df | 3400 | /* Output definitions of all the decls in a chain. Return nonzero if |
00262c8a | 3401 | anything was output */ |
00fe048c | 3402 | |
00262c8a | 3403 | int |
7080f735 | 3404 | dbxout_syms (tree syms) |
00fe048c | 3405 | { |
00262c8a | 3406 | int result = 0; |
7151ffbe GH |
3407 | const char *comm_prev = NULL; |
3408 | tree syms_prev = NULL; | |
3409 | ||
00fe048c RS |
3410 | while (syms) |
3411 | { | |
7151ffbe GH |
3412 | int temp, copen, cclos; |
3413 | const char *comm_new; | |
3414 | ||
3415 | /* Check for common symbol, and then progression into a new/different | |
3416 | block of common symbols. Emit closing/opening common bracket if | |
3417 | necessary. */ | |
3418 | comm_new = dbxout_common_check (syms, &temp); | |
3419 | copen = comm_new != NULL | |
3420 | && (comm_prev == NULL || strcmp (comm_new, comm_prev)); | |
3421 | cclos = comm_prev != NULL | |
3422 | && (comm_new == NULL || strcmp (comm_new, comm_prev)); | |
3423 | if (cclos) | |
3424 | dbxout_common_name (syms_prev, comm_prev, N_ECOMM); | |
3425 | if (copen) | |
3426 | { | |
3427 | dbxout_common_name (syms, comm_new, N_BCOMM); | |
3428 | syms_prev = syms; | |
3429 | } | |
3430 | comm_prev = comm_new; | |
3431 | ||
00262c8a | 3432 | result += dbxout_symbol (syms, 1); |
910ad8de | 3433 | syms = DECL_CHAIN (syms); |
00fe048c | 3434 | } |
7151ffbe GH |
3435 | |
3436 | if (comm_prev != NULL) | |
3437 | dbxout_common_name (syms_prev, comm_prev, N_ECOMM); | |
3438 | ||
00262c8a | 3439 | return result; |
00fe048c RS |
3440 | } |
3441 | \f | |
3442 | /* The following two functions output definitions of function parameters. | |
3443 | Each parameter gets a definition locating it in the parameter list. | |
3444 | Each parameter that is a register variable gets a second definition | |
3445 | locating it in the register. | |
3446 | ||
3447 | Printing or argument lists in gdb uses the definitions that | |
3448 | locate in the parameter list. But reference to the variable in | |
3449 | expressions uses preferentially the definition as a register. */ | |
3450 | ||
3451 | /* Output definitions, referring to storage in the parmlist, | |
3452 | of all the parms in PARMS, which is a chain of PARM_DECL nodes. */ | |
3453 | ||
b372168c | 3454 | void |
7080f735 | 3455 | dbxout_parms (tree parms) |
00fe048c | 3456 | { |
6a08f7b3 | 3457 | ++debug_nesting; |
33e9d2aa | 3458 | emit_pending_bincls_if_required (); |
ef1d3b57 | 3459 | fixed_size_mode rtl_mode, type_mode; |
33e9d2aa | 3460 | |
910ad8de | 3461 | for (; parms; parms = DECL_CHAIN (parms)) |
7a3e01c4 JDA |
3462 | if (DECL_NAME (parms) |
3463 | && TREE_TYPE (parms) != error_mark_node | |
3464 | && DECL_RTL_SET_P (parms) | |
ef1d3b57 RS |
3465 | && DECL_INCOMING_RTL (parms) |
3466 | /* We can't represent variable-sized types in this format. */ | |
3467 | && is_a <fixed_size_mode> (TYPE_MODE (TREE_TYPE (parms)), &type_mode) | |
3468 | && is_a <fixed_size_mode> (GET_MODE (DECL_RTL (parms)), &rtl_mode)) | |
00fe048c | 3469 | { |
93a27b7b ZW |
3470 | tree eff_type; |
3471 | char letter; | |
dbb6088f | 3472 | stab_code_type code; |
93a27b7b | 3473 | int number; |
00fe048c RS |
3474 | |
3475 | /* Perform any necessary register eliminations on the parameter's rtl, | |
3476 | so that the debugging output will be accurate. */ | |
3477 | DECL_INCOMING_RTL (parms) | |
bbbbb16a ILT |
3478 | = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX); |
3479 | SET_DECL_RTL (parms, | |
3480 | eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX)); | |
00fe048c | 3481 | #ifdef LEAF_REG_REMAP |
416ff32e | 3482 | if (crtl->uses_only_leaf_regs) |
00fe048c RS |
3483 | { |
3484 | leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms)); | |
3485 | leaf_renumber_regs_insn (DECL_RTL (parms)); | |
3486 | } | |
3487 | #endif | |
3488 | ||
3489 | if (PARM_PASSED_IN_MEMORY (parms)) | |
3490 | { | |
93a27b7b | 3491 | rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0); |
00fe048c RS |
3492 | |
3493 | /* ??? Here we assume that the parm address is indexed | |
3494 | off the frame pointer or arg pointer. | |
3495 | If that is not true, we produce meaningless results, | |
3496 | but do not crash. */ | |
93a27b7b | 3497 | if (GET_CODE (inrtl) == PLUS |
481683e1 | 3498 | && CONST_INT_P (XEXP (inrtl, 1))) |
93a27b7b | 3499 | number = INTVAL (XEXP (inrtl, 1)); |
00fe048c | 3500 | else |
93a27b7b ZW |
3501 | number = 0; |
3502 | ||
3503 | code = N_PSYM; | |
3504 | number = DEBUGGER_ARG_OFFSET (number, inrtl); | |
3505 | letter = 'p'; | |
3506 | ||
3507 | /* It is quite tempting to use TREE_TYPE (parms) instead | |
3508 | of DECL_ARG_TYPE (parms) for the eff_type, so that gcc | |
3509 | reports the actual type of the parameter, rather than | |
3510 | the promoted type. This certainly makes GDB's life | |
3511 | easier, at least for some ports. The change is a bad | |
3512 | idea however, since GDB expects to be able access the | |
3513 | type without performing any conversions. So for | |
3514 | example, if we were passing a float to an unprototyped | |
3515 | function, gcc will store a double on the stack, but if | |
3516 | we emit a stab saying the type is a float, then gdb | |
3517 | will only read in a single value, and this will produce | |
3518 | an erroneous value. */ | |
3519 | eff_type = DECL_ARG_TYPE (parms); | |
00fe048c | 3520 | } |
f8cfc6aa | 3521 | else if (REG_P (DECL_RTL (parms))) |
00fe048c RS |
3522 | { |
3523 | rtx best_rtl; | |
25b5c537 | 3524 | |
93a27b7b ZW |
3525 | /* Parm passed in registers and lives in registers or nowhere. */ |
3526 | code = DBX_REGPARM_STABS_CODE; | |
3527 | letter = DBX_REGPARM_STABS_LETTER; | |
3528 | ||
3529 | /* For parms passed in registers, it is better to use the | |
3530 | declared type of the variable, not the type it arrived in. */ | |
3531 | eff_type = TREE_TYPE (parms); | |
3532 | ||
3533 | /* If parm lives in a register, use that register; pretend | |
3534 | the parm was passed there. It would be more consistent | |
3535 | to describe the register where the parm was passed, but | |
3536 | in practice that register usually holds something else. | |
3537 | If the parm lives nowhere, use the register where it | |
3538 | was passed. */ | |
770ae6cc | 3539 | if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) |
93a27b7b | 3540 | best_rtl = DECL_RTL (parms); |
116612b9 EB |
3541 | else if (GET_CODE (DECL_INCOMING_RTL (parms)) == PARALLEL) |
3542 | best_rtl = XEXP (XVECEXP (DECL_INCOMING_RTL (parms), 0, 0), 0); | |
00fe048c | 3543 | else |
93a27b7b | 3544 | best_rtl = DECL_INCOMING_RTL (parms); |
00fe048c | 3545 | |
93a27b7b | 3546 | number = DBX_REGISTER_NUMBER (REGNO (best_rtl)); |
00fe048c | 3547 | } |
3c0cb5de | 3548 | else if (MEM_P (DECL_RTL (parms)) |
f8cfc6aa | 3549 | && REG_P (XEXP (DECL_RTL (parms), 0)) |
b205fb6f JW |
3550 | && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM |
3551 | && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM | |
e3339d0f | 3552 | #if !HARD_FRAME_POINTER_IS_ARG_POINTER |
b205fb6f JW |
3553 | && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM |
3554 | #endif | |
3555 | ) | |
dad0145a RS |
3556 | { |
3557 | /* Parm was passed via invisible reference. | |
3558 | That is, its address was passed in a register. | |
3559 | Output it as if it lived in that register. | |
3560 | The debugger will know from the type | |
4828a73e | 3561 | that it was actually passed by invisible reference. */ |
ac746f1d | 3562 | |
93a27b7b | 3563 | code = DBX_REGPARM_STABS_CODE; |
b8698a0f | 3564 | |
93a27b7b ZW |
3565 | /* GDB likes this marked with a special letter. */ |
3566 | letter = (use_gnu_debug_info_extensions | |
3567 | ? 'a' : DBX_REGPARM_STABS_LETTER); | |
3568 | eff_type = TREE_TYPE (parms); | |
dad0145a | 3569 | |
4e6ee267 JW |
3570 | /* DECL_RTL looks like (MEM (REG...). Get the register number. |
3571 | If it is an unallocated pseudo-reg, then use the register where | |
93a27b7b ZW |
3572 | it was passed instead. |
3573 | ??? Why is DBX_REGISTER_NUMBER not used here? */ | |
4e6ee267 | 3574 | |
93a27b7b ZW |
3575 | if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER) |
3576 | number = REGNO (XEXP (DECL_RTL (parms), 0)); | |
dad0145a | 3577 | else |
93a27b7b | 3578 | number = REGNO (DECL_INCOMING_RTL (parms)); |
dad0145a | 3579 | } |
3c0cb5de JQ |
3580 | else if (MEM_P (DECL_RTL (parms)) |
3581 | && MEM_P (XEXP (DECL_RTL (parms), 0))) | |
27646dba JB |
3582 | { |
3583 | /* Parm was passed via invisible reference, with the reference | |
3584 | living on the stack. DECL_RTL looks like | |
ebb0cdf3 CM |
3585 | (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it |
3586 | could look like (MEM (MEM (REG))). */ | |
93a27b7b ZW |
3587 | |
3588 | code = N_PSYM; | |
3589 | letter = 'v'; | |
3590 | eff_type = TREE_TYPE (parms); | |
3591 | ||
3592 | if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0))) | |
3593 | number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1)); | |
ebb0cdf3 | 3594 | else |
93a27b7b ZW |
3595 | number = 0; |
3596 | ||
3597 | number = DEBUGGER_ARG_OFFSET (number, | |
3598 | XEXP (XEXP (DECL_RTL (parms), 0), 0)); | |
27646dba | 3599 | } |
3c0cb5de | 3600 | else if (MEM_P (DECL_RTL (parms)) |
8d291181 RS |
3601 | && XEXP (DECL_RTL (parms), 0) != const0_rtx |
3602 | /* ??? A constant address for a parm can happen | |
3603 | when the reg it lives in is equiv to a constant in memory. | |
3604 | Should make this not happen, after 2.4. */ | |
3605 | && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0))) | |
00fe048c RS |
3606 | { |
3607 | /* Parm was passed in registers but lives on the stack. */ | |
3608 | ||
93a27b7b ZW |
3609 | code = N_PSYM; |
3610 | letter = 'p'; | |
3611 | eff_type = TREE_TYPE (parms); | |
3612 | ||
00fe048c RS |
3613 | /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))), |
3614 | in which case we want the value of that CONST_INT, | |
27646dba | 3615 | or (MEM (REG ...)), |
00fe048c | 3616 | in which case we use a value of zero. */ |
93a27b7b ZW |
3617 | if (!REG_P (XEXP (DECL_RTL (parms), 0))) |
3618 | number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)); | |
00fe048c | 3619 | else |
93a27b7b | 3620 | number = 0; |
00fe048c | 3621 | |
620422fd DE |
3622 | /* Make a big endian correction if the mode of the type of the |
3623 | parameter is not the same as the mode of the rtl. */ | |
3624 | if (BYTES_BIG_ENDIAN | |
ef1d3b57 RS |
3625 | && type_mode != rtl_mode |
3626 | && GET_MODE_SIZE (type_mode) < UNITS_PER_WORD) | |
3627 | number += GET_MODE_SIZE (rtl_mode) - GET_MODE_SIZE (type_mode); | |
93a27b7b ZW |
3628 | } |
3629 | else | |
3630 | /* ??? We don't know how to represent this argument. */ | |
3631 | continue; | |
00fe048c | 3632 | |
93a27b7b | 3633 | dbxout_begin_complex_stabs (); |
b8698a0f | 3634 | |
93a27b7b ZW |
3635 | if (DECL_NAME (parms)) |
3636 | { | |
3637 | stabstr_I (DECL_NAME (parms)); | |
3638 | stabstr_C (':'); | |
00fe048c | 3639 | } |
93a27b7b ZW |
3640 | else |
3641 | stabstr_S ("(anon):"); | |
3642 | stabstr_C (letter); | |
3643 | dbxout_type (eff_type, 0); | |
3644 | dbxout_finish_complex_stabs (parms, code, 0, 0, number); | |
00fe048c | 3645 | } |
6a08f7b3 | 3646 | DBXOUT_DECR_NESTING; |
00fe048c RS |
3647 | } |
3648 | ||
3649 | /* Output definitions for the places where parms live during the function, | |
3650 | when different from where they were passed, when the parms were passed | |
3651 | in memory. | |
3652 | ||
3653 | It is not useful to do this for parms passed in registers | |
3654 | that live during the function in different registers, because it is | |
3655 | impossible to look in the passed register for the passed value, | |
3656 | so we use the within-the-function register to begin with. | |
3657 | ||
3658 | PARMS is a chain of PARM_DECL nodes. */ | |
3659 | ||
b372168c | 3660 | void |
7080f735 | 3661 | dbxout_reg_parms (tree parms) |
00fe048c | 3662 | { |
6a08f7b3 DP |
3663 | ++debug_nesting; |
3664 | ||
910ad8de | 3665 | for (; parms; parms = DECL_CHAIN (parms)) |
dc2fba60 | 3666 | if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms)) |
00fe048c | 3667 | { |
00fe048c RS |
3668 | /* Report parms that live in registers during the function |
3669 | but were passed in memory. */ | |
f8cfc6aa | 3670 | if (REG_P (DECL_RTL (parms)) |
dc2fba60 | 3671 | && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) |
47700802 RS |
3672 | dbxout_symbol_location (parms, TREE_TYPE (parms), |
3673 | 0, DECL_RTL (parms)); | |
dc2fba60 | 3674 | else if (GET_CODE (DECL_RTL (parms)) == CONCAT) |
47700802 RS |
3675 | dbxout_symbol_location (parms, TREE_TYPE (parms), |
3676 | 0, DECL_RTL (parms)); | |
00fe048c | 3677 | /* Report parms that live in memory but not where they were passed. */ |
3c0cb5de | 3678 | else if (MEM_P (DECL_RTL (parms)) |
00fe048c | 3679 | && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms))) |
dc2fba60 JW |
3680 | dbxout_symbol_location (parms, TREE_TYPE (parms), |
3681 | 0, DECL_RTL (parms)); | |
00fe048c | 3682 | } |
6a08f7b3 | 3683 | DBXOUT_DECR_NESTING; |
00fe048c RS |
3684 | } |
3685 | \f | |
3686 | /* Given a chain of ..._TYPE nodes (as come in a parameter list), | |
3687 | output definitions of those names, in raw form */ | |
3688 | ||
e1772ac0 | 3689 | static void |
7080f735 | 3690 | dbxout_args (tree args) |
00fe048c RS |
3691 | { |
3692 | while (args) | |
3693 | { | |
93a27b7b | 3694 | stabstr_C (','); |
deda4b76 | 3695 | dbxout_type (TREE_VALUE (args), 0); |
00fe048c RS |
3696 | args = TREE_CHAIN (args); |
3697 | } | |
3698 | } | |
3699 | \f | |
b420396f OH |
3700 | #if defined (DBX_DEBUGGING_INFO) |
3701 | ||
7e2e8179 ZW |
3702 | /* Subroutine of dbxout_block. Emit an N_LBRAC stab referencing LABEL. |
3703 | BEGIN_LABEL is the name of the beginning of the function, which may | |
3704 | be required. */ | |
3705 | static void | |
3706 | dbx_output_lbrac (const char *label, | |
3707 | const char *begin_label ATTRIBUTE_UNUSED) | |
3708 | { | |
93a27b7b | 3709 | dbxout_begin_stabn (N_LBRAC); |
3e487b21 | 3710 | if (DBX_BLOCKS_FUNCTION_RELATIVE) |
93a27b7b ZW |
3711 | dbxout_stab_value_label_diff (label, begin_label); |
3712 | else | |
3713 | dbxout_stab_value_label (label); | |
7e2e8179 ZW |
3714 | } |
3715 | ||
3716 | /* Subroutine of dbxout_block. Emit an N_RBRAC stab referencing LABEL. | |
3717 | BEGIN_LABEL is the name of the beginning of the function, which may | |
3718 | be required. */ | |
3719 | static void | |
3720 | dbx_output_rbrac (const char *label, | |
3721 | const char *begin_label ATTRIBUTE_UNUSED) | |
3722 | { | |
93a27b7b | 3723 | dbxout_begin_stabn (N_RBRAC); |
3e487b21 | 3724 | if (DBX_BLOCKS_FUNCTION_RELATIVE) |
93a27b7b ZW |
3725 | dbxout_stab_value_label_diff (label, begin_label); |
3726 | else | |
3727 | dbxout_stab_value_label (label); | |
7e2e8179 ZW |
3728 | } |
3729 | ||
5a198ba9 JJ |
3730 | /* Return true if at least one block among BLOCK, its children or siblings |
3731 | has TREE_USED, TREE_ASM_WRITTEN and BLOCK_IN_COLD_SECTION_P | |
b8cb3096 JJ |
3732 | set. If there is none, clear TREE_USED bit on such blocks. */ |
3733 | ||
3734 | static bool | |
3735 | dbx_block_with_cold_children (tree block) | |
3736 | { | |
3737 | bool ret = false; | |
3738 | for (; block; block = BLOCK_CHAIN (block)) | |
3739 | if (TREE_USED (block) && TREE_ASM_WRITTEN (block)) | |
3740 | { | |
3741 | bool children = dbx_block_with_cold_children (BLOCK_SUBBLOCKS (block)); | |
3742 | if (BLOCK_IN_COLD_SECTION_P (block) || children) | |
3743 | ret = true; | |
3744 | else | |
3745 | TREE_USED (block) = false; | |
3746 | } | |
3747 | return ret; | |
3748 | } | |
3749 | ||
00fe048c RS |
3750 | /* Output everything about a symbol block (a BLOCK node |
3751 | that represents a scope level), | |
3752 | including recursive output of contained blocks. | |
3753 | ||
3754 | BLOCK is the BLOCK node. | |
3755 | DEPTH is its depth within containing symbol blocks. | |
3756 | ARGS is usually zero; but for the outermost block of the | |
3757 | body of a function, it is a chain of PARM_DECLs for the function parameters. | |
3758 | We output definitions of all the register parms | |
3759 | as if they were local variables of that block. | |
3760 | ||
3761 | If -g1 was used, we count blocks just the same, but output nothing | |
3762 | except for the outermost block. | |
3763 | ||
3764 | Actually, BLOCK may be several blocks chained together. | |
b8cb3096 | 3765 | We handle them all in sequence. |
00fe048c | 3766 | |
b8cb3096 JJ |
3767 | Return true if we emitted any LBRAC/RBRAC. */ |
3768 | ||
3769 | static bool | |
3770 | dbxout_block (tree block, int depth, tree args, int parent_blocknum) | |
00fe048c | 3771 | { |
b8cb3096 | 3772 | bool ret = false; |
03471b3f CD |
3773 | char begin_label[20]; |
3774 | /* Reference current function start using LFBB. */ | |
3775 | ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno); | |
00fe048c | 3776 | |
b8cb3096 JJ |
3777 | /* If called for the second partition, ignore blocks that don't have |
3778 | any children in the second partition. */ | |
3779 | if (crtl->has_bb_partition && in_cold_section_p && depth == 0) | |
3780 | dbx_block_with_cold_children (block); | |
3781 | ||
3782 | for (; block; block = BLOCK_CHAIN (block)) | |
00fe048c RS |
3783 | { |
3784 | /* Ignore blocks never expanded or otherwise marked as real. */ | |
5b4c43d7 | 3785 | if (TREE_USED (block) && TREE_ASM_WRITTEN (block)) |
00fe048c | 3786 | { |
711d4bb3 | 3787 | int did_output; |
7e2e8179 | 3788 | int blocknum = BLOCK_NUMBER (block); |
b8cb3096 | 3789 | int this_parent = parent_blocknum; |
711d4bb3 | 3790 | |
00262c8a | 3791 | /* In dbx format, the syms of a block come before the N_LBRAC. |
30f7a378 | 3792 | If nothing is output, we don't need the N_LBRAC, either. */ |
711d4bb3 | 3793 | did_output = 0; |
00fe048c | 3794 | if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0) |
711d4bb3 | 3795 | did_output = dbxout_syms (BLOCK_VARS (block)); |
00fe048c RS |
3796 | if (args) |
3797 | dbxout_reg_parms (args); | |
00fe048c RS |
3798 | |
3799 | /* Now output an N_LBRAC symbol to represent the beginning of | |
3800 | the block. Use the block's tree-walk order to generate | |
3801 | the assembler symbols LBBn and LBEn | |
3802 | that final will define around the code in this block. */ | |
b8cb3096 JJ |
3803 | if (did_output |
3804 | && BLOCK_IN_COLD_SECTION_P (block) == in_cold_section_p) | |
00fe048c RS |
3805 | { |
3806 | char buf[20]; | |
7e2e8179 ZW |
3807 | const char *scope_start; |
3808 | ||
b8cb3096 | 3809 | ret = true; |
7e2e8179 ZW |
3810 | if (depth == 0) |
3811 | /* The outermost block doesn't get LBB labels; use | |
03471b3f | 3812 | the LFBB local symbol emitted by dbxout_begin_prologue. */ |
7e2e8179 ZW |
3813 | scope_start = begin_label; |
3814 | else | |
3815 | { | |
3816 | ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum); | |
3817 | scope_start = buf; | |
b8cb3096 | 3818 | this_parent = blocknum; |
7e2e8179 | 3819 | } |
00fe048c | 3820 | |
7e2e8179 | 3821 | dbx_output_lbrac (scope_start, begin_label); |
00fe048c | 3822 | } |
00fe048c | 3823 | |
00fe048c | 3824 | /* Output the subblocks. */ |
b8cb3096 JJ |
3825 | bool children |
3826 | = dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE, | |
3827 | this_parent); | |
3828 | ret |= children; | |
00fe048c RS |
3829 | |
3830 | /* Refer to the marker for the end of the block. */ | |
b8cb3096 JJ |
3831 | if (did_output |
3832 | && BLOCK_IN_COLD_SECTION_P (block) == in_cold_section_p) | |
00fe048c | 3833 | { |
7e2e8179 ZW |
3834 | char buf[100]; |
3835 | if (depth == 0) | |
3836 | /* The outermost block doesn't get LBE labels; | |
3837 | use the "scope" label which will be emitted | |
3838 | by dbxout_function_end. */ | |
3839 | ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno); | |
3840 | else | |
3841 | ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum); | |
3842 | ||
3843 | dbx_output_rbrac (buf, begin_label); | |
00fe048c | 3844 | } |
b8cb3096 JJ |
3845 | else if (did_output && !children) |
3846 | { | |
3847 | /* If we emitted any vars and didn't output any LBRAC/RBRAC, | |
3848 | either at this level or any lower level, we need to emit | |
3849 | an empty LBRAC/RBRAC pair now. */ | |
bf2f5c89 | 3850 | char buf[30]; |
b8cb3096 JJ |
3851 | const char *scope_start; |
3852 | ||
3853 | ret = true; | |
3854 | if (parent_blocknum == -1) | |
3855 | scope_start = begin_label; | |
3856 | else | |
3857 | { | |
3858 | ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", parent_blocknum); | |
3859 | scope_start = buf; | |
3860 | } | |
3861 | ||
3862 | dbx_output_lbrac (scope_start, begin_label); | |
3863 | dbx_output_rbrac (scope_start, begin_label); | |
3864 | } | |
00fe048c | 3865 | } |
00fe048c | 3866 | } |
b8cb3096 | 3867 | return ret; |
00fe048c RS |
3868 | } |
3869 | ||
3870 | /* Output the information about a function and its arguments and result. | |
3871 | Usually this follows the function's code, | |
3872 | but on some systems, it comes before. */ | |
3873 | ||
3874 | static void | |
7080f735 | 3875 | dbxout_begin_function (tree decl) |
00fe048c | 3876 | { |
847d0c08 RH |
3877 | int saved_tree_used1; |
3878 | ||
847d0c08 | 3879 | saved_tree_used1 = TREE_USED (decl); |
6a08f7b3 DP |
3880 | TREE_USED (decl) = 1; |
3881 | if (DECL_NAME (DECL_RESULT (decl)) != 0) | |
3882 | { | |
7080f735 | 3883 | int saved_tree_used2 = TREE_USED (DECL_RESULT (decl)); |
6a08f7b3 DP |
3884 | TREE_USED (DECL_RESULT (decl)) = 1; |
3885 | dbxout_symbol (decl, 0); | |
3886 | TREE_USED (DECL_RESULT (decl)) = saved_tree_used2; | |
3887 | } | |
3888 | else | |
3889 | dbxout_symbol (decl, 0); | |
3890 | TREE_USED (decl) = saved_tree_used1; | |
3891 | ||
00fe048c RS |
3892 | dbxout_parms (DECL_ARGUMENTS (decl)); |
3893 | if (DECL_NAME (DECL_RESULT (decl)) != 0) | |
3894 | dbxout_symbol (DECL_RESULT (decl), 1); | |
3895 | } | |
c3fb23f4 | 3896 | #endif /* DBX_DEBUGGING_INFO */ |
00fe048c | 3897 | |
4f70758f | 3898 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ |
17211ab5 | 3899 | |
be7a421e SB |
3900 | /* Record an element in the table of global destructors. SYMBOL is |
3901 | a SYMBOL_REF of the function to be called; PRIORITY is a number | |
3902 | between 0 and MAX_INIT_PRIORITY. */ | |
3903 | ||
3904 | void | |
3905 | default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED, | |
3906 | int priority ATTRIBUTE_UNUSED) | |
3907 | { | |
3908 | #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO | |
3909 | /* Tell GNU LD that this is part of the static destructor set. | |
3910 | This will work for any system that uses stabs, most usefully | |
3911 | aout systems. */ | |
3912 | dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */); | |
3913 | dbxout_stab_value_label (XSTR (symbol, 0)); | |
3914 | #else | |
3915 | sorry ("global destructors not supported on this target"); | |
3916 | #endif | |
3917 | } | |
3918 | ||
3919 | /* Likewise for global constructors. */ | |
3920 | ||
3921 | void | |
3922 | default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED, | |
3923 | int priority ATTRIBUTE_UNUSED) | |
3924 | { | |
3925 | #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO | |
3926 | /* Tell GNU LD that this is part of the static destructor set. | |
3927 | This will work for any system that uses stabs, most usefully | |
3928 | aout systems. */ | |
3929 | dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */); | |
3930 | dbxout_stab_value_label (XSTR (symbol, 0)); | |
3931 | #else | |
3932 | sorry ("global constructors not supported on this target"); | |
3933 | #endif | |
3934 | } | |
3935 | ||
17211ab5 | 3936 | #include "gt-dbxout.h" |