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