Don't use #if inside C test expression.
[gcc.git] / gcc / dwarfout.c
1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 /*
24
25 Notes on the GNU Implementation of DWARF Debugging Information
26 --------------------------------------------------------------
27 Last Major Update: Sun Jul 17 08:17:42 PDT 1994 by rfg@segfault.us.com
28 ------------------------------------------------------------
29
30 This file describes special and unique aspects of the GNU implementation of
31 the DWARF Version 1 debugging information language, as provided in the GNU
32 version 2.x compiler(s).
33
34 For general information about the DWARF debugging information language,
35 you should obtain the DWARF version 1.1 specification document (and perhaps
36 also the DWARF version 2 draft specification document) developed by the
37 (now defunct) UNIX International Programming Languages Special Interest Group.
38
39 To obtain a copy of the DWARF Version 1 and/or DWARF Version 2
40 specification, visit the web page for the DWARF Version 2 committee, at
41
42 http://www.eagercon.com/dwarf/dwarf2std.htm
43
44 The generation of DWARF debugging information by the GNU version 2.x C
45 compiler has now been tested rather extensively for m88k, i386, i860, and
46 Sparc targets. The DWARF output of the GNU C compiler appears to inter-
47 operate well with the standard SVR4 SDB debugger on these kinds of target
48 systems (but of course, there are no guarantees).
49
50 DWARF 1 generation for the GNU g++ compiler is implemented, but limited.
51 C++ users should definitely use DWARF 2 instead.
52
53 Future plans for the dwarfout.c module of the GNU compiler(s) includes the
54 addition of full support for GNU FORTRAN. (This should, in theory, be a
55 lot simpler to add than adding support for g++... but we'll see.)
56
57 Many features of the DWARF version 2 specification have been adapted to
58 (and used in) the GNU implementation of DWARF (version 1). In most of
59 these cases, a DWARF version 2 approach is used in place of (or in addition
60 to) DWARF version 1 stuff simply because it is apparent that DWARF version
61 1 is not sufficiently expressive to provide the kinds of information which
62 may be necessary to support really robust debugging. In all of these cases
63 however, the use of DWARF version 2 features should not interfere in any
64 way with the interoperability (of GNU compilers) with generally available
65 "classic" (pre version 1) DWARF consumer tools (e.g. SVR4 SDB).
66
67 The DWARF generation enhancement for the GNU compiler(s) was initially
68 donated to the Free Software Foundation by Network Computing Devices.
69 (Thanks NCD!) Additional development and maintenance of dwarfout.c has
70 been largely supported (i.e. funded) by Intel Corporation. (Thanks Intel!)
71
72 If you have questions or comments about the DWARF generation feature, please
73 send mail to me <rfg@netcom.com>. I will be happy to investigate any bugs
74 reported and I may even provide fixes (but of course, I can make no promises).
75
76 The DWARF debugging information produced by GCC may deviate in a few minor
77 (but perhaps significant) respects from the DWARF debugging information
78 currently produced by other C compilers. A serious attempt has been made
79 however to conform to the published specifications, to existing practice,
80 and to generally accepted norms in the GNU implementation of DWARF.
81
82 ** IMPORTANT NOTE ** ** IMPORTANT NOTE ** ** IMPORTANT NOTE **
83
84 Under normal circumstances, the DWARF information generated by the GNU
85 compilers (in an assembly language file) is essentially impossible for
86 a human being to read. This fact can make it very difficult to debug
87 certain DWARF-related problems. In order to overcome this difficulty,
88 a feature has been added to dwarfout.c (enabled by the -dA
89 option) which causes additional comments to be placed into the assembly
90 language output file, out to the right-hand side of most bits of DWARF
91 material. The comments indicate (far more clearly that the obscure
92 DWARF hex codes do) what is actually being encoded in DWARF. Thus, the
93 -dA option can be highly useful for those who must study the
94 DWARF output from the GNU compilers in detail.
95
96 ---------
97
98 (Footnote: Within this file, the term `Debugging Information Entry' will
99 be abbreviated as `DIE'.)
100
101
102 Release Notes (aka known bugs)
103 -------------------------------
104
105 In one very obscure case involving dynamically sized arrays, the DWARF
106 "location information" for such an array may make it appear that the
107 array has been totally optimized out of existence, when in fact it
108 *must* actually exist. (This only happens when you are using *both* -g
109 *and* -O.) This is due to aggressive dead store elimination in the
110 compiler, and to the fact that the DECL_RTL expressions associated with
111 variables are not always updated to correctly reflect the effects of
112 GCC's aggressive dead store elimination.
113
114 -------------------------------
115
116 When attempting to set a breakpoint at the "start" of a function compiled
117 with -g1, the debugger currently has no way of knowing exactly where the
118 end of the prologue code for the function is. Thus, for most targets,
119 all the debugger can do is to set the breakpoint at the AT_low_pc address
120 for the function. But if you stop there and then try to look at one or
121 more of the formal parameter values, they may not have been "homed" yet,
122 so you may get inaccurate answers (or perhaps even addressing errors).
123
124 Some people may consider this simply a non-feature, but I consider it a
125 bug, and I hope to provide some GNU-specific attributes (on function
126 DIEs) which will specify the address of the end of the prologue and the
127 address of the beginning of the epilogue in a future release.
128
129 -------------------------------
130
131 It is believed at this time that old bugs relating to the AT_bit_offset
132 values for bit-fields have been fixed.
133
134 There may still be some very obscure bugs relating to the DWARF description
135 of type `long long' bit-fields for target machines (e.g. 80x86 machines)
136 where the alignment of type `long long' data objects is different from
137 (and less than) the size of a type `long long' data object.
138
139 Please report any problems with the DWARF description of bit-fields as you
140 would any other GCC bug. (Procedures for bug reporting are given in the
141 GNU C compiler manual.)
142
143 --------------------------------
144
145 At this time, GCC does not know how to handle the GNU C "nested functions"
146 extension. (See the GCC manual for more info on this extension to ANSI C.)
147
148 --------------------------------
149
150 The GNU compilers now represent inline functions (and inlined instances
151 thereof) in exactly the manner described by the current DWARF version 2
152 (draft) specification. The version 1 specification for handling inline
153 functions (and inlined instances) was known to be brain-damaged (by the
154 PLSIG) when the version 1 spec was finalized, but it was simply too late
155 in the cycle to get it removed before the version 1 spec was formally
156 released to the public (by UI).
157
158 --------------------------------
159
160 At this time, GCC does not generate the kind of really precise information
161 about the exact declared types of entities with signed integral types which
162 is required by the current DWARF draft specification.
163
164 Specifically, the current DWARF draft specification seems to require that
165 the type of an non-unsigned integral bit-field member of a struct or union
166 type be represented as either a "signed" type or as a "plain" type,
167 depending upon the exact set of keywords that were used in the
168 type specification for the given bit-field member. It was felt (by the
169 UI/PLSIG) that this distinction between "plain" and "signed" integral types
170 could have some significance (in the case of bit-fields) because ANSI C
171 does not constrain the signedness of a plain bit-field, whereas it does
172 constrain the signedness of an explicitly "signed" bit-field. For this
173 reason, the current DWARF specification calls for compilers to produce
174 type information (for *all* integral typed entities... not just bit-fields)
175 which explicitly indicates the signedness of the relevant type to be
176 "signed" or "plain" or "unsigned".
177
178 Unfortunately, the GNU DWARF implementation is currently incapable of making
179 such distinctions.
180
181 --------------------------------
182
183
184 Known Interoperability Problems
185 -------------------------------
186
187 Although the GNU implementation of DWARF conforms (for the most part) with
188 the current UI/PLSIG DWARF version 1 specification (with many compatible
189 version 2 features added in as "vendor specific extensions" just for good
190 measure) there are a few known cases where GCC's DWARF output can cause
191 some confusion for "classic" (pre version 1) DWARF consumers such as the
192 System V Release 4 SDB debugger. These cases are described in this section.
193
194 --------------------------------
195
196 The DWARF version 1 specification includes the fundamental type codes
197 FT_ext_prec_float, FT_complex, FT_dbl_prec_complex, and FT_ext_prec_complex.
198 Since GNU C is only a C compiler (and since C doesn't provide any "complex"
199 data types) the only one of these fundamental type codes which GCC ever
200 generates is FT_ext_prec_float. This fundamental type code is generated
201 by GCC for the `long double' data type. Unfortunately, due to an apparent
202 bug in the SVR4 SDB debugger, SDB can become very confused wherever any
203 attempt is made to print a variable, parameter, or field whose type was
204 given in terms of FT_ext_prec_float.
205
206 (Actually, SVR4 SDB fails to understand *any* of the four fundamental type
207 codes mentioned here. This will fact will cause additional problems when
208 there is a GNU FORTRAN front-end.)
209
210 --------------------------------
211
212 In general, it appears that SVR4 SDB is not able to effectively ignore
213 fundamental type codes in the "implementation defined" range. This can
214 cause problems when a program being debugged uses the `long long' data
215 type (or the signed or unsigned varieties thereof) because these types
216 are not defined by ANSI C, and thus, GCC must use its own private fundamental
217 type codes (from the implementation-defined range) to represent these types.
218
219 --------------------------------
220
221
222 General GNU DWARF extensions
223 ----------------------------
224
225 In the current DWARF version 1 specification, no mechanism is specified by
226 which accurate information about executable code from include files can be
227 properly (and fully) described. (The DWARF version 2 specification *does*
228 specify such a mechanism, but it is about 10 times more complicated than
229 it needs to be so I'm not terribly anxious to try to implement it right
230 away.)
231
232 In the GNU implementation of DWARF version 1, a fully downward-compatible
233 extension has been implemented which permits the GNU compilers to specify
234 which executable lines come from which files. This extension places
235 additional information (about source file names) in GNU-specific sections
236 (which should be totally ignored by all non-GNU DWARF consumers) so that
237 this extended information can be provided (to GNU DWARF consumers) in a way
238 which is totally transparent (and invisible) to non-GNU DWARF consumers
239 (e.g. the SVR4 SDB debugger). The additional information is placed *only*
240 in specialized GNU-specific sections, where it should never even be seen
241 by non-GNU DWARF consumers.
242
243 To understand this GNU DWARF extension, imagine that the sequence of entries
244 in the .lines section is broken up into several subsections. Each contiguous
245 sequence of .line entries which relates to a sequence of lines (or statements)
246 from one particular file (either a `base' file or an `include' file) could
247 be called a `line entries chunk' (LEC).
248
249 For each LEC there is one entry in the .debug_srcinfo section.
250
251 Each normal entry in the .debug_srcinfo section consists of two 4-byte
252 words of data as follows:
253
254 (1) The starting address (relative to the entire .line section)
255 of the first .line entry in the relevant LEC.
256
257 (2) The starting address (relative to the entire .debug_sfnames
258 section) of a NUL terminated string representing the
259 relevant filename. (This filename name be either a
260 relative or an absolute filename, depending upon how the
261 given source file was located during compilation.)
262
263 Obviously, each .debug_srcinfo entry allows you to find the relevant filename,
264 and it also points you to the first .line entry that was generated as a result
265 of having compiled a given source line from the given source file.
266
267 Each subsequent .line entry should also be assumed to have been produced
268 as a result of compiling yet more lines from the same file. The end of
269 any given LEC is easily found by looking at the first 4-byte pointer in
270 the *next* .debug_srcinfo entry. That next .debug_srcinfo entry points
271 to a new and different LEC, so the preceding LEC (implicitly) must have
272 ended with the last .line section entry which occurs at the 2 1/2 words
273 just before the address given in the first pointer of the new .debug_srcinfo
274 entry.
275
276 The following picture may help to clarify this feature. Let's assume that
277 `LE' stands for `.line entry'. Also, assume that `* 'stands for a pointer.
278
279
280 .line section .debug_srcinfo section .debug_sfnames section
281 ----------------------------------------------------------------
282
283 LE <---------------------- *
284 LE * -----------------> "foobar.c" <---
285 LE |
286 LE |
287 LE <---------------------- * |
288 LE * -----------------> "foobar.h" <| |
289 LE | |
290 LE | |
291 LE <---------------------- * | |
292 LE * -----------------> "inner.h" | |
293 LE | |
294 LE <---------------------- * | |
295 LE * ------------------------------- |
296 LE |
297 LE |
298 LE |
299 LE |
300 LE <---------------------- * |
301 LE * -----------------------------------
302 LE
303 LE
304 LE
305
306 In effect, each entry in the .debug_srcinfo section points to *both* a
307 filename (in the .debug_sfnames section) and to the start of a block of
308 consecutive LEs (in the .line section).
309
310 Note that just like in the .line section, there are specialized first and
311 last entries in the .debug_srcinfo section for each object file. These
312 special first and last entries for the .debug_srcinfo section are very
313 different from the normal .debug_srcinfo section entries. They provide
314 additional information which may be helpful to a debugger when it is
315 interpreting the data in the .debug_srcinfo, .debug_sfnames, and .line
316 sections.
317
318 The first entry in the .debug_srcinfo section for each compilation unit
319 consists of five 4-byte words of data. The contents of these five words
320 should be interpreted (by debuggers) as follows:
321
322 (1) The starting address (relative to the entire .line section)
323 of the .line section for this compilation unit.
324
325 (2) The starting address (relative to the entire .debug_sfnames
326 section) of the .debug_sfnames section for this compilation
327 unit.
328
329 (3) The starting address (in the execution virtual address space)
330 of the .text section for this compilation unit.
331
332 (4) The ending address plus one (in the execution virtual address
333 space) of the .text section for this compilation unit.
334
335 (5) The date/time (in seconds since midnight 1/1/70) at which the
336 compilation of this compilation unit occurred. This value
337 should be interpreted as an unsigned quantity because gcc
338 might be configured to generate a default value of 0xffffffff
339 in this field (in cases where it is desired to have object
340 files created at different times from identical source files
341 be byte-for-byte identical). By default, these timestamps
342 are *not* generated by dwarfout.c (so that object files
343 compiled at different times will be byte-for-byte identical).
344 If you wish to enable this "timestamp" feature however, you
345 can simply place a #define for the symbol `DWARF_TIMESTAMPS'
346 in your target configuration file and then rebuild the GNU
347 compiler(s).
348
349 Note that the first string placed into the .debug_sfnames section for each
350 compilation unit is the name of the directory in which compilation occurred.
351 This string ends with a `/' (to help indicate that it is the pathname of a
352 directory). Thus, the second word of each specialized initial .debug_srcinfo
353 entry for each compilation unit may be used as a pointer to the (string)
354 name of the compilation directory, and that string may in turn be used to
355 "absolutize" any relative pathnames which may appear later on in the
356 .debug_sfnames section entries for the same compilation unit.
357
358 The fifth and last word of each specialized starting entry for a compilation
359 unit in the .debug_srcinfo section may (depending upon your configuration)
360 indicate the date/time of compilation, and this may be used (by a debugger)
361 to determine if any of the source files which contributed code to this
362 compilation unit are newer than the object code for the compilation unit
363 itself. If so, the debugger may wish to print an "out-of-date" warning
364 about the compilation unit.
365
366 The .debug_srcinfo section associated with each compilation will also have
367 a specialized terminating entry. This terminating .debug_srcinfo section
368 entry will consist of the following two 4-byte words of data:
369
370 (1) The offset, measured from the start of the .line section to
371 the beginning of the terminating entry for the .line section.
372
373 (2) A word containing the value 0xffffffff.
374
375 --------------------------------
376
377 In the current DWARF version 1 specification, no mechanism is specified by
378 which information about macro definitions and un-definitions may be provided
379 to the DWARF consumer.
380
381 The DWARF version 2 (draft) specification does specify such a mechanism.
382 That specification was based on the GNU ("vendor specific extension")
383 which provided some support for macro definitions and un-definitions,
384 but the "official" DWARF version 2 (draft) specification mechanism for
385 handling macros and the GNU implementation have diverged somewhat. I
386 plan to update the GNU implementation to conform to the "official"
387 DWARF version 2 (draft) specification as soon as I get time to do that.
388
389 Note that in the GNU implementation, additional information about macro
390 definitions and un-definitions is *only* provided when the -g3 level of
391 debug-info production is selected. (The default level is -g2 and the
392 plain old -g option is considered to be identical to -g2.)
393
394 GCC records information about macro definitions and undefinitions primarily
395 in a section called the .debug_macinfo section. Normal entries in the
396 .debug_macinfo section consist of the following three parts:
397
398 (1) A special "type" byte.
399
400 (2) A 3-byte line-number/filename-offset field.
401
402 (3) A NUL terminated string.
403
404 The interpretation of the second and third parts is dependent upon the
405 value of the leading (type) byte.
406
407 The type byte may have one of four values depending upon the type of the
408 .debug_macinfo entry which follows. The 1-byte MACINFO type codes presently
409 used, and their meanings are as follows:
410
411 MACINFO_start A base file or an include file starts here.
412 MACINFO_resume The current base or include file ends here.
413 MACINFO_define A #define directive occurs here.
414 MACINFO_undef A #undef directive occur here.
415
416 (Note that the MACINFO_... codes mentioned here are simply symbolic names
417 for constants which are defined in the GNU dwarf.h file.)
418
419 For MACINFO_define and MACINFO_undef entries, the second (3-byte) field
420 contains the number of the source line (relative to the start of the current
421 base source file or the current include files) when the #define or #undef
422 directive appears. For a MACINFO_define entry, the following string field
423 contains the name of the macro which is defined, followed by its definition.
424 Note that the definition is always separated from the name of the macro
425 by at least one whitespace character. For a MACINFO_undef entry, the
426 string which follows the 3-byte line number field contains just the name
427 of the macro which is being undef'ed.
428
429 For a MACINFO_start entry, the 3-byte field following the type byte contains
430 the offset, relative to the start of the .debug_sfnames section for the
431 current compilation unit, of a string which names the new source file which
432 is beginning its inclusion at this point. Following that 3-byte field,
433 each MACINFO_start entry always contains a zero length NUL terminated
434 string.
435
436 For a MACINFO_resume entry, the 3-byte field following the type byte contains
437 the line number WITHIN THE INCLUDING FILE at which the inclusion of the
438 current file (whose inclusion ends here) was initiated. Following that
439 3-byte field, each MACINFO_resume entry always contains a zero length NUL
440 terminated string.
441
442 Each set of .debug_macinfo entries for each compilation unit is terminated
443 by a special .debug_macinfo entry consisting of a 4-byte zero value followed
444 by a single NUL byte.
445
446 --------------------------------
447
448 In the current DWARF draft specification, no provision is made for providing
449 a separate level of (limited) debugging information necessary to support
450 tracebacks (only) through fully-debugged code (e.g. code in system libraries).
451
452 A proposal to define such a level was submitted (by me) to the UI/PLSIG.
453 This proposal was rejected by the UI/PLSIG for inclusion into the DWARF
454 version 1 specification for two reasons. First, it was felt (by the PLSIG)
455 that the issues involved in supporting a "traceback only" subset of DWARF
456 were not well understood. Second, and perhaps more importantly, the PLSIG
457 is already having enough trouble agreeing on what it means to be "conforming"
458 to the DWARF specification, and it was felt that trying to specify multiple
459 different *levels* of conformance would only complicate our discussions of
460 this already divisive issue. Nonetheless, the GNU implementation of DWARF
461 provides an abbreviated "traceback only" level of debug-info production for
462 use with fully-debugged "system library" code. This level should only be
463 used for fully debugged system library code, and even then, it should only
464 be used where there is a very strong need to conserve disk space. This
465 abbreviated level of debug-info production can be used by specifying the
466 -g1 option on the compilation command line.
467
468 --------------------------------
469
470 As mentioned above, the GNU implementation of DWARF currently uses the DWARF
471 version 2 (draft) approach for inline functions (and inlined instances
472 thereof). This is used in preference to the version 1 approach because
473 (quite simply) the version 1 approach is highly brain-damaged and probably
474 unworkable.
475
476 --------------------------------
477
478
479 GNU DWARF Representation of GNU C Extensions to ANSI C
480 ------------------------------------------------------
481
482 The file dwarfout.c has been designed and implemented so as to provide
483 some reasonable DWARF representation for each and every declarative
484 construct which is accepted by the GNU C compiler. Since the GNU C
485 compiler accepts a superset of ANSI C, this means that there are some
486 cases in which the DWARF information produced by GCC must take some
487 liberties in improvising DWARF representations for declarations which
488 are only valid in (extended) GNU C.
489
490 In particular, GNU C provides at least three significant extensions to
491 ANSI C when it comes to declarations. These are (1) inline functions,
492 and (2) dynamic arrays, and (3) incomplete enum types. (See the GCC
493 manual for more information on these GNU extensions to ANSI C.) When
494 used, these GNU C extensions are represented (in the generated DWARF
495 output of GCC) in the most natural and intuitively obvious ways.
496
497 In the case of inline functions, the DWARF representation is exactly as
498 called for in the DWARF version 2 (draft) specification for an identical
499 function written in C++; i.e. we "reuse" the representation of inline
500 functions which has been defined for C++ to support this GNU C extension.
501
502 In the case of dynamic arrays, we use the most obvious representational
503 mechanism available; i.e. an array type in which the upper bound of
504 some dimension (usually the first and only dimension) is a variable
505 rather than a constant. (See the DWARF version 1 specification for more
506 details.)
507
508 In the case of incomplete enum types, such types are represented simply
509 as TAG_enumeration_type DIEs which DO NOT contain either AT_byte_size
510 attributes or AT_element_list attributes.
511
512 --------------------------------
513
514
515 Future Directions
516 -----------------
517
518 The codes, formats, and other paraphernalia necessary to provide proper
519 support for symbolic debugging for the C++ language are still being worked
520 on by the UI/PLSIG. The vast majority of the additions to DWARF which will
521 be needed to completely support C++ have already been hashed out and agreed
522 upon, but a few small issues (e.g. anonymous unions, access declarations)
523 are still being discussed. Also, we in the PLSIG are still discussing
524 whether or not we need to do anything special for C++ templates. (At this
525 time it is not yet clear whether we even need to do anything special for
526 these.)
527
528 With regard to FORTRAN, the UI/PLSIG has defined what is believed to be a
529 complete and sufficient set of codes and rules for adequately representing
530 all of FORTRAN 77, and most of Fortran 90 in DWARF. While some support for
531 this has been implemented in dwarfout.c, further implementation and testing
532 is needed.
533
534 GNU DWARF support for other languages (i.e. Pascal and Modula) is a moot
535 issue until there are GNU front-ends for these other languages.
536
537 As currently defined, DWARF only describes a (binary) language which can
538 be used to communicate symbolic debugging information from a compiler
539 through an assembler and a linker, to a debugger. There is no clear
540 specification of what processing should be (or must be) done by the
541 assembler and/or the linker. Fortunately, the role of the assembler
542 is easily inferred (by anyone knowledgeable about assemblers) just by
543 looking at examples of assembly-level DWARF code. Sadly though, the
544 allowable (or required) processing steps performed by a linker are
545 harder to infer and (perhaps) even harder to agree upon. There are
546 several forms of very useful `post-processing' steps which intelligent
547 linkers *could* (in theory) perform on object files containing DWARF,
548 but any and all such link-time transformations are currently both disallowed
549 and unspecified.
550
551 In particular, possible link-time transformations of DWARF code which could
552 provide significant benefits include (but are not limited to):
553
554 Commonization of duplicate DIEs obtained from multiple input
555 (object) files.
556
557 Cross-compilation type checking based upon DWARF type information
558 for objects and functions.
559
560 Other possible `compacting' transformations designed to save disk
561 space and to reduce linker & debugger I/O activity.
562
563 */
564
565 #include "config.h"
566
567 #ifdef DWARF_DEBUGGING_INFO
568 #include "system.h"
569 #include "dwarf.h"
570 #include "tree.h"
571 #include "flags.h"
572 #include "rtl.h"
573 #include "hard-reg-set.h"
574 #include "insn-config.h"
575 #include "reload.h"
576 #include "output.h"
577 #include "toplev.h"
578 #include "tm_p.h"
579 #include "debug.h"
580
581 /* NOTE: In the comments in this file, many references are made to
582 so called "Debugging Information Entries". For the sake of brevity,
583 this term is abbreviated to `DIE' throughout the remainder of this
584 file. */
585
586 /* Note that the implementation of C++ support herein is (as yet) unfinished.
587 If you want to try to complete it, more power to you. */
588
589 /* How to start an assembler comment. */
590 #ifndef ASM_COMMENT_START
591 #define ASM_COMMENT_START ";#"
592 #endif
593
594 /* How to print out a register name. */
595 #ifndef PRINT_REG
596 #define PRINT_REG(RTX, CODE, FILE) \
597 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
598 #endif
599
600 /* Define a macro which returns non-zero for any tagged type which is
601 used (directly or indirectly) in the specification of either some
602 function's return type or some formal parameter of some function.
603 We use this macro when we are operating in "terse" mode to help us
604 know what tagged types have to be represented in Dwarf (even in
605 terse mode) and which ones don't.
606
607 A flag bit with this meaning really should be a part of the normal
608 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
609 for these nodes. For now, we have to just fake it. It it safe for
610 us to simply return zero for all complete tagged types (which will
611 get forced out anyway if they were used in the specification of some
612 formal or return type) and non-zero for all incomplete tagged types.
613 */
614
615 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
616
617 /* Define a macro which returns non-zero for a TYPE_DECL which was
618 implicitly generated for a tagged type.
619
620 Note that unlike the gcc front end (which generates a NULL named
621 TYPE_DECL node for each complete tagged type, each array type, and
622 each function type node created) the g++ front end generates a
623 _named_ TYPE_DECL node for each tagged type node created.
624 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
625 generate a DW_TAG_typedef DIE for them. */
626 #define TYPE_DECL_IS_STUB(decl) \
627 (DECL_NAME (decl) == NULL \
628 || (DECL_ARTIFICIAL (decl) \
629 && is_tagged_type (TREE_TYPE (decl)) \
630 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
631
632 extern int flag_traditional;
633
634 /* Maximum size (in bytes) of an artificially generated label. */
635
636 #define MAX_ARTIFICIAL_LABEL_BYTES 30
637 \f
638 /* Structure to keep track of source filenames. */
639
640 struct filename_entry {
641 unsigned number;
642 const char * name;
643 };
644
645 typedef struct filename_entry filename_entry;
646
647 /* Pointer to an array of elements, each one having the structure above. */
648
649 static filename_entry *filename_table;
650
651 /* Total number of entries in the table (i.e. array) pointed to by
652 `filename_table'. This is the *total* and includes both used and
653 unused slots. */
654
655 static unsigned ft_entries_allocated;
656
657 /* Number of entries in the filename_table which are actually in use. */
658
659 static unsigned ft_entries;
660
661 /* Size (in elements) of increments by which we may expand the filename
662 table. Actually, a single hunk of space of this size should be enough
663 for most typical programs. */
664
665 #define FT_ENTRIES_INCREMENT 64
666
667 /* Local pointer to the name of the main input file. Initialized in
668 dwarfout_init. */
669
670 static const char *primary_filename;
671
672 /* Pointer to the most recent filename for which we produced some line info. */
673
674 static const char *last_filename;
675
676 /* Counter to generate unique names for DIEs. */
677
678 static unsigned next_unused_dienum = 1;
679
680 /* Number of the DIE which is currently being generated. */
681
682 static unsigned current_dienum;
683
684 /* Number to use for the special "pubname" label on the next DIE which
685 represents a function or data object defined in this compilation
686 unit which has "extern" linkage. */
687
688 static int next_pubname_number = 0;
689
690 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
691
692 /* Pointer to a dynamically allocated list of pre-reserved and still
693 pending sibling DIE numbers. Note that this list will grow as needed. */
694
695 static unsigned *pending_sibling_stack;
696
697 /* Counter to keep track of the number of pre-reserved and still pending
698 sibling DIE numbers. */
699
700 static unsigned pending_siblings;
701
702 /* The currently allocated size of the above list (expressed in number of
703 list elements). */
704
705 static unsigned pending_siblings_allocated;
706
707 /* Size (in elements) of increments by which we may expand the pending
708 sibling stack. Actually, a single hunk of space of this size should
709 be enough for most typical programs. */
710
711 #define PENDING_SIBLINGS_INCREMENT 64
712
713 /* Non-zero if we are performing our file-scope finalization pass and if
714 we should force out Dwarf descriptions of any and all file-scope
715 tagged types which are still incomplete types. */
716
717 static int finalizing = 0;
718
719 /* A pointer to the base of a list of pending types which we haven't
720 generated DIEs for yet, but which we will have to come back to
721 later on. */
722
723 static tree *pending_types_list;
724
725 /* Number of elements currently allocated for the pending_types_list. */
726
727 static unsigned pending_types_allocated;
728
729 /* Number of elements of pending_types_list currently in use. */
730
731 static unsigned pending_types;
732
733 /* Size (in elements) of increments by which we may expand the pending
734 types list. Actually, a single hunk of space of this size should
735 be enough for most typical programs. */
736
737 #define PENDING_TYPES_INCREMENT 64
738
739 /* A pointer to the base of a list of incomplete types which might be
740 completed at some later time. */
741
742 static tree *incomplete_types_list;
743
744 /* Number of elements currently allocated for the incomplete_types_list. */
745 static unsigned incomplete_types_allocated;
746
747 /* Number of elements of incomplete_types_list currently in use. */
748 static unsigned incomplete_types;
749
750 /* Size (in elements) of increments by which we may expand the incomplete
751 types list. Actually, a single hunk of space of this size should
752 be enough for most typical programs. */
753 #define INCOMPLETE_TYPES_INCREMENT 64
754
755 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
756 This is used in a hack to help us get the DIEs describing types of
757 formal parameters to come *after* all of the DIEs describing the formal
758 parameters themselves. That's necessary in order to be compatible
759 with what the brain-damaged svr4 SDB debugger requires. */
760
761 static tree fake_containing_scope;
762
763 /* The number of the current function definition that we are generating
764 debugging information for. These numbers range from 1 up to the maximum
765 number of function definitions contained within the current compilation
766 unit. These numbers are used to create unique labels for various things
767 contained within various function definitions. */
768
769 static unsigned current_funcdef_number = 1;
770
771 /* A pointer to the ..._DECL node which we have most recently been working
772 on. We keep this around just in case something about it looks screwy
773 and we want to tell the user what the source coordinates for the actual
774 declaration are. */
775
776 static tree dwarf_last_decl;
777
778 /* A flag indicating that we are emitting the member declarations of a
779 class, so member functions and variables should not be entirely emitted.
780 This is a kludge to avoid passing a second argument to output_*_die. */
781
782 static int in_class;
783
784 /* Forward declarations for functions defined in this file. */
785
786 static void dwarfout_init PARAMS ((const char *));
787 static void dwarfout_finish PARAMS ((const char *));
788 static void dwarfout_define PARAMS ((unsigned int, const char *));
789 static void dwarfout_undef PARAMS ((unsigned int, const char *));
790 static void dwarfout_start_source_file PARAMS ((unsigned, const char *));
791 static void dwarfout_start_source_file_check PARAMS ((unsigned, const char *));
792 static void dwarfout_end_source_file PARAMS ((unsigned));
793 static void dwarfout_end_source_file_check PARAMS ((unsigned));
794 static void dwarfout_begin_block PARAMS ((unsigned, unsigned));
795 static void dwarfout_end_block PARAMS ((unsigned, unsigned));
796 static void dwarfout_end_epilogue PARAMS ((void));
797 static void dwarfout_source_line PARAMS ((unsigned int, const char *));
798 static void dwarfout_end_prologue PARAMS ((unsigned int));
799 static void dwarfout_end_function PARAMS ((unsigned int));
800 static void dwarfout_function_decl PARAMS ((tree));
801 static void dwarfout_global_decl PARAMS ((tree));
802 static void dwarfout_deferred_inline_function PARAMS ((tree));
803 static void dwarfout_file_scope_decl PARAMS ((tree , int));
804 static const char *dwarf_tag_name PARAMS ((unsigned));
805 static const char *dwarf_attr_name PARAMS ((unsigned));
806 static const char *dwarf_stack_op_name PARAMS ((unsigned));
807 static const char *dwarf_typemod_name PARAMS ((unsigned));
808 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
809 static const char *dwarf_fund_type_name PARAMS ((unsigned));
810 static tree decl_ultimate_origin PARAMS ((tree));
811 static tree block_ultimate_origin PARAMS ((tree));
812 static tree decl_class_context PARAMS ((tree));
813 #if 0
814 static void output_unsigned_leb128 PARAMS ((unsigned long));
815 static void output_signed_leb128 PARAMS ((long));
816 #endif
817 static int fundamental_type_code PARAMS ((tree));
818 static tree root_type_1 PARAMS ((tree, int));
819 static tree root_type PARAMS ((tree));
820 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
821 static void write_modifier_bytes PARAMS ((tree, int, int));
822 static inline int type_is_fundamental PARAMS ((tree));
823 static void equate_decl_number_to_die_number PARAMS ((tree));
824 static inline void equate_type_number_to_die_number PARAMS ((tree));
825 static void output_reg_number PARAMS ((rtx));
826 static void output_mem_loc_descriptor PARAMS ((rtx));
827 static void output_loc_descriptor PARAMS ((rtx));
828 static void output_bound_representation PARAMS ((tree, unsigned, int));
829 static void output_enumeral_list PARAMS ((tree));
830 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
831 static inline tree field_type PARAMS ((tree));
832 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
833 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
834 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
835 static inline void sibling_attribute PARAMS ((void));
836 static void location_attribute PARAMS ((rtx));
837 static void data_member_location_attribute PARAMS ((tree));
838 static void const_value_attribute PARAMS ((rtx));
839 static void location_or_const_value_attribute PARAMS ((tree));
840 static inline void name_attribute PARAMS ((const char *));
841 static inline void fund_type_attribute PARAMS ((unsigned));
842 static void mod_fund_type_attribute PARAMS ((tree, int, int));
843 static inline void user_def_type_attribute PARAMS ((tree));
844 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
845 #ifdef USE_ORDERING_ATTRIBUTE
846 static inline void ordering_attribute PARAMS ((unsigned));
847 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
848 static void subscript_data_attribute PARAMS ((tree));
849 static void byte_size_attribute PARAMS ((tree));
850 static inline void bit_offset_attribute PARAMS ((tree));
851 static inline void bit_size_attribute PARAMS ((tree));
852 static inline void element_list_attribute PARAMS ((tree));
853 static inline void stmt_list_attribute PARAMS ((const char *));
854 static inline void low_pc_attribute PARAMS ((const char *));
855 static inline void high_pc_attribute PARAMS ((const char *));
856 static inline void body_begin_attribute PARAMS ((const char *));
857 static inline void body_end_attribute PARAMS ((const char *));
858 static inline void language_attribute PARAMS ((unsigned));
859 static inline void member_attribute PARAMS ((tree));
860 #if 0
861 static inline void string_length_attribute PARAMS ((tree));
862 #endif
863 static inline void comp_dir_attribute PARAMS ((const char *));
864 static inline void sf_names_attribute PARAMS ((const char *));
865 static inline void src_info_attribute PARAMS ((const char *));
866 static inline void mac_info_attribute PARAMS ((const char *));
867 static inline void prototyped_attribute PARAMS ((tree));
868 static inline void producer_attribute PARAMS ((const char *));
869 static inline void inline_attribute PARAMS ((tree));
870 static inline void containing_type_attribute PARAMS ((tree));
871 static inline void abstract_origin_attribute PARAMS ((tree));
872 #ifdef DWARF_DECL_COORDINATES
873 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
874 #endif /* defined(DWARF_DECL_COORDINATES) */
875 static inline void pure_or_virtual_attribute PARAMS ((tree));
876 static void name_and_src_coords_attributes PARAMS ((tree));
877 static void type_attribute PARAMS ((tree, int, int));
878 static const char *type_tag PARAMS ((tree));
879 static inline void dienum_push PARAMS ((void));
880 static inline void dienum_pop PARAMS ((void));
881 static inline tree member_declared_type PARAMS ((tree));
882 static const char *function_start_label PARAMS ((tree));
883 static void output_array_type_die PARAMS ((void *));
884 static void output_set_type_die PARAMS ((void *));
885 #if 0
886 static void output_entry_point_die PARAMS ((void *));
887 #endif
888 static void output_inlined_enumeration_type_die PARAMS ((void *));
889 static void output_inlined_structure_type_die PARAMS ((void *));
890 static void output_inlined_union_type_die PARAMS ((void *));
891 static void output_enumeration_type_die PARAMS ((void *));
892 static void output_formal_parameter_die PARAMS ((void *));
893 static void output_global_subroutine_die PARAMS ((void *));
894 static void output_global_variable_die PARAMS ((void *));
895 static void output_label_die PARAMS ((void *));
896 static void output_lexical_block_die PARAMS ((void *));
897 static void output_inlined_subroutine_die PARAMS ((void *));
898 static void output_local_variable_die PARAMS ((void *));
899 static void output_member_die PARAMS ((void *));
900 #if 0
901 static void output_pointer_type_die PARAMS ((void *));
902 static void output_reference_type_die PARAMS ((void *));
903 #endif
904 static void output_ptr_to_mbr_type_die PARAMS ((void *));
905 static void output_compile_unit_die PARAMS ((void *));
906 static void output_string_type_die PARAMS ((void *));
907 static void output_inheritance_die PARAMS ((void *));
908 static void output_structure_type_die PARAMS ((void *));
909 static void output_local_subroutine_die PARAMS ((void *));
910 static void output_subroutine_type_die PARAMS ((void *));
911 static void output_typedef_die PARAMS ((void *));
912 static void output_union_type_die PARAMS ((void *));
913 static void output_unspecified_parameters_die PARAMS ((void *));
914 static void output_padded_null_die PARAMS ((void *));
915 static void output_die PARAMS ((void (*)(void *), void *));
916 static void end_sibling_chain PARAMS ((void));
917 static void output_formal_types PARAMS ((tree));
918 static void pend_type PARAMS ((tree));
919 static int type_ok_for_scope PARAMS ((tree, tree));
920 static void output_pending_types_for_scope PARAMS ((tree));
921 static void output_type PARAMS ((tree, tree));
922 static void output_tagged_type_instantiation PARAMS ((tree));
923 static void output_block PARAMS ((tree, int));
924 static void output_decls_for_scope PARAMS ((tree, int));
925 static void output_decl PARAMS ((tree, tree));
926 static void shuffle_filename_entry PARAMS ((filename_entry *));
927 static void generate_new_sfname_entry PARAMS ((void));
928 static unsigned lookup_filename PARAMS ((const char *));
929 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
930 static void generate_macinfo_entry PARAMS ((const char *, const char *));
931 static int is_pseudo_reg PARAMS ((rtx));
932 static tree type_main_variant PARAMS ((tree));
933 static int is_tagged_type PARAMS ((tree));
934 static int is_redundant_typedef PARAMS ((tree));
935 static void add_incomplete_type PARAMS ((tree));
936 static void retry_incomplete_types PARAMS ((void));
937 \f
938 /* Definitions of defaults for assembler-dependent names of various
939 pseudo-ops and section names.
940
941 Theses may be overridden in your tm.h file (if necessary) for your
942 particular assembler. The default values provided here correspond to
943 what is expected by "standard" AT&T System V.4 assemblers. */
944
945 #ifndef FILE_ASM_OP
946 #define FILE_ASM_OP "\t.file\t"
947 #endif
948 #ifndef VERSION_ASM_OP
949 #define VERSION_ASM_OP "\t.version\t"
950 #endif
951 #ifndef UNALIGNED_SHORT_ASM_OP
952 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
953 #endif
954 #ifndef UNALIGNED_INT_ASM_OP
955 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
956 #endif
957 #ifndef ASM_BYTE_OP
958 #define ASM_BYTE_OP "\t.byte\t"
959 #endif
960 #ifndef SET_ASM_OP
961 #define SET_ASM_OP "\t.set\t"
962 #endif
963
964 /* Pseudo-ops for pushing the current section onto the section stack (and
965 simultaneously changing to a new section) and for poping back to the
966 section we were in immediately before this one. Note that most svr4
967 assemblers only maintain a one level stack... you can push all the
968 sections you want, but you can only pop out one level. (The sparc
969 svr4 assembler is an exception to this general rule.) That's
970 OK because we only use at most one level of the section stack herein. */
971
972 #ifndef PUSHSECTION_ASM_OP
973 #define PUSHSECTION_ASM_OP "\t.section\t"
974 #endif
975 #ifndef POPSECTION_ASM_OP
976 #define POPSECTION_ASM_OP "\t.previous"
977 #endif
978
979 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
980 to print the PUSHSECTION_ASM_OP and the section name. The default here
981 works for almost all svr4 assemblers, except for the sparc, where the
982 section name must be enclosed in double quotes. (See sparcv4.h.) */
983
984 #ifndef PUSHSECTION_FORMAT
985 #define PUSHSECTION_FORMAT "%s%s\n"
986 #endif
987
988 #ifndef DEBUG_SECTION
989 #define DEBUG_SECTION ".debug"
990 #endif
991 #ifndef LINE_SECTION
992 #define LINE_SECTION ".line"
993 #endif
994 #ifndef DEBUG_SFNAMES_SECTION
995 #define DEBUG_SFNAMES_SECTION ".debug_sfnames"
996 #endif
997 #ifndef DEBUG_SRCINFO_SECTION
998 #define DEBUG_SRCINFO_SECTION ".debug_srcinfo"
999 #endif
1000 #ifndef DEBUG_MACINFO_SECTION
1001 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
1002 #endif
1003 #ifndef DEBUG_PUBNAMES_SECTION
1004 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
1005 #endif
1006 #ifndef DEBUG_ARANGES_SECTION
1007 #define DEBUG_ARANGES_SECTION ".debug_aranges"
1008 #endif
1009 #ifndef TEXT_SECTION
1010 #define TEXT_SECTION ".text"
1011 #endif
1012 #ifndef DATA_SECTION
1013 #define DATA_SECTION ".data"
1014 #endif
1015 #ifndef DATA1_SECTION
1016 #define DATA1_SECTION ".data1"
1017 #endif
1018 #ifndef RODATA_SECTION
1019 #define RODATA_SECTION ".rodata"
1020 #endif
1021 #ifndef RODATA1_SECTION
1022 #define RODATA1_SECTION ".rodata1"
1023 #endif
1024 #ifndef BSS_SECTION
1025 #define BSS_SECTION ".bss"
1026 #endif
1027 \f
1028 /* Definitions of defaults for formats and names of various special
1029 (artificial) labels which may be generated within this file (when
1030 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
1031
1032 If necessary, these may be overridden from within your tm.h file,
1033 but typically, you should never need to override these.
1034
1035 These labels have been hacked (temporarily) so that they all begin with
1036 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
1037 stock m88k/svr4 assembler, both of which need to see .L at the start of
1038 a label in order to prevent that label from going into the linker symbol
1039 table). When I get time, I'll have to fix this the right way so that we
1040 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
1041 but that will require a rather massive set of changes. For the moment,
1042 the following definitions out to produce the right results for all svr4
1043 and svr3 assemblers. -- rfg
1044 */
1045
1046 #ifndef TEXT_BEGIN_LABEL
1047 #define TEXT_BEGIN_LABEL "*.L_text_b"
1048 #endif
1049 #ifndef TEXT_END_LABEL
1050 #define TEXT_END_LABEL "*.L_text_e"
1051 #endif
1052
1053 #ifndef DATA_BEGIN_LABEL
1054 #define DATA_BEGIN_LABEL "*.L_data_b"
1055 #endif
1056 #ifndef DATA_END_LABEL
1057 #define DATA_END_LABEL "*.L_data_e"
1058 #endif
1059
1060 #ifndef DATA1_BEGIN_LABEL
1061 #define DATA1_BEGIN_LABEL "*.L_data1_b"
1062 #endif
1063 #ifndef DATA1_END_LABEL
1064 #define DATA1_END_LABEL "*.L_data1_e"
1065 #endif
1066
1067 #ifndef RODATA_BEGIN_LABEL
1068 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
1069 #endif
1070 #ifndef RODATA_END_LABEL
1071 #define RODATA_END_LABEL "*.L_rodata_e"
1072 #endif
1073
1074 #ifndef RODATA1_BEGIN_LABEL
1075 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
1076 #endif
1077 #ifndef RODATA1_END_LABEL
1078 #define RODATA1_END_LABEL "*.L_rodata1_e"
1079 #endif
1080
1081 #ifndef BSS_BEGIN_LABEL
1082 #define BSS_BEGIN_LABEL "*.L_bss_b"
1083 #endif
1084 #ifndef BSS_END_LABEL
1085 #define BSS_END_LABEL "*.L_bss_e"
1086 #endif
1087
1088 #ifndef LINE_BEGIN_LABEL
1089 #define LINE_BEGIN_LABEL "*.L_line_b"
1090 #endif
1091 #ifndef LINE_LAST_ENTRY_LABEL
1092 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
1093 #endif
1094 #ifndef LINE_END_LABEL
1095 #define LINE_END_LABEL "*.L_line_e"
1096 #endif
1097
1098 #ifndef DEBUG_BEGIN_LABEL
1099 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
1100 #endif
1101 #ifndef SFNAMES_BEGIN_LABEL
1102 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
1103 #endif
1104 #ifndef SRCINFO_BEGIN_LABEL
1105 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
1106 #endif
1107 #ifndef MACINFO_BEGIN_LABEL
1108 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
1109 #endif
1110
1111 #ifndef DEBUG_ARANGES_BEGIN_LABEL
1112 #define DEBUG_ARANGES_BEGIN_LABEL "*.L_debug_aranges_begin"
1113 #endif
1114 #ifndef DEBUG_ARANGES_END_LABEL
1115 #define DEBUG_ARANGES_END_LABEL "*.L_debug_aranges_end"
1116 #endif
1117
1118 #ifndef DIE_BEGIN_LABEL_FMT
1119 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
1120 #endif
1121 #ifndef DIE_END_LABEL_FMT
1122 #define DIE_END_LABEL_FMT "*.L_D%u_e"
1123 #endif
1124 #ifndef PUB_DIE_LABEL_FMT
1125 #define PUB_DIE_LABEL_FMT "*.L_P%u"
1126 #endif
1127 #ifndef BLOCK_BEGIN_LABEL_FMT
1128 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
1129 #endif
1130 #ifndef BLOCK_END_LABEL_FMT
1131 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
1132 #endif
1133 #ifndef SS_BEGIN_LABEL_FMT
1134 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
1135 #endif
1136 #ifndef SS_END_LABEL_FMT
1137 #define SS_END_LABEL_FMT "*.L_s%u_e"
1138 #endif
1139 #ifndef EE_BEGIN_LABEL_FMT
1140 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
1141 #endif
1142 #ifndef EE_END_LABEL_FMT
1143 #define EE_END_LABEL_FMT "*.L_e%u_e"
1144 #endif
1145 #ifndef MT_BEGIN_LABEL_FMT
1146 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
1147 #endif
1148 #ifndef MT_END_LABEL_FMT
1149 #define MT_END_LABEL_FMT "*.L_t%u_e"
1150 #endif
1151 #ifndef LOC_BEGIN_LABEL_FMT
1152 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
1153 #endif
1154 #ifndef LOC_END_LABEL_FMT
1155 #define LOC_END_LABEL_FMT "*.L_l%u_e"
1156 #endif
1157 #ifndef BOUND_BEGIN_LABEL_FMT
1158 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
1159 #endif
1160 #ifndef BOUND_END_LABEL_FMT
1161 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
1162 #endif
1163 #ifndef DERIV_BEGIN_LABEL_FMT
1164 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
1165 #endif
1166 #ifndef DERIV_END_LABEL_FMT
1167 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
1168 #endif
1169 #ifndef SL_BEGIN_LABEL_FMT
1170 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
1171 #endif
1172 #ifndef SL_END_LABEL_FMT
1173 #define SL_END_LABEL_FMT "*.L_sl%u_e"
1174 #endif
1175 #ifndef BODY_BEGIN_LABEL_FMT
1176 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
1177 #endif
1178 #ifndef BODY_END_LABEL_FMT
1179 #define BODY_END_LABEL_FMT "*.L_b%u_e"
1180 #endif
1181 #ifndef FUNC_END_LABEL_FMT
1182 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
1183 #endif
1184 #ifndef TYPE_NAME_FMT
1185 #define TYPE_NAME_FMT "*.L_T%u"
1186 #endif
1187 #ifndef DECL_NAME_FMT
1188 #define DECL_NAME_FMT "*.L_E%u"
1189 #endif
1190 #ifndef LINE_CODE_LABEL_FMT
1191 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
1192 #endif
1193 #ifndef SFNAMES_ENTRY_LABEL_FMT
1194 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
1195 #endif
1196 #ifndef LINE_ENTRY_LABEL_FMT
1197 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
1198 #endif
1199 \f
1200 /* Definitions of defaults for various types of primitive assembly language
1201 output operations.
1202
1203 If necessary, these may be overridden from within your tm.h file,
1204 but typically, you shouldn't need to override these. */
1205
1206 #ifndef ASM_OUTPUT_PUSH_SECTION
1207 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
1208 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
1209 #endif
1210
1211 #ifndef ASM_OUTPUT_POP_SECTION
1212 #define ASM_OUTPUT_POP_SECTION(FILE) \
1213 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
1214 #endif
1215
1216 #ifndef ASM_OUTPUT_DWARF_DELTA2
1217 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
1218 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
1219 assemble_name (FILE, LABEL1); \
1220 fprintf (FILE, "-"); \
1221 assemble_name (FILE, LABEL2); \
1222 fprintf (FILE, "\n"); \
1223 } while (0)
1224 #endif
1225
1226 #ifndef ASM_OUTPUT_DWARF_DELTA4
1227 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
1228 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1229 assemble_name (FILE, LABEL1); \
1230 fprintf (FILE, "-"); \
1231 assemble_name (FILE, LABEL2); \
1232 fprintf (FILE, "\n"); \
1233 } while (0)
1234 #endif
1235
1236 #ifndef ASM_OUTPUT_DWARF_TAG
1237 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
1238 do { \
1239 fprintf ((FILE), "%s0x%x", \
1240 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
1241 if (flag_debug_asm) \
1242 fprintf ((FILE), "\t%s %s", \
1243 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
1244 fputc ('\n', (FILE)); \
1245 } while (0)
1246 #endif
1247
1248 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
1249 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
1250 do { \
1251 fprintf ((FILE), "%s0x%x", \
1252 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
1253 if (flag_debug_asm) \
1254 fprintf ((FILE), "\t%s %s", \
1255 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
1256 fputc ('\n', (FILE)); \
1257 } while (0)
1258 #endif
1259
1260 #ifndef ASM_OUTPUT_DWARF_STACK_OP
1261 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
1262 do { \
1263 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) OP); \
1264 if (flag_debug_asm) \
1265 fprintf ((FILE), "\t%s %s", \
1266 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
1267 fputc ('\n', (FILE)); \
1268 } while (0)
1269 #endif
1270
1271 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
1272 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
1273 do { \
1274 fprintf ((FILE), "%s0x%x", \
1275 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
1276 if (flag_debug_asm) \
1277 fprintf ((FILE), "\t%s %s", \
1278 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
1279 fputc ('\n', (FILE)); \
1280 } while (0)
1281 #endif
1282
1283 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
1284 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
1285 do { \
1286 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) FMT); \
1287 if (flag_debug_asm) \
1288 fprintf ((FILE), "\t%s %s", \
1289 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
1290 fputc ('\n', (FILE)); \
1291 } while (0)
1292 #endif
1293
1294 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
1295 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
1296 do { \
1297 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) MOD); \
1298 if (flag_debug_asm) \
1299 fprintf ((FILE), "\t%s %s", \
1300 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
1301 fputc ('\n', (FILE)); \
1302 } while (0)
1303 #endif
1304 \f
1305 #ifndef ASM_OUTPUT_DWARF_ADDR
1306 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
1307 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1308 assemble_name (FILE, LABEL); \
1309 fprintf (FILE, "\n"); \
1310 } while (0)
1311 #endif
1312
1313 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
1314 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
1315 do { \
1316 fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1317 output_addr_const ((FILE), (RTX)); \
1318 fputc ('\n', (FILE)); \
1319 } while (0)
1320 #endif
1321
1322 #ifndef ASM_OUTPUT_DWARF_REF
1323 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
1324 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1325 assemble_name (FILE, LABEL); \
1326 fprintf (FILE, "\n"); \
1327 } while (0)
1328 #endif
1329
1330 #ifndef ASM_OUTPUT_DWARF_DATA1
1331 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
1332 fprintf ((FILE), "%s0x%x\n", ASM_BYTE_OP, VALUE)
1333 #endif
1334
1335 #ifndef ASM_OUTPUT_DWARF_DATA2
1336 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
1337 fprintf ((FILE), "%s0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
1338 #endif
1339
1340 #ifndef ASM_OUTPUT_DWARF_DATA4
1341 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
1342 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
1343 #endif
1344
1345 #ifndef ASM_OUTPUT_DWARF_DATA8
1346 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
1347 do { \
1348 if (WORDS_BIG_ENDIAN) \
1349 { \
1350 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1351 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1352 } \
1353 else \
1354 { \
1355 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1356 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1357 } \
1358 } while (0)
1359 #endif
1360
1361 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
1362 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
1363 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
1364 defined, we call it, then issue the line feed. If not, we supply a
1365 default defintion of calling ASM_OUTPUT_ASCII */
1366
1367 #ifndef ASM_OUTPUT_DWARF_STRING
1368 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1369 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
1370 #else
1371 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1372 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
1373 #endif
1374
1375 \f
1376 /* The debug hooks structure. */
1377 struct gcc_debug_hooks dwarf_debug_hooks =
1378 {
1379 dwarfout_init,
1380 dwarfout_finish,
1381 dwarfout_define,
1382 dwarfout_undef,
1383 dwarfout_start_source_file_check,
1384 dwarfout_end_source_file_check,
1385 dwarfout_begin_block,
1386 dwarfout_end_block,
1387 debug_true_tree, /* ignore_block */
1388 dwarfout_source_line, /* source_line */
1389 dwarfout_source_line, /* begin_prologue */
1390 dwarfout_end_prologue,
1391 dwarfout_end_epilogue,
1392 debug_nothing_tree, /* begin_function */
1393 dwarfout_end_function,
1394 dwarfout_function_decl,
1395 dwarfout_global_decl,
1396 dwarfout_deferred_inline_function,
1397 debug_nothing_tree, /* outlining_inline_function */
1398 debug_nothing_rtx /* label */
1399 };
1400 \f
1401 /************************ general utility functions **************************/
1402
1403 static inline int
1404 is_pseudo_reg (rtl)
1405 register rtx rtl;
1406 {
1407 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1408 || ((GET_CODE (rtl) == SUBREG)
1409 && (REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)));
1410 }
1411
1412 static inline tree
1413 type_main_variant (type)
1414 register tree type;
1415 {
1416 type = TYPE_MAIN_VARIANT (type);
1417
1418 /* There really should be only one main variant among any group of variants
1419 of a given type (and all of the MAIN_VARIANT values for all members of
1420 the group should point to that one type) but sometimes the C front-end
1421 messes this up for array types, so we work around that bug here. */
1422
1423 if (TREE_CODE (type) == ARRAY_TYPE)
1424 {
1425 while (type != TYPE_MAIN_VARIANT (type))
1426 type = TYPE_MAIN_VARIANT (type);
1427 }
1428
1429 return type;
1430 }
1431
1432 /* Return non-zero if the given type node represents a tagged type. */
1433
1434 static inline int
1435 is_tagged_type (type)
1436 register tree type;
1437 {
1438 register enum tree_code code = TREE_CODE (type);
1439
1440 return (code == RECORD_TYPE || code == UNION_TYPE
1441 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1442 }
1443
1444 static const char *
1445 dwarf_tag_name (tag)
1446 register unsigned tag;
1447 {
1448 switch (tag)
1449 {
1450 case TAG_padding: return "TAG_padding";
1451 case TAG_array_type: return "TAG_array_type";
1452 case TAG_class_type: return "TAG_class_type";
1453 case TAG_entry_point: return "TAG_entry_point";
1454 case TAG_enumeration_type: return "TAG_enumeration_type";
1455 case TAG_formal_parameter: return "TAG_formal_parameter";
1456 case TAG_global_subroutine: return "TAG_global_subroutine";
1457 case TAG_global_variable: return "TAG_global_variable";
1458 case TAG_label: return "TAG_label";
1459 case TAG_lexical_block: return "TAG_lexical_block";
1460 case TAG_local_variable: return "TAG_local_variable";
1461 case TAG_member: return "TAG_member";
1462 case TAG_pointer_type: return "TAG_pointer_type";
1463 case TAG_reference_type: return "TAG_reference_type";
1464 case TAG_compile_unit: return "TAG_compile_unit";
1465 case TAG_string_type: return "TAG_string_type";
1466 case TAG_structure_type: return "TAG_structure_type";
1467 case TAG_subroutine: return "TAG_subroutine";
1468 case TAG_subroutine_type: return "TAG_subroutine_type";
1469 case TAG_typedef: return "TAG_typedef";
1470 case TAG_union_type: return "TAG_union_type";
1471 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
1472 case TAG_variant: return "TAG_variant";
1473 case TAG_common_block: return "TAG_common_block";
1474 case TAG_common_inclusion: return "TAG_common_inclusion";
1475 case TAG_inheritance: return "TAG_inheritance";
1476 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
1477 case TAG_module: return "TAG_module";
1478 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
1479 case TAG_set_type: return "TAG_set_type";
1480 case TAG_subrange_type: return "TAG_subrange_type";
1481 case TAG_with_stmt: return "TAG_with_stmt";
1482
1483 /* GNU extensions. */
1484
1485 case TAG_format_label: return "TAG_format_label";
1486 case TAG_namelist: return "TAG_namelist";
1487 case TAG_function_template: return "TAG_function_template";
1488 case TAG_class_template: return "TAG_class_template";
1489
1490 default: return "TAG_<unknown>";
1491 }
1492 }
1493
1494 static const char *
1495 dwarf_attr_name (attr)
1496 register unsigned attr;
1497 {
1498 switch (attr)
1499 {
1500 case AT_sibling: return "AT_sibling";
1501 case AT_location: return "AT_location";
1502 case AT_name: return "AT_name";
1503 case AT_fund_type: return "AT_fund_type";
1504 case AT_mod_fund_type: return "AT_mod_fund_type";
1505 case AT_user_def_type: return "AT_user_def_type";
1506 case AT_mod_u_d_type: return "AT_mod_u_d_type";
1507 case AT_ordering: return "AT_ordering";
1508 case AT_subscr_data: return "AT_subscr_data";
1509 case AT_byte_size: return "AT_byte_size";
1510 case AT_bit_offset: return "AT_bit_offset";
1511 case AT_bit_size: return "AT_bit_size";
1512 case AT_element_list: return "AT_element_list";
1513 case AT_stmt_list: return "AT_stmt_list";
1514 case AT_low_pc: return "AT_low_pc";
1515 case AT_high_pc: return "AT_high_pc";
1516 case AT_language: return "AT_language";
1517 case AT_member: return "AT_member";
1518 case AT_discr: return "AT_discr";
1519 case AT_discr_value: return "AT_discr_value";
1520 case AT_string_length: return "AT_string_length";
1521 case AT_common_reference: return "AT_common_reference";
1522 case AT_comp_dir: return "AT_comp_dir";
1523 case AT_const_value_string: return "AT_const_value_string";
1524 case AT_const_value_data2: return "AT_const_value_data2";
1525 case AT_const_value_data4: return "AT_const_value_data4";
1526 case AT_const_value_data8: return "AT_const_value_data8";
1527 case AT_const_value_block2: return "AT_const_value_block2";
1528 case AT_const_value_block4: return "AT_const_value_block4";
1529 case AT_containing_type: return "AT_containing_type";
1530 case AT_default_value_addr: return "AT_default_value_addr";
1531 case AT_default_value_data2: return "AT_default_value_data2";
1532 case AT_default_value_data4: return "AT_default_value_data4";
1533 case AT_default_value_data8: return "AT_default_value_data8";
1534 case AT_default_value_string: return "AT_default_value_string";
1535 case AT_friends: return "AT_friends";
1536 case AT_inline: return "AT_inline";
1537 case AT_is_optional: return "AT_is_optional";
1538 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1539 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1540 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1541 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1542 case AT_private: return "AT_private";
1543 case AT_producer: return "AT_producer";
1544 case AT_program: return "AT_program";
1545 case AT_protected: return "AT_protected";
1546 case AT_prototyped: return "AT_prototyped";
1547 case AT_public: return "AT_public";
1548 case AT_pure_virtual: return "AT_pure_virtual";
1549 case AT_return_addr: return "AT_return_addr";
1550 case AT_abstract_origin: return "AT_abstract_origin";
1551 case AT_start_scope: return "AT_start_scope";
1552 case AT_stride_size: return "AT_stride_size";
1553 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1554 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1555 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1556 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1557 case AT_virtual: return "AT_virtual";
1558
1559 /* GNU extensions */
1560
1561 case AT_sf_names: return "AT_sf_names";
1562 case AT_src_info: return "AT_src_info";
1563 case AT_mac_info: return "AT_mac_info";
1564 case AT_src_coords: return "AT_src_coords";
1565 case AT_body_begin: return "AT_body_begin";
1566 case AT_body_end: return "AT_body_end";
1567
1568 default: return "AT_<unknown>";
1569 }
1570 }
1571
1572 static const char *
1573 dwarf_stack_op_name (op)
1574 register unsigned op;
1575 {
1576 switch (op)
1577 {
1578 case OP_REG: return "OP_REG";
1579 case OP_BASEREG: return "OP_BASEREG";
1580 case OP_ADDR: return "OP_ADDR";
1581 case OP_CONST: return "OP_CONST";
1582 case OP_DEREF2: return "OP_DEREF2";
1583 case OP_DEREF4: return "OP_DEREF4";
1584 case OP_ADD: return "OP_ADD";
1585 default: return "OP_<unknown>";
1586 }
1587 }
1588
1589 static const char *
1590 dwarf_typemod_name (mod)
1591 register unsigned mod;
1592 {
1593 switch (mod)
1594 {
1595 case MOD_pointer_to: return "MOD_pointer_to";
1596 case MOD_reference_to: return "MOD_reference_to";
1597 case MOD_const: return "MOD_const";
1598 case MOD_volatile: return "MOD_volatile";
1599 default: return "MOD_<unknown>";
1600 }
1601 }
1602
1603 static const char *
1604 dwarf_fmt_byte_name (fmt)
1605 register unsigned fmt;
1606 {
1607 switch (fmt)
1608 {
1609 case FMT_FT_C_C: return "FMT_FT_C_C";
1610 case FMT_FT_C_X: return "FMT_FT_C_X";
1611 case FMT_FT_X_C: return "FMT_FT_X_C";
1612 case FMT_FT_X_X: return "FMT_FT_X_X";
1613 case FMT_UT_C_C: return "FMT_UT_C_C";
1614 case FMT_UT_C_X: return "FMT_UT_C_X";
1615 case FMT_UT_X_C: return "FMT_UT_X_C";
1616 case FMT_UT_X_X: return "FMT_UT_X_X";
1617 case FMT_ET: return "FMT_ET";
1618 default: return "FMT_<unknown>";
1619 }
1620 }
1621
1622 static const char *
1623 dwarf_fund_type_name (ft)
1624 register unsigned ft;
1625 {
1626 switch (ft)
1627 {
1628 case FT_char: return "FT_char";
1629 case FT_signed_char: return "FT_signed_char";
1630 case FT_unsigned_char: return "FT_unsigned_char";
1631 case FT_short: return "FT_short";
1632 case FT_signed_short: return "FT_signed_short";
1633 case FT_unsigned_short: return "FT_unsigned_short";
1634 case FT_integer: return "FT_integer";
1635 case FT_signed_integer: return "FT_signed_integer";
1636 case FT_unsigned_integer: return "FT_unsigned_integer";
1637 case FT_long: return "FT_long";
1638 case FT_signed_long: return "FT_signed_long";
1639 case FT_unsigned_long: return "FT_unsigned_long";
1640 case FT_pointer: return "FT_pointer";
1641 case FT_float: return "FT_float";
1642 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1643 case FT_ext_prec_float: return "FT_ext_prec_float";
1644 case FT_complex: return "FT_complex";
1645 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1646 case FT_void: return "FT_void";
1647 case FT_boolean: return "FT_boolean";
1648 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1649 case FT_label: return "FT_label";
1650
1651 /* GNU extensions. */
1652
1653 case FT_long_long: return "FT_long_long";
1654 case FT_signed_long_long: return "FT_signed_long_long";
1655 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1656
1657 case FT_int8: return "FT_int8";
1658 case FT_signed_int8: return "FT_signed_int8";
1659 case FT_unsigned_int8: return "FT_unsigned_int8";
1660 case FT_int16: return "FT_int16";
1661 case FT_signed_int16: return "FT_signed_int16";
1662 case FT_unsigned_int16: return "FT_unsigned_int16";
1663 case FT_int32: return "FT_int32";
1664 case FT_signed_int32: return "FT_signed_int32";
1665 case FT_unsigned_int32: return "FT_unsigned_int32";
1666 case FT_int64: return "FT_int64";
1667 case FT_signed_int64: return "FT_signed_int64";
1668 case FT_unsigned_int64: return "FT_unsigned_int64";
1669 case FT_int128: return "FT_int128";
1670 case FT_signed_int128: return "FT_signed_int128";
1671 case FT_unsigned_int128: return "FT_unsigned_int128";
1672
1673 case FT_real32: return "FT_real32";
1674 case FT_real64: return "FT_real64";
1675 case FT_real96: return "FT_real96";
1676 case FT_real128: return "FT_real128";
1677
1678 default: return "FT_<unknown>";
1679 }
1680 }
1681
1682 /* Determine the "ultimate origin" of a decl. The decl may be an
1683 inlined instance of an inlined instance of a decl which is local
1684 to an inline function, so we have to trace all of the way back
1685 through the origin chain to find out what sort of node actually
1686 served as the original seed for the given block. */
1687
1688 static tree
1689 decl_ultimate_origin (decl)
1690 register tree decl;
1691 {
1692 #ifdef ENABLE_CHECKING
1693 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1694 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1695 most distant ancestor, this should never happen. */
1696 abort ();
1697 #endif
1698
1699 return DECL_ABSTRACT_ORIGIN (decl);
1700 }
1701
1702 /* Determine the "ultimate origin" of a block. The block may be an
1703 inlined instance of an inlined instance of a block which is local
1704 to an inline function, so we have to trace all of the way back
1705 through the origin chain to find out what sort of node actually
1706 served as the original seed for the given block. */
1707
1708 static tree
1709 block_ultimate_origin (block)
1710 register tree block;
1711 {
1712 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1713
1714 if (immediate_origin == NULL)
1715 return NULL;
1716 else
1717 {
1718 register tree ret_val;
1719 register tree lookahead = immediate_origin;
1720
1721 do
1722 {
1723 ret_val = lookahead;
1724 lookahead = (TREE_CODE (ret_val) == BLOCK)
1725 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1726 : NULL;
1727 }
1728 while (lookahead != NULL && lookahead != ret_val);
1729 return ret_val;
1730 }
1731 }
1732
1733 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1734 of a virtual function may refer to a base class, so we check the 'this'
1735 parameter. */
1736
1737 static tree
1738 decl_class_context (decl)
1739 tree decl;
1740 {
1741 tree context = NULL_TREE;
1742 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1743 context = DECL_CONTEXT (decl);
1744 else
1745 context = TYPE_MAIN_VARIANT
1746 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1747
1748 if (context && !TYPE_P (context))
1749 context = NULL_TREE;
1750
1751 return context;
1752 }
1753
1754 #if 0
1755 static void
1756 output_unsigned_leb128 (value)
1757 register unsigned long value;
1758 {
1759 register unsigned long orig_value = value;
1760
1761 do
1762 {
1763 register unsigned byte = (value & 0x7f);
1764
1765 value >>= 7;
1766 if (value != 0) /* more bytes to follow */
1767 byte |= 0x80;
1768 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1769 if (flag_debug_asm && value == 0)
1770 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1771 ASM_COMMENT_START, orig_value);
1772 fputc ('\n', asm_out_file);
1773 }
1774 while (value != 0);
1775 }
1776
1777 static void
1778 output_signed_leb128 (value)
1779 register long value;
1780 {
1781 register long orig_value = value;
1782 register int negative = (value < 0);
1783 register int more;
1784
1785 do
1786 {
1787 register unsigned byte = (value & 0x7f);
1788
1789 value >>= 7;
1790 if (negative)
1791 value |= 0xfe000000; /* manually sign extend */
1792 if (((value == 0) && ((byte & 0x40) == 0))
1793 || ((value == -1) && ((byte & 0x40) == 1)))
1794 more = 0;
1795 else
1796 {
1797 byte |= 0x80;
1798 more = 1;
1799 }
1800 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1801 if (flag_debug_asm && more == 0)
1802 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1803 ASM_COMMENT_START, orig_value);
1804 fputc ('\n', asm_out_file);
1805 }
1806 while (more);
1807 }
1808 #endif
1809 \f
1810 /**************** utility functions for attribute functions ******************/
1811
1812 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1813 type code for the given type.
1814
1815 This routine must only be called for GCC type nodes that correspond to
1816 Dwarf fundamental types.
1817
1818 The current Dwarf draft specification calls for Dwarf fundamental types
1819 to accurately reflect the fact that a given type was either a "plain"
1820 integral type or an explicitly "signed" integral type. Unfortunately,
1821 we can't always do this, because GCC may already have thrown away the
1822 information about the precise way in which the type was originally
1823 specified, as in:
1824
1825 typedef signed int my_type;
1826
1827 struct s { my_type f; };
1828
1829 Since we may be stuck here without enought information to do exactly
1830 what is called for in the Dwarf draft specification, we do the best
1831 that we can under the circumstances and always use the "plain" integral
1832 fundamental type codes for int, short, and long types. That's probably
1833 good enough. The additional accuracy called for in the current DWARF
1834 draft specification is probably never even useful in practice. */
1835
1836 static int
1837 fundamental_type_code (type)
1838 register tree type;
1839 {
1840 if (TREE_CODE (type) == ERROR_MARK)
1841 return 0;
1842
1843 switch (TREE_CODE (type))
1844 {
1845 case ERROR_MARK:
1846 return FT_void;
1847
1848 case VOID_TYPE:
1849 return FT_void;
1850
1851 case INTEGER_TYPE:
1852 /* Carefully distinguish all the standard types of C,
1853 without messing up if the language is not C.
1854 Note that we check only for the names that contain spaces;
1855 other names might occur by coincidence in other languages. */
1856 if (TYPE_NAME (type) != 0
1857 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1858 && DECL_NAME (TYPE_NAME (type)) != 0
1859 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1860 {
1861 const char *name =
1862 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1863
1864 if (!strcmp (name, "unsigned char"))
1865 return FT_unsigned_char;
1866 if (!strcmp (name, "signed char"))
1867 return FT_signed_char;
1868 if (!strcmp (name, "unsigned int"))
1869 return FT_unsigned_integer;
1870 if (!strcmp (name, "short int"))
1871 return FT_short;
1872 if (!strcmp (name, "short unsigned int"))
1873 return FT_unsigned_short;
1874 if (!strcmp (name, "long int"))
1875 return FT_long;
1876 if (!strcmp (name, "long unsigned int"))
1877 return FT_unsigned_long;
1878 if (!strcmp (name, "long long int"))
1879 return FT_long_long; /* Not grok'ed by svr4 SDB */
1880 if (!strcmp (name, "long long unsigned int"))
1881 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1882 }
1883
1884 /* Most integer types will be sorted out above, however, for the
1885 sake of special `array index' integer types, the following code
1886 is also provided. */
1887
1888 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1889 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1890
1891 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1892 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1893
1894 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1895 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1896
1897 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1898 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1899
1900 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1901 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1902
1903 if (TYPE_MODE (type) == TImode)
1904 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1905
1906 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1907 if (TYPE_PRECISION (type) == 1)
1908 return FT_boolean;
1909
1910 abort ();
1911
1912 case REAL_TYPE:
1913 /* Carefully distinguish all the standard types of C,
1914 without messing up if the language is not C. */
1915 if (TYPE_NAME (type) != 0
1916 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1917 && DECL_NAME (TYPE_NAME (type)) != 0
1918 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1919 {
1920 const char *name =
1921 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1922
1923 /* Note that here we can run afowl of a serious bug in "classic"
1924 svr4 SDB debuggers. They don't seem to understand the
1925 FT_ext_prec_float type (even though they should). */
1926
1927 if (!strcmp (name, "long double"))
1928 return FT_ext_prec_float;
1929 }
1930
1931 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1932 {
1933 /* On the SH, when compiling with -m3e or -m4-single-only, both
1934 float and double are 32 bits. But since the debugger doesn't
1935 know about the subtarget, it always thinks double is 64 bits.
1936 So we have to tell the debugger that the type is float to
1937 make the output of the 'print' command etc. readable. */
1938 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1939 return FT_float;
1940 return FT_dbl_prec_float;
1941 }
1942 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1943 return FT_float;
1944
1945 /* Note that here we can run afowl of a serious bug in "classic"
1946 svr4 SDB debuggers. They don't seem to understand the
1947 FT_ext_prec_float type (even though they should). */
1948
1949 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1950 return FT_ext_prec_float;
1951 abort ();
1952
1953 case COMPLEX_TYPE:
1954 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1955
1956 case CHAR_TYPE:
1957 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1958
1959 case BOOLEAN_TYPE:
1960 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1961
1962 default:
1963 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1964 }
1965 return 0;
1966 }
1967 \f
1968 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1969 the Dwarf "root" type for the given input type. The Dwarf "root" type
1970 of a given type is generally the same as the given type, except that if
1971 the given type is a pointer or reference type, then the root type of
1972 the given type is the root type of the "basis" type for the pointer or
1973 reference type. (This definition of the "root" type is recursive.)
1974 Also, the root type of a `const' qualified type or a `volatile'
1975 qualified type is the root type of the given type without the
1976 qualifiers. */
1977
1978 static tree
1979 root_type_1 (type, count)
1980 register tree type;
1981 register int count;
1982 {
1983 /* Give up after searching 1000 levels, in case this is a recursive
1984 pointer type. Such types are possible in Ada, but it is not possible
1985 to represent them in DWARF1 debug info. */
1986 if (count > 1000)
1987 return error_mark_node;
1988
1989 switch (TREE_CODE (type))
1990 {
1991 case ERROR_MARK:
1992 return error_mark_node;
1993
1994 case POINTER_TYPE:
1995 case REFERENCE_TYPE:
1996 return root_type_1 (TREE_TYPE (type), count+1);
1997
1998 default:
1999 return type;
2000 }
2001 }
2002
2003 static tree
2004 root_type (type)
2005 register tree type;
2006 {
2007 type = root_type_1 (type, 0);
2008 if (type != error_mark_node)
2009 type = type_main_variant (type);
2010 return type;
2011 }
2012
2013 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
2014 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
2015
2016 static void
2017 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
2018 register tree type;
2019 register int decl_const;
2020 register int decl_volatile;
2021 register int count;
2022 {
2023 if (TREE_CODE (type) == ERROR_MARK)
2024 return;
2025
2026 /* Give up after searching 1000 levels, in case this is a recursive
2027 pointer type. Such types are possible in Ada, but it is not possible
2028 to represent them in DWARF1 debug info. */
2029 if (count > 1000)
2030 return;
2031
2032 if (TYPE_READONLY (type) || decl_const)
2033 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
2034 if (TYPE_VOLATILE (type) || decl_volatile)
2035 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
2036 switch (TREE_CODE (type))
2037 {
2038 case POINTER_TYPE:
2039 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
2040 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
2041 return;
2042
2043 case REFERENCE_TYPE:
2044 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
2045 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
2046 return;
2047
2048 case ERROR_MARK:
2049 default:
2050 return;
2051 }
2052 }
2053
2054 static void
2055 write_modifier_bytes (type, decl_const, decl_volatile)
2056 register tree type;
2057 register int decl_const;
2058 register int decl_volatile;
2059 {
2060 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
2061 }
2062 \f
2063 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
2064 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
2065
2066 static inline int
2067 type_is_fundamental (type)
2068 register tree type;
2069 {
2070 switch (TREE_CODE (type))
2071 {
2072 case ERROR_MARK:
2073 case VOID_TYPE:
2074 case INTEGER_TYPE:
2075 case REAL_TYPE:
2076 case COMPLEX_TYPE:
2077 case BOOLEAN_TYPE:
2078 case CHAR_TYPE:
2079 return 1;
2080
2081 case SET_TYPE:
2082 case ARRAY_TYPE:
2083 case RECORD_TYPE:
2084 case UNION_TYPE:
2085 case QUAL_UNION_TYPE:
2086 case ENUMERAL_TYPE:
2087 case FUNCTION_TYPE:
2088 case METHOD_TYPE:
2089 case POINTER_TYPE:
2090 case REFERENCE_TYPE:
2091 case FILE_TYPE:
2092 case OFFSET_TYPE:
2093 case LANG_TYPE:
2094 case VECTOR_TYPE:
2095 return 0;
2096
2097 default:
2098 abort ();
2099 }
2100 return 0;
2101 }
2102
2103 /* Given a pointer to some ..._DECL tree node, generate an assembly language
2104 equate directive which will associate a symbolic name with the current DIE.
2105
2106 The name used is an artificial label generated from the DECL_UID number
2107 associated with the given decl node. The name it gets equated to is the
2108 symbolic label that we (previously) output at the start of the DIE that
2109 we are currently generating.
2110
2111 Calling this function while generating some "decl related" form of DIE
2112 makes it possible to later refer to the DIE which represents the given
2113 decl simply by re-generating the symbolic name from the ..._DECL node's
2114 UID number. */
2115
2116 static void
2117 equate_decl_number_to_die_number (decl)
2118 register tree decl;
2119 {
2120 /* In the case where we are generating a DIE for some ..._DECL node
2121 which represents either some inline function declaration or some
2122 entity declared within an inline function declaration/definition,
2123 setup a symbolic name for the current DIE so that we have a name
2124 for this DIE that we can easily refer to later on within
2125 AT_abstract_origin attributes. */
2126
2127 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
2128 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2129
2130 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
2131 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2132 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
2133 }
2134
2135 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
2136 equate directive which will associate a symbolic name with the current DIE.
2137
2138 The name used is an artificial label generated from the TYPE_UID number
2139 associated with the given type node. The name it gets equated to is the
2140 symbolic label that we (previously) output at the start of the DIE that
2141 we are currently generating.
2142
2143 Calling this function while generating some "type related" form of DIE
2144 makes it easy to later refer to the DIE which represents the given type
2145 simply by re-generating the alternative name from the ..._TYPE node's
2146 UID number. */
2147
2148 static inline void
2149 equate_type_number_to_die_number (type)
2150 register tree type;
2151 {
2152 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
2153 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2154
2155 /* We are generating a DIE to represent the main variant of this type
2156 (i.e the type without any const or volatile qualifiers) so in order
2157 to get the equate to come out right, we need to get the main variant
2158 itself here. */
2159
2160 type = type_main_variant (type);
2161
2162 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
2163 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2164 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
2165 }
2166
2167 static void
2168 output_reg_number (rtl)
2169 register rtx rtl;
2170 {
2171 register unsigned regno = REGNO (rtl);
2172
2173 if (regno >= DWARF_FRAME_REGISTERS)
2174 {
2175 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
2176 regno);
2177 regno = 0;
2178 }
2179 fprintf (asm_out_file, "%s0x%x",
2180 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
2181 if (flag_debug_asm)
2182 {
2183 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
2184 PRINT_REG (rtl, 0, asm_out_file);
2185 }
2186 fputc ('\n', asm_out_file);
2187 }
2188
2189 /* The following routine is a nice and simple transducer. It converts the
2190 RTL for a variable or parameter (resident in memory) into an equivalent
2191 Dwarf representation of a mechanism for getting the address of that same
2192 variable onto the top of a hypothetical "address evaluation" stack.
2193
2194 When creating memory location descriptors, we are effectively trans-
2195 forming the RTL for a memory-resident object into its Dwarf postfix
2196 expression equivalent. This routine just recursively descends an
2197 RTL tree, turning it into Dwarf postfix code as it goes. */
2198
2199 static void
2200 output_mem_loc_descriptor (rtl)
2201 register rtx rtl;
2202 {
2203 /* Note that for a dynamically sized array, the location we will
2204 generate a description of here will be the lowest numbered location
2205 which is actually within the array. That's *not* necessarily the
2206 same as the zeroth element of the array. */
2207
2208 #ifdef ASM_SIMPLIFY_DWARF_ADDR
2209 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
2210 #endif
2211
2212 switch (GET_CODE (rtl))
2213 {
2214 case SUBREG:
2215
2216 /* The case of a subreg may arise when we have a local (register)
2217 variable or a formal (register) parameter which doesn't quite
2218 fill up an entire register. For now, just assume that it is
2219 legitimate to make the Dwarf info refer to the whole register
2220 which contains the given subreg. */
2221
2222 rtl = SUBREG_REG (rtl);
2223 /* Drop thru. */
2224
2225 case REG:
2226
2227 /* Whenever a register number forms a part of the description of
2228 the method for calculating the (dynamic) address of a memory
2229 resident object, DWARF rules require the register number to
2230 be referred to as a "base register". This distinction is not
2231 based in any way upon what category of register the hardware
2232 believes the given register belongs to. This is strictly
2233 DWARF terminology we're dealing with here.
2234
2235 Note that in cases where the location of a memory-resident data
2236 object could be expressed as:
2237
2238 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
2239
2240 the actual DWARF location descriptor that we generate may just
2241 be OP_BASEREG (basereg). This may look deceptively like the
2242 object in question was allocated to a register (rather than
2243 in memory) so DWARF consumers need to be aware of the subtle
2244 distinction between OP_REG and OP_BASEREG. */
2245
2246 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
2247 output_reg_number (rtl);
2248 break;
2249
2250 case MEM:
2251 output_mem_loc_descriptor (XEXP (rtl, 0));
2252 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
2253 break;
2254
2255 case CONST:
2256 case SYMBOL_REF:
2257 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
2258 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2259 break;
2260
2261 case PLUS:
2262 output_mem_loc_descriptor (XEXP (rtl, 0));
2263 output_mem_loc_descriptor (XEXP (rtl, 1));
2264 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2265 break;
2266
2267 case CONST_INT:
2268 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2269 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
2270 break;
2271
2272 case MULT:
2273 /* If a pseudo-reg is optimized away, it is possible for it to
2274 be replaced with a MEM containing a multiply. Use a GNU extension
2275 to describe it. */
2276 output_mem_loc_descriptor (XEXP (rtl, 0));
2277 output_mem_loc_descriptor (XEXP (rtl, 1));
2278 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
2279 break;
2280
2281 default:
2282 abort ();
2283 }
2284 }
2285
2286 /* Output a proper Dwarf location descriptor for a variable or parameter
2287 which is either allocated in a register or in a memory location. For
2288 a register, we just generate an OP_REG and the register number. For a
2289 memory location we provide a Dwarf postfix expression describing how to
2290 generate the (dynamic) address of the object onto the address stack. */
2291
2292 static void
2293 output_loc_descriptor (rtl)
2294 register rtx rtl;
2295 {
2296 switch (GET_CODE (rtl))
2297 {
2298 case SUBREG:
2299
2300 /* The case of a subreg may arise when we have a local (register)
2301 variable or a formal (register) parameter which doesn't quite
2302 fill up an entire register. For now, just assume that it is
2303 legitimate to make the Dwarf info refer to the whole register
2304 which contains the given subreg. */
2305
2306 rtl = SUBREG_REG (rtl);
2307 /* Drop thru. */
2308
2309 case REG:
2310 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
2311 output_reg_number (rtl);
2312 break;
2313
2314 case MEM:
2315 output_mem_loc_descriptor (XEXP (rtl, 0));
2316 break;
2317
2318 default:
2319 abort (); /* Should never happen */
2320 }
2321 }
2322
2323 /* Given a tree node describing an array bound (either lower or upper)
2324 output a representation for that bound. */
2325
2326 static void
2327 output_bound_representation (bound, dim_num, u_or_l)
2328 register tree bound;
2329 register unsigned dim_num; /* For multi-dimensional arrays. */
2330 register char u_or_l; /* Designates upper or lower bound. */
2331 {
2332 switch (TREE_CODE (bound))
2333 {
2334
2335 case ERROR_MARK:
2336 return;
2337
2338 /* All fixed-bounds are represented by INTEGER_CST nodes. */
2339
2340 case INTEGER_CST:
2341 if (host_integerp (bound, 0))
2342 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
2343 break;
2344
2345 default:
2346
2347 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
2348 SAVE_EXPR nodes, in which case we can do something, or as
2349 an expression, which we cannot represent. */
2350 {
2351 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2352 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2353
2354 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
2355 current_dienum, dim_num, u_or_l);
2356
2357 sprintf (end_label, BOUND_END_LABEL_FMT,
2358 current_dienum, dim_num, u_or_l);
2359
2360 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2361 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2362
2363 /* If optimization is turned on, the SAVE_EXPRs that describe
2364 how to access the upper bound values are essentially bogus.
2365 They only describe (at best) how to get at these values at
2366 the points in the generated code right after they have just
2367 been computed. Worse yet, in the typical case, the upper
2368 bound values will not even *be* computed in the optimized
2369 code, so these SAVE_EXPRs are entirely bogus.
2370
2371 In order to compensate for this fact, we check here to see
2372 if optimization is enabled, and if so, we effectively create
2373 an empty location description for the (unknown and unknowable)
2374 upper bound.
2375
2376 This should not cause too much trouble for existing (stupid?)
2377 debuggers because they have to deal with empty upper bounds
2378 location descriptions anyway in order to be able to deal with
2379 incomplete array types.
2380
2381 Of course an intelligent debugger (GDB?) should be able to
2382 comprehend that a missing upper bound specification in a
2383 array type used for a storage class `auto' local array variable
2384 indicates that the upper bound is both unknown (at compile-
2385 time) and unknowable (at run-time) due to optimization. */
2386
2387 if (! optimize)
2388 {
2389 while (TREE_CODE (bound) == NOP_EXPR
2390 || TREE_CODE (bound) == CONVERT_EXPR)
2391 bound = TREE_OPERAND (bound, 0);
2392
2393 if (TREE_CODE (bound) == SAVE_EXPR)
2394 output_loc_descriptor
2395 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
2396 }
2397
2398 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2399 }
2400 break;
2401
2402 }
2403 }
2404
2405 /* Recursive function to output a sequence of value/name pairs for
2406 enumeration constants in reversed order. This is called from
2407 enumeration_type_die. */
2408
2409 static void
2410 output_enumeral_list (link)
2411 register tree link;
2412 {
2413 if (link)
2414 {
2415 output_enumeral_list (TREE_CHAIN (link));
2416
2417 if (host_integerp (TREE_VALUE (link), 0))
2418 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2419 tree_low_cst (TREE_VALUE (link), 0));
2420
2421 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
2422 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
2423 }
2424 }
2425
2426 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
2427 which is not less than the value itself. */
2428
2429 static inline HOST_WIDE_INT
2430 ceiling (value, boundary)
2431 register HOST_WIDE_INT value;
2432 register unsigned int boundary;
2433 {
2434 return (((value + boundary - 1) / boundary) * boundary);
2435 }
2436
2437 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
2438 pointer to the declared type for the relevant field variable, or return
2439 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
2440
2441 static inline tree
2442 field_type (decl)
2443 register tree decl;
2444 {
2445 register tree type;
2446
2447 if (TREE_CODE (decl) == ERROR_MARK)
2448 return integer_type_node;
2449
2450 type = DECL_BIT_FIELD_TYPE (decl);
2451 if (type == NULL)
2452 type = TREE_TYPE (decl);
2453 return type;
2454 }
2455
2456 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2457 node, return the alignment in bits for the type, or else return
2458 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
2459
2460 static inline unsigned int
2461 simple_type_align_in_bits (type)
2462 register tree type;
2463 {
2464 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
2465 }
2466
2467 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2468 node, return the size in bits for the type if it is a constant, or
2469 else return the alignment for the type if the type's size is not
2470 constant, or else return BITS_PER_WORD if the type actually turns out
2471 to be an ERROR_MARK node. */
2472
2473 static inline unsigned HOST_WIDE_INT
2474 simple_type_size_in_bits (type)
2475 register tree type;
2476 {
2477 tree type_size_tree;
2478
2479 if (TREE_CODE (type) == ERROR_MARK)
2480 return BITS_PER_WORD;
2481 type_size_tree = TYPE_SIZE (type);
2482
2483 if (type_size_tree == NULL_TREE)
2484 return 0;
2485 if (! host_integerp (type_size_tree, 1))
2486 return TYPE_ALIGN (type);
2487 return tree_low_cst (type_size_tree, 1);
2488 }
2489
2490 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
2491 return the byte offset of the lowest addressed byte of the "containing
2492 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
2493 mine what that offset is, either because the argument turns out to be a
2494 pointer to an ERROR_MARK node, or because the offset is actually variable.
2495 (We can't handle the latter case just yet.) */
2496
2497 static HOST_WIDE_INT
2498 field_byte_offset (decl)
2499 register tree decl;
2500 {
2501 unsigned int type_align_in_bytes;
2502 unsigned int type_align_in_bits;
2503 unsigned HOST_WIDE_INT type_size_in_bits;
2504 HOST_WIDE_INT object_offset_in_align_units;
2505 HOST_WIDE_INT object_offset_in_bits;
2506 HOST_WIDE_INT object_offset_in_bytes;
2507 tree type;
2508 tree field_size_tree;
2509 HOST_WIDE_INT bitpos_int;
2510 HOST_WIDE_INT deepest_bitpos;
2511 unsigned HOST_WIDE_INT field_size_in_bits;
2512
2513 if (TREE_CODE (decl) == ERROR_MARK)
2514 return 0;
2515
2516 if (TREE_CODE (decl) != FIELD_DECL)
2517 abort ();
2518
2519 type = field_type (decl);
2520 field_size_tree = DECL_SIZE (decl);
2521
2522 /* The size could be unspecified if there was an error, or for
2523 a flexible array member. */
2524 if (! field_size_tree)
2525 field_size_tree = bitsize_zero_node;
2526
2527 /* We cannot yet cope with fields whose positions or sizes are variable,
2528 so for now, when we see such things, we simply return 0. Someday,
2529 we may be able to handle such cases, but it will be damn difficult. */
2530
2531 if (! host_integerp (bit_position (decl), 0)
2532 || ! host_integerp (field_size_tree, 1))
2533 return 0;
2534
2535 bitpos_int = int_bit_position (decl);
2536 field_size_in_bits = tree_low_cst (field_size_tree, 1);
2537
2538 type_size_in_bits = simple_type_size_in_bits (type);
2539 type_align_in_bits = simple_type_align_in_bits (type);
2540 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2541
2542 /* Note that the GCC front-end doesn't make any attempt to keep track
2543 of the starting bit offset (relative to the start of the containing
2544 structure type) of the hypothetical "containing object" for a bit-
2545 field. Thus, when computing the byte offset value for the start of
2546 the "containing object" of a bit-field, we must deduce this infor-
2547 mation on our own.
2548
2549 This can be rather tricky to do in some cases. For example, handling
2550 the following structure type definition when compiling for an i386/i486
2551 target (which only aligns long long's to 32-bit boundaries) can be very
2552 tricky:
2553
2554 struct S {
2555 int field1;
2556 long long field2:31;
2557 };
2558
2559 Fortunately, there is a simple rule-of-thumb which can be used in such
2560 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2561 the structure shown above. It decides to do this based upon one simple
2562 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2563 taining object" for each bit-field at the first (i.e. lowest addressed)
2564 legitimate alignment boundary (based upon the required minimum alignment
2565 for the declared type of the field) which it can possibly use, subject
2566 to the condition that there is still enough available space remaining
2567 in the containing object (when allocated at the selected point) to
2568 fully accommodate all of the bits of the bit-field itself.
2569
2570 This simple rule makes it obvious why GCC allocates 8 bytes for each
2571 object of the structure type shown above. When looking for a place to
2572 allocate the "containing object" for `field2', the compiler simply tries
2573 to allocate a 64-bit "containing object" at each successive 32-bit
2574 boundary (starting at zero) until it finds a place to allocate that 64-
2575 bit field such that at least 31 contiguous (and previously unallocated)
2576 bits remain within that selected 64 bit field. (As it turns out, for
2577 the example above, the compiler finds that it is OK to allocate the
2578 "containing object" 64-bit field at bit-offset zero within the
2579 structure type.)
2580
2581 Here we attempt to work backwards from the limited set of facts we're
2582 given, and we try to deduce from those facts, where GCC must have
2583 believed that the containing object started (within the structure type).
2584
2585 The value we deduce is then used (by the callers of this routine) to
2586 generate AT_location and AT_bit_offset attributes for fields (both
2587 bit-fields and, in the case of AT_location, regular fields as well). */
2588
2589 /* Figure out the bit-distance from the start of the structure to the
2590 "deepest" bit of the bit-field. */
2591 deepest_bitpos = bitpos_int + field_size_in_bits;
2592
2593 /* This is the tricky part. Use some fancy footwork to deduce where the
2594 lowest addressed bit of the containing object must be. */
2595 object_offset_in_bits
2596 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2597
2598 /* Compute the offset of the containing object in "alignment units". */
2599 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2600
2601 /* Compute the offset of the containing object in bytes. */
2602 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2603
2604 /* The above code assumes that the field does not cross an alignment
2605 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2606 or if the structure is packed. If this happens, then we get an object
2607 which starts after the bitfield, which means that the bit offset is
2608 negative. Gdb fails when given negative bit offsets. We avoid this
2609 by recomputing using the first bit of the bitfield. This will give
2610 us an object which does not completely contain the bitfield, but it
2611 will be aligned, and it will contain the first bit of the bitfield.
2612
2613 However, only do this for a BYTES_BIG_ENDIAN target. For a
2614 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2615 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2616 then we end up computing the object byte offset for the wrong word of the
2617 desired bitfield, which in turn causes the field offset to be negative
2618 in bit_offset_attribute. */
2619 if (BYTES_BIG_ENDIAN
2620 && object_offset_in_bits > bitpos_int)
2621 {
2622 deepest_bitpos = bitpos_int + 1;
2623 object_offset_in_bits
2624 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2625 object_offset_in_align_units = (object_offset_in_bits
2626 / type_align_in_bits);
2627 object_offset_in_bytes = (object_offset_in_align_units
2628 * type_align_in_bytes);
2629 }
2630
2631 return object_offset_in_bytes;
2632 }
2633
2634 /****************************** attributes *********************************/
2635
2636 /* The following routines are responsible for writing out the various types
2637 of Dwarf attributes (and any following data bytes associated with them).
2638 These routines are listed in order based on the numerical codes of their
2639 associated attributes. */
2640
2641 /* Generate an AT_sibling attribute. */
2642
2643 static inline void
2644 sibling_attribute ()
2645 {
2646 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2647
2648 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2649 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2650 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2651 }
2652
2653 /* Output the form of location attributes suitable for whole variables and
2654 whole parameters. Note that the location attributes for struct fields
2655 are generated by the routine `data_member_location_attribute' below. */
2656
2657 static void
2658 location_attribute (rtl)
2659 register rtx rtl;
2660 {
2661 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2662 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2663
2664 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2665 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2666 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2667 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2668 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2669
2670 /* Handle a special case. If we are about to output a location descriptor
2671 for a variable or parameter which has been optimized out of existence,
2672 don't do that. Instead we output a zero-length location descriptor
2673 value as part of the location attribute.
2674
2675 A variable which has been optimized out of existence will have a
2676 DECL_RTL value which denotes a pseudo-reg.
2677
2678 Currently, in some rare cases, variables can have DECL_RTL values
2679 which look like (MEM (REG pseudo-reg#)). These cases are due to
2680 bugs elsewhere in the compiler. We treat such cases
2681 as if the variable(s) in question had been optimized out of existence.
2682
2683 Note that in all cases where we wish to express the fact that a
2684 variable has been optimized out of existence, we do not simply
2685 suppress the generation of the entire location attribute because
2686 the absence of a location attribute in certain kinds of DIEs is
2687 used to indicate something else entirely... i.e. that the DIE
2688 represents an object declaration, but not a definition. So saith
2689 the PLSIG.
2690 */
2691
2692 if (! is_pseudo_reg (rtl)
2693 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2694 output_loc_descriptor (rtl);
2695
2696 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2697 }
2698
2699 /* Output the specialized form of location attribute used for data members
2700 of struct and union types.
2701
2702 In the special case of a FIELD_DECL node which represents a bit-field,
2703 the "offset" part of this special location descriptor must indicate the
2704 distance in bytes from the lowest-addressed byte of the containing
2705 struct or union type to the lowest-addressed byte of the "containing
2706 object" for the bit-field. (See the `field_byte_offset' function above.)
2707
2708 For any given bit-field, the "containing object" is a hypothetical
2709 object (of some integral or enum type) within which the given bit-field
2710 lives. The type of this hypothetical "containing object" is always the
2711 same as the declared type of the individual bit-field itself (for GCC
2712 anyway... the DWARF spec doesn't actually mandate this).
2713
2714 Note that it is the size (in bytes) of the hypothetical "containing
2715 object" which will be given in the AT_byte_size attribute for this
2716 bit-field. (See the `byte_size_attribute' function below.) It is
2717 also used when calculating the value of the AT_bit_offset attribute.
2718 (See the `bit_offset_attribute' function below.) */
2719
2720 static void
2721 data_member_location_attribute (t)
2722 register tree t;
2723 {
2724 register unsigned object_offset_in_bytes;
2725 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2726 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2727
2728 if (TREE_CODE (t) == TREE_VEC)
2729 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2730 else
2731 object_offset_in_bytes = field_byte_offset (t);
2732
2733 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2734 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2735 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2736 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2737 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2738 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2739 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2740 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2741 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2742 }
2743
2744 /* Output an AT_const_value attribute for a variable or a parameter which
2745 does not have a "location" either in memory or in a register. These
2746 things can arise in GNU C when a constant is passed as an actual
2747 parameter to an inlined function. They can also arise in C++ where
2748 declared constants do not necessarily get memory "homes". */
2749
2750 static void
2751 const_value_attribute (rtl)
2752 register rtx rtl;
2753 {
2754 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2755 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2756
2757 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2758 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2759 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2760 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2761 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2762
2763 switch (GET_CODE (rtl))
2764 {
2765 case CONST_INT:
2766 /* Note that a CONST_INT rtx could represent either an integer or
2767 a floating-point constant. A CONST_INT is used whenever the
2768 constant will fit into a single word. In all such cases, the
2769 original mode of the constant value is wiped out, and the
2770 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2771 precise mode information for these constants, we always just
2772 output them using 4 bytes. */
2773
2774 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2775 break;
2776
2777 case CONST_DOUBLE:
2778 /* Note that a CONST_DOUBLE rtx could represent either an integer
2779 or a floating-point constant. A CONST_DOUBLE is used whenever
2780 the constant requires more than one word in order to be adequately
2781 represented. In all such cases, the original mode of the constant
2782 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2783 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2784
2785 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2786 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2787 (unsigned int) CONST_DOUBLE_LOW (rtl));
2788 break;
2789
2790 case CONST_STRING:
2791 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2792 break;
2793
2794 case SYMBOL_REF:
2795 case LABEL_REF:
2796 case CONST:
2797 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2798 break;
2799
2800 case PLUS:
2801 /* In cases where an inlined instance of an inline function is passed
2802 the address of an `auto' variable (which is local to the caller)
2803 we can get a situation where the DECL_RTL of the artificial
2804 local variable (for the inlining) which acts as a stand-in for
2805 the corresponding formal parameter (of the inline function)
2806 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2807 This is not exactly a compile-time constant expression, but it
2808 isn't the address of the (artificial) local variable either.
2809 Rather, it represents the *value* which the artificial local
2810 variable always has during its lifetime. We currently have no
2811 way to represent such quasi-constant values in Dwarf, so for now
2812 we just punt and generate an AT_const_value attribute with form
2813 FORM_BLOCK4 and a length of zero. */
2814 break;
2815
2816 default:
2817 abort (); /* No other kinds of rtx should be possible here. */
2818 }
2819
2820 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2821 }
2822
2823 /* Generate *either* an AT_location attribute or else an AT_const_value
2824 data attribute for a variable or a parameter. We generate the
2825 AT_const_value attribute only in those cases where the given
2826 variable or parameter does not have a true "location" either in
2827 memory or in a register. This can happen (for example) when a
2828 constant is passed as an actual argument in a call to an inline
2829 function. (It's possible that these things can crop up in other
2830 ways also.) Note that one type of constant value which can be
2831 passed into an inlined function is a constant pointer. This can
2832 happen for example if an actual argument in an inlined function
2833 call evaluates to a compile-time constant address. */
2834
2835 static void
2836 location_or_const_value_attribute (decl)
2837 register tree decl;
2838 {
2839 register rtx rtl;
2840
2841 if (TREE_CODE (decl) == ERROR_MARK)
2842 return;
2843
2844 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2845 {
2846 /* Should never happen. */
2847 abort ();
2848 return;
2849 }
2850
2851 /* Here we have to decide where we are going to say the parameter "lives"
2852 (as far as the debugger is concerned). We only have a couple of choices.
2853 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2854 normally indicates where the parameter lives during most of the activa-
2855 tion of the function. If optimization is enabled however, this could
2856 be either NULL or else a pseudo-reg. Both of those cases indicate that
2857 the parameter doesn't really live anywhere (as far as the code generation
2858 parts of GCC are concerned) during most of the function's activation.
2859 That will happen (for example) if the parameter is never referenced
2860 within the function.
2861
2862 We could just generate a location descriptor here for all non-NULL
2863 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2864 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2865 cases where DECL_RTL is NULL or is a pseudo-reg.
2866
2867 Note however that we can only get away with using DECL_INCOMING_RTL as
2868 a backup substitute for DECL_RTL in certain limited cases. In cases
2869 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2870 we can be sure that the parameter was passed using the same type as it
2871 is declared to have within the function, and that its DECL_INCOMING_RTL
2872 points us to a place where a value of that type is passed. In cases
2873 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2874 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2875 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2876 points us to a value of some type which is *different* from the type
2877 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2878 to generate a location attribute in such cases, the debugger would
2879 end up (for example) trying to fetch a `float' from a place which
2880 actually contains the first part of a `double'. That would lead to
2881 really incorrect and confusing output at debug-time, and we don't
2882 want that now do we?
2883
2884 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2885 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2886 couple of cute exceptions however. On little-endian machines we can
2887 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2888 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2889 an integral type which is smaller than TREE_TYPE(decl). These cases
2890 arise when (on a little-endian machine) a non-prototyped function has
2891 a parameter declared to be of type `short' or `char'. In such cases,
2892 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2893 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2894 passed `int' value. If the debugger then uses that address to fetch a
2895 `short' or a `char' (on a little-endian machine) the result will be the
2896 correct data, so we allow for such exceptional cases below.
2897
2898 Note that our goal here is to describe the place where the given formal
2899 parameter lives during most of the function's activation (i.e. between
2900 the end of the prologue and the start of the epilogue). We'll do that
2901 as best as we can. Note however that if the given formal parameter is
2902 modified sometime during the execution of the function, then a stack
2903 backtrace (at debug-time) will show the function as having been called
2904 with the *new* value rather than the value which was originally passed
2905 in. This happens rarely enough that it is not a major problem, but it
2906 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2907 may generate two additional attributes for any given TAG_formal_parameter
2908 DIE which will describe the "passed type" and the "passed location" for
2909 the given formal parameter in addition to the attributes we now generate
2910 to indicate the "declared type" and the "active location" for each
2911 parameter. This additional set of attributes could be used by debuggers
2912 for stack backtraces.
2913
2914 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2915 can be NULL also. This happens (for example) for inlined-instances of
2916 inline function formal parameters which are never referenced. This really
2917 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2918 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2919 these values for inlined instances of inline function parameters, so
2920 when we see such cases, we are just out-of-luck for the time
2921 being (until integrate.c gets fixed).
2922 */
2923
2924 /* Use DECL_RTL as the "location" unless we find something better. */
2925 rtl = DECL_RTL (decl);
2926
2927 if (TREE_CODE (decl) == PARM_DECL)
2928 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2929 {
2930 /* This decl represents a formal parameter which was optimized out. */
2931 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2932 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2933
2934 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2935 *all* cases where (rtl == NULL_RTX) just below. */
2936
2937 if (declared_type == passed_type)
2938 rtl = DECL_INCOMING_RTL (decl);
2939 else if (! BYTES_BIG_ENDIAN)
2940 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2941 /* NMS WTF? */
2942 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2943 rtl = DECL_INCOMING_RTL (decl);
2944 }
2945
2946 if (rtl == NULL_RTX)
2947 return;
2948
2949 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2950 #ifdef LEAF_REG_REMAP
2951 if (current_function_uses_only_leaf_regs)
2952 leaf_renumber_regs_insn (rtl);
2953 #endif
2954
2955 switch (GET_CODE (rtl))
2956 {
2957 case ADDRESSOF:
2958 /* The address of a variable that was optimized away; don't emit
2959 anything. */
2960 break;
2961
2962 case CONST_INT:
2963 case CONST_DOUBLE:
2964 case CONST_STRING:
2965 case SYMBOL_REF:
2966 case LABEL_REF:
2967 case CONST:
2968 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2969 const_value_attribute (rtl);
2970 break;
2971
2972 case MEM:
2973 case REG:
2974 case SUBREG:
2975 location_attribute (rtl);
2976 break;
2977
2978 case CONCAT:
2979 /* ??? CONCAT is used for complex variables, which may have the real
2980 part stored in one place and the imag part stored somewhere else.
2981 DWARF1 has no way to describe a variable that lives in two different
2982 places, so we just describe where the first part lives, and hope that
2983 the second part is stored after it. */
2984 location_attribute (XEXP (rtl, 0));
2985 break;
2986
2987 default:
2988 abort (); /* Should never happen. */
2989 }
2990 }
2991
2992 /* Generate an AT_name attribute given some string value to be included as
2993 the value of the attribute. */
2994
2995 static inline void
2996 name_attribute (name_string)
2997 register const char *name_string;
2998 {
2999 if (name_string && *name_string)
3000 {
3001 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
3002 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
3003 }
3004 }
3005
3006 static inline void
3007 fund_type_attribute (ft_code)
3008 register unsigned ft_code;
3009 {
3010 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
3011 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
3012 }
3013
3014 static void
3015 mod_fund_type_attribute (type, decl_const, decl_volatile)
3016 register tree type;
3017 register int decl_const;
3018 register int decl_volatile;
3019 {
3020 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3021 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3022
3023 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
3024 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
3025 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
3026 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3027 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3028 write_modifier_bytes (type, decl_const, decl_volatile);
3029 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3030 fundamental_type_code (root_type (type)));
3031 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3032 }
3033
3034 static inline void
3035 user_def_type_attribute (type)
3036 register tree type;
3037 {
3038 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
3039
3040 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
3041 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
3042 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
3043 }
3044
3045 static void
3046 mod_u_d_type_attribute (type, decl_const, decl_volatile)
3047 register tree type;
3048 register int decl_const;
3049 register int decl_volatile;
3050 {
3051 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3052 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3053 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
3054
3055 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
3056 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
3057 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
3058 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3059 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3060 write_modifier_bytes (type, decl_const, decl_volatile);
3061 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
3062 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
3063 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3064 }
3065
3066 #ifdef USE_ORDERING_ATTRIBUTE
3067 static inline void
3068 ordering_attribute (ordering)
3069 register unsigned ordering;
3070 {
3071 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
3072 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
3073 }
3074 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3075
3076 /* Note that the block of subscript information for an array type also
3077 includes information about the element type of type given array type. */
3078
3079 static void
3080 subscript_data_attribute (type)
3081 register tree type;
3082 {
3083 register unsigned dimension_number;
3084 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3085 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3086
3087 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
3088 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
3089 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
3090 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3091 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3092
3093 /* The GNU compilers represent multidimensional array types as sequences
3094 of one dimensional array types whose element types are themselves array
3095 types. Here we squish that down, so that each multidimensional array
3096 type gets only one array_type DIE in the Dwarf debugging info. The
3097 draft Dwarf specification say that we are allowed to do this kind
3098 of compression in C (because there is no difference between an
3099 array or arrays and a multidimensional array in C) but for other
3100 source languages (e.g. Ada) we probably shouldn't do this. */
3101
3102 for (dimension_number = 0;
3103 TREE_CODE (type) == ARRAY_TYPE;
3104 type = TREE_TYPE (type), dimension_number++)
3105 {
3106 register tree domain = TYPE_DOMAIN (type);
3107
3108 /* Arrays come in three flavors. Unspecified bounds, fixed
3109 bounds, and (in GNU C only) variable bounds. Handle all
3110 three forms here. */
3111
3112 if (domain)
3113 {
3114 /* We have an array type with specified bounds. */
3115
3116 register tree lower = TYPE_MIN_VALUE (domain);
3117 register tree upper = TYPE_MAX_VALUE (domain);
3118
3119 /* Handle only fundamental types as index types for now. */
3120 if (! type_is_fundamental (domain))
3121 abort ();
3122
3123 /* Output the representation format byte for this dimension. */
3124 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
3125 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
3126 upper && TREE_CODE (upper) == INTEGER_CST));
3127
3128 /* Output the index type for this dimension. */
3129 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3130 fundamental_type_code (domain));
3131
3132 /* Output the representation for the lower bound. */
3133 output_bound_representation (lower, dimension_number, 'l');
3134
3135 /* Output the representation for the upper bound. */
3136 if (upper)
3137 output_bound_representation (upper, dimension_number, 'u');
3138 else
3139 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3140 }
3141 else
3142 {
3143 /* We have an array type with an unspecified length. For C and
3144 C++ we can assume that this really means that (a) the index
3145 type is an integral type, and (b) the lower bound is zero.
3146 Note that Dwarf defines the representation of an unspecified
3147 (upper) bound as being a zero-length location description. */
3148
3149 /* Output the array-bounds format byte. */
3150
3151 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
3152
3153 /* Output the (assumed) index type. */
3154
3155 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
3156
3157 /* Output the (assumed) lower bound (constant) value. */
3158
3159 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3160
3161 /* Output the (empty) location description for the upper bound. */
3162
3163 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3164 }
3165 }
3166
3167 /* Output the prefix byte that says that the element type is coming up. */
3168
3169 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
3170
3171 /* Output a representation of the type of the elements of this array type. */
3172
3173 type_attribute (type, 0, 0);
3174
3175 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3176 }
3177
3178 static void
3179 byte_size_attribute (tree_node)
3180 register tree tree_node;
3181 {
3182 register unsigned size;
3183
3184 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
3185 switch (TREE_CODE (tree_node))
3186 {
3187 case ERROR_MARK:
3188 size = 0;
3189 break;
3190
3191 case ENUMERAL_TYPE:
3192 case RECORD_TYPE:
3193 case UNION_TYPE:
3194 case QUAL_UNION_TYPE:
3195 case ARRAY_TYPE:
3196 size = int_size_in_bytes (tree_node);
3197 break;
3198
3199 case FIELD_DECL:
3200 /* For a data member of a struct or union, the AT_byte_size is
3201 generally given as the number of bytes normally allocated for
3202 an object of the *declared* type of the member itself. This
3203 is true even for bit-fields. */
3204 size = simple_type_size_in_bits (field_type (tree_node))
3205 / BITS_PER_UNIT;
3206 break;
3207
3208 default:
3209 abort ();
3210 }
3211
3212 /* Note that `size' might be -1 when we get to this point. If it
3213 is, that indicates that the byte size of the entity in question
3214 is variable. We have no good way of expressing this fact in Dwarf
3215 at the present time, so just let the -1 pass on through. */
3216
3217 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
3218 }
3219
3220 /* For a FIELD_DECL node which represents a bit-field, output an attribute
3221 which specifies the distance in bits from the highest order bit of the
3222 "containing object" for the bit-field to the highest order bit of the
3223 bit-field itself.
3224
3225 For any given bit-field, the "containing object" is a hypothetical
3226 object (of some integral or enum type) within which the given bit-field
3227 lives. The type of this hypothetical "containing object" is always the
3228 same as the declared type of the individual bit-field itself.
3229
3230 The determination of the exact location of the "containing object" for
3231 a bit-field is rather complicated. It's handled by the `field_byte_offset'
3232 function (above).
3233
3234 Note that it is the size (in bytes) of the hypothetical "containing
3235 object" which will be given in the AT_byte_size attribute for this
3236 bit-field. (See `byte_size_attribute' above.) */
3237
3238 static inline void
3239 bit_offset_attribute (decl)
3240 register tree decl;
3241 {
3242 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
3243 tree type = DECL_BIT_FIELD_TYPE (decl);
3244 HOST_WIDE_INT bitpos_int;
3245 HOST_WIDE_INT highest_order_object_bit_offset;
3246 HOST_WIDE_INT highest_order_field_bit_offset;
3247 HOST_WIDE_INT bit_offset;
3248
3249 /* Must be a bit field. */
3250 if (!type
3251 || TREE_CODE (decl) != FIELD_DECL)
3252 abort ();
3253
3254 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
3255 if we encounter such things, just return without generating any
3256 attribute whatsoever. */
3257
3258 if (! host_integerp (bit_position (decl), 0)
3259 || ! host_integerp (DECL_SIZE (decl), 1))
3260 return;
3261
3262 bitpos_int = int_bit_position (decl);
3263
3264 /* Note that the bit offset is always the distance (in bits) from the
3265 highest-order bit of the "containing object" to the highest-order
3266 bit of the bit-field itself. Since the "high-order end" of any
3267 object or field is different on big-endian and little-endian machines,
3268 the computation below must take account of these differences. */
3269
3270 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
3271 highest_order_field_bit_offset = bitpos_int;
3272
3273 if (! BYTES_BIG_ENDIAN)
3274 {
3275 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
3276 highest_order_object_bit_offset += simple_type_size_in_bits (type);
3277 }
3278
3279 bit_offset =
3280 (! BYTES_BIG_ENDIAN
3281 ? highest_order_object_bit_offset - highest_order_field_bit_offset
3282 : highest_order_field_bit_offset - highest_order_object_bit_offset);
3283
3284 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
3285 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
3286 }
3287
3288 /* For a FIELD_DECL node which represents a bit field, output an attribute
3289 which specifies the length in bits of the given field. */
3290
3291 static inline void
3292 bit_size_attribute (decl)
3293 register tree decl;
3294 {
3295 /* Must be a field and a bit field. */
3296 if (TREE_CODE (decl) != FIELD_DECL
3297 || ! DECL_BIT_FIELD_TYPE (decl))
3298 abort ();
3299
3300 if (host_integerp (DECL_SIZE (decl), 1))
3301 {
3302 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
3303 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3304 tree_low_cst (DECL_SIZE (decl), 1));
3305 }
3306 }
3307
3308 /* The following routine outputs the `element_list' attribute for enumeration
3309 type DIEs. The element_lits attribute includes the names and values of
3310 all of the enumeration constants associated with the given enumeration
3311 type. */
3312
3313 static inline void
3314 element_list_attribute (element)
3315 register tree element;
3316 {
3317 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3318 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3319
3320 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
3321 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
3322 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
3323 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3324 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3325
3326 /* Here we output a list of value/name pairs for each enumeration constant
3327 defined for this enumeration type (as required), but we do it in REVERSE
3328 order. The order is the one required by the draft #5 Dwarf specification
3329 published by the UI/PLSIG. */
3330
3331 output_enumeral_list (element); /* Recursively output the whole list. */
3332
3333 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3334 }
3335
3336 /* Generate an AT_stmt_list attribute. These are normally present only in
3337 DIEs with a TAG_compile_unit tag. */
3338
3339 static inline void
3340 stmt_list_attribute (label)
3341 register const char *label;
3342 {
3343 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
3344 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3345 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3346 }
3347
3348 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
3349 for a subroutine DIE. */
3350
3351 static inline void
3352 low_pc_attribute (asm_low_label)
3353 register const char *asm_low_label;
3354 {
3355 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
3356 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
3357 }
3358
3359 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
3360 subroutine DIE. */
3361
3362 static inline void
3363 high_pc_attribute (asm_high_label)
3364 register const char *asm_high_label;
3365 {
3366 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
3367 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
3368 }
3369
3370 /* Generate an AT_body_begin attribute for a subroutine DIE. */
3371
3372 static inline void
3373 body_begin_attribute (asm_begin_label)
3374 register const char *asm_begin_label;
3375 {
3376 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
3377 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
3378 }
3379
3380 /* Generate an AT_body_end attribute for a subroutine DIE. */
3381
3382 static inline void
3383 body_end_attribute (asm_end_label)
3384 register const char *asm_end_label;
3385 {
3386 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
3387 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
3388 }
3389
3390 /* Generate an AT_language attribute given a LANG value. These attributes
3391 are used only within TAG_compile_unit DIEs. */
3392
3393 static inline void
3394 language_attribute (language_code)
3395 register unsigned language_code;
3396 {
3397 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
3398 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
3399 }
3400
3401 static inline void
3402 member_attribute (context)
3403 register tree context;
3404 {
3405 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3406
3407 /* Generate this attribute only for members in C++. */
3408
3409 if (context != NULL && is_tagged_type (context))
3410 {
3411 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
3412 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
3413 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3414 }
3415 }
3416
3417 #if 0
3418 static inline void
3419 string_length_attribute (upper_bound)
3420 register tree upper_bound;
3421 {
3422 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3423 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3424
3425 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
3426 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
3427 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
3428 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3429 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3430 output_bound_representation (upper_bound, 0, 'u');
3431 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3432 }
3433 #endif
3434
3435 static inline void
3436 comp_dir_attribute (dirname)
3437 register const char *dirname;
3438 {
3439 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
3440 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
3441 }
3442
3443 static inline void
3444 sf_names_attribute (sf_names_start_label)
3445 register const char *sf_names_start_label;
3446 {
3447 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
3448 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3449 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
3450 }
3451
3452 static inline void
3453 src_info_attribute (src_info_start_label)
3454 register const char *src_info_start_label;
3455 {
3456 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
3457 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3458 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
3459 }
3460
3461 static inline void
3462 mac_info_attribute (mac_info_start_label)
3463 register const char *mac_info_start_label;
3464 {
3465 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
3466 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3467 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
3468 }
3469
3470 static inline void
3471 prototyped_attribute (func_type)
3472 register tree func_type;
3473 {
3474 if ((strcmp (language_string, "GNU C") == 0)
3475 && (TYPE_ARG_TYPES (func_type) != NULL))
3476 {
3477 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
3478 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3479 }
3480 }
3481
3482 static inline void
3483 producer_attribute (producer)
3484 register const char *producer;
3485 {
3486 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
3487 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
3488 }
3489
3490 static inline void
3491 inline_attribute (decl)
3492 register tree decl;
3493 {
3494 if (DECL_INLINE (decl))
3495 {
3496 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3497 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3498 }
3499 }
3500
3501 static inline void
3502 containing_type_attribute (containing_type)
3503 register tree containing_type;
3504 {
3505 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3506
3507 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3508 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3509 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3510 }
3511
3512 static inline void
3513 abstract_origin_attribute (origin)
3514 register tree origin;
3515 {
3516 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3517
3518 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3519 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3520 {
3521 case 'd':
3522 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3523 break;
3524
3525 case 't':
3526 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3527 break;
3528
3529 default:
3530 abort (); /* Should never happen. */
3531
3532 }
3533 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3534 }
3535
3536 #ifdef DWARF_DECL_COORDINATES
3537 static inline void
3538 src_coords_attribute (src_fileno, src_lineno)
3539 register unsigned src_fileno;
3540 register unsigned src_lineno;
3541 {
3542 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3543 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3544 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3545 }
3546 #endif /* defined(DWARF_DECL_COORDINATES) */
3547
3548 static inline void
3549 pure_or_virtual_attribute (func_decl)
3550 register tree func_decl;
3551 {
3552 if (DECL_VIRTUAL_P (func_decl))
3553 {
3554 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3555 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3556 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3557 else
3558 #endif
3559 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3560 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3561 }
3562 }
3563
3564 /************************* end of attributes *****************************/
3565
3566 /********************* utility routines for DIEs *************************/
3567
3568 /* Output an AT_name attribute and an AT_src_coords attribute for the
3569 given decl, but only if it actually has a name. */
3570
3571 static void
3572 name_and_src_coords_attributes (decl)
3573 register tree decl;
3574 {
3575 register tree decl_name = DECL_NAME (decl);
3576
3577 if (decl_name && IDENTIFIER_POINTER (decl_name))
3578 {
3579 name_attribute (IDENTIFIER_POINTER (decl_name));
3580 #ifdef DWARF_DECL_COORDINATES
3581 {
3582 register unsigned file_index;
3583
3584 /* This is annoying, but we have to pop out of the .debug section
3585 for a moment while we call `lookup_filename' because calling it
3586 may cause a temporary switch into the .debug_sfnames section and
3587 most svr4 assemblers are not smart enough to be able to nest
3588 section switches to any depth greater than one. Note that we
3589 also can't skirt this issue by delaying all output to the
3590 .debug_sfnames section unit the end of compilation because that
3591 would cause us to have inter-section forward references and
3592 Fred Fish sez that m68k/svr4 assemblers botch those. */
3593
3594 ASM_OUTPUT_POP_SECTION (asm_out_file);
3595 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3596 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3597
3598 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3599 }
3600 #endif /* defined(DWARF_DECL_COORDINATES) */
3601 }
3602 }
3603
3604 /* Many forms of DIEs contain a "type description" part. The following
3605 routine writes out these "type descriptor" parts. */
3606
3607 static void
3608 type_attribute (type, decl_const, decl_volatile)
3609 register tree type;
3610 register int decl_const;
3611 register int decl_volatile;
3612 {
3613 register enum tree_code code = TREE_CODE (type);
3614 register int root_type_modified;
3615
3616 if (code == ERROR_MARK)
3617 return;
3618
3619 /* Handle a special case. For functions whose return type is void,
3620 we generate *no* type attribute. (Note that no object may have
3621 type `void', so this only applies to function return types. */
3622
3623 if (code == VOID_TYPE)
3624 return;
3625
3626 /* If this is a subtype, find the underlying type. Eventually,
3627 this should write out the appropriate subtype info. */
3628 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3629 && TREE_TYPE (type) != 0)
3630 type = TREE_TYPE (type), code = TREE_CODE (type);
3631
3632 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3633 || decl_const || decl_volatile
3634 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3635
3636 if (type_is_fundamental (root_type (type)))
3637 {
3638 if (root_type_modified)
3639 mod_fund_type_attribute (type, decl_const, decl_volatile);
3640 else
3641 fund_type_attribute (fundamental_type_code (type));
3642 }
3643 else
3644 {
3645 if (root_type_modified)
3646 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3647 else
3648 /* We have to get the type_main_variant here (and pass that to the
3649 `user_def_type_attribute' routine) because the ..._TYPE node we
3650 have might simply be a *copy* of some original type node (where
3651 the copy was created to help us keep track of typedef names)
3652 and that copy might have a different TYPE_UID from the original
3653 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3654 is labeling a given type DIE for future reference, it always and
3655 only creates labels for DIEs representing *main variants*, and it
3656 never even knows about non-main-variants.) */
3657 user_def_type_attribute (type_main_variant (type));
3658 }
3659 }
3660
3661 /* Given a tree pointer to a struct, class, union, or enum type node, return
3662 a pointer to the (string) tag name for the given type, or zero if the
3663 type was declared without a tag. */
3664
3665 static const char *
3666 type_tag (type)
3667 register tree type;
3668 {
3669 register const char *name = 0;
3670
3671 if (TYPE_NAME (type) != 0)
3672 {
3673 register tree t = 0;
3674
3675 /* Find the IDENTIFIER_NODE for the type name. */
3676 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3677 t = TYPE_NAME (type);
3678
3679 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3680 a TYPE_DECL node, regardless of whether or not a `typedef' was
3681 involved. */
3682 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3683 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3684 t = DECL_NAME (TYPE_NAME (type));
3685
3686 /* Now get the name as a string, or invent one. */
3687 if (t != 0)
3688 name = IDENTIFIER_POINTER (t);
3689 }
3690
3691 return (name == 0 || *name == '\0') ? 0 : name;
3692 }
3693
3694 static inline void
3695 dienum_push ()
3696 {
3697 /* Start by checking if the pending_sibling_stack needs to be expanded.
3698 If necessary, expand it. */
3699
3700 if (pending_siblings == pending_siblings_allocated)
3701 {
3702 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3703 pending_sibling_stack
3704 = (unsigned *) xrealloc (pending_sibling_stack,
3705 pending_siblings_allocated * sizeof(unsigned));
3706 }
3707
3708 pending_siblings++;
3709 NEXT_DIE_NUM = next_unused_dienum++;
3710 }
3711
3712 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3713 NEXT_DIE_NUM. */
3714
3715 static inline void
3716 dienum_pop ()
3717 {
3718 pending_siblings--;
3719 }
3720
3721 static inline tree
3722 member_declared_type (member)
3723 register tree member;
3724 {
3725 return (DECL_BIT_FIELD_TYPE (member))
3726 ? DECL_BIT_FIELD_TYPE (member)
3727 : TREE_TYPE (member);
3728 }
3729
3730 /* Get the function's label, as described by its RTL.
3731 This may be different from the DECL_NAME name used
3732 in the source file. */
3733
3734 static const char *
3735 function_start_label (decl)
3736 register tree decl;
3737 {
3738 rtx x;
3739 const char *fnname;
3740
3741 x = DECL_RTL (decl);
3742 if (GET_CODE (x) != MEM)
3743 abort ();
3744 x = XEXP (x, 0);
3745 if (GET_CODE (x) != SYMBOL_REF)
3746 abort ();
3747 fnname = XSTR (x, 0);
3748 return fnname;
3749 }
3750
3751
3752 /******************************* DIEs ************************************/
3753
3754 /* Output routines for individual types of DIEs. */
3755
3756 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3757
3758 static void
3759 output_array_type_die (arg)
3760 register void *arg;
3761 {
3762 register tree type = arg;
3763
3764 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3765 sibling_attribute ();
3766 equate_type_number_to_die_number (type);
3767 member_attribute (TYPE_CONTEXT (type));
3768
3769 /* I believe that we can default the array ordering. SDB will probably
3770 do the right things even if AT_ordering is not present. It's not
3771 even an issue until we start to get into multidimensional arrays
3772 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3773 dimensional arrays, then we'll have to put the AT_ordering attribute
3774 back in. (But if and when we find out that we need to put these in,
3775 we will only do so for multidimensional arrays. After all, we don't
3776 want to waste space in the .debug section now do we?) */
3777
3778 #ifdef USE_ORDERING_ATTRIBUTE
3779 ordering_attribute (ORD_row_major);
3780 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3781
3782 subscript_data_attribute (type);
3783 }
3784
3785 static void
3786 output_set_type_die (arg)
3787 register void *arg;
3788 {
3789 register tree type = arg;
3790
3791 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3792 sibling_attribute ();
3793 equate_type_number_to_die_number (type);
3794 member_attribute (TYPE_CONTEXT (type));
3795 type_attribute (TREE_TYPE (type), 0, 0);
3796 }
3797
3798 #if 0
3799 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3800
3801 static void
3802 output_entry_point_die (arg)
3803 register void *arg;
3804 {
3805 register tree decl = arg;
3806 register tree origin = decl_ultimate_origin (decl);
3807
3808 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3809 sibling_attribute ();
3810 dienum_push ();
3811 if (origin != NULL)
3812 abstract_origin_attribute (origin);
3813 else
3814 {
3815 name_and_src_coords_attributes (decl);
3816 member_attribute (DECL_CONTEXT (decl));
3817 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3818 }
3819 if (DECL_ABSTRACT (decl))
3820 equate_decl_number_to_die_number (decl);
3821 else
3822 low_pc_attribute (function_start_label (decl));
3823 }
3824 #endif
3825
3826 /* Output a DIE to represent an inlined instance of an enumeration type. */
3827
3828 static void
3829 output_inlined_enumeration_type_die (arg)
3830 register void *arg;
3831 {
3832 register tree type = arg;
3833
3834 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3835 sibling_attribute ();
3836 if (!TREE_ASM_WRITTEN (type))
3837 abort ();
3838 abstract_origin_attribute (type);
3839 }
3840
3841 /* Output a DIE to represent an inlined instance of a structure type. */
3842
3843 static void
3844 output_inlined_structure_type_die (arg)
3845 register void *arg;
3846 {
3847 register tree type = arg;
3848
3849 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3850 sibling_attribute ();
3851 if (!TREE_ASM_WRITTEN (type))
3852 abort ();
3853 abstract_origin_attribute (type);
3854 }
3855
3856 /* Output a DIE to represent an inlined instance of a union type. */
3857
3858 static void
3859 output_inlined_union_type_die (arg)
3860 register void *arg;
3861 {
3862 register tree type = arg;
3863
3864 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3865 sibling_attribute ();
3866 if (!TREE_ASM_WRITTEN (type))
3867 abort ();
3868 abstract_origin_attribute (type);
3869 }
3870
3871 /* Output a DIE to represent an enumeration type. Note that these DIEs
3872 include all of the information about the enumeration values also.
3873 This information is encoded into the element_list attribute. */
3874
3875 static void
3876 output_enumeration_type_die (arg)
3877 register void *arg;
3878 {
3879 register tree type = arg;
3880
3881 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3882 sibling_attribute ();
3883 equate_type_number_to_die_number (type);
3884 name_attribute (type_tag (type));
3885 member_attribute (TYPE_CONTEXT (type));
3886
3887 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3888 given enum type is incomplete, do not generate the AT_byte_size
3889 attribute or the AT_element_list attribute. */
3890
3891 if (COMPLETE_TYPE_P (type))
3892 {
3893 byte_size_attribute (type);
3894 element_list_attribute (TYPE_FIELDS (type));
3895 }
3896 }
3897
3898 /* Output a DIE to represent either a real live formal parameter decl or
3899 to represent just the type of some formal parameter position in some
3900 function type.
3901
3902 Note that this routine is a bit unusual because its argument may be
3903 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3904 represents an inlining of some PARM_DECL) or else some sort of a
3905 ..._TYPE node. If it's the former then this function is being called
3906 to output a DIE to represent a formal parameter object (or some inlining
3907 thereof). If it's the latter, then this function is only being called
3908 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3909 formal argument type of some subprogram type. */
3910
3911 static void
3912 output_formal_parameter_die (arg)
3913 register void *arg;
3914 {
3915 register tree node = arg;
3916
3917 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3918 sibling_attribute ();
3919
3920 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3921 {
3922 case 'd': /* We were called with some kind of a ..._DECL node. */
3923 {
3924 register tree origin = decl_ultimate_origin (node);
3925
3926 if (origin != NULL)
3927 abstract_origin_attribute (origin);
3928 else
3929 {
3930 name_and_src_coords_attributes (node);
3931 type_attribute (TREE_TYPE (node),
3932 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3933 }
3934 if (DECL_ABSTRACT (node))
3935 equate_decl_number_to_die_number (node);
3936 else
3937 location_or_const_value_attribute (node);
3938 }
3939 break;
3940
3941 case 't': /* We were called with some kind of a ..._TYPE node. */
3942 type_attribute (node, 0, 0);
3943 break;
3944
3945 default:
3946 abort (); /* Should never happen. */
3947 }
3948 }
3949
3950 /* Output a DIE to represent a declared function (either file-scope
3951 or block-local) which has "external linkage" (according to ANSI-C). */
3952
3953 static void
3954 output_global_subroutine_die (arg)
3955 register void *arg;
3956 {
3957 register tree decl = arg;
3958 register tree origin = decl_ultimate_origin (decl);
3959
3960 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3961 sibling_attribute ();
3962 dienum_push ();
3963 if (origin != NULL)
3964 abstract_origin_attribute (origin);
3965 else
3966 {
3967 register tree type = TREE_TYPE (decl);
3968
3969 name_and_src_coords_attributes (decl);
3970 inline_attribute (decl);
3971 prototyped_attribute (type);
3972 member_attribute (DECL_CONTEXT (decl));
3973 type_attribute (TREE_TYPE (type), 0, 0);
3974 pure_or_virtual_attribute (decl);
3975 }
3976 if (DECL_ABSTRACT (decl))
3977 equate_decl_number_to_die_number (decl);
3978 else
3979 {
3980 if (! DECL_EXTERNAL (decl) && ! in_class
3981 && decl == current_function_decl)
3982 {
3983 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3984
3985 low_pc_attribute (function_start_label (decl));
3986 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3987 high_pc_attribute (label);
3988 if (use_gnu_debug_info_extensions)
3989 {
3990 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3991 body_begin_attribute (label);
3992 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3993 body_end_attribute (label);
3994 }
3995 }
3996 }
3997 }
3998
3999 /* Output a DIE to represent a declared data object (either file-scope
4000 or block-local) which has "external linkage" (according to ANSI-C). */
4001
4002 static void
4003 output_global_variable_die (arg)
4004 register void *arg;
4005 {
4006 register tree decl = arg;
4007 register tree origin = decl_ultimate_origin (decl);
4008
4009 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
4010 sibling_attribute ();
4011 if (origin != NULL)
4012 abstract_origin_attribute (origin);
4013 else
4014 {
4015 name_and_src_coords_attributes (decl);
4016 member_attribute (DECL_CONTEXT (decl));
4017 type_attribute (TREE_TYPE (decl),
4018 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4019 }
4020 if (DECL_ABSTRACT (decl))
4021 equate_decl_number_to_die_number (decl);
4022 else
4023 {
4024 if (! DECL_EXTERNAL (decl) && ! in_class
4025 && current_function_decl == decl_function_context (decl))
4026 location_or_const_value_attribute (decl);
4027 }
4028 }
4029
4030 static void
4031 output_label_die (arg)
4032 register void *arg;
4033 {
4034 register tree decl = arg;
4035 register tree origin = decl_ultimate_origin (decl);
4036
4037 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
4038 sibling_attribute ();
4039 if (origin != NULL)
4040 abstract_origin_attribute (origin);
4041 else
4042 name_and_src_coords_attributes (decl);
4043 if (DECL_ABSTRACT (decl))
4044 equate_decl_number_to_die_number (decl);
4045 else
4046 {
4047 register rtx insn = DECL_RTL (decl);
4048
4049 /* Deleted labels are programmer specified labels which have been
4050 eliminated because of various optimisations. We still emit them
4051 here so that it is possible to put breakpoints on them. */
4052 if (GET_CODE (insn) == CODE_LABEL
4053 || ((GET_CODE (insn) == NOTE
4054 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
4055 {
4056 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4057
4058 /* When optimization is enabled (via -O) some parts of the compiler
4059 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
4060 represent source-level labels which were explicitly declared by
4061 the user. This really shouldn't be happening though, so catch
4062 it if it ever does happen. */
4063
4064 if (INSN_DELETED_P (insn))
4065 abort (); /* Should never happen. */
4066
4067 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
4068 low_pc_attribute (label);
4069 }
4070 }
4071 }
4072
4073 static void
4074 output_lexical_block_die (arg)
4075 register void *arg;
4076 {
4077 register tree stmt = arg;
4078
4079 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
4080 sibling_attribute ();
4081 dienum_push ();
4082 if (! BLOCK_ABSTRACT (stmt))
4083 {
4084 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4085 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4086
4087 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4088 low_pc_attribute (begin_label);
4089 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4090 high_pc_attribute (end_label);
4091 }
4092 }
4093
4094 static void
4095 output_inlined_subroutine_die (arg)
4096 register void *arg;
4097 {
4098 register tree stmt = arg;
4099
4100 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
4101 sibling_attribute ();
4102 dienum_push ();
4103 abstract_origin_attribute (block_ultimate_origin (stmt));
4104 if (! BLOCK_ABSTRACT (stmt))
4105 {
4106 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4107 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4108
4109 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4110 low_pc_attribute (begin_label);
4111 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4112 high_pc_attribute (end_label);
4113 }
4114 }
4115
4116 /* Output a DIE to represent a declared data object (either file-scope
4117 or block-local) which has "internal linkage" (according to ANSI-C). */
4118
4119 static void
4120 output_local_variable_die (arg)
4121 register void *arg;
4122 {
4123 register tree decl = arg;
4124 register tree origin = decl_ultimate_origin (decl);
4125
4126 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
4127 sibling_attribute ();
4128 if (origin != NULL)
4129 abstract_origin_attribute (origin);
4130 else
4131 {
4132 name_and_src_coords_attributes (decl);
4133 member_attribute (DECL_CONTEXT (decl));
4134 type_attribute (TREE_TYPE (decl),
4135 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4136 }
4137 if (DECL_ABSTRACT (decl))
4138 equate_decl_number_to_die_number (decl);
4139 else
4140 location_or_const_value_attribute (decl);
4141 }
4142
4143 static void
4144 output_member_die (arg)
4145 register void *arg;
4146 {
4147 register tree decl = arg;
4148
4149 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
4150 sibling_attribute ();
4151 name_and_src_coords_attributes (decl);
4152 member_attribute (DECL_CONTEXT (decl));
4153 type_attribute (member_declared_type (decl),
4154 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4155 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
4156 {
4157 byte_size_attribute (decl);
4158 bit_size_attribute (decl);
4159 bit_offset_attribute (decl);
4160 }
4161 data_member_location_attribute (decl);
4162 }
4163
4164 #if 0
4165 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
4166 modified types instead.
4167
4168 We keep this code here just in case these types of DIEs may be
4169 needed to represent certain things in other languages (e.g. Pascal)
4170 someday. */
4171
4172 static void
4173 output_pointer_type_die (arg)
4174 register void *arg;
4175 {
4176 register tree type = arg;
4177
4178 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
4179 sibling_attribute ();
4180 equate_type_number_to_die_number (type);
4181 member_attribute (TYPE_CONTEXT (type));
4182 type_attribute (TREE_TYPE (type), 0, 0);
4183 }
4184
4185 static void
4186 output_reference_type_die (arg)
4187 register void *arg;
4188 {
4189 register tree type = arg;
4190
4191 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
4192 sibling_attribute ();
4193 equate_type_number_to_die_number (type);
4194 member_attribute (TYPE_CONTEXT (type));
4195 type_attribute (TREE_TYPE (type), 0, 0);
4196 }
4197 #endif
4198
4199 static void
4200 output_ptr_to_mbr_type_die (arg)
4201 register void *arg;
4202 {
4203 register tree type = arg;
4204
4205 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
4206 sibling_attribute ();
4207 equate_type_number_to_die_number (type);
4208 member_attribute (TYPE_CONTEXT (type));
4209 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
4210 type_attribute (TREE_TYPE (type), 0, 0);
4211 }
4212
4213 static void
4214 output_compile_unit_die (arg)
4215 register void *arg;
4216 {
4217 register const char *main_input_filename = arg;
4218
4219 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
4220 sibling_attribute ();
4221 dienum_push ();
4222 name_attribute (main_input_filename);
4223
4224 {
4225 char producer[250];
4226
4227 sprintf (producer, "%s %s", language_string, version_string);
4228 producer_attribute (producer);
4229 }
4230
4231 if (strcmp (language_string, "GNU C++") == 0)
4232 language_attribute (LANG_C_PLUS_PLUS);
4233 else if (strcmp (language_string, "GNU Ada") == 0)
4234 language_attribute (LANG_ADA83);
4235 else if (strcmp (language_string, "GNU F77") == 0)
4236 language_attribute (LANG_FORTRAN77);
4237 else if (strcmp (language_string, "GNU Pascal") == 0)
4238 language_attribute (LANG_PASCAL83);
4239 else if (strcmp (language_string, "GNU Java") == 0)
4240 language_attribute (LANG_JAVA);
4241 else if (flag_traditional)
4242 language_attribute (LANG_C);
4243 else
4244 language_attribute (LANG_C89);
4245 low_pc_attribute (TEXT_BEGIN_LABEL);
4246 high_pc_attribute (TEXT_END_LABEL);
4247 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4248 stmt_list_attribute (LINE_BEGIN_LABEL);
4249 last_filename = xstrdup (main_input_filename);
4250
4251 {
4252 const char *wd = getpwd ();
4253 if (wd)
4254 comp_dir_attribute (wd);
4255 }
4256
4257 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
4258 {
4259 sf_names_attribute (SFNAMES_BEGIN_LABEL);
4260 src_info_attribute (SRCINFO_BEGIN_LABEL);
4261 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4262 mac_info_attribute (MACINFO_BEGIN_LABEL);
4263 }
4264 }
4265
4266 static void
4267 output_string_type_die (arg)
4268 register void *arg;
4269 {
4270 register tree type = arg;
4271
4272 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
4273 sibling_attribute ();
4274 equate_type_number_to_die_number (type);
4275 member_attribute (TYPE_CONTEXT (type));
4276 /* this is a fixed length string */
4277 byte_size_attribute (type);
4278 }
4279
4280 static void
4281 output_inheritance_die (arg)
4282 register void *arg;
4283 {
4284 register tree binfo = arg;
4285
4286 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
4287 sibling_attribute ();
4288 type_attribute (BINFO_TYPE (binfo), 0, 0);
4289 data_member_location_attribute (binfo);
4290 if (TREE_VIA_VIRTUAL (binfo))
4291 {
4292 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
4293 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4294 }
4295 if (TREE_VIA_PUBLIC (binfo))
4296 {
4297 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
4298 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4299 }
4300 else if (TREE_VIA_PROTECTED (binfo))
4301 {
4302 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
4303 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4304 }
4305 }
4306
4307 static void
4308 output_structure_type_die (arg)
4309 register void *arg;
4310 {
4311 register tree type = arg;
4312
4313 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
4314 sibling_attribute ();
4315 equate_type_number_to_die_number (type);
4316 name_attribute (type_tag (type));
4317 member_attribute (TYPE_CONTEXT (type));
4318
4319 /* If this type has been completed, then give it a byte_size attribute
4320 and prepare to give a list of members. Otherwise, don't do either of
4321 these things. In the latter case, we will not be generating a list
4322 of members (since we don't have any idea what they might be for an
4323 incomplete type). */
4324
4325 if (COMPLETE_TYPE_P (type))
4326 {
4327 dienum_push ();
4328 byte_size_attribute (type);
4329 }
4330 }
4331
4332 /* Output a DIE to represent a declared function (either file-scope
4333 or block-local) which has "internal linkage" (according to ANSI-C). */
4334
4335 static void
4336 output_local_subroutine_die (arg)
4337 register void *arg;
4338 {
4339 register tree decl = arg;
4340 register tree origin = decl_ultimate_origin (decl);
4341
4342 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
4343 sibling_attribute ();
4344 dienum_push ();
4345 if (origin != NULL)
4346 abstract_origin_attribute (origin);
4347 else
4348 {
4349 register tree type = TREE_TYPE (decl);
4350
4351 name_and_src_coords_attributes (decl);
4352 inline_attribute (decl);
4353 prototyped_attribute (type);
4354 member_attribute (DECL_CONTEXT (decl));
4355 type_attribute (TREE_TYPE (type), 0, 0);
4356 pure_or_virtual_attribute (decl);
4357 }
4358 if (DECL_ABSTRACT (decl))
4359 equate_decl_number_to_die_number (decl);
4360 else
4361 {
4362 /* Avoid getting screwed up in cases where a function was declared
4363 static but where no definition was ever given for it. */
4364
4365 if (TREE_ASM_WRITTEN (decl))
4366 {
4367 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4368 low_pc_attribute (function_start_label (decl));
4369 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4370 high_pc_attribute (label);
4371 if (use_gnu_debug_info_extensions)
4372 {
4373 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
4374 body_begin_attribute (label);
4375 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
4376 body_end_attribute (label);
4377 }
4378 }
4379 }
4380 }
4381
4382 static void
4383 output_subroutine_type_die (arg)
4384 register void *arg;
4385 {
4386 register tree type = arg;
4387 register tree return_type = TREE_TYPE (type);
4388
4389 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
4390 sibling_attribute ();
4391 dienum_push ();
4392 equate_type_number_to_die_number (type);
4393 prototyped_attribute (type);
4394 member_attribute (TYPE_CONTEXT (type));
4395 type_attribute (return_type, 0, 0);
4396 }
4397
4398 static void
4399 output_typedef_die (arg)
4400 register void *arg;
4401 {
4402 register tree decl = arg;
4403 register tree origin = decl_ultimate_origin (decl);
4404
4405 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
4406 sibling_attribute ();
4407 if (origin != NULL)
4408 abstract_origin_attribute (origin);
4409 else
4410 {
4411 name_and_src_coords_attributes (decl);
4412 member_attribute (DECL_CONTEXT (decl));
4413 type_attribute (TREE_TYPE (decl),
4414 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4415 }
4416 if (DECL_ABSTRACT (decl))
4417 equate_decl_number_to_die_number (decl);
4418 }
4419
4420 static void
4421 output_union_type_die (arg)
4422 register void *arg;
4423 {
4424 register tree type = arg;
4425
4426 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
4427 sibling_attribute ();
4428 equate_type_number_to_die_number (type);
4429 name_attribute (type_tag (type));
4430 member_attribute (TYPE_CONTEXT (type));
4431
4432 /* If this type has been completed, then give it a byte_size attribute
4433 and prepare to give a list of members. Otherwise, don't do either of
4434 these things. In the latter case, we will not be generating a list
4435 of members (since we don't have any idea what they might be for an
4436 incomplete type). */
4437
4438 if (COMPLETE_TYPE_P (type))
4439 {
4440 dienum_push ();
4441 byte_size_attribute (type);
4442 }
4443 }
4444
4445 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
4446 at the end of an (ANSI prototyped) formal parameters list. */
4447
4448 static void
4449 output_unspecified_parameters_die (arg)
4450 register void *arg;
4451 {
4452 register tree decl_or_type = arg;
4453
4454 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
4455 sibling_attribute ();
4456
4457 /* This kludge is here only for the sake of being compatible with what
4458 the USL CI5 C compiler does. The specification of Dwarf Version 1
4459 doesn't say that TAG_unspecified_parameters DIEs should contain any
4460 attributes other than the AT_sibling attribute, but they are certainly
4461 allowed to contain additional attributes, and the CI5 compiler
4462 generates AT_name, AT_fund_type, and AT_location attributes within
4463 TAG_unspecified_parameters DIEs which appear in the child lists for
4464 DIEs representing function definitions, so we do likewise here. */
4465
4466 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
4467 {
4468 name_attribute ("...");
4469 fund_type_attribute (FT_pointer);
4470 /* location_attribute (?); */
4471 }
4472 }
4473
4474 static void
4475 output_padded_null_die (arg)
4476 register void *arg ATTRIBUTE_UNUSED;
4477 {
4478 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
4479 }
4480
4481 /*************************** end of DIEs *********************************/
4482
4483 /* Generate some type of DIE. This routine generates the generic outer
4484 wrapper stuff which goes around all types of DIE's (regardless of their
4485 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
4486 DIE-length word, followed by the guts of the DIE itself. After the guts
4487 of the DIE, there must always be a terminator label for the DIE. */
4488
4489 static void
4490 output_die (die_specific_output_function, param)
4491 register void (*die_specific_output_function) PARAMS ((void *));
4492 register void *param;
4493 {
4494 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4495 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4496
4497 current_dienum = NEXT_DIE_NUM;
4498 NEXT_DIE_NUM = next_unused_dienum;
4499
4500 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4501 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4502
4503 /* Write a label which will act as the name for the start of this DIE. */
4504
4505 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4506
4507 /* Write the DIE-length word. */
4508
4509 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4510
4511 /* Fill in the guts of the DIE. */
4512
4513 next_unused_dienum++;
4514 die_specific_output_function (param);
4515
4516 /* Write a label which will act as the name for the end of this DIE. */
4517
4518 ASM_OUTPUT_LABEL (asm_out_file, end_label);
4519 }
4520
4521 static void
4522 end_sibling_chain ()
4523 {
4524 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4525
4526 current_dienum = NEXT_DIE_NUM;
4527 NEXT_DIE_NUM = next_unused_dienum;
4528
4529 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4530
4531 /* Write a label which will act as the name for the start of this DIE. */
4532
4533 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4534
4535 /* Write the DIE-length word. */
4536
4537 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4538
4539 dienum_pop ();
4540 }
4541 \f
4542 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4543 TAG_unspecified_parameters DIE) to represent the types of the formal
4544 parameters as specified in some function type specification (except
4545 for those which appear as part of a function *definition*).
4546
4547 Note that we must be careful here to output all of the parameter
4548 DIEs *before* we output any DIEs needed to represent the types of
4549 the formal parameters. This keeps svr4 SDB happy because it
4550 (incorrectly) thinks that the first non-parameter DIE it sees ends
4551 the formal parameter list. */
4552
4553 static void
4554 output_formal_types (function_or_method_type)
4555 register tree function_or_method_type;
4556 {
4557 register tree link;
4558 register tree formal_type = NULL;
4559 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4560
4561 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4562 get bogus recursion when outputting tagged types local to a
4563 function declaration. */
4564 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4565 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4566
4567 /* In the case where we are generating a formal types list for a C++
4568 non-static member function type, skip over the first thing on the
4569 TYPE_ARG_TYPES list because it only represents the type of the
4570 hidden `this pointer'. The debugger should be able to figure
4571 out (without being explicitly told) that this non-static member
4572 function type takes a `this pointer' and should be able to figure
4573 what the type of that hidden parameter is from the AT_member
4574 attribute of the parent TAG_subroutine_type DIE. */
4575
4576 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4577 first_parm_type = TREE_CHAIN (first_parm_type);
4578
4579 /* Make our first pass over the list of formal parameter types and output
4580 a TAG_formal_parameter DIE for each one. */
4581
4582 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4583 {
4584 formal_type = TREE_VALUE (link);
4585 if (formal_type == void_type_node)
4586 break;
4587
4588 /* Output a (nameless) DIE to represent the formal parameter itself. */
4589
4590 output_die (output_formal_parameter_die, formal_type);
4591 }
4592
4593 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4594 DIE to the end of the parameter list. */
4595
4596 if (formal_type != void_type_node)
4597 output_die (output_unspecified_parameters_die, function_or_method_type);
4598
4599 /* Make our second (and final) pass over the list of formal parameter types
4600 and output DIEs to represent those types (as necessary). */
4601
4602 for (link = TYPE_ARG_TYPES (function_or_method_type);
4603 link;
4604 link = TREE_CHAIN (link))
4605 {
4606 formal_type = TREE_VALUE (link);
4607 if (formal_type == void_type_node)
4608 break;
4609
4610 output_type (formal_type, function_or_method_type);
4611 }
4612
4613 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4614 }
4615 \f
4616 /* Remember a type in the pending_types_list. */
4617
4618 static void
4619 pend_type (type)
4620 register tree type;
4621 {
4622 if (pending_types == pending_types_allocated)
4623 {
4624 pending_types_allocated += PENDING_TYPES_INCREMENT;
4625 pending_types_list
4626 = (tree *) xrealloc (pending_types_list,
4627 sizeof (tree) * pending_types_allocated);
4628 }
4629 pending_types_list[pending_types++] = type;
4630
4631 /* Mark the pending type as having been output already (even though
4632 it hasn't been). This prevents the type from being added to the
4633 pending_types_list more than once. */
4634
4635 TREE_ASM_WRITTEN (type) = 1;
4636 }
4637
4638 /* Return non-zero if it is legitimate to output DIEs to represent a
4639 given type while we are generating the list of child DIEs for some
4640 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4641
4642 See the comments within the function for a description of when it is
4643 considered legitimate to output DIEs for various kinds of types.
4644
4645 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4646 or it may point to a BLOCK node (for types local to a block), or to a
4647 FUNCTION_DECL node (for types local to the heading of some function
4648 definition), or to a FUNCTION_TYPE node (for types local to the
4649 prototyped parameter list of a function type specification), or to a
4650 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4651 (in the case of C++ nested types).
4652
4653 The `scope' parameter should likewise be NULL or should point to a
4654 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4655 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4656
4657 This function is used only for deciding when to "pend" and when to
4658 "un-pend" types to/from the pending_types_list.
4659
4660 Note that we sometimes make use of this "type pending" feature in a
4661 rather twisted way to temporarily delay the production of DIEs for the
4662 types of formal parameters. (We do this just to make svr4 SDB happy.)
4663 It order to delay the production of DIEs representing types of formal
4664 parameters, callers of this function supply `fake_containing_scope' as
4665 the `scope' parameter to this function. Given that fake_containing_scope
4666 is a tagged type which is *not* the containing scope for *any* other type,
4667 the desired effect is achieved, i.e. output of DIEs representing types
4668 is temporarily suspended, and any type DIEs which would have otherwise
4669 been output are instead placed onto the pending_types_list. Later on,
4670 we force these (temporarily pended) types to be output simply by calling
4671 `output_pending_types_for_scope' with an actual argument equal to the
4672 true scope of the types we temporarily pended. */
4673
4674 static inline int
4675 type_ok_for_scope (type, scope)
4676 register tree type;
4677 register tree scope;
4678 {
4679 /* Tagged types (i.e. struct, union, and enum types) must always be
4680 output only in the scopes where they actually belong (or else the
4681 scoping of their own tag names and the scoping of their member
4682 names will be incorrect). Non-tagged-types on the other hand can
4683 generally be output anywhere, except that svr4 SDB really doesn't
4684 want to see them nested within struct or union types, so here we
4685 say it is always OK to immediately output any such a (non-tagged)
4686 type, so long as we are not within such a context. Note that the
4687 only kinds of non-tagged types which we will be dealing with here
4688 (for C and C++ anyway) will be array types and function types. */
4689
4690 return is_tagged_type (type)
4691 ? (TYPE_CONTEXT (type) == scope
4692 /* Ignore namespaces for the moment. */
4693 || (scope == NULL_TREE
4694 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4695 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4696 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4697 : (scope == NULL_TREE || ! is_tagged_type (scope));
4698 }
4699
4700 /* Output any pending types (from the pending_types list) which we can output
4701 now (taking into account the scope that we are working on now).
4702
4703 For each type output, remove the given type from the pending_types_list
4704 *before* we try to output it.
4705
4706 Note that we have to process the list in beginning-to-end order,
4707 because the call made here to output_type may cause yet more types
4708 to be added to the end of the list, and we may have to output some
4709 of them too. */
4710
4711 static void
4712 output_pending_types_for_scope (containing_scope)
4713 register tree containing_scope;
4714 {
4715 register unsigned i;
4716
4717 for (i = 0; i < pending_types; )
4718 {
4719 register tree type = pending_types_list[i];
4720
4721 if (type_ok_for_scope (type, containing_scope))
4722 {
4723 register tree *mover;
4724 register tree *limit;
4725
4726 pending_types--;
4727 limit = &pending_types_list[pending_types];
4728 for (mover = &pending_types_list[i]; mover < limit; mover++)
4729 *mover = *(mover+1);
4730
4731 /* Un-mark the type as having been output already (because it
4732 hasn't been, really). Then call output_type to generate a
4733 Dwarf representation of it. */
4734
4735 TREE_ASM_WRITTEN (type) = 0;
4736 output_type (type, containing_scope);
4737
4738 /* Don't increment the loop counter in this case because we
4739 have shifted all of the subsequent pending types down one
4740 element in the pending_types_list array. */
4741 }
4742 else
4743 i++;
4744 }
4745 }
4746
4747 /* Remember a type in the incomplete_types_list. */
4748
4749 static void
4750 add_incomplete_type (type)
4751 tree type;
4752 {
4753 if (incomplete_types == incomplete_types_allocated)
4754 {
4755 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4756 incomplete_types_list
4757 = (tree *) xrealloc (incomplete_types_list,
4758 sizeof (tree) * incomplete_types_allocated);
4759 }
4760
4761 incomplete_types_list[incomplete_types++] = type;
4762 }
4763
4764 /* Walk through the list of incomplete types again, trying once more to
4765 emit full debugging info for them. */
4766
4767 static void
4768 retry_incomplete_types ()
4769 {
4770 register tree type;
4771
4772 finalizing = 1;
4773 while (incomplete_types)
4774 {
4775 --incomplete_types;
4776 type = incomplete_types_list[incomplete_types];
4777 output_type (type, NULL_TREE);
4778 }
4779 }
4780
4781 static void
4782 output_type (type, containing_scope)
4783 register tree type;
4784 register tree containing_scope;
4785 {
4786 if (type == 0 || type == error_mark_node)
4787 return;
4788
4789 /* We are going to output a DIE to represent the unqualified version of
4790 this type (i.e. without any const or volatile qualifiers) so get
4791 the main variant (i.e. the unqualified version) of this type now. */
4792
4793 type = type_main_variant (type);
4794
4795 if (TREE_ASM_WRITTEN (type))
4796 {
4797 if (finalizing && AGGREGATE_TYPE_P (type))
4798 {
4799 register tree member;
4800
4801 /* Some of our nested types might not have been defined when we
4802 were written out before; force them out now. */
4803
4804 for (member = TYPE_FIELDS (type); member;
4805 member = TREE_CHAIN (member))
4806 if (TREE_CODE (member) == TYPE_DECL
4807 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4808 output_type (TREE_TYPE (member), containing_scope);
4809 }
4810 return;
4811 }
4812
4813 /* If this is a nested type whose containing class hasn't been
4814 written out yet, writing it out will cover this one, too. */
4815
4816 if (TYPE_CONTEXT (type)
4817 && TYPE_P (TYPE_CONTEXT (type))
4818 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4819 {
4820 output_type (TYPE_CONTEXT (type), containing_scope);
4821 return;
4822 }
4823
4824 /* Don't generate any DIEs for this type now unless it is OK to do so
4825 (based upon what `type_ok_for_scope' tells us). */
4826
4827 if (! type_ok_for_scope (type, containing_scope))
4828 {
4829 pend_type (type);
4830 return;
4831 }
4832
4833 switch (TREE_CODE (type))
4834 {
4835 case ERROR_MARK:
4836 break;
4837
4838 case VECTOR_TYPE:
4839 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4840 break;
4841
4842 case POINTER_TYPE:
4843 case REFERENCE_TYPE:
4844 /* Prevent infinite recursion in cases where this is a recursive
4845 type. Recursive types are possible in Ada. */
4846 TREE_ASM_WRITTEN (type) = 1;
4847 /* For these types, all that is required is that we output a DIE
4848 (or a set of DIEs) to represent the "basis" type. */
4849 output_type (TREE_TYPE (type), containing_scope);
4850 break;
4851
4852 case OFFSET_TYPE:
4853 /* This code is used for C++ pointer-to-data-member types. */
4854 /* Output a description of the relevant class type. */
4855 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4856 /* Output a description of the type of the object pointed to. */
4857 output_type (TREE_TYPE (type), containing_scope);
4858 /* Now output a DIE to represent this pointer-to-data-member type
4859 itself. */
4860 output_die (output_ptr_to_mbr_type_die, type);
4861 break;
4862
4863 case SET_TYPE:
4864 output_type (TYPE_DOMAIN (type), containing_scope);
4865 output_die (output_set_type_die, type);
4866 break;
4867
4868 case FILE_TYPE:
4869 output_type (TREE_TYPE (type), containing_scope);
4870 abort (); /* No way to represent these in Dwarf yet! */
4871 break;
4872
4873 case FUNCTION_TYPE:
4874 /* Force out return type (in case it wasn't forced out already). */
4875 output_type (TREE_TYPE (type), containing_scope);
4876 output_die (output_subroutine_type_die, type);
4877 output_formal_types (type);
4878 end_sibling_chain ();
4879 break;
4880
4881 case METHOD_TYPE:
4882 /* Force out return type (in case it wasn't forced out already). */
4883 output_type (TREE_TYPE (type), containing_scope);
4884 output_die (output_subroutine_type_die, type);
4885 output_formal_types (type);
4886 end_sibling_chain ();
4887 break;
4888
4889 case ARRAY_TYPE:
4890 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4891 {
4892 output_type (TREE_TYPE (type), containing_scope);
4893 output_die (output_string_type_die, type);
4894 }
4895 else
4896 {
4897 register tree element_type;
4898
4899 element_type = TREE_TYPE (type);
4900 while (TREE_CODE (element_type) == ARRAY_TYPE)
4901 element_type = TREE_TYPE (element_type);
4902
4903 output_type (element_type, containing_scope);
4904 output_die (output_array_type_die, type);
4905 }
4906 break;
4907
4908 case ENUMERAL_TYPE:
4909 case RECORD_TYPE:
4910 case UNION_TYPE:
4911 case QUAL_UNION_TYPE:
4912
4913 /* For a non-file-scope tagged type, we can always go ahead and
4914 output a Dwarf description of this type right now, even if
4915 the type in question is still incomplete, because if this
4916 local type *was* ever completed anywhere within its scope,
4917 that complete definition would already have been attached to
4918 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4919 node by the time we reach this point. That's true because of the
4920 way the front-end does its processing of file-scope declarations (of
4921 functions and class types) within which other types might be
4922 nested. The C and C++ front-ends always gobble up such "local
4923 scope" things en-mass before they try to output *any* debugging
4924 information for any of the stuff contained inside them and thus,
4925 we get the benefit here of what is (in effect) a pre-resolution
4926 of forward references to tagged types in local scopes.
4927
4928 Note however that for file-scope tagged types we cannot assume
4929 that such pre-resolution of forward references has taken place.
4930 A given file-scope tagged type may appear to be incomplete when
4931 we reach this point, but it may yet be given a full definition
4932 (at file-scope) later on during compilation. In order to avoid
4933 generating a premature (and possibly incorrect) set of Dwarf
4934 DIEs for such (as yet incomplete) file-scope tagged types, we
4935 generate nothing at all for as-yet incomplete file-scope tagged
4936 types here unless we are making our special "finalization" pass
4937 for file-scope things at the very end of compilation. At that
4938 time, we will certainly know as much about each file-scope tagged
4939 type as we are ever going to know, so at that point in time, we
4940 can safely generate correct Dwarf descriptions for these file-
4941 scope tagged types. */
4942
4943 if (!COMPLETE_TYPE_P (type)
4944 && (TYPE_CONTEXT (type) == NULL
4945 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4946 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4947 && !finalizing)
4948 {
4949 /* We don't need to do this for function-local types. */
4950 if (! decl_function_context (TYPE_STUB_DECL (type)))
4951 add_incomplete_type (type);
4952 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4953 }
4954
4955 /* Prevent infinite recursion in cases where the type of some
4956 member of this type is expressed in terms of this type itself. */
4957
4958 TREE_ASM_WRITTEN (type) = 1;
4959
4960 /* Output a DIE to represent the tagged type itself. */
4961
4962 switch (TREE_CODE (type))
4963 {
4964 case ENUMERAL_TYPE:
4965 output_die (output_enumeration_type_die, type);
4966 return; /* a special case -- nothing left to do so just return */
4967
4968 case RECORD_TYPE:
4969 output_die (output_structure_type_die, type);
4970 break;
4971
4972 case UNION_TYPE:
4973 case QUAL_UNION_TYPE:
4974 output_die (output_union_type_die, type);
4975 break;
4976
4977 default:
4978 abort (); /* Should never happen. */
4979 }
4980
4981 /* If this is not an incomplete type, output descriptions of
4982 each of its members.
4983
4984 Note that as we output the DIEs necessary to represent the
4985 members of this record or union type, we will also be trying
4986 to output DIEs to represent the *types* of those members.
4987 However the `output_type' function (above) will specifically
4988 avoid generating type DIEs for member types *within* the list
4989 of member DIEs for this (containing) type execpt for those
4990 types (of members) which are explicitly marked as also being
4991 members of this (containing) type themselves. The g++ front-
4992 end can force any given type to be treated as a member of some
4993 other (containing) type by setting the TYPE_CONTEXT of the
4994 given (member) type to point to the TREE node representing the
4995 appropriate (containing) type.
4996 */
4997
4998 if (COMPLETE_TYPE_P (type))
4999 {
5000 /* First output info about the base classes. */
5001 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
5002 {
5003 register tree bases = TYPE_BINFO_BASETYPES (type);
5004 register int n_bases = TREE_VEC_LENGTH (bases);
5005 register int i;
5006
5007 for (i = 0; i < n_bases; i++)
5008 {
5009 tree binfo = TREE_VEC_ELT (bases, i);
5010 output_type (BINFO_TYPE (binfo), containing_scope);
5011 output_die (output_inheritance_die, binfo);
5012 }
5013 }
5014
5015 ++in_class;
5016
5017 {
5018 register tree normal_member;
5019
5020 /* Now output info about the data members and type members. */
5021
5022 for (normal_member = TYPE_FIELDS (type);
5023 normal_member;
5024 normal_member = TREE_CHAIN (normal_member))
5025 output_decl (normal_member, type);
5026 }
5027
5028 {
5029 register tree func_member;
5030
5031 /* Now output info about the function members (if any). */
5032
5033 for (func_member = TYPE_METHODS (type);
5034 func_member;
5035 func_member = TREE_CHAIN (func_member))
5036 {
5037 /* Don't include clones in the member list. */
5038 if (DECL_ABSTRACT_ORIGIN (func_member))
5039 continue;
5040
5041 output_decl (func_member, type);
5042 }
5043 }
5044
5045 --in_class;
5046
5047 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
5048 scopes (at least in C++) so we must now output any nested
5049 pending types which are local just to this type. */
5050
5051 output_pending_types_for_scope (type);
5052
5053 end_sibling_chain (); /* Terminate member chain. */
5054 }
5055
5056 break;
5057
5058 case VOID_TYPE:
5059 case INTEGER_TYPE:
5060 case REAL_TYPE:
5061 case COMPLEX_TYPE:
5062 case BOOLEAN_TYPE:
5063 case CHAR_TYPE:
5064 break; /* No DIEs needed for fundamental types. */
5065
5066 case LANG_TYPE: /* No Dwarf representation currently defined. */
5067 break;
5068
5069 default:
5070 abort ();
5071 }
5072
5073 TREE_ASM_WRITTEN (type) = 1;
5074 }
5075
5076 static void
5077 output_tagged_type_instantiation (type)
5078 register tree type;
5079 {
5080 if (type == 0 || type == error_mark_node)
5081 return;
5082
5083 /* We are going to output a DIE to represent the unqualified version of
5084 this type (i.e. without any const or volatile qualifiers) so make
5085 sure that we have the main variant (i.e. the unqualified version) of
5086 this type now. */
5087
5088 if (type != type_main_variant (type))
5089 abort ();
5090
5091 if (!TREE_ASM_WRITTEN (type))
5092 abort ();
5093
5094 switch (TREE_CODE (type))
5095 {
5096 case ERROR_MARK:
5097 break;
5098
5099 case ENUMERAL_TYPE:
5100 output_die (output_inlined_enumeration_type_die, type);
5101 break;
5102
5103 case RECORD_TYPE:
5104 output_die (output_inlined_structure_type_die, type);
5105 break;
5106
5107 case UNION_TYPE:
5108 case QUAL_UNION_TYPE:
5109 output_die (output_inlined_union_type_die, type);
5110 break;
5111
5112 default:
5113 abort (); /* Should never happen. */
5114 }
5115 }
5116 \f
5117 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
5118 the things which are local to the given block. */
5119
5120 static void
5121 output_block (stmt, depth)
5122 register tree stmt;
5123 int depth;
5124 {
5125 register int must_output_die = 0;
5126 register tree origin;
5127 register enum tree_code origin_code;
5128
5129 /* Ignore blocks never really used to make RTL. */
5130
5131 if (! stmt || ! TREE_USED (stmt)
5132 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
5133 return;
5134
5135 /* Determine the "ultimate origin" of this block. This block may be an
5136 inlined instance of an inlined instance of inline function, so we
5137 have to trace all of the way back through the origin chain to find
5138 out what sort of node actually served as the original seed for the
5139 creation of the current block. */
5140
5141 origin = block_ultimate_origin (stmt);
5142 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
5143
5144 /* Determine if we need to output any Dwarf DIEs at all to represent this
5145 block. */
5146
5147 if (origin_code == FUNCTION_DECL)
5148 /* The outer scopes for inlinings *must* always be represented. We
5149 generate TAG_inlined_subroutine DIEs for them. (See below.) */
5150 must_output_die = 1;
5151 else
5152 {
5153 /* In the case where the current block represents an inlining of the
5154 "body block" of an inline function, we must *NOT* output any DIE
5155 for this block because we have already output a DIE to represent
5156 the whole inlined function scope and the "body block" of any
5157 function doesn't really represent a different scope according to
5158 ANSI C rules. So we check here to make sure that this block does
5159 not represent a "body block inlining" before trying to set the
5160 `must_output_die' flag. */
5161
5162 if (! is_body_block (origin ? origin : stmt))
5163 {
5164 /* Determine if this block directly contains any "significant"
5165 local declarations which we will need to output DIEs for. */
5166
5167 if (debug_info_level > DINFO_LEVEL_TERSE)
5168 /* We are not in terse mode so *any* local declaration counts
5169 as being a "significant" one. */
5170 must_output_die = (BLOCK_VARS (stmt) != NULL);
5171 else
5172 {
5173 register tree decl;
5174
5175 /* We are in terse mode, so only local (nested) function
5176 definitions count as "significant" local declarations. */
5177
5178 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5179 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
5180 {
5181 must_output_die = 1;
5182 break;
5183 }
5184 }
5185 }
5186 }
5187
5188 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
5189 DIE for any block which contains no significant local declarations
5190 at all. Rather, in such cases we just call `output_decls_for_scope'
5191 so that any needed Dwarf info for any sub-blocks will get properly
5192 generated. Note that in terse mode, our definition of what constitutes
5193 a "significant" local declaration gets restricted to include only
5194 inlined function instances and local (nested) function definitions. */
5195
5196 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
5197 /* We don't care about an abstract inlined subroutine. */;
5198 else if (must_output_die)
5199 {
5200 output_die ((origin_code == FUNCTION_DECL)
5201 ? output_inlined_subroutine_die
5202 : output_lexical_block_die,
5203 stmt);
5204 output_decls_for_scope (stmt, depth);
5205 end_sibling_chain ();
5206 }
5207 else
5208 output_decls_for_scope (stmt, depth);
5209 }
5210
5211 /* Output all of the decls declared within a given scope (also called
5212 a `binding contour') and (recursively) all of it's sub-blocks. */
5213
5214 static void
5215 output_decls_for_scope (stmt, depth)
5216 register tree stmt;
5217 int depth;
5218 {
5219 /* Ignore blocks never really used to make RTL. */
5220
5221 if (! stmt || ! TREE_USED (stmt))
5222 return;
5223
5224 /* Output the DIEs to represent all of the data objects, functions,
5225 typedefs, and tagged types declared directly within this block
5226 but not within any nested sub-blocks. */
5227
5228 {
5229 register tree decl;
5230
5231 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5232 output_decl (decl, stmt);
5233 }
5234
5235 output_pending_types_for_scope (stmt);
5236
5237 /* Output the DIEs to represent all sub-blocks (and the items declared
5238 therein) of this block. */
5239
5240 {
5241 register tree subblocks;
5242
5243 for (subblocks = BLOCK_SUBBLOCKS (stmt);
5244 subblocks;
5245 subblocks = BLOCK_CHAIN (subblocks))
5246 output_block (subblocks, depth + 1);
5247 }
5248 }
5249
5250 /* Is this a typedef we can avoid emitting? */
5251
5252 static inline int
5253 is_redundant_typedef (decl)
5254 register tree decl;
5255 {
5256 if (TYPE_DECL_IS_STUB (decl))
5257 return 1;
5258 if (DECL_ARTIFICIAL (decl)
5259 && DECL_CONTEXT (decl)
5260 && is_tagged_type (DECL_CONTEXT (decl))
5261 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
5262 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
5263 /* Also ignore the artificial member typedef for the class name. */
5264 return 1;
5265 return 0;
5266 }
5267
5268 /* Output Dwarf .debug information for a decl described by DECL. */
5269
5270 static void
5271 output_decl (decl, containing_scope)
5272 register tree decl;
5273 register tree containing_scope;
5274 {
5275 /* Make a note of the decl node we are going to be working on. We may
5276 need to give the user the source coordinates of where it appeared in
5277 case we notice (later on) that something about it looks screwy. */
5278
5279 dwarf_last_decl = decl;
5280
5281 if (TREE_CODE (decl) == ERROR_MARK)
5282 return;
5283
5284 /* If a structure is declared within an initialization, e.g. as the
5285 operand of a sizeof, then it will not have a name. We don't want
5286 to output a DIE for it, as the tree nodes are in the temporary obstack */
5287
5288 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5289 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
5290 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
5291 || (TYPE_FIELDS (TREE_TYPE (decl))
5292 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
5293 return;
5294
5295 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5296
5297 if (DECL_IGNORED_P (decl))
5298 return;
5299
5300 switch (TREE_CODE (decl))
5301 {
5302 case CONST_DECL:
5303 /* The individual enumerators of an enum type get output when we
5304 output the Dwarf representation of the relevant enum type itself. */
5305 break;
5306
5307 case FUNCTION_DECL:
5308 /* If we are in terse mode, don't output any DIEs to represent
5309 mere function declarations. Also, if we are conforming
5310 to the DWARF version 1 specification, don't output DIEs for
5311 mere function declarations. */
5312
5313 if (DECL_INITIAL (decl) == NULL_TREE)
5314 #if (DWARF_VERSION > 1)
5315 if (debug_info_level <= DINFO_LEVEL_TERSE)
5316 #endif
5317 break;
5318
5319 /* Before we describe the FUNCTION_DECL itself, make sure that we
5320 have described its return type. */
5321
5322 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
5323
5324 {
5325 /* And its containing type. */
5326 register tree origin = decl_class_context (decl);
5327 if (origin)
5328 output_type (origin, containing_scope);
5329 }
5330
5331 /* If we're emitting an out-of-line copy of an inline function,
5332 set up to refer to the abstract instance emitted from
5333 dwarfout_deferred_inline_function. */
5334 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
5335 && ! (containing_scope && TYPE_P (containing_scope)))
5336 set_decl_origin_self (decl);
5337
5338 /* If the following DIE will represent a function definition for a
5339 function with "extern" linkage, output a special "pubnames" DIE
5340 label just ahead of the actual DIE. A reference to this label
5341 was already generated in the .debug_pubnames section sub-entry
5342 for this function definition. */
5343
5344 if (TREE_PUBLIC (decl))
5345 {
5346 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5347
5348 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5349 ASM_OUTPUT_LABEL (asm_out_file, label);
5350 }
5351
5352 /* Now output a DIE to represent the function itself. */
5353
5354 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
5355 ? output_global_subroutine_die
5356 : output_local_subroutine_die,
5357 decl);
5358
5359 /* Now output descriptions of the arguments for this function.
5360 This gets (unnecessarily?) complex because of the fact that
5361 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
5362 cases where there was a trailing `...' at the end of the formal
5363 parameter list. In order to find out if there was a trailing
5364 ellipsis or not, we must instead look at the type associated
5365 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
5366 If the chain of type nodes hanging off of this FUNCTION_TYPE node
5367 ends with a void_type_node then there should *not* be an ellipsis
5368 at the end. */
5369
5370 /* In the case where we are describing a mere function declaration, all
5371 we need to do here (and all we *can* do here) is to describe
5372 the *types* of its formal parameters. */
5373
5374 if (decl != current_function_decl || in_class)
5375 output_formal_types (TREE_TYPE (decl));
5376 else
5377 {
5378 /* Generate DIEs to represent all known formal parameters */
5379
5380 register tree arg_decls = DECL_ARGUMENTS (decl);
5381 register tree parm;
5382
5383 /* WARNING! Kludge zone ahead! Here we have a special
5384 hack for svr4 SDB compatibility. Instead of passing the
5385 current FUNCTION_DECL node as the second parameter (i.e.
5386 the `containing_scope' parameter) to `output_decl' (as
5387 we ought to) we instead pass a pointer to our own private
5388 fake_containing_scope node. That node is a RECORD_TYPE
5389 node which NO OTHER TYPE may ever actually be a member of.
5390
5391 This pointer will ultimately get passed into `output_type'
5392 as its `containing_scope' parameter. `Output_type' will
5393 then perform its part in the hack... i.e. it will pend
5394 the type of the formal parameter onto the pending_types
5395 list. Later on, when we are done generating the whole
5396 sequence of formal parameter DIEs for this function
5397 definition, we will un-pend all previously pended types
5398 of formal parameters for this function definition.
5399
5400 This whole kludge prevents any type DIEs from being
5401 mixed in with the formal parameter DIEs. That's good
5402 because svr4 SDB believes that the list of formal
5403 parameter DIEs for a function ends wherever the first
5404 non-formal-parameter DIE appears. Thus, we have to
5405 keep the formal parameter DIEs segregated. They must
5406 all appear (consecutively) at the start of the list of
5407 children for the DIE representing the function definition.
5408 Then (and only then) may we output any additional DIEs
5409 needed to represent the types of these formal parameters.
5410 */
5411
5412 /*
5413 When generating DIEs, generate the unspecified_parameters
5414 DIE instead if we come across the arg "__builtin_va_alist"
5415 */
5416
5417 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
5418 if (TREE_CODE (parm) == PARM_DECL)
5419 {
5420 if (DECL_NAME(parm) &&
5421 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
5422 "__builtin_va_alist") )
5423 output_die (output_unspecified_parameters_die, decl);
5424 else
5425 output_decl (parm, fake_containing_scope);
5426 }
5427
5428 /*
5429 Now that we have finished generating all of the DIEs to
5430 represent the formal parameters themselves, force out
5431 any DIEs needed to represent their types. We do this
5432 simply by un-pending all previously pended types which
5433 can legitimately go into the chain of children DIEs for
5434 the current FUNCTION_DECL.
5435 */
5436
5437 output_pending_types_for_scope (decl);
5438
5439 /*
5440 Decide whether we need a unspecified_parameters DIE at the end.
5441 There are 2 more cases to do this for:
5442 1) the ansi ... declaration - this is detectable when the end
5443 of the arg list is not a void_type_node
5444 2) an unprototyped function declaration (not a definition). This
5445 just means that we have no info about the parameters at all.
5446 */
5447
5448 {
5449 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
5450
5451 if (fn_arg_types)
5452 {
5453 /* this is the prototyped case, check for ... */
5454 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
5455 output_die (output_unspecified_parameters_die, decl);
5456 }
5457 else
5458 {
5459 /* this is unprototyped, check for undefined (just declaration) */
5460 if (!DECL_INITIAL (decl))
5461 output_die (output_unspecified_parameters_die, decl);
5462 }
5463 }
5464
5465 /* Output Dwarf info for all of the stuff within the body of the
5466 function (if it has one - it may be just a declaration). */
5467
5468 {
5469 register tree outer_scope = DECL_INITIAL (decl);
5470
5471 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
5472 {
5473 /* Note that here, `outer_scope' is a pointer to the outermost
5474 BLOCK node created to represent a function.
5475 This outermost BLOCK actually represents the outermost
5476 binding contour for the function, i.e. the contour in which
5477 the function's formal parameters and labels get declared.
5478
5479 Curiously, it appears that the front end doesn't actually
5480 put the PARM_DECL nodes for the current function onto the
5481 BLOCK_VARS list for this outer scope. (They are strung
5482 off of the DECL_ARGUMENTS list for the function instead.)
5483 The BLOCK_VARS list for the `outer_scope' does provide us
5484 with a list of the LABEL_DECL nodes for the function however,
5485 and we output DWARF info for those here.
5486
5487 Just within the `outer_scope' there will be a BLOCK node
5488 representing the function's outermost pair of curly braces,
5489 and any blocks used for the base and member initializers of
5490 a C++ constructor function. */
5491
5492 output_decls_for_scope (outer_scope, 0);
5493
5494 /* Finally, force out any pending types which are local to the
5495 outermost block of this function definition. These will
5496 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
5497 node itself. */
5498
5499 output_pending_types_for_scope (decl);
5500 }
5501 }
5502 }
5503
5504 /* Generate a terminator for the list of stuff `owned' by this
5505 function. */
5506
5507 end_sibling_chain ();
5508
5509 break;
5510
5511 case TYPE_DECL:
5512 /* If we are in terse mode, don't generate any DIEs to represent
5513 any actual typedefs. Note that even when we are in terse mode,
5514 we must still output DIEs to represent those tagged types which
5515 are used (directly or indirectly) in the specification of either
5516 a return type or a formal parameter type of some function. */
5517
5518 if (debug_info_level <= DINFO_LEVEL_TERSE)
5519 if (! TYPE_DECL_IS_STUB (decl)
5520 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5521 return;
5522
5523 /* In the special case of a TYPE_DECL node representing
5524 the declaration of some type tag, if the given TYPE_DECL is
5525 marked as having been instantiated from some other (original)
5526 TYPE_DECL node (e.g. one which was generated within the original
5527 definition of an inline function) we have to generate a special
5528 (abbreviated) TAG_structure_type, TAG_union_type, or
5529 TAG_enumeration-type DIE here. */
5530
5531 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5532 {
5533 output_tagged_type_instantiation (TREE_TYPE (decl));
5534 return;
5535 }
5536
5537 output_type (TREE_TYPE (decl), containing_scope);
5538
5539 if (! is_redundant_typedef (decl))
5540 /* Output a DIE to represent the typedef itself. */
5541 output_die (output_typedef_die, decl);
5542 break;
5543
5544 case LABEL_DECL:
5545 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5546 output_die (output_label_die, decl);
5547 break;
5548
5549 case VAR_DECL:
5550 /* If we are conforming to the DWARF version 1 specification, don't
5551 generated any DIEs to represent mere external object declarations. */
5552
5553 #if (DWARF_VERSION <= 1)
5554 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5555 break;
5556 #endif
5557
5558 /* If we are in terse mode, don't generate any DIEs to represent
5559 any variable declarations or definitions. */
5560
5561 if (debug_info_level <= DINFO_LEVEL_TERSE)
5562 break;
5563
5564 /* Output any DIEs that are needed to specify the type of this data
5565 object. */
5566
5567 output_type (TREE_TYPE (decl), containing_scope);
5568
5569 {
5570 /* And its containing type. */
5571 register tree origin = decl_class_context (decl);
5572 if (origin)
5573 output_type (origin, containing_scope);
5574 }
5575
5576 /* If the following DIE will represent a data object definition for a
5577 data object with "extern" linkage, output a special "pubnames" DIE
5578 label just ahead of the actual DIE. A reference to this label
5579 was already generated in the .debug_pubnames section sub-entry
5580 for this data object definition. */
5581
5582 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5583 {
5584 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5585
5586 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5587 ASM_OUTPUT_LABEL (asm_out_file, label);
5588 }
5589
5590 /* Now output the DIE to represent the data object itself. This gets
5591 complicated because of the possibility that the VAR_DECL really
5592 represents an inlined instance of a formal parameter for an inline
5593 function. */
5594
5595 {
5596 register void (*func) PARAMS ((void *));
5597 register tree origin = decl_ultimate_origin (decl);
5598
5599 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5600 func = output_formal_parameter_die;
5601 else
5602 {
5603 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5604 func = output_global_variable_die;
5605 else
5606 func = output_local_variable_die;
5607 }
5608 output_die (func, decl);
5609 }
5610 break;
5611
5612 case FIELD_DECL:
5613 /* Ignore the nameless fields that are used to skip bits. */
5614 if (DECL_NAME (decl) != 0)
5615 {
5616 output_type (member_declared_type (decl), containing_scope);
5617 output_die (output_member_die, decl);
5618 }
5619 break;
5620
5621 case PARM_DECL:
5622 /* Force out the type of this formal, if it was not forced out yet.
5623 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5624 It should be able to grok the presence of type DIEs within a list
5625 of TAG_formal_parameter DIEs, but it doesn't. */
5626
5627 output_type (TREE_TYPE (decl), containing_scope);
5628 output_die (output_formal_parameter_die, decl);
5629 break;
5630
5631 case NAMESPACE_DECL:
5632 /* Ignore for now. */
5633 break;
5634
5635 default:
5636 abort ();
5637 }
5638 }
5639 \f
5640 /* Output debug information for a function. */
5641 static void
5642 dwarfout_function_decl (decl)
5643 tree decl;
5644 {
5645 dwarfout_file_scope_decl (decl, 0);
5646 }
5647
5648 /* Debug information for a global DECL. Called from toplev.c after
5649 compilation proper has finished. */
5650 static void
5651 dwarfout_global_decl (decl)
5652 tree decl;
5653 {
5654 /* Output DWARF information for file-scope tentative data object
5655 declarations, file-scope (extern) function declarations (which
5656 had no corresponding body) and file-scope tagged type
5657 declarations and definitions which have not yet been forced out. */
5658
5659 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
5660 dwarfout_file_scope_decl (decl, 1);
5661 }
5662
5663 /* DECL is an inline function, whose body is present, but which is not
5664 being output at this point. (We're putting that off until we need
5665 to do it.) */
5666 static void
5667 dwarfout_deferred_inline_function (decl)
5668 tree decl;
5669 {
5670 /* Generate the DWARF info for the "abstract" instance of a function
5671 which we may later generate inlined and/or out-of-line instances
5672 of. */
5673 if ((DECL_INLINE (decl) || DECL_ABSTRACT (decl))
5674 && ! DECL_ABSTRACT_ORIGIN (decl))
5675 {
5676 /* The front-end may not have set CURRENT_FUNCTION_DECL, but the
5677 DWARF code expects it to be set in this case. Intuitively,
5678 DECL is the function we just finished defining, so setting
5679 CURRENT_FUNCTION_DECL is sensible. */
5680 tree saved_cfd = current_function_decl;
5681 int was_abstract = DECL_ABSTRACT (decl);
5682 current_function_decl = decl;
5683
5684 /* Let the DWARF code do its work. */
5685 set_decl_abstract_flags (decl, 1);
5686 dwarfout_file_scope_decl (decl, 0);
5687 if (! was_abstract)
5688 set_decl_abstract_flags (decl, 0);
5689
5690 /* Reset CURRENT_FUNCTION_DECL. */
5691 current_function_decl = saved_cfd;
5692 }
5693 }
5694
5695 static void
5696 dwarfout_file_scope_decl (decl, set_finalizing)
5697 register tree decl;
5698 register int set_finalizing;
5699 {
5700 if (TREE_CODE (decl) == ERROR_MARK)
5701 return;
5702
5703 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5704
5705 if (DECL_IGNORED_P (decl))
5706 return;
5707
5708 switch (TREE_CODE (decl))
5709 {
5710 case FUNCTION_DECL:
5711
5712 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5713 a builtin function. Explicit programmer-supplied declarations of
5714 these same functions should NOT be ignored however. */
5715
5716 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5717 return;
5718
5719 /* What we would really like to do here is to filter out all mere
5720 file-scope declarations of file-scope functions which are never
5721 referenced later within this translation unit (and keep all of
5722 ones that *are* referenced later on) but we aren't clairvoyant,
5723 so we have no idea which functions will be referenced in the
5724 future (i.e. later on within the current translation unit).
5725 So here we just ignore all file-scope function declarations
5726 which are not also definitions. If and when the debugger needs
5727 to know something about these functions, it wil have to hunt
5728 around and find the DWARF information associated with the
5729 *definition* of the function.
5730
5731 Note that we can't just check `DECL_EXTERNAL' to find out which
5732 FUNCTION_DECL nodes represent definitions and which ones represent
5733 mere declarations. We have to check `DECL_INITIAL' instead. That's
5734 because the C front-end supports some weird semantics for "extern
5735 inline" function definitions. These can get inlined within the
5736 current translation unit (an thus, we need to generate DWARF info
5737 for their abstract instances so that the DWARF info for the
5738 concrete inlined instances can have something to refer to) but
5739 the compiler never generates any out-of-lines instances of such
5740 things (despite the fact that they *are* definitions). The
5741 important point is that the C front-end marks these "extern inline"
5742 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5743 anyway.
5744
5745 Note that the C++ front-end also plays some similar games for inline
5746 function definitions appearing within include files which also
5747 contain `#pragma interface' pragmas. */
5748
5749 if (DECL_INITIAL (decl) == NULL_TREE)
5750 return;
5751
5752 if (TREE_PUBLIC (decl)
5753 && ! DECL_EXTERNAL (decl)
5754 && ! DECL_ABSTRACT (decl))
5755 {
5756 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5757
5758 /* Output a .debug_pubnames entry for a public function
5759 defined in this compilation unit. */
5760
5761 fputc ('\n', asm_out_file);
5762 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5763 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5764 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5765 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5766 IDENTIFIER_POINTER (DECL_NAME (decl)));
5767 ASM_OUTPUT_POP_SECTION (asm_out_file);
5768 }
5769
5770 break;
5771
5772 case VAR_DECL:
5773
5774 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5775 object declaration and if the declaration was never even
5776 referenced from within this entire compilation unit. We
5777 suppress these DIEs in order to save space in the .debug section
5778 (by eliminating entries which are probably useless). Note that
5779 we must not suppress block-local extern declarations (whether
5780 used or not) because that would screw-up the debugger's name
5781 lookup mechanism and cause it to miss things which really ought
5782 to be in scope at a given point. */
5783
5784 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5785 return;
5786
5787 if (TREE_PUBLIC (decl)
5788 && ! DECL_EXTERNAL (decl)
5789 && GET_CODE (DECL_RTL (decl)) == MEM
5790 && ! DECL_ABSTRACT (decl))
5791 {
5792 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5793
5794 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5795 {
5796 /* Output a .debug_pubnames entry for a public variable
5797 defined in this compilation unit. */
5798
5799 fputc ('\n', asm_out_file);
5800 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5801 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5802 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5803 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5804 IDENTIFIER_POINTER (DECL_NAME (decl)));
5805 ASM_OUTPUT_POP_SECTION (asm_out_file);
5806 }
5807
5808 if (DECL_INITIAL (decl) == NULL)
5809 {
5810 /* Output a .debug_aranges entry for a public variable
5811 which is tentatively defined in this compilation unit. */
5812
5813 fputc ('\n', asm_out_file);
5814 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
5815 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5816 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5817 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5818 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5819 ASM_OUTPUT_POP_SECTION (asm_out_file);
5820 }
5821 }
5822
5823 /* If we are in terse mode, don't generate any DIEs to represent
5824 any variable declarations or definitions. */
5825
5826 if (debug_info_level <= DINFO_LEVEL_TERSE)
5827 return;
5828
5829 break;
5830
5831 case TYPE_DECL:
5832 /* Don't bother trying to generate any DIEs to represent any of the
5833 normal built-in types for the language we are compiling, except
5834 in cases where the types in question are *not* DWARF fundamental
5835 types. We make an exception in the case of non-fundamental types
5836 for the sake of objective C (and perhaps C++) because the GNU
5837 front-ends for these languages may in fact create certain "built-in"
5838 types which are (for example) RECORD_TYPEs. In such cases, we
5839 really need to output these (non-fundamental) types because other
5840 DIEs may contain references to them. */
5841
5842 /* Also ignore language dependent types here, because they are probably
5843 also built-in types. If we didn't ignore them, then we would get
5844 references to undefined labels because output_type doesn't support
5845 them. So, for now, we need to ignore them to avoid assembler
5846 errors. */
5847
5848 /* ??? This code is different than the equivalent code in dwarf2out.c.
5849 The dwarf2out.c code is probably more correct. */
5850
5851 if (DECL_SOURCE_LINE (decl) == 0
5852 && (type_is_fundamental (TREE_TYPE (decl))
5853 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5854 return;
5855
5856 /* If we are in terse mode, don't generate any DIEs to represent
5857 any actual typedefs. Note that even when we are in terse mode,
5858 we must still output DIEs to represent those tagged types which
5859 are used (directly or indirectly) in the specification of either
5860 a return type or a formal parameter type of some function. */
5861
5862 if (debug_info_level <= DINFO_LEVEL_TERSE)
5863 if (! TYPE_DECL_IS_STUB (decl)
5864 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5865 return;
5866
5867 break;
5868
5869 default:
5870 return;
5871 }
5872
5873 fputc ('\n', asm_out_file);
5874 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5875 finalizing = set_finalizing;
5876 output_decl (decl, NULL_TREE);
5877
5878 /* NOTE: The call above to `output_decl' may have caused one or more
5879 file-scope named types (i.e. tagged types) to be placed onto the
5880 pending_types_list. We have to get those types off of that list
5881 at some point, and this is the perfect time to do it. If we didn't
5882 take them off now, they might still be on the list when cc1 finally
5883 exits. That might be OK if it weren't for the fact that when we put
5884 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5885 for these types, and that causes them never to be output unless
5886 `output_pending_types_for_scope' takes them off of the list and un-sets
5887 their TREE_ASM_WRITTEN flags. */
5888
5889 output_pending_types_for_scope (NULL_TREE);
5890
5891 /* The above call should have totally emptied the pending_types_list
5892 if this is not a nested function or class. If this is a nested type,
5893 then the remaining pending_types will be emitted when the containing type
5894 is handled. */
5895
5896 if (! DECL_CONTEXT (decl))
5897 {
5898 if (pending_types != 0)
5899 abort ();
5900 }
5901
5902 ASM_OUTPUT_POP_SECTION (asm_out_file);
5903
5904 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5905 current_funcdef_number++;
5906 }
5907 \f
5908 /* Output a marker (i.e. a label) for the beginning of the generated code
5909 for a lexical block. */
5910
5911 static void
5912 dwarfout_begin_block (line, blocknum)
5913 unsigned int line ATTRIBUTE_UNUSED;
5914 unsigned int blocknum;
5915 {
5916 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5917
5918 function_section (current_function_decl);
5919 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5920 ASM_OUTPUT_LABEL (asm_out_file, label);
5921 }
5922
5923 /* Output a marker (i.e. a label) for the end of the generated code
5924 for a lexical block. */
5925
5926 static void
5927 dwarfout_end_block (line, blocknum)
5928 unsigned int line ATTRIBUTE_UNUSED;
5929 unsigned int blocknum;
5930 {
5931 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5932
5933 function_section (current_function_decl);
5934 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5935 ASM_OUTPUT_LABEL (asm_out_file, label);
5936 }
5937
5938 /* Output a marker (i.e. a label) for the point in the generated code where
5939 the real body of the function begins (after parameters have been moved
5940 to their home locations). */
5941
5942 static void
5943 dwarfout_end_prologue (line)
5944 unsigned int line ATTRIBUTE_UNUSED;
5945 {
5946 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5947
5948 if (! use_gnu_debug_info_extensions)
5949 return;
5950
5951 function_section (current_function_decl);
5952 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5953 ASM_OUTPUT_LABEL (asm_out_file, label);
5954 }
5955
5956 /* Output a marker (i.e. a label) for the point in the generated code where
5957 the real body of the function ends (just before the epilogue code). */
5958
5959 static void
5960 dwarfout_end_function (line)
5961 unsigned int line ATTRIBUTE_UNUSED;
5962 {
5963 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5964
5965 if (! use_gnu_debug_info_extensions)
5966 return;
5967 function_section (current_function_decl);
5968 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5969 ASM_OUTPUT_LABEL (asm_out_file, label);
5970 }
5971
5972 /* Output a marker (i.e. a label) for the absolute end of the generated code
5973 for a function definition. This gets called *after* the epilogue code
5974 has been generated. */
5975
5976 static void
5977 dwarfout_end_epilogue ()
5978 {
5979 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5980
5981 /* Output a label to mark the endpoint of the code generated for this
5982 function. */
5983
5984 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5985 ASM_OUTPUT_LABEL (asm_out_file, label);
5986 }
5987
5988 static void
5989 shuffle_filename_entry (new_zeroth)
5990 register filename_entry *new_zeroth;
5991 {
5992 filename_entry temp_entry;
5993 register filename_entry *limit_p;
5994 register filename_entry *move_p;
5995
5996 if (new_zeroth == &filename_table[0])
5997 return;
5998
5999 temp_entry = *new_zeroth;
6000
6001 /* Shift entries up in the table to make room at [0]. */
6002
6003 limit_p = &filename_table[0];
6004 for (move_p = new_zeroth; move_p > limit_p; move_p--)
6005 *move_p = *(move_p-1);
6006
6007 /* Install the found entry at [0]. */
6008
6009 filename_table[0] = temp_entry;
6010 }
6011
6012 /* Create a new (string) entry for the .debug_sfnames section. */
6013
6014 static void
6015 generate_new_sfname_entry ()
6016 {
6017 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6018
6019 fputc ('\n', asm_out_file);
6020 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6021 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
6022 ASM_OUTPUT_LABEL (asm_out_file, label);
6023 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
6024 filename_table[0].name
6025 ? filename_table[0].name
6026 : "");
6027 ASM_OUTPUT_POP_SECTION (asm_out_file);
6028 }
6029
6030 /* Lookup a filename (in the list of filenames that we know about here in
6031 dwarfout.c) and return its "index". The index of each (known) filename
6032 is just a unique number which is associated with only that one filename.
6033 We need such numbers for the sake of generating labels (in the
6034 .debug_sfnames section) and references to those unique labels (in the
6035 .debug_srcinfo and .debug_macinfo sections).
6036
6037 If the filename given as an argument is not found in our current list,
6038 add it to the list and assign it the next available unique index number.
6039
6040 Whatever we do (i.e. whether we find a pre-existing filename or add a new
6041 one), we shuffle the filename found (or added) up to the zeroth entry of
6042 our list of filenames (which is always searched linearly). We do this so
6043 as to optimize the most common case for these filename lookups within
6044 dwarfout.c. The most common case by far is the case where we call
6045 lookup_filename to lookup the very same filename that we did a lookup
6046 on the last time we called lookup_filename. We make sure that this
6047 common case is fast because such cases will constitute 99.9% of the
6048 lookups we ever do (in practice).
6049
6050 If we add a new filename entry to our table, we go ahead and generate
6051 the corresponding entry in the .debug_sfnames section right away.
6052 Doing so allows us to avoid tickling an assembler bug (present in some
6053 m68k assemblers) which yields assembly-time errors in cases where the
6054 difference of two label addresses is taken and where the two labels
6055 are in a section *other* than the one where the difference is being
6056 calculated, and where at least one of the two symbol references is a
6057 forward reference. (This bug could be tickled by our .debug_srcinfo
6058 entries if we don't output their corresponding .debug_sfnames entries
6059 before them.) */
6060
6061 static unsigned
6062 lookup_filename (file_name)
6063 const char *file_name;
6064 {
6065 register filename_entry *search_p;
6066 register filename_entry *limit_p = &filename_table[ft_entries];
6067
6068 for (search_p = filename_table; search_p < limit_p; search_p++)
6069 if (!strcmp (file_name, search_p->name))
6070 {
6071 /* When we get here, we have found the filename that we were
6072 looking for in the filename_table. Now we want to make sure
6073 that it gets moved to the zero'th entry in the table (if it
6074 is not already there) so that subsequent attempts to find the
6075 same filename will find it as quickly as possible. */
6076
6077 shuffle_filename_entry (search_p);
6078 return filename_table[0].number;
6079 }
6080
6081 /* We come here whenever we have a new filename which is not registered
6082 in the current table. Here we add it to the table. */
6083
6084 /* Prepare to add a new table entry by making sure there is enough space
6085 in the table to do so. If not, expand the current table. */
6086
6087 if (ft_entries == ft_entries_allocated)
6088 {
6089 ft_entries_allocated += FT_ENTRIES_INCREMENT;
6090 filename_table
6091 = (filename_entry *)
6092 xrealloc (filename_table,
6093 ft_entries_allocated * sizeof (filename_entry));
6094 }
6095
6096 /* Initially, add the new entry at the end of the filename table. */
6097
6098 filename_table[ft_entries].number = ft_entries;
6099 filename_table[ft_entries].name = xstrdup (file_name);
6100
6101 /* Shuffle the new entry into filename_table[0]. */
6102
6103 shuffle_filename_entry (&filename_table[ft_entries]);
6104
6105 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6106 generate_new_sfname_entry ();
6107
6108 ft_entries++;
6109 return filename_table[0].number;
6110 }
6111
6112 static void
6113 generate_srcinfo_entry (line_entry_num, files_entry_num)
6114 unsigned line_entry_num;
6115 unsigned files_entry_num;
6116 {
6117 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6118
6119 fputc ('\n', asm_out_file);
6120 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6121 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
6122 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
6123 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
6124 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
6125 ASM_OUTPUT_POP_SECTION (asm_out_file);
6126 }
6127
6128 static void
6129 dwarfout_source_line (line, filename)
6130 unsigned int line;
6131 const char *filename;
6132 {
6133 if (debug_info_level >= DINFO_LEVEL_NORMAL
6134 /* We can't emit line number info for functions in separate sections,
6135 because the assembler can't subtract labels in different sections. */
6136 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
6137 {
6138 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6139 static unsigned last_line_entry_num = 0;
6140 static unsigned prev_file_entry_num = (unsigned) -1;
6141 register unsigned this_file_entry_num;
6142
6143 function_section (current_function_decl);
6144 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
6145 ASM_OUTPUT_LABEL (asm_out_file, label);
6146
6147 fputc ('\n', asm_out_file);
6148
6149 if (use_gnu_debug_info_extensions)
6150 this_file_entry_num = lookup_filename (filename);
6151 else
6152 this_file_entry_num = (unsigned) -1;
6153
6154 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6155 if (this_file_entry_num != prev_file_entry_num)
6156 {
6157 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
6158
6159 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
6160 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
6161 }
6162
6163 {
6164 register const char *tail = strrchr (filename, '/');
6165
6166 if (tail != NULL)
6167 filename = tail;
6168 }
6169
6170 fprintf (asm_out_file, "%s%u\t%s %s:%u\n",
6171 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
6172 filename, line);
6173 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6174 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
6175 ASM_OUTPUT_POP_SECTION (asm_out_file);
6176
6177 if (this_file_entry_num != prev_file_entry_num)
6178 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
6179 prev_file_entry_num = this_file_entry_num;
6180 }
6181 }
6182
6183 /* Generate an entry in the .debug_macinfo section. */
6184
6185 static void
6186 generate_macinfo_entry (type_and_offset, string)
6187 register const char *type_and_offset;
6188 register const char *string;
6189 {
6190 if (! use_gnu_debug_info_extensions)
6191 return;
6192
6193 fputc ('\n', asm_out_file);
6194 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6195 fprintf (asm_out_file, "%s%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
6196 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
6197 ASM_OUTPUT_POP_SECTION (asm_out_file);
6198 }
6199
6200 /* Wrapper for toplev.c callback to check debug info level. */
6201 static void
6202 dwarfout_start_source_file_check (line, filename)
6203 unsigned int line;
6204 register const char *filename;
6205 {
6206 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6207 dwarfout_start_source_file (line, filename);
6208 }
6209
6210 static void
6211 dwarfout_start_source_file (line, filename)
6212 unsigned int line ATTRIBUTE_UNUSED;
6213 register const char *filename;
6214 {
6215 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6216 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
6217
6218 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
6219 sprintf (type_and_offset, "0x%08x+%s-%s",
6220 ((unsigned) MACINFO_start << 24),
6221 /* Hack: skip leading '*' . */
6222 (*label == '*') + label,
6223 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
6224 generate_macinfo_entry (type_and_offset, "");
6225 }
6226
6227 /* Wrapper for toplev.c callback to check debug info level. */
6228 static void
6229 dwarfout_end_source_file_check (lineno)
6230 register unsigned lineno;
6231 {
6232 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6233 dwarfout_end_source_file (lineno);
6234 }
6235
6236 static void
6237 dwarfout_end_source_file (lineno)
6238 register unsigned lineno;
6239 {
6240 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6241
6242 sprintf (type_and_offset, "0x%08x+%u",
6243 ((unsigned) MACINFO_resume << 24), lineno);
6244 generate_macinfo_entry (type_and_offset, "");
6245 }
6246
6247 /* Called from check_newline in c-parse.y. The `buffer' parameter
6248 contains the tail part of the directive line, i.e. the part which
6249 is past the initial whitespace, #, whitespace, directive-name,
6250 whitespace part. */
6251
6252 static void
6253 dwarfout_define (lineno, buffer)
6254 register unsigned lineno;
6255 register const char *buffer;
6256 {
6257 static int initialized = 0;
6258 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6259
6260 if (!initialized)
6261 {
6262 dwarfout_start_source_file (0, primary_filename);
6263 initialized = 1;
6264 }
6265 sprintf (type_and_offset, "0x%08x+%u",
6266 ((unsigned) MACINFO_define << 24), lineno);
6267 generate_macinfo_entry (type_and_offset, buffer);
6268 }
6269
6270 /* Called from check_newline in c-parse.y. The `buffer' parameter
6271 contains the tail part of the directive line, i.e. the part which
6272 is past the initial whitespace, #, whitespace, directive-name,
6273 whitespace part. */
6274
6275 static void
6276 dwarfout_undef (lineno, buffer)
6277 register unsigned lineno;
6278 register const char *buffer;
6279 {
6280 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6281
6282 sprintf (type_and_offset, "0x%08x+%u",
6283 ((unsigned) MACINFO_undef << 24), lineno);
6284 generate_macinfo_entry (type_and_offset, buffer);
6285 }
6286
6287 /* Set up for Dwarf output at the start of compilation. */
6288
6289 static void
6290 dwarfout_init (main_input_filename)
6291 register const char *main_input_filename;
6292 {
6293 /* Remember the name of the primary input file. */
6294
6295 primary_filename = main_input_filename;
6296
6297 /* Allocate the initial hunk of the pending_sibling_stack. */
6298
6299 pending_sibling_stack
6300 = (unsigned *)
6301 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
6302 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
6303 pending_siblings = 1;
6304
6305 /* Allocate the initial hunk of the filename_table. */
6306
6307 filename_table
6308 = (filename_entry *)
6309 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
6310 ft_entries_allocated = FT_ENTRIES_INCREMENT;
6311 ft_entries = 0;
6312
6313 /* Allocate the initial hunk of the pending_types_list. */
6314
6315 pending_types_list
6316 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
6317 pending_types_allocated = PENDING_TYPES_INCREMENT;
6318 pending_types = 0;
6319
6320 /* Create an artificial RECORD_TYPE node which we can use in our hack
6321 to get the DIEs representing types of formal parameters to come out
6322 only *after* the DIEs for the formal parameters themselves. */
6323
6324 fake_containing_scope = make_node (RECORD_TYPE);
6325
6326 /* Output a starting label for the .text section. */
6327
6328 fputc ('\n', asm_out_file);
6329 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
6330 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
6331 ASM_OUTPUT_POP_SECTION (asm_out_file);
6332
6333 /* Output a starting label for the .data section. */
6334
6335 fputc ('\n', asm_out_file);
6336 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
6337 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
6338 ASM_OUTPUT_POP_SECTION (asm_out_file);
6339
6340 #if 0 /* GNU C doesn't currently use .data1. */
6341 /* Output a starting label for the .data1 section. */
6342
6343 fputc ('\n', asm_out_file);
6344 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
6345 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
6346 ASM_OUTPUT_POP_SECTION (asm_out_file);
6347 #endif
6348
6349 /* Output a starting label for the .rodata section. */
6350
6351 fputc ('\n', asm_out_file);
6352 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
6353 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
6354 ASM_OUTPUT_POP_SECTION (asm_out_file);
6355
6356 #if 0 /* GNU C doesn't currently use .rodata1. */
6357 /* Output a starting label for the .rodata1 section. */
6358
6359 fputc ('\n', asm_out_file);
6360 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
6361 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
6362 ASM_OUTPUT_POP_SECTION (asm_out_file);
6363 #endif
6364
6365 /* Output a starting label for the .bss section. */
6366
6367 fputc ('\n', asm_out_file);
6368 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
6369 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
6370 ASM_OUTPUT_POP_SECTION (asm_out_file);
6371
6372 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6373 {
6374 if (use_gnu_debug_info_extensions)
6375 {
6376 /* Output a starting label and an initial (compilation directory)
6377 entry for the .debug_sfnames section. The starting label will be
6378 referenced by the initial entry in the .debug_srcinfo section. */
6379
6380 fputc ('\n', asm_out_file);
6381 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6382 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
6383 {
6384 register const char *pwd = getpwd ();
6385 register char *dirname;
6386
6387 if (!pwd)
6388 fatal_io_error ("can't get current directory");
6389
6390 dirname = concat (pwd, "/", NULL);
6391 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
6392 free (dirname);
6393 }
6394 ASM_OUTPUT_POP_SECTION (asm_out_file);
6395 }
6396
6397 if (debug_info_level >= DINFO_LEVEL_VERBOSE
6398 && use_gnu_debug_info_extensions)
6399 {
6400 /* Output a starting label for the .debug_macinfo section. This
6401 label will be referenced by the AT_mac_info attribute in the
6402 TAG_compile_unit DIE. */
6403
6404 fputc ('\n', asm_out_file);
6405 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6406 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
6407 ASM_OUTPUT_POP_SECTION (asm_out_file);
6408 }
6409
6410 /* Generate the initial entry for the .line section. */
6411
6412 fputc ('\n', asm_out_file);
6413 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6414 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
6415 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
6416 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6417 ASM_OUTPUT_POP_SECTION (asm_out_file);
6418
6419 if (use_gnu_debug_info_extensions)
6420 {
6421 /* Generate the initial entry for the .debug_srcinfo section. */
6422
6423 fputc ('\n', asm_out_file);
6424 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6425 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
6426 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
6427 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
6428 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6429 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
6430 #ifdef DWARF_TIMESTAMPS
6431 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
6432 #else
6433 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6434 #endif
6435 ASM_OUTPUT_POP_SECTION (asm_out_file);
6436 }
6437
6438 /* Generate the initial entry for the .debug_pubnames section. */
6439
6440 fputc ('\n', asm_out_file);
6441 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6442 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6443 ASM_OUTPUT_POP_SECTION (asm_out_file);
6444
6445 /* Generate the initial entry for the .debug_aranges section. */
6446
6447 fputc ('\n', asm_out_file);
6448 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6449 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6450 DEBUG_ARANGES_END_LABEL,
6451 DEBUG_ARANGES_BEGIN_LABEL);
6452 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_BEGIN_LABEL);
6453 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 1);
6454 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6455 ASM_OUTPUT_POP_SECTION (asm_out_file);
6456 }
6457
6458 /* Setup first DIE number == 1. */
6459 NEXT_DIE_NUM = next_unused_dienum++;
6460
6461 /* Generate the initial DIE for the .debug section. Note that the
6462 (string) value given in the AT_name attribute of the TAG_compile_unit
6463 DIE will (typically) be a relative pathname and that this pathname
6464 should be taken as being relative to the directory from which the
6465 compiler was invoked when the given (base) source file was compiled. */
6466
6467 fputc ('\n', asm_out_file);
6468 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6469 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
6470 output_die (output_compile_unit_die, (PTR) main_input_filename);
6471 ASM_OUTPUT_POP_SECTION (asm_out_file);
6472
6473 fputc ('\n', asm_out_file);
6474 }
6475
6476 /* Output stuff that dwarf requires at the end of every file. */
6477
6478 static void
6479 dwarfout_finish (main_input_filename)
6480 register const char *main_input_filename ATTRIBUTE_UNUSED;
6481 {
6482 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6483
6484 fputc ('\n', asm_out_file);
6485 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6486 retry_incomplete_types ();
6487 fputc ('\n', asm_out_file);
6488
6489 /* Mark the end of the chain of siblings which represent all file-scope
6490 declarations in this compilation unit. */
6491
6492 /* The (null) DIE which represents the terminator for the (sibling linked)
6493 list of file-scope items is *special*. Normally, we would just call
6494 end_sibling_chain at this point in order to output a word with the
6495 value `4' and that word would act as the terminator for the list of
6496 DIEs describing file-scope items. Unfortunately, if we were to simply
6497 do that, the label that would follow this DIE in the .debug section
6498 (i.e. `..D2') would *not* be properly aligned (as it must be on some
6499 machines) to a 4 byte boundary.
6500
6501 In order to force the label `..D2' to get aligned to a 4 byte boundary,
6502 the trick used is to insert extra (otherwise useless) padding bytes
6503 into the (null) DIE that we know must precede the ..D2 label in the
6504 .debug section. The amount of padding required can be anywhere between
6505 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
6506 with the padding) would normally contain the value 4, but now it will
6507 also have to include the padding bytes, so it will instead have some
6508 value in the range 4..7.
6509
6510 Fortunately, the rules of Dwarf say that any DIE whose length word
6511 contains *any* value less than 8 should be treated as a null DIE, so
6512 this trick works out nicely. Clever, eh? Don't give me any credit
6513 (or blame). I didn't think of this scheme. I just conformed to it.
6514 */
6515
6516 output_die (output_padded_null_die, (void *) 0);
6517 dienum_pop ();
6518
6519 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
6520 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
6521 ASM_OUTPUT_POP_SECTION (asm_out_file);
6522
6523 /* Output a terminator label for the .text section. */
6524
6525 fputc ('\n', asm_out_file);
6526 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
6527 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
6528 ASM_OUTPUT_POP_SECTION (asm_out_file);
6529
6530 /* Output a terminator label for the .data section. */
6531
6532 fputc ('\n', asm_out_file);
6533 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
6534 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
6535 ASM_OUTPUT_POP_SECTION (asm_out_file);
6536
6537 #if 0 /* GNU C doesn't currently use .data1. */
6538 /* Output a terminator label for the .data1 section. */
6539
6540 fputc ('\n', asm_out_file);
6541 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
6542 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
6543 ASM_OUTPUT_POP_SECTION (asm_out_file);
6544 #endif
6545
6546 /* Output a terminator label for the .rodata section. */
6547
6548 fputc ('\n', asm_out_file);
6549 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
6550 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
6551 ASM_OUTPUT_POP_SECTION (asm_out_file);
6552
6553 #if 0 /* GNU C doesn't currently use .rodata1. */
6554 /* Output a terminator label for the .rodata1 section. */
6555
6556 fputc ('\n', asm_out_file);
6557 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
6558 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
6559 ASM_OUTPUT_POP_SECTION (asm_out_file);
6560 #endif
6561
6562 /* Output a terminator label for the .bss section. */
6563
6564 fputc ('\n', asm_out_file);
6565 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
6566 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
6567 ASM_OUTPUT_POP_SECTION (asm_out_file);
6568
6569 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6570 {
6571 /* Output a terminating entry for the .line section. */
6572
6573 fputc ('\n', asm_out_file);
6574 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6575 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
6576 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6577 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6578 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6579 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
6580 ASM_OUTPUT_POP_SECTION (asm_out_file);
6581
6582 if (use_gnu_debug_info_extensions)
6583 {
6584 /* Output a terminating entry for the .debug_srcinfo section. */
6585
6586 fputc ('\n', asm_out_file);
6587 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6588 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6589 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6590 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6591 ASM_OUTPUT_POP_SECTION (asm_out_file);
6592 }
6593
6594 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6595 {
6596 /* Output terminating entries for the .debug_macinfo section. */
6597
6598 dwarfout_end_source_file (0);
6599
6600 fputc ('\n', asm_out_file);
6601 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6602 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6603 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6604 ASM_OUTPUT_POP_SECTION (asm_out_file);
6605 }
6606
6607 /* Generate the terminating entry for the .debug_pubnames section. */
6608
6609 fputc ('\n', asm_out_file);
6610 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6611 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6612 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6613 ASM_OUTPUT_POP_SECTION (asm_out_file);
6614
6615 /* Generate the terminating entries for the .debug_aranges section.
6616
6617 Note that we want to do this only *after* we have output the end
6618 labels (for the various program sections) which we are going to
6619 refer to here. This allows us to work around a bug in the m68k
6620 svr4 assembler. That assembler gives bogus assembly-time errors
6621 if (within any given section) you try to take the difference of
6622 two relocatable symbols, both of which are located within some
6623 other section, and if one (or both?) of the symbols involved is
6624 being forward-referenced. By generating the .debug_aranges
6625 entries at this late point in the assembly output, we skirt the
6626 issue simply by avoiding forward-references.
6627 */
6628
6629 fputc ('\n', asm_out_file);
6630 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6631
6632 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6633 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6634
6635 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6636 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6637
6638 #if 0 /* GNU C doesn't currently use .data1. */
6639 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6640 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6641 DATA1_BEGIN_LABEL);
6642 #endif
6643
6644 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6645 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6646 RODATA_BEGIN_LABEL);
6647
6648 #if 0 /* GNU C doesn't currently use .rodata1. */
6649 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6650 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6651 RODATA1_BEGIN_LABEL);
6652 #endif
6653
6654 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6655 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6656
6657 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6658 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6659
6660 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_END_LABEL);
6661 ASM_OUTPUT_POP_SECTION (asm_out_file);
6662 }
6663
6664 /* There should not be any pending types left at the end. We need
6665 this now because it may not have been checked on the last call to
6666 dwarfout_file_scope_decl. */
6667 if (pending_types != 0)
6668 abort ();
6669 }
6670
6671 #endif /* DWARF_DEBUGGING_INFO */