Update copyright.
[official-gcc.git] / gcc / dwarfout.c
blob8f456f7ee7e6b6f4c6e058a0b5de0bb3fe2d743f
1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003 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 a 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"
566 #include "system.h"
567 #include "coretypes.h"
568 #include "tm.h"
570 #ifdef DWARF_DEBUGGING_INFO
571 #include "dwarf.h"
572 #include "tree.h"
573 #include "flags.h"
574 #include "function.h"
575 #include "rtl.h"
576 #include "hard-reg-set.h"
577 #include "insn-config.h"
578 #include "reload.h"
579 #include "output.h"
580 #include "dwarf2asm.h"
581 #include "toplev.h"
582 #include "tm_p.h"
583 #include "debug.h"
584 #include "target.h"
585 #include "langhooks.h"
587 /* NOTE: In the comments in this file, many references are made to
588 so called "Debugging Information Entries". For the sake of brevity,
589 this term is abbreviated to `DIE' throughout the remainder of this
590 file. */
592 /* Note that the implementation of C++ support herein is (as yet) unfinished.
593 If you want to try to complete it, more power to you. */
595 /* How to start an assembler comment. */
596 #ifndef ASM_COMMENT_START
597 #define ASM_COMMENT_START ";#"
598 #endif
600 /* How to print out a register name. */
601 #ifndef PRINT_REG
602 #define PRINT_REG(RTX, CODE, FILE) \
603 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
604 #endif
606 /* Define a macro which returns nonzero for any tagged type which is
607 used (directly or indirectly) in the specification of either some
608 function's return type or some formal parameter of some function.
609 We use this macro when we are operating in "terse" mode to help us
610 know what tagged types have to be represented in Dwarf (even in
611 terse mode) and which ones don't.
613 A flag bit with this meaning really should be a part of the normal
614 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
615 for these nodes. For now, we have to just fake it. It it safe for
616 us to simply return zero for all complete tagged types (which will
617 get forced out anyway if they were used in the specification of some
618 formal or return type) and nonzero for all incomplete tagged types.
621 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
623 /* Define a macro which returns nonzero for a TYPE_DECL which was
624 implicitly generated for a tagged type.
626 Note that unlike the gcc front end (which generates a NULL named
627 TYPE_DECL node for each complete tagged type, each array type, and
628 each function type node created) the g++ front end generates a
629 _named_ TYPE_DECL node for each tagged type node created.
630 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
631 generate a DW_TAG_typedef DIE for them. */
632 #define TYPE_DECL_IS_STUB(decl) \
633 (DECL_NAME (decl) == NULL \
634 || (DECL_ARTIFICIAL (decl) \
635 && is_tagged_type (TREE_TYPE (decl)) \
636 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
638 /* Maximum size (in bytes) of an artificially generated label. */
640 #define MAX_ARTIFICIAL_LABEL_BYTES 30
642 /* Structure to keep track of source filenames. */
644 struct filename_entry {
645 unsigned number;
646 const char * name;
649 typedef struct filename_entry filename_entry;
651 /* Pointer to an array of elements, each one having the structure above. */
653 static filename_entry *filename_table;
655 /* Total number of entries in the table (i.e. array) pointed to by
656 `filename_table'. This is the *total* and includes both used and
657 unused slots. */
659 static unsigned ft_entries_allocated;
661 /* Number of entries in the filename_table which are actually in use. */
663 static unsigned ft_entries;
665 /* Size (in elements) of increments by which we may expand the filename
666 table. Actually, a single hunk of space of this size should be enough
667 for most typical programs. */
669 #define FT_ENTRIES_INCREMENT 64
671 /* Local pointer to the name of the main input file. Initialized in
672 dwarfout_init. */
674 static const char *primary_filename;
676 /* Counter to generate unique names for DIEs. */
678 static unsigned next_unused_dienum = 1;
680 /* Number of the DIE which is currently being generated. */
682 static unsigned current_dienum;
684 /* Number to use for the special "pubname" label on the next DIE which
685 represents a function or data object defined in this compilation
686 unit which has "extern" linkage. */
688 static int next_pubname_number = 0;
690 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
692 /* Pointer to a dynamically allocated list of pre-reserved and still
693 pending sibling DIE numbers. Note that this list will grow as needed. */
695 static unsigned *pending_sibling_stack;
697 /* Counter to keep track of the number of pre-reserved and still pending
698 sibling DIE numbers. */
700 static unsigned pending_siblings;
702 /* The currently allocated size of the above list (expressed in number of
703 list elements). */
705 static unsigned pending_siblings_allocated;
707 /* Size (in elements) of increments by which we may expand the pending
708 sibling stack. Actually, a single hunk of space of this size should
709 be enough for most typical programs. */
711 #define PENDING_SIBLINGS_INCREMENT 64
713 /* Nonzero if we are performing our file-scope finalization pass and if
714 we should force out Dwarf descriptions of any and all file-scope
715 tagged types which are still incomplete types. */
717 static int finalizing = 0;
719 /* A pointer to the base of a list of pending types which we haven't
720 generated DIEs for yet, but which we will have to come back to
721 later on. */
723 static tree *pending_types_list;
725 /* Number of elements currently allocated for the pending_types_list. */
727 static unsigned pending_types_allocated;
729 /* Number of elements of pending_types_list currently in use. */
731 static unsigned pending_types;
733 /* Size (in elements) of increments by which we may expand the pending
734 types list. Actually, a single hunk of space of this size should
735 be enough for most typical programs. */
737 #define PENDING_TYPES_INCREMENT 64
739 /* A pointer to the base of a list of incomplete types which might be
740 completed at some later time. */
742 static tree *incomplete_types_list;
744 /* Number of elements currently allocated for the incomplete_types_list. */
745 static unsigned incomplete_types_allocated;
747 /* Number of elements of incomplete_types_list currently in use. */
748 static unsigned incomplete_types;
750 /* Size (in elements) of increments by which we may expand the incomplete
751 types list. Actually, a single hunk of space of this size should
752 be enough for most typical programs. */
753 #define INCOMPLETE_TYPES_INCREMENT 64
755 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
756 This is used in a hack to help us get the DIEs describing types of
757 formal parameters to come *after* all of the DIEs describing the formal
758 parameters themselves. That's necessary in order to be compatible
759 with what the brain-damaged svr4 SDB debugger requires. */
761 static tree fake_containing_scope;
763 /* A pointer to the ..._DECL node which we have most recently been working
764 on. We keep this around just in case something about it looks screwy
765 and we want to tell the user what the source coordinates for the actual
766 declaration are. */
768 static tree dwarf_last_decl;
770 /* A flag indicating that we are emitting the member declarations of a
771 class, so member functions and variables should not be entirely emitted.
772 This is a kludge to avoid passing a second argument to output_*_die. */
774 static int in_class;
776 /* Forward declarations for functions defined in this file. */
778 static void dwarfout_init PARAMS ((const char *));
779 static void dwarfout_finish PARAMS ((const char *));
780 static void dwarfout_define PARAMS ((unsigned int, const char *));
781 static void dwarfout_undef PARAMS ((unsigned int, const char *));
782 static void dwarfout_start_source_file PARAMS ((unsigned, const char *));
783 static void dwarfout_start_source_file_check PARAMS ((unsigned, const char *));
784 static void dwarfout_end_source_file PARAMS ((unsigned));
785 static void dwarfout_end_source_file_check PARAMS ((unsigned));
786 static void dwarfout_begin_block PARAMS ((unsigned, unsigned));
787 static void dwarfout_end_block PARAMS ((unsigned, unsigned));
788 static void dwarfout_end_epilogue PARAMS ((unsigned int, const char *));
789 static void dwarfout_source_line PARAMS ((unsigned int, const char *));
790 static void dwarfout_end_prologue PARAMS ((unsigned int, const char *));
791 static void dwarfout_end_function PARAMS ((unsigned int));
792 static void dwarfout_function_decl PARAMS ((tree));
793 static void dwarfout_global_decl PARAMS ((tree));
794 static void dwarfout_deferred_inline_function PARAMS ((tree));
795 static void dwarfout_file_scope_decl PARAMS ((tree , int));
796 static const char *dwarf_tag_name PARAMS ((unsigned));
797 static const char *dwarf_attr_name PARAMS ((unsigned));
798 static const char *dwarf_stack_op_name PARAMS ((unsigned));
799 static const char *dwarf_typemod_name PARAMS ((unsigned));
800 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
801 static const char *dwarf_fund_type_name PARAMS ((unsigned));
802 static tree decl_ultimate_origin PARAMS ((tree));
803 static tree block_ultimate_origin PARAMS ((tree));
804 static tree decl_class_context PARAMS ((tree));
805 #if 0
806 static void output_unsigned_leb128 PARAMS ((unsigned long));
807 static void output_signed_leb128 PARAMS ((long));
808 #endif
809 static int fundamental_type_code PARAMS ((tree));
810 static tree root_type_1 PARAMS ((tree, int));
811 static tree root_type PARAMS ((tree));
812 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
813 static void write_modifier_bytes PARAMS ((tree, int, int));
814 static inline int type_is_fundamental PARAMS ((tree));
815 static void equate_decl_number_to_die_number PARAMS ((tree));
816 static inline void equate_type_number_to_die_number PARAMS ((tree));
817 static void output_reg_number PARAMS ((rtx));
818 static void output_mem_loc_descriptor PARAMS ((rtx));
819 static void output_loc_descriptor PARAMS ((rtx));
820 static void output_bound_representation PARAMS ((tree, unsigned, int));
821 static void output_enumeral_list PARAMS ((tree));
822 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
823 static inline tree field_type PARAMS ((tree));
824 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
825 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
826 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
827 static inline void sibling_attribute PARAMS ((void));
828 static void location_attribute PARAMS ((rtx));
829 static void data_member_location_attribute PARAMS ((tree));
830 static void const_value_attribute PARAMS ((rtx));
831 static void location_or_const_value_attribute PARAMS ((tree));
832 static inline void name_attribute PARAMS ((const char *));
833 static inline void fund_type_attribute PARAMS ((unsigned));
834 static void mod_fund_type_attribute PARAMS ((tree, int, int));
835 static inline void user_def_type_attribute PARAMS ((tree));
836 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
837 #ifdef USE_ORDERING_ATTRIBUTE
838 static inline void ordering_attribute PARAMS ((unsigned));
839 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
840 static void subscript_data_attribute PARAMS ((tree));
841 static void byte_size_attribute PARAMS ((tree));
842 static inline void bit_offset_attribute PARAMS ((tree));
843 static inline void bit_size_attribute PARAMS ((tree));
844 static inline void element_list_attribute PARAMS ((tree));
845 static inline void stmt_list_attribute PARAMS ((const char *));
846 static inline void low_pc_attribute PARAMS ((const char *));
847 static inline void high_pc_attribute PARAMS ((const char *));
848 static inline void body_begin_attribute PARAMS ((const char *));
849 static inline void body_end_attribute PARAMS ((const char *));
850 static inline void language_attribute PARAMS ((unsigned));
851 static inline void member_attribute PARAMS ((tree));
852 #if 0
853 static inline void string_length_attribute PARAMS ((tree));
854 #endif
855 static inline void comp_dir_attribute PARAMS ((const char *));
856 static inline void sf_names_attribute PARAMS ((const char *));
857 static inline void src_info_attribute PARAMS ((const char *));
858 static inline void mac_info_attribute PARAMS ((const char *));
859 static inline void prototyped_attribute PARAMS ((tree));
860 static inline void producer_attribute PARAMS ((const char *));
861 static inline void inline_attribute PARAMS ((tree));
862 static inline void containing_type_attribute PARAMS ((tree));
863 static inline void abstract_origin_attribute PARAMS ((tree));
864 #ifdef DWARF_DECL_COORDINATES
865 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
866 #endif /* defined(DWARF_DECL_COORDINATES) */
867 static inline void pure_or_virtual_attribute PARAMS ((tree));
868 static void name_and_src_coords_attributes PARAMS ((tree));
869 static void type_attribute PARAMS ((tree, int, int));
870 static const char *type_tag PARAMS ((tree));
871 static inline void dienum_push PARAMS ((void));
872 static inline void dienum_pop PARAMS ((void));
873 static inline tree member_declared_type PARAMS ((tree));
874 static const char *function_start_label PARAMS ((tree));
875 static void output_array_type_die PARAMS ((void *));
876 static void output_set_type_die PARAMS ((void *));
877 #if 0
878 static void output_entry_point_die PARAMS ((void *));
879 #endif
880 static void output_inlined_enumeration_type_die PARAMS ((void *));
881 static void output_inlined_structure_type_die PARAMS ((void *));
882 static void output_inlined_union_type_die PARAMS ((void *));
883 static void output_enumeration_type_die PARAMS ((void *));
884 static void output_formal_parameter_die PARAMS ((void *));
885 static void output_global_subroutine_die PARAMS ((void *));
886 static void output_global_variable_die PARAMS ((void *));
887 static void output_label_die PARAMS ((void *));
888 static void output_lexical_block_die PARAMS ((void *));
889 static void output_inlined_subroutine_die PARAMS ((void *));
890 static void output_local_variable_die PARAMS ((void *));
891 static void output_member_die PARAMS ((void *));
892 #if 0
893 static void output_pointer_type_die PARAMS ((void *));
894 static void output_reference_type_die PARAMS ((void *));
895 #endif
896 static void output_ptr_to_mbr_type_die PARAMS ((void *));
897 static void output_compile_unit_die PARAMS ((void *));
898 static void output_string_type_die PARAMS ((void *));
899 static void output_inheritance_die PARAMS ((void *));
900 static void output_structure_type_die PARAMS ((void *));
901 static void output_local_subroutine_die PARAMS ((void *));
902 static void output_subroutine_type_die PARAMS ((void *));
903 static void output_typedef_die PARAMS ((void *));
904 static void output_union_type_die PARAMS ((void *));
905 static void output_unspecified_parameters_die PARAMS ((void *));
906 static void output_padded_null_die PARAMS ((void *));
907 static void output_die PARAMS ((void (*)(void *), void *));
908 static void end_sibling_chain PARAMS ((void));
909 static void output_formal_types PARAMS ((tree));
910 static void pend_type PARAMS ((tree));
911 static int type_ok_for_scope PARAMS ((tree, tree));
912 static void output_pending_types_for_scope PARAMS ((tree));
913 static void output_type PARAMS ((tree, tree));
914 static void output_tagged_type_instantiation PARAMS ((tree));
915 static void output_block PARAMS ((tree, int));
916 static void output_decls_for_scope PARAMS ((tree, int));
917 static void output_decl PARAMS ((tree, tree));
918 static void shuffle_filename_entry PARAMS ((filename_entry *));
919 static void generate_new_sfname_entry PARAMS ((void));
920 static unsigned lookup_filename PARAMS ((const char *));
921 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
922 static void generate_macinfo_entry PARAMS ((unsigned int, rtx,
923 const char *));
924 static int is_pseudo_reg PARAMS ((rtx));
925 static tree type_main_variant PARAMS ((tree));
926 static int is_tagged_type PARAMS ((tree));
927 static int is_redundant_typedef PARAMS ((tree));
928 static void add_incomplete_type PARAMS ((tree));
929 static void retry_incomplete_types PARAMS ((void));
931 /* Definitions of defaults for assembler-dependent names of various
932 pseudo-ops and section names.
934 Theses may be overridden in your tm.h file (if necessary) for your
935 particular assembler. The default values provided here correspond to
936 what is expected by "standard" AT&T System V.4 assemblers. */
938 #ifndef FILE_ASM_OP
939 #define FILE_ASM_OP "\t.file\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 (*targetm.asm_out.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 BODY_BEGIN_LABEL_FMT
1145 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
1146 #endif
1147 #ifndef BODY_END_LABEL_FMT
1148 #define BODY_END_LABEL_FMT "*.L_b%u_e"
1149 #endif
1150 #ifndef FUNC_END_LABEL_FMT
1151 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
1152 #endif
1153 #ifndef TYPE_NAME_FMT
1154 #define TYPE_NAME_FMT "*.L_T%u"
1155 #endif
1156 #ifndef DECL_NAME_FMT
1157 #define DECL_NAME_FMT "*.L_E%u"
1158 #endif
1159 #ifndef LINE_CODE_LABEL_FMT
1160 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
1161 #endif
1162 #ifndef SFNAMES_ENTRY_LABEL_FMT
1163 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
1164 #endif
1165 #ifndef LINE_ENTRY_LABEL_FMT
1166 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
1167 #endif
1169 /* Definitions of defaults for various types of primitive assembly language
1170 output operations.
1172 If necessary, these may be overridden from within your tm.h file,
1173 but typically, you shouldn't need to override these. */
1175 #ifndef ASM_OUTPUT_PUSH_SECTION
1176 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
1177 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
1178 #endif
1180 #ifndef ASM_OUTPUT_POP_SECTION
1181 #define ASM_OUTPUT_POP_SECTION(FILE) \
1182 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
1183 #endif
1185 #ifndef ASM_OUTPUT_DWARF_DELTA2
1186 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
1187 dw2_asm_output_delta (2, LABEL1, LABEL2, NULL)
1188 #endif
1190 #ifndef ASM_OUTPUT_DWARF_DELTA4
1191 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
1192 dw2_asm_output_delta (4, LABEL1, LABEL2, NULL)
1193 #endif
1195 #ifndef ASM_OUTPUT_DWARF_TAG
1196 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
1197 dw2_asm_output_data (2, TAG, "%s", dwarf_tag_name (TAG));
1198 #endif
1200 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
1201 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
1202 dw2_asm_output_data (2, ATTR, "%s", dwarf_attr_name (ATTR))
1203 #endif
1205 #ifndef ASM_OUTPUT_DWARF_STACK_OP
1206 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
1207 dw2_asm_output_data (1, OP, "%s", dwarf_stack_op_name (OP))
1208 #endif
1210 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
1211 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
1212 dw2_asm_output_data (2, FT, "%s", dwarf_fund_type_name (FT))
1213 #endif
1215 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
1216 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
1217 dw2_asm_output_data (1, FMT, "%s", dwarf_fmt_byte_name (FMT));
1218 #endif
1220 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
1221 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
1222 dw2_asm_output_data (1, MOD, "%s", dwarf_typemod_name (MOD));
1223 #endif
1225 #ifndef ASM_OUTPUT_DWARF_ADDR
1226 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
1227 dw2_asm_output_addr (4, LABEL, NULL)
1228 #endif
1230 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
1231 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
1232 dw2_asm_output_addr_rtx (4, RTX, NULL)
1233 #endif
1235 #ifndef ASM_OUTPUT_DWARF_REF
1236 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
1237 dw2_asm_output_addr (4, LABEL, NULL)
1238 #endif
1240 #ifndef ASM_OUTPUT_DWARF_DATA1
1241 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
1242 dw2_asm_output_data (1, VALUE, NULL)
1243 #endif
1245 #ifndef ASM_OUTPUT_DWARF_DATA2
1246 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
1247 dw2_asm_output_data (2, VALUE, NULL)
1248 #endif
1250 #ifndef ASM_OUTPUT_DWARF_DATA4
1251 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
1252 dw2_asm_output_data (4, VALUE, NULL)
1253 #endif
1255 #ifndef ASM_OUTPUT_DWARF_DATA8
1256 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
1257 dw2_asm_output_data (8, VALUE, NULL)
1258 #endif
1260 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
1261 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
1262 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
1263 defined, we call it, then issue the line feed. If not, we supply a
1264 default definition of calling ASM_OUTPUT_ASCII */
1266 #ifndef ASM_OUTPUT_DWARF_STRING
1267 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1268 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
1269 #else
1270 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1271 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
1272 #endif
1275 /* The debug hooks structure. */
1276 const struct gcc_debug_hooks dwarf_debug_hooks =
1278 dwarfout_init,
1279 dwarfout_finish,
1280 dwarfout_define,
1281 dwarfout_undef,
1282 dwarfout_start_source_file_check,
1283 dwarfout_end_source_file_check,
1284 dwarfout_begin_block,
1285 dwarfout_end_block,
1286 debug_true_tree, /* ignore_block */
1287 dwarfout_source_line, /* source_line */
1288 dwarfout_source_line, /* begin_prologue */
1289 dwarfout_end_prologue,
1290 dwarfout_end_epilogue,
1291 debug_nothing_tree, /* begin_function */
1292 dwarfout_end_function,
1293 dwarfout_function_decl,
1294 dwarfout_global_decl,
1295 dwarfout_deferred_inline_function,
1296 debug_nothing_tree, /* outlining_inline_function */
1297 debug_nothing_rtx /* label */
1300 /************************ general utility functions **************************/
1302 static inline int
1303 is_pseudo_reg (rtl)
1304 rtx rtl;
1306 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1307 || ((GET_CODE (rtl) == SUBREG)
1308 && (REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)));
1311 static inline tree
1312 type_main_variant (type)
1313 tree type;
1315 type = TYPE_MAIN_VARIANT (type);
1317 /* There really should be only one main variant among any group of variants
1318 of a given type (and all of the MAIN_VARIANT values for all members of
1319 the group should point to that one type) but sometimes the C front-end
1320 messes this up for array types, so we work around that bug here. */
1322 if (TREE_CODE (type) == ARRAY_TYPE)
1324 while (type != TYPE_MAIN_VARIANT (type))
1325 type = TYPE_MAIN_VARIANT (type);
1328 return type;
1331 /* Return nonzero if the given type node represents a tagged type. */
1333 static inline int
1334 is_tagged_type (type)
1335 tree type;
1337 enum tree_code code = TREE_CODE (type);
1339 return (code == RECORD_TYPE || code == UNION_TYPE
1340 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1343 static const char *
1344 dwarf_tag_name (tag)
1345 unsigned tag;
1347 switch (tag)
1349 case TAG_padding: return "TAG_padding";
1350 case TAG_array_type: return "TAG_array_type";
1351 case TAG_class_type: return "TAG_class_type";
1352 case TAG_entry_point: return "TAG_entry_point";
1353 case TAG_enumeration_type: return "TAG_enumeration_type";
1354 case TAG_formal_parameter: return "TAG_formal_parameter";
1355 case TAG_global_subroutine: return "TAG_global_subroutine";
1356 case TAG_global_variable: return "TAG_global_variable";
1357 case TAG_label: return "TAG_label";
1358 case TAG_lexical_block: return "TAG_lexical_block";
1359 case TAG_local_variable: return "TAG_local_variable";
1360 case TAG_member: return "TAG_member";
1361 case TAG_pointer_type: return "TAG_pointer_type";
1362 case TAG_reference_type: return "TAG_reference_type";
1363 case TAG_compile_unit: return "TAG_compile_unit";
1364 case TAG_string_type: return "TAG_string_type";
1365 case TAG_structure_type: return "TAG_structure_type";
1366 case TAG_subroutine: return "TAG_subroutine";
1367 case TAG_subroutine_type: return "TAG_subroutine_type";
1368 case TAG_typedef: return "TAG_typedef";
1369 case TAG_union_type: return "TAG_union_type";
1370 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
1371 case TAG_variant: return "TAG_variant";
1372 case TAG_common_block: return "TAG_common_block";
1373 case TAG_common_inclusion: return "TAG_common_inclusion";
1374 case TAG_inheritance: return "TAG_inheritance";
1375 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
1376 case TAG_module: return "TAG_module";
1377 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
1378 case TAG_set_type: return "TAG_set_type";
1379 case TAG_subrange_type: return "TAG_subrange_type";
1380 case TAG_with_stmt: return "TAG_with_stmt";
1382 /* GNU extensions. */
1384 case TAG_format_label: return "TAG_format_label";
1385 case TAG_namelist: return "TAG_namelist";
1386 case TAG_function_template: return "TAG_function_template";
1387 case TAG_class_template: return "TAG_class_template";
1389 default: return "TAG_<unknown>";
1393 static const char *
1394 dwarf_attr_name (attr)
1395 unsigned attr;
1397 switch (attr)
1399 case AT_sibling: return "AT_sibling";
1400 case AT_location: return "AT_location";
1401 case AT_name: return "AT_name";
1402 case AT_fund_type: return "AT_fund_type";
1403 case AT_mod_fund_type: return "AT_mod_fund_type";
1404 case AT_user_def_type: return "AT_user_def_type";
1405 case AT_mod_u_d_type: return "AT_mod_u_d_type";
1406 case AT_ordering: return "AT_ordering";
1407 case AT_subscr_data: return "AT_subscr_data";
1408 case AT_byte_size: return "AT_byte_size";
1409 case AT_bit_offset: return "AT_bit_offset";
1410 case AT_bit_size: return "AT_bit_size";
1411 case AT_element_list: return "AT_element_list";
1412 case AT_stmt_list: return "AT_stmt_list";
1413 case AT_low_pc: return "AT_low_pc";
1414 case AT_high_pc: return "AT_high_pc";
1415 case AT_language: return "AT_language";
1416 case AT_member: return "AT_member";
1417 case AT_discr: return "AT_discr";
1418 case AT_discr_value: return "AT_discr_value";
1419 case AT_string_length: return "AT_string_length";
1420 case AT_common_reference: return "AT_common_reference";
1421 case AT_comp_dir: return "AT_comp_dir";
1422 case AT_const_value_string: return "AT_const_value_string";
1423 case AT_const_value_data2: return "AT_const_value_data2";
1424 case AT_const_value_data4: return "AT_const_value_data4";
1425 case AT_const_value_data8: return "AT_const_value_data8";
1426 case AT_const_value_block2: return "AT_const_value_block2";
1427 case AT_const_value_block4: return "AT_const_value_block4";
1428 case AT_containing_type: return "AT_containing_type";
1429 case AT_default_value_addr: return "AT_default_value_addr";
1430 case AT_default_value_data2: return "AT_default_value_data2";
1431 case AT_default_value_data4: return "AT_default_value_data4";
1432 case AT_default_value_data8: return "AT_default_value_data8";
1433 case AT_default_value_string: return "AT_default_value_string";
1434 case AT_friends: return "AT_friends";
1435 case AT_inline: return "AT_inline";
1436 case AT_is_optional: return "AT_is_optional";
1437 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1438 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1439 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1440 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1441 case AT_private: return "AT_private";
1442 case AT_producer: return "AT_producer";
1443 case AT_program: return "AT_program";
1444 case AT_protected: return "AT_protected";
1445 case AT_prototyped: return "AT_prototyped";
1446 case AT_public: return "AT_public";
1447 case AT_pure_virtual: return "AT_pure_virtual";
1448 case AT_return_addr: return "AT_return_addr";
1449 case AT_abstract_origin: return "AT_abstract_origin";
1450 case AT_start_scope: return "AT_start_scope";
1451 case AT_stride_size: return "AT_stride_size";
1452 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1453 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1454 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1455 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1456 case AT_virtual: return "AT_virtual";
1458 /* GNU extensions */
1460 case AT_sf_names: return "AT_sf_names";
1461 case AT_src_info: return "AT_src_info";
1462 case AT_mac_info: return "AT_mac_info";
1463 case AT_src_coords: return "AT_src_coords";
1464 case AT_body_begin: return "AT_body_begin";
1465 case AT_body_end: return "AT_body_end";
1467 default: return "AT_<unknown>";
1471 static const char *
1472 dwarf_stack_op_name (op)
1473 unsigned op;
1475 switch (op)
1477 case OP_REG: return "OP_REG";
1478 case OP_BASEREG: return "OP_BASEREG";
1479 case OP_ADDR: return "OP_ADDR";
1480 case OP_CONST: return "OP_CONST";
1481 case OP_DEREF2: return "OP_DEREF2";
1482 case OP_DEREF4: return "OP_DEREF4";
1483 case OP_ADD: return "OP_ADD";
1484 default: return "OP_<unknown>";
1488 static const char *
1489 dwarf_typemod_name (mod)
1490 unsigned mod;
1492 switch (mod)
1494 case MOD_pointer_to: return "MOD_pointer_to";
1495 case MOD_reference_to: return "MOD_reference_to";
1496 case MOD_const: return "MOD_const";
1497 case MOD_volatile: return "MOD_volatile";
1498 default: return "MOD_<unknown>";
1502 static const char *
1503 dwarf_fmt_byte_name (fmt)
1504 unsigned fmt;
1506 switch (fmt)
1508 case FMT_FT_C_C: return "FMT_FT_C_C";
1509 case FMT_FT_C_X: return "FMT_FT_C_X";
1510 case FMT_FT_X_C: return "FMT_FT_X_C";
1511 case FMT_FT_X_X: return "FMT_FT_X_X";
1512 case FMT_UT_C_C: return "FMT_UT_C_C";
1513 case FMT_UT_C_X: return "FMT_UT_C_X";
1514 case FMT_UT_X_C: return "FMT_UT_X_C";
1515 case FMT_UT_X_X: return "FMT_UT_X_X";
1516 case FMT_ET: return "FMT_ET";
1517 default: return "FMT_<unknown>";
1521 static const char *
1522 dwarf_fund_type_name (ft)
1523 unsigned ft;
1525 switch (ft)
1527 case FT_char: return "FT_char";
1528 case FT_signed_char: return "FT_signed_char";
1529 case FT_unsigned_char: return "FT_unsigned_char";
1530 case FT_short: return "FT_short";
1531 case FT_signed_short: return "FT_signed_short";
1532 case FT_unsigned_short: return "FT_unsigned_short";
1533 case FT_integer: return "FT_integer";
1534 case FT_signed_integer: return "FT_signed_integer";
1535 case FT_unsigned_integer: return "FT_unsigned_integer";
1536 case FT_long: return "FT_long";
1537 case FT_signed_long: return "FT_signed_long";
1538 case FT_unsigned_long: return "FT_unsigned_long";
1539 case FT_pointer: return "FT_pointer";
1540 case FT_float: return "FT_float";
1541 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1542 case FT_ext_prec_float: return "FT_ext_prec_float";
1543 case FT_complex: return "FT_complex";
1544 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1545 case FT_void: return "FT_void";
1546 case FT_boolean: return "FT_boolean";
1547 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1548 case FT_label: return "FT_label";
1550 /* GNU extensions. */
1552 case FT_long_long: return "FT_long_long";
1553 case FT_signed_long_long: return "FT_signed_long_long";
1554 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1556 case FT_int8: return "FT_int8";
1557 case FT_signed_int8: return "FT_signed_int8";
1558 case FT_unsigned_int8: return "FT_unsigned_int8";
1559 case FT_int16: return "FT_int16";
1560 case FT_signed_int16: return "FT_signed_int16";
1561 case FT_unsigned_int16: return "FT_unsigned_int16";
1562 case FT_int32: return "FT_int32";
1563 case FT_signed_int32: return "FT_signed_int32";
1564 case FT_unsigned_int32: return "FT_unsigned_int32";
1565 case FT_int64: return "FT_int64";
1566 case FT_signed_int64: return "FT_signed_int64";
1567 case FT_unsigned_int64: return "FT_unsigned_int64";
1568 case FT_int128: return "FT_int128";
1569 case FT_signed_int128: return "FT_signed_int128";
1570 case FT_unsigned_int128: return "FT_unsigned_int128";
1572 case FT_real32: return "FT_real32";
1573 case FT_real64: return "FT_real64";
1574 case FT_real96: return "FT_real96";
1575 case FT_real128: return "FT_real128";
1577 default: return "FT_<unknown>";
1581 /* Determine the "ultimate origin" of a decl. The decl may be an
1582 inlined instance of an inlined instance of a decl which is local
1583 to an inline function, so we have to trace all of the way back
1584 through the origin chain to find out what sort of node actually
1585 served as the original seed for the given block. */
1587 static tree
1588 decl_ultimate_origin (decl)
1589 tree decl;
1591 #ifdef ENABLE_CHECKING
1592 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1593 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1594 most distant ancestor, this should never happen. */
1595 abort ();
1596 #endif
1598 return DECL_ABSTRACT_ORIGIN (decl);
1601 /* Determine the "ultimate origin" of a block. The block may be an
1602 inlined instance of an inlined instance of a block which is local
1603 to an inline function, so we have to trace all of the way back
1604 through the origin chain to find out what sort of node actually
1605 served as the original seed for the given block. */
1607 static tree
1608 block_ultimate_origin (block)
1609 tree block;
1611 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1613 if (immediate_origin == NULL)
1614 return NULL;
1615 else
1617 tree ret_val;
1618 tree lookahead = immediate_origin;
1622 ret_val = lookahead;
1623 lookahead = (TREE_CODE (ret_val) == BLOCK)
1624 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1625 : NULL;
1627 while (lookahead != NULL && lookahead != ret_val);
1628 return ret_val;
1632 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1633 of a virtual function may refer to a base class, so we check the 'this'
1634 parameter. */
1636 static tree
1637 decl_class_context (decl)
1638 tree decl;
1640 tree context = NULL_TREE;
1641 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1642 context = DECL_CONTEXT (decl);
1643 else
1644 context = TYPE_MAIN_VARIANT
1645 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1647 if (context && !TYPE_P (context))
1648 context = NULL_TREE;
1650 return context;
1653 #if 0
1654 static void
1655 output_unsigned_leb128 (value)
1656 unsigned long value;
1658 unsigned long orig_value = value;
1662 unsigned byte = (value & 0x7f);
1664 value >>= 7;
1665 if (value != 0) /* more bytes to follow */
1666 byte |= 0x80;
1667 dw2_asm_output_data (1, byte, "\t%s ULEB128 number - value = %lu",
1668 orig_value);
1670 while (value != 0);
1673 static void
1674 output_signed_leb128 (value)
1675 long value;
1677 long orig_value = value;
1678 int negative = (value < 0);
1679 int more;
1683 unsigned byte = (value & 0x7f);
1685 value >>= 7;
1686 if (negative)
1687 value |= 0xfe000000; /* manually sign extend */
1688 if (((value == 0) && ((byte & 0x40) == 0))
1689 || ((value == -1) && ((byte & 0x40) == 1)))
1690 more = 0;
1691 else
1693 byte |= 0x80;
1694 more = 1;
1696 dw2_asm_output_data (1, byte, "\t%s SLEB128 number - value = %ld",
1697 orig_value);
1699 while (more);
1701 #endif
1703 /**************** utility functions for attribute functions ******************/
1705 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1706 type code for the given type.
1708 This routine must only be called for GCC type nodes that correspond to
1709 Dwarf fundamental types.
1711 The current Dwarf draft specification calls for Dwarf fundamental types
1712 to accurately reflect the fact that a given type was either a "plain"
1713 integral type or an explicitly "signed" integral type. Unfortunately,
1714 we can't always do this, because GCC may already have thrown away the
1715 information about the precise way in which the type was originally
1716 specified, as in:
1718 typedef signed int my_type;
1720 struct s { my_type f; };
1722 Since we may be stuck here without enough information to do exactly
1723 what is called for in the Dwarf draft specification, we do the best
1724 that we can under the circumstances and always use the "plain" integral
1725 fundamental type codes for int, short, and long types. That's probably
1726 good enough. The additional accuracy called for in the current DWARF
1727 draft specification is probably never even useful in practice. */
1729 static int
1730 fundamental_type_code (type)
1731 tree type;
1733 if (TREE_CODE (type) == ERROR_MARK)
1734 return 0;
1736 switch (TREE_CODE (type))
1738 case ERROR_MARK:
1739 return FT_void;
1741 case VOID_TYPE:
1742 return FT_void;
1744 case INTEGER_TYPE:
1745 /* Carefully distinguish all the standard types of C,
1746 without messing up if the language is not C.
1747 Note that we check only for the names that contain spaces;
1748 other names might occur by coincidence in other languages. */
1749 if (TYPE_NAME (type) != 0
1750 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1751 && DECL_NAME (TYPE_NAME (type)) != 0
1752 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1754 const char *const name =
1755 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1757 if (!strcmp (name, "unsigned char"))
1758 return FT_unsigned_char;
1759 if (!strcmp (name, "signed char"))
1760 return FT_signed_char;
1761 if (!strcmp (name, "unsigned int"))
1762 return FT_unsigned_integer;
1763 if (!strcmp (name, "short int"))
1764 return FT_short;
1765 if (!strcmp (name, "short unsigned int"))
1766 return FT_unsigned_short;
1767 if (!strcmp (name, "long int"))
1768 return FT_long;
1769 if (!strcmp (name, "long unsigned int"))
1770 return FT_unsigned_long;
1771 if (!strcmp (name, "long long int"))
1772 return FT_long_long; /* Not grok'ed by svr4 SDB */
1773 if (!strcmp (name, "long long unsigned int"))
1774 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1777 /* Most integer types will be sorted out above, however, for the
1778 sake of special `array index' integer types, the following code
1779 is also provided. */
1781 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1782 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1784 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1785 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1787 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1788 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1790 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1791 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1793 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1794 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1796 if (TYPE_MODE (type) == TImode)
1797 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1799 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1800 if (TYPE_PRECISION (type) == 1)
1801 return FT_boolean;
1803 abort ();
1805 case REAL_TYPE:
1806 /* Carefully distinguish all the standard types of C,
1807 without messing up if the language is not C. */
1808 if (TYPE_NAME (type) != 0
1809 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1810 && DECL_NAME (TYPE_NAME (type)) != 0
1811 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1813 const char *const name =
1814 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1816 /* Note that here we can run afoul of a serious bug in "classic"
1817 svr4 SDB debuggers. They don't seem to understand the
1818 FT_ext_prec_float type (even though they should). */
1820 if (!strcmp (name, "long double"))
1821 return FT_ext_prec_float;
1824 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1826 /* On the SH, when compiling with -m3e or -m4-single-only, both
1827 float and double are 32 bits. But since the debugger doesn't
1828 know about the subtarget, it always thinks double is 64 bits.
1829 So we have to tell the debugger that the type is float to
1830 make the output of the 'print' command etc. readable. */
1831 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1832 return FT_float;
1833 return FT_dbl_prec_float;
1835 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1836 return FT_float;
1838 /* Note that here we can run afoul of a serious bug in "classic"
1839 svr4 SDB debuggers. They don't seem to understand the
1840 FT_ext_prec_float type (even though they should). */
1842 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1843 return FT_ext_prec_float;
1844 abort ();
1846 case COMPLEX_TYPE:
1847 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1849 case CHAR_TYPE:
1850 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1852 case BOOLEAN_TYPE:
1853 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1855 default:
1856 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1858 return 0;
1861 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1862 the Dwarf "root" type for the given input type. The Dwarf "root" type
1863 of a given type is generally the same as the given type, except that if
1864 the given type is a pointer or reference type, then the root type of
1865 the given type is the root type of the "basis" type for the pointer or
1866 reference type. (This definition of the "root" type is recursive.)
1867 Also, the root type of a `const' qualified type or a `volatile'
1868 qualified type is the root type of the given type without the
1869 qualifiers. */
1871 static tree
1872 root_type_1 (type, count)
1873 tree type;
1874 int count;
1876 /* Give up after searching 1000 levels, in case this is a recursive
1877 pointer type. Such types are possible in Ada, but it is not possible
1878 to represent them in DWARF1 debug info. */
1879 if (count > 1000)
1880 return error_mark_node;
1882 switch (TREE_CODE (type))
1884 case ERROR_MARK:
1885 return error_mark_node;
1887 case POINTER_TYPE:
1888 case REFERENCE_TYPE:
1889 return root_type_1 (TREE_TYPE (type), count+1);
1891 default:
1892 return type;
1896 static tree
1897 root_type (type)
1898 tree type;
1900 type = root_type_1 (type, 0);
1901 if (type != error_mark_node)
1902 type = type_main_variant (type);
1903 return type;
1906 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1907 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1909 static void
1910 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1911 tree type;
1912 int decl_const;
1913 int decl_volatile;
1914 int count;
1916 if (TREE_CODE (type) == ERROR_MARK)
1917 return;
1919 /* Give up after searching 1000 levels, in case this is a recursive
1920 pointer type. Such types are possible in Ada, but it is not possible
1921 to represent them in DWARF1 debug info. */
1922 if (count > 1000)
1923 return;
1925 if (TYPE_READONLY (type) || decl_const)
1926 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1927 if (TYPE_VOLATILE (type) || decl_volatile)
1928 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1929 switch (TREE_CODE (type))
1931 case POINTER_TYPE:
1932 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1933 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1934 return;
1936 case REFERENCE_TYPE:
1937 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1938 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1939 return;
1941 case ERROR_MARK:
1942 default:
1943 return;
1947 static void
1948 write_modifier_bytes (type, decl_const, decl_volatile)
1949 tree type;
1950 int decl_const;
1951 int decl_volatile;
1953 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1956 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
1957 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1959 static inline int
1960 type_is_fundamental (type)
1961 tree type;
1963 switch (TREE_CODE (type))
1965 case ERROR_MARK:
1966 case VOID_TYPE:
1967 case INTEGER_TYPE:
1968 case REAL_TYPE:
1969 case COMPLEX_TYPE:
1970 case BOOLEAN_TYPE:
1971 case CHAR_TYPE:
1972 return 1;
1974 case SET_TYPE:
1975 case ARRAY_TYPE:
1976 case RECORD_TYPE:
1977 case UNION_TYPE:
1978 case QUAL_UNION_TYPE:
1979 case ENUMERAL_TYPE:
1980 case FUNCTION_TYPE:
1981 case METHOD_TYPE:
1982 case POINTER_TYPE:
1983 case REFERENCE_TYPE:
1984 case FILE_TYPE:
1985 case OFFSET_TYPE:
1986 case LANG_TYPE:
1987 case VECTOR_TYPE:
1988 return 0;
1990 default:
1991 abort ();
1993 return 0;
1996 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1997 equate directive which will associate a symbolic name with the current DIE.
1999 The name used is an artificial label generated from the DECL_UID number
2000 associated with the given decl node. The name it gets equated to is the
2001 symbolic label that we (previously) output at the start of the DIE that
2002 we are currently generating.
2004 Calling this function while generating some "decl related" form of DIE
2005 makes it possible to later refer to the DIE which represents the given
2006 decl simply by re-generating the symbolic name from the ..._DECL node's
2007 UID number. */
2009 static void
2010 equate_decl_number_to_die_number (decl)
2011 tree decl;
2013 /* In the case where we are generating a DIE for some ..._DECL node
2014 which represents either some inline function declaration or some
2015 entity declared within an inline function declaration/definition,
2016 setup a symbolic name for the current DIE so that we have a name
2017 for this DIE that we can easily refer to later on within
2018 AT_abstract_origin attributes. */
2020 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
2021 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2023 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
2024 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2025 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
2028 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
2029 equate directive which will associate a symbolic name with the current DIE.
2031 The name used is an artificial label generated from the TYPE_UID number
2032 associated with the given type node. The name it gets equated to is the
2033 symbolic label that we (previously) output at the start of the DIE that
2034 we are currently generating.
2036 Calling this function while generating some "type related" form of DIE
2037 makes it easy to later refer to the DIE which represents the given type
2038 simply by re-generating the alternative name from the ..._TYPE node's
2039 UID number. */
2041 static inline void
2042 equate_type_number_to_die_number (type)
2043 tree type;
2045 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
2046 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2048 /* We are generating a DIE to represent the main variant of this type
2049 (i.e the type without any const or volatile qualifiers) so in order
2050 to get the equate to come out right, we need to get the main variant
2051 itself here. */
2053 type = type_main_variant (type);
2055 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
2056 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2057 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
2060 static void
2061 output_reg_number (rtl)
2062 rtx rtl;
2064 unsigned regno = REGNO (rtl);
2066 if (regno >= DWARF_FRAME_REGISTERS)
2068 warning_with_decl (dwarf_last_decl,
2069 "internal regno botch: `%s' has regno = %d\n",
2070 regno);
2071 regno = 0;
2073 dw2_assemble_integer (4, GEN_INT (DBX_REGISTER_NUMBER (regno)));
2074 if (flag_debug_asm)
2076 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
2077 PRINT_REG (rtl, 0, asm_out_file);
2079 fputc ('\n', asm_out_file);
2082 /* The following routine is a nice and simple transducer. It converts the
2083 RTL for a variable or parameter (resident in memory) into an equivalent
2084 Dwarf representation of a mechanism for getting the address of that same
2085 variable onto the top of a hypothetical "address evaluation" stack.
2087 When creating memory location descriptors, we are effectively trans-
2088 forming the RTL for a memory-resident object into its Dwarf postfix
2089 expression equivalent. This routine just recursively descends an
2090 RTL tree, turning it into Dwarf postfix code as it goes. */
2092 static void
2093 output_mem_loc_descriptor (rtl)
2094 rtx rtl;
2096 /* Note that for a dynamically sized array, the location we will
2097 generate a description of here will be the lowest numbered location
2098 which is actually within the array. That's *not* necessarily the
2099 same as the zeroth element of the array. */
2101 rtl = (*targetm.delegitimize_address) (rtl);
2103 switch (GET_CODE (rtl))
2105 case SUBREG:
2107 /* The case of a subreg may arise when we have a local (register)
2108 variable or a formal (register) parameter which doesn't quite
2109 fill up an entire register. For now, just assume that it is
2110 legitimate to make the Dwarf info refer to the whole register
2111 which contains the given subreg. */
2113 rtl = SUBREG_REG (rtl);
2114 /* Drop thru. */
2116 case REG:
2118 /* Whenever a register number forms a part of the description of
2119 the method for calculating the (dynamic) address of a memory
2120 resident object, DWARF rules require the register number to
2121 be referred to as a "base register". This distinction is not
2122 based in any way upon what category of register the hardware
2123 believes the given register belongs to. This is strictly
2124 DWARF terminology we're dealing with here.
2126 Note that in cases where the location of a memory-resident data
2127 object could be expressed as:
2129 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
2131 the actual DWARF location descriptor that we generate may just
2132 be OP_BASEREG (basereg). This may look deceptively like the
2133 object in question was allocated to a register (rather than
2134 in memory) so DWARF consumers need to be aware of the subtle
2135 distinction between OP_REG and OP_BASEREG. */
2137 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
2138 output_reg_number (rtl);
2139 break;
2141 case MEM:
2142 output_mem_loc_descriptor (XEXP (rtl, 0));
2143 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
2144 break;
2146 case CONST:
2147 case SYMBOL_REF:
2148 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
2149 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2150 break;
2152 case PLUS:
2153 output_mem_loc_descriptor (XEXP (rtl, 0));
2154 output_mem_loc_descriptor (XEXP (rtl, 1));
2155 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2156 break;
2158 case CONST_INT:
2159 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2160 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
2161 break;
2163 case MULT:
2164 /* If a pseudo-reg is optimized away, it is possible for it to
2165 be replaced with a MEM containing a multiply. Use a GNU extension
2166 to describe it. */
2167 output_mem_loc_descriptor (XEXP (rtl, 0));
2168 output_mem_loc_descriptor (XEXP (rtl, 1));
2169 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
2170 break;
2172 default:
2173 abort ();
2177 /* Output a proper Dwarf location descriptor for a variable or parameter
2178 which is either allocated in a register or in a memory location. For
2179 a register, we just generate an OP_REG and the register number. For a
2180 memory location we provide a Dwarf postfix expression describing how to
2181 generate the (dynamic) address of the object onto the address stack. */
2183 static void
2184 output_loc_descriptor (rtl)
2185 rtx rtl;
2187 switch (GET_CODE (rtl))
2189 case SUBREG:
2191 /* The case of a subreg may arise when we have a local (register)
2192 variable or a formal (register) parameter which doesn't quite
2193 fill up an entire register. For now, just assume that it is
2194 legitimate to make the Dwarf info refer to the whole register
2195 which contains the given subreg. */
2197 rtl = SUBREG_REG (rtl);
2198 /* Drop thru. */
2200 case REG:
2201 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
2202 output_reg_number (rtl);
2203 break;
2205 case MEM:
2206 output_mem_loc_descriptor (XEXP (rtl, 0));
2207 break;
2209 default:
2210 abort (); /* Should never happen */
2214 /* Given a tree node describing an array bound (either lower or upper)
2215 output a representation for that bound. */
2217 static void
2218 output_bound_representation (bound, dim_num, u_or_l)
2219 tree bound;
2220 unsigned dim_num; /* For multi-dimensional arrays. */
2221 char u_or_l; /* Designates upper or lower bound. */
2223 switch (TREE_CODE (bound))
2226 case ERROR_MARK:
2227 return;
2229 /* All fixed-bounds are represented by INTEGER_CST nodes. */
2231 case INTEGER_CST:
2232 if (host_integerp (bound, 0))
2233 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
2234 break;
2236 default:
2238 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
2239 SAVE_EXPR nodes, in which case we can do something, or as
2240 an expression, which we cannot represent. */
2242 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2243 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2245 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
2246 current_dienum, dim_num, u_or_l);
2248 sprintf (end_label, BOUND_END_LABEL_FMT,
2249 current_dienum, dim_num, u_or_l);
2251 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2252 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2254 /* If optimization is turned on, the SAVE_EXPRs that describe
2255 how to access the upper bound values are essentially bogus.
2256 They only describe (at best) how to get at these values at
2257 the points in the generated code right after they have just
2258 been computed. Worse yet, in the typical case, the upper
2259 bound values will not even *be* computed in the optimized
2260 code, so these SAVE_EXPRs are entirely bogus.
2262 In order to compensate for this fact, we check here to see
2263 if optimization is enabled, and if so, we effectively create
2264 an empty location description for the (unknown and unknowable)
2265 upper bound.
2267 This should not cause too much trouble for existing (stupid?)
2268 debuggers because they have to deal with empty upper bounds
2269 location descriptions anyway in order to be able to deal with
2270 incomplete array types.
2272 Of course an intelligent debugger (GDB?) should be able to
2273 comprehend that a missing upper bound specification in a
2274 array type used for a storage class `auto' local array variable
2275 indicates that the upper bound is both unknown (at compile-
2276 time) and unknowable (at run-time) due to optimization. */
2278 if (! optimize)
2280 while (TREE_CODE (bound) == NOP_EXPR
2281 || TREE_CODE (bound) == CONVERT_EXPR)
2282 bound = TREE_OPERAND (bound, 0);
2284 if (TREE_CODE (bound) == SAVE_EXPR
2285 && SAVE_EXPR_RTL (bound))
2286 output_loc_descriptor
2287 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
2290 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2292 break;
2297 /* Recursive function to output a sequence of value/name pairs for
2298 enumeration constants in reversed order. This is called from
2299 enumeration_type_die. */
2301 static void
2302 output_enumeral_list (link)
2303 tree link;
2305 if (link)
2307 output_enumeral_list (TREE_CHAIN (link));
2309 if (host_integerp (TREE_VALUE (link), 0))
2310 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2311 tree_low_cst (TREE_VALUE (link), 0));
2313 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
2314 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
2318 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
2319 which is not less than the value itself. */
2321 static inline HOST_WIDE_INT
2322 ceiling (value, boundary)
2323 HOST_WIDE_INT value;
2324 unsigned int boundary;
2326 return (((value + boundary - 1) / boundary) * boundary);
2329 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
2330 pointer to the declared type for the relevant field variable, or return
2331 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
2333 static inline tree
2334 field_type (decl)
2335 tree decl;
2337 tree type;
2339 if (TREE_CODE (decl) == ERROR_MARK)
2340 return integer_type_node;
2342 type = DECL_BIT_FIELD_TYPE (decl);
2343 if (type == NULL)
2344 type = TREE_TYPE (decl);
2345 return type;
2348 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2349 node, return the alignment in bits for the type, or else return
2350 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
2352 static inline unsigned int
2353 simple_type_align_in_bits (type)
2354 tree type;
2356 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
2359 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2360 node, return the size in bits for the type if it is a constant, or
2361 else return the alignment for the type if the type's size is not
2362 constant, or else return BITS_PER_WORD if the type actually turns out
2363 to be an ERROR_MARK node. */
2365 static inline unsigned HOST_WIDE_INT
2366 simple_type_size_in_bits (type)
2367 tree type;
2369 tree type_size_tree;
2371 if (TREE_CODE (type) == ERROR_MARK)
2372 return BITS_PER_WORD;
2373 type_size_tree = TYPE_SIZE (type);
2375 if (type_size_tree == NULL_TREE)
2376 return 0;
2377 if (! host_integerp (type_size_tree, 1))
2378 return TYPE_ALIGN (type);
2379 return tree_low_cst (type_size_tree, 1);
2382 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
2383 return the byte offset of the lowest addressed byte of the "containing
2384 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
2385 mine what that offset is, either because the argument turns out to be a
2386 pointer to an ERROR_MARK node, or because the offset is actually variable.
2387 (We can't handle the latter case just yet.) */
2389 static HOST_WIDE_INT
2390 field_byte_offset (decl)
2391 tree decl;
2393 unsigned int type_align_in_bytes;
2394 unsigned int type_align_in_bits;
2395 unsigned HOST_WIDE_INT type_size_in_bits;
2396 HOST_WIDE_INT object_offset_in_align_units;
2397 HOST_WIDE_INT object_offset_in_bits;
2398 HOST_WIDE_INT object_offset_in_bytes;
2399 tree type;
2400 tree field_size_tree;
2401 HOST_WIDE_INT bitpos_int;
2402 HOST_WIDE_INT deepest_bitpos;
2403 unsigned HOST_WIDE_INT field_size_in_bits;
2405 if (TREE_CODE (decl) == ERROR_MARK)
2406 return 0;
2408 if (TREE_CODE (decl) != FIELD_DECL)
2409 abort ();
2411 type = field_type (decl);
2412 field_size_tree = DECL_SIZE (decl);
2414 /* The size could be unspecified if there was an error, or for
2415 a flexible array member. */
2416 if (! field_size_tree)
2417 field_size_tree = bitsize_zero_node;
2419 /* We cannot yet cope with fields whose positions or sizes are variable,
2420 so for now, when we see such things, we simply return 0. Someday,
2421 we may be able to handle such cases, but it will be damn difficult. */
2423 if (! host_integerp (bit_position (decl), 0)
2424 || ! host_integerp (field_size_tree, 1))
2425 return 0;
2427 bitpos_int = int_bit_position (decl);
2428 field_size_in_bits = tree_low_cst (field_size_tree, 1);
2430 type_size_in_bits = simple_type_size_in_bits (type);
2431 type_align_in_bits = simple_type_align_in_bits (type);
2432 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2434 /* Note that the GCC front-end doesn't make any attempt to keep track
2435 of the starting bit offset (relative to the start of the containing
2436 structure type) of the hypothetical "containing object" for a bit-
2437 field. Thus, when computing the byte offset value for the start of
2438 the "containing object" of a bit-field, we must deduce this infor-
2439 mation on our own.
2441 This can be rather tricky to do in some cases. For example, handling
2442 the following structure type definition when compiling for an i386/i486
2443 target (which only aligns long long's to 32-bit boundaries) can be very
2444 tricky:
2446 struct S {
2447 int field1;
2448 long long field2:31;
2451 Fortunately, there is a simple rule-of-thumb which can be used in such
2452 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2453 the structure shown above. It decides to do this based upon one simple
2454 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2455 taining object" for each bit-field at the first (i.e. lowest addressed)
2456 legitimate alignment boundary (based upon the required minimum alignment
2457 for the declared type of the field) which it can possibly use, subject
2458 to the condition that there is still enough available space remaining
2459 in the containing object (when allocated at the selected point) to
2460 fully accommodate all of the bits of the bit-field itself.
2462 This simple rule makes it obvious why GCC allocates 8 bytes for each
2463 object of the structure type shown above. When looking for a place to
2464 allocate the "containing object" for `field2', the compiler simply tries
2465 to allocate a 64-bit "containing object" at each successive 32-bit
2466 boundary (starting at zero) until it finds a place to allocate that 64-
2467 bit field such that at least 31 contiguous (and previously unallocated)
2468 bits remain within that selected 64 bit field. (As it turns out, for
2469 the example above, the compiler finds that it is OK to allocate the
2470 "containing object" 64-bit field at bit-offset zero within the
2471 structure type.)
2473 Here we attempt to work backwards from the limited set of facts we're
2474 given, and we try to deduce from those facts, where GCC must have
2475 believed that the containing object started (within the structure type).
2477 The value we deduce is then used (by the callers of this routine) to
2478 generate AT_location and AT_bit_offset attributes for fields (both
2479 bit-fields and, in the case of AT_location, regular fields as well). */
2481 /* Figure out the bit-distance from the start of the structure to the
2482 "deepest" bit of the bit-field. */
2483 deepest_bitpos = bitpos_int + field_size_in_bits;
2485 /* This is the tricky part. Use some fancy footwork to deduce where the
2486 lowest addressed bit of the containing object must be. */
2487 object_offset_in_bits
2488 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2490 /* Compute the offset of the containing object in "alignment units". */
2491 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2493 /* Compute the offset of the containing object in bytes. */
2494 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2496 /* The above code assumes that the field does not cross an alignment
2497 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2498 or if the structure is packed. If this happens, then we get an object
2499 which starts after the bitfield, which means that the bit offset is
2500 negative. Gdb fails when given negative bit offsets. We avoid this
2501 by recomputing using the first bit of the bitfield. This will give
2502 us an object which does not completely contain the bitfield, but it
2503 will be aligned, and it will contain the first bit of the bitfield.
2505 However, only do this for a BYTES_BIG_ENDIAN target. For a
2506 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2507 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2508 then we end up computing the object byte offset for the wrong word of the
2509 desired bitfield, which in turn causes the field offset to be negative
2510 in bit_offset_attribute. */
2511 if (BYTES_BIG_ENDIAN
2512 && object_offset_in_bits > bitpos_int)
2514 deepest_bitpos = bitpos_int + 1;
2515 object_offset_in_bits
2516 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2517 object_offset_in_align_units = (object_offset_in_bits
2518 / type_align_in_bits);
2519 object_offset_in_bytes = (object_offset_in_align_units
2520 * type_align_in_bytes);
2523 return object_offset_in_bytes;
2526 /****************************** attributes *********************************/
2528 /* The following routines are responsible for writing out the various types
2529 of Dwarf attributes (and any following data bytes associated with them).
2530 These routines are listed in order based on the numerical codes of their
2531 associated attributes. */
2533 /* Generate an AT_sibling attribute. */
2535 static inline void
2536 sibling_attribute ()
2538 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2540 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2541 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2542 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2545 /* Output the form of location attributes suitable for whole variables and
2546 whole parameters. Note that the location attributes for struct fields
2547 are generated by the routine `data_member_location_attribute' below. */
2549 static void
2550 location_attribute (rtl)
2551 rtx rtl;
2553 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2554 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2556 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2557 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2558 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2559 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2560 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2562 /* Handle a special case. If we are about to output a location descriptor
2563 for a variable or parameter which has been optimized out of existence,
2564 don't do that. Instead we output a zero-length location descriptor
2565 value as part of the location attribute.
2567 A variable which has been optimized out of existence will have a
2568 DECL_RTL value which denotes a pseudo-reg.
2570 Currently, in some rare cases, variables can have DECL_RTL values
2571 which look like (MEM (REG pseudo-reg#)). These cases are due to
2572 bugs elsewhere in the compiler. We treat such cases
2573 as if the variable(s) in question had been optimized out of existence.
2575 Note that in all cases where we wish to express the fact that a
2576 variable has been optimized out of existence, we do not simply
2577 suppress the generation of the entire location attribute because
2578 the absence of a location attribute in certain kinds of DIEs is
2579 used to indicate something else entirely... i.e. that the DIE
2580 represents an object declaration, but not a definition. So saith
2581 the PLSIG.
2584 if (! is_pseudo_reg (rtl)
2585 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2586 output_loc_descriptor (rtl);
2588 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2591 /* Output the specialized form of location attribute used for data members
2592 of struct and union types.
2594 In the special case of a FIELD_DECL node which represents a bit-field,
2595 the "offset" part of this special location descriptor must indicate the
2596 distance in bytes from the lowest-addressed byte of the containing
2597 struct or union type to the lowest-addressed byte of the "containing
2598 object" for the bit-field. (See the `field_byte_offset' function above.)
2600 For any given bit-field, the "containing object" is a hypothetical
2601 object (of some integral or enum type) within which the given bit-field
2602 lives. The type of this hypothetical "containing object" is always the
2603 same as the declared type of the individual bit-field itself (for GCC
2604 anyway... the DWARF spec doesn't actually mandate this).
2606 Note that it is the size (in bytes) of the hypothetical "containing
2607 object" which will be given in the AT_byte_size attribute for this
2608 bit-field. (See the `byte_size_attribute' function below.) It is
2609 also used when calculating the value of the AT_bit_offset attribute.
2610 (See the `bit_offset_attribute' function below.) */
2612 static void
2613 data_member_location_attribute (t)
2614 tree t;
2616 unsigned object_offset_in_bytes;
2617 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2618 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2620 if (TREE_CODE (t) == TREE_VEC)
2621 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2622 else
2623 object_offset_in_bytes = field_byte_offset (t);
2625 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2626 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2627 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2628 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2629 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2630 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2631 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2632 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2633 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2636 /* Output an AT_const_value attribute for a variable or a parameter which
2637 does not have a "location" either in memory or in a register. These
2638 things can arise in GNU C when a constant is passed as an actual
2639 parameter to an inlined function. They can also arise in C++ where
2640 declared constants do not necessarily get memory "homes". */
2642 static void
2643 const_value_attribute (rtl)
2644 rtx rtl;
2646 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2647 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2649 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2650 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2651 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2652 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2653 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2655 switch (GET_CODE (rtl))
2657 case CONST_INT:
2658 /* Note that a CONST_INT rtx could represent either an integer or
2659 a floating-point constant. A CONST_INT is used whenever the
2660 constant will fit into a single word. In all such cases, the
2661 original mode of the constant value is wiped out, and the
2662 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2663 precise mode information for these constants, we always just
2664 output them using 4 bytes. */
2666 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2667 break;
2669 case CONST_DOUBLE:
2670 /* Note that a CONST_DOUBLE rtx could represent either an integer
2671 or a floating-point constant. A CONST_DOUBLE is used whenever
2672 the constant requires more than one word in order to be adequately
2673 represented. In all such cases, the original mode of the constant
2674 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2675 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2677 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2678 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2679 (unsigned int) CONST_DOUBLE_LOW (rtl));
2680 break;
2682 case CONST_STRING:
2683 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2684 break;
2686 case SYMBOL_REF:
2687 case LABEL_REF:
2688 case CONST:
2689 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2690 break;
2692 case PLUS:
2693 /* In cases where an inlined instance of an inline function is passed
2694 the address of an `auto' variable (which is local to the caller)
2695 we can get a situation where the DECL_RTL of the artificial
2696 local variable (for the inlining) which acts as a stand-in for
2697 the corresponding formal parameter (of the inline function)
2698 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2699 This is not exactly a compile-time constant expression, but it
2700 isn't the address of the (artificial) local variable either.
2701 Rather, it represents the *value* which the artificial local
2702 variable always has during its lifetime. We currently have no
2703 way to represent such quasi-constant values in Dwarf, so for now
2704 we just punt and generate an AT_const_value attribute with form
2705 FORM_BLOCK4 and a length of zero. */
2706 break;
2708 default:
2709 abort (); /* No other kinds of rtx should be possible here. */
2712 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2715 /* Generate *either* an AT_location attribute or else an AT_const_value
2716 data attribute for a variable or a parameter. We generate the
2717 AT_const_value attribute only in those cases where the given
2718 variable or parameter does not have a true "location" either in
2719 memory or in a register. This can happen (for example) when a
2720 constant is passed as an actual argument in a call to an inline
2721 function. (It's possible that these things can crop up in other
2722 ways also.) Note that one type of constant value which can be
2723 passed into an inlined function is a constant pointer. This can
2724 happen for example if an actual argument in an inlined function
2725 call evaluates to a compile-time constant address. */
2727 static void
2728 location_or_const_value_attribute (decl)
2729 tree decl;
2731 rtx rtl;
2733 if (TREE_CODE (decl) == ERROR_MARK)
2734 return;
2736 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2738 /* Should never happen. */
2739 abort ();
2740 return;
2743 /* Here we have to decide where we are going to say the parameter "lives"
2744 (as far as the debugger is concerned). We only have a couple of choices.
2745 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2746 normally indicates where the parameter lives during most of the activa-
2747 tion of the function. If optimization is enabled however, this could
2748 be either NULL or else a pseudo-reg. Both of those cases indicate that
2749 the parameter doesn't really live anywhere (as far as the code generation
2750 parts of GCC are concerned) during most of the function's activation.
2751 That will happen (for example) if the parameter is never referenced
2752 within the function.
2754 We could just generate a location descriptor here for all non-NULL
2755 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2756 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2757 cases where DECL_RTL is NULL or is a pseudo-reg.
2759 Note however that we can only get away with using DECL_INCOMING_RTL as
2760 a backup substitute for DECL_RTL in certain limited cases. In cases
2761 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2762 we can be sure that the parameter was passed using the same type as it
2763 is declared to have within the function, and that its DECL_INCOMING_RTL
2764 points us to a place where a value of that type is passed. In cases
2765 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2766 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2767 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2768 points us to a value of some type which is *different* from the type
2769 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2770 to generate a location attribute in such cases, the debugger would
2771 end up (for example) trying to fetch a `float' from a place which
2772 actually contains the first part of a `double'. That would lead to
2773 really incorrect and confusing output at debug-time, and we don't
2774 want that now do we?
2776 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2777 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2778 couple of cute exceptions however. On little-endian machines we can
2779 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2780 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2781 an integral type which is smaller than TREE_TYPE(decl). These cases
2782 arise when (on a little-endian machine) a non-prototyped function has
2783 a parameter declared to be of type `short' or `char'. In such cases,
2784 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2785 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2786 passed `int' value. If the debugger then uses that address to fetch a
2787 `short' or a `char' (on a little-endian machine) the result will be the
2788 correct data, so we allow for such exceptional cases below.
2790 Note that our goal here is to describe the place where the given formal
2791 parameter lives during most of the function's activation (i.e. between
2792 the end of the prologue and the start of the epilogue). We'll do that
2793 as best as we can. Note however that if the given formal parameter is
2794 modified sometime during the execution of the function, then a stack
2795 backtrace (at debug-time) will show the function as having been called
2796 with the *new* value rather than the value which was originally passed
2797 in. This happens rarely enough that it is not a major problem, but it
2798 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2799 may generate two additional attributes for any given TAG_formal_parameter
2800 DIE which will describe the "passed type" and the "passed location" for
2801 the given formal parameter in addition to the attributes we now generate
2802 to indicate the "declared type" and the "active location" for each
2803 parameter. This additional set of attributes could be used by debuggers
2804 for stack backtraces.
2806 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2807 can be NULL also. This happens (for example) for inlined-instances of
2808 inline function formal parameters which are never referenced. This really
2809 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2810 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2811 these values for inlined instances of inline function parameters, so
2812 when we see such cases, we are just out-of-luck for the time
2813 being (until integrate.c gets fixed).
2816 /* Use DECL_RTL as the "location" unless we find something better. */
2817 rtl = DECL_RTL (decl);
2819 if (TREE_CODE (decl) == PARM_DECL)
2820 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2822 /* This decl represents a formal parameter which was optimized out. */
2823 tree declared_type = type_main_variant (TREE_TYPE (decl));
2824 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2826 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2827 *all* cases where (rtl == NULL_RTX) just below. */
2829 if (declared_type == passed_type)
2830 rtl = DECL_INCOMING_RTL (decl);
2831 else if (! BYTES_BIG_ENDIAN)
2832 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2833 /* NMS WTF? */
2834 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2835 rtl = DECL_INCOMING_RTL (decl);
2838 if (rtl == NULL_RTX)
2839 return;
2841 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2842 #ifdef LEAF_REG_REMAP
2843 if (current_function_uses_only_leaf_regs)
2844 leaf_renumber_regs_insn (rtl);
2845 #endif
2847 switch (GET_CODE (rtl))
2849 case ADDRESSOF:
2850 /* The address of a variable that was optimized away; don't emit
2851 anything. */
2852 break;
2854 case CONST_INT:
2855 case CONST_DOUBLE:
2856 case CONST_STRING:
2857 case SYMBOL_REF:
2858 case LABEL_REF:
2859 case CONST:
2860 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2861 const_value_attribute (rtl);
2862 break;
2864 case MEM:
2865 case REG:
2866 case SUBREG:
2867 location_attribute (rtl);
2868 break;
2870 case CONCAT:
2871 /* ??? CONCAT is used for complex variables, which may have the real
2872 part stored in one place and the imag part stored somewhere else.
2873 DWARF1 has no way to describe a variable that lives in two different
2874 places, so we just describe where the first part lives, and hope that
2875 the second part is stored after it. */
2876 location_attribute (XEXP (rtl, 0));
2877 break;
2879 default:
2880 abort (); /* Should never happen. */
2884 /* Generate an AT_name attribute given some string value to be included as
2885 the value of the attribute. */
2887 static inline void
2888 name_attribute (name_string)
2889 const char *name_string;
2891 if (name_string && *name_string)
2893 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2894 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2898 static inline void
2899 fund_type_attribute (ft_code)
2900 unsigned ft_code;
2902 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2903 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2906 static void
2907 mod_fund_type_attribute (type, decl_const, decl_volatile)
2908 tree type;
2909 int decl_const;
2910 int decl_volatile;
2912 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2913 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2915 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2916 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2917 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2918 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2919 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2920 write_modifier_bytes (type, decl_const, decl_volatile);
2921 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2922 fundamental_type_code (root_type (type)));
2923 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2926 static inline void
2927 user_def_type_attribute (type)
2928 tree type;
2930 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2932 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2933 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2934 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2937 static void
2938 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2939 tree type;
2940 int decl_const;
2941 int decl_volatile;
2943 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2944 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2945 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2947 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2948 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2949 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2950 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2951 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2952 write_modifier_bytes (type, decl_const, decl_volatile);
2953 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2954 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2955 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2958 #ifdef USE_ORDERING_ATTRIBUTE
2959 static inline void
2960 ordering_attribute (ordering)
2961 unsigned ordering;
2963 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2964 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2966 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2968 /* Note that the block of subscript information for an array type also
2969 includes information about the element type of type given array type. */
2971 static void
2972 subscript_data_attribute (type)
2973 tree type;
2975 unsigned dimension_number;
2976 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2977 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2979 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2980 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2981 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2982 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2983 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2985 /* The GNU compilers represent multidimensional array types as sequences
2986 of one dimensional array types whose element types are themselves array
2987 types. Here we squish that down, so that each multidimensional array
2988 type gets only one array_type DIE in the Dwarf debugging info. The
2989 draft Dwarf specification say that we are allowed to do this kind
2990 of compression in C (because there is no difference between an
2991 array or arrays and a multidimensional array in C) but for other
2992 source languages (e.g. Ada) we probably shouldn't do this. */
2994 for (dimension_number = 0;
2995 TREE_CODE (type) == ARRAY_TYPE;
2996 type = TREE_TYPE (type), dimension_number++)
2998 tree domain = TYPE_DOMAIN (type);
3000 /* Arrays come in three flavors. Unspecified bounds, fixed
3001 bounds, and (in GNU C only) variable bounds. Handle all
3002 three forms here. */
3004 if (domain)
3006 /* We have an array type with specified bounds. */
3008 tree lower = TYPE_MIN_VALUE (domain);
3009 tree upper = TYPE_MAX_VALUE (domain);
3011 /* Handle only fundamental types as index types for now. */
3012 if (! type_is_fundamental (domain))
3013 abort ();
3015 /* Output the representation format byte for this dimension. */
3016 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
3017 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
3018 upper && TREE_CODE (upper) == INTEGER_CST));
3020 /* Output the index type for this dimension. */
3021 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3022 fundamental_type_code (domain));
3024 /* Output the representation for the lower bound. */
3025 output_bound_representation (lower, dimension_number, 'l');
3027 /* Output the representation for the upper bound. */
3028 if (upper)
3029 output_bound_representation (upper, dimension_number, 'u');
3030 else
3031 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3033 else
3035 /* We have an array type with an unspecified length. For C and
3036 C++ we can assume that this really means that (a) the index
3037 type is an integral type, and (b) the lower bound is zero.
3038 Note that Dwarf defines the representation of an unspecified
3039 (upper) bound as being a zero-length location description. */
3041 /* Output the array-bounds format byte. */
3043 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
3045 /* Output the (assumed) index type. */
3047 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
3049 /* Output the (assumed) lower bound (constant) value. */
3051 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3053 /* Output the (empty) location description for the upper bound. */
3055 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3059 /* Output the prefix byte that says that the element type is coming up. */
3061 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
3063 /* Output a representation of the type of the elements of this array type. */
3065 type_attribute (type, 0, 0);
3067 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3070 static void
3071 byte_size_attribute (tree_node)
3072 tree tree_node;
3074 unsigned size;
3076 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
3077 switch (TREE_CODE (tree_node))
3079 case ERROR_MARK:
3080 size = 0;
3081 break;
3083 case ENUMERAL_TYPE:
3084 case RECORD_TYPE:
3085 case UNION_TYPE:
3086 case QUAL_UNION_TYPE:
3087 case ARRAY_TYPE:
3088 size = int_size_in_bytes (tree_node);
3089 break;
3091 case FIELD_DECL:
3092 /* For a data member of a struct or union, the AT_byte_size is
3093 generally given as the number of bytes normally allocated for
3094 an object of the *declared* type of the member itself. This
3095 is true even for bit-fields. */
3096 size = simple_type_size_in_bits (field_type (tree_node))
3097 / BITS_PER_UNIT;
3098 break;
3100 default:
3101 abort ();
3104 /* Note that `size' might be -1 when we get to this point. If it
3105 is, that indicates that the byte size of the entity in question
3106 is variable. We have no good way of expressing this fact in Dwarf
3107 at the present time, so just let the -1 pass on through. */
3109 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
3112 /* For a FIELD_DECL node which represents a bit-field, output an attribute
3113 which specifies the distance in bits from the highest order bit of the
3114 "containing object" for the bit-field to the highest order bit of the
3115 bit-field itself.
3117 For any given bit-field, the "containing object" is a hypothetical
3118 object (of some integral or enum type) within which the given bit-field
3119 lives. The type of this hypothetical "containing object" is always the
3120 same as the declared type of the individual bit-field itself.
3122 The determination of the exact location of the "containing object" for
3123 a bit-field is rather complicated. It's handled by the `field_byte_offset'
3124 function (above).
3126 Note that it is the size (in bytes) of the hypothetical "containing
3127 object" which will be given in the AT_byte_size attribute for this
3128 bit-field. (See `byte_size_attribute' above.) */
3130 static inline void
3131 bit_offset_attribute (decl)
3132 tree decl;
3134 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
3135 tree type = DECL_BIT_FIELD_TYPE (decl);
3136 HOST_WIDE_INT bitpos_int;
3137 HOST_WIDE_INT highest_order_object_bit_offset;
3138 HOST_WIDE_INT highest_order_field_bit_offset;
3139 HOST_WIDE_INT bit_offset;
3141 /* Must be a bit field. */
3142 if (!type
3143 || TREE_CODE (decl) != FIELD_DECL)
3144 abort ();
3146 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
3147 if we encounter such things, just return without generating any
3148 attribute whatsoever. */
3150 if (! host_integerp (bit_position (decl), 0)
3151 || ! host_integerp (DECL_SIZE (decl), 1))
3152 return;
3154 bitpos_int = int_bit_position (decl);
3156 /* Note that the bit offset is always the distance (in bits) from the
3157 highest-order bit of the "containing object" to the highest-order
3158 bit of the bit-field itself. Since the "high-order end" of any
3159 object or field is different on big-endian and little-endian machines,
3160 the computation below must take account of these differences. */
3162 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
3163 highest_order_field_bit_offset = bitpos_int;
3165 if (! BYTES_BIG_ENDIAN)
3167 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
3168 highest_order_object_bit_offset += simple_type_size_in_bits (type);
3171 bit_offset =
3172 (! BYTES_BIG_ENDIAN
3173 ? highest_order_object_bit_offset - highest_order_field_bit_offset
3174 : highest_order_field_bit_offset - highest_order_object_bit_offset);
3176 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
3177 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
3180 /* For a FIELD_DECL node which represents a bit field, output an attribute
3181 which specifies the length in bits of the given field. */
3183 static inline void
3184 bit_size_attribute (decl)
3185 tree decl;
3187 /* Must be a field and a bit field. */
3188 if (TREE_CODE (decl) != FIELD_DECL
3189 || ! DECL_BIT_FIELD_TYPE (decl))
3190 abort ();
3192 if (host_integerp (DECL_SIZE (decl), 1))
3194 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
3195 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3196 tree_low_cst (DECL_SIZE (decl), 1));
3200 /* The following routine outputs the `element_list' attribute for enumeration
3201 type DIEs. The element_lits attribute includes the names and values of
3202 all of the enumeration constants associated with the given enumeration
3203 type. */
3205 static inline void
3206 element_list_attribute (element)
3207 tree element;
3209 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3210 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3212 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
3213 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
3214 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
3215 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3216 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3218 /* Here we output a list of value/name pairs for each enumeration constant
3219 defined for this enumeration type (as required), but we do it in REVERSE
3220 order. The order is the one required by the draft #5 Dwarf specification
3221 published by the UI/PLSIG. */
3223 output_enumeral_list (element); /* Recursively output the whole list. */
3225 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3228 /* Generate an AT_stmt_list attribute. These are normally present only in
3229 DIEs with a TAG_compile_unit tag. */
3231 static inline void
3232 stmt_list_attribute (label)
3233 const char *label;
3235 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
3236 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3237 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3240 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
3241 for a subroutine DIE. */
3243 static inline void
3244 low_pc_attribute (asm_low_label)
3245 const char *asm_low_label;
3247 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
3248 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
3251 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
3252 subroutine DIE. */
3254 static inline void
3255 high_pc_attribute (asm_high_label)
3256 const char *asm_high_label;
3258 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
3259 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
3262 /* Generate an AT_body_begin attribute for a subroutine DIE. */
3264 static inline void
3265 body_begin_attribute (asm_begin_label)
3266 const char *asm_begin_label;
3268 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
3269 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
3272 /* Generate an AT_body_end attribute for a subroutine DIE. */
3274 static inline void
3275 body_end_attribute (asm_end_label)
3276 const char *asm_end_label;
3278 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
3279 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
3282 /* Generate an AT_language attribute given a LANG value. These attributes
3283 are used only within TAG_compile_unit DIEs. */
3285 static inline void
3286 language_attribute (language_code)
3287 unsigned language_code;
3289 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
3290 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
3293 static inline void
3294 member_attribute (context)
3295 tree context;
3297 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3299 /* Generate this attribute only for members in C++. */
3301 if (context != NULL && is_tagged_type (context))
3303 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
3304 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
3305 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3309 #if 0
3310 #ifndef SL_BEGIN_LABEL_FMT
3311 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
3312 #endif
3313 #ifndef SL_END_LABEL_FMT
3314 #define SL_END_LABEL_FMT "*.L_sl%u_e"
3315 #endif
3317 static inline void
3318 string_length_attribute (upper_bound)
3319 tree upper_bound;
3321 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3322 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3324 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
3325 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
3326 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
3327 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3328 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3329 output_bound_representation (upper_bound, 0, 'u');
3330 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3332 #endif
3334 static inline void
3335 comp_dir_attribute (dirname)
3336 const char *dirname;
3338 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
3339 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
3342 static inline void
3343 sf_names_attribute (sf_names_start_label)
3344 const char *sf_names_start_label;
3346 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
3347 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3348 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
3351 static inline void
3352 src_info_attribute (src_info_start_label)
3353 const char *src_info_start_label;
3355 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
3356 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3357 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
3360 static inline void
3361 mac_info_attribute (mac_info_start_label)
3362 const char *mac_info_start_label;
3364 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
3365 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3366 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
3369 static inline void
3370 prototyped_attribute (func_type)
3371 tree func_type;
3373 if ((strcmp (lang_hooks.name, "GNU C") == 0)
3374 && (TYPE_ARG_TYPES (func_type) != NULL))
3376 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
3377 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3381 static inline void
3382 producer_attribute (producer)
3383 const char *producer;
3385 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
3386 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
3389 static inline void
3390 inline_attribute (decl)
3391 tree decl;
3393 if (DECL_INLINE (decl))
3395 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3396 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3400 static inline void
3401 containing_type_attribute (containing_type)
3402 tree containing_type;
3404 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3406 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3407 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3408 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3411 static inline void
3412 abstract_origin_attribute (origin)
3413 tree origin;
3415 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3417 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3418 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3420 case 'd':
3421 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3422 break;
3424 case 't':
3425 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3426 break;
3428 default:
3429 abort (); /* Should never happen. */
3432 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3435 #ifdef DWARF_DECL_COORDINATES
3436 static inline void
3437 src_coords_attribute (src_fileno, src_lineno)
3438 unsigned src_fileno;
3439 unsigned src_lineno;
3441 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3442 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3443 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3445 #endif /* defined(DWARF_DECL_COORDINATES) */
3447 static inline void
3448 pure_or_virtual_attribute (func_decl)
3449 tree func_decl;
3451 if (DECL_VIRTUAL_P (func_decl))
3453 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3454 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3455 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3456 else
3457 #endif
3458 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3459 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3463 /************************* end of attributes *****************************/
3465 /********************* utility routines for DIEs *************************/
3467 /* Output an AT_name attribute and an AT_src_coords attribute for the
3468 given decl, but only if it actually has a name. */
3470 static void
3471 name_and_src_coords_attributes (decl)
3472 tree decl;
3474 tree decl_name = DECL_NAME (decl);
3476 if (decl_name && IDENTIFIER_POINTER (decl_name))
3478 name_attribute (IDENTIFIER_POINTER (decl_name));
3479 #ifdef DWARF_DECL_COORDINATES
3481 register unsigned file_index;
3483 /* This is annoying, but we have to pop out of the .debug section
3484 for a moment while we call `lookup_filename' because calling it
3485 may cause a temporary switch into the .debug_sfnames section and
3486 most svr4 assemblers are not smart enough to be able to nest
3487 section switches to any depth greater than one. Note that we
3488 also can't skirt this issue by delaying all output to the
3489 .debug_sfnames section unit the end of compilation because that
3490 would cause us to have inter-section forward references and
3491 Fred Fish sez that m68k/svr4 assemblers botch those. */
3493 ASM_OUTPUT_POP_SECTION (asm_out_file);
3494 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3495 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3497 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3499 #endif /* defined(DWARF_DECL_COORDINATES) */
3503 /* Many forms of DIEs contain a "type description" part. The following
3504 routine writes out these "type descriptor" parts. */
3506 static void
3507 type_attribute (type, decl_const, decl_volatile)
3508 tree type;
3509 int decl_const;
3510 int decl_volatile;
3512 enum tree_code code = TREE_CODE (type);
3513 int root_type_modified;
3515 if (code == ERROR_MARK)
3516 return;
3518 /* Handle a special case. For functions whose return type is void,
3519 we generate *no* type attribute. (Note that no object may have
3520 type `void', so this only applies to function return types. */
3522 if (code == VOID_TYPE)
3523 return;
3525 /* If this is a subtype, find the underlying type. Eventually,
3526 this should write out the appropriate subtype info. */
3527 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3528 && TREE_TYPE (type) != 0)
3529 type = TREE_TYPE (type), code = TREE_CODE (type);
3531 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3532 || decl_const || decl_volatile
3533 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3535 if (type_is_fundamental (root_type (type)))
3537 if (root_type_modified)
3538 mod_fund_type_attribute (type, decl_const, decl_volatile);
3539 else
3540 fund_type_attribute (fundamental_type_code (type));
3542 else
3544 if (root_type_modified)
3545 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3546 else
3547 /* We have to get the type_main_variant here (and pass that to the
3548 `user_def_type_attribute' routine) because the ..._TYPE node we
3549 have might simply be a *copy* of some original type node (where
3550 the copy was created to help us keep track of typedef names)
3551 and that copy might have a different TYPE_UID from the original
3552 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3553 is labeling a given type DIE for future reference, it always and
3554 only creates labels for DIEs representing *main variants*, and it
3555 never even knows about non-main-variants.) */
3556 user_def_type_attribute (type_main_variant (type));
3560 /* Given a tree pointer to a struct, class, union, or enum type node, return
3561 a pointer to the (string) tag name for the given type, or zero if the
3562 type was declared without a tag. */
3564 static const char *
3565 type_tag (type)
3566 tree type;
3568 const char *name = 0;
3570 if (TYPE_NAME (type) != 0)
3572 tree t = 0;
3574 /* Find the IDENTIFIER_NODE for the type name. */
3575 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3576 t = TYPE_NAME (type);
3578 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3579 a TYPE_DECL node, regardless of whether or not a `typedef' was
3580 involved. */
3581 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3582 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3583 t = DECL_NAME (TYPE_NAME (type));
3585 /* Now get the name as a string, or invent one. */
3586 if (t != 0)
3587 name = IDENTIFIER_POINTER (t);
3590 return (name == 0 || *name == '\0') ? 0 : name;
3593 static inline void
3594 dienum_push ()
3596 /* Start by checking if the pending_sibling_stack needs to be expanded.
3597 If necessary, expand it. */
3599 if (pending_siblings == pending_siblings_allocated)
3601 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3602 pending_sibling_stack
3603 = (unsigned *) xrealloc (pending_sibling_stack,
3604 pending_siblings_allocated * sizeof(unsigned));
3607 pending_siblings++;
3608 NEXT_DIE_NUM = next_unused_dienum++;
3611 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3612 NEXT_DIE_NUM. */
3614 static inline void
3615 dienum_pop ()
3617 pending_siblings--;
3620 static inline tree
3621 member_declared_type (member)
3622 tree member;
3624 return (DECL_BIT_FIELD_TYPE (member))
3625 ? DECL_BIT_FIELD_TYPE (member)
3626 : TREE_TYPE (member);
3629 /* Get the function's label, as described by its RTL.
3630 This may be different from the DECL_NAME name used
3631 in the source file. */
3633 static const char *
3634 function_start_label (decl)
3635 tree decl;
3637 rtx x;
3638 const char *fnname;
3640 x = DECL_RTL (decl);
3641 if (GET_CODE (x) != MEM)
3642 abort ();
3643 x = XEXP (x, 0);
3644 if (GET_CODE (x) != SYMBOL_REF)
3645 abort ();
3646 fnname = XSTR (x, 0);
3647 return fnname;
3651 /******************************* DIEs ************************************/
3653 /* Output routines for individual types of DIEs. */
3655 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3657 static void
3658 output_array_type_die (arg)
3659 void *arg;
3661 tree type = arg;
3663 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3664 sibling_attribute ();
3665 equate_type_number_to_die_number (type);
3666 member_attribute (TYPE_CONTEXT (type));
3668 /* I believe that we can default the array ordering. SDB will probably
3669 do the right things even if AT_ordering is not present. It's not
3670 even an issue until we start to get into multidimensional arrays
3671 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3672 dimensional arrays, then we'll have to put the AT_ordering attribute
3673 back in. (But if and when we find out that we need to put these in,
3674 we will only do so for multidimensional arrays. After all, we don't
3675 want to waste space in the .debug section now do we?) */
3677 #ifdef USE_ORDERING_ATTRIBUTE
3678 ordering_attribute (ORD_row_major);
3679 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3681 subscript_data_attribute (type);
3684 static void
3685 output_set_type_die (arg)
3686 void *arg;
3688 tree type = arg;
3690 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3691 sibling_attribute ();
3692 equate_type_number_to_die_number (type);
3693 member_attribute (TYPE_CONTEXT (type));
3694 type_attribute (TREE_TYPE (type), 0, 0);
3697 #if 0
3698 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3700 static void
3701 output_entry_point_die (arg)
3702 void *arg;
3704 tree decl = arg;
3705 tree origin = decl_ultimate_origin (decl);
3707 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3708 sibling_attribute ();
3709 dienum_push ();
3710 if (origin != NULL)
3711 abstract_origin_attribute (origin);
3712 else
3714 name_and_src_coords_attributes (decl);
3715 member_attribute (DECL_CONTEXT (decl));
3716 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3718 if (DECL_ABSTRACT (decl))
3719 equate_decl_number_to_die_number (decl);
3720 else
3721 low_pc_attribute (function_start_label (decl));
3723 #endif
3725 /* Output a DIE to represent an inlined instance of an enumeration type. */
3727 static void
3728 output_inlined_enumeration_type_die (arg)
3729 void *arg;
3731 tree type = arg;
3733 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3734 sibling_attribute ();
3735 if (!TREE_ASM_WRITTEN (type))
3736 abort ();
3737 abstract_origin_attribute (type);
3740 /* Output a DIE to represent an inlined instance of a structure type. */
3742 static void
3743 output_inlined_structure_type_die (arg)
3744 void *arg;
3746 tree type = arg;
3748 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3749 sibling_attribute ();
3750 if (!TREE_ASM_WRITTEN (type))
3751 abort ();
3752 abstract_origin_attribute (type);
3755 /* Output a DIE to represent an inlined instance of a union type. */
3757 static void
3758 output_inlined_union_type_die (arg)
3759 void *arg;
3761 tree type = arg;
3763 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3764 sibling_attribute ();
3765 if (!TREE_ASM_WRITTEN (type))
3766 abort ();
3767 abstract_origin_attribute (type);
3770 /* Output a DIE to represent an enumeration type. Note that these DIEs
3771 include all of the information about the enumeration values also.
3772 This information is encoded into the element_list attribute. */
3774 static void
3775 output_enumeration_type_die (arg)
3776 void *arg;
3778 tree type = arg;
3780 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3781 sibling_attribute ();
3782 equate_type_number_to_die_number (type);
3783 name_attribute (type_tag (type));
3784 member_attribute (TYPE_CONTEXT (type));
3786 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3787 given enum type is incomplete, do not generate the AT_byte_size
3788 attribute or the AT_element_list attribute. */
3790 if (COMPLETE_TYPE_P (type))
3792 byte_size_attribute (type);
3793 element_list_attribute (TYPE_FIELDS (type));
3797 /* Output a DIE to represent either a real live formal parameter decl or
3798 to represent just the type of some formal parameter position in some
3799 function type.
3801 Note that this routine is a bit unusual because its argument may be
3802 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3803 represents an inlining of some PARM_DECL) or else some sort of a
3804 ..._TYPE node. If it's the former then this function is being called
3805 to output a DIE to represent a formal parameter object (or some inlining
3806 thereof). If it's the latter, then this function is only being called
3807 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3808 formal argument type of some subprogram type. */
3810 static void
3811 output_formal_parameter_die (arg)
3812 void *arg;
3814 tree node = arg;
3816 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3817 sibling_attribute ();
3819 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3821 case 'd': /* We were called with some kind of a ..._DECL node. */
3823 register tree origin = decl_ultimate_origin (node);
3825 if (origin != NULL)
3826 abstract_origin_attribute (origin);
3827 else
3829 name_and_src_coords_attributes (node);
3830 type_attribute (TREE_TYPE (node),
3831 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3833 if (DECL_ABSTRACT (node))
3834 equate_decl_number_to_die_number (node);
3835 else
3836 location_or_const_value_attribute (node);
3838 break;
3840 case 't': /* We were called with some kind of a ..._TYPE node. */
3841 type_attribute (node, 0, 0);
3842 break;
3844 default:
3845 abort (); /* Should never happen. */
3849 /* Output a DIE to represent a declared function (either file-scope
3850 or block-local) which has "external linkage" (according to ANSI-C). */
3852 static void
3853 output_global_subroutine_die (arg)
3854 void *arg;
3856 tree decl = arg;
3857 tree origin = decl_ultimate_origin (decl);
3859 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3860 sibling_attribute ();
3861 dienum_push ();
3862 if (origin != NULL)
3863 abstract_origin_attribute (origin);
3864 else
3866 tree type = TREE_TYPE (decl);
3868 name_and_src_coords_attributes (decl);
3869 inline_attribute (decl);
3870 prototyped_attribute (type);
3871 member_attribute (DECL_CONTEXT (decl));
3872 type_attribute (TREE_TYPE (type), 0, 0);
3873 pure_or_virtual_attribute (decl);
3875 if (DECL_ABSTRACT (decl))
3876 equate_decl_number_to_die_number (decl);
3877 else
3879 if (! DECL_EXTERNAL (decl) && ! in_class
3880 && decl == current_function_decl)
3882 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3884 low_pc_attribute (function_start_label (decl));
3885 sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no);
3886 high_pc_attribute (label);
3887 if (use_gnu_debug_info_extensions)
3889 sprintf (label, BODY_BEGIN_LABEL_FMT,
3890 current_function_funcdef_no);
3891 body_begin_attribute (label);
3892 sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no);
3893 body_end_attribute (label);
3899 /* Output a DIE to represent a declared data object (either file-scope
3900 or block-local) which has "external linkage" (according to ANSI-C). */
3902 static void
3903 output_global_variable_die (arg)
3904 void *arg;
3906 tree decl = arg;
3907 tree origin = decl_ultimate_origin (decl);
3909 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3910 sibling_attribute ();
3911 if (origin != NULL)
3912 abstract_origin_attribute (origin);
3913 else
3915 name_and_src_coords_attributes (decl);
3916 member_attribute (DECL_CONTEXT (decl));
3917 type_attribute (TREE_TYPE (decl),
3918 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3920 if (DECL_ABSTRACT (decl))
3921 equate_decl_number_to_die_number (decl);
3922 else
3924 if (! DECL_EXTERNAL (decl) && ! in_class
3925 && current_function_decl == decl_function_context (decl))
3926 location_or_const_value_attribute (decl);
3930 static void
3931 output_label_die (arg)
3932 void *arg;
3934 tree decl = arg;
3935 tree origin = decl_ultimate_origin (decl);
3937 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3938 sibling_attribute ();
3939 if (origin != NULL)
3940 abstract_origin_attribute (origin);
3941 else
3942 name_and_src_coords_attributes (decl);
3943 if (DECL_ABSTRACT (decl))
3944 equate_decl_number_to_die_number (decl);
3945 else
3947 rtx insn = DECL_RTL (decl);
3949 /* Deleted labels are programmer specified labels which have been
3950 eliminated because of various optimisations. We still emit them
3951 here so that it is possible to put breakpoints on them. */
3952 if (GET_CODE (insn) == CODE_LABEL
3953 || ((GET_CODE (insn) == NOTE
3954 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
3956 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3958 /* When optimization is enabled (via -O) some parts of the compiler
3959 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3960 represent source-level labels which were explicitly declared by
3961 the user. This really shouldn't be happening though, so catch
3962 it if it ever does happen. */
3964 if (INSN_DELETED_P (insn))
3965 abort (); /* Should never happen. */
3967 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
3968 low_pc_attribute (label);
3973 static void
3974 output_lexical_block_die (arg)
3975 void *arg;
3977 tree stmt = arg;
3979 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3980 sibling_attribute ();
3981 dienum_push ();
3982 if (! BLOCK_ABSTRACT (stmt))
3984 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3985 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3987 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3988 low_pc_attribute (begin_label);
3989 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3990 high_pc_attribute (end_label);
3994 static void
3995 output_inlined_subroutine_die (arg)
3996 void *arg;
3998 tree stmt = arg;
4000 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
4001 sibling_attribute ();
4002 dienum_push ();
4003 abstract_origin_attribute (block_ultimate_origin (stmt));
4004 if (! BLOCK_ABSTRACT (stmt))
4006 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4007 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4009 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4010 low_pc_attribute (begin_label);
4011 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4012 high_pc_attribute (end_label);
4016 /* Output a DIE to represent a declared data object (either file-scope
4017 or block-local) which has "internal linkage" (according to ANSI-C). */
4019 static void
4020 output_local_variable_die (arg)
4021 void *arg;
4023 tree decl = arg;
4024 tree origin = decl_ultimate_origin (decl);
4026 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
4027 sibling_attribute ();
4028 if (origin != NULL)
4029 abstract_origin_attribute (origin);
4030 else
4032 name_and_src_coords_attributes (decl);
4033 member_attribute (DECL_CONTEXT (decl));
4034 type_attribute (TREE_TYPE (decl),
4035 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4037 if (DECL_ABSTRACT (decl))
4038 equate_decl_number_to_die_number (decl);
4039 else
4040 location_or_const_value_attribute (decl);
4043 static void
4044 output_member_die (arg)
4045 void *arg;
4047 tree decl = arg;
4049 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
4050 sibling_attribute ();
4051 name_and_src_coords_attributes (decl);
4052 member_attribute (DECL_CONTEXT (decl));
4053 type_attribute (member_declared_type (decl),
4054 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4055 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
4057 byte_size_attribute (decl);
4058 bit_size_attribute (decl);
4059 bit_offset_attribute (decl);
4061 data_member_location_attribute (decl);
4064 #if 0
4065 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
4066 modified types instead.
4068 We keep this code here just in case these types of DIEs may be
4069 needed to represent certain things in other languages (e.g. Pascal)
4070 someday. */
4072 static void
4073 output_pointer_type_die (arg)
4074 void *arg;
4076 tree type = arg;
4078 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
4079 sibling_attribute ();
4080 equate_type_number_to_die_number (type);
4081 member_attribute (TYPE_CONTEXT (type));
4082 type_attribute (TREE_TYPE (type), 0, 0);
4085 static void
4086 output_reference_type_die (arg)
4087 void *arg;
4089 tree type = arg;
4091 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
4092 sibling_attribute ();
4093 equate_type_number_to_die_number (type);
4094 member_attribute (TYPE_CONTEXT (type));
4095 type_attribute (TREE_TYPE (type), 0, 0);
4097 #endif
4099 static void
4100 output_ptr_to_mbr_type_die (arg)
4101 void *arg;
4103 tree type = arg;
4105 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
4106 sibling_attribute ();
4107 equate_type_number_to_die_number (type);
4108 member_attribute (TYPE_CONTEXT (type));
4109 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
4110 type_attribute (TREE_TYPE (type), 0, 0);
4113 static void
4114 output_compile_unit_die (arg)
4115 void *arg;
4117 const char *main_input_filename = arg;
4118 const char *language_string = lang_hooks.name;
4120 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
4121 sibling_attribute ();
4122 dienum_push ();
4123 name_attribute (main_input_filename);
4126 char producer[250];
4128 sprintf (producer, "%s %s", language_string, version_string);
4129 producer_attribute (producer);
4132 if (strcmp (language_string, "GNU C++") == 0)
4133 language_attribute (LANG_C_PLUS_PLUS);
4134 else if (strcmp (language_string, "GNU Ada") == 0)
4135 language_attribute (LANG_ADA83);
4136 else if (strcmp (language_string, "GNU F77") == 0)
4137 language_attribute (LANG_FORTRAN77);
4138 else if (strcmp (language_string, "GNU Pascal") == 0)
4139 language_attribute (LANG_PASCAL83);
4140 else if (strcmp (language_string, "GNU Java") == 0)
4141 language_attribute (LANG_JAVA);
4142 else
4143 language_attribute (LANG_C89);
4144 low_pc_attribute (TEXT_BEGIN_LABEL);
4145 high_pc_attribute (TEXT_END_LABEL);
4146 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4147 stmt_list_attribute (LINE_BEGIN_LABEL);
4150 const char *wd = getpwd ();
4151 if (wd)
4152 comp_dir_attribute (wd);
4155 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
4157 sf_names_attribute (SFNAMES_BEGIN_LABEL);
4158 src_info_attribute (SRCINFO_BEGIN_LABEL);
4159 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4160 mac_info_attribute (MACINFO_BEGIN_LABEL);
4164 static void
4165 output_string_type_die (arg)
4166 void *arg;
4168 tree type = arg;
4170 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
4171 sibling_attribute ();
4172 equate_type_number_to_die_number (type);
4173 member_attribute (TYPE_CONTEXT (type));
4174 /* this is a fixed length string */
4175 byte_size_attribute (type);
4178 static void
4179 output_inheritance_die (arg)
4180 void *arg;
4182 tree binfo = ((tree *)arg)[0];
4183 tree access = ((tree *)arg)[1];
4185 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
4186 sibling_attribute ();
4187 type_attribute (BINFO_TYPE (binfo), 0, 0);
4188 data_member_location_attribute (binfo);
4189 if (TREE_VIA_VIRTUAL (binfo))
4191 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
4192 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4194 if (access == access_public_node)
4196 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
4197 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4199 else if (access == access_protected_node)
4201 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
4202 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4206 static void
4207 output_structure_type_die (arg)
4208 void *arg;
4210 tree type = arg;
4212 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
4213 sibling_attribute ();
4214 equate_type_number_to_die_number (type);
4215 name_attribute (type_tag (type));
4216 member_attribute (TYPE_CONTEXT (type));
4218 /* If this type has been completed, then give it a byte_size attribute
4219 and prepare to give a list of members. Otherwise, don't do either of
4220 these things. In the latter case, we will not be generating a list
4221 of members (since we don't have any idea what they might be for an
4222 incomplete type). */
4224 if (COMPLETE_TYPE_P (type))
4226 dienum_push ();
4227 byte_size_attribute (type);
4231 /* Output a DIE to represent a declared function (either file-scope
4232 or block-local) which has "internal linkage" (according to ANSI-C). */
4234 static void
4235 output_local_subroutine_die (arg)
4236 void *arg;
4238 tree decl = arg;
4239 tree origin = decl_ultimate_origin (decl);
4241 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
4242 sibling_attribute ();
4243 dienum_push ();
4244 if (origin != NULL)
4245 abstract_origin_attribute (origin);
4246 else
4248 tree type = TREE_TYPE (decl);
4250 name_and_src_coords_attributes (decl);
4251 inline_attribute (decl);
4252 prototyped_attribute (type);
4253 member_attribute (DECL_CONTEXT (decl));
4254 type_attribute (TREE_TYPE (type), 0, 0);
4255 pure_or_virtual_attribute (decl);
4257 if (DECL_ABSTRACT (decl))
4258 equate_decl_number_to_die_number (decl);
4259 else
4261 /* Avoid getting screwed up in cases where a function was declared
4262 static but where no definition was ever given for it. */
4264 if (TREE_ASM_WRITTEN (decl))
4266 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4267 low_pc_attribute (function_start_label (decl));
4268 sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no);
4269 high_pc_attribute (label);
4270 if (use_gnu_debug_info_extensions)
4272 sprintf (label, BODY_BEGIN_LABEL_FMT,
4273 current_function_funcdef_no);
4274 body_begin_attribute (label);
4275 sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no);
4276 body_end_attribute (label);
4282 static void
4283 output_subroutine_type_die (arg)
4284 void *arg;
4286 tree type = arg;
4287 tree return_type = TREE_TYPE (type);
4289 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
4290 sibling_attribute ();
4291 dienum_push ();
4292 equate_type_number_to_die_number (type);
4293 prototyped_attribute (type);
4294 member_attribute (TYPE_CONTEXT (type));
4295 type_attribute (return_type, 0, 0);
4298 static void
4299 output_typedef_die (arg)
4300 void *arg;
4302 tree decl = arg;
4303 tree origin = decl_ultimate_origin (decl);
4305 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
4306 sibling_attribute ();
4307 if (origin != NULL)
4308 abstract_origin_attribute (origin);
4309 else
4311 name_and_src_coords_attributes (decl);
4312 member_attribute (DECL_CONTEXT (decl));
4313 type_attribute (TREE_TYPE (decl),
4314 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4316 if (DECL_ABSTRACT (decl))
4317 equate_decl_number_to_die_number (decl);
4320 static void
4321 output_union_type_die (arg)
4322 void *arg;
4324 tree type = arg;
4326 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
4327 sibling_attribute ();
4328 equate_type_number_to_die_number (type);
4329 name_attribute (type_tag (type));
4330 member_attribute (TYPE_CONTEXT (type));
4332 /* If this type has been completed, then give it a byte_size attribute
4333 and prepare to give a list of members. Otherwise, don't do either of
4334 these things. In the latter case, we will not be generating a list
4335 of members (since we don't have any idea what they might be for an
4336 incomplete type). */
4338 if (COMPLETE_TYPE_P (type))
4340 dienum_push ();
4341 byte_size_attribute (type);
4345 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
4346 at the end of an (ANSI prototyped) formal parameters list. */
4348 static void
4349 output_unspecified_parameters_die (arg)
4350 void *arg;
4352 tree decl_or_type = arg;
4354 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
4355 sibling_attribute ();
4357 /* This kludge is here only for the sake of being compatible with what
4358 the USL CI5 C compiler does. The specification of Dwarf Version 1
4359 doesn't say that TAG_unspecified_parameters DIEs should contain any
4360 attributes other than the AT_sibling attribute, but they are certainly
4361 allowed to contain additional attributes, and the CI5 compiler
4362 generates AT_name, AT_fund_type, and AT_location attributes within
4363 TAG_unspecified_parameters DIEs which appear in the child lists for
4364 DIEs representing function definitions, so we do likewise here. */
4366 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
4368 name_attribute ("...");
4369 fund_type_attribute (FT_pointer);
4370 /* location_attribute (?); */
4374 static void
4375 output_padded_null_die (arg)
4376 void *arg ATTRIBUTE_UNUSED;
4378 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
4381 /*************************** end of DIEs *********************************/
4383 /* Generate some type of DIE. This routine generates the generic outer
4384 wrapper stuff which goes around all types of DIE's (regardless of their
4385 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
4386 DIE-length word, followed by the guts of the DIE itself. After the guts
4387 of the DIE, there must always be a terminator label for the DIE. */
4389 static void
4390 output_die (die_specific_output_function, param)
4391 void (*die_specific_output_function) PARAMS ((void *));
4392 void *param;
4394 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4395 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4397 current_dienum = NEXT_DIE_NUM;
4398 NEXT_DIE_NUM = next_unused_dienum;
4400 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4401 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4403 /* Write a label which will act as the name for the start of this DIE. */
4405 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4407 /* Write the DIE-length word. */
4409 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4411 /* Fill in the guts of the DIE. */
4413 next_unused_dienum++;
4414 die_specific_output_function (param);
4416 /* Write a label which will act as the name for the end of this DIE. */
4418 ASM_OUTPUT_LABEL (asm_out_file, end_label);
4421 static void
4422 end_sibling_chain ()
4424 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4426 current_dienum = NEXT_DIE_NUM;
4427 NEXT_DIE_NUM = next_unused_dienum;
4429 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4431 /* Write a label which will act as the name for the start of this DIE. */
4433 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4435 /* Write the DIE-length word. */
4437 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4439 dienum_pop ();
4442 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4443 TAG_unspecified_parameters DIE) to represent the types of the formal
4444 parameters as specified in some function type specification (except
4445 for those which appear as part of a function *definition*).
4447 Note that we must be careful here to output all of the parameter
4448 DIEs *before* we output any DIEs needed to represent the types of
4449 the formal parameters. This keeps svr4 SDB happy because it
4450 (incorrectly) thinks that the first non-parameter DIE it sees ends
4451 the formal parameter list. */
4453 static void
4454 output_formal_types (function_or_method_type)
4455 tree function_or_method_type;
4457 tree link;
4458 tree formal_type = NULL;
4459 tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4461 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4462 get bogus recursion when outputting tagged types local to a
4463 function declaration. */
4464 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4465 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4467 /* In the case where we are generating a formal types list for a C++
4468 non-static member function type, skip over the first thing on the
4469 TYPE_ARG_TYPES list because it only represents the type of the
4470 hidden `this pointer'. The debugger should be able to figure
4471 out (without being explicitly told) that this non-static member
4472 function type takes a `this pointer' and should be able to figure
4473 what the type of that hidden parameter is from the AT_member
4474 attribute of the parent TAG_subroutine_type DIE. */
4476 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4477 first_parm_type = TREE_CHAIN (first_parm_type);
4479 /* Make our first pass over the list of formal parameter types and output
4480 a TAG_formal_parameter DIE for each one. */
4482 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4484 formal_type = TREE_VALUE (link);
4485 if (formal_type == void_type_node)
4486 break;
4488 /* Output a (nameless) DIE to represent the formal parameter itself. */
4490 output_die (output_formal_parameter_die, formal_type);
4493 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4494 DIE to the end of the parameter list. */
4496 if (formal_type != void_type_node)
4497 output_die (output_unspecified_parameters_die, function_or_method_type);
4499 /* Make our second (and final) pass over the list of formal parameter types
4500 and output DIEs to represent those types (as necessary). */
4502 for (link = TYPE_ARG_TYPES (function_or_method_type);
4503 link;
4504 link = TREE_CHAIN (link))
4506 formal_type = TREE_VALUE (link);
4507 if (formal_type == void_type_node)
4508 break;
4510 output_type (formal_type, function_or_method_type);
4513 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4516 /* Remember a type in the pending_types_list. */
4518 static void
4519 pend_type (type)
4520 tree type;
4522 if (pending_types == pending_types_allocated)
4524 pending_types_allocated += PENDING_TYPES_INCREMENT;
4525 pending_types_list
4526 = (tree *) xrealloc (pending_types_list,
4527 sizeof (tree) * pending_types_allocated);
4529 pending_types_list[pending_types++] = type;
4531 /* Mark the pending type as having been output already (even though
4532 it hasn't been). This prevents the type from being added to the
4533 pending_types_list more than once. */
4535 TREE_ASM_WRITTEN (type) = 1;
4538 /* Return nonzero if it is legitimate to output DIEs to represent a
4539 given type while we are generating the list of child DIEs for some
4540 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4542 See the comments within the function for a description of when it is
4543 considered legitimate to output DIEs for various kinds of types.
4545 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4546 or it may point to a BLOCK node (for types local to a block), or to a
4547 FUNCTION_DECL node (for types local to the heading of some function
4548 definition), or to a FUNCTION_TYPE node (for types local to the
4549 prototyped parameter list of a function type specification), or to a
4550 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4551 (in the case of C++ nested types).
4553 The `scope' parameter should likewise be NULL or should point to a
4554 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4555 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4557 This function is used only for deciding when to "pend" and when to
4558 "un-pend" types to/from the pending_types_list.
4560 Note that we sometimes make use of this "type pending" feature in a
4561 rather twisted way to temporarily delay the production of DIEs for the
4562 types of formal parameters. (We do this just to make svr4 SDB happy.)
4563 It order to delay the production of DIEs representing types of formal
4564 parameters, callers of this function supply `fake_containing_scope' as
4565 the `scope' parameter to this function. Given that fake_containing_scope
4566 is a tagged type which is *not* the containing scope for *any* other type,
4567 the desired effect is achieved, i.e. output of DIEs representing types
4568 is temporarily suspended, and any type DIEs which would have otherwise
4569 been output are instead placed onto the pending_types_list. Later on,
4570 we force these (temporarily pended) types to be output simply by calling
4571 `output_pending_types_for_scope' with an actual argument equal to the
4572 true scope of the types we temporarily pended. */
4574 static inline int
4575 type_ok_for_scope (type, scope)
4576 tree type;
4577 tree scope;
4579 /* Tagged types (i.e. struct, union, and enum types) must always be
4580 output only in the scopes where they actually belong (or else the
4581 scoping of their own tag names and the scoping of their member
4582 names will be incorrect). Non-tagged-types on the other hand can
4583 generally be output anywhere, except that svr4 SDB really doesn't
4584 want to see them nested within struct or union types, so here we
4585 say it is always OK to immediately output any such a (non-tagged)
4586 type, so long as we are not within such a context. Note that the
4587 only kinds of non-tagged types which we will be dealing with here
4588 (for C and C++ anyway) will be array types and function types. */
4590 return is_tagged_type (type)
4591 ? (TYPE_CONTEXT (type) == scope
4592 /* Ignore namespaces for the moment. */
4593 || (scope == NULL_TREE
4594 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4595 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4596 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4597 : (scope == NULL_TREE || ! is_tagged_type (scope));
4600 /* Output any pending types (from the pending_types list) which we can output
4601 now (taking into account the scope that we are working on now).
4603 For each type output, remove the given type from the pending_types_list
4604 *before* we try to output it.
4606 Note that we have to process the list in beginning-to-end order,
4607 because the call made here to output_type may cause yet more types
4608 to be added to the end of the list, and we may have to output some
4609 of them too. */
4611 static void
4612 output_pending_types_for_scope (containing_scope)
4613 tree containing_scope;
4615 unsigned i;
4617 for (i = 0; i < pending_types; )
4619 tree type = pending_types_list[i];
4621 if (type_ok_for_scope (type, containing_scope))
4623 tree *mover;
4624 tree *limit;
4626 pending_types--;
4627 limit = &pending_types_list[pending_types];
4628 for (mover = &pending_types_list[i]; mover < limit; mover++)
4629 *mover = *(mover+1);
4631 /* Un-mark the type as having been output already (because it
4632 hasn't been, really). Then call output_type to generate a
4633 Dwarf representation of it. */
4635 TREE_ASM_WRITTEN (type) = 0;
4636 output_type (type, containing_scope);
4638 /* Don't increment the loop counter in this case because we
4639 have shifted all of the subsequent pending types down one
4640 element in the pending_types_list array. */
4642 else
4643 i++;
4647 /* Remember a type in the incomplete_types_list. */
4649 static void
4650 add_incomplete_type (type)
4651 tree type;
4653 if (incomplete_types == incomplete_types_allocated)
4655 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4656 incomplete_types_list
4657 = (tree *) xrealloc (incomplete_types_list,
4658 sizeof (tree) * incomplete_types_allocated);
4661 incomplete_types_list[incomplete_types++] = type;
4664 /* Walk through the list of incomplete types again, trying once more to
4665 emit full debugging info for them. */
4667 static void
4668 retry_incomplete_types ()
4670 tree type;
4672 finalizing = 1;
4673 while (incomplete_types)
4675 --incomplete_types;
4676 type = incomplete_types_list[incomplete_types];
4677 output_type (type, NULL_TREE);
4681 static void
4682 output_type (type, containing_scope)
4683 tree type;
4684 tree containing_scope;
4686 if (type == 0 || type == error_mark_node)
4687 return;
4689 /* We are going to output a DIE to represent the unqualified version of
4690 this type (i.e. without any const or volatile qualifiers) so get
4691 the main variant (i.e. the unqualified version) of this type now. */
4693 type = type_main_variant (type);
4695 if (TREE_ASM_WRITTEN (type))
4697 if (finalizing && AGGREGATE_TYPE_P (type))
4699 tree member;
4701 /* Some of our nested types might not have been defined when we
4702 were written out before; force them out now. */
4704 for (member = TYPE_FIELDS (type); member;
4705 member = TREE_CHAIN (member))
4706 if (TREE_CODE (member) == TYPE_DECL
4707 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4708 output_type (TREE_TYPE (member), containing_scope);
4710 return;
4713 /* If this is a nested type whose containing class hasn't been
4714 written out yet, writing it out will cover this one, too. */
4716 if (TYPE_CONTEXT (type)
4717 && TYPE_P (TYPE_CONTEXT (type))
4718 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4720 output_type (TYPE_CONTEXT (type), containing_scope);
4721 return;
4724 /* Don't generate any DIEs for this type now unless it is OK to do so
4725 (based upon what `type_ok_for_scope' tells us). */
4727 if (! type_ok_for_scope (type, containing_scope))
4729 pend_type (type);
4730 return;
4733 switch (TREE_CODE (type))
4735 case ERROR_MARK:
4736 break;
4738 case VECTOR_TYPE:
4739 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4740 break;
4742 case POINTER_TYPE:
4743 case REFERENCE_TYPE:
4744 /* Prevent infinite recursion in cases where this is a recursive
4745 type. Recursive types are possible in Ada. */
4746 TREE_ASM_WRITTEN (type) = 1;
4747 /* For these types, all that is required is that we output a DIE
4748 (or a set of DIEs) to represent the "basis" type. */
4749 output_type (TREE_TYPE (type), containing_scope);
4750 break;
4752 case OFFSET_TYPE:
4753 /* This code is used for C++ pointer-to-data-member types. */
4754 /* Output a description of the relevant class type. */
4755 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4756 /* Output a description of the type of the object pointed to. */
4757 output_type (TREE_TYPE (type), containing_scope);
4758 /* Now output a DIE to represent this pointer-to-data-member type
4759 itself. */
4760 output_die (output_ptr_to_mbr_type_die, type);
4761 break;
4763 case SET_TYPE:
4764 output_type (TYPE_DOMAIN (type), containing_scope);
4765 output_die (output_set_type_die, type);
4766 break;
4768 case FILE_TYPE:
4769 output_type (TREE_TYPE (type), containing_scope);
4770 abort (); /* No way to represent these in Dwarf yet! */
4771 break;
4773 case FUNCTION_TYPE:
4774 /* Force out return type (in case it wasn't forced out already). */
4775 output_type (TREE_TYPE (type), containing_scope);
4776 output_die (output_subroutine_type_die, type);
4777 output_formal_types (type);
4778 end_sibling_chain ();
4779 break;
4781 case METHOD_TYPE:
4782 /* Force out return type (in case it wasn't forced out already). */
4783 output_type (TREE_TYPE (type), containing_scope);
4784 output_die (output_subroutine_type_die, type);
4785 output_formal_types (type);
4786 end_sibling_chain ();
4787 break;
4789 case ARRAY_TYPE:
4790 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4792 output_type (TREE_TYPE (type), containing_scope);
4793 output_die (output_string_type_die, type);
4795 else
4797 tree element_type;
4799 element_type = TREE_TYPE (type);
4800 while (TREE_CODE (element_type) == ARRAY_TYPE)
4801 element_type = TREE_TYPE (element_type);
4803 output_type (element_type, containing_scope);
4804 output_die (output_array_type_die, type);
4806 break;
4808 case ENUMERAL_TYPE:
4809 case RECORD_TYPE:
4810 case UNION_TYPE:
4811 case QUAL_UNION_TYPE:
4813 /* For a non-file-scope tagged type, we can always go ahead and
4814 output a Dwarf description of this type right now, even if
4815 the type in question is still incomplete, because if this
4816 local type *was* ever completed anywhere within its scope,
4817 that complete definition would already have been attached to
4818 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4819 node by the time we reach this point. That's true because of the
4820 way the front-end does its processing of file-scope declarations (of
4821 functions and class types) within which other types might be
4822 nested. The C and C++ front-ends always gobble up such "local
4823 scope" things en-mass before they try to output *any* debugging
4824 information for any of the stuff contained inside them and thus,
4825 we get the benefit here of what is (in effect) a pre-resolution
4826 of forward references to tagged types in local scopes.
4828 Note however that for file-scope tagged types we cannot assume
4829 that such pre-resolution of forward references has taken place.
4830 A given file-scope tagged type may appear to be incomplete when
4831 we reach this point, but it may yet be given a full definition
4832 (at file-scope) later on during compilation. In order to avoid
4833 generating a premature (and possibly incorrect) set of Dwarf
4834 DIEs for such (as yet incomplete) file-scope tagged types, we
4835 generate nothing at all for as-yet incomplete file-scope tagged
4836 types here unless we are making our special "finalization" pass
4837 for file-scope things at the very end of compilation. At that
4838 time, we will certainly know as much about each file-scope tagged
4839 type as we are ever going to know, so at that point in time, we
4840 can safely generate correct Dwarf descriptions for these file-
4841 scope tagged types. */
4843 if (!COMPLETE_TYPE_P (type)
4844 && (TYPE_CONTEXT (type) == NULL
4845 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4846 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4847 && !finalizing)
4849 /* We don't need to do this for function-local types. */
4850 if (! decl_function_context (TYPE_STUB_DECL (type)))
4851 add_incomplete_type (type);
4852 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4855 /* Prevent infinite recursion in cases where the type of some
4856 member of this type is expressed in terms of this type itself. */
4858 TREE_ASM_WRITTEN (type) = 1;
4860 /* Output a DIE to represent the tagged type itself. */
4862 switch (TREE_CODE (type))
4864 case ENUMERAL_TYPE:
4865 output_die (output_enumeration_type_die, type);
4866 return; /* a special case -- nothing left to do so just return */
4868 case RECORD_TYPE:
4869 output_die (output_structure_type_die, type);
4870 break;
4872 case UNION_TYPE:
4873 case QUAL_UNION_TYPE:
4874 output_die (output_union_type_die, type);
4875 break;
4877 default:
4878 abort (); /* Should never happen. */
4881 /* If this is not an incomplete type, output descriptions of
4882 each of its members.
4884 Note that as we output the DIEs necessary to represent the
4885 members of this record or union type, we will also be trying
4886 to output DIEs to represent the *types* of those members.
4887 However the `output_type' function (above) will specifically
4888 avoid generating type DIEs for member types *within* the list
4889 of member DIEs for this (containing) type except for those
4890 types (of members) which are explicitly marked as also being
4891 members of this (containing) type themselves. The g++ front-
4892 end can force any given type to be treated as a member of some
4893 other (containing) type by setting the TYPE_CONTEXT of the
4894 given (member) type to point to the TREE node representing the
4895 appropriate (containing) type.
4898 if (COMPLETE_TYPE_P (type))
4900 tree binfo = TYPE_BINFO (type);
4902 /* First output info about the base classes. */
4903 if (binfo)
4905 tree bases = BINFO_BASETYPES (binfo);
4906 tree accesses = BINFO_BASEACCESSES (binfo);
4907 register int n_bases = BINFO_N_BASETYPES (binfo);
4908 register int i;
4910 for (i = 0; i < n_bases; i++)
4912 tree arg[2];
4914 arg[0] = TREE_VEC_ELT (bases, i);
4915 arg[1] = (accesses ? TREE_VEC_ELT (accesses, i)
4916 : access_public_node);
4917 output_type (BINFO_TYPE (binfo), containing_scope);
4918 output_die (output_inheritance_die, arg);
4922 ++in_class;
4925 tree normal_member;
4927 /* Now output info about the data members and type members. */
4929 for (normal_member = TYPE_FIELDS (type);
4930 normal_member;
4931 normal_member = TREE_CHAIN (normal_member))
4932 output_decl (normal_member, type);
4936 tree func_member;
4938 /* Now output info about the function members (if any). */
4940 for (func_member = TYPE_METHODS (type);
4941 func_member;
4942 func_member = TREE_CHAIN (func_member))
4944 /* Don't include clones in the member list. */
4945 if (DECL_ABSTRACT_ORIGIN (func_member))
4946 continue;
4948 output_decl (func_member, type);
4952 --in_class;
4954 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4955 scopes (at least in C++) so we must now output any nested
4956 pending types which are local just to this type. */
4958 output_pending_types_for_scope (type);
4960 end_sibling_chain (); /* Terminate member chain. */
4963 break;
4965 case VOID_TYPE:
4966 case INTEGER_TYPE:
4967 case REAL_TYPE:
4968 case COMPLEX_TYPE:
4969 case BOOLEAN_TYPE:
4970 case CHAR_TYPE:
4971 break; /* No DIEs needed for fundamental types. */
4973 case LANG_TYPE: /* No Dwarf representation currently defined. */
4974 break;
4976 default:
4977 abort ();
4980 TREE_ASM_WRITTEN (type) = 1;
4983 static void
4984 output_tagged_type_instantiation (type)
4985 tree type;
4987 if (type == 0 || type == error_mark_node)
4988 return;
4990 /* We are going to output a DIE to represent the unqualified version of
4991 this type (i.e. without any const or volatile qualifiers) so make
4992 sure that we have the main variant (i.e. the unqualified version) of
4993 this type now. */
4995 if (type != type_main_variant (type))
4996 abort ();
4998 if (!TREE_ASM_WRITTEN (type))
4999 abort ();
5001 switch (TREE_CODE (type))
5003 case ERROR_MARK:
5004 break;
5006 case ENUMERAL_TYPE:
5007 output_die (output_inlined_enumeration_type_die, type);
5008 break;
5010 case RECORD_TYPE:
5011 output_die (output_inlined_structure_type_die, type);
5012 break;
5014 case UNION_TYPE:
5015 case QUAL_UNION_TYPE:
5016 output_die (output_inlined_union_type_die, type);
5017 break;
5019 default:
5020 abort (); /* Should never happen. */
5024 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
5025 the things which are local to the given block. */
5027 static void
5028 output_block (stmt, depth)
5029 tree stmt;
5030 int depth;
5032 int must_output_die = 0;
5033 tree origin;
5034 enum tree_code origin_code;
5036 /* Ignore blocks never really used to make RTL. */
5038 if (! stmt || ! TREE_USED (stmt)
5039 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
5040 return;
5042 /* Determine the "ultimate origin" of this block. This block may be an
5043 inlined instance of an inlined instance of inline function, so we
5044 have to trace all of the way back through the origin chain to find
5045 out what sort of node actually served as the original seed for the
5046 creation of the current block. */
5048 origin = block_ultimate_origin (stmt);
5049 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
5051 /* Determine if we need to output any Dwarf DIEs at all to represent this
5052 block. */
5054 if (origin_code == FUNCTION_DECL)
5055 /* The outer scopes for inlinings *must* always be represented. We
5056 generate TAG_inlined_subroutine DIEs for them. (See below.) */
5057 must_output_die = 1;
5058 else
5060 /* In the case where the current block represents an inlining of the
5061 "body block" of an inline function, we must *NOT* output any DIE
5062 for this block because we have already output a DIE to represent
5063 the whole inlined function scope and the "body block" of any
5064 function doesn't really represent a different scope according to
5065 ANSI C rules. So we check here to make sure that this block does
5066 not represent a "body block inlining" before trying to set the
5067 `must_output_die' flag. */
5069 if (! is_body_block (origin ? origin : stmt))
5071 /* Determine if this block directly contains any "significant"
5072 local declarations which we will need to output DIEs for. */
5074 if (debug_info_level > DINFO_LEVEL_TERSE)
5075 /* We are not in terse mode so *any* local declaration counts
5076 as being a "significant" one. */
5077 must_output_die = (BLOCK_VARS (stmt) != NULL);
5078 else
5080 tree decl;
5082 /* We are in terse mode, so only local (nested) function
5083 definitions count as "significant" local declarations. */
5085 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5086 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
5088 must_output_die = 1;
5089 break;
5095 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
5096 DIE for any block which contains no significant local declarations
5097 at all. Rather, in such cases we just call `output_decls_for_scope'
5098 so that any needed Dwarf info for any sub-blocks will get properly
5099 generated. Note that in terse mode, our definition of what constitutes
5100 a "significant" local declaration gets restricted to include only
5101 inlined function instances and local (nested) function definitions. */
5103 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
5104 /* We don't care about an abstract inlined subroutine. */;
5105 else if (must_output_die)
5107 output_die ((origin_code == FUNCTION_DECL)
5108 ? output_inlined_subroutine_die
5109 : output_lexical_block_die,
5110 stmt);
5111 output_decls_for_scope (stmt, depth);
5112 end_sibling_chain ();
5114 else
5115 output_decls_for_scope (stmt, depth);
5118 /* Output all of the decls declared within a given scope (also called
5119 a `binding contour') and (recursively) all of it's sub-blocks. */
5121 static void
5122 output_decls_for_scope (stmt, depth)
5123 tree stmt;
5124 int depth;
5126 /* Ignore blocks never really used to make RTL. */
5128 if (! stmt || ! TREE_USED (stmt))
5129 return;
5131 /* Output the DIEs to represent all of the data objects, functions,
5132 typedefs, and tagged types declared directly within this block
5133 but not within any nested sub-blocks. */
5136 tree decl;
5138 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5139 output_decl (decl, stmt);
5142 output_pending_types_for_scope (stmt);
5144 /* Output the DIEs to represent all sub-blocks (and the items declared
5145 therein) of this block. */
5148 tree subblocks;
5150 for (subblocks = BLOCK_SUBBLOCKS (stmt);
5151 subblocks;
5152 subblocks = BLOCK_CHAIN (subblocks))
5153 output_block (subblocks, depth + 1);
5157 /* Is this a typedef we can avoid emitting? */
5159 static inline int
5160 is_redundant_typedef (decl)
5161 tree decl;
5163 if (TYPE_DECL_IS_STUB (decl))
5164 return 1;
5165 if (DECL_ARTIFICIAL (decl)
5166 && DECL_CONTEXT (decl)
5167 && is_tagged_type (DECL_CONTEXT (decl))
5168 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
5169 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
5170 /* Also ignore the artificial member typedef for the class name. */
5171 return 1;
5172 return 0;
5175 /* Output Dwarf .debug information for a decl described by DECL. */
5177 static void
5178 output_decl (decl, containing_scope)
5179 tree decl;
5180 tree containing_scope;
5182 /* Make a note of the decl node we are going to be working on. We may
5183 need to give the user the source coordinates of where it appeared in
5184 case we notice (later on) that something about it looks screwy. */
5186 dwarf_last_decl = decl;
5188 if (TREE_CODE (decl) == ERROR_MARK)
5189 return;
5191 /* If a structure is declared within an initialization, e.g. as the
5192 operand of a sizeof, then it will not have a name. We don't want
5193 to output a DIE for it, as the tree nodes are in the temporary obstack */
5195 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5196 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
5197 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
5198 || (TYPE_FIELDS (TREE_TYPE (decl))
5199 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
5200 return;
5202 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5204 if (DECL_IGNORED_P (decl))
5205 return;
5207 switch (TREE_CODE (decl))
5209 case CONST_DECL:
5210 /* The individual enumerators of an enum type get output when we
5211 output the Dwarf representation of the relevant enum type itself. */
5212 break;
5214 case FUNCTION_DECL:
5215 /* If we are in terse mode, don't output any DIEs to represent
5216 mere function declarations. Also, if we are conforming
5217 to the DWARF version 1 specification, don't output DIEs for
5218 mere function declarations. */
5220 if (DECL_INITIAL (decl) == NULL_TREE)
5221 #if (DWARF_VERSION > 1)
5222 if (debug_info_level <= DINFO_LEVEL_TERSE)
5223 #endif
5224 break;
5226 /* Before we describe the FUNCTION_DECL itself, make sure that we
5227 have described its return type. */
5229 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
5232 /* And its containing type. */
5233 register tree origin = decl_class_context (decl);
5234 if (origin)
5235 output_type (origin, containing_scope);
5238 /* If we're emitting an out-of-line copy of an inline function,
5239 set up to refer to the abstract instance emitted from
5240 dwarfout_deferred_inline_function. */
5241 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
5242 && ! (containing_scope && TYPE_P (containing_scope)))
5243 set_decl_origin_self (decl);
5245 /* If the following DIE will represent a function definition for a
5246 function with "extern" linkage, output a special "pubnames" DIE
5247 label just ahead of the actual DIE. A reference to this label
5248 was already generated in the .debug_pubnames section sub-entry
5249 for this function definition. */
5251 if (TREE_PUBLIC (decl))
5253 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5255 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5256 ASM_OUTPUT_LABEL (asm_out_file, label);
5259 /* Now output a DIE to represent the function itself. */
5261 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
5262 ? output_global_subroutine_die
5263 : output_local_subroutine_die,
5264 decl);
5266 /* Now output descriptions of the arguments for this function.
5267 This gets (unnecessarily?) complex because of the fact that
5268 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
5269 cases where there was a trailing `...' at the end of the formal
5270 parameter list. In order to find out if there was a trailing
5271 ellipsis or not, we must instead look at the type associated
5272 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
5273 If the chain of type nodes hanging off of this FUNCTION_TYPE node
5274 ends with a void_type_node then there should *not* be an ellipsis
5275 at the end. */
5277 /* In the case where we are describing a mere function declaration, all
5278 we need to do here (and all we *can* do here) is to describe
5279 the *types* of its formal parameters. */
5281 if (decl != current_function_decl || in_class)
5282 output_formal_types (TREE_TYPE (decl));
5283 else
5285 /* Generate DIEs to represent all known formal parameters */
5287 tree arg_decls = DECL_ARGUMENTS (decl);
5288 tree parm;
5290 /* WARNING! Kludge zone ahead! Here we have a special
5291 hack for svr4 SDB compatibility. Instead of passing the
5292 current FUNCTION_DECL node as the second parameter (i.e.
5293 the `containing_scope' parameter) to `output_decl' (as
5294 we ought to) we instead pass a pointer to our own private
5295 fake_containing_scope node. That node is a RECORD_TYPE
5296 node which NO OTHER TYPE may ever actually be a member of.
5298 This pointer will ultimately get passed into `output_type'
5299 as its `containing_scope' parameter. `Output_type' will
5300 then perform its part in the hack... i.e. it will pend
5301 the type of the formal parameter onto the pending_types
5302 list. Later on, when we are done generating the whole
5303 sequence of formal parameter DIEs for this function
5304 definition, we will un-pend all previously pended types
5305 of formal parameters for this function definition.
5307 This whole kludge prevents any type DIEs from being
5308 mixed in with the formal parameter DIEs. That's good
5309 because svr4 SDB believes that the list of formal
5310 parameter DIEs for a function ends wherever the first
5311 non-formal-parameter DIE appears. Thus, we have to
5312 keep the formal parameter DIEs segregated. They must
5313 all appear (consecutively) at the start of the list of
5314 children for the DIE representing the function definition.
5315 Then (and only then) may we output any additional DIEs
5316 needed to represent the types of these formal parameters.
5320 When generating DIEs, generate the unspecified_parameters
5321 DIE instead if we come across the arg "__builtin_va_alist"
5324 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
5325 if (TREE_CODE (parm) == PARM_DECL)
5327 if (DECL_NAME(parm) &&
5328 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
5329 "__builtin_va_alist") )
5330 output_die (output_unspecified_parameters_die, decl);
5331 else
5332 output_decl (parm, fake_containing_scope);
5336 Now that we have finished generating all of the DIEs to
5337 represent the formal parameters themselves, force out
5338 any DIEs needed to represent their types. We do this
5339 simply by un-pending all previously pended types which
5340 can legitimately go into the chain of children DIEs for
5341 the current FUNCTION_DECL.
5344 output_pending_types_for_scope (decl);
5347 Decide whether we need an unspecified_parameters DIE at the end.
5348 There are 2 more cases to do this for:
5349 1) the ansi ... declaration - this is detectable when the end
5350 of the arg list is not a void_type_node
5351 2) an unprototyped function declaration (not a definition). This
5352 just means that we have no info about the parameters at all.
5356 tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
5358 if (fn_arg_types)
5360 /* this is the prototyped case, check for ... */
5361 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
5362 output_die (output_unspecified_parameters_die, decl);
5364 else
5366 /* this is unprototyped, check for undefined (just declaration) */
5367 if (!DECL_INITIAL (decl))
5368 output_die (output_unspecified_parameters_die, decl);
5372 /* Output Dwarf info for all of the stuff within the body of the
5373 function (if it has one - it may be just a declaration). */
5376 tree outer_scope = DECL_INITIAL (decl);
5378 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
5380 /* Note that here, `outer_scope' is a pointer to the outermost
5381 BLOCK node created to represent a function.
5382 This outermost BLOCK actually represents the outermost
5383 binding contour for the function, i.e. the contour in which
5384 the function's formal parameters and labels get declared.
5386 Curiously, it appears that the front end doesn't actually
5387 put the PARM_DECL nodes for the current function onto the
5388 BLOCK_VARS list for this outer scope. (They are strung
5389 off of the DECL_ARGUMENTS list for the function instead.)
5390 The BLOCK_VARS list for the `outer_scope' does provide us
5391 with a list of the LABEL_DECL nodes for the function however,
5392 and we output DWARF info for those here.
5394 Just within the `outer_scope' there will be a BLOCK node
5395 representing the function's outermost pair of curly braces,
5396 and any blocks used for the base and member initializers of
5397 a C++ constructor function. */
5399 output_decls_for_scope (outer_scope, 0);
5401 /* Finally, force out any pending types which are local to the
5402 outermost block of this function definition. These will
5403 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
5404 node itself. */
5406 output_pending_types_for_scope (decl);
5411 /* Generate a terminator for the list of stuff `owned' by this
5412 function. */
5414 end_sibling_chain ();
5416 break;
5418 case TYPE_DECL:
5419 /* If we are in terse mode, don't generate any DIEs to represent
5420 any actual typedefs. Note that even when we are in terse mode,
5421 we must still output DIEs to represent those tagged types which
5422 are used (directly or indirectly) in the specification of either
5423 a return type or a formal parameter type of some function. */
5425 if (debug_info_level <= DINFO_LEVEL_TERSE)
5426 if (! TYPE_DECL_IS_STUB (decl)
5427 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5428 return;
5430 /* In the special case of a TYPE_DECL node representing
5431 the declaration of some type tag, if the given TYPE_DECL is
5432 marked as having been instantiated from some other (original)
5433 TYPE_DECL node (e.g. one which was generated within the original
5434 definition of an inline function) we have to generate a special
5435 (abbreviated) TAG_structure_type, TAG_union_type, or
5436 TAG_enumeration-type DIE here. */
5438 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5440 output_tagged_type_instantiation (TREE_TYPE (decl));
5441 return;
5444 output_type (TREE_TYPE (decl), containing_scope);
5446 if (! is_redundant_typedef (decl))
5447 /* Output a DIE to represent the typedef itself. */
5448 output_die (output_typedef_die, decl);
5449 break;
5451 case LABEL_DECL:
5452 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5453 output_die (output_label_die, decl);
5454 break;
5456 case VAR_DECL:
5457 /* If we are conforming to the DWARF version 1 specification, don't
5458 generated any DIEs to represent mere external object declarations. */
5460 #if (DWARF_VERSION <= 1)
5461 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5462 break;
5463 #endif
5465 /* If we are in terse mode, don't generate any DIEs to represent
5466 any variable declarations or definitions. */
5468 if (debug_info_level <= DINFO_LEVEL_TERSE)
5469 break;
5471 /* Output any DIEs that are needed to specify the type of this data
5472 object. */
5474 output_type (TREE_TYPE (decl), containing_scope);
5477 /* And its containing type. */
5478 register tree origin = decl_class_context (decl);
5479 if (origin)
5480 output_type (origin, containing_scope);
5483 /* If the following DIE will represent a data object definition for a
5484 data object with "extern" linkage, output a special "pubnames" DIE
5485 label just ahead of the actual DIE. A reference to this label
5486 was already generated in the .debug_pubnames section sub-entry
5487 for this data object definition. */
5489 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5491 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5493 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5494 ASM_OUTPUT_LABEL (asm_out_file, label);
5497 /* Now output the DIE to represent the data object itself. This gets
5498 complicated because of the possibility that the VAR_DECL really
5499 represents an inlined instance of a formal parameter for an inline
5500 function. */
5503 void (*func) PARAMS ((void *));
5504 register tree origin = decl_ultimate_origin (decl);
5506 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5507 func = output_formal_parameter_die;
5508 else
5510 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5511 func = output_global_variable_die;
5512 else
5513 func = output_local_variable_die;
5515 output_die (func, decl);
5517 break;
5519 case FIELD_DECL:
5520 /* Ignore the nameless fields that are used to skip bits. */
5521 if (DECL_NAME (decl) != 0)
5523 output_type (member_declared_type (decl), containing_scope);
5524 output_die (output_member_die, decl);
5526 break;
5528 case PARM_DECL:
5529 /* Force out the type of this formal, if it was not forced out yet.
5530 Note that here we can run afoul of a bug in "classic" svr4 SDB.
5531 It should be able to grok the presence of type DIEs within a list
5532 of TAG_formal_parameter DIEs, but it doesn't. */
5534 output_type (TREE_TYPE (decl), containing_scope);
5535 output_die (output_formal_parameter_die, decl);
5536 break;
5538 case NAMESPACE_DECL:
5539 /* Ignore for now. */
5540 break;
5542 default:
5543 abort ();
5547 /* Output debug information for a function. */
5548 static void
5549 dwarfout_function_decl (decl)
5550 tree decl;
5552 dwarfout_file_scope_decl (decl, 0);
5555 /* Debug information for a global DECL. Called from toplev.c after
5556 compilation proper has finished. */
5557 static void
5558 dwarfout_global_decl (decl)
5559 tree decl;
5561 /* Output DWARF information for file-scope tentative data object
5562 declarations, file-scope (extern) function declarations (which
5563 had no corresponding body) and file-scope tagged type
5564 declarations and definitions which have not yet been forced out. */
5566 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
5567 dwarfout_file_scope_decl (decl, 1);
5570 /* DECL is an inline function, whose body is present, but which is not
5571 being output at this point. (We're putting that off until we need
5572 to do it.) */
5573 static void
5574 dwarfout_deferred_inline_function (decl)
5575 tree decl;
5577 /* Generate the DWARF info for the "abstract" instance of a function
5578 which we may later generate inlined and/or out-of-line instances
5579 of. */
5580 if ((DECL_INLINE (decl) || DECL_ABSTRACT (decl))
5581 && ! DECL_ABSTRACT_ORIGIN (decl))
5583 /* The front-end may not have set CURRENT_FUNCTION_DECL, but the
5584 DWARF code expects it to be set in this case. Intuitively,
5585 DECL is the function we just finished defining, so setting
5586 CURRENT_FUNCTION_DECL is sensible. */
5587 tree saved_cfd = current_function_decl;
5588 int was_abstract = DECL_ABSTRACT (decl);
5589 current_function_decl = decl;
5591 /* Let the DWARF code do its work. */
5592 set_decl_abstract_flags (decl, 1);
5593 dwarfout_file_scope_decl (decl, 0);
5594 if (! was_abstract)
5595 set_decl_abstract_flags (decl, 0);
5597 /* Reset CURRENT_FUNCTION_DECL. */
5598 current_function_decl = saved_cfd;
5602 static void
5603 dwarfout_file_scope_decl (decl, set_finalizing)
5604 tree decl;
5605 int set_finalizing;
5607 if (TREE_CODE (decl) == ERROR_MARK)
5608 return;
5610 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5612 if (DECL_IGNORED_P (decl))
5613 return;
5615 switch (TREE_CODE (decl))
5617 case FUNCTION_DECL:
5619 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5620 a builtin function. Explicit programmer-supplied declarations of
5621 these same functions should NOT be ignored however. */
5623 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5624 return;
5626 /* What we would really like to do here is to filter out all mere
5627 file-scope declarations of file-scope functions which are never
5628 referenced later within this translation unit (and keep all of
5629 ones that *are* referenced later on) but we aren't clairvoyant,
5630 so we have no idea which functions will be referenced in the
5631 future (i.e. later on within the current translation unit).
5632 So here we just ignore all file-scope function declarations
5633 which are not also definitions. If and when the debugger needs
5634 to know something about these functions, it will have to hunt
5635 around and find the DWARF information associated with the
5636 *definition* of the function.
5638 Note that we can't just check `DECL_EXTERNAL' to find out which
5639 FUNCTION_DECL nodes represent definitions and which ones represent
5640 mere declarations. We have to check `DECL_INITIAL' instead. That's
5641 because the C front-end supports some weird semantics for "extern
5642 inline" function definitions. These can get inlined within the
5643 current translation unit (an thus, we need to generate DWARF info
5644 for their abstract instances so that the DWARF info for the
5645 concrete inlined instances can have something to refer to) but
5646 the compiler never generates any out-of-lines instances of such
5647 things (despite the fact that they *are* definitions). The
5648 important point is that the C front-end marks these "extern inline"
5649 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5650 anyway.
5652 Note that the C++ front-end also plays some similar games for inline
5653 function definitions appearing within include files which also
5654 contain `#pragma interface' pragmas. */
5656 if (DECL_INITIAL (decl) == NULL_TREE)
5657 return;
5659 if (TREE_PUBLIC (decl)
5660 && ! DECL_EXTERNAL (decl)
5661 && ! DECL_ABSTRACT (decl))
5663 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5665 /* Output a .debug_pubnames entry for a public function
5666 defined in this compilation unit. */
5668 fputc ('\n', asm_out_file);
5669 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5670 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5671 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5672 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5673 IDENTIFIER_POINTER (DECL_NAME (decl)));
5674 ASM_OUTPUT_POP_SECTION (asm_out_file);
5677 break;
5679 case VAR_DECL:
5681 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5682 object declaration and if the declaration was never even
5683 referenced from within this entire compilation unit. We
5684 suppress these DIEs in order to save space in the .debug section
5685 (by eliminating entries which are probably useless). Note that
5686 we must not suppress block-local extern declarations (whether
5687 used or not) because that would screw-up the debugger's name
5688 lookup mechanism and cause it to miss things which really ought
5689 to be in scope at a given point. */
5691 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5692 return;
5694 if (TREE_PUBLIC (decl)
5695 && ! DECL_EXTERNAL (decl)
5696 && GET_CODE (DECL_RTL (decl)) == MEM
5697 && ! DECL_ABSTRACT (decl))
5699 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5701 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5703 /* Output a .debug_pubnames entry for a public variable
5704 defined in this compilation unit. */
5706 fputc ('\n', asm_out_file);
5707 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5708 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5709 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5710 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5711 IDENTIFIER_POINTER (DECL_NAME (decl)));
5712 ASM_OUTPUT_POP_SECTION (asm_out_file);
5715 if (DECL_INITIAL (decl) == NULL)
5717 /* Output a .debug_aranges entry for a public variable
5718 which is tentatively defined in this compilation unit. */
5720 fputc ('\n', asm_out_file);
5721 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
5722 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5723 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5724 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5725 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5726 ASM_OUTPUT_POP_SECTION (asm_out_file);
5730 /* If we are in terse mode, don't generate any DIEs to represent
5731 any variable declarations or definitions. */
5733 if (debug_info_level <= DINFO_LEVEL_TERSE)
5734 return;
5736 break;
5738 case TYPE_DECL:
5739 /* Don't bother trying to generate any DIEs to represent any of the
5740 normal built-in types for the language we are compiling, except
5741 in cases where the types in question are *not* DWARF fundamental
5742 types. We make an exception in the case of non-fundamental types
5743 for the sake of objective C (and perhaps C++) because the GNU
5744 front-ends for these languages may in fact create certain "built-in"
5745 types which are (for example) RECORD_TYPEs. In such cases, we
5746 really need to output these (non-fundamental) types because other
5747 DIEs may contain references to them. */
5749 /* Also ignore language dependent types here, because they are probably
5750 also built-in types. If we didn't ignore them, then we would get
5751 references to undefined labels because output_type doesn't support
5752 them. So, for now, we need to ignore them to avoid assembler
5753 errors. */
5755 /* ??? This code is different than the equivalent code in dwarf2out.c.
5756 The dwarf2out.c code is probably more correct. */
5758 if (DECL_SOURCE_LINE (decl) == 0
5759 && (type_is_fundamental (TREE_TYPE (decl))
5760 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5761 return;
5763 /* If we are in terse mode, don't generate any DIEs to represent
5764 any actual typedefs. Note that even when we are in terse mode,
5765 we must still output DIEs to represent those tagged types which
5766 are used (directly or indirectly) in the specification of either
5767 a return type or a formal parameter type of some function. */
5769 if (debug_info_level <= DINFO_LEVEL_TERSE)
5770 if (! TYPE_DECL_IS_STUB (decl)
5771 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5772 return;
5774 break;
5776 default:
5777 return;
5780 fputc ('\n', asm_out_file);
5781 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5782 finalizing = set_finalizing;
5783 output_decl (decl, NULL_TREE);
5785 /* NOTE: The call above to `output_decl' may have caused one or more
5786 file-scope named types (i.e. tagged types) to be placed onto the
5787 pending_types_list. We have to get those types off of that list
5788 at some point, and this is the perfect time to do it. If we didn't
5789 take them off now, they might still be on the list when cc1 finally
5790 exits. That might be OK if it weren't for the fact that when we put
5791 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5792 for these types, and that causes them never to be output unless
5793 `output_pending_types_for_scope' takes them off of the list and un-sets
5794 their TREE_ASM_WRITTEN flags. */
5796 output_pending_types_for_scope (NULL_TREE);
5798 /* The above call should have totally emptied the pending_types_list
5799 if this is not a nested function or class. If this is a nested type,
5800 then the remaining pending_types will be emitted when the containing type
5801 is handled. */
5803 if (! DECL_CONTEXT (decl))
5805 if (pending_types != 0)
5806 abort ();
5809 ASM_OUTPUT_POP_SECTION (asm_out_file);
5812 /* Output a marker (i.e. a label) for the beginning of the generated code
5813 for a lexical block. */
5815 static void
5816 dwarfout_begin_block (line, blocknum)
5817 unsigned int line ATTRIBUTE_UNUSED;
5818 unsigned int blocknum;
5820 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5822 function_section (current_function_decl);
5823 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5824 ASM_OUTPUT_LABEL (asm_out_file, label);
5827 /* Output a marker (i.e. a label) for the end of the generated code
5828 for a lexical block. */
5830 static void
5831 dwarfout_end_block (line, blocknum)
5832 unsigned int line ATTRIBUTE_UNUSED;
5833 unsigned int blocknum;
5835 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5837 function_section (current_function_decl);
5838 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5839 ASM_OUTPUT_LABEL (asm_out_file, label);
5842 /* Output a marker (i.e. a label) for the point in the generated code where
5843 the real body of the function begins (after parameters have been moved
5844 to their home locations). */
5846 static void
5847 dwarfout_end_prologue (line, file)
5848 unsigned int line ATTRIBUTE_UNUSED;
5849 const char *file ATTRIBUTE_UNUSED;
5851 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5853 if (! use_gnu_debug_info_extensions)
5854 return;
5856 function_section (current_function_decl);
5857 sprintf (label, BODY_BEGIN_LABEL_FMT, current_function_funcdef_no);
5858 ASM_OUTPUT_LABEL (asm_out_file, label);
5861 /* Output a marker (i.e. a label) for the point in the generated code where
5862 the real body of the function ends (just before the epilogue code). */
5864 static void
5865 dwarfout_end_function (line)
5866 unsigned int line ATTRIBUTE_UNUSED;
5868 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5870 if (! use_gnu_debug_info_extensions)
5871 return;
5872 function_section (current_function_decl);
5873 sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no);
5874 ASM_OUTPUT_LABEL (asm_out_file, label);
5877 /* Output a marker (i.e. a label) for the absolute end of the generated code
5878 for a function definition. This gets called *after* the epilogue code
5879 has been generated. */
5881 static void
5882 dwarfout_end_epilogue (line, file)
5883 unsigned int line ATTRIBUTE_UNUSED;
5884 const char *file ATTRIBUTE_UNUSED;
5886 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5888 /* Output a label to mark the endpoint of the code generated for this
5889 function. */
5891 sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no);
5892 ASM_OUTPUT_LABEL (asm_out_file, label);
5895 static void
5896 shuffle_filename_entry (new_zeroth)
5897 filename_entry *new_zeroth;
5899 filename_entry temp_entry;
5900 filename_entry *limit_p;
5901 filename_entry *move_p;
5903 if (new_zeroth == &filename_table[0])
5904 return;
5906 temp_entry = *new_zeroth;
5908 /* Shift entries up in the table to make room at [0]. */
5910 limit_p = &filename_table[0];
5911 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5912 *move_p = *(move_p-1);
5914 /* Install the found entry at [0]. */
5916 filename_table[0] = temp_entry;
5919 /* Create a new (string) entry for the .debug_sfnames section. */
5921 static void
5922 generate_new_sfname_entry ()
5924 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5926 fputc ('\n', asm_out_file);
5927 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
5928 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5929 ASM_OUTPUT_LABEL (asm_out_file, label);
5930 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5931 filename_table[0].name
5932 ? filename_table[0].name
5933 : "");
5934 ASM_OUTPUT_POP_SECTION (asm_out_file);
5937 /* Lookup a filename (in the list of filenames that we know about here in
5938 dwarfout.c) and return its "index". The index of each (known) filename
5939 is just a unique number which is associated with only that one filename.
5940 We need such numbers for the sake of generating labels (in the
5941 .debug_sfnames section) and references to those unique labels (in the
5942 .debug_srcinfo and .debug_macinfo sections).
5944 If the filename given as an argument is not found in our current list,
5945 add it to the list and assign it the next available unique index number.
5947 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5948 one), we shuffle the filename found (or added) up to the zeroth entry of
5949 our list of filenames (which is always searched linearly). We do this so
5950 as to optimize the most common case for these filename lookups within
5951 dwarfout.c. The most common case by far is the case where we call
5952 lookup_filename to lookup the very same filename that we did a lookup
5953 on the last time we called lookup_filename. We make sure that this
5954 common case is fast because such cases will constitute 99.9% of the
5955 lookups we ever do (in practice).
5957 If we add a new filename entry to our table, we go ahead and generate
5958 the corresponding entry in the .debug_sfnames section right away.
5959 Doing so allows us to avoid tickling an assembler bug (present in some
5960 m68k assemblers) which yields assembly-time errors in cases where the
5961 difference of two label addresses is taken and where the two labels
5962 are in a section *other* than the one where the difference is being
5963 calculated, and where at least one of the two symbol references is a
5964 forward reference. (This bug could be tickled by our .debug_srcinfo
5965 entries if we don't output their corresponding .debug_sfnames entries
5966 before them.) */
5968 static unsigned
5969 lookup_filename (file_name)
5970 const char *file_name;
5972 filename_entry *search_p;
5973 filename_entry *limit_p = &filename_table[ft_entries];
5975 for (search_p = filename_table; search_p < limit_p; search_p++)
5976 if (!strcmp (file_name, search_p->name))
5978 /* When we get here, we have found the filename that we were
5979 looking for in the filename_table. Now we want to make sure
5980 that it gets moved to the zero'th entry in the table (if it
5981 is not already there) so that subsequent attempts to find the
5982 same filename will find it as quickly as possible. */
5984 shuffle_filename_entry (search_p);
5985 return filename_table[0].number;
5988 /* We come here whenever we have a new filename which is not registered
5989 in the current table. Here we add it to the table. */
5991 /* Prepare to add a new table entry by making sure there is enough space
5992 in the table to do so. If not, expand the current table. */
5994 if (ft_entries == ft_entries_allocated)
5996 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5997 filename_table
5998 = (filename_entry *)
5999 xrealloc (filename_table,
6000 ft_entries_allocated * sizeof (filename_entry));
6003 /* Initially, add the new entry at the end of the filename table. */
6005 filename_table[ft_entries].number = ft_entries;
6006 filename_table[ft_entries].name = xstrdup (file_name);
6008 /* Shuffle the new entry into filename_table[0]. */
6010 shuffle_filename_entry (&filename_table[ft_entries]);
6012 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6013 generate_new_sfname_entry ();
6015 ft_entries++;
6016 return filename_table[0].number;
6019 static void
6020 generate_srcinfo_entry (line_entry_num, files_entry_num)
6021 unsigned line_entry_num;
6022 unsigned files_entry_num;
6024 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6026 fputc ('\n', asm_out_file);
6027 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6028 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
6029 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
6030 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
6031 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
6032 ASM_OUTPUT_POP_SECTION (asm_out_file);
6035 static void
6036 dwarfout_source_line (line, filename)
6037 unsigned int line;
6038 const char *filename;
6040 if (debug_info_level >= DINFO_LEVEL_NORMAL
6041 /* We can't emit line number info for functions in separate sections,
6042 because the assembler can't subtract labels in different sections. */
6043 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
6045 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6046 static unsigned last_line_entry_num = 0;
6047 static unsigned prev_file_entry_num = (unsigned) -1;
6048 unsigned this_file_entry_num;
6050 function_section (current_function_decl);
6051 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
6052 ASM_OUTPUT_LABEL (asm_out_file, label);
6054 fputc ('\n', asm_out_file);
6056 if (use_gnu_debug_info_extensions)
6057 this_file_entry_num = lookup_filename (filename);
6058 else
6059 this_file_entry_num = (unsigned) -1;
6061 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6062 if (this_file_entry_num != prev_file_entry_num)
6064 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
6066 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
6067 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
6071 const char *tail = strrchr (filename, '/');
6073 if (tail != NULL)
6074 filename = tail;
6077 dw2_asm_output_data (4, line, "%s:%u", filename, line);
6078 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6079 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
6080 ASM_OUTPUT_POP_SECTION (asm_out_file);
6082 if (this_file_entry_num != prev_file_entry_num)
6083 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
6084 prev_file_entry_num = this_file_entry_num;
6088 /* Generate an entry in the .debug_macinfo section. */
6090 static void
6091 generate_macinfo_entry (type, offset, string)
6092 unsigned int type;
6093 rtx offset;
6094 const char *string;
6096 if (! use_gnu_debug_info_extensions)
6097 return;
6099 fputc ('\n', asm_out_file);
6100 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6101 assemble_integer (gen_rtx_PLUS (SImode, GEN_INT (type << 24), offset),
6102 4, BITS_PER_UNIT, 1);
6103 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
6104 ASM_OUTPUT_POP_SECTION (asm_out_file);
6107 /* Wrapper for toplev.c callback to check debug info level. */
6108 static void
6109 dwarfout_start_source_file_check (line, filename)
6110 unsigned int line;
6111 const char *filename;
6113 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6114 dwarfout_start_source_file (line, filename);
6117 static void
6118 dwarfout_start_source_file (line, filename)
6119 unsigned int line ATTRIBUTE_UNUSED;
6120 const char *filename;
6122 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6123 const char *label1, *label2;
6125 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
6126 label1 = (*label == '*') + label;
6127 label2 = (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL;
6128 generate_macinfo_entry (MACINFO_start,
6129 gen_rtx_MINUS (Pmode,
6130 gen_rtx_SYMBOL_REF (Pmode, label1),
6131 gen_rtx_SYMBOL_REF (Pmode, label2)),
6132 "");
6135 /* Wrapper for toplev.c callback to check debug info level. */
6136 static void
6137 dwarfout_end_source_file_check (lineno)
6138 unsigned lineno;
6140 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6141 dwarfout_end_source_file (lineno);
6144 static void
6145 dwarfout_end_source_file (lineno)
6146 unsigned lineno;
6148 generate_macinfo_entry (MACINFO_resume, GEN_INT (lineno), "");
6151 /* Called from check_newline in c-parse.y. The `buffer' parameter
6152 contains the tail part of the directive line, i.e. the part which
6153 is past the initial whitespace, #, whitespace, directive-name,
6154 whitespace part. */
6156 static void
6157 dwarfout_define (lineno, buffer)
6158 unsigned lineno;
6159 const char *buffer;
6161 static int initialized = 0;
6163 if (!initialized)
6165 dwarfout_start_source_file (0, primary_filename);
6166 initialized = 1;
6168 generate_macinfo_entry (MACINFO_define, GEN_INT (lineno), buffer);
6171 /* Called from check_newline in c-parse.y. The `buffer' parameter
6172 contains the tail part of the directive line, i.e. the part which
6173 is past the initial whitespace, #, whitespace, directive-name,
6174 whitespace part. */
6176 static void
6177 dwarfout_undef (lineno, buffer)
6178 unsigned lineno;
6179 const char *buffer;
6181 generate_macinfo_entry (MACINFO_undef, GEN_INT (lineno), buffer);
6184 /* Set up for Dwarf output at the start of compilation. */
6186 static void
6187 dwarfout_init (main_input_filename)
6188 const char *main_input_filename;
6190 warning ("support for the DWARF1 debugging format is deprecated");
6192 /* Remember the name of the primary input file. */
6194 primary_filename = main_input_filename;
6196 /* Allocate the initial hunk of the pending_sibling_stack. */
6198 pending_sibling_stack
6199 = (unsigned *)
6200 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
6201 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
6202 pending_siblings = 1;
6204 /* Allocate the initial hunk of the filename_table. */
6206 filename_table
6207 = (filename_entry *)
6208 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
6209 ft_entries_allocated = FT_ENTRIES_INCREMENT;
6210 ft_entries = 0;
6212 /* Allocate the initial hunk of the pending_types_list. */
6214 pending_types_list
6215 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
6216 pending_types_allocated = PENDING_TYPES_INCREMENT;
6217 pending_types = 0;
6219 /* Create an artificial RECORD_TYPE node which we can use in our hack
6220 to get the DIEs representing types of formal parameters to come out
6221 only *after* the DIEs for the formal parameters themselves. */
6223 fake_containing_scope = make_node (RECORD_TYPE);
6225 /* Output a starting label for the .text section. */
6227 fputc ('\n', asm_out_file);
6228 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6229 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
6230 ASM_OUTPUT_POP_SECTION (asm_out_file);
6232 /* Output a starting label for the .data section. */
6234 fputc ('\n', asm_out_file);
6235 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6236 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
6237 ASM_OUTPUT_POP_SECTION (asm_out_file);
6239 #if 0 /* GNU C doesn't currently use .data1. */
6240 /* Output a starting label for the .data1 section. */
6242 fputc ('\n', asm_out_file);
6243 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6244 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
6245 ASM_OUTPUT_POP_SECTION (asm_out_file);
6246 #endif
6248 /* Output a starting label for the .rodata section. */
6250 fputc ('\n', asm_out_file);
6251 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6252 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
6253 ASM_OUTPUT_POP_SECTION (asm_out_file);
6255 #if 0 /* GNU C doesn't currently use .rodata1. */
6256 /* Output a starting label for the .rodata1 section. */
6258 fputc ('\n', asm_out_file);
6259 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6260 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
6261 ASM_OUTPUT_POP_SECTION (asm_out_file);
6262 #endif
6264 /* Output a starting label for the .bss section. */
6266 fputc ('\n', asm_out_file);
6267 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6268 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
6269 ASM_OUTPUT_POP_SECTION (asm_out_file);
6271 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6273 if (use_gnu_debug_info_extensions)
6275 /* Output a starting label and an initial (compilation directory)
6276 entry for the .debug_sfnames section. The starting label will be
6277 referenced by the initial entry in the .debug_srcinfo section. */
6279 fputc ('\n', asm_out_file);
6280 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6281 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
6283 const char *pwd = getpwd ();
6284 char *dirname;
6286 if (!pwd)
6287 fatal_io_error ("can't get current directory");
6289 dirname = concat (pwd, "/", NULL);
6290 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
6291 free (dirname);
6293 ASM_OUTPUT_POP_SECTION (asm_out_file);
6296 if (debug_info_level >= DINFO_LEVEL_VERBOSE
6297 && use_gnu_debug_info_extensions)
6299 /* Output a starting label for the .debug_macinfo section. This
6300 label will be referenced by the AT_mac_info attribute in the
6301 TAG_compile_unit DIE. */
6303 fputc ('\n', asm_out_file);
6304 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6305 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
6306 ASM_OUTPUT_POP_SECTION (asm_out_file);
6309 /* Generate the initial entry for the .line section. */
6311 fputc ('\n', asm_out_file);
6312 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6313 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
6314 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
6315 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6316 ASM_OUTPUT_POP_SECTION (asm_out_file);
6318 if (use_gnu_debug_info_extensions)
6320 /* Generate the initial entry for the .debug_srcinfo section. */
6322 fputc ('\n', asm_out_file);
6323 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6324 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
6325 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
6326 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
6327 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6328 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
6329 #ifdef DWARF_TIMESTAMPS
6330 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
6331 #else
6332 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6333 #endif
6334 ASM_OUTPUT_POP_SECTION (asm_out_file);
6337 /* Generate the initial entry for the .debug_pubnames section. */
6339 fputc ('\n', asm_out_file);
6340 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6341 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6342 ASM_OUTPUT_POP_SECTION (asm_out_file);
6344 /* Generate the initial entry for the .debug_aranges section. */
6346 fputc ('\n', asm_out_file);
6347 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6348 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6349 DEBUG_ARANGES_END_LABEL,
6350 DEBUG_ARANGES_BEGIN_LABEL);
6351 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_BEGIN_LABEL);
6352 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 1);
6353 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6354 ASM_OUTPUT_POP_SECTION (asm_out_file);
6357 /* Setup first DIE number == 1. */
6358 NEXT_DIE_NUM = next_unused_dienum++;
6360 /* Generate the initial DIE for the .debug section. Note that the
6361 (string) value given in the AT_name attribute of the TAG_compile_unit
6362 DIE will (typically) be a relative pathname and that this pathname
6363 should be taken as being relative to the directory from which the
6364 compiler was invoked when the given (base) source file was compiled. */
6366 fputc ('\n', asm_out_file);
6367 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6368 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
6369 output_die (output_compile_unit_die, (PTR) main_input_filename);
6370 ASM_OUTPUT_POP_SECTION (asm_out_file);
6372 fputc ('\n', asm_out_file);
6375 /* Output stuff that dwarf requires at the end of every file. */
6377 static void
6378 dwarfout_finish (main_input_filename)
6379 const char *main_input_filename ATTRIBUTE_UNUSED;
6381 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6383 fputc ('\n', asm_out_file);
6384 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6385 retry_incomplete_types ();
6386 fputc ('\n', asm_out_file);
6388 /* Mark the end of the chain of siblings which represent all file-scope
6389 declarations in this compilation unit. */
6391 /* The (null) DIE which represents the terminator for the (sibling linked)
6392 list of file-scope items is *special*. Normally, we would just call
6393 end_sibling_chain at this point in order to output a word with the
6394 value `4' and that word would act as the terminator for the list of
6395 DIEs describing file-scope items. Unfortunately, if we were to simply
6396 do that, the label that would follow this DIE in the .debug section
6397 (i.e. `..D2') would *not* be properly aligned (as it must be on some
6398 machines) to a 4 byte boundary.
6400 In order to force the label `..D2' to get aligned to a 4 byte boundary,
6401 the trick used is to insert extra (otherwise useless) padding bytes
6402 into the (null) DIE that we know must precede the ..D2 label in the
6403 .debug section. The amount of padding required can be anywhere between
6404 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
6405 with the padding) would normally contain the value 4, but now it will
6406 also have to include the padding bytes, so it will instead have some
6407 value in the range 4..7.
6409 Fortunately, the rules of Dwarf say that any DIE whose length word
6410 contains *any* value less than 8 should be treated as a null DIE, so
6411 this trick works out nicely. Clever, eh? Don't give me any credit
6412 (or blame). I didn't think of this scheme. I just conformed to it.
6415 output_die (output_padded_null_die, (void *) 0);
6416 dienum_pop ();
6418 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
6419 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
6420 ASM_OUTPUT_POP_SECTION (asm_out_file);
6422 /* Output a terminator label for the .text section. */
6424 fputc ('\n', asm_out_file);
6425 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6426 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
6427 ASM_OUTPUT_POP_SECTION (asm_out_file);
6429 /* Output a terminator label for the .data section. */
6431 fputc ('\n', asm_out_file);
6432 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6433 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
6434 ASM_OUTPUT_POP_SECTION (asm_out_file);
6436 #if 0 /* GNU C doesn't currently use .data1. */
6437 /* Output a terminator label for the .data1 section. */
6439 fputc ('\n', asm_out_file);
6440 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6441 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
6442 ASM_OUTPUT_POP_SECTION (asm_out_file);
6443 #endif
6445 /* Output a terminator label for the .rodata section. */
6447 fputc ('\n', asm_out_file);
6448 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6449 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
6450 ASM_OUTPUT_POP_SECTION (asm_out_file);
6452 #if 0 /* GNU C doesn't currently use .rodata1. */
6453 /* Output a terminator label for the .rodata1 section. */
6455 fputc ('\n', asm_out_file);
6456 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6457 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
6458 ASM_OUTPUT_POP_SECTION (asm_out_file);
6459 #endif
6461 /* Output a terminator label for the .bss section. */
6463 fputc ('\n', asm_out_file);
6464 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6465 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
6466 ASM_OUTPUT_POP_SECTION (asm_out_file);
6468 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6470 /* Output a terminating entry for the .line section. */
6472 fputc ('\n', asm_out_file);
6473 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6474 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
6475 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6476 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6477 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6478 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
6479 ASM_OUTPUT_POP_SECTION (asm_out_file);
6481 if (use_gnu_debug_info_extensions)
6483 /* Output a terminating entry for the .debug_srcinfo section. */
6485 fputc ('\n', asm_out_file);
6486 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6487 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6488 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6489 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6490 ASM_OUTPUT_POP_SECTION (asm_out_file);
6493 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6495 /* Output terminating entries for the .debug_macinfo section. */
6497 dwarfout_end_source_file (0);
6499 fputc ('\n', asm_out_file);
6500 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6501 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6502 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6503 ASM_OUTPUT_POP_SECTION (asm_out_file);
6506 /* Generate the terminating entry for the .debug_pubnames section. */
6508 fputc ('\n', asm_out_file);
6509 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6510 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6511 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6512 ASM_OUTPUT_POP_SECTION (asm_out_file);
6514 /* Generate the terminating entries for the .debug_aranges section.
6516 Note that we want to do this only *after* we have output the end
6517 labels (for the various program sections) which we are going to
6518 refer to here. This allows us to work around a bug in the m68k
6519 svr4 assembler. That assembler gives bogus assembly-time errors
6520 if (within any given section) you try to take the difference of
6521 two relocatable symbols, both of which are located within some
6522 other section, and if one (or both?) of the symbols involved is
6523 being forward-referenced. By generating the .debug_aranges
6524 entries at this late point in the assembly output, we skirt the
6525 issue simply by avoiding forward-references.
6528 fputc ('\n', asm_out_file);
6529 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6531 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6532 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6534 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6535 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6537 #if 0 /* GNU C doesn't currently use .data1. */
6538 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6539 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6540 DATA1_BEGIN_LABEL);
6541 #endif
6543 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6544 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6545 RODATA_BEGIN_LABEL);
6547 #if 0 /* GNU C doesn't currently use .rodata1. */
6548 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6549 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6550 RODATA1_BEGIN_LABEL);
6551 #endif
6553 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6554 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6556 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6557 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6559 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_END_LABEL);
6560 ASM_OUTPUT_POP_SECTION (asm_out_file);
6563 /* There should not be any pending types left at the end. We need
6564 this now because it may not have been checked on the last call to
6565 dwarfout_file_scope_decl. */
6566 if (pending_types != 0)
6567 abort ();
6570 #endif /* DWARF_DEBUGGING_INFO */