Merge from mainline
[official-gcc.git] / gcc / dwarfout.c
blobc26a018f5005e0f2de40fe9e7fb44ce07195998e
1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 2002,
3 1999, 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
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 ------------------------------------------------------------
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).
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.
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
42 http://www.eagercon.com/dwarf/dwarf2std.htm
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).
50 DWARF 1 generation for the GNU g++ compiler is implemented, but limited.
51 C++ users should definitely use DWARF 2 instead.
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.)
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).
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!)
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).
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.
82 ** IMPORTANT NOTE ** ** IMPORTANT NOTE ** ** IMPORTANT NOTE **
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.
96 ---------
98 (Footnote: Within this file, the term `Debugging Information Entry' will
99 be abbreviated as `DIE'.)
102 Release Notes (aka known bugs)
103 -------------------------------
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.
114 -------------------------------
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).
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.
129 -------------------------------
131 It is believed at this time that old bugs relating to the AT_bit_offset
132 values for bit-fields have been fixed.
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.
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.)
143 --------------------------------
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.)
148 --------------------------------
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).
158 --------------------------------
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.
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".
178 Unfortunately, the GNU DWARF implementation is currently incapable of making
179 such distinctions.
181 --------------------------------
184 Known Interoperability Problems
185 -------------------------------
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.
194 --------------------------------
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.
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.)
210 --------------------------------
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.
219 --------------------------------
222 General GNU DWARF extensions
223 ----------------------------
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.)
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.
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).
249 For each LEC there is one entry in the .debug_srcinfo section.
251 Each normal entry in the .debug_srcinfo section consists of two 4-byte
252 words of data as follows:
254 (1) The starting address (relative to the entire .line section)
255 of the first .line entry in the relevant LEC.
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.)
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.
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.
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.
280 .line section .debug_srcinfo section .debug_sfnames section
281 ----------------------------------------------------------------
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 * -----------------------------------
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).
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.
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:
322 (1) The starting address (relative to the entire .line section)
323 of the .line section for this compilation unit.
325 (2) The starting address (relative to the entire .debug_sfnames
326 section) of the .debug_sfnames section for this compilation
327 unit.
329 (3) The starting address (in the execution virtual address space)
330 of the .text section for this compilation unit.
332 (4) The ending address plus one (in the execution virtual address
333 space) of the .text section for this compilation unit.
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).
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.
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.
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:
370 (1) The offset, measured from the start of the .line section to
371 the beginning of the terminating entry for the .line section.
373 (2) A word containing the value 0xffffffff.
375 --------------------------------
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.
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.
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.)
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:
398 (1) A special "type" byte.
400 (2) A 3-byte line-number/filename-offset field.
402 (3) A NUL terminated string.
404 The interpretation of the second and third parts is dependent upon the
405 value of the leading (type) byte.
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:
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.
416 (Note that the MACINFO_... codes mentioned here are simply symbolic names
417 for constants which are defined in the GNU dwarf.h file.)
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.
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.
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.
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.
446 --------------------------------
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).
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.
468 --------------------------------
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.
476 --------------------------------
479 GNU DWARF Representation of GNU C Extensions to ANSI C
480 ------------------------------------------------------
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.
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.
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.
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.)
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.
512 --------------------------------
515 Future Directions
516 -----------------
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.)
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.
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.
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.
551 In particular, possible link-time transformations of DWARF code which could
552 provide significant benefits include (but are not limited to):
554 Commonization of duplicate DIEs obtained from multiple input
555 (object) files.
557 Cross-compilation type checking based upon DWARF type information
558 for objects and functions.
560 Other possible `compacting' transformations designed to save disk
561 space and to reduce linker & debugger I/O activity.
565 #include "config.h"
567 #ifdef DWARF_DEBUGGING_INFO
568 #include "system.h"
569 #include "dwarf.h"
570 #include "tree.h"
571 #include "flags.h"
572 #include "function.h"
573 #include "rtl.h"
574 #include "hard-reg-set.h"
575 #include "insn-config.h"
576 #include "reload.h"
577 #include "output.h"
578 #include "dwarf2asm.h"
579 #include "toplev.h"
580 #include "tm_p.h"
581 #include "debug.h"
582 #include "langhooks.h"
584 /* NOTE: In the comments in this file, many references are made to
585 so called "Debugging Information Entries". For the sake of brevity,
586 this term is abbreviated to `DIE' throughout the remainder of this
587 file. */
589 /* Note that the implementation of C++ support herein is (as yet) unfinished.
590 If you want to try to complete it, more power to you. */
592 /* How to start an assembler comment. */
593 #ifndef ASM_COMMENT_START
594 #define ASM_COMMENT_START ";#"
595 #endif
597 /* How to print out a register name. */
598 #ifndef PRINT_REG
599 #define PRINT_REG(RTX, CODE, FILE) \
600 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
601 #endif
603 /* Define a macro which returns non-zero for any tagged type which is
604 used (directly or indirectly) in the specification of either some
605 function's return type or some formal parameter of some function.
606 We use this macro when we are operating in "terse" mode to help us
607 know what tagged types have to be represented in Dwarf (even in
608 terse mode) and which ones don't.
610 A flag bit with this meaning really should be a part of the normal
611 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
612 for these nodes. For now, we have to just fake it. It it safe for
613 us to simply return zero for all complete tagged types (which will
614 get forced out anyway if they were used in the specification of some
615 formal or return type) and non-zero for all incomplete tagged types.
618 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
620 /* Define a macro which returns non-zero for a TYPE_DECL which was
621 implicitly generated for a tagged type.
623 Note that unlike the gcc front end (which generates a NULL named
624 TYPE_DECL node for each complete tagged type, each array type, and
625 each function type node created) the g++ front end generates a
626 _named_ TYPE_DECL node for each tagged type node created.
627 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
628 generate a DW_TAG_typedef DIE for them. */
629 #define TYPE_DECL_IS_STUB(decl) \
630 (DECL_NAME (decl) == NULL \
631 || (DECL_ARTIFICIAL (decl) \
632 && is_tagged_type (TREE_TYPE (decl)) \
633 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
635 /* Maximum size (in bytes) of an artificially generated label. */
637 #define MAX_ARTIFICIAL_LABEL_BYTES 30
639 /* Structure to keep track of source filenames. */
641 struct filename_entry {
642 unsigned number;
643 const char * name;
646 typedef struct filename_entry filename_entry;
648 /* Pointer to an array of elements, each one having the structure above. */
650 static filename_entry *filename_table;
652 /* Total number of entries in the table (i.e. array) pointed to by
653 `filename_table'. This is the *total* and includes both used and
654 unused slots. */
656 static unsigned ft_entries_allocated;
658 /* Number of entries in the filename_table which are actually in use. */
660 static unsigned ft_entries;
662 /* Size (in elements) of increments by which we may expand the filename
663 table. Actually, a single hunk of space of this size should be enough
664 for most typical programs. */
666 #define FT_ENTRIES_INCREMENT 64
668 /* Local pointer to the name of the main input file. Initialized in
669 dwarfout_init. */
671 static const char *primary_filename;
673 /* Counter to generate unique names for DIEs. */
675 static unsigned next_unused_dienum = 1;
677 /* Number of the DIE which is currently being generated. */
679 static unsigned current_dienum;
681 /* Number to use for the special "pubname" label on the next DIE which
682 represents a function or data object defined in this compilation
683 unit which has "extern" linkage. */
685 static int next_pubname_number = 0;
687 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
689 /* Pointer to a dynamically allocated list of pre-reserved and still
690 pending sibling DIE numbers. Note that this list will grow as needed. */
692 static unsigned *pending_sibling_stack;
694 /* Counter to keep track of the number of pre-reserved and still pending
695 sibling DIE numbers. */
697 static unsigned pending_siblings;
699 /* The currently allocated size of the above list (expressed in number of
700 list elements). */
702 static unsigned pending_siblings_allocated;
704 /* Size (in elements) of increments by which we may expand the pending
705 sibling stack. Actually, a single hunk of space of this size should
706 be enough for most typical programs. */
708 #define PENDING_SIBLINGS_INCREMENT 64
710 /* Non-zero if we are performing our file-scope finalization pass and if
711 we should force out Dwarf descriptions of any and all file-scope
712 tagged types which are still incomplete types. */
714 static int finalizing = 0;
716 /* A pointer to the base of a list of pending types which we haven't
717 generated DIEs for yet, but which we will have to come back to
718 later on. */
720 static tree *pending_types_list;
722 /* Number of elements currently allocated for the pending_types_list. */
724 static unsigned pending_types_allocated;
726 /* Number of elements of pending_types_list currently in use. */
728 static unsigned pending_types;
730 /* Size (in elements) of increments by which we may expand the pending
731 types list. Actually, a single hunk of space of this size should
732 be enough for most typical programs. */
734 #define PENDING_TYPES_INCREMENT 64
736 /* A pointer to the base of a list of incomplete types which might be
737 completed at some later time. */
739 static tree *incomplete_types_list;
741 /* Number of elements currently allocated for the incomplete_types_list. */
742 static unsigned incomplete_types_allocated;
744 /* Number of elements of incomplete_types_list currently in use. */
745 static unsigned incomplete_types;
747 /* Size (in elements) of increments by which we may expand the incomplete
748 types list. Actually, a single hunk of space of this size should
749 be enough for most typical programs. */
750 #define INCOMPLETE_TYPES_INCREMENT 64
752 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
753 This is used in a hack to help us get the DIEs describing types of
754 formal parameters to come *after* all of the DIEs describing the formal
755 parameters themselves. That's necessary in order to be compatible
756 with what the brain-damaged svr4 SDB debugger requires. */
758 static tree fake_containing_scope;
760 /* A pointer to the ..._DECL node which we have most recently been working
761 on. We keep this around just in case something about it looks screwy
762 and we want to tell the user what the source coordinates for the actual
763 declaration are. */
765 static tree dwarf_last_decl;
767 /* A flag indicating that we are emitting the member declarations of a
768 class, so member functions and variables should not be entirely emitted.
769 This is a kludge to avoid passing a second argument to output_*_die. */
771 static int in_class;
773 /* Forward declarations for functions defined in this file. */
775 static void dwarfout_init PARAMS ((const char *));
776 static void dwarfout_finish PARAMS ((const char *));
777 static void dwarfout_define PARAMS ((unsigned int, const char *));
778 static void dwarfout_undef PARAMS ((unsigned int, const char *));
779 static void dwarfout_start_source_file PARAMS ((unsigned, const char *));
780 static void dwarfout_start_source_file_check PARAMS ((unsigned, const char *));
781 static void dwarfout_end_source_file PARAMS ((unsigned));
782 static void dwarfout_end_source_file_check PARAMS ((unsigned));
783 static void dwarfout_begin_block PARAMS ((unsigned, unsigned));
784 static void dwarfout_end_block PARAMS ((unsigned, unsigned));
785 static void dwarfout_end_epilogue PARAMS ((void));
786 static void dwarfout_source_line PARAMS ((unsigned int, const char *));
787 static void dwarfout_end_prologue PARAMS ((unsigned int));
788 static void dwarfout_end_function PARAMS ((unsigned int));
789 static void dwarfout_function_decl PARAMS ((tree));
790 static void dwarfout_global_decl PARAMS ((tree));
791 static void dwarfout_deferred_inline_function PARAMS ((tree));
792 static void dwarfout_file_scope_decl PARAMS ((tree , int));
793 static const char *dwarf_tag_name PARAMS ((unsigned));
794 static const char *dwarf_attr_name PARAMS ((unsigned));
795 static const char *dwarf_stack_op_name PARAMS ((unsigned));
796 static const char *dwarf_typemod_name PARAMS ((unsigned));
797 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
798 static const char *dwarf_fund_type_name PARAMS ((unsigned));
799 static tree decl_ultimate_origin PARAMS ((tree));
800 static tree block_ultimate_origin PARAMS ((tree));
801 static tree decl_class_context PARAMS ((tree));
802 #if 0
803 static void output_unsigned_leb128 PARAMS ((unsigned long));
804 static void output_signed_leb128 PARAMS ((long));
805 #endif
806 static int fundamental_type_code PARAMS ((tree));
807 static tree root_type_1 PARAMS ((tree, int));
808 static tree root_type PARAMS ((tree));
809 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
810 static void write_modifier_bytes PARAMS ((tree, int, int));
811 static inline int type_is_fundamental PARAMS ((tree));
812 static void equate_decl_number_to_die_number PARAMS ((tree));
813 static inline void equate_type_number_to_die_number PARAMS ((tree));
814 static void output_reg_number PARAMS ((rtx));
815 static void output_mem_loc_descriptor PARAMS ((rtx));
816 static void output_loc_descriptor PARAMS ((rtx));
817 static void output_bound_representation PARAMS ((tree, unsigned, int));
818 static void output_enumeral_list PARAMS ((tree));
819 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
820 static inline tree field_type PARAMS ((tree));
821 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
822 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
823 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
824 static inline void sibling_attribute PARAMS ((void));
825 static void location_attribute PARAMS ((rtx));
826 static void data_member_location_attribute PARAMS ((tree));
827 static void const_value_attribute PARAMS ((rtx));
828 static void location_or_const_value_attribute PARAMS ((tree));
829 static inline void name_attribute PARAMS ((const char *));
830 static inline void fund_type_attribute PARAMS ((unsigned));
831 static void mod_fund_type_attribute PARAMS ((tree, int, int));
832 static inline void user_def_type_attribute PARAMS ((tree));
833 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
834 #ifdef USE_ORDERING_ATTRIBUTE
835 static inline void ordering_attribute PARAMS ((unsigned));
836 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
837 static void subscript_data_attribute PARAMS ((tree));
838 static void byte_size_attribute PARAMS ((tree));
839 static inline void bit_offset_attribute PARAMS ((tree));
840 static inline void bit_size_attribute PARAMS ((tree));
841 static inline void element_list_attribute PARAMS ((tree));
842 static inline void stmt_list_attribute PARAMS ((const char *));
843 static inline void low_pc_attribute PARAMS ((const char *));
844 static inline void high_pc_attribute PARAMS ((const char *));
845 static inline void body_begin_attribute PARAMS ((const char *));
846 static inline void body_end_attribute PARAMS ((const char *));
847 static inline void language_attribute PARAMS ((unsigned));
848 static inline void member_attribute PARAMS ((tree));
849 #if 0
850 static inline void string_length_attribute PARAMS ((tree));
851 #endif
852 static inline void comp_dir_attribute PARAMS ((const char *));
853 static inline void sf_names_attribute PARAMS ((const char *));
854 static inline void src_info_attribute PARAMS ((const char *));
855 static inline void mac_info_attribute PARAMS ((const char *));
856 static inline void prototyped_attribute PARAMS ((tree));
857 static inline void producer_attribute PARAMS ((const char *));
858 static inline void inline_attribute PARAMS ((tree));
859 static inline void containing_type_attribute PARAMS ((tree));
860 static inline void abstract_origin_attribute PARAMS ((tree));
861 #ifdef DWARF_DECL_COORDINATES
862 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
863 #endif /* defined(DWARF_DECL_COORDINATES) */
864 static inline void pure_or_virtual_attribute PARAMS ((tree));
865 static void name_and_src_coords_attributes PARAMS ((tree));
866 static void type_attribute PARAMS ((tree, int, int));
867 static const char *type_tag PARAMS ((tree));
868 static inline void dienum_push PARAMS ((void));
869 static inline void dienum_pop PARAMS ((void));
870 static inline tree member_declared_type PARAMS ((tree));
871 static const char *function_start_label PARAMS ((tree));
872 static void output_array_type_die PARAMS ((void *));
873 static void output_set_type_die PARAMS ((void *));
874 #if 0
875 static void output_entry_point_die PARAMS ((void *));
876 #endif
877 static void output_inlined_enumeration_type_die PARAMS ((void *));
878 static void output_inlined_structure_type_die PARAMS ((void *));
879 static void output_inlined_union_type_die PARAMS ((void *));
880 static void output_enumeration_type_die PARAMS ((void *));
881 static void output_formal_parameter_die PARAMS ((void *));
882 static void output_global_subroutine_die PARAMS ((void *));
883 static void output_global_variable_die PARAMS ((void *));
884 static void output_label_die PARAMS ((void *));
885 static void output_lexical_block_die PARAMS ((void *));
886 static void output_inlined_subroutine_die PARAMS ((void *));
887 static void output_local_variable_die PARAMS ((void *));
888 static void output_member_die PARAMS ((void *));
889 #if 0
890 static void output_pointer_type_die PARAMS ((void *));
891 static void output_reference_type_die PARAMS ((void *));
892 #endif
893 static void output_ptr_to_mbr_type_die PARAMS ((void *));
894 static void output_compile_unit_die PARAMS ((void *));
895 static void output_string_type_die PARAMS ((void *));
896 static void output_inheritance_die PARAMS ((void *));
897 static void output_structure_type_die PARAMS ((void *));
898 static void output_local_subroutine_die PARAMS ((void *));
899 static void output_subroutine_type_die PARAMS ((void *));
900 static void output_typedef_die PARAMS ((void *));
901 static void output_union_type_die PARAMS ((void *));
902 static void output_unspecified_parameters_die PARAMS ((void *));
903 static void output_padded_null_die PARAMS ((void *));
904 static void output_die PARAMS ((void (*)(void *), void *));
905 static void end_sibling_chain PARAMS ((void));
906 static void output_formal_types PARAMS ((tree));
907 static void pend_type PARAMS ((tree));
908 static int type_ok_for_scope PARAMS ((tree, tree));
909 static void output_pending_types_for_scope PARAMS ((tree));
910 static void output_type PARAMS ((tree, tree));
911 static void output_tagged_type_instantiation PARAMS ((tree));
912 static void output_block PARAMS ((tree, int));
913 static void output_decls_for_scope PARAMS ((tree, int));
914 static void output_decl PARAMS ((tree, tree));
915 static void shuffle_filename_entry PARAMS ((filename_entry *));
916 static void generate_new_sfname_entry PARAMS ((void));
917 static unsigned lookup_filename PARAMS ((const char *));
918 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
919 static void generate_macinfo_entry PARAMS ((unsigned int, rtx,
920 const char *));
921 static int is_pseudo_reg PARAMS ((rtx));
922 static tree type_main_variant PARAMS ((tree));
923 static int is_tagged_type PARAMS ((tree));
924 static int is_redundant_typedef PARAMS ((tree));
925 static void add_incomplete_type PARAMS ((tree));
926 static void retry_incomplete_types PARAMS ((void));
928 /* Definitions of defaults for assembler-dependent names of various
929 pseudo-ops and section names.
931 Theses may be overridden in your tm.h file (if necessary) for your
932 particular assembler. The default values provided here correspond to
933 what is expected by "standard" AT&T System V.4 assemblers. */
935 #ifndef FILE_ASM_OP
936 #define FILE_ASM_OP "\t.file\t"
937 #endif
938 #ifndef VERSION_ASM_OP
939 #define VERSION_ASM_OP "\t.version\t"
940 #endif
941 #ifndef SET_ASM_OP
942 #define SET_ASM_OP "\t.set\t"
943 #endif
945 /* Pseudo-ops for pushing the current section onto the section stack (and
946 simultaneously changing to a new section) and for poping back to the
947 section we were in immediately before this one. Note that most svr4
948 assemblers only maintain a one level stack... you can push all the
949 sections you want, but you can only pop out one level. (The sparc
950 svr4 assembler is an exception to this general rule.) That's
951 OK because we only use at most one level of the section stack herein. */
953 #ifndef PUSHSECTION_ASM_OP
954 #define PUSHSECTION_ASM_OP "\t.section\t"
955 #endif
956 #ifndef POPSECTION_ASM_OP
957 #define POPSECTION_ASM_OP "\t.previous"
958 #endif
960 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
961 to print the PUSHSECTION_ASM_OP and the section name. The default here
962 works for almost all svr4 assemblers, except for the sparc, where the
963 section name must be enclosed in double quotes. (See sparcv4.h.) */
965 #ifndef PUSHSECTION_FORMAT
966 #define PUSHSECTION_FORMAT "%s%s\n"
967 #endif
969 #ifndef DEBUG_SECTION
970 #define DEBUG_SECTION ".debug"
971 #endif
972 #ifndef LINE_SECTION
973 #define LINE_SECTION ".line"
974 #endif
975 #ifndef DEBUG_SFNAMES_SECTION
976 #define DEBUG_SFNAMES_SECTION ".debug_sfnames"
977 #endif
978 #ifndef DEBUG_SRCINFO_SECTION
979 #define DEBUG_SRCINFO_SECTION ".debug_srcinfo"
980 #endif
981 #ifndef DEBUG_MACINFO_SECTION
982 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
983 #endif
984 #ifndef DEBUG_PUBNAMES_SECTION
985 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
986 #endif
987 #ifndef DEBUG_ARANGES_SECTION
988 #define DEBUG_ARANGES_SECTION ".debug_aranges"
989 #endif
990 #ifndef TEXT_SECTION_NAME
991 #define TEXT_SECTION_NAME ".text"
992 #endif
993 #ifndef DATA_SECTION_NAME
994 #define DATA_SECTION_NAME ".data"
995 #endif
996 #ifndef DATA1_SECTION_NAME
997 #define DATA1_SECTION_NAME ".data1"
998 #endif
999 #ifndef RODATA_SECTION_NAME
1000 #define RODATA_SECTION_NAME ".rodata"
1001 #endif
1002 #ifndef RODATA1_SECTION_NAME
1003 #define RODATA1_SECTION_NAME ".rodata1"
1004 #endif
1005 #ifndef BSS_SECTION_NAME
1006 #define BSS_SECTION_NAME ".bss"
1007 #endif
1009 /* Definitions of defaults for formats and names of various special
1010 (artificial) labels which may be generated within this file (when
1011 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
1013 If necessary, these may be overridden from within your tm.h file,
1014 but typically, you should never need to override these.
1016 These labels have been hacked (temporarily) so that they all begin with
1017 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
1018 stock m88k/svr4 assembler, both of which need to see .L at the start of
1019 a label in order to prevent that label from going into the linker symbol
1020 table). When I get time, I'll have to fix this the right way so that we
1021 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
1022 but that will require a rather massive set of changes. For the moment,
1023 the following definitions out to produce the right results for all svr4
1024 and svr3 assemblers. -- rfg
1027 #ifndef TEXT_BEGIN_LABEL
1028 #define TEXT_BEGIN_LABEL "*.L_text_b"
1029 #endif
1030 #ifndef TEXT_END_LABEL
1031 #define TEXT_END_LABEL "*.L_text_e"
1032 #endif
1034 #ifndef DATA_BEGIN_LABEL
1035 #define DATA_BEGIN_LABEL "*.L_data_b"
1036 #endif
1037 #ifndef DATA_END_LABEL
1038 #define DATA_END_LABEL "*.L_data_e"
1039 #endif
1041 #ifndef DATA1_BEGIN_LABEL
1042 #define DATA1_BEGIN_LABEL "*.L_data1_b"
1043 #endif
1044 #ifndef DATA1_END_LABEL
1045 #define DATA1_END_LABEL "*.L_data1_e"
1046 #endif
1048 #ifndef RODATA_BEGIN_LABEL
1049 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
1050 #endif
1051 #ifndef RODATA_END_LABEL
1052 #define RODATA_END_LABEL "*.L_rodata_e"
1053 #endif
1055 #ifndef RODATA1_BEGIN_LABEL
1056 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
1057 #endif
1058 #ifndef RODATA1_END_LABEL
1059 #define RODATA1_END_LABEL "*.L_rodata1_e"
1060 #endif
1062 #ifndef BSS_BEGIN_LABEL
1063 #define BSS_BEGIN_LABEL "*.L_bss_b"
1064 #endif
1065 #ifndef BSS_END_LABEL
1066 #define BSS_END_LABEL "*.L_bss_e"
1067 #endif
1069 #ifndef LINE_BEGIN_LABEL
1070 #define LINE_BEGIN_LABEL "*.L_line_b"
1071 #endif
1072 #ifndef LINE_LAST_ENTRY_LABEL
1073 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
1074 #endif
1075 #ifndef LINE_END_LABEL
1076 #define LINE_END_LABEL "*.L_line_e"
1077 #endif
1079 #ifndef DEBUG_BEGIN_LABEL
1080 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
1081 #endif
1082 #ifndef SFNAMES_BEGIN_LABEL
1083 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
1084 #endif
1085 #ifndef SRCINFO_BEGIN_LABEL
1086 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
1087 #endif
1088 #ifndef MACINFO_BEGIN_LABEL
1089 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
1090 #endif
1092 #ifndef DEBUG_ARANGES_BEGIN_LABEL
1093 #define DEBUG_ARANGES_BEGIN_LABEL "*.L_debug_aranges_begin"
1094 #endif
1095 #ifndef DEBUG_ARANGES_END_LABEL
1096 #define DEBUG_ARANGES_END_LABEL "*.L_debug_aranges_end"
1097 #endif
1099 #ifndef DIE_BEGIN_LABEL_FMT
1100 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
1101 #endif
1102 #ifndef DIE_END_LABEL_FMT
1103 #define DIE_END_LABEL_FMT "*.L_D%u_e"
1104 #endif
1105 #ifndef PUB_DIE_LABEL_FMT
1106 #define PUB_DIE_LABEL_FMT "*.L_P%u"
1107 #endif
1108 #ifndef BLOCK_BEGIN_LABEL_FMT
1109 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
1110 #endif
1111 #ifndef BLOCK_END_LABEL_FMT
1112 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
1113 #endif
1114 #ifndef SS_BEGIN_LABEL_FMT
1115 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
1116 #endif
1117 #ifndef SS_END_LABEL_FMT
1118 #define SS_END_LABEL_FMT "*.L_s%u_e"
1119 #endif
1120 #ifndef EE_BEGIN_LABEL_FMT
1121 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
1122 #endif
1123 #ifndef EE_END_LABEL_FMT
1124 #define EE_END_LABEL_FMT "*.L_e%u_e"
1125 #endif
1126 #ifndef MT_BEGIN_LABEL_FMT
1127 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
1128 #endif
1129 #ifndef MT_END_LABEL_FMT
1130 #define MT_END_LABEL_FMT "*.L_t%u_e"
1131 #endif
1132 #ifndef LOC_BEGIN_LABEL_FMT
1133 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
1134 #endif
1135 #ifndef LOC_END_LABEL_FMT
1136 #define LOC_END_LABEL_FMT "*.L_l%u_e"
1137 #endif
1138 #ifndef BOUND_BEGIN_LABEL_FMT
1139 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
1140 #endif
1141 #ifndef BOUND_END_LABEL_FMT
1142 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
1143 #endif
1144 #ifndef DERIV_BEGIN_LABEL_FMT
1145 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
1146 #endif
1147 #ifndef DERIV_END_LABEL_FMT
1148 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
1149 #endif
1150 #ifndef SL_BEGIN_LABEL_FMT
1151 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
1152 #endif
1153 #ifndef SL_END_LABEL_FMT
1154 #define SL_END_LABEL_FMT "*.L_sl%u_e"
1155 #endif
1156 #ifndef BODY_BEGIN_LABEL_FMT
1157 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
1158 #endif
1159 #ifndef BODY_END_LABEL_FMT
1160 #define BODY_END_LABEL_FMT "*.L_b%u_e"
1161 #endif
1162 #ifndef FUNC_END_LABEL_FMT
1163 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
1164 #endif
1165 #ifndef TYPE_NAME_FMT
1166 #define TYPE_NAME_FMT "*.L_T%u"
1167 #endif
1168 #ifndef DECL_NAME_FMT
1169 #define DECL_NAME_FMT "*.L_E%u"
1170 #endif
1171 #ifndef LINE_CODE_LABEL_FMT
1172 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
1173 #endif
1174 #ifndef SFNAMES_ENTRY_LABEL_FMT
1175 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
1176 #endif
1177 #ifndef LINE_ENTRY_LABEL_FMT
1178 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
1179 #endif
1181 /* Definitions of defaults for various types of primitive assembly language
1182 output operations.
1184 If necessary, these may be overridden from within your tm.h file,
1185 but typically, you shouldn't need to override these. */
1187 #ifndef ASM_OUTPUT_PUSH_SECTION
1188 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
1189 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
1190 #endif
1192 #ifndef ASM_OUTPUT_POP_SECTION
1193 #define ASM_OUTPUT_POP_SECTION(FILE) \
1194 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
1195 #endif
1197 #ifndef ASM_OUTPUT_DWARF_DELTA2
1198 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
1199 dw2_asm_output_delta (2, LABEL1, LABEL2, NULL)
1200 #endif
1202 #ifndef ASM_OUTPUT_DWARF_DELTA4
1203 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
1204 dw2_asm_output_delta (4, LABEL1, LABEL2, NULL)
1205 #endif
1207 #ifndef ASM_OUTPUT_DWARF_TAG
1208 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
1209 dw2_asm_output_data (2, TAG, "%s", dwarf_tag_name (TAG));
1210 #endif
1212 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
1213 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
1214 dw2_asm_output_data (2, ATTR, "%s", dwarf_attr_name (ATTR))
1215 #endif
1217 #ifndef ASM_OUTPUT_DWARF_STACK_OP
1218 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
1219 dw2_asm_output_data (1, OP, "%s", dwarf_stack_op_name (OP))
1220 #endif
1222 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
1223 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
1224 dw2_asm_output_data (2, FT, "%s", dwarf_fund_type_name (FT))
1225 #endif
1227 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
1228 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
1229 dw2_asm_output_data (1, FMT, "%s", dwarf_fmt_byte_name (FMT));
1230 #endif
1232 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
1233 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
1234 dw2_asm_output_data (1, MOD, "%s", dwarf_typemod_name (MOD));
1235 #endif
1237 #ifndef ASM_OUTPUT_DWARF_ADDR
1238 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
1239 dw2_asm_output_addr (4, LABEL, NULL)
1240 #endif
1242 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
1243 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
1244 dw2_asm_output_addr_rtx (4, RTX, NULL)
1245 #endif
1247 #ifndef ASM_OUTPUT_DWARF_REF
1248 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
1249 dw2_asm_output_addr (4, LABEL, NULL)
1250 #endif
1252 #ifndef ASM_OUTPUT_DWARF_DATA1
1253 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
1254 dw2_asm_output_data (1, VALUE, NULL)
1255 #endif
1257 #ifndef ASM_OUTPUT_DWARF_DATA2
1258 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
1259 dw2_asm_output_data (2, VALUE, NULL)
1260 #endif
1262 #ifndef ASM_OUTPUT_DWARF_DATA4
1263 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
1264 dw2_asm_output_data (4, VALUE, NULL)
1265 #endif
1267 #ifndef ASM_OUTPUT_DWARF_DATA8
1268 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
1269 dw2_asm_output_data (8, VALUE, NULL)
1270 #endif
1272 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
1273 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
1274 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
1275 defined, we call it, then issue the line feed. If not, we supply a
1276 default definition of calling ASM_OUTPUT_ASCII */
1278 #ifndef ASM_OUTPUT_DWARF_STRING
1279 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1280 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
1281 #else
1282 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1283 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
1284 #endif
1287 /* The debug hooks structure. */
1288 const struct gcc_debug_hooks dwarf_debug_hooks =
1290 dwarfout_init,
1291 dwarfout_finish,
1292 dwarfout_define,
1293 dwarfout_undef,
1294 dwarfout_start_source_file_check,
1295 dwarfout_end_source_file_check,
1296 dwarfout_begin_block,
1297 dwarfout_end_block,
1298 debug_true_tree, /* ignore_block */
1299 dwarfout_source_line, /* source_line */
1300 dwarfout_source_line, /* begin_prologue */
1301 dwarfout_end_prologue,
1302 dwarfout_end_epilogue,
1303 debug_nothing_tree, /* begin_function */
1304 dwarfout_end_function,
1305 dwarfout_function_decl,
1306 dwarfout_global_decl,
1307 dwarfout_deferred_inline_function,
1308 debug_nothing_tree, /* outlining_inline_function */
1309 debug_nothing_rtx /* label */
1312 /************************ general utility functions **************************/
1314 static inline int
1315 is_pseudo_reg (rtl)
1316 rtx rtl;
1318 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1319 || ((GET_CODE (rtl) == SUBREG)
1320 && (REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)));
1323 static inline tree
1324 type_main_variant (type)
1325 tree type;
1327 type = TYPE_MAIN_VARIANT (type);
1329 /* There really should be only one main variant among any group of variants
1330 of a given type (and all of the MAIN_VARIANT values for all members of
1331 the group should point to that one type) but sometimes the C front-end
1332 messes this up for array types, so we work around that bug here. */
1334 if (TREE_CODE (type) == ARRAY_TYPE)
1336 while (type != TYPE_MAIN_VARIANT (type))
1337 type = TYPE_MAIN_VARIANT (type);
1340 return type;
1343 /* Return non-zero if the given type node represents a tagged type. */
1345 static inline int
1346 is_tagged_type (type)
1347 tree type;
1349 enum tree_code code = TREE_CODE (type);
1351 return (code == RECORD_TYPE || code == UNION_TYPE
1352 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1355 static const char *
1356 dwarf_tag_name (tag)
1357 unsigned tag;
1359 switch (tag)
1361 case TAG_padding: return "TAG_padding";
1362 case TAG_array_type: return "TAG_array_type";
1363 case TAG_class_type: return "TAG_class_type";
1364 case TAG_entry_point: return "TAG_entry_point";
1365 case TAG_enumeration_type: return "TAG_enumeration_type";
1366 case TAG_formal_parameter: return "TAG_formal_parameter";
1367 case TAG_global_subroutine: return "TAG_global_subroutine";
1368 case TAG_global_variable: return "TAG_global_variable";
1369 case TAG_label: return "TAG_label";
1370 case TAG_lexical_block: return "TAG_lexical_block";
1371 case TAG_local_variable: return "TAG_local_variable";
1372 case TAG_member: return "TAG_member";
1373 case TAG_pointer_type: return "TAG_pointer_type";
1374 case TAG_reference_type: return "TAG_reference_type";
1375 case TAG_compile_unit: return "TAG_compile_unit";
1376 case TAG_string_type: return "TAG_string_type";
1377 case TAG_structure_type: return "TAG_structure_type";
1378 case TAG_subroutine: return "TAG_subroutine";
1379 case TAG_subroutine_type: return "TAG_subroutine_type";
1380 case TAG_typedef: return "TAG_typedef";
1381 case TAG_union_type: return "TAG_union_type";
1382 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
1383 case TAG_variant: return "TAG_variant";
1384 case TAG_common_block: return "TAG_common_block";
1385 case TAG_common_inclusion: return "TAG_common_inclusion";
1386 case TAG_inheritance: return "TAG_inheritance";
1387 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
1388 case TAG_module: return "TAG_module";
1389 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
1390 case TAG_set_type: return "TAG_set_type";
1391 case TAG_subrange_type: return "TAG_subrange_type";
1392 case TAG_with_stmt: return "TAG_with_stmt";
1394 /* GNU extensions. */
1396 case TAG_format_label: return "TAG_format_label";
1397 case TAG_namelist: return "TAG_namelist";
1398 case TAG_function_template: return "TAG_function_template";
1399 case TAG_class_template: return "TAG_class_template";
1401 default: return "TAG_<unknown>";
1405 static const char *
1406 dwarf_attr_name (attr)
1407 unsigned attr;
1409 switch (attr)
1411 case AT_sibling: return "AT_sibling";
1412 case AT_location: return "AT_location";
1413 case AT_name: return "AT_name";
1414 case AT_fund_type: return "AT_fund_type";
1415 case AT_mod_fund_type: return "AT_mod_fund_type";
1416 case AT_user_def_type: return "AT_user_def_type";
1417 case AT_mod_u_d_type: return "AT_mod_u_d_type";
1418 case AT_ordering: return "AT_ordering";
1419 case AT_subscr_data: return "AT_subscr_data";
1420 case AT_byte_size: return "AT_byte_size";
1421 case AT_bit_offset: return "AT_bit_offset";
1422 case AT_bit_size: return "AT_bit_size";
1423 case AT_element_list: return "AT_element_list";
1424 case AT_stmt_list: return "AT_stmt_list";
1425 case AT_low_pc: return "AT_low_pc";
1426 case AT_high_pc: return "AT_high_pc";
1427 case AT_language: return "AT_language";
1428 case AT_member: return "AT_member";
1429 case AT_discr: return "AT_discr";
1430 case AT_discr_value: return "AT_discr_value";
1431 case AT_string_length: return "AT_string_length";
1432 case AT_common_reference: return "AT_common_reference";
1433 case AT_comp_dir: return "AT_comp_dir";
1434 case AT_const_value_string: return "AT_const_value_string";
1435 case AT_const_value_data2: return "AT_const_value_data2";
1436 case AT_const_value_data4: return "AT_const_value_data4";
1437 case AT_const_value_data8: return "AT_const_value_data8";
1438 case AT_const_value_block2: return "AT_const_value_block2";
1439 case AT_const_value_block4: return "AT_const_value_block4";
1440 case AT_containing_type: return "AT_containing_type";
1441 case AT_default_value_addr: return "AT_default_value_addr";
1442 case AT_default_value_data2: return "AT_default_value_data2";
1443 case AT_default_value_data4: return "AT_default_value_data4";
1444 case AT_default_value_data8: return "AT_default_value_data8";
1445 case AT_default_value_string: return "AT_default_value_string";
1446 case AT_friends: return "AT_friends";
1447 case AT_inline: return "AT_inline";
1448 case AT_is_optional: return "AT_is_optional";
1449 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1450 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1451 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1452 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1453 case AT_private: return "AT_private";
1454 case AT_producer: return "AT_producer";
1455 case AT_program: return "AT_program";
1456 case AT_protected: return "AT_protected";
1457 case AT_prototyped: return "AT_prototyped";
1458 case AT_public: return "AT_public";
1459 case AT_pure_virtual: return "AT_pure_virtual";
1460 case AT_return_addr: return "AT_return_addr";
1461 case AT_abstract_origin: return "AT_abstract_origin";
1462 case AT_start_scope: return "AT_start_scope";
1463 case AT_stride_size: return "AT_stride_size";
1464 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1465 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1466 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1467 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1468 case AT_virtual: return "AT_virtual";
1470 /* GNU extensions */
1472 case AT_sf_names: return "AT_sf_names";
1473 case AT_src_info: return "AT_src_info";
1474 case AT_mac_info: return "AT_mac_info";
1475 case AT_src_coords: return "AT_src_coords";
1476 case AT_body_begin: return "AT_body_begin";
1477 case AT_body_end: return "AT_body_end";
1479 default: return "AT_<unknown>";
1483 static const char *
1484 dwarf_stack_op_name (op)
1485 unsigned op;
1487 switch (op)
1489 case OP_REG: return "OP_REG";
1490 case OP_BASEREG: return "OP_BASEREG";
1491 case OP_ADDR: return "OP_ADDR";
1492 case OP_CONST: return "OP_CONST";
1493 case OP_DEREF2: return "OP_DEREF2";
1494 case OP_DEREF4: return "OP_DEREF4";
1495 case OP_ADD: return "OP_ADD";
1496 default: return "OP_<unknown>";
1500 static const char *
1501 dwarf_typemod_name (mod)
1502 unsigned mod;
1504 switch (mod)
1506 case MOD_pointer_to: return "MOD_pointer_to";
1507 case MOD_reference_to: return "MOD_reference_to";
1508 case MOD_const: return "MOD_const";
1509 case MOD_volatile: return "MOD_volatile";
1510 default: return "MOD_<unknown>";
1514 static const char *
1515 dwarf_fmt_byte_name (fmt)
1516 unsigned fmt;
1518 switch (fmt)
1520 case FMT_FT_C_C: return "FMT_FT_C_C";
1521 case FMT_FT_C_X: return "FMT_FT_C_X";
1522 case FMT_FT_X_C: return "FMT_FT_X_C";
1523 case FMT_FT_X_X: return "FMT_FT_X_X";
1524 case FMT_UT_C_C: return "FMT_UT_C_C";
1525 case FMT_UT_C_X: return "FMT_UT_C_X";
1526 case FMT_UT_X_C: return "FMT_UT_X_C";
1527 case FMT_UT_X_X: return "FMT_UT_X_X";
1528 case FMT_ET: return "FMT_ET";
1529 default: return "FMT_<unknown>";
1533 static const char *
1534 dwarf_fund_type_name (ft)
1535 unsigned ft;
1537 switch (ft)
1539 case FT_char: return "FT_char";
1540 case FT_signed_char: return "FT_signed_char";
1541 case FT_unsigned_char: return "FT_unsigned_char";
1542 case FT_short: return "FT_short";
1543 case FT_signed_short: return "FT_signed_short";
1544 case FT_unsigned_short: return "FT_unsigned_short";
1545 case FT_integer: return "FT_integer";
1546 case FT_signed_integer: return "FT_signed_integer";
1547 case FT_unsigned_integer: return "FT_unsigned_integer";
1548 case FT_long: return "FT_long";
1549 case FT_signed_long: return "FT_signed_long";
1550 case FT_unsigned_long: return "FT_unsigned_long";
1551 case FT_pointer: return "FT_pointer";
1552 case FT_float: return "FT_float";
1553 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1554 case FT_ext_prec_float: return "FT_ext_prec_float";
1555 case FT_complex: return "FT_complex";
1556 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1557 case FT_void: return "FT_void";
1558 case FT_boolean: return "FT_boolean";
1559 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1560 case FT_label: return "FT_label";
1562 /* GNU extensions. */
1564 case FT_long_long: return "FT_long_long";
1565 case FT_signed_long_long: return "FT_signed_long_long";
1566 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1568 case FT_int8: return "FT_int8";
1569 case FT_signed_int8: return "FT_signed_int8";
1570 case FT_unsigned_int8: return "FT_unsigned_int8";
1571 case FT_int16: return "FT_int16";
1572 case FT_signed_int16: return "FT_signed_int16";
1573 case FT_unsigned_int16: return "FT_unsigned_int16";
1574 case FT_int32: return "FT_int32";
1575 case FT_signed_int32: return "FT_signed_int32";
1576 case FT_unsigned_int32: return "FT_unsigned_int32";
1577 case FT_int64: return "FT_int64";
1578 case FT_signed_int64: return "FT_signed_int64";
1579 case FT_unsigned_int64: return "FT_unsigned_int64";
1580 case FT_int128: return "FT_int128";
1581 case FT_signed_int128: return "FT_signed_int128";
1582 case FT_unsigned_int128: return "FT_unsigned_int128";
1584 case FT_real32: return "FT_real32";
1585 case FT_real64: return "FT_real64";
1586 case FT_real96: return "FT_real96";
1587 case FT_real128: return "FT_real128";
1589 default: return "FT_<unknown>";
1593 /* Determine the "ultimate origin" of a decl. The decl may be an
1594 inlined instance of an inlined instance of a decl which is local
1595 to an inline function, so we have to trace all of the way back
1596 through the origin chain to find out what sort of node actually
1597 served as the original seed for the given block. */
1599 static tree
1600 decl_ultimate_origin (decl)
1601 tree decl;
1603 #ifdef ENABLE_CHECKING
1604 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1605 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1606 most distant ancestor, this should never happen. */
1607 abort ();
1608 #endif
1610 return DECL_ABSTRACT_ORIGIN (decl);
1613 /* Determine the "ultimate origin" of a block. The block may be an
1614 inlined instance of an inlined instance of a block which is local
1615 to an inline function, so we have to trace all of the way back
1616 through the origin chain to find out what sort of node actually
1617 served as the original seed for the given block. */
1619 static tree
1620 block_ultimate_origin (block)
1621 tree block;
1623 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1625 if (immediate_origin == NULL)
1626 return NULL;
1627 else
1629 tree ret_val;
1630 tree lookahead = immediate_origin;
1634 ret_val = lookahead;
1635 lookahead = (TREE_CODE (ret_val) == BLOCK)
1636 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1637 : NULL;
1639 while (lookahead != NULL && lookahead != ret_val);
1640 return ret_val;
1644 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1645 of a virtual function may refer to a base class, so we check the 'this'
1646 parameter. */
1648 static tree
1649 decl_class_context (decl)
1650 tree decl;
1652 tree context = NULL_TREE;
1653 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1654 context = DECL_CONTEXT (decl);
1655 else
1656 context = TYPE_MAIN_VARIANT
1657 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1659 if (context && !TYPE_P (context))
1660 context = NULL_TREE;
1662 return context;
1665 #if 0
1666 static void
1667 output_unsigned_leb128 (value)
1668 unsigned long value;
1670 unsigned long orig_value = value;
1674 unsigned byte = (value & 0x7f);
1676 value >>= 7;
1677 if (value != 0) /* more bytes to follow */
1678 byte |= 0x80;
1679 dw2_asm_output_data (1, byte, "\t%s ULEB128 number - value = %lu",
1680 orig_value);
1682 while (value != 0);
1685 static void
1686 output_signed_leb128 (value)
1687 long value;
1689 long orig_value = value;
1690 int negative = (value < 0);
1691 int more;
1695 unsigned byte = (value & 0x7f);
1697 value >>= 7;
1698 if (negative)
1699 value |= 0xfe000000; /* manually sign extend */
1700 if (((value == 0) && ((byte & 0x40) == 0))
1701 || ((value == -1) && ((byte & 0x40) == 1)))
1702 more = 0;
1703 else
1705 byte |= 0x80;
1706 more = 1;
1708 dw2_asm_output_data (1, byte, "\t%s SLEB128 number - value = %ld",
1709 orig_value);
1711 while (more);
1713 #endif
1715 /**************** utility functions for attribute functions ******************/
1717 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1718 type code for the given type.
1720 This routine must only be called for GCC type nodes that correspond to
1721 Dwarf fundamental types.
1723 The current Dwarf draft specification calls for Dwarf fundamental types
1724 to accurately reflect the fact that a given type was either a "plain"
1725 integral type or an explicitly "signed" integral type. Unfortunately,
1726 we can't always do this, because GCC may already have thrown away the
1727 information about the precise way in which the type was originally
1728 specified, as in:
1730 typedef signed int my_type;
1732 struct s { my_type f; };
1734 Since we may be stuck here without enough information to do exactly
1735 what is called for in the Dwarf draft specification, we do the best
1736 that we can under the circumstances and always use the "plain" integral
1737 fundamental type codes for int, short, and long types. That's probably
1738 good enough. The additional accuracy called for in the current DWARF
1739 draft specification is probably never even useful in practice. */
1741 static int
1742 fundamental_type_code (type)
1743 tree type;
1745 if (TREE_CODE (type) == ERROR_MARK)
1746 return 0;
1748 switch (TREE_CODE (type))
1750 case ERROR_MARK:
1751 return FT_void;
1753 case VOID_TYPE:
1754 return FT_void;
1756 case INTEGER_TYPE:
1757 /* Carefully distinguish all the standard types of C,
1758 without messing up if the language is not C.
1759 Note that we check only for the names that contain spaces;
1760 other names might occur by coincidence in other languages. */
1761 if (TYPE_NAME (type) != 0
1762 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1763 && DECL_NAME (TYPE_NAME (type)) != 0
1764 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1766 const char *const name =
1767 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1769 if (!strcmp (name, "unsigned char"))
1770 return FT_unsigned_char;
1771 if (!strcmp (name, "signed char"))
1772 return FT_signed_char;
1773 if (!strcmp (name, "unsigned int"))
1774 return FT_unsigned_integer;
1775 if (!strcmp (name, "short int"))
1776 return FT_short;
1777 if (!strcmp (name, "short unsigned int"))
1778 return FT_unsigned_short;
1779 if (!strcmp (name, "long int"))
1780 return FT_long;
1781 if (!strcmp (name, "long unsigned int"))
1782 return FT_unsigned_long;
1783 if (!strcmp (name, "long long int"))
1784 return FT_long_long; /* Not grok'ed by svr4 SDB */
1785 if (!strcmp (name, "long long unsigned int"))
1786 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1789 /* Most integer types will be sorted out above, however, for the
1790 sake of special `array index' integer types, the following code
1791 is also provided. */
1793 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1794 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1796 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1797 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1799 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1800 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1802 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1803 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1805 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1806 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1808 if (TYPE_MODE (type) == TImode)
1809 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1811 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1812 if (TYPE_PRECISION (type) == 1)
1813 return FT_boolean;
1815 abort ();
1817 case REAL_TYPE:
1818 /* Carefully distinguish all the standard types of C,
1819 without messing up if the language is not C. */
1820 if (TYPE_NAME (type) != 0
1821 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1822 && DECL_NAME (TYPE_NAME (type)) != 0
1823 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1825 const char *const name =
1826 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1828 /* Note that here we can run afoul of a serious bug in "classic"
1829 svr4 SDB debuggers. They don't seem to understand the
1830 FT_ext_prec_float type (even though they should). */
1832 if (!strcmp (name, "long double"))
1833 return FT_ext_prec_float;
1836 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1838 /* On the SH, when compiling with -m3e or -m4-single-only, both
1839 float and double are 32 bits. But since the debugger doesn't
1840 know about the subtarget, it always thinks double is 64 bits.
1841 So we have to tell the debugger that the type is float to
1842 make the output of the 'print' command etc. readable. */
1843 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1844 return FT_float;
1845 return FT_dbl_prec_float;
1847 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1848 return FT_float;
1850 /* Note that here we can run afoul of a serious bug in "classic"
1851 svr4 SDB debuggers. They don't seem to understand the
1852 FT_ext_prec_float type (even though they should). */
1854 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1855 return FT_ext_prec_float;
1856 abort ();
1858 case COMPLEX_TYPE:
1859 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1861 case CHAR_TYPE:
1862 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1864 case BOOLEAN_TYPE:
1865 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1867 default:
1868 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1870 return 0;
1873 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1874 the Dwarf "root" type for the given input type. The Dwarf "root" type
1875 of a given type is generally the same as the given type, except that if
1876 the given type is a pointer or reference type, then the root type of
1877 the given type is the root type of the "basis" type for the pointer or
1878 reference type. (This definition of the "root" type is recursive.)
1879 Also, the root type of a `const' qualified type or a `volatile'
1880 qualified type is the root type of the given type without the
1881 qualifiers. */
1883 static tree
1884 root_type_1 (type, count)
1885 tree type;
1886 int count;
1888 /* Give up after searching 1000 levels, in case this is a recursive
1889 pointer type. Such types are possible in Ada, but it is not possible
1890 to represent them in DWARF1 debug info. */
1891 if (count > 1000)
1892 return error_mark_node;
1894 switch (TREE_CODE (type))
1896 case ERROR_MARK:
1897 return error_mark_node;
1899 case POINTER_TYPE:
1900 case REFERENCE_TYPE:
1901 return root_type_1 (TREE_TYPE (type), count+1);
1903 default:
1904 return type;
1908 static tree
1909 root_type (type)
1910 tree type;
1912 type = root_type_1 (type, 0);
1913 if (type != error_mark_node)
1914 type = type_main_variant (type);
1915 return type;
1918 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1919 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1921 static void
1922 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1923 tree type;
1924 int decl_const;
1925 int decl_volatile;
1926 int count;
1928 if (TREE_CODE (type) == ERROR_MARK)
1929 return;
1931 /* Give up after searching 1000 levels, in case this is a recursive
1932 pointer type. Such types are possible in Ada, but it is not possible
1933 to represent them in DWARF1 debug info. */
1934 if (count > 1000)
1935 return;
1937 if (TYPE_READONLY (type) || decl_const)
1938 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1939 if (TYPE_VOLATILE (type) || decl_volatile)
1940 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1941 switch (TREE_CODE (type))
1943 case POINTER_TYPE:
1944 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1945 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1946 return;
1948 case REFERENCE_TYPE:
1949 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1950 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1951 return;
1953 case ERROR_MARK:
1954 default:
1955 return;
1959 static void
1960 write_modifier_bytes (type, decl_const, decl_volatile)
1961 tree type;
1962 int decl_const;
1963 int decl_volatile;
1965 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1968 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1969 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1971 static inline int
1972 type_is_fundamental (type)
1973 tree type;
1975 switch (TREE_CODE (type))
1977 case ERROR_MARK:
1978 case VOID_TYPE:
1979 case INTEGER_TYPE:
1980 case REAL_TYPE:
1981 case COMPLEX_TYPE:
1982 case BOOLEAN_TYPE:
1983 case CHAR_TYPE:
1984 return 1;
1986 case SET_TYPE:
1987 case ARRAY_TYPE:
1988 case RECORD_TYPE:
1989 case UNION_TYPE:
1990 case QUAL_UNION_TYPE:
1991 case ENUMERAL_TYPE:
1992 case FUNCTION_TYPE:
1993 case METHOD_TYPE:
1994 case POINTER_TYPE:
1995 case REFERENCE_TYPE:
1996 case FILE_TYPE:
1997 case OFFSET_TYPE:
1998 case LANG_TYPE:
1999 case VECTOR_TYPE:
2000 return 0;
2002 default:
2003 abort ();
2005 return 0;
2008 /* Given a pointer to some ..._DECL tree node, generate an assembly language
2009 equate directive which will associate a symbolic name with the current DIE.
2011 The name used is an artificial label generated from the DECL_UID number
2012 associated with the given decl node. The name it gets equated to is the
2013 symbolic label that we (previously) output at the start of the DIE that
2014 we are currently generating.
2016 Calling this function while generating some "decl related" form of DIE
2017 makes it possible to later refer to the DIE which represents the given
2018 decl simply by re-generating the symbolic name from the ..._DECL node's
2019 UID number. */
2021 static void
2022 equate_decl_number_to_die_number (decl)
2023 tree decl;
2025 /* In the case where we are generating a DIE for some ..._DECL node
2026 which represents either some inline function declaration or some
2027 entity declared within an inline function declaration/definition,
2028 setup a symbolic name for the current DIE so that we have a name
2029 for this DIE that we can easily refer to later on within
2030 AT_abstract_origin attributes. */
2032 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
2033 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2035 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
2036 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2037 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
2040 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
2041 equate directive which will associate a symbolic name with the current DIE.
2043 The name used is an artificial label generated from the TYPE_UID number
2044 associated with the given type node. The name it gets equated to is the
2045 symbolic label that we (previously) output at the start of the DIE that
2046 we are currently generating.
2048 Calling this function while generating some "type related" form of DIE
2049 makes it easy to later refer to the DIE which represents the given type
2050 simply by re-generating the alternative name from the ..._TYPE node's
2051 UID number. */
2053 static inline void
2054 equate_type_number_to_die_number (type)
2055 tree type;
2057 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
2058 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2060 /* We are generating a DIE to represent the main variant of this type
2061 (i.e the type without any const or volatile qualifiers) so in order
2062 to get the equate to come out right, we need to get the main variant
2063 itself here. */
2065 type = type_main_variant (type);
2067 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
2068 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2069 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
2072 static void
2073 output_reg_number (rtl)
2074 rtx rtl;
2076 unsigned regno = REGNO (rtl);
2078 if (regno >= DWARF_FRAME_REGISTERS)
2080 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
2081 regno);
2082 regno = 0;
2084 dw2_assemble_integer (4, GEN_INT (DBX_REGISTER_NUMBER (regno)));
2085 if (flag_debug_asm)
2087 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
2088 PRINT_REG (rtl, 0, asm_out_file);
2090 fputc ('\n', asm_out_file);
2093 /* The following routine is a nice and simple transducer. It converts the
2094 RTL for a variable or parameter (resident in memory) into an equivalent
2095 Dwarf representation of a mechanism for getting the address of that same
2096 variable onto the top of a hypothetical "address evaluation" stack.
2098 When creating memory location descriptors, we are effectively trans-
2099 forming the RTL for a memory-resident object into its Dwarf postfix
2100 expression equivalent. This routine just recursively descends an
2101 RTL tree, turning it into Dwarf postfix code as it goes. */
2103 static void
2104 output_mem_loc_descriptor (rtl)
2105 rtx rtl;
2107 /* Note that for a dynamically sized array, the location we will
2108 generate a description of here will be the lowest numbered location
2109 which is actually within the array. That's *not* necessarily the
2110 same as the zeroth element of the array. */
2112 #ifdef ASM_SIMPLIFY_DWARF_ADDR
2113 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
2114 #endif
2116 switch (GET_CODE (rtl))
2118 case SUBREG:
2120 /* The case of a subreg may arise when we have a local (register)
2121 variable or a formal (register) parameter which doesn't quite
2122 fill up an entire register. For now, just assume that it is
2123 legitimate to make the Dwarf info refer to the whole register
2124 which contains the given subreg. */
2126 rtl = SUBREG_REG (rtl);
2127 /* Drop thru. */
2129 case REG:
2131 /* Whenever a register number forms a part of the description of
2132 the method for calculating the (dynamic) address of a memory
2133 resident object, DWARF rules require the register number to
2134 be referred to as a "base register". This distinction is not
2135 based in any way upon what category of register the hardware
2136 believes the given register belongs to. This is strictly
2137 DWARF terminology we're dealing with here.
2139 Note that in cases where the location of a memory-resident data
2140 object could be expressed as:
2142 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
2144 the actual DWARF location descriptor that we generate may just
2145 be OP_BASEREG (basereg). This may look deceptively like the
2146 object in question was allocated to a register (rather than
2147 in memory) so DWARF consumers need to be aware of the subtle
2148 distinction between OP_REG and OP_BASEREG. */
2150 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
2151 output_reg_number (rtl);
2152 break;
2154 case MEM:
2155 output_mem_loc_descriptor (XEXP (rtl, 0));
2156 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
2157 break;
2159 case CONST:
2160 case SYMBOL_REF:
2161 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
2162 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2163 break;
2165 case PLUS:
2166 output_mem_loc_descriptor (XEXP (rtl, 0));
2167 output_mem_loc_descriptor (XEXP (rtl, 1));
2168 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2169 break;
2171 case CONST_INT:
2172 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2173 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
2174 break;
2176 case MULT:
2177 /* If a pseudo-reg is optimized away, it is possible for it to
2178 be replaced with a MEM containing a multiply. Use a GNU extension
2179 to describe it. */
2180 output_mem_loc_descriptor (XEXP (rtl, 0));
2181 output_mem_loc_descriptor (XEXP (rtl, 1));
2182 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
2183 break;
2185 default:
2186 abort ();
2190 /* Output a proper Dwarf location descriptor for a variable or parameter
2191 which is either allocated in a register or in a memory location. For
2192 a register, we just generate an OP_REG and the register number. For a
2193 memory location we provide a Dwarf postfix expression describing how to
2194 generate the (dynamic) address of the object onto the address stack. */
2196 static void
2197 output_loc_descriptor (rtl)
2198 rtx rtl;
2200 switch (GET_CODE (rtl))
2202 case SUBREG:
2204 /* The case of a subreg may arise when we have a local (register)
2205 variable or a formal (register) parameter which doesn't quite
2206 fill up an entire register. For now, just assume that it is
2207 legitimate to make the Dwarf info refer to the whole register
2208 which contains the given subreg. */
2210 rtl = SUBREG_REG (rtl);
2211 /* Drop thru. */
2213 case REG:
2214 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
2215 output_reg_number (rtl);
2216 break;
2218 case MEM:
2219 output_mem_loc_descriptor (XEXP (rtl, 0));
2220 break;
2222 default:
2223 abort (); /* Should never happen */
2227 /* Given a tree node describing an array bound (either lower or upper)
2228 output a representation for that bound. */
2230 static void
2231 output_bound_representation (bound, dim_num, u_or_l)
2232 tree bound;
2233 unsigned dim_num; /* For multi-dimensional arrays. */
2234 char u_or_l; /* Designates upper or lower bound. */
2236 switch (TREE_CODE (bound))
2239 case ERROR_MARK:
2240 return;
2242 /* All fixed-bounds are represented by INTEGER_CST nodes. */
2244 case INTEGER_CST:
2245 if (host_integerp (bound, 0))
2246 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
2247 break;
2249 default:
2251 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
2252 SAVE_EXPR nodes, in which case we can do something, or as
2253 an expression, which we cannot represent. */
2255 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2256 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2258 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
2259 current_dienum, dim_num, u_or_l);
2261 sprintf (end_label, BOUND_END_LABEL_FMT,
2262 current_dienum, dim_num, u_or_l);
2264 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2265 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2267 /* If optimization is turned on, the SAVE_EXPRs that describe
2268 how to access the upper bound values are essentially bogus.
2269 They only describe (at best) how to get at these values at
2270 the points in the generated code right after they have just
2271 been computed. Worse yet, in the typical case, the upper
2272 bound values will not even *be* computed in the optimized
2273 code, so these SAVE_EXPRs are entirely bogus.
2275 In order to compensate for this fact, we check here to see
2276 if optimization is enabled, and if so, we effectively create
2277 an empty location description for the (unknown and unknowable)
2278 upper bound.
2280 This should not cause too much trouble for existing (stupid?)
2281 debuggers because they have to deal with empty upper bounds
2282 location descriptions anyway in order to be able to deal with
2283 incomplete array types.
2285 Of course an intelligent debugger (GDB?) should be able to
2286 comprehend that a missing upper bound specification in a
2287 array type used for a storage class `auto' local array variable
2288 indicates that the upper bound is both unknown (at compile-
2289 time) and unknowable (at run-time) due to optimization. */
2291 if (! optimize)
2293 while (TREE_CODE (bound) == NOP_EXPR
2294 || TREE_CODE (bound) == CONVERT_EXPR)
2295 bound = TREE_OPERAND (bound, 0);
2297 if (TREE_CODE (bound) == SAVE_EXPR)
2298 output_loc_descriptor
2299 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
2302 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2304 break;
2309 /* Recursive function to output a sequence of value/name pairs for
2310 enumeration constants in reversed order. This is called from
2311 enumeration_type_die. */
2313 static void
2314 output_enumeral_list (link)
2315 tree link;
2317 if (link)
2319 output_enumeral_list (TREE_CHAIN (link));
2321 if (host_integerp (TREE_VALUE (link), 0))
2322 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2323 tree_low_cst (TREE_VALUE (link), 0));
2325 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
2326 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
2330 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
2331 which is not less than the value itself. */
2333 static inline HOST_WIDE_INT
2334 ceiling (value, boundary)
2335 HOST_WIDE_INT value;
2336 unsigned int boundary;
2338 return (((value + boundary - 1) / boundary) * boundary);
2341 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
2342 pointer to the declared type for the relevant field variable, or return
2343 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
2345 static inline tree
2346 field_type (decl)
2347 tree decl;
2349 tree type;
2351 if (TREE_CODE (decl) == ERROR_MARK)
2352 return integer_type_node;
2354 type = DECL_BIT_FIELD_TYPE (decl);
2355 if (type == NULL)
2356 type = TREE_TYPE (decl);
2357 return type;
2360 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2361 node, return the alignment in bits for the type, or else return
2362 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
2364 static inline unsigned int
2365 simple_type_align_in_bits (type)
2366 tree type;
2368 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
2371 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2372 node, return the size in bits for the type if it is a constant, or
2373 else return the alignment for the type if the type's size is not
2374 constant, or else return BITS_PER_WORD if the type actually turns out
2375 to be an ERROR_MARK node. */
2377 static inline unsigned HOST_WIDE_INT
2378 simple_type_size_in_bits (type)
2379 tree type;
2381 tree type_size_tree;
2383 if (TREE_CODE (type) == ERROR_MARK)
2384 return BITS_PER_WORD;
2385 type_size_tree = TYPE_SIZE (type);
2387 if (type_size_tree == NULL_TREE)
2388 return 0;
2389 if (! host_integerp (type_size_tree, 1))
2390 return TYPE_ALIGN (type);
2391 return tree_low_cst (type_size_tree, 1);
2394 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
2395 return the byte offset of the lowest addressed byte of the "containing
2396 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
2397 mine what that offset is, either because the argument turns out to be a
2398 pointer to an ERROR_MARK node, or because the offset is actually variable.
2399 (We can't handle the latter case just yet.) */
2401 static HOST_WIDE_INT
2402 field_byte_offset (decl)
2403 tree decl;
2405 unsigned int type_align_in_bytes;
2406 unsigned int type_align_in_bits;
2407 unsigned HOST_WIDE_INT type_size_in_bits;
2408 HOST_WIDE_INT object_offset_in_align_units;
2409 HOST_WIDE_INT object_offset_in_bits;
2410 HOST_WIDE_INT object_offset_in_bytes;
2411 tree type;
2412 tree field_size_tree;
2413 HOST_WIDE_INT bitpos_int;
2414 HOST_WIDE_INT deepest_bitpos;
2415 unsigned HOST_WIDE_INT field_size_in_bits;
2417 if (TREE_CODE (decl) == ERROR_MARK)
2418 return 0;
2420 if (TREE_CODE (decl) != FIELD_DECL)
2421 abort ();
2423 type = field_type (decl);
2424 field_size_tree = DECL_SIZE (decl);
2426 /* The size could be unspecified if there was an error, or for
2427 a flexible array member. */
2428 if (! field_size_tree)
2429 field_size_tree = bitsize_zero_node;
2431 /* We cannot yet cope with fields whose positions or sizes are variable,
2432 so for now, when we see such things, we simply return 0. Someday,
2433 we may be able to handle such cases, but it will be damn difficult. */
2435 if (! host_integerp (bit_position (decl), 0)
2436 || ! host_integerp (field_size_tree, 1))
2437 return 0;
2439 bitpos_int = int_bit_position (decl);
2440 field_size_in_bits = tree_low_cst (field_size_tree, 1);
2442 type_size_in_bits = simple_type_size_in_bits (type);
2443 type_align_in_bits = simple_type_align_in_bits (type);
2444 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2446 /* Note that the GCC front-end doesn't make any attempt to keep track
2447 of the starting bit offset (relative to the start of the containing
2448 structure type) of the hypothetical "containing object" for a bit-
2449 field. Thus, when computing the byte offset value for the start of
2450 the "containing object" of a bit-field, we must deduce this infor-
2451 mation on our own.
2453 This can be rather tricky to do in some cases. For example, handling
2454 the following structure type definition when compiling for an i386/i486
2455 target (which only aligns long long's to 32-bit boundaries) can be very
2456 tricky:
2458 struct S {
2459 int field1;
2460 long long field2:31;
2463 Fortunately, there is a simple rule-of-thumb which can be used in such
2464 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2465 the structure shown above. It decides to do this based upon one simple
2466 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2467 taining object" for each bit-field at the first (i.e. lowest addressed)
2468 legitimate alignment boundary (based upon the required minimum alignment
2469 for the declared type of the field) which it can possibly use, subject
2470 to the condition that there is still enough available space remaining
2471 in the containing object (when allocated at the selected point) to
2472 fully accommodate all of the bits of the bit-field itself.
2474 This simple rule makes it obvious why GCC allocates 8 bytes for each
2475 object of the structure type shown above. When looking for a place to
2476 allocate the "containing object" for `field2', the compiler simply tries
2477 to allocate a 64-bit "containing object" at each successive 32-bit
2478 boundary (starting at zero) until it finds a place to allocate that 64-
2479 bit field such that at least 31 contiguous (and previously unallocated)
2480 bits remain within that selected 64 bit field. (As it turns out, for
2481 the example above, the compiler finds that it is OK to allocate the
2482 "containing object" 64-bit field at bit-offset zero within the
2483 structure type.)
2485 Here we attempt to work backwards from the limited set of facts we're
2486 given, and we try to deduce from those facts, where GCC must have
2487 believed that the containing object started (within the structure type).
2489 The value we deduce is then used (by the callers of this routine) to
2490 generate AT_location and AT_bit_offset attributes for fields (both
2491 bit-fields and, in the case of AT_location, regular fields as well). */
2493 /* Figure out the bit-distance from the start of the structure to the
2494 "deepest" bit of the bit-field. */
2495 deepest_bitpos = bitpos_int + field_size_in_bits;
2497 /* This is the tricky part. Use some fancy footwork to deduce where the
2498 lowest addressed bit of the containing object must be. */
2499 object_offset_in_bits
2500 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2502 /* Compute the offset of the containing object in "alignment units". */
2503 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2505 /* Compute the offset of the containing object in bytes. */
2506 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2508 /* The above code assumes that the field does not cross an alignment
2509 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2510 or if the structure is packed. If this happens, then we get an object
2511 which starts after the bitfield, which means that the bit offset is
2512 negative. Gdb fails when given negative bit offsets. We avoid this
2513 by recomputing using the first bit of the bitfield. This will give
2514 us an object which does not completely contain the bitfield, but it
2515 will be aligned, and it will contain the first bit of the bitfield.
2517 However, only do this for a BYTES_BIG_ENDIAN target. For a
2518 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2519 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2520 then we end up computing the object byte offset for the wrong word of the
2521 desired bitfield, which in turn causes the field offset to be negative
2522 in bit_offset_attribute. */
2523 if (BYTES_BIG_ENDIAN
2524 && object_offset_in_bits > bitpos_int)
2526 deepest_bitpos = bitpos_int + 1;
2527 object_offset_in_bits
2528 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2529 object_offset_in_align_units = (object_offset_in_bits
2530 / type_align_in_bits);
2531 object_offset_in_bytes = (object_offset_in_align_units
2532 * type_align_in_bytes);
2535 return object_offset_in_bytes;
2538 /****************************** attributes *********************************/
2540 /* The following routines are responsible for writing out the various types
2541 of Dwarf attributes (and any following data bytes associated with them).
2542 These routines are listed in order based on the numerical codes of their
2543 associated attributes. */
2545 /* Generate an AT_sibling attribute. */
2547 static inline void
2548 sibling_attribute ()
2550 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2552 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2553 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2554 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2557 /* Output the form of location attributes suitable for whole variables and
2558 whole parameters. Note that the location attributes for struct fields
2559 are generated by the routine `data_member_location_attribute' below. */
2561 static void
2562 location_attribute (rtl)
2563 rtx rtl;
2565 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2566 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2568 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2569 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2570 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2571 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2572 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2574 /* Handle a special case. If we are about to output a location descriptor
2575 for a variable or parameter which has been optimized out of existence,
2576 don't do that. Instead we output a zero-length location descriptor
2577 value as part of the location attribute.
2579 A variable which has been optimized out of existence will have a
2580 DECL_RTL value which denotes a pseudo-reg.
2582 Currently, in some rare cases, variables can have DECL_RTL values
2583 which look like (MEM (REG pseudo-reg#)). These cases are due to
2584 bugs elsewhere in the compiler. We treat such cases
2585 as if the variable(s) in question had been optimized out of existence.
2587 Note that in all cases where we wish to express the fact that a
2588 variable has been optimized out of existence, we do not simply
2589 suppress the generation of the entire location attribute because
2590 the absence of a location attribute in certain kinds of DIEs is
2591 used to indicate something else entirely... i.e. that the DIE
2592 represents an object declaration, but not a definition. So saith
2593 the PLSIG.
2596 if (! is_pseudo_reg (rtl)
2597 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2598 output_loc_descriptor (rtl);
2600 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2603 /* Output the specialized form of location attribute used for data members
2604 of struct and union types.
2606 In the special case of a FIELD_DECL node which represents a bit-field,
2607 the "offset" part of this special location descriptor must indicate the
2608 distance in bytes from the lowest-addressed byte of the containing
2609 struct or union type to the lowest-addressed byte of the "containing
2610 object" for the bit-field. (See the `field_byte_offset' function above.)
2612 For any given bit-field, the "containing object" is a hypothetical
2613 object (of some integral or enum type) within which the given bit-field
2614 lives. The type of this hypothetical "containing object" is always the
2615 same as the declared type of the individual bit-field itself (for GCC
2616 anyway... the DWARF spec doesn't actually mandate this).
2618 Note that it is the size (in bytes) of the hypothetical "containing
2619 object" which will be given in the AT_byte_size attribute for this
2620 bit-field. (See the `byte_size_attribute' function below.) It is
2621 also used when calculating the value of the AT_bit_offset attribute.
2622 (See the `bit_offset_attribute' function below.) */
2624 static void
2625 data_member_location_attribute (t)
2626 tree t;
2628 unsigned object_offset_in_bytes;
2629 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2630 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2632 if (TREE_CODE (t) == TREE_VEC)
2633 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2634 else
2635 object_offset_in_bytes = field_byte_offset (t);
2637 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2638 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2639 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2640 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2641 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2642 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2643 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2644 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2645 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2648 /* Output an AT_const_value attribute for a variable or a parameter which
2649 does not have a "location" either in memory or in a register. These
2650 things can arise in GNU C when a constant is passed as an actual
2651 parameter to an inlined function. They can also arise in C++ where
2652 declared constants do not necessarily get memory "homes". */
2654 static void
2655 const_value_attribute (rtl)
2656 rtx rtl;
2658 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2659 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2661 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2662 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2663 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2664 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2665 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2667 switch (GET_CODE (rtl))
2669 case CONST_INT:
2670 /* Note that a CONST_INT rtx could represent either an integer or
2671 a floating-point constant. A CONST_INT is used whenever the
2672 constant will fit into a single word. In all such cases, the
2673 original mode of the constant value is wiped out, and the
2674 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2675 precise mode information for these constants, we always just
2676 output them using 4 bytes. */
2678 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2679 break;
2681 case CONST_DOUBLE:
2682 /* Note that a CONST_DOUBLE rtx could represent either an integer
2683 or a floating-point constant. A CONST_DOUBLE is used whenever
2684 the constant requires more than one word in order to be adequately
2685 represented. In all such cases, the original mode of the constant
2686 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2687 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2689 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2690 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2691 (unsigned int) CONST_DOUBLE_LOW (rtl));
2692 break;
2694 case CONST_STRING:
2695 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2696 break;
2698 case SYMBOL_REF:
2699 case LABEL_REF:
2700 case CONST:
2701 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2702 break;
2704 case PLUS:
2705 /* In cases where an inlined instance of an inline function is passed
2706 the address of an `auto' variable (which is local to the caller)
2707 we can get a situation where the DECL_RTL of the artificial
2708 local variable (for the inlining) which acts as a stand-in for
2709 the corresponding formal parameter (of the inline function)
2710 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2711 This is not exactly a compile-time constant expression, but it
2712 isn't the address of the (artificial) local variable either.
2713 Rather, it represents the *value* which the artificial local
2714 variable always has during its lifetime. We currently have no
2715 way to represent such quasi-constant values in Dwarf, so for now
2716 we just punt and generate an AT_const_value attribute with form
2717 FORM_BLOCK4 and a length of zero. */
2718 break;
2720 default:
2721 abort (); /* No other kinds of rtx should be possible here. */
2724 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2727 /* Generate *either* an AT_location attribute or else an AT_const_value
2728 data attribute for a variable or a parameter. We generate the
2729 AT_const_value attribute only in those cases where the given
2730 variable or parameter does not have a true "location" either in
2731 memory or in a register. This can happen (for example) when a
2732 constant is passed as an actual argument in a call to an inline
2733 function. (It's possible that these things can crop up in other
2734 ways also.) Note that one type of constant value which can be
2735 passed into an inlined function is a constant pointer. This can
2736 happen for example if an actual argument in an inlined function
2737 call evaluates to a compile-time constant address. */
2739 static void
2740 location_or_const_value_attribute (decl)
2741 tree decl;
2743 rtx rtl;
2745 if (TREE_CODE (decl) == ERROR_MARK)
2746 return;
2748 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2750 /* Should never happen. */
2751 abort ();
2752 return;
2755 /* Here we have to decide where we are going to say the parameter "lives"
2756 (as far as the debugger is concerned). We only have a couple of choices.
2757 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2758 normally indicates where the parameter lives during most of the activa-
2759 tion of the function. If optimization is enabled however, this could
2760 be either NULL or else a pseudo-reg. Both of those cases indicate that
2761 the parameter doesn't really live anywhere (as far as the code generation
2762 parts of GCC are concerned) during most of the function's activation.
2763 That will happen (for example) if the parameter is never referenced
2764 within the function.
2766 We could just generate a location descriptor here for all non-NULL
2767 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2768 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2769 cases where DECL_RTL is NULL or is a pseudo-reg.
2771 Note however that we can only get away with using DECL_INCOMING_RTL as
2772 a backup substitute for DECL_RTL in certain limited cases. In cases
2773 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2774 we can be sure that the parameter was passed using the same type as it
2775 is declared to have within the function, and that its DECL_INCOMING_RTL
2776 points us to a place where a value of that type is passed. In cases
2777 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2778 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2779 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2780 points us to a value of some type which is *different* from the type
2781 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2782 to generate a location attribute in such cases, the debugger would
2783 end up (for example) trying to fetch a `float' from a place which
2784 actually contains the first part of a `double'. That would lead to
2785 really incorrect and confusing output at debug-time, and we don't
2786 want that now do we?
2788 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2789 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2790 couple of cute exceptions however. On little-endian machines we can
2791 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2792 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2793 an integral type which is smaller than TREE_TYPE(decl). These cases
2794 arise when (on a little-endian machine) a non-prototyped function has
2795 a parameter declared to be of type `short' or `char'. In such cases,
2796 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2797 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2798 passed `int' value. If the debugger then uses that address to fetch a
2799 `short' or a `char' (on a little-endian machine) the result will be the
2800 correct data, so we allow for such exceptional cases below.
2802 Note that our goal here is to describe the place where the given formal
2803 parameter lives during most of the function's activation (i.e. between
2804 the end of the prologue and the start of the epilogue). We'll do that
2805 as best as we can. Note however that if the given formal parameter is
2806 modified sometime during the execution of the function, then a stack
2807 backtrace (at debug-time) will show the function as having been called
2808 with the *new* value rather than the value which was originally passed
2809 in. This happens rarely enough that it is not a major problem, but it
2810 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2811 may generate two additional attributes for any given TAG_formal_parameter
2812 DIE which will describe the "passed type" and the "passed location" for
2813 the given formal parameter in addition to the attributes we now generate
2814 to indicate the "declared type" and the "active location" for each
2815 parameter. This additional set of attributes could be used by debuggers
2816 for stack backtraces.
2818 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2819 can be NULL also. This happens (for example) for inlined-instances of
2820 inline function formal parameters which are never referenced. This really
2821 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2822 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2823 these values for inlined instances of inline function parameters, so
2824 when we see such cases, we are just out-of-luck for the time
2825 being (until integrate.c gets fixed).
2828 /* Use DECL_RTL as the "location" unless we find something better. */
2829 rtl = DECL_RTL (decl);
2831 if (TREE_CODE (decl) == PARM_DECL)
2832 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2834 /* This decl represents a formal parameter which was optimized out. */
2835 tree declared_type = type_main_variant (TREE_TYPE (decl));
2836 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2838 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2839 *all* cases where (rtl == NULL_RTX) just below. */
2841 if (declared_type == passed_type)
2842 rtl = DECL_INCOMING_RTL (decl);
2843 else if (! BYTES_BIG_ENDIAN)
2844 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2845 /* NMS WTF? */
2846 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2847 rtl = DECL_INCOMING_RTL (decl);
2850 if (rtl == NULL_RTX)
2851 return;
2853 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2854 #ifdef LEAF_REG_REMAP
2855 if (current_function_uses_only_leaf_regs)
2856 leaf_renumber_regs_insn (rtl);
2857 #endif
2859 switch (GET_CODE (rtl))
2861 case ADDRESSOF:
2862 /* The address of a variable that was optimized away; don't emit
2863 anything. */
2864 break;
2866 case CONST_INT:
2867 case CONST_DOUBLE:
2868 case CONST_STRING:
2869 case SYMBOL_REF:
2870 case LABEL_REF:
2871 case CONST:
2872 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2873 const_value_attribute (rtl);
2874 break;
2876 case MEM:
2877 case REG:
2878 case SUBREG:
2879 location_attribute (rtl);
2880 break;
2882 case CONCAT:
2883 /* ??? CONCAT is used for complex variables, which may have the real
2884 part stored in one place and the imag part stored somewhere else.
2885 DWARF1 has no way to describe a variable that lives in two different
2886 places, so we just describe where the first part lives, and hope that
2887 the second part is stored after it. */
2888 location_attribute (XEXP (rtl, 0));
2889 break;
2891 default:
2892 abort (); /* Should never happen. */
2896 /* Generate an AT_name attribute given some string value to be included as
2897 the value of the attribute. */
2899 static inline void
2900 name_attribute (name_string)
2901 const char *name_string;
2903 if (name_string && *name_string)
2905 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2906 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2910 static inline void
2911 fund_type_attribute (ft_code)
2912 unsigned ft_code;
2914 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2915 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2918 static void
2919 mod_fund_type_attribute (type, decl_const, decl_volatile)
2920 tree type;
2921 int decl_const;
2922 int decl_volatile;
2924 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2925 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2927 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2928 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2929 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2930 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2931 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2932 write_modifier_bytes (type, decl_const, decl_volatile);
2933 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2934 fundamental_type_code (root_type (type)));
2935 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2938 static inline void
2939 user_def_type_attribute (type)
2940 tree type;
2942 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2944 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2945 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2946 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2949 static void
2950 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2951 tree type;
2952 int decl_const;
2953 int decl_volatile;
2955 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2956 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2957 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2959 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2960 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2961 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2962 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2963 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2964 write_modifier_bytes (type, decl_const, decl_volatile);
2965 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2966 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2967 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2970 #ifdef USE_ORDERING_ATTRIBUTE
2971 static inline void
2972 ordering_attribute (ordering)
2973 unsigned ordering;
2975 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2976 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2978 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2980 /* Note that the block of subscript information for an array type also
2981 includes information about the element type of type given array type. */
2983 static void
2984 subscript_data_attribute (type)
2985 tree type;
2987 unsigned dimension_number;
2988 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2989 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2991 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2992 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2993 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2994 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2995 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2997 /* The GNU compilers represent multidimensional array types as sequences
2998 of one dimensional array types whose element types are themselves array
2999 types. Here we squish that down, so that each multidimensional array
3000 type gets only one array_type DIE in the Dwarf debugging info. The
3001 draft Dwarf specification say that we are allowed to do this kind
3002 of compression in C (because there is no difference between an
3003 array or arrays and a multidimensional array in C) but for other
3004 source languages (e.g. Ada) we probably shouldn't do this. */
3006 for (dimension_number = 0;
3007 TREE_CODE (type) == ARRAY_TYPE;
3008 type = TREE_TYPE (type), dimension_number++)
3010 tree domain = TYPE_DOMAIN (type);
3012 /* Arrays come in three flavors. Unspecified bounds, fixed
3013 bounds, and (in GNU C only) variable bounds. Handle all
3014 three forms here. */
3016 if (domain)
3018 /* We have an array type with specified bounds. */
3020 tree lower = TYPE_MIN_VALUE (domain);
3021 tree upper = TYPE_MAX_VALUE (domain);
3023 /* Handle only fundamental types as index types for now. */
3024 if (! type_is_fundamental (domain))
3025 abort ();
3027 /* Output the representation format byte for this dimension. */
3028 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
3029 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
3030 upper && TREE_CODE (upper) == INTEGER_CST));
3032 /* Output the index type for this dimension. */
3033 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3034 fundamental_type_code (domain));
3036 /* Output the representation for the lower bound. */
3037 output_bound_representation (lower, dimension_number, 'l');
3039 /* Output the representation for the upper bound. */
3040 if (upper)
3041 output_bound_representation (upper, dimension_number, 'u');
3042 else
3043 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3045 else
3047 /* We have an array type with an unspecified length. For C and
3048 C++ we can assume that this really means that (a) the index
3049 type is an integral type, and (b) the lower bound is zero.
3050 Note that Dwarf defines the representation of an unspecified
3051 (upper) bound as being a zero-length location description. */
3053 /* Output the array-bounds format byte. */
3055 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
3057 /* Output the (assumed) index type. */
3059 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
3061 /* Output the (assumed) lower bound (constant) value. */
3063 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3065 /* Output the (empty) location description for the upper bound. */
3067 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3071 /* Output the prefix byte that says that the element type is coming up. */
3073 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
3075 /* Output a representation of the type of the elements of this array type. */
3077 type_attribute (type, 0, 0);
3079 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3082 static void
3083 byte_size_attribute (tree_node)
3084 tree tree_node;
3086 unsigned size;
3088 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
3089 switch (TREE_CODE (tree_node))
3091 case ERROR_MARK:
3092 size = 0;
3093 break;
3095 case ENUMERAL_TYPE:
3096 case RECORD_TYPE:
3097 case UNION_TYPE:
3098 case QUAL_UNION_TYPE:
3099 case ARRAY_TYPE:
3100 size = int_size_in_bytes (tree_node);
3101 break;
3103 case FIELD_DECL:
3104 /* For a data member of a struct or union, the AT_byte_size is
3105 generally given as the number of bytes normally allocated for
3106 an object of the *declared* type of the member itself. This
3107 is true even for bit-fields. */
3108 size = simple_type_size_in_bits (field_type (tree_node))
3109 / BITS_PER_UNIT;
3110 break;
3112 default:
3113 abort ();
3116 /* Note that `size' might be -1 when we get to this point. If it
3117 is, that indicates that the byte size of the entity in question
3118 is variable. We have no good way of expressing this fact in Dwarf
3119 at the present time, so just let the -1 pass on through. */
3121 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
3124 /* For a FIELD_DECL node which represents a bit-field, output an attribute
3125 which specifies the distance in bits from the highest order bit of the
3126 "containing object" for the bit-field to the highest order bit of the
3127 bit-field itself.
3129 For any given bit-field, the "containing object" is a hypothetical
3130 object (of some integral or enum type) within which the given bit-field
3131 lives. The type of this hypothetical "containing object" is always the
3132 same as the declared type of the individual bit-field itself.
3134 The determination of the exact location of the "containing object" for
3135 a bit-field is rather complicated. It's handled by the `field_byte_offset'
3136 function (above).
3138 Note that it is the size (in bytes) of the hypothetical "containing
3139 object" which will be given in the AT_byte_size attribute for this
3140 bit-field. (See `byte_size_attribute' above.) */
3142 static inline void
3143 bit_offset_attribute (decl)
3144 tree decl;
3146 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
3147 tree type = DECL_BIT_FIELD_TYPE (decl);
3148 HOST_WIDE_INT bitpos_int;
3149 HOST_WIDE_INT highest_order_object_bit_offset;
3150 HOST_WIDE_INT highest_order_field_bit_offset;
3151 HOST_WIDE_INT bit_offset;
3153 /* Must be a bit field. */
3154 if (!type
3155 || TREE_CODE (decl) != FIELD_DECL)
3156 abort ();
3158 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
3159 if we encounter such things, just return without generating any
3160 attribute whatsoever. */
3162 if (! host_integerp (bit_position (decl), 0)
3163 || ! host_integerp (DECL_SIZE (decl), 1))
3164 return;
3166 bitpos_int = int_bit_position (decl);
3168 /* Note that the bit offset is always the distance (in bits) from the
3169 highest-order bit of the "containing object" to the highest-order
3170 bit of the bit-field itself. Since the "high-order end" of any
3171 object or field is different on big-endian and little-endian machines,
3172 the computation below must take account of these differences. */
3174 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
3175 highest_order_field_bit_offset = bitpos_int;
3177 if (! BYTES_BIG_ENDIAN)
3179 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
3180 highest_order_object_bit_offset += simple_type_size_in_bits (type);
3183 bit_offset =
3184 (! BYTES_BIG_ENDIAN
3185 ? highest_order_object_bit_offset - highest_order_field_bit_offset
3186 : highest_order_field_bit_offset - highest_order_object_bit_offset);
3188 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
3189 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
3192 /* For a FIELD_DECL node which represents a bit field, output an attribute
3193 which specifies the length in bits of the given field. */
3195 static inline void
3196 bit_size_attribute (decl)
3197 tree decl;
3199 /* Must be a field and a bit field. */
3200 if (TREE_CODE (decl) != FIELD_DECL
3201 || ! DECL_BIT_FIELD_TYPE (decl))
3202 abort ();
3204 if (host_integerp (DECL_SIZE (decl), 1))
3206 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
3207 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3208 tree_low_cst (DECL_SIZE (decl), 1));
3212 /* The following routine outputs the `element_list' attribute for enumeration
3213 type DIEs. The element_lits attribute includes the names and values of
3214 all of the enumeration constants associated with the given enumeration
3215 type. */
3217 static inline void
3218 element_list_attribute (element)
3219 tree element;
3221 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3222 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3224 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
3225 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
3226 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
3227 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3228 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3230 /* Here we output a list of value/name pairs for each enumeration constant
3231 defined for this enumeration type (as required), but we do it in REVERSE
3232 order. The order is the one required by the draft #5 Dwarf specification
3233 published by the UI/PLSIG. */
3235 output_enumeral_list (element); /* Recursively output the whole list. */
3237 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3240 /* Generate an AT_stmt_list attribute. These are normally present only in
3241 DIEs with a TAG_compile_unit tag. */
3243 static inline void
3244 stmt_list_attribute (label)
3245 const char *label;
3247 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
3248 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3249 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3252 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
3253 for a subroutine DIE. */
3255 static inline void
3256 low_pc_attribute (asm_low_label)
3257 const char *asm_low_label;
3259 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
3260 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
3263 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
3264 subroutine DIE. */
3266 static inline void
3267 high_pc_attribute (asm_high_label)
3268 const char *asm_high_label;
3270 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
3271 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
3274 /* Generate an AT_body_begin attribute for a subroutine DIE. */
3276 static inline void
3277 body_begin_attribute (asm_begin_label)
3278 const char *asm_begin_label;
3280 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
3281 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
3284 /* Generate an AT_body_end attribute for a subroutine DIE. */
3286 static inline void
3287 body_end_attribute (asm_end_label)
3288 const char *asm_end_label;
3290 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
3291 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
3294 /* Generate an AT_language attribute given a LANG value. These attributes
3295 are used only within TAG_compile_unit DIEs. */
3297 static inline void
3298 language_attribute (language_code)
3299 unsigned language_code;
3301 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
3302 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
3305 static inline void
3306 member_attribute (context)
3307 tree context;
3309 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3311 /* Generate this attribute only for members in C++. */
3313 if (context != NULL && is_tagged_type (context))
3315 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
3316 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
3317 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3321 #if 0
3322 static inline void
3323 string_length_attribute (upper_bound)
3324 tree upper_bound;
3326 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3327 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3329 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
3330 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
3331 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
3332 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3333 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3334 output_bound_representation (upper_bound, 0, 'u');
3335 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3337 #endif
3339 static inline void
3340 comp_dir_attribute (dirname)
3341 const char *dirname;
3343 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
3344 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
3347 static inline void
3348 sf_names_attribute (sf_names_start_label)
3349 const char *sf_names_start_label;
3351 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
3352 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3353 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
3356 static inline void
3357 src_info_attribute (src_info_start_label)
3358 const char *src_info_start_label;
3360 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
3361 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3362 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
3365 static inline void
3366 mac_info_attribute (mac_info_start_label)
3367 const char *mac_info_start_label;
3369 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
3370 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3371 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
3374 static inline void
3375 prototyped_attribute (func_type)
3376 tree func_type;
3378 if ((strcmp (lang_hooks.name, "GNU C") == 0)
3379 && (TYPE_ARG_TYPES (func_type) != NULL))
3381 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
3382 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3386 static inline void
3387 producer_attribute (producer)
3388 const char *producer;
3390 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
3391 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
3394 static inline void
3395 inline_attribute (decl)
3396 tree decl;
3398 if (DECL_INLINE (decl))
3400 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3401 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3405 static inline void
3406 containing_type_attribute (containing_type)
3407 tree containing_type;
3409 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3411 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3412 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3413 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3416 static inline void
3417 abstract_origin_attribute (origin)
3418 tree origin;
3420 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3422 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3423 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3425 case 'd':
3426 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3427 break;
3429 case 't':
3430 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3431 break;
3433 default:
3434 abort (); /* Should never happen. */
3437 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3440 #ifdef DWARF_DECL_COORDINATES
3441 static inline void
3442 src_coords_attribute (src_fileno, src_lineno)
3443 unsigned src_fileno;
3444 unsigned src_lineno;
3446 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3447 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3448 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3450 #endif /* defined(DWARF_DECL_COORDINATES) */
3452 static inline void
3453 pure_or_virtual_attribute (func_decl)
3454 tree func_decl;
3456 if (DECL_VIRTUAL_P (func_decl))
3458 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3459 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3460 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3461 else
3462 #endif
3463 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3464 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3468 /************************* end of attributes *****************************/
3470 /********************* utility routines for DIEs *************************/
3472 /* Output an AT_name attribute and an AT_src_coords attribute for the
3473 given decl, but only if it actually has a name. */
3475 static void
3476 name_and_src_coords_attributes (decl)
3477 tree decl;
3479 tree decl_name = DECL_NAME (decl);
3481 if (decl_name && IDENTIFIER_POINTER (decl_name))
3483 name_attribute (IDENTIFIER_POINTER (decl_name));
3484 #ifdef DWARF_DECL_COORDINATES
3486 register unsigned file_index;
3488 /* This is annoying, but we have to pop out of the .debug section
3489 for a moment while we call `lookup_filename' because calling it
3490 may cause a temporary switch into the .debug_sfnames section and
3491 most svr4 assemblers are not smart enough to be able to nest
3492 section switches to any depth greater than one. Note that we
3493 also can't skirt this issue by delaying all output to the
3494 .debug_sfnames section unit the end of compilation because that
3495 would cause us to have inter-section forward references and
3496 Fred Fish sez that m68k/svr4 assemblers botch those. */
3498 ASM_OUTPUT_POP_SECTION (asm_out_file);
3499 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3500 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3502 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3504 #endif /* defined(DWARF_DECL_COORDINATES) */
3508 /* Many forms of DIEs contain a "type description" part. The following
3509 routine writes out these "type descriptor" parts. */
3511 static void
3512 type_attribute (type, decl_const, decl_volatile)
3513 tree type;
3514 int decl_const;
3515 int decl_volatile;
3517 enum tree_code code = TREE_CODE (type);
3518 int root_type_modified;
3520 if (code == ERROR_MARK)
3521 return;
3523 /* Handle a special case. For functions whose return type is void,
3524 we generate *no* type attribute. (Note that no object may have
3525 type `void', so this only applies to function return types. */
3527 if (code == VOID_TYPE)
3528 return;
3530 /* If this is a subtype, find the underlying type. Eventually,
3531 this should write out the appropriate subtype info. */
3532 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3533 && TREE_TYPE (type) != 0)
3534 type = TREE_TYPE (type), code = TREE_CODE (type);
3536 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3537 || decl_const || decl_volatile
3538 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3540 if (type_is_fundamental (root_type (type)))
3542 if (root_type_modified)
3543 mod_fund_type_attribute (type, decl_const, decl_volatile);
3544 else
3545 fund_type_attribute (fundamental_type_code (type));
3547 else
3549 if (root_type_modified)
3550 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3551 else
3552 /* We have to get the type_main_variant here (and pass that to the
3553 `user_def_type_attribute' routine) because the ..._TYPE node we
3554 have might simply be a *copy* of some original type node (where
3555 the copy was created to help us keep track of typedef names)
3556 and that copy might have a different TYPE_UID from the original
3557 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3558 is labeling a given type DIE for future reference, it always and
3559 only creates labels for DIEs representing *main variants*, and it
3560 never even knows about non-main-variants.) */
3561 user_def_type_attribute (type_main_variant (type));
3565 /* Given a tree pointer to a struct, class, union, or enum type node, return
3566 a pointer to the (string) tag name for the given type, or zero if the
3567 type was declared without a tag. */
3569 static const char *
3570 type_tag (type)
3571 tree type;
3573 const char *name = 0;
3575 if (TYPE_NAME (type) != 0)
3577 tree t = 0;
3579 /* Find the IDENTIFIER_NODE for the type name. */
3580 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3581 t = TYPE_NAME (type);
3583 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3584 a TYPE_DECL node, regardless of whether or not a `typedef' was
3585 involved. */
3586 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3587 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3588 t = DECL_NAME (TYPE_NAME (type));
3590 /* Now get the name as a string, or invent one. */
3591 if (t != 0)
3592 name = IDENTIFIER_POINTER (t);
3595 return (name == 0 || *name == '\0') ? 0 : name;
3598 static inline void
3599 dienum_push ()
3601 /* Start by checking if the pending_sibling_stack needs to be expanded.
3602 If necessary, expand it. */
3604 if (pending_siblings == pending_siblings_allocated)
3606 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3607 pending_sibling_stack
3608 = (unsigned *) xrealloc (pending_sibling_stack,
3609 pending_siblings_allocated * sizeof(unsigned));
3612 pending_siblings++;
3613 NEXT_DIE_NUM = next_unused_dienum++;
3616 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3617 NEXT_DIE_NUM. */
3619 static inline void
3620 dienum_pop ()
3622 pending_siblings--;
3625 static inline tree
3626 member_declared_type (member)
3627 tree member;
3629 return (DECL_BIT_FIELD_TYPE (member))
3630 ? DECL_BIT_FIELD_TYPE (member)
3631 : TREE_TYPE (member);
3634 /* Get the function's label, as described by its RTL.
3635 This may be different from the DECL_NAME name used
3636 in the source file. */
3638 static const char *
3639 function_start_label (decl)
3640 tree decl;
3642 rtx x;
3643 const char *fnname;
3645 x = DECL_RTL (decl);
3646 if (GET_CODE (x) != MEM)
3647 abort ();
3648 x = XEXP (x, 0);
3649 if (GET_CODE (x) != SYMBOL_REF)
3650 abort ();
3651 fnname = XSTR (x, 0);
3652 return fnname;
3656 /******************************* DIEs ************************************/
3658 /* Output routines for individual types of DIEs. */
3660 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3662 static void
3663 output_array_type_die (arg)
3664 void *arg;
3666 tree type = arg;
3668 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3669 sibling_attribute ();
3670 equate_type_number_to_die_number (type);
3671 member_attribute (TYPE_CONTEXT (type));
3673 /* I believe that we can default the array ordering. SDB will probably
3674 do the right things even if AT_ordering is not present. It's not
3675 even an issue until we start to get into multidimensional arrays
3676 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3677 dimensional arrays, then we'll have to put the AT_ordering attribute
3678 back in. (But if and when we find out that we need to put these in,
3679 we will only do so for multidimensional arrays. After all, we don't
3680 want to waste space in the .debug section now do we?) */
3682 #ifdef USE_ORDERING_ATTRIBUTE
3683 ordering_attribute (ORD_row_major);
3684 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3686 subscript_data_attribute (type);
3689 static void
3690 output_set_type_die (arg)
3691 void *arg;
3693 tree type = arg;
3695 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3696 sibling_attribute ();
3697 equate_type_number_to_die_number (type);
3698 member_attribute (TYPE_CONTEXT (type));
3699 type_attribute (TREE_TYPE (type), 0, 0);
3702 #if 0
3703 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3705 static void
3706 output_entry_point_die (arg)
3707 void *arg;
3709 tree decl = arg;
3710 tree origin = decl_ultimate_origin (decl);
3712 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3713 sibling_attribute ();
3714 dienum_push ();
3715 if (origin != NULL)
3716 abstract_origin_attribute (origin);
3717 else
3719 name_and_src_coords_attributes (decl);
3720 member_attribute (DECL_CONTEXT (decl));
3721 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3723 if (DECL_ABSTRACT (decl))
3724 equate_decl_number_to_die_number (decl);
3725 else
3726 low_pc_attribute (function_start_label (decl));
3728 #endif
3730 /* Output a DIE to represent an inlined instance of an enumeration type. */
3732 static void
3733 output_inlined_enumeration_type_die (arg)
3734 void *arg;
3736 tree type = arg;
3738 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3739 sibling_attribute ();
3740 if (!TREE_ASM_WRITTEN (type))
3741 abort ();
3742 abstract_origin_attribute (type);
3745 /* Output a DIE to represent an inlined instance of a structure type. */
3747 static void
3748 output_inlined_structure_type_die (arg)
3749 void *arg;
3751 tree type = arg;
3753 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3754 sibling_attribute ();
3755 if (!TREE_ASM_WRITTEN (type))
3756 abort ();
3757 abstract_origin_attribute (type);
3760 /* Output a DIE to represent an inlined instance of a union type. */
3762 static void
3763 output_inlined_union_type_die (arg)
3764 void *arg;
3766 tree type = arg;
3768 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3769 sibling_attribute ();
3770 if (!TREE_ASM_WRITTEN (type))
3771 abort ();
3772 abstract_origin_attribute (type);
3775 /* Output a DIE to represent an enumeration type. Note that these DIEs
3776 include all of the information about the enumeration values also.
3777 This information is encoded into the element_list attribute. */
3779 static void
3780 output_enumeration_type_die (arg)
3781 void *arg;
3783 tree type = arg;
3785 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3786 sibling_attribute ();
3787 equate_type_number_to_die_number (type);
3788 name_attribute (type_tag (type));
3789 member_attribute (TYPE_CONTEXT (type));
3791 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3792 given enum type is incomplete, do not generate the AT_byte_size
3793 attribute or the AT_element_list attribute. */
3795 if (COMPLETE_TYPE_P (type))
3797 byte_size_attribute (type);
3798 element_list_attribute (TYPE_FIELDS (type));
3802 /* Output a DIE to represent either a real live formal parameter decl or
3803 to represent just the type of some formal parameter position in some
3804 function type.
3806 Note that this routine is a bit unusual because its argument may be
3807 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3808 represents an inlining of some PARM_DECL) or else some sort of a
3809 ..._TYPE node. If it's the former then this function is being called
3810 to output a DIE to represent a formal parameter object (or some inlining
3811 thereof). If it's the latter, then this function is only being called
3812 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3813 formal argument type of some subprogram type. */
3815 static void
3816 output_formal_parameter_die (arg)
3817 void *arg;
3819 tree node = arg;
3821 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3822 sibling_attribute ();
3824 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3826 case 'd': /* We were called with some kind of a ..._DECL node. */
3828 register tree origin = decl_ultimate_origin (node);
3830 if (origin != NULL)
3831 abstract_origin_attribute (origin);
3832 else
3834 name_and_src_coords_attributes (node);
3835 type_attribute (TREE_TYPE (node),
3836 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3838 if (DECL_ABSTRACT (node))
3839 equate_decl_number_to_die_number (node);
3840 else
3841 location_or_const_value_attribute (node);
3843 break;
3845 case 't': /* We were called with some kind of a ..._TYPE node. */
3846 type_attribute (node, 0, 0);
3847 break;
3849 default:
3850 abort (); /* Should never happen. */
3854 /* Output a DIE to represent a declared function (either file-scope
3855 or block-local) which has "external linkage" (according to ANSI-C). */
3857 static void
3858 output_global_subroutine_die (arg)
3859 void *arg;
3861 tree decl = arg;
3862 tree origin = decl_ultimate_origin (decl);
3864 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3865 sibling_attribute ();
3866 dienum_push ();
3867 if (origin != NULL)
3868 abstract_origin_attribute (origin);
3869 else
3871 tree type = TREE_TYPE (decl);
3873 name_and_src_coords_attributes (decl);
3874 inline_attribute (decl);
3875 prototyped_attribute (type);
3876 member_attribute (DECL_CONTEXT (decl));
3877 type_attribute (TREE_TYPE (type), 0, 0);
3878 pure_or_virtual_attribute (decl);
3880 if (DECL_ABSTRACT (decl))
3881 equate_decl_number_to_die_number (decl);
3882 else
3884 if (! DECL_EXTERNAL (decl) && ! in_class
3885 && decl == current_function_decl)
3887 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3889 low_pc_attribute (function_start_label (decl));
3890 sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no);
3891 high_pc_attribute (label);
3892 if (use_gnu_debug_info_extensions)
3894 sprintf (label, BODY_BEGIN_LABEL_FMT,
3895 current_function_funcdef_no);
3896 body_begin_attribute (label);
3897 sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no);
3898 body_end_attribute (label);
3904 /* Output a DIE to represent a declared data object (either file-scope
3905 or block-local) which has "external linkage" (according to ANSI-C). */
3907 static void
3908 output_global_variable_die (arg)
3909 void *arg;
3911 tree decl = arg;
3912 tree origin = decl_ultimate_origin (decl);
3914 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3915 sibling_attribute ();
3916 if (origin != NULL)
3917 abstract_origin_attribute (origin);
3918 else
3920 name_and_src_coords_attributes (decl);
3921 member_attribute (DECL_CONTEXT (decl));
3922 type_attribute (TREE_TYPE (decl),
3923 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3925 if (DECL_ABSTRACT (decl))
3926 equate_decl_number_to_die_number (decl);
3927 else
3929 if (! DECL_EXTERNAL (decl) && ! in_class
3930 && current_function_decl == decl_function_context (decl))
3931 location_or_const_value_attribute (decl);
3935 static void
3936 output_label_die (arg)
3937 void *arg;
3939 tree decl = arg;
3940 tree origin = decl_ultimate_origin (decl);
3942 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3943 sibling_attribute ();
3944 if (origin != NULL)
3945 abstract_origin_attribute (origin);
3946 else
3947 name_and_src_coords_attributes (decl);
3948 if (DECL_ABSTRACT (decl))
3949 equate_decl_number_to_die_number (decl);
3950 else
3952 rtx insn = DECL_RTL (decl);
3954 /* Deleted labels are programmer specified labels which have been
3955 eliminated because of various optimisations. We still emit them
3956 here so that it is possible to put breakpoints on them. */
3957 if (GET_CODE (insn) == CODE_LABEL
3958 || ((GET_CODE (insn) == NOTE
3959 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
3961 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3963 /* When optimization is enabled (via -O) some parts of the compiler
3964 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3965 represent source-level labels which were explicitly declared by
3966 the user. This really shouldn't be happening though, so catch
3967 it if it ever does happen. */
3969 if (INSN_DELETED_P (insn))
3970 abort (); /* Should never happen. */
3972 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
3973 low_pc_attribute (label);
3978 static void
3979 output_lexical_block_die (arg)
3980 void *arg;
3982 tree stmt = arg;
3984 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3985 sibling_attribute ();
3986 dienum_push ();
3987 if (! BLOCK_ABSTRACT (stmt))
3989 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3990 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3992 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3993 low_pc_attribute (begin_label);
3994 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3995 high_pc_attribute (end_label);
3999 static void
4000 output_inlined_subroutine_die (arg)
4001 void *arg;
4003 tree stmt = arg;
4005 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
4006 sibling_attribute ();
4007 dienum_push ();
4008 abstract_origin_attribute (block_ultimate_origin (stmt));
4009 if (! BLOCK_ABSTRACT (stmt))
4011 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4012 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4014 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4015 low_pc_attribute (begin_label);
4016 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4017 high_pc_attribute (end_label);
4021 /* Output a DIE to represent a declared data object (either file-scope
4022 or block-local) which has "internal linkage" (according to ANSI-C). */
4024 static void
4025 output_local_variable_die (arg)
4026 void *arg;
4028 tree decl = arg;
4029 tree origin = decl_ultimate_origin (decl);
4031 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
4032 sibling_attribute ();
4033 if (origin != NULL)
4034 abstract_origin_attribute (origin);
4035 else
4037 name_and_src_coords_attributes (decl);
4038 member_attribute (DECL_CONTEXT (decl));
4039 type_attribute (TREE_TYPE (decl),
4040 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4042 if (DECL_ABSTRACT (decl))
4043 equate_decl_number_to_die_number (decl);
4044 else
4045 location_or_const_value_attribute (decl);
4048 static void
4049 output_member_die (arg)
4050 void *arg;
4052 tree decl = arg;
4054 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
4055 sibling_attribute ();
4056 name_and_src_coords_attributes (decl);
4057 member_attribute (DECL_CONTEXT (decl));
4058 type_attribute (member_declared_type (decl),
4059 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4060 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
4062 byte_size_attribute (decl);
4063 bit_size_attribute (decl);
4064 bit_offset_attribute (decl);
4066 data_member_location_attribute (decl);
4069 #if 0
4070 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
4071 modified types instead.
4073 We keep this code here just in case these types of DIEs may be
4074 needed to represent certain things in other languages (e.g. Pascal)
4075 someday. */
4077 static void
4078 output_pointer_type_die (arg)
4079 void *arg;
4081 tree type = arg;
4083 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
4084 sibling_attribute ();
4085 equate_type_number_to_die_number (type);
4086 member_attribute (TYPE_CONTEXT (type));
4087 type_attribute (TREE_TYPE (type), 0, 0);
4090 static void
4091 output_reference_type_die (arg)
4092 void *arg;
4094 tree type = arg;
4096 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
4097 sibling_attribute ();
4098 equate_type_number_to_die_number (type);
4099 member_attribute (TYPE_CONTEXT (type));
4100 type_attribute (TREE_TYPE (type), 0, 0);
4102 #endif
4104 static void
4105 output_ptr_to_mbr_type_die (arg)
4106 void *arg;
4108 tree type = arg;
4110 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
4111 sibling_attribute ();
4112 equate_type_number_to_die_number (type);
4113 member_attribute (TYPE_CONTEXT (type));
4114 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
4115 type_attribute (TREE_TYPE (type), 0, 0);
4118 static void
4119 output_compile_unit_die (arg)
4120 void *arg;
4122 const char *main_input_filename = arg;
4123 const char *language_string = lang_hooks.name;
4125 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
4126 sibling_attribute ();
4127 dienum_push ();
4128 name_attribute (main_input_filename);
4131 char producer[250];
4133 sprintf (producer, "%s %s", language_string, version_string);
4134 producer_attribute (producer);
4137 if (strcmp (language_string, "GNU C++") == 0)
4138 language_attribute (LANG_C_PLUS_PLUS);
4139 else if (strcmp (language_string, "GNU Ada") == 0)
4140 language_attribute (LANG_ADA83);
4141 else if (strcmp (language_string, "GNU F77") == 0)
4142 language_attribute (LANG_FORTRAN77);
4143 else if (strcmp (language_string, "GNU Pascal") == 0)
4144 language_attribute (LANG_PASCAL83);
4145 else if (strcmp (language_string, "GNU Java") == 0)
4146 language_attribute (LANG_JAVA);
4147 else
4148 language_attribute (LANG_C89);
4149 low_pc_attribute (TEXT_BEGIN_LABEL);
4150 high_pc_attribute (TEXT_END_LABEL);
4151 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4152 stmt_list_attribute (LINE_BEGIN_LABEL);
4155 const char *wd = getpwd ();
4156 if (wd)
4157 comp_dir_attribute (wd);
4160 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
4162 sf_names_attribute (SFNAMES_BEGIN_LABEL);
4163 src_info_attribute (SRCINFO_BEGIN_LABEL);
4164 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4165 mac_info_attribute (MACINFO_BEGIN_LABEL);
4169 static void
4170 output_string_type_die (arg)
4171 void *arg;
4173 tree type = arg;
4175 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
4176 sibling_attribute ();
4177 equate_type_number_to_die_number (type);
4178 member_attribute (TYPE_CONTEXT (type));
4179 /* this is a fixed length string */
4180 byte_size_attribute (type);
4183 static void
4184 output_inheritance_die (arg)
4185 void *arg;
4187 tree binfo = arg;
4189 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
4190 sibling_attribute ();
4191 type_attribute (BINFO_TYPE (binfo), 0, 0);
4192 data_member_location_attribute (binfo);
4193 if (TREE_VIA_VIRTUAL (binfo))
4195 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
4196 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4198 if (TREE_VIA_PUBLIC (binfo))
4200 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
4201 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4203 else if (TREE_VIA_PROTECTED (binfo))
4205 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
4206 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4210 static void
4211 output_structure_type_die (arg)
4212 void *arg;
4214 tree type = arg;
4216 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
4217 sibling_attribute ();
4218 equate_type_number_to_die_number (type);
4219 name_attribute (type_tag (type));
4220 member_attribute (TYPE_CONTEXT (type));
4222 /* If this type has been completed, then give it a byte_size attribute
4223 and prepare to give a list of members. Otherwise, don't do either of
4224 these things. In the latter case, we will not be generating a list
4225 of members (since we don't have any idea what they might be for an
4226 incomplete type). */
4228 if (COMPLETE_TYPE_P (type))
4230 dienum_push ();
4231 byte_size_attribute (type);
4235 /* Output a DIE to represent a declared function (either file-scope
4236 or block-local) which has "internal linkage" (according to ANSI-C). */
4238 static void
4239 output_local_subroutine_die (arg)
4240 void *arg;
4242 tree decl = arg;
4243 tree origin = decl_ultimate_origin (decl);
4245 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
4246 sibling_attribute ();
4247 dienum_push ();
4248 if (origin != NULL)
4249 abstract_origin_attribute (origin);
4250 else
4252 tree type = TREE_TYPE (decl);
4254 name_and_src_coords_attributes (decl);
4255 inline_attribute (decl);
4256 prototyped_attribute (type);
4257 member_attribute (DECL_CONTEXT (decl));
4258 type_attribute (TREE_TYPE (type), 0, 0);
4259 pure_or_virtual_attribute (decl);
4261 if (DECL_ABSTRACT (decl))
4262 equate_decl_number_to_die_number (decl);
4263 else
4265 /* Avoid getting screwed up in cases where a function was declared
4266 static but where no definition was ever given for it. */
4268 if (TREE_ASM_WRITTEN (decl))
4270 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4271 low_pc_attribute (function_start_label (decl));
4272 sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no);
4273 high_pc_attribute (label);
4274 if (use_gnu_debug_info_extensions)
4276 sprintf (label, BODY_BEGIN_LABEL_FMT,
4277 current_function_funcdef_no);
4278 body_begin_attribute (label);
4279 sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no);
4280 body_end_attribute (label);
4286 static void
4287 output_subroutine_type_die (arg)
4288 void *arg;
4290 tree type = arg;
4291 tree return_type = TREE_TYPE (type);
4293 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
4294 sibling_attribute ();
4295 dienum_push ();
4296 equate_type_number_to_die_number (type);
4297 prototyped_attribute (type);
4298 member_attribute (TYPE_CONTEXT (type));
4299 type_attribute (return_type, 0, 0);
4302 static void
4303 output_typedef_die (arg)
4304 void *arg;
4306 tree decl = arg;
4307 tree origin = decl_ultimate_origin (decl);
4309 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
4310 sibling_attribute ();
4311 if (origin != NULL)
4312 abstract_origin_attribute (origin);
4313 else
4315 name_and_src_coords_attributes (decl);
4316 member_attribute (DECL_CONTEXT (decl));
4317 type_attribute (TREE_TYPE (decl),
4318 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4320 if (DECL_ABSTRACT (decl))
4321 equate_decl_number_to_die_number (decl);
4324 static void
4325 output_union_type_die (arg)
4326 void *arg;
4328 tree type = arg;
4330 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
4331 sibling_attribute ();
4332 equate_type_number_to_die_number (type);
4333 name_attribute (type_tag (type));
4334 member_attribute (TYPE_CONTEXT (type));
4336 /* If this type has been completed, then give it a byte_size attribute
4337 and prepare to give a list of members. Otherwise, don't do either of
4338 these things. In the latter case, we will not be generating a list
4339 of members (since we don't have any idea what they might be for an
4340 incomplete type). */
4342 if (COMPLETE_TYPE_P (type))
4344 dienum_push ();
4345 byte_size_attribute (type);
4349 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
4350 at the end of an (ANSI prototyped) formal parameters list. */
4352 static void
4353 output_unspecified_parameters_die (arg)
4354 void *arg;
4356 tree decl_or_type = arg;
4358 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
4359 sibling_attribute ();
4361 /* This kludge is here only for the sake of being compatible with what
4362 the USL CI5 C compiler does. The specification of Dwarf Version 1
4363 doesn't say that TAG_unspecified_parameters DIEs should contain any
4364 attributes other than the AT_sibling attribute, but they are certainly
4365 allowed to contain additional attributes, and the CI5 compiler
4366 generates AT_name, AT_fund_type, and AT_location attributes within
4367 TAG_unspecified_parameters DIEs which appear in the child lists for
4368 DIEs representing function definitions, so we do likewise here. */
4370 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
4372 name_attribute ("...");
4373 fund_type_attribute (FT_pointer);
4374 /* location_attribute (?); */
4378 static void
4379 output_padded_null_die (arg)
4380 void *arg ATTRIBUTE_UNUSED;
4382 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
4385 /*************************** end of DIEs *********************************/
4387 /* Generate some type of DIE. This routine generates the generic outer
4388 wrapper stuff which goes around all types of DIE's (regardless of their
4389 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
4390 DIE-length word, followed by the guts of the DIE itself. After the guts
4391 of the DIE, there must always be a terminator label for the DIE. */
4393 static void
4394 output_die (die_specific_output_function, param)
4395 void (*die_specific_output_function) PARAMS ((void *));
4396 void *param;
4398 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4399 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4401 current_dienum = NEXT_DIE_NUM;
4402 NEXT_DIE_NUM = next_unused_dienum;
4404 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4405 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4407 /* Write a label which will act as the name for the start of this DIE. */
4409 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4411 /* Write the DIE-length word. */
4413 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4415 /* Fill in the guts of the DIE. */
4417 next_unused_dienum++;
4418 die_specific_output_function (param);
4420 /* Write a label which will act as the name for the end of this DIE. */
4422 ASM_OUTPUT_LABEL (asm_out_file, end_label);
4425 static void
4426 end_sibling_chain ()
4428 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4430 current_dienum = NEXT_DIE_NUM;
4431 NEXT_DIE_NUM = next_unused_dienum;
4433 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4435 /* Write a label which will act as the name for the start of this DIE. */
4437 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4439 /* Write the DIE-length word. */
4441 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4443 dienum_pop ();
4446 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4447 TAG_unspecified_parameters DIE) to represent the types of the formal
4448 parameters as specified in some function type specification (except
4449 for those which appear as part of a function *definition*).
4451 Note that we must be careful here to output all of the parameter
4452 DIEs *before* we output any DIEs needed to represent the types of
4453 the formal parameters. This keeps svr4 SDB happy because it
4454 (incorrectly) thinks that the first non-parameter DIE it sees ends
4455 the formal parameter list. */
4457 static void
4458 output_formal_types (function_or_method_type)
4459 tree function_or_method_type;
4461 tree link;
4462 tree formal_type = NULL;
4463 tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4465 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4466 get bogus recursion when outputting tagged types local to a
4467 function declaration. */
4468 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4469 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4471 /* In the case where we are generating a formal types list for a C++
4472 non-static member function type, skip over the first thing on the
4473 TYPE_ARG_TYPES list because it only represents the type of the
4474 hidden `this pointer'. The debugger should be able to figure
4475 out (without being explicitly told) that this non-static member
4476 function type takes a `this pointer' and should be able to figure
4477 what the type of that hidden parameter is from the AT_member
4478 attribute of the parent TAG_subroutine_type DIE. */
4480 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4481 first_parm_type = TREE_CHAIN (first_parm_type);
4483 /* Make our first pass over the list of formal parameter types and output
4484 a TAG_formal_parameter DIE for each one. */
4486 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4488 formal_type = TREE_VALUE (link);
4489 if (formal_type == void_type_node)
4490 break;
4492 /* Output a (nameless) DIE to represent the formal parameter itself. */
4494 output_die (output_formal_parameter_die, formal_type);
4497 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4498 DIE to the end of the parameter list. */
4500 if (formal_type != void_type_node)
4501 output_die (output_unspecified_parameters_die, function_or_method_type);
4503 /* Make our second (and final) pass over the list of formal parameter types
4504 and output DIEs to represent those types (as necessary). */
4506 for (link = TYPE_ARG_TYPES (function_or_method_type);
4507 link;
4508 link = TREE_CHAIN (link))
4510 formal_type = TREE_VALUE (link);
4511 if (formal_type == void_type_node)
4512 break;
4514 output_type (formal_type, function_or_method_type);
4517 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4520 /* Remember a type in the pending_types_list. */
4522 static void
4523 pend_type (type)
4524 tree type;
4526 if (pending_types == pending_types_allocated)
4528 pending_types_allocated += PENDING_TYPES_INCREMENT;
4529 pending_types_list
4530 = (tree *) xrealloc (pending_types_list,
4531 sizeof (tree) * pending_types_allocated);
4533 pending_types_list[pending_types++] = type;
4535 /* Mark the pending type as having been output already (even though
4536 it hasn't been). This prevents the type from being added to the
4537 pending_types_list more than once. */
4539 TREE_ASM_WRITTEN (type) = 1;
4542 /* Return non-zero if it is legitimate to output DIEs to represent a
4543 given type while we are generating the list of child DIEs for some
4544 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4546 See the comments within the function for a description of when it is
4547 considered legitimate to output DIEs for various kinds of types.
4549 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4550 or it may point to a BLOCK node (for types local to a block), or to a
4551 FUNCTION_DECL node (for types local to the heading of some function
4552 definition), or to a FUNCTION_TYPE node (for types local to the
4553 prototyped parameter list of a function type specification), or to a
4554 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4555 (in the case of C++ nested types).
4557 The `scope' parameter should likewise be NULL or should point to a
4558 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4559 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4561 This function is used only for deciding when to "pend" and when to
4562 "un-pend" types to/from the pending_types_list.
4564 Note that we sometimes make use of this "type pending" feature in a
4565 rather twisted way to temporarily delay the production of DIEs for the
4566 types of formal parameters. (We do this just to make svr4 SDB happy.)
4567 It order to delay the production of DIEs representing types of formal
4568 parameters, callers of this function supply `fake_containing_scope' as
4569 the `scope' parameter to this function. Given that fake_containing_scope
4570 is a tagged type which is *not* the containing scope for *any* other type,
4571 the desired effect is achieved, i.e. output of DIEs representing types
4572 is temporarily suspended, and any type DIEs which would have otherwise
4573 been output are instead placed onto the pending_types_list. Later on,
4574 we force these (temporarily pended) types to be output simply by calling
4575 `output_pending_types_for_scope' with an actual argument equal to the
4576 true scope of the types we temporarily pended. */
4578 static inline int
4579 type_ok_for_scope (type, scope)
4580 tree type;
4581 tree scope;
4583 /* Tagged types (i.e. struct, union, and enum types) must always be
4584 output only in the scopes where they actually belong (or else the
4585 scoping of their own tag names and the scoping of their member
4586 names will be incorrect). Non-tagged-types on the other hand can
4587 generally be output anywhere, except that svr4 SDB really doesn't
4588 want to see them nested within struct or union types, so here we
4589 say it is always OK to immediately output any such a (non-tagged)
4590 type, so long as we are not within such a context. Note that the
4591 only kinds of non-tagged types which we will be dealing with here
4592 (for C and C++ anyway) will be array types and function types. */
4594 return is_tagged_type (type)
4595 ? (TYPE_CONTEXT (type) == scope
4596 /* Ignore namespaces for the moment. */
4597 || (scope == NULL_TREE
4598 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4599 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4600 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4601 : (scope == NULL_TREE || ! is_tagged_type (scope));
4604 /* Output any pending types (from the pending_types list) which we can output
4605 now (taking into account the scope that we are working on now).
4607 For each type output, remove the given type from the pending_types_list
4608 *before* we try to output it.
4610 Note that we have to process the list in beginning-to-end order,
4611 because the call made here to output_type may cause yet more types
4612 to be added to the end of the list, and we may have to output some
4613 of them too. */
4615 static void
4616 output_pending_types_for_scope (containing_scope)
4617 tree containing_scope;
4619 unsigned i;
4621 for (i = 0; i < pending_types; )
4623 tree type = pending_types_list[i];
4625 if (type_ok_for_scope (type, containing_scope))
4627 tree *mover;
4628 tree *limit;
4630 pending_types--;
4631 limit = &pending_types_list[pending_types];
4632 for (mover = &pending_types_list[i]; mover < limit; mover++)
4633 *mover = *(mover+1);
4635 /* Un-mark the type as having been output already (because it
4636 hasn't been, really). Then call output_type to generate a
4637 Dwarf representation of it. */
4639 TREE_ASM_WRITTEN (type) = 0;
4640 output_type (type, containing_scope);
4642 /* Don't increment the loop counter in this case because we
4643 have shifted all of the subsequent pending types down one
4644 element in the pending_types_list array. */
4646 else
4647 i++;
4651 /* Remember a type in the incomplete_types_list. */
4653 static void
4654 add_incomplete_type (type)
4655 tree type;
4657 if (incomplete_types == incomplete_types_allocated)
4659 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4660 incomplete_types_list
4661 = (tree *) xrealloc (incomplete_types_list,
4662 sizeof (tree) * incomplete_types_allocated);
4665 incomplete_types_list[incomplete_types++] = type;
4668 /* Walk through the list of incomplete types again, trying once more to
4669 emit full debugging info for them. */
4671 static void
4672 retry_incomplete_types ()
4674 tree type;
4676 finalizing = 1;
4677 while (incomplete_types)
4679 --incomplete_types;
4680 type = incomplete_types_list[incomplete_types];
4681 output_type (type, NULL_TREE);
4685 static void
4686 output_type (type, containing_scope)
4687 tree type;
4688 tree containing_scope;
4690 if (type == 0 || type == error_mark_node)
4691 return;
4693 /* We are going to output a DIE to represent the unqualified version of
4694 this type (i.e. without any const or volatile qualifiers) so get
4695 the main variant (i.e. the unqualified version) of this type now. */
4697 type = type_main_variant (type);
4699 if (TREE_ASM_WRITTEN (type))
4701 if (finalizing && AGGREGATE_TYPE_P (type))
4703 tree member;
4705 /* Some of our nested types might not have been defined when we
4706 were written out before; force them out now. */
4708 for (member = TYPE_FIELDS (type); member;
4709 member = TREE_CHAIN (member))
4710 if (TREE_CODE (member) == TYPE_DECL
4711 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4712 output_type (TREE_TYPE (member), containing_scope);
4714 return;
4717 /* If this is a nested type whose containing class hasn't been
4718 written out yet, writing it out will cover this one, too. */
4720 if (TYPE_CONTEXT (type)
4721 && TYPE_P (TYPE_CONTEXT (type))
4722 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4724 output_type (TYPE_CONTEXT (type), containing_scope);
4725 return;
4728 /* Don't generate any DIEs for this type now unless it is OK to do so
4729 (based upon what `type_ok_for_scope' tells us). */
4731 if (! type_ok_for_scope (type, containing_scope))
4733 pend_type (type);
4734 return;
4737 switch (TREE_CODE (type))
4739 case ERROR_MARK:
4740 break;
4742 case VECTOR_TYPE:
4743 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4744 break;
4746 case POINTER_TYPE:
4747 case REFERENCE_TYPE:
4748 /* Prevent infinite recursion in cases where this is a recursive
4749 type. Recursive types are possible in Ada. */
4750 TREE_ASM_WRITTEN (type) = 1;
4751 /* For these types, all that is required is that we output a DIE
4752 (or a set of DIEs) to represent the "basis" type. */
4753 output_type (TREE_TYPE (type), containing_scope);
4754 break;
4756 case OFFSET_TYPE:
4757 /* This code is used for C++ pointer-to-data-member types. */
4758 /* Output a description of the relevant class type. */
4759 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4760 /* Output a description of the type of the object pointed to. */
4761 output_type (TREE_TYPE (type), containing_scope);
4762 /* Now output a DIE to represent this pointer-to-data-member type
4763 itself. */
4764 output_die (output_ptr_to_mbr_type_die, type);
4765 break;
4767 case SET_TYPE:
4768 output_type (TYPE_DOMAIN (type), containing_scope);
4769 output_die (output_set_type_die, type);
4770 break;
4772 case FILE_TYPE:
4773 output_type (TREE_TYPE (type), containing_scope);
4774 abort (); /* No way to represent these in Dwarf yet! */
4775 break;
4777 case FUNCTION_TYPE:
4778 /* Force out return type (in case it wasn't forced out already). */
4779 output_type (TREE_TYPE (type), containing_scope);
4780 output_die (output_subroutine_type_die, type);
4781 output_formal_types (type);
4782 end_sibling_chain ();
4783 break;
4785 case METHOD_TYPE:
4786 /* Force out return type (in case it wasn't forced out already). */
4787 output_type (TREE_TYPE (type), containing_scope);
4788 output_die (output_subroutine_type_die, type);
4789 output_formal_types (type);
4790 end_sibling_chain ();
4791 break;
4793 case ARRAY_TYPE:
4794 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4796 output_type (TREE_TYPE (type), containing_scope);
4797 output_die (output_string_type_die, type);
4799 else
4801 tree element_type;
4803 element_type = TREE_TYPE (type);
4804 while (TREE_CODE (element_type) == ARRAY_TYPE)
4805 element_type = TREE_TYPE (element_type);
4807 output_type (element_type, containing_scope);
4808 output_die (output_array_type_die, type);
4810 break;
4812 case ENUMERAL_TYPE:
4813 case RECORD_TYPE:
4814 case UNION_TYPE:
4815 case QUAL_UNION_TYPE:
4817 /* For a non-file-scope tagged type, we can always go ahead and
4818 output a Dwarf description of this type right now, even if
4819 the type in question is still incomplete, because if this
4820 local type *was* ever completed anywhere within its scope,
4821 that complete definition would already have been attached to
4822 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4823 node by the time we reach this point. That's true because of the
4824 way the front-end does its processing of file-scope declarations (of
4825 functions and class types) within which other types might be
4826 nested. The C and C++ front-ends always gobble up such "local
4827 scope" things en-mass before they try to output *any* debugging
4828 information for any of the stuff contained inside them and thus,
4829 we get the benefit here of what is (in effect) a pre-resolution
4830 of forward references to tagged types in local scopes.
4832 Note however that for file-scope tagged types we cannot assume
4833 that such pre-resolution of forward references has taken place.
4834 A given file-scope tagged type may appear to be incomplete when
4835 we reach this point, but it may yet be given a full definition
4836 (at file-scope) later on during compilation. In order to avoid
4837 generating a premature (and possibly incorrect) set of Dwarf
4838 DIEs for such (as yet incomplete) file-scope tagged types, we
4839 generate nothing at all for as-yet incomplete file-scope tagged
4840 types here unless we are making our special "finalization" pass
4841 for file-scope things at the very end of compilation. At that
4842 time, we will certainly know as much about each file-scope tagged
4843 type as we are ever going to know, so at that point in time, we
4844 can safely generate correct Dwarf descriptions for these file-
4845 scope tagged types. */
4847 if (!COMPLETE_TYPE_P (type)
4848 && (TYPE_CONTEXT (type) == NULL
4849 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4850 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4851 && !finalizing)
4853 /* We don't need to do this for function-local types. */
4854 if (! decl_function_context (TYPE_STUB_DECL (type)))
4855 add_incomplete_type (type);
4856 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4859 /* Prevent infinite recursion in cases where the type of some
4860 member of this type is expressed in terms of this type itself. */
4862 TREE_ASM_WRITTEN (type) = 1;
4864 /* Output a DIE to represent the tagged type itself. */
4866 switch (TREE_CODE (type))
4868 case ENUMERAL_TYPE:
4869 output_die (output_enumeration_type_die, type);
4870 return; /* a special case -- nothing left to do so just return */
4872 case RECORD_TYPE:
4873 output_die (output_structure_type_die, type);
4874 break;
4876 case UNION_TYPE:
4877 case QUAL_UNION_TYPE:
4878 output_die (output_union_type_die, type);
4879 break;
4881 default:
4882 abort (); /* Should never happen. */
4885 /* If this is not an incomplete type, output descriptions of
4886 each of its members.
4888 Note that as we output the DIEs necessary to represent the
4889 members of this record or union type, we will also be trying
4890 to output DIEs to represent the *types* of those members.
4891 However the `output_type' function (above) will specifically
4892 avoid generating type DIEs for member types *within* the list
4893 of member DIEs for this (containing) type except for those
4894 types (of members) which are explicitly marked as also being
4895 members of this (containing) type themselves. The g++ front-
4896 end can force any given type to be treated as a member of some
4897 other (containing) type by setting the TYPE_CONTEXT of the
4898 given (member) type to point to the TREE node representing the
4899 appropriate (containing) type.
4902 if (COMPLETE_TYPE_P (type))
4904 /* First output info about the base classes. */
4905 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4907 register tree bases = TYPE_BINFO_BASETYPES (type);
4908 register int n_bases = TREE_VEC_LENGTH (bases);
4909 register int i;
4911 for (i = 0; i < n_bases; i++)
4913 tree binfo = TREE_VEC_ELT (bases, i);
4914 output_type (BINFO_TYPE (binfo), containing_scope);
4915 output_die (output_inheritance_die, binfo);
4919 ++in_class;
4922 tree normal_member;
4924 /* Now output info about the data members and type members. */
4926 for (normal_member = TYPE_FIELDS (type);
4927 normal_member;
4928 normal_member = TREE_CHAIN (normal_member))
4929 output_decl (normal_member, type);
4933 tree func_member;
4935 /* Now output info about the function members (if any). */
4937 for (func_member = TYPE_METHODS (type);
4938 func_member;
4939 func_member = TREE_CHAIN (func_member))
4941 /* Don't include clones in the member list. */
4942 if (DECL_ABSTRACT_ORIGIN (func_member))
4943 continue;
4945 output_decl (func_member, type);
4949 --in_class;
4951 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4952 scopes (at least in C++) so we must now output any nested
4953 pending types which are local just to this type. */
4955 output_pending_types_for_scope (type);
4957 end_sibling_chain (); /* Terminate member chain. */
4960 break;
4962 case VOID_TYPE:
4963 case INTEGER_TYPE:
4964 case REAL_TYPE:
4965 case COMPLEX_TYPE:
4966 case BOOLEAN_TYPE:
4967 case CHAR_TYPE:
4968 break; /* No DIEs needed for fundamental types. */
4970 case LANG_TYPE: /* No Dwarf representation currently defined. */
4971 break;
4973 default:
4974 abort ();
4977 TREE_ASM_WRITTEN (type) = 1;
4980 static void
4981 output_tagged_type_instantiation (type)
4982 tree type;
4984 if (type == 0 || type == error_mark_node)
4985 return;
4987 /* We are going to output a DIE to represent the unqualified version of
4988 this type (i.e. without any const or volatile qualifiers) so make
4989 sure that we have the main variant (i.e. the unqualified version) of
4990 this type now. */
4992 if (type != type_main_variant (type))
4993 abort ();
4995 if (!TREE_ASM_WRITTEN (type))
4996 abort ();
4998 switch (TREE_CODE (type))
5000 case ERROR_MARK:
5001 break;
5003 case ENUMERAL_TYPE:
5004 output_die (output_inlined_enumeration_type_die, type);
5005 break;
5007 case RECORD_TYPE:
5008 output_die (output_inlined_structure_type_die, type);
5009 break;
5011 case UNION_TYPE:
5012 case QUAL_UNION_TYPE:
5013 output_die (output_inlined_union_type_die, type);
5014 break;
5016 default:
5017 abort (); /* Should never happen. */
5021 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
5022 the things which are local to the given block. */
5024 static void
5025 output_block (stmt, depth)
5026 tree stmt;
5027 int depth;
5029 int must_output_die = 0;
5030 tree origin;
5031 enum tree_code origin_code;
5033 /* Ignore blocks never really used to make RTL. */
5035 if (! stmt || ! TREE_USED (stmt)
5036 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
5037 return;
5039 /* Determine the "ultimate origin" of this block. This block may be an
5040 inlined instance of an inlined instance of inline function, so we
5041 have to trace all of the way back through the origin chain to find
5042 out what sort of node actually served as the original seed for the
5043 creation of the current block. */
5045 origin = block_ultimate_origin (stmt);
5046 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
5048 /* Determine if we need to output any Dwarf DIEs at all to represent this
5049 block. */
5051 if (origin_code == FUNCTION_DECL)
5052 /* The outer scopes for inlinings *must* always be represented. We
5053 generate TAG_inlined_subroutine DIEs for them. (See below.) */
5054 must_output_die = 1;
5055 else
5057 /* In the case where the current block represents an inlining of the
5058 "body block" of an inline function, we must *NOT* output any DIE
5059 for this block because we have already output a DIE to represent
5060 the whole inlined function scope and the "body block" of any
5061 function doesn't really represent a different scope according to
5062 ANSI C rules. So we check here to make sure that this block does
5063 not represent a "body block inlining" before trying to set the
5064 `must_output_die' flag. */
5066 if (! is_body_block (origin ? origin : stmt))
5068 /* Determine if this block directly contains any "significant"
5069 local declarations which we will need to output DIEs for. */
5071 if (debug_info_level > DINFO_LEVEL_TERSE)
5072 /* We are not in terse mode so *any* local declaration counts
5073 as being a "significant" one. */
5074 must_output_die = (BLOCK_VARS (stmt) != NULL);
5075 else
5077 tree decl;
5079 /* We are in terse mode, so only local (nested) function
5080 definitions count as "significant" local declarations. */
5082 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5083 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
5085 must_output_die = 1;
5086 break;
5092 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
5093 DIE for any block which contains no significant local declarations
5094 at all. Rather, in such cases we just call `output_decls_for_scope'
5095 so that any needed Dwarf info for any sub-blocks will get properly
5096 generated. Note that in terse mode, our definition of what constitutes
5097 a "significant" local declaration gets restricted to include only
5098 inlined function instances and local (nested) function definitions. */
5100 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
5101 /* We don't care about an abstract inlined subroutine. */;
5102 else if (must_output_die)
5104 output_die ((origin_code == FUNCTION_DECL)
5105 ? output_inlined_subroutine_die
5106 : output_lexical_block_die,
5107 stmt);
5108 output_decls_for_scope (stmt, depth);
5109 end_sibling_chain ();
5111 else
5112 output_decls_for_scope (stmt, depth);
5115 /* Output all of the decls declared within a given scope (also called
5116 a `binding contour') and (recursively) all of it's sub-blocks. */
5118 static void
5119 output_decls_for_scope (stmt, depth)
5120 tree stmt;
5121 int depth;
5123 /* Ignore blocks never really used to make RTL. */
5125 if (! stmt || ! TREE_USED (stmt))
5126 return;
5128 /* Output the DIEs to represent all of the data objects, functions,
5129 typedefs, and tagged types declared directly within this block
5130 but not within any nested sub-blocks. */
5133 tree decl;
5135 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5136 output_decl (decl, stmt);
5139 output_pending_types_for_scope (stmt);
5141 /* Output the DIEs to represent all sub-blocks (and the items declared
5142 therein) of this block. */
5145 tree subblocks;
5147 for (subblocks = BLOCK_SUBBLOCKS (stmt);
5148 subblocks;
5149 subblocks = BLOCK_CHAIN (subblocks))
5150 output_block (subblocks, depth + 1);
5154 /* Is this a typedef we can avoid emitting? */
5156 static inline int
5157 is_redundant_typedef (decl)
5158 tree decl;
5160 if (TYPE_DECL_IS_STUB (decl))
5161 return 1;
5162 if (DECL_ARTIFICIAL (decl)
5163 && DECL_CONTEXT (decl)
5164 && is_tagged_type (DECL_CONTEXT (decl))
5165 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
5166 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
5167 /* Also ignore the artificial member typedef for the class name. */
5168 return 1;
5169 return 0;
5172 /* Output Dwarf .debug information for a decl described by DECL. */
5174 static void
5175 output_decl (decl, containing_scope)
5176 tree decl;
5177 tree containing_scope;
5179 /* Make a note of the decl node we are going to be working on. We may
5180 need to give the user the source coordinates of where it appeared in
5181 case we notice (later on) that something about it looks screwy. */
5183 dwarf_last_decl = decl;
5185 if (TREE_CODE (decl) == ERROR_MARK)
5186 return;
5188 /* If a structure is declared within an initialization, e.g. as the
5189 operand of a sizeof, then it will not have a name. We don't want
5190 to output a DIE for it, as the tree nodes are in the temporary obstack */
5192 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5193 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
5194 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
5195 || (TYPE_FIELDS (TREE_TYPE (decl))
5196 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
5197 return;
5199 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5201 if (DECL_IGNORED_P (decl))
5202 return;
5204 switch (TREE_CODE (decl))
5206 case CONST_DECL:
5207 /* The individual enumerators of an enum type get output when we
5208 output the Dwarf representation of the relevant enum type itself. */
5209 break;
5211 case FUNCTION_DECL:
5212 /* If we are in terse mode, don't output any DIEs to represent
5213 mere function declarations. Also, if we are conforming
5214 to the DWARF version 1 specification, don't output DIEs for
5215 mere function declarations. */
5217 if (DECL_INITIAL (decl) == NULL_TREE)
5218 #if (DWARF_VERSION > 1)
5219 if (debug_info_level <= DINFO_LEVEL_TERSE)
5220 #endif
5221 break;
5223 /* Before we describe the FUNCTION_DECL itself, make sure that we
5224 have described its return type. */
5226 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
5229 /* And its containing type. */
5230 register tree origin = decl_class_context (decl);
5231 if (origin)
5232 output_type (origin, containing_scope);
5235 /* If we're emitting an out-of-line copy of an inline function,
5236 set up to refer to the abstract instance emitted from
5237 dwarfout_deferred_inline_function. */
5238 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
5239 && ! (containing_scope && TYPE_P (containing_scope)))
5240 set_decl_origin_self (decl);
5242 /* If the following DIE will represent a function definition for a
5243 function with "extern" linkage, output a special "pubnames" DIE
5244 label just ahead of the actual DIE. A reference to this label
5245 was already generated in the .debug_pubnames section sub-entry
5246 for this function definition. */
5248 if (TREE_PUBLIC (decl))
5250 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5252 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5253 ASM_OUTPUT_LABEL (asm_out_file, label);
5256 /* Now output a DIE to represent the function itself. */
5258 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
5259 ? output_global_subroutine_die
5260 : output_local_subroutine_die,
5261 decl);
5263 /* Now output descriptions of the arguments for this function.
5264 This gets (unnecessarily?) complex because of the fact that
5265 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
5266 cases where there was a trailing `...' at the end of the formal
5267 parameter list. In order to find out if there was a trailing
5268 ellipsis or not, we must instead look at the type associated
5269 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
5270 If the chain of type nodes hanging off of this FUNCTION_TYPE node
5271 ends with a void_type_node then there should *not* be an ellipsis
5272 at the end. */
5274 /* In the case where we are describing a mere function declaration, all
5275 we need to do here (and all we *can* do here) is to describe
5276 the *types* of its formal parameters. */
5278 if (decl != current_function_decl || in_class)
5279 output_formal_types (TREE_TYPE (decl));
5280 else
5282 /* Generate DIEs to represent all known formal parameters */
5284 tree arg_decls = DECL_ARGUMENTS (decl);
5285 tree parm;
5287 /* WARNING! Kludge zone ahead! Here we have a special
5288 hack for svr4 SDB compatibility. Instead of passing the
5289 current FUNCTION_DECL node as the second parameter (i.e.
5290 the `containing_scope' parameter) to `output_decl' (as
5291 we ought to) we instead pass a pointer to our own private
5292 fake_containing_scope node. That node is a RECORD_TYPE
5293 node which NO OTHER TYPE may ever actually be a member of.
5295 This pointer will ultimately get passed into `output_type'
5296 as its `containing_scope' parameter. `Output_type' will
5297 then perform its part in the hack... i.e. it will pend
5298 the type of the formal parameter onto the pending_types
5299 list. Later on, when we are done generating the whole
5300 sequence of formal parameter DIEs for this function
5301 definition, we will un-pend all previously pended types
5302 of formal parameters for this function definition.
5304 This whole kludge prevents any type DIEs from being
5305 mixed in with the formal parameter DIEs. That's good
5306 because svr4 SDB believes that the list of formal
5307 parameter DIEs for a function ends wherever the first
5308 non-formal-parameter DIE appears. Thus, we have to
5309 keep the formal parameter DIEs segregated. They must
5310 all appear (consecutively) at the start of the list of
5311 children for the DIE representing the function definition.
5312 Then (and only then) may we output any additional DIEs
5313 needed to represent the types of these formal parameters.
5317 When generating DIEs, generate the unspecified_parameters
5318 DIE instead if we come across the arg "__builtin_va_alist"
5321 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
5322 if (TREE_CODE (parm) == PARM_DECL)
5324 if (DECL_NAME(parm) &&
5325 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
5326 "__builtin_va_alist") )
5327 output_die (output_unspecified_parameters_die, decl);
5328 else
5329 output_decl (parm, fake_containing_scope);
5333 Now that we have finished generating all of the DIEs to
5334 represent the formal parameters themselves, force out
5335 any DIEs needed to represent their types. We do this
5336 simply by un-pending all previously pended types which
5337 can legitimately go into the chain of children DIEs for
5338 the current FUNCTION_DECL.
5341 output_pending_types_for_scope (decl);
5344 Decide whether we need an unspecified_parameters DIE at the end.
5345 There are 2 more cases to do this for:
5346 1) the ansi ... declaration - this is detectable when the end
5347 of the arg list is not a void_type_node
5348 2) an unprototyped function declaration (not a definition). This
5349 just means that we have no info about the parameters at all.
5353 tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
5355 if (fn_arg_types)
5357 /* this is the prototyped case, check for ... */
5358 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
5359 output_die (output_unspecified_parameters_die, decl);
5361 else
5363 /* this is unprototyped, check for undefined (just declaration) */
5364 if (!DECL_INITIAL (decl))
5365 output_die (output_unspecified_parameters_die, decl);
5369 /* Output Dwarf info for all of the stuff within the body of the
5370 function (if it has one - it may be just a declaration). */
5373 tree outer_scope = DECL_INITIAL (decl);
5375 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
5377 /* Note that here, `outer_scope' is a pointer to the outermost
5378 BLOCK node created to represent a function.
5379 This outermost BLOCK actually represents the outermost
5380 binding contour for the function, i.e. the contour in which
5381 the function's formal parameters and labels get declared.
5383 Curiously, it appears that the front end doesn't actually
5384 put the PARM_DECL nodes for the current function onto the
5385 BLOCK_VARS list for this outer scope. (They are strung
5386 off of the DECL_ARGUMENTS list for the function instead.)
5387 The BLOCK_VARS list for the `outer_scope' does provide us
5388 with a list of the LABEL_DECL nodes for the function however,
5389 and we output DWARF info for those here.
5391 Just within the `outer_scope' there will be a BLOCK node
5392 representing the function's outermost pair of curly braces,
5393 and any blocks used for the base and member initializers of
5394 a C++ constructor function. */
5396 output_decls_for_scope (outer_scope, 0);
5398 /* Finally, force out any pending types which are local to the
5399 outermost block of this function definition. These will
5400 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
5401 node itself. */
5403 output_pending_types_for_scope (decl);
5408 /* Generate a terminator for the list of stuff `owned' by this
5409 function. */
5411 end_sibling_chain ();
5413 break;
5415 case TYPE_DECL:
5416 /* If we are in terse mode, don't generate any DIEs to represent
5417 any actual typedefs. Note that even when we are in terse mode,
5418 we must still output DIEs to represent those tagged types which
5419 are used (directly or indirectly) in the specification of either
5420 a return type or a formal parameter type of some function. */
5422 if (debug_info_level <= DINFO_LEVEL_TERSE)
5423 if (! TYPE_DECL_IS_STUB (decl)
5424 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5425 return;
5427 /* In the special case of a TYPE_DECL node representing
5428 the declaration of some type tag, if the given TYPE_DECL is
5429 marked as having been instantiated from some other (original)
5430 TYPE_DECL node (e.g. one which was generated within the original
5431 definition of an inline function) we have to generate a special
5432 (abbreviated) TAG_structure_type, TAG_union_type, or
5433 TAG_enumeration-type DIE here. */
5435 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5437 output_tagged_type_instantiation (TREE_TYPE (decl));
5438 return;
5441 output_type (TREE_TYPE (decl), containing_scope);
5443 if (! is_redundant_typedef (decl))
5444 /* Output a DIE to represent the typedef itself. */
5445 output_die (output_typedef_die, decl);
5446 break;
5448 case LABEL_DECL:
5449 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5450 output_die (output_label_die, decl);
5451 break;
5453 case VAR_DECL:
5454 /* If we are conforming to the DWARF version 1 specification, don't
5455 generated any DIEs to represent mere external object declarations. */
5457 #if (DWARF_VERSION <= 1)
5458 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5459 break;
5460 #endif
5462 /* If we are in terse mode, don't generate any DIEs to represent
5463 any variable declarations or definitions. */
5465 if (debug_info_level <= DINFO_LEVEL_TERSE)
5466 break;
5468 /* Output any DIEs that are needed to specify the type of this data
5469 object. */
5471 output_type (TREE_TYPE (decl), containing_scope);
5474 /* And its containing type. */
5475 register tree origin = decl_class_context (decl);
5476 if (origin)
5477 output_type (origin, containing_scope);
5480 /* If the following DIE will represent a data object definition for a
5481 data object with "extern" linkage, output a special "pubnames" DIE
5482 label just ahead of the actual DIE. A reference to this label
5483 was already generated in the .debug_pubnames section sub-entry
5484 for this data object definition. */
5486 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5488 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5490 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5491 ASM_OUTPUT_LABEL (asm_out_file, label);
5494 /* Now output the DIE to represent the data object itself. This gets
5495 complicated because of the possibility that the VAR_DECL really
5496 represents an inlined instance of a formal parameter for an inline
5497 function. */
5500 void (*func) PARAMS ((void *));
5501 register tree origin = decl_ultimate_origin (decl);
5503 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5504 func = output_formal_parameter_die;
5505 else
5507 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5508 func = output_global_variable_die;
5509 else
5510 func = output_local_variable_die;
5512 output_die (func, decl);
5514 break;
5516 case FIELD_DECL:
5517 /* Ignore the nameless fields that are used to skip bits. */
5518 if (DECL_NAME (decl) != 0)
5520 output_type (member_declared_type (decl), containing_scope);
5521 output_die (output_member_die, decl);
5523 break;
5525 case PARM_DECL:
5526 /* Force out the type of this formal, if it was not forced out yet.
5527 Note that here we can run afoul of a bug in "classic" svr4 SDB.
5528 It should be able to grok the presence of type DIEs within a list
5529 of TAG_formal_parameter DIEs, but it doesn't. */
5531 output_type (TREE_TYPE (decl), containing_scope);
5532 output_die (output_formal_parameter_die, decl);
5533 break;
5535 case NAMESPACE_DECL:
5536 /* Ignore for now. */
5537 break;
5539 default:
5540 abort ();
5544 /* Output debug information for a function. */
5545 static void
5546 dwarfout_function_decl (decl)
5547 tree decl;
5549 dwarfout_file_scope_decl (decl, 0);
5552 /* Debug information for a global DECL. Called from toplev.c after
5553 compilation proper has finished. */
5554 static void
5555 dwarfout_global_decl (decl)
5556 tree decl;
5558 /* Output DWARF information for file-scope tentative data object
5559 declarations, file-scope (extern) function declarations (which
5560 had no corresponding body) and file-scope tagged type
5561 declarations and definitions which have not yet been forced out. */
5563 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
5564 dwarfout_file_scope_decl (decl, 1);
5567 /* DECL is an inline function, whose body is present, but which is not
5568 being output at this point. (We're putting that off until we need
5569 to do it.) */
5570 static void
5571 dwarfout_deferred_inline_function (decl)
5572 tree decl;
5574 /* Generate the DWARF info for the "abstract" instance of a function
5575 which we may later generate inlined and/or out-of-line instances
5576 of. */
5577 if ((DECL_INLINE (decl) || DECL_ABSTRACT (decl))
5578 && ! DECL_ABSTRACT_ORIGIN (decl))
5580 /* The front-end may not have set CURRENT_FUNCTION_DECL, but the
5581 DWARF code expects it to be set in this case. Intuitively,
5582 DECL is the function we just finished defining, so setting
5583 CURRENT_FUNCTION_DECL is sensible. */
5584 tree saved_cfd = current_function_decl;
5585 int was_abstract = DECL_ABSTRACT (decl);
5586 current_function_decl = decl;
5588 /* Let the DWARF code do its work. */
5589 set_decl_abstract_flags (decl, 1);
5590 dwarfout_file_scope_decl (decl, 0);
5591 if (! was_abstract)
5592 set_decl_abstract_flags (decl, 0);
5594 /* Reset CURRENT_FUNCTION_DECL. */
5595 current_function_decl = saved_cfd;
5599 static void
5600 dwarfout_file_scope_decl (decl, set_finalizing)
5601 tree decl;
5602 int set_finalizing;
5604 if (TREE_CODE (decl) == ERROR_MARK)
5605 return;
5607 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5609 if (DECL_IGNORED_P (decl))
5610 return;
5612 switch (TREE_CODE (decl))
5614 case FUNCTION_DECL:
5616 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5617 a builtin function. Explicit programmer-supplied declarations of
5618 these same functions should NOT be ignored however. */
5620 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5621 return;
5623 /* What we would really like to do here is to filter out all mere
5624 file-scope declarations of file-scope functions which are never
5625 referenced later within this translation unit (and keep all of
5626 ones that *are* referenced later on) but we aren't clairvoyant,
5627 so we have no idea which functions will be referenced in the
5628 future (i.e. later on within the current translation unit).
5629 So here we just ignore all file-scope function declarations
5630 which are not also definitions. If and when the debugger needs
5631 to know something about these functions, it will have to hunt
5632 around and find the DWARF information associated with the
5633 *definition* of the function.
5635 Note that we can't just check `DECL_EXTERNAL' to find out which
5636 FUNCTION_DECL nodes represent definitions and which ones represent
5637 mere declarations. We have to check `DECL_INITIAL' instead. That's
5638 because the C front-end supports some weird semantics for "extern
5639 inline" function definitions. These can get inlined within the
5640 current translation unit (an thus, we need to generate DWARF info
5641 for their abstract instances so that the DWARF info for the
5642 concrete inlined instances can have something to refer to) but
5643 the compiler never generates any out-of-lines instances of such
5644 things (despite the fact that they *are* definitions). The
5645 important point is that the C front-end marks these "extern inline"
5646 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5647 anyway.
5649 Note that the C++ front-end also plays some similar games for inline
5650 function definitions appearing within include files which also
5651 contain `#pragma interface' pragmas. */
5653 if (DECL_INITIAL (decl) == NULL_TREE)
5654 return;
5656 if (TREE_PUBLIC (decl)
5657 && ! DECL_EXTERNAL (decl)
5658 && ! DECL_ABSTRACT (decl))
5660 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5662 /* Output a .debug_pubnames entry for a public function
5663 defined in this compilation unit. */
5665 fputc ('\n', asm_out_file);
5666 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5667 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5668 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5669 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5670 IDENTIFIER_POINTER (DECL_NAME (decl)));
5671 ASM_OUTPUT_POP_SECTION (asm_out_file);
5674 break;
5676 case VAR_DECL:
5678 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5679 object declaration and if the declaration was never even
5680 referenced from within this entire compilation unit. We
5681 suppress these DIEs in order to save space in the .debug section
5682 (by eliminating entries which are probably useless). Note that
5683 we must not suppress block-local extern declarations (whether
5684 used or not) because that would screw-up the debugger's name
5685 lookup mechanism and cause it to miss things which really ought
5686 to be in scope at a given point. */
5688 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5689 return;
5691 if (TREE_PUBLIC (decl)
5692 && ! DECL_EXTERNAL (decl)
5693 && GET_CODE (DECL_RTL (decl)) == MEM
5694 && ! DECL_ABSTRACT (decl))
5696 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5698 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5700 /* Output a .debug_pubnames entry for a public variable
5701 defined in this compilation unit. */
5703 fputc ('\n', asm_out_file);
5704 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5705 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5706 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5707 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5708 IDENTIFIER_POINTER (DECL_NAME (decl)));
5709 ASM_OUTPUT_POP_SECTION (asm_out_file);
5712 if (DECL_INITIAL (decl) == NULL)
5714 /* Output a .debug_aranges entry for a public variable
5715 which is tentatively defined in this compilation unit. */
5717 fputc ('\n', asm_out_file);
5718 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
5719 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5720 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5721 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5722 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5723 ASM_OUTPUT_POP_SECTION (asm_out_file);
5727 /* If we are in terse mode, don't generate any DIEs to represent
5728 any variable declarations or definitions. */
5730 if (debug_info_level <= DINFO_LEVEL_TERSE)
5731 return;
5733 break;
5735 case TYPE_DECL:
5736 /* Don't bother trying to generate any DIEs to represent any of the
5737 normal built-in types for the language we are compiling, except
5738 in cases where the types in question are *not* DWARF fundamental
5739 types. We make an exception in the case of non-fundamental types
5740 for the sake of objective C (and perhaps C++) because the GNU
5741 front-ends for these languages may in fact create certain "built-in"
5742 types which are (for example) RECORD_TYPEs. In such cases, we
5743 really need to output these (non-fundamental) types because other
5744 DIEs may contain references to them. */
5746 /* Also ignore language dependent types here, because they are probably
5747 also built-in types. If we didn't ignore them, then we would get
5748 references to undefined labels because output_type doesn't support
5749 them. So, for now, we need to ignore them to avoid assembler
5750 errors. */
5752 /* ??? This code is different than the equivalent code in dwarf2out.c.
5753 The dwarf2out.c code is probably more correct. */
5755 if (DECL_SOURCE_LINE (decl) == 0
5756 && (type_is_fundamental (TREE_TYPE (decl))
5757 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5758 return;
5760 /* If we are in terse mode, don't generate any DIEs to represent
5761 any actual typedefs. Note that even when we are in terse mode,
5762 we must still output DIEs to represent those tagged types which
5763 are used (directly or indirectly) in the specification of either
5764 a return type or a formal parameter type of some function. */
5766 if (debug_info_level <= DINFO_LEVEL_TERSE)
5767 if (! TYPE_DECL_IS_STUB (decl)
5768 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5769 return;
5771 break;
5773 default:
5774 return;
5777 fputc ('\n', asm_out_file);
5778 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5779 finalizing = set_finalizing;
5780 output_decl (decl, NULL_TREE);
5782 /* NOTE: The call above to `output_decl' may have caused one or more
5783 file-scope named types (i.e. tagged types) to be placed onto the
5784 pending_types_list. We have to get those types off of that list
5785 at some point, and this is the perfect time to do it. If we didn't
5786 take them off now, they might still be on the list when cc1 finally
5787 exits. That might be OK if it weren't for the fact that when we put
5788 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5789 for these types, and that causes them never to be output unless
5790 `output_pending_types_for_scope' takes them off of the list and un-sets
5791 their TREE_ASM_WRITTEN flags. */
5793 output_pending_types_for_scope (NULL_TREE);
5795 /* The above call should have totally emptied the pending_types_list
5796 if this is not a nested function or class. If this is a nested type,
5797 then the remaining pending_types will be emitted when the containing type
5798 is handled. */
5800 if (! DECL_CONTEXT (decl))
5802 if (pending_types != 0)
5803 abort ();
5806 ASM_OUTPUT_POP_SECTION (asm_out_file);
5809 /* Output a marker (i.e. a label) for the beginning of the generated code
5810 for a lexical block. */
5812 static void
5813 dwarfout_begin_block (line, blocknum)
5814 unsigned int line ATTRIBUTE_UNUSED;
5815 unsigned int blocknum;
5817 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5819 function_section (current_function_decl);
5820 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5821 ASM_OUTPUT_LABEL (asm_out_file, label);
5824 /* Output a marker (i.e. a label) for the end of the generated code
5825 for a lexical block. */
5827 static void
5828 dwarfout_end_block (line, blocknum)
5829 unsigned int line ATTRIBUTE_UNUSED;
5830 unsigned int blocknum;
5832 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5834 function_section (current_function_decl);
5835 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5836 ASM_OUTPUT_LABEL (asm_out_file, label);
5839 /* Output a marker (i.e. a label) for the point in the generated code where
5840 the real body of the function begins (after parameters have been moved
5841 to their home locations). */
5843 static void
5844 dwarfout_end_prologue (line)
5845 unsigned int line ATTRIBUTE_UNUSED;
5847 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5849 if (! use_gnu_debug_info_extensions)
5850 return;
5852 function_section (current_function_decl);
5853 sprintf (label, BODY_BEGIN_LABEL_FMT, current_function_funcdef_no);
5854 ASM_OUTPUT_LABEL (asm_out_file, label);
5857 /* Output a marker (i.e. a label) for the point in the generated code where
5858 the real body of the function ends (just before the epilogue code). */
5860 static void
5861 dwarfout_end_function (line)
5862 unsigned int line ATTRIBUTE_UNUSED;
5864 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5866 if (! use_gnu_debug_info_extensions)
5867 return;
5868 function_section (current_function_decl);
5869 sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no);
5870 ASM_OUTPUT_LABEL (asm_out_file, label);
5873 /* Output a marker (i.e. a label) for the absolute end of the generated code
5874 for a function definition. This gets called *after* the epilogue code
5875 has been generated. */
5877 static void
5878 dwarfout_end_epilogue ()
5880 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5882 /* Output a label to mark the endpoint of the code generated for this
5883 function. */
5885 sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no);
5886 ASM_OUTPUT_LABEL (asm_out_file, label);
5889 static void
5890 shuffle_filename_entry (new_zeroth)
5891 filename_entry *new_zeroth;
5893 filename_entry temp_entry;
5894 filename_entry *limit_p;
5895 filename_entry *move_p;
5897 if (new_zeroth == &filename_table[0])
5898 return;
5900 temp_entry = *new_zeroth;
5902 /* Shift entries up in the table to make room at [0]. */
5904 limit_p = &filename_table[0];
5905 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5906 *move_p = *(move_p-1);
5908 /* Install the found entry at [0]. */
5910 filename_table[0] = temp_entry;
5913 /* Create a new (string) entry for the .debug_sfnames section. */
5915 static void
5916 generate_new_sfname_entry ()
5918 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5920 fputc ('\n', asm_out_file);
5921 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
5922 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5923 ASM_OUTPUT_LABEL (asm_out_file, label);
5924 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5925 filename_table[0].name
5926 ? filename_table[0].name
5927 : "");
5928 ASM_OUTPUT_POP_SECTION (asm_out_file);
5931 /* Lookup a filename (in the list of filenames that we know about here in
5932 dwarfout.c) and return its "index". The index of each (known) filename
5933 is just a unique number which is associated with only that one filename.
5934 We need such numbers for the sake of generating labels (in the
5935 .debug_sfnames section) and references to those unique labels (in the
5936 .debug_srcinfo and .debug_macinfo sections).
5938 If the filename given as an argument is not found in our current list,
5939 add it to the list and assign it the next available unique index number.
5941 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5942 one), we shuffle the filename found (or added) up to the zeroth entry of
5943 our list of filenames (which is always searched linearly). We do this so
5944 as to optimize the most common case for these filename lookups within
5945 dwarfout.c. The most common case by far is the case where we call
5946 lookup_filename to lookup the very same filename that we did a lookup
5947 on the last time we called lookup_filename. We make sure that this
5948 common case is fast because such cases will constitute 99.9% of the
5949 lookups we ever do (in practice).
5951 If we add a new filename entry to our table, we go ahead and generate
5952 the corresponding entry in the .debug_sfnames section right away.
5953 Doing so allows us to avoid tickling an assembler bug (present in some
5954 m68k assemblers) which yields assembly-time errors in cases where the
5955 difference of two label addresses is taken and where the two labels
5956 are in a section *other* than the one where the difference is being
5957 calculated, and where at least one of the two symbol references is a
5958 forward reference. (This bug could be tickled by our .debug_srcinfo
5959 entries if we don't output their corresponding .debug_sfnames entries
5960 before them.) */
5962 static unsigned
5963 lookup_filename (file_name)
5964 const char *file_name;
5966 filename_entry *search_p;
5967 filename_entry *limit_p = &filename_table[ft_entries];
5969 for (search_p = filename_table; search_p < limit_p; search_p++)
5970 if (!strcmp (file_name, search_p->name))
5972 /* When we get here, we have found the filename that we were
5973 looking for in the filename_table. Now we want to make sure
5974 that it gets moved to the zero'th entry in the table (if it
5975 is not already there) so that subsequent attempts to find the
5976 same filename will find it as quickly as possible. */
5978 shuffle_filename_entry (search_p);
5979 return filename_table[0].number;
5982 /* We come here whenever we have a new filename which is not registered
5983 in the current table. Here we add it to the table. */
5985 /* Prepare to add a new table entry by making sure there is enough space
5986 in the table to do so. If not, expand the current table. */
5988 if (ft_entries == ft_entries_allocated)
5990 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5991 filename_table
5992 = (filename_entry *)
5993 xrealloc (filename_table,
5994 ft_entries_allocated * sizeof (filename_entry));
5997 /* Initially, add the new entry at the end of the filename table. */
5999 filename_table[ft_entries].number = ft_entries;
6000 filename_table[ft_entries].name = xstrdup (file_name);
6002 /* Shuffle the new entry into filename_table[0]. */
6004 shuffle_filename_entry (&filename_table[ft_entries]);
6006 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6007 generate_new_sfname_entry ();
6009 ft_entries++;
6010 return filename_table[0].number;
6013 static void
6014 generate_srcinfo_entry (line_entry_num, files_entry_num)
6015 unsigned line_entry_num;
6016 unsigned files_entry_num;
6018 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6020 fputc ('\n', asm_out_file);
6021 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6022 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
6023 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
6024 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
6025 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
6026 ASM_OUTPUT_POP_SECTION (asm_out_file);
6029 static void
6030 dwarfout_source_line (line, filename)
6031 unsigned int line;
6032 const char *filename;
6034 if (debug_info_level >= DINFO_LEVEL_NORMAL
6035 /* We can't emit line number info for functions in separate sections,
6036 because the assembler can't subtract labels in different sections. */
6037 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
6039 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6040 static unsigned last_line_entry_num = 0;
6041 static unsigned prev_file_entry_num = (unsigned) -1;
6042 unsigned this_file_entry_num;
6044 function_section (current_function_decl);
6045 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
6046 ASM_OUTPUT_LABEL (asm_out_file, label);
6048 fputc ('\n', asm_out_file);
6050 if (use_gnu_debug_info_extensions)
6051 this_file_entry_num = lookup_filename (filename);
6052 else
6053 this_file_entry_num = (unsigned) -1;
6055 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6056 if (this_file_entry_num != prev_file_entry_num)
6058 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
6060 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
6061 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
6065 const char *tail = strrchr (filename, '/');
6067 if (tail != NULL)
6068 filename = tail;
6071 dw2_asm_output_data (4, line, "%s:%u", filename, line);
6072 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6073 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
6074 ASM_OUTPUT_POP_SECTION (asm_out_file);
6076 if (this_file_entry_num != prev_file_entry_num)
6077 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
6078 prev_file_entry_num = this_file_entry_num;
6082 /* Generate an entry in the .debug_macinfo section. */
6084 static void
6085 generate_macinfo_entry (type, offset, string)
6086 unsigned int type;
6087 rtx offset;
6088 const char *string;
6090 if (! use_gnu_debug_info_extensions)
6091 return;
6093 fputc ('\n', asm_out_file);
6094 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6095 assemble_integer (gen_rtx_PLUS (SImode, GEN_INT (type << 24), offset),
6096 4, BITS_PER_UNIT, 1);
6097 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
6098 ASM_OUTPUT_POP_SECTION (asm_out_file);
6101 /* Wrapper for toplev.c callback to check debug info level. */
6102 static void
6103 dwarfout_start_source_file_check (line, filename)
6104 unsigned int line;
6105 const char *filename;
6107 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6108 dwarfout_start_source_file (line, filename);
6111 static void
6112 dwarfout_start_source_file (line, filename)
6113 unsigned int line ATTRIBUTE_UNUSED;
6114 const char *filename;
6116 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6117 const char *label1, *label2;
6119 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
6120 label1 = (*label == '*') + label;
6121 label2 = (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL;
6122 generate_macinfo_entry (MACINFO_start,
6123 gen_rtx_MINUS (Pmode,
6124 gen_rtx_SYMBOL_REF (Pmode, label1),
6125 gen_rtx_SYMBOL_REF (Pmode, label2)),
6126 "");
6129 /* Wrapper for toplev.c callback to check debug info level. */
6130 static void
6131 dwarfout_end_source_file_check (lineno)
6132 unsigned lineno;
6134 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6135 dwarfout_end_source_file (lineno);
6138 static void
6139 dwarfout_end_source_file (lineno)
6140 unsigned lineno;
6142 generate_macinfo_entry (MACINFO_resume, GEN_INT (lineno), "");
6145 /* Called from check_newline in c-parse.y. The `buffer' parameter
6146 contains the tail part of the directive line, i.e. the part which
6147 is past the initial whitespace, #, whitespace, directive-name,
6148 whitespace part. */
6150 static void
6151 dwarfout_define (lineno, buffer)
6152 unsigned lineno;
6153 const char *buffer;
6155 static int initialized = 0;
6157 if (!initialized)
6159 dwarfout_start_source_file (0, primary_filename);
6160 initialized = 1;
6162 generate_macinfo_entry (MACINFO_define, GEN_INT (lineno), buffer);
6165 /* Called from check_newline in c-parse.y. The `buffer' parameter
6166 contains the tail part of the directive line, i.e. the part which
6167 is past the initial whitespace, #, whitespace, directive-name,
6168 whitespace part. */
6170 static void
6171 dwarfout_undef (lineno, buffer)
6172 unsigned lineno;
6173 const char *buffer;
6175 generate_macinfo_entry (MACINFO_undef, GEN_INT (lineno), buffer);
6178 /* Set up for Dwarf output at the start of compilation. */
6180 static void
6181 dwarfout_init (main_input_filename)
6182 const char *main_input_filename;
6184 /* Remember the name of the primary input file. */
6186 primary_filename = main_input_filename;
6188 /* Allocate the initial hunk of the pending_sibling_stack. */
6190 pending_sibling_stack
6191 = (unsigned *)
6192 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
6193 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
6194 pending_siblings = 1;
6196 /* Allocate the initial hunk of the filename_table. */
6198 filename_table
6199 = (filename_entry *)
6200 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
6201 ft_entries_allocated = FT_ENTRIES_INCREMENT;
6202 ft_entries = 0;
6204 /* Allocate the initial hunk of the pending_types_list. */
6206 pending_types_list
6207 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
6208 pending_types_allocated = PENDING_TYPES_INCREMENT;
6209 pending_types = 0;
6211 /* Create an artificial RECORD_TYPE node which we can use in our hack
6212 to get the DIEs representing types of formal parameters to come out
6213 only *after* the DIEs for the formal parameters themselves. */
6215 fake_containing_scope = make_node (RECORD_TYPE);
6217 /* Output a starting label for the .text section. */
6219 fputc ('\n', asm_out_file);
6220 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6221 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
6222 ASM_OUTPUT_POP_SECTION (asm_out_file);
6224 /* Output a starting label for the .data section. */
6226 fputc ('\n', asm_out_file);
6227 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6228 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
6229 ASM_OUTPUT_POP_SECTION (asm_out_file);
6231 #if 0 /* GNU C doesn't currently use .data1. */
6232 /* Output a starting label for the .data1 section. */
6234 fputc ('\n', asm_out_file);
6235 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6236 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
6237 ASM_OUTPUT_POP_SECTION (asm_out_file);
6238 #endif
6240 /* Output a starting label for the .rodata section. */
6242 fputc ('\n', asm_out_file);
6243 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6244 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
6245 ASM_OUTPUT_POP_SECTION (asm_out_file);
6247 #if 0 /* GNU C doesn't currently use .rodata1. */
6248 /* Output a starting label for the .rodata1 section. */
6250 fputc ('\n', asm_out_file);
6251 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6252 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
6253 ASM_OUTPUT_POP_SECTION (asm_out_file);
6254 #endif
6256 /* Output a starting label for the .bss section. */
6258 fputc ('\n', asm_out_file);
6259 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6260 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
6261 ASM_OUTPUT_POP_SECTION (asm_out_file);
6263 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6265 if (use_gnu_debug_info_extensions)
6267 /* Output a starting label and an initial (compilation directory)
6268 entry for the .debug_sfnames section. The starting label will be
6269 referenced by the initial entry in the .debug_srcinfo section. */
6271 fputc ('\n', asm_out_file);
6272 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6273 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
6275 const char *pwd = getpwd ();
6276 char *dirname;
6278 if (!pwd)
6279 fatal_io_error ("can't get current directory");
6281 dirname = concat (pwd, "/", NULL);
6282 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
6283 free (dirname);
6285 ASM_OUTPUT_POP_SECTION (asm_out_file);
6288 if (debug_info_level >= DINFO_LEVEL_VERBOSE
6289 && use_gnu_debug_info_extensions)
6291 /* Output a starting label for the .debug_macinfo section. This
6292 label will be referenced by the AT_mac_info attribute in the
6293 TAG_compile_unit DIE. */
6295 fputc ('\n', asm_out_file);
6296 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6297 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
6298 ASM_OUTPUT_POP_SECTION (asm_out_file);
6301 /* Generate the initial entry for the .line section. */
6303 fputc ('\n', asm_out_file);
6304 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6305 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
6306 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
6307 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6308 ASM_OUTPUT_POP_SECTION (asm_out_file);
6310 if (use_gnu_debug_info_extensions)
6312 /* Generate the initial entry for the .debug_srcinfo section. */
6314 fputc ('\n', asm_out_file);
6315 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6316 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
6317 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
6318 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
6319 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6320 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
6321 #ifdef DWARF_TIMESTAMPS
6322 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
6323 #else
6324 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6325 #endif
6326 ASM_OUTPUT_POP_SECTION (asm_out_file);
6329 /* Generate the initial entry for the .debug_pubnames section. */
6331 fputc ('\n', asm_out_file);
6332 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6333 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6334 ASM_OUTPUT_POP_SECTION (asm_out_file);
6336 /* Generate the initial entry for the .debug_aranges section. */
6338 fputc ('\n', asm_out_file);
6339 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6340 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6341 DEBUG_ARANGES_END_LABEL,
6342 DEBUG_ARANGES_BEGIN_LABEL);
6343 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_BEGIN_LABEL);
6344 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 1);
6345 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6346 ASM_OUTPUT_POP_SECTION (asm_out_file);
6349 /* Setup first DIE number == 1. */
6350 NEXT_DIE_NUM = next_unused_dienum++;
6352 /* Generate the initial DIE for the .debug section. Note that the
6353 (string) value given in the AT_name attribute of the TAG_compile_unit
6354 DIE will (typically) be a relative pathname and that this pathname
6355 should be taken as being relative to the directory from which the
6356 compiler was invoked when the given (base) source file was compiled. */
6358 fputc ('\n', asm_out_file);
6359 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6360 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
6361 output_die (output_compile_unit_die, (PTR) main_input_filename);
6362 ASM_OUTPUT_POP_SECTION (asm_out_file);
6364 fputc ('\n', asm_out_file);
6367 /* Output stuff that dwarf requires at the end of every file. */
6369 static void
6370 dwarfout_finish (main_input_filename)
6371 const char *main_input_filename ATTRIBUTE_UNUSED;
6373 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6375 fputc ('\n', asm_out_file);
6376 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6377 retry_incomplete_types ();
6378 fputc ('\n', asm_out_file);
6380 /* Mark the end of the chain of siblings which represent all file-scope
6381 declarations in this compilation unit. */
6383 /* The (null) DIE which represents the terminator for the (sibling linked)
6384 list of file-scope items is *special*. Normally, we would just call
6385 end_sibling_chain at this point in order to output a word with the
6386 value `4' and that word would act as the terminator for the list of
6387 DIEs describing file-scope items. Unfortunately, if we were to simply
6388 do that, the label that would follow this DIE in the .debug section
6389 (i.e. `..D2') would *not* be properly aligned (as it must be on some
6390 machines) to a 4 byte boundary.
6392 In order to force the label `..D2' to get aligned to a 4 byte boundary,
6393 the trick used is to insert extra (otherwise useless) padding bytes
6394 into the (null) DIE that we know must precede the ..D2 label in the
6395 .debug section. The amount of padding required can be anywhere between
6396 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
6397 with the padding) would normally contain the value 4, but now it will
6398 also have to include the padding bytes, so it will instead have some
6399 value in the range 4..7.
6401 Fortunately, the rules of Dwarf say that any DIE whose length word
6402 contains *any* value less than 8 should be treated as a null DIE, so
6403 this trick works out nicely. Clever, eh? Don't give me any credit
6404 (or blame). I didn't think of this scheme. I just conformed to it.
6407 output_die (output_padded_null_die, (void *) 0);
6408 dienum_pop ();
6410 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
6411 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
6412 ASM_OUTPUT_POP_SECTION (asm_out_file);
6414 /* Output a terminator label for the .text section. */
6416 fputc ('\n', asm_out_file);
6417 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6418 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
6419 ASM_OUTPUT_POP_SECTION (asm_out_file);
6421 /* Output a terminator label for the .data section. */
6423 fputc ('\n', asm_out_file);
6424 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6425 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
6426 ASM_OUTPUT_POP_SECTION (asm_out_file);
6428 #if 0 /* GNU C doesn't currently use .data1. */
6429 /* Output a terminator label for the .data1 section. */
6431 fputc ('\n', asm_out_file);
6432 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6433 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
6434 ASM_OUTPUT_POP_SECTION (asm_out_file);
6435 #endif
6437 /* Output a terminator label for the .rodata section. */
6439 fputc ('\n', asm_out_file);
6440 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6441 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
6442 ASM_OUTPUT_POP_SECTION (asm_out_file);
6444 #if 0 /* GNU C doesn't currently use .rodata1. */
6445 /* Output a terminator label for the .rodata1 section. */
6447 fputc ('\n', asm_out_file);
6448 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6449 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
6450 ASM_OUTPUT_POP_SECTION (asm_out_file);
6451 #endif
6453 /* Output a terminator label for the .bss section. */
6455 fputc ('\n', asm_out_file);
6456 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6457 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
6458 ASM_OUTPUT_POP_SECTION (asm_out_file);
6460 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6462 /* Output a terminating entry for the .line section. */
6464 fputc ('\n', asm_out_file);
6465 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6466 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
6467 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6468 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6469 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6470 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
6471 ASM_OUTPUT_POP_SECTION (asm_out_file);
6473 if (use_gnu_debug_info_extensions)
6475 /* Output a terminating entry for the .debug_srcinfo section. */
6477 fputc ('\n', asm_out_file);
6478 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6479 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6480 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6481 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6482 ASM_OUTPUT_POP_SECTION (asm_out_file);
6485 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6487 /* Output terminating entries for the .debug_macinfo section. */
6489 dwarfout_end_source_file (0);
6491 fputc ('\n', asm_out_file);
6492 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6493 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6494 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6495 ASM_OUTPUT_POP_SECTION (asm_out_file);
6498 /* Generate the terminating entry for the .debug_pubnames section. */
6500 fputc ('\n', asm_out_file);
6501 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6502 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6503 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6504 ASM_OUTPUT_POP_SECTION (asm_out_file);
6506 /* Generate the terminating entries for the .debug_aranges section.
6508 Note that we want to do this only *after* we have output the end
6509 labels (for the various program sections) which we are going to
6510 refer to here. This allows us to work around a bug in the m68k
6511 svr4 assembler. That assembler gives bogus assembly-time errors
6512 if (within any given section) you try to take the difference of
6513 two relocatable symbols, both of which are located within some
6514 other section, and if one (or both?) of the symbols involved is
6515 being forward-referenced. By generating the .debug_aranges
6516 entries at this late point in the assembly output, we skirt the
6517 issue simply by avoiding forward-references.
6520 fputc ('\n', asm_out_file);
6521 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6523 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6524 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6526 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6527 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6529 #if 0 /* GNU C doesn't currently use .data1. */
6530 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6531 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6532 DATA1_BEGIN_LABEL);
6533 #endif
6535 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6536 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6537 RODATA_BEGIN_LABEL);
6539 #if 0 /* GNU C doesn't currently use .rodata1. */
6540 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6541 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6542 RODATA1_BEGIN_LABEL);
6543 #endif
6545 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6546 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6548 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6549 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6551 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_END_LABEL);
6552 ASM_OUTPUT_POP_SECTION (asm_out_file);
6555 /* There should not be any pending types left at the end. We need
6556 this now because it may not have been checked on the last call to
6557 dwarfout_file_scope_decl. */
6558 if (pending_types != 0)
6559 abort ();
6562 #endif /* DWARF_DEBUGGING_INFO */