* cfglayout.c (fixup_fallthru_exit_predecesor): Make void, rename
[official-gcc.git] / gcc / dwarfout.c
blobcc6886d4c97f0fe129f9016594196c28210ecf17
1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
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 "rtl.h"
573 #include "hard-reg-set.h"
574 #include "insn-config.h"
575 #include "reload.h"
576 #include "output.h"
577 #include "toplev.h"
578 #include "tm_p.h"
579 #include "debug.h"
580 #include "langhooks.h"
582 /* NOTE: In the comments in this file, many references are made to
583 so called "Debugging Information Entries". For the sake of brevity,
584 this term is abbreviated to `DIE' throughout the remainder of this
585 file. */
587 /* Note that the implementation of C++ support herein is (as yet) unfinished.
588 If you want to try to complete it, more power to you. */
590 /* How to start an assembler comment. */
591 #ifndef ASM_COMMENT_START
592 #define ASM_COMMENT_START ";#"
593 #endif
595 /* How to print out a register name. */
596 #ifndef PRINT_REG
597 #define PRINT_REG(RTX, CODE, FILE) \
598 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
599 #endif
601 /* Define a macro which returns non-zero for any tagged type which is
602 used (directly or indirectly) in the specification of either some
603 function's return type or some formal parameter of some function.
604 We use this macro when we are operating in "terse" mode to help us
605 know what tagged types have to be represented in Dwarf (even in
606 terse mode) and which ones don't.
608 A flag bit with this meaning really should be a part of the normal
609 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
610 for these nodes. For now, we have to just fake it. It it safe for
611 us to simply return zero for all complete tagged types (which will
612 get forced out anyway if they were used in the specification of some
613 formal or return type) and non-zero for all incomplete tagged types.
616 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
618 /* Define a macro which returns non-zero for a TYPE_DECL which was
619 implicitly generated for a tagged type.
621 Note that unlike the gcc front end (which generates a NULL named
622 TYPE_DECL node for each complete tagged type, each array type, and
623 each function type node created) the g++ front end generates a
624 _named_ TYPE_DECL node for each tagged type node created.
625 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
626 generate a DW_TAG_typedef DIE for them. */
627 #define TYPE_DECL_IS_STUB(decl) \
628 (DECL_NAME (decl) == NULL \
629 || (DECL_ARTIFICIAL (decl) \
630 && is_tagged_type (TREE_TYPE (decl)) \
631 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
633 extern int flag_traditional;
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 /* Pointer to the most recent filename for which we produced some line info. */
675 static const char *last_filename;
677 /* Counter to generate unique names for DIEs. */
679 static unsigned next_unused_dienum = 1;
681 /* Number of the DIE which is currently being generated. */
683 static unsigned current_dienum;
685 /* Number to use for the special "pubname" label on the next DIE which
686 represents a function or data object defined in this compilation
687 unit which has "extern" linkage. */
689 static int next_pubname_number = 0;
691 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
693 /* Pointer to a dynamically allocated list of pre-reserved and still
694 pending sibling DIE numbers. Note that this list will grow as needed. */
696 static unsigned *pending_sibling_stack;
698 /* Counter to keep track of the number of pre-reserved and still pending
699 sibling DIE numbers. */
701 static unsigned pending_siblings;
703 /* The currently allocated size of the above list (expressed in number of
704 list elements). */
706 static unsigned pending_siblings_allocated;
708 /* Size (in elements) of increments by which we may expand the pending
709 sibling stack. Actually, a single hunk of space of this size should
710 be enough for most typical programs. */
712 #define PENDING_SIBLINGS_INCREMENT 64
714 /* Non-zero if we are performing our file-scope finalization pass and if
715 we should force out Dwarf descriptions of any and all file-scope
716 tagged types which are still incomplete types. */
718 static int finalizing = 0;
720 /* A pointer to the base of a list of pending types which we haven't
721 generated DIEs for yet, but which we will have to come back to
722 later on. */
724 static tree *pending_types_list;
726 /* Number of elements currently allocated for the pending_types_list. */
728 static unsigned pending_types_allocated;
730 /* Number of elements of pending_types_list currently in use. */
732 static unsigned pending_types;
734 /* Size (in elements) of increments by which we may expand the pending
735 types list. Actually, a single hunk of space of this size should
736 be enough for most typical programs. */
738 #define PENDING_TYPES_INCREMENT 64
740 /* A pointer to the base of a list of incomplete types which might be
741 completed at some later time. */
743 static tree *incomplete_types_list;
745 /* Number of elements currently allocated for the incomplete_types_list. */
746 static unsigned incomplete_types_allocated;
748 /* Number of elements of incomplete_types_list currently in use. */
749 static unsigned incomplete_types;
751 /* Size (in elements) of increments by which we may expand the incomplete
752 types list. Actually, a single hunk of space of this size should
753 be enough for most typical programs. */
754 #define INCOMPLETE_TYPES_INCREMENT 64
756 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
757 This is used in a hack to help us get the DIEs describing types of
758 formal parameters to come *after* all of the DIEs describing the formal
759 parameters themselves. That's necessary in order to be compatible
760 with what the brain-damaged svr4 SDB debugger requires. */
762 static tree fake_containing_scope;
764 /* The number of the current function definition that we are generating
765 debugging information for. These numbers range from 1 up to the maximum
766 number of function definitions contained within the current compilation
767 unit. These numbers are used to create unique labels for various things
768 contained within various function definitions. */
770 static unsigned current_funcdef_number = 1;
772 /* A pointer to the ..._DECL node which we have most recently been working
773 on. We keep this around just in case something about it looks screwy
774 and we want to tell the user what the source coordinates for the actual
775 declaration are. */
777 static tree dwarf_last_decl;
779 /* A flag indicating that we are emitting the member declarations of a
780 class, so member functions and variables should not be entirely emitted.
781 This is a kludge to avoid passing a second argument to output_*_die. */
783 static int in_class;
785 /* Forward declarations for functions defined in this file. */
787 static void dwarfout_init PARAMS ((const char *));
788 static void dwarfout_finish PARAMS ((const char *));
789 static void dwarfout_define PARAMS ((unsigned int, const char *));
790 static void dwarfout_undef PARAMS ((unsigned int, const char *));
791 static void dwarfout_start_source_file PARAMS ((unsigned, const char *));
792 static void dwarfout_start_source_file_check PARAMS ((unsigned, const char *));
793 static void dwarfout_end_source_file PARAMS ((unsigned));
794 static void dwarfout_end_source_file_check PARAMS ((unsigned));
795 static void dwarfout_begin_block PARAMS ((unsigned, unsigned));
796 static void dwarfout_end_block PARAMS ((unsigned, unsigned));
797 static void dwarfout_end_epilogue PARAMS ((void));
798 static void dwarfout_source_line PARAMS ((unsigned int, const char *));
799 static void dwarfout_end_prologue PARAMS ((unsigned int));
800 static void dwarfout_end_function PARAMS ((unsigned int));
801 static void dwarfout_function_decl PARAMS ((tree));
802 static void dwarfout_global_decl PARAMS ((tree));
803 static void dwarfout_deferred_inline_function PARAMS ((tree));
804 static void dwarfout_file_scope_decl PARAMS ((tree , int));
805 static const char *dwarf_tag_name PARAMS ((unsigned));
806 static const char *dwarf_attr_name PARAMS ((unsigned));
807 static const char *dwarf_stack_op_name PARAMS ((unsigned));
808 static const char *dwarf_typemod_name PARAMS ((unsigned));
809 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
810 static const char *dwarf_fund_type_name PARAMS ((unsigned));
811 static tree decl_ultimate_origin PARAMS ((tree));
812 static tree block_ultimate_origin PARAMS ((tree));
813 static tree decl_class_context PARAMS ((tree));
814 #if 0
815 static void output_unsigned_leb128 PARAMS ((unsigned long));
816 static void output_signed_leb128 PARAMS ((long));
817 #endif
818 static int fundamental_type_code PARAMS ((tree));
819 static tree root_type_1 PARAMS ((tree, int));
820 static tree root_type PARAMS ((tree));
821 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
822 static void write_modifier_bytes PARAMS ((tree, int, int));
823 static inline int type_is_fundamental PARAMS ((tree));
824 static void equate_decl_number_to_die_number PARAMS ((tree));
825 static inline void equate_type_number_to_die_number PARAMS ((tree));
826 static void output_reg_number PARAMS ((rtx));
827 static void output_mem_loc_descriptor PARAMS ((rtx));
828 static void output_loc_descriptor PARAMS ((rtx));
829 static void output_bound_representation PARAMS ((tree, unsigned, int));
830 static void output_enumeral_list PARAMS ((tree));
831 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
832 static inline tree field_type PARAMS ((tree));
833 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
834 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
835 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
836 static inline void sibling_attribute PARAMS ((void));
837 static void location_attribute PARAMS ((rtx));
838 static void data_member_location_attribute PARAMS ((tree));
839 static void const_value_attribute PARAMS ((rtx));
840 static void location_or_const_value_attribute PARAMS ((tree));
841 static inline void name_attribute PARAMS ((const char *));
842 static inline void fund_type_attribute PARAMS ((unsigned));
843 static void mod_fund_type_attribute PARAMS ((tree, int, int));
844 static inline void user_def_type_attribute PARAMS ((tree));
845 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
846 #ifdef USE_ORDERING_ATTRIBUTE
847 static inline void ordering_attribute PARAMS ((unsigned));
848 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
849 static void subscript_data_attribute PARAMS ((tree));
850 static void byte_size_attribute PARAMS ((tree));
851 static inline void bit_offset_attribute PARAMS ((tree));
852 static inline void bit_size_attribute PARAMS ((tree));
853 static inline void element_list_attribute PARAMS ((tree));
854 static inline void stmt_list_attribute PARAMS ((const char *));
855 static inline void low_pc_attribute PARAMS ((const char *));
856 static inline void high_pc_attribute PARAMS ((const char *));
857 static inline void body_begin_attribute PARAMS ((const char *));
858 static inline void body_end_attribute PARAMS ((const char *));
859 static inline void language_attribute PARAMS ((unsigned));
860 static inline void member_attribute PARAMS ((tree));
861 #if 0
862 static inline void string_length_attribute PARAMS ((tree));
863 #endif
864 static inline void comp_dir_attribute PARAMS ((const char *));
865 static inline void sf_names_attribute PARAMS ((const char *));
866 static inline void src_info_attribute PARAMS ((const char *));
867 static inline void mac_info_attribute PARAMS ((const char *));
868 static inline void prototyped_attribute PARAMS ((tree));
869 static inline void producer_attribute PARAMS ((const char *));
870 static inline void inline_attribute PARAMS ((tree));
871 static inline void containing_type_attribute PARAMS ((tree));
872 static inline void abstract_origin_attribute PARAMS ((tree));
873 #ifdef DWARF_DECL_COORDINATES
874 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
875 #endif /* defined(DWARF_DECL_COORDINATES) */
876 static inline void pure_or_virtual_attribute PARAMS ((tree));
877 static void name_and_src_coords_attributes PARAMS ((tree));
878 static void type_attribute PARAMS ((tree, int, int));
879 static const char *type_tag PARAMS ((tree));
880 static inline void dienum_push PARAMS ((void));
881 static inline void dienum_pop PARAMS ((void));
882 static inline tree member_declared_type PARAMS ((tree));
883 static const char *function_start_label PARAMS ((tree));
884 static void output_array_type_die PARAMS ((void *));
885 static void output_set_type_die PARAMS ((void *));
886 #if 0
887 static void output_entry_point_die PARAMS ((void *));
888 #endif
889 static void output_inlined_enumeration_type_die PARAMS ((void *));
890 static void output_inlined_structure_type_die PARAMS ((void *));
891 static void output_inlined_union_type_die PARAMS ((void *));
892 static void output_enumeration_type_die PARAMS ((void *));
893 static void output_formal_parameter_die PARAMS ((void *));
894 static void output_global_subroutine_die PARAMS ((void *));
895 static void output_global_variable_die PARAMS ((void *));
896 static void output_label_die PARAMS ((void *));
897 static void output_lexical_block_die PARAMS ((void *));
898 static void output_inlined_subroutine_die PARAMS ((void *));
899 static void output_local_variable_die PARAMS ((void *));
900 static void output_member_die PARAMS ((void *));
901 #if 0
902 static void output_pointer_type_die PARAMS ((void *));
903 static void output_reference_type_die PARAMS ((void *));
904 #endif
905 static void output_ptr_to_mbr_type_die PARAMS ((void *));
906 static void output_compile_unit_die PARAMS ((void *));
907 static void output_string_type_die PARAMS ((void *));
908 static void output_inheritance_die PARAMS ((void *));
909 static void output_structure_type_die PARAMS ((void *));
910 static void output_local_subroutine_die PARAMS ((void *));
911 static void output_subroutine_type_die PARAMS ((void *));
912 static void output_typedef_die PARAMS ((void *));
913 static void output_union_type_die PARAMS ((void *));
914 static void output_unspecified_parameters_die PARAMS ((void *));
915 static void output_padded_null_die PARAMS ((void *));
916 static void output_die PARAMS ((void (*)(void *), void *));
917 static void end_sibling_chain PARAMS ((void));
918 static void output_formal_types PARAMS ((tree));
919 static void pend_type PARAMS ((tree));
920 static int type_ok_for_scope PARAMS ((tree, tree));
921 static void output_pending_types_for_scope PARAMS ((tree));
922 static void output_type PARAMS ((tree, tree));
923 static void output_tagged_type_instantiation PARAMS ((tree));
924 static void output_block PARAMS ((tree, int));
925 static void output_decls_for_scope PARAMS ((tree, int));
926 static void output_decl PARAMS ((tree, tree));
927 static void shuffle_filename_entry PARAMS ((filename_entry *));
928 static void generate_new_sfname_entry PARAMS ((void));
929 static unsigned lookup_filename PARAMS ((const char *));
930 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
931 static void generate_macinfo_entry PARAMS ((const char *, const char *));
932 static int is_pseudo_reg PARAMS ((rtx));
933 static tree type_main_variant PARAMS ((tree));
934 static int is_tagged_type PARAMS ((tree));
935 static int is_redundant_typedef PARAMS ((tree));
936 static void add_incomplete_type PARAMS ((tree));
937 static void retry_incomplete_types PARAMS ((void));
939 /* Definitions of defaults for assembler-dependent names of various
940 pseudo-ops and section names.
942 Theses may be overridden in your tm.h file (if necessary) for your
943 particular assembler. The default values provided here correspond to
944 what is expected by "standard" AT&T System V.4 assemblers. */
946 #ifndef FILE_ASM_OP
947 #define FILE_ASM_OP "\t.file\t"
948 #endif
949 #ifndef VERSION_ASM_OP
950 #define VERSION_ASM_OP "\t.version\t"
951 #endif
952 #ifndef SET_ASM_OP
953 #define SET_ASM_OP "\t.set\t"
954 #endif
956 /* Pseudo-ops for pushing the current section onto the section stack (and
957 simultaneously changing to a new section) and for poping back to the
958 section we were in immediately before this one. Note that most svr4
959 assemblers only maintain a one level stack... you can push all the
960 sections you want, but you can only pop out one level. (The sparc
961 svr4 assembler is an exception to this general rule.) That's
962 OK because we only use at most one level of the section stack herein. */
964 #ifndef PUSHSECTION_ASM_OP
965 #define PUSHSECTION_ASM_OP "\t.section\t"
966 #endif
967 #ifndef POPSECTION_ASM_OP
968 #define POPSECTION_ASM_OP "\t.previous"
969 #endif
971 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
972 to print the PUSHSECTION_ASM_OP and the section name. The default here
973 works for almost all svr4 assemblers, except for the sparc, where the
974 section name must be enclosed in double quotes. (See sparcv4.h.) */
976 #ifndef PUSHSECTION_FORMAT
977 #define PUSHSECTION_FORMAT "%s%s\n"
978 #endif
980 #ifndef DEBUG_SECTION
981 #define DEBUG_SECTION ".debug"
982 #endif
983 #ifndef LINE_SECTION
984 #define LINE_SECTION ".line"
985 #endif
986 #ifndef DEBUG_SFNAMES_SECTION
987 #define DEBUG_SFNAMES_SECTION ".debug_sfnames"
988 #endif
989 #ifndef DEBUG_SRCINFO_SECTION
990 #define DEBUG_SRCINFO_SECTION ".debug_srcinfo"
991 #endif
992 #ifndef DEBUG_MACINFO_SECTION
993 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
994 #endif
995 #ifndef DEBUG_PUBNAMES_SECTION
996 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
997 #endif
998 #ifndef DEBUG_ARANGES_SECTION
999 #define DEBUG_ARANGES_SECTION ".debug_aranges"
1000 #endif
1001 #ifndef TEXT_SECTION_NAME
1002 #define TEXT_SECTION_NAME ".text"
1003 #endif
1004 #ifndef DATA_SECTION_NAME
1005 #define DATA_SECTION_NAME ".data"
1006 #endif
1007 #ifndef DATA1_SECTION_NAME
1008 #define DATA1_SECTION_NAME ".data1"
1009 #endif
1010 #ifndef RODATA_SECTION_NAME
1011 #define RODATA_SECTION_NAME ".rodata"
1012 #endif
1013 #ifndef RODATA1_SECTION_NAME
1014 #define RODATA1_SECTION_NAME ".rodata1"
1015 #endif
1016 #ifndef BSS_SECTION_NAME
1017 #define BSS_SECTION_NAME ".bss"
1018 #endif
1020 /* Definitions of defaults for formats and names of various special
1021 (artificial) labels which may be generated within this file (when
1022 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
1024 If necessary, these may be overridden from within your tm.h file,
1025 but typically, you should never need to override these.
1027 These labels have been hacked (temporarily) so that they all begin with
1028 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
1029 stock m88k/svr4 assembler, both of which need to see .L at the start of
1030 a label in order to prevent that label from going into the linker symbol
1031 table). When I get time, I'll have to fix this the right way so that we
1032 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
1033 but that will require a rather massive set of changes. For the moment,
1034 the following definitions out to produce the right results for all svr4
1035 and svr3 assemblers. -- rfg
1038 #ifndef TEXT_BEGIN_LABEL
1039 #define TEXT_BEGIN_LABEL "*.L_text_b"
1040 #endif
1041 #ifndef TEXT_END_LABEL
1042 #define TEXT_END_LABEL "*.L_text_e"
1043 #endif
1045 #ifndef DATA_BEGIN_LABEL
1046 #define DATA_BEGIN_LABEL "*.L_data_b"
1047 #endif
1048 #ifndef DATA_END_LABEL
1049 #define DATA_END_LABEL "*.L_data_e"
1050 #endif
1052 #ifndef DATA1_BEGIN_LABEL
1053 #define DATA1_BEGIN_LABEL "*.L_data1_b"
1054 #endif
1055 #ifndef DATA1_END_LABEL
1056 #define DATA1_END_LABEL "*.L_data1_e"
1057 #endif
1059 #ifndef RODATA_BEGIN_LABEL
1060 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
1061 #endif
1062 #ifndef RODATA_END_LABEL
1063 #define RODATA_END_LABEL "*.L_rodata_e"
1064 #endif
1066 #ifndef RODATA1_BEGIN_LABEL
1067 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
1068 #endif
1069 #ifndef RODATA1_END_LABEL
1070 #define RODATA1_END_LABEL "*.L_rodata1_e"
1071 #endif
1073 #ifndef BSS_BEGIN_LABEL
1074 #define BSS_BEGIN_LABEL "*.L_bss_b"
1075 #endif
1076 #ifndef BSS_END_LABEL
1077 #define BSS_END_LABEL "*.L_bss_e"
1078 #endif
1080 #ifndef LINE_BEGIN_LABEL
1081 #define LINE_BEGIN_LABEL "*.L_line_b"
1082 #endif
1083 #ifndef LINE_LAST_ENTRY_LABEL
1084 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
1085 #endif
1086 #ifndef LINE_END_LABEL
1087 #define LINE_END_LABEL "*.L_line_e"
1088 #endif
1090 #ifndef DEBUG_BEGIN_LABEL
1091 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
1092 #endif
1093 #ifndef SFNAMES_BEGIN_LABEL
1094 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
1095 #endif
1096 #ifndef SRCINFO_BEGIN_LABEL
1097 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
1098 #endif
1099 #ifndef MACINFO_BEGIN_LABEL
1100 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
1101 #endif
1103 #ifndef DEBUG_ARANGES_BEGIN_LABEL
1104 #define DEBUG_ARANGES_BEGIN_LABEL "*.L_debug_aranges_begin"
1105 #endif
1106 #ifndef DEBUG_ARANGES_END_LABEL
1107 #define DEBUG_ARANGES_END_LABEL "*.L_debug_aranges_end"
1108 #endif
1110 #ifndef DIE_BEGIN_LABEL_FMT
1111 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
1112 #endif
1113 #ifndef DIE_END_LABEL_FMT
1114 #define DIE_END_LABEL_FMT "*.L_D%u_e"
1115 #endif
1116 #ifndef PUB_DIE_LABEL_FMT
1117 #define PUB_DIE_LABEL_FMT "*.L_P%u"
1118 #endif
1119 #ifndef BLOCK_BEGIN_LABEL_FMT
1120 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
1121 #endif
1122 #ifndef BLOCK_END_LABEL_FMT
1123 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
1124 #endif
1125 #ifndef SS_BEGIN_LABEL_FMT
1126 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
1127 #endif
1128 #ifndef SS_END_LABEL_FMT
1129 #define SS_END_LABEL_FMT "*.L_s%u_e"
1130 #endif
1131 #ifndef EE_BEGIN_LABEL_FMT
1132 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
1133 #endif
1134 #ifndef EE_END_LABEL_FMT
1135 #define EE_END_LABEL_FMT "*.L_e%u_e"
1136 #endif
1137 #ifndef MT_BEGIN_LABEL_FMT
1138 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
1139 #endif
1140 #ifndef MT_END_LABEL_FMT
1141 #define MT_END_LABEL_FMT "*.L_t%u_e"
1142 #endif
1143 #ifndef LOC_BEGIN_LABEL_FMT
1144 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
1145 #endif
1146 #ifndef LOC_END_LABEL_FMT
1147 #define LOC_END_LABEL_FMT "*.L_l%u_e"
1148 #endif
1149 #ifndef BOUND_BEGIN_LABEL_FMT
1150 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
1151 #endif
1152 #ifndef BOUND_END_LABEL_FMT
1153 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
1154 #endif
1155 #ifndef DERIV_BEGIN_LABEL_FMT
1156 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
1157 #endif
1158 #ifndef DERIV_END_LABEL_FMT
1159 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
1160 #endif
1161 #ifndef SL_BEGIN_LABEL_FMT
1162 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
1163 #endif
1164 #ifndef SL_END_LABEL_FMT
1165 #define SL_END_LABEL_FMT "*.L_sl%u_e"
1166 #endif
1167 #ifndef BODY_BEGIN_LABEL_FMT
1168 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
1169 #endif
1170 #ifndef BODY_END_LABEL_FMT
1171 #define BODY_END_LABEL_FMT "*.L_b%u_e"
1172 #endif
1173 #ifndef FUNC_END_LABEL_FMT
1174 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
1175 #endif
1176 #ifndef TYPE_NAME_FMT
1177 #define TYPE_NAME_FMT "*.L_T%u"
1178 #endif
1179 #ifndef DECL_NAME_FMT
1180 #define DECL_NAME_FMT "*.L_E%u"
1181 #endif
1182 #ifndef LINE_CODE_LABEL_FMT
1183 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
1184 #endif
1185 #ifndef SFNAMES_ENTRY_LABEL_FMT
1186 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
1187 #endif
1188 #ifndef LINE_ENTRY_LABEL_FMT
1189 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
1190 #endif
1192 /* Definitions of defaults for various types of primitive assembly language
1193 output operations.
1195 If necessary, these may be overridden from within your tm.h file,
1196 but typically, you shouldn't need to override these. */
1198 #ifndef ASM_OUTPUT_PUSH_SECTION
1199 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
1200 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
1201 #endif
1203 #ifndef ASM_OUTPUT_POP_SECTION
1204 #define ASM_OUTPUT_POP_SECTION(FILE) \
1205 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
1206 #endif
1208 #ifndef ASM_OUTPUT_DWARF_DELTA2
1209 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
1210 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
1211 assemble_name (FILE, LABEL1); \
1212 fprintf (FILE, "-"); \
1213 assemble_name (FILE, LABEL2); \
1214 fprintf (FILE, "\n"); \
1215 } while (0)
1216 #endif
1218 #ifndef ASM_OUTPUT_DWARF_DELTA4
1219 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
1220 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1221 assemble_name (FILE, LABEL1); \
1222 fprintf (FILE, "-"); \
1223 assemble_name (FILE, LABEL2); \
1224 fprintf (FILE, "\n"); \
1225 } while (0)
1226 #endif
1228 #ifndef ASM_OUTPUT_DWARF_TAG
1229 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
1230 do { \
1231 fprintf ((FILE), "%s0x%x", \
1232 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
1233 if (flag_debug_asm) \
1234 fprintf ((FILE), "\t%s %s", \
1235 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
1236 fputc ('\n', (FILE)); \
1237 } while (0)
1238 #endif
1240 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
1241 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
1242 do { \
1243 fprintf ((FILE), "%s0x%x", \
1244 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
1245 if (flag_debug_asm) \
1246 fprintf ((FILE), "\t%s %s", \
1247 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
1248 fputc ('\n', (FILE)); \
1249 } while (0)
1250 #endif
1252 #ifndef ASM_OUTPUT_DWARF_STACK_OP
1253 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
1254 do { \
1255 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) OP); \
1256 if (flag_debug_asm) \
1257 fprintf ((FILE), "\t%s %s", \
1258 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
1259 fputc ('\n', (FILE)); \
1260 } while (0)
1261 #endif
1263 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
1264 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
1265 do { \
1266 fprintf ((FILE), "%s0x%x", \
1267 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
1268 if (flag_debug_asm) \
1269 fprintf ((FILE), "\t%s %s", \
1270 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
1271 fputc ('\n', (FILE)); \
1272 } while (0)
1273 #endif
1275 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
1276 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
1277 do { \
1278 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) FMT); \
1279 if (flag_debug_asm) \
1280 fprintf ((FILE), "\t%s %s", \
1281 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
1282 fputc ('\n', (FILE)); \
1283 } while (0)
1284 #endif
1286 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
1287 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
1288 do { \
1289 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) MOD); \
1290 if (flag_debug_asm) \
1291 fprintf ((FILE), "\t%s %s", \
1292 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
1293 fputc ('\n', (FILE)); \
1294 } while (0)
1295 #endif
1297 #ifndef ASM_OUTPUT_DWARF_ADDR
1298 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
1299 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1300 assemble_name (FILE, LABEL); \
1301 fprintf (FILE, "\n"); \
1302 } while (0)
1303 #endif
1305 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
1306 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
1307 do { \
1308 fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1309 output_addr_const ((FILE), (RTX)); \
1310 fputc ('\n', (FILE)); \
1311 } while (0)
1312 #endif
1314 #ifndef ASM_OUTPUT_DWARF_REF
1315 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
1316 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1317 assemble_name (FILE, LABEL); \
1318 fprintf (FILE, "\n"); \
1319 } while (0)
1320 #endif
1322 #ifndef ASM_OUTPUT_DWARF_DATA1
1323 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
1324 fprintf ((FILE), "%s0x%x\n", ASM_BYTE_OP, VALUE)
1325 #endif
1327 #ifndef ASM_OUTPUT_DWARF_DATA2
1328 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
1329 fprintf ((FILE), "%s0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
1330 #endif
1332 #ifndef ASM_OUTPUT_DWARF_DATA4
1333 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
1334 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
1335 #endif
1337 #ifndef ASM_OUTPUT_DWARF_DATA8
1338 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
1339 do { \
1340 if (WORDS_BIG_ENDIAN) \
1342 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1343 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1345 else \
1347 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1348 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1350 } while (0)
1351 #endif
1353 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
1354 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
1355 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
1356 defined, we call it, then issue the line feed. If not, we supply a
1357 default defintion of calling ASM_OUTPUT_ASCII */
1359 #ifndef ASM_OUTPUT_DWARF_STRING
1360 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1361 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
1362 #else
1363 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1364 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
1365 #endif
1368 /* The debug hooks structure. */
1369 struct gcc_debug_hooks dwarf_debug_hooks =
1371 dwarfout_init,
1372 dwarfout_finish,
1373 dwarfout_define,
1374 dwarfout_undef,
1375 dwarfout_start_source_file_check,
1376 dwarfout_end_source_file_check,
1377 dwarfout_begin_block,
1378 dwarfout_end_block,
1379 debug_true_tree, /* ignore_block */
1380 dwarfout_source_line, /* source_line */
1381 dwarfout_source_line, /* begin_prologue */
1382 dwarfout_end_prologue,
1383 dwarfout_end_epilogue,
1384 debug_nothing_tree, /* begin_function */
1385 dwarfout_end_function,
1386 dwarfout_function_decl,
1387 dwarfout_global_decl,
1388 dwarfout_deferred_inline_function,
1389 debug_nothing_tree, /* outlining_inline_function */
1390 debug_nothing_rtx /* label */
1393 /************************ general utility functions **************************/
1395 static inline int
1396 is_pseudo_reg (rtl)
1397 rtx rtl;
1399 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1400 || ((GET_CODE (rtl) == SUBREG)
1401 && (REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)));
1404 static inline tree
1405 type_main_variant (type)
1406 tree type;
1408 type = TYPE_MAIN_VARIANT (type);
1410 /* There really should be only one main variant among any group of variants
1411 of a given type (and all of the MAIN_VARIANT values for all members of
1412 the group should point to that one type) but sometimes the C front-end
1413 messes this up for array types, so we work around that bug here. */
1415 if (TREE_CODE (type) == ARRAY_TYPE)
1417 while (type != TYPE_MAIN_VARIANT (type))
1418 type = TYPE_MAIN_VARIANT (type);
1421 return type;
1424 /* Return non-zero if the given type node represents a tagged type. */
1426 static inline int
1427 is_tagged_type (type)
1428 tree type;
1430 enum tree_code code = TREE_CODE (type);
1432 return (code == RECORD_TYPE || code == UNION_TYPE
1433 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1436 static const char *
1437 dwarf_tag_name (tag)
1438 unsigned tag;
1440 switch (tag)
1442 case TAG_padding: return "TAG_padding";
1443 case TAG_array_type: return "TAG_array_type";
1444 case TAG_class_type: return "TAG_class_type";
1445 case TAG_entry_point: return "TAG_entry_point";
1446 case TAG_enumeration_type: return "TAG_enumeration_type";
1447 case TAG_formal_parameter: return "TAG_formal_parameter";
1448 case TAG_global_subroutine: return "TAG_global_subroutine";
1449 case TAG_global_variable: return "TAG_global_variable";
1450 case TAG_label: return "TAG_label";
1451 case TAG_lexical_block: return "TAG_lexical_block";
1452 case TAG_local_variable: return "TAG_local_variable";
1453 case TAG_member: return "TAG_member";
1454 case TAG_pointer_type: return "TAG_pointer_type";
1455 case TAG_reference_type: return "TAG_reference_type";
1456 case TAG_compile_unit: return "TAG_compile_unit";
1457 case TAG_string_type: return "TAG_string_type";
1458 case TAG_structure_type: return "TAG_structure_type";
1459 case TAG_subroutine: return "TAG_subroutine";
1460 case TAG_subroutine_type: return "TAG_subroutine_type";
1461 case TAG_typedef: return "TAG_typedef";
1462 case TAG_union_type: return "TAG_union_type";
1463 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
1464 case TAG_variant: return "TAG_variant";
1465 case TAG_common_block: return "TAG_common_block";
1466 case TAG_common_inclusion: return "TAG_common_inclusion";
1467 case TAG_inheritance: return "TAG_inheritance";
1468 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
1469 case TAG_module: return "TAG_module";
1470 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
1471 case TAG_set_type: return "TAG_set_type";
1472 case TAG_subrange_type: return "TAG_subrange_type";
1473 case TAG_with_stmt: return "TAG_with_stmt";
1475 /* GNU extensions. */
1477 case TAG_format_label: return "TAG_format_label";
1478 case TAG_namelist: return "TAG_namelist";
1479 case TAG_function_template: return "TAG_function_template";
1480 case TAG_class_template: return "TAG_class_template";
1482 default: return "TAG_<unknown>";
1486 static const char *
1487 dwarf_attr_name (attr)
1488 unsigned attr;
1490 switch (attr)
1492 case AT_sibling: return "AT_sibling";
1493 case AT_location: return "AT_location";
1494 case AT_name: return "AT_name";
1495 case AT_fund_type: return "AT_fund_type";
1496 case AT_mod_fund_type: return "AT_mod_fund_type";
1497 case AT_user_def_type: return "AT_user_def_type";
1498 case AT_mod_u_d_type: return "AT_mod_u_d_type";
1499 case AT_ordering: return "AT_ordering";
1500 case AT_subscr_data: return "AT_subscr_data";
1501 case AT_byte_size: return "AT_byte_size";
1502 case AT_bit_offset: return "AT_bit_offset";
1503 case AT_bit_size: return "AT_bit_size";
1504 case AT_element_list: return "AT_element_list";
1505 case AT_stmt_list: return "AT_stmt_list";
1506 case AT_low_pc: return "AT_low_pc";
1507 case AT_high_pc: return "AT_high_pc";
1508 case AT_language: return "AT_language";
1509 case AT_member: return "AT_member";
1510 case AT_discr: return "AT_discr";
1511 case AT_discr_value: return "AT_discr_value";
1512 case AT_string_length: return "AT_string_length";
1513 case AT_common_reference: return "AT_common_reference";
1514 case AT_comp_dir: return "AT_comp_dir";
1515 case AT_const_value_string: return "AT_const_value_string";
1516 case AT_const_value_data2: return "AT_const_value_data2";
1517 case AT_const_value_data4: return "AT_const_value_data4";
1518 case AT_const_value_data8: return "AT_const_value_data8";
1519 case AT_const_value_block2: return "AT_const_value_block2";
1520 case AT_const_value_block4: return "AT_const_value_block4";
1521 case AT_containing_type: return "AT_containing_type";
1522 case AT_default_value_addr: return "AT_default_value_addr";
1523 case AT_default_value_data2: return "AT_default_value_data2";
1524 case AT_default_value_data4: return "AT_default_value_data4";
1525 case AT_default_value_data8: return "AT_default_value_data8";
1526 case AT_default_value_string: return "AT_default_value_string";
1527 case AT_friends: return "AT_friends";
1528 case AT_inline: return "AT_inline";
1529 case AT_is_optional: return "AT_is_optional";
1530 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1531 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1532 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1533 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1534 case AT_private: return "AT_private";
1535 case AT_producer: return "AT_producer";
1536 case AT_program: return "AT_program";
1537 case AT_protected: return "AT_protected";
1538 case AT_prototyped: return "AT_prototyped";
1539 case AT_public: return "AT_public";
1540 case AT_pure_virtual: return "AT_pure_virtual";
1541 case AT_return_addr: return "AT_return_addr";
1542 case AT_abstract_origin: return "AT_abstract_origin";
1543 case AT_start_scope: return "AT_start_scope";
1544 case AT_stride_size: return "AT_stride_size";
1545 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1546 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1547 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1548 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1549 case AT_virtual: return "AT_virtual";
1551 /* GNU extensions */
1553 case AT_sf_names: return "AT_sf_names";
1554 case AT_src_info: return "AT_src_info";
1555 case AT_mac_info: return "AT_mac_info";
1556 case AT_src_coords: return "AT_src_coords";
1557 case AT_body_begin: return "AT_body_begin";
1558 case AT_body_end: return "AT_body_end";
1560 default: return "AT_<unknown>";
1564 static const char *
1565 dwarf_stack_op_name (op)
1566 unsigned op;
1568 switch (op)
1570 case OP_REG: return "OP_REG";
1571 case OP_BASEREG: return "OP_BASEREG";
1572 case OP_ADDR: return "OP_ADDR";
1573 case OP_CONST: return "OP_CONST";
1574 case OP_DEREF2: return "OP_DEREF2";
1575 case OP_DEREF4: return "OP_DEREF4";
1576 case OP_ADD: return "OP_ADD";
1577 default: return "OP_<unknown>";
1581 static const char *
1582 dwarf_typemod_name (mod)
1583 unsigned mod;
1585 switch (mod)
1587 case MOD_pointer_to: return "MOD_pointer_to";
1588 case MOD_reference_to: return "MOD_reference_to";
1589 case MOD_const: return "MOD_const";
1590 case MOD_volatile: return "MOD_volatile";
1591 default: return "MOD_<unknown>";
1595 static const char *
1596 dwarf_fmt_byte_name (fmt)
1597 unsigned fmt;
1599 switch (fmt)
1601 case FMT_FT_C_C: return "FMT_FT_C_C";
1602 case FMT_FT_C_X: return "FMT_FT_C_X";
1603 case FMT_FT_X_C: return "FMT_FT_X_C";
1604 case FMT_FT_X_X: return "FMT_FT_X_X";
1605 case FMT_UT_C_C: return "FMT_UT_C_C";
1606 case FMT_UT_C_X: return "FMT_UT_C_X";
1607 case FMT_UT_X_C: return "FMT_UT_X_C";
1608 case FMT_UT_X_X: return "FMT_UT_X_X";
1609 case FMT_ET: return "FMT_ET";
1610 default: return "FMT_<unknown>";
1614 static const char *
1615 dwarf_fund_type_name (ft)
1616 unsigned ft;
1618 switch (ft)
1620 case FT_char: return "FT_char";
1621 case FT_signed_char: return "FT_signed_char";
1622 case FT_unsigned_char: return "FT_unsigned_char";
1623 case FT_short: return "FT_short";
1624 case FT_signed_short: return "FT_signed_short";
1625 case FT_unsigned_short: return "FT_unsigned_short";
1626 case FT_integer: return "FT_integer";
1627 case FT_signed_integer: return "FT_signed_integer";
1628 case FT_unsigned_integer: return "FT_unsigned_integer";
1629 case FT_long: return "FT_long";
1630 case FT_signed_long: return "FT_signed_long";
1631 case FT_unsigned_long: return "FT_unsigned_long";
1632 case FT_pointer: return "FT_pointer";
1633 case FT_float: return "FT_float";
1634 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1635 case FT_ext_prec_float: return "FT_ext_prec_float";
1636 case FT_complex: return "FT_complex";
1637 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1638 case FT_void: return "FT_void";
1639 case FT_boolean: return "FT_boolean";
1640 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1641 case FT_label: return "FT_label";
1643 /* GNU extensions. */
1645 case FT_long_long: return "FT_long_long";
1646 case FT_signed_long_long: return "FT_signed_long_long";
1647 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1649 case FT_int8: return "FT_int8";
1650 case FT_signed_int8: return "FT_signed_int8";
1651 case FT_unsigned_int8: return "FT_unsigned_int8";
1652 case FT_int16: return "FT_int16";
1653 case FT_signed_int16: return "FT_signed_int16";
1654 case FT_unsigned_int16: return "FT_unsigned_int16";
1655 case FT_int32: return "FT_int32";
1656 case FT_signed_int32: return "FT_signed_int32";
1657 case FT_unsigned_int32: return "FT_unsigned_int32";
1658 case FT_int64: return "FT_int64";
1659 case FT_signed_int64: return "FT_signed_int64";
1660 case FT_unsigned_int64: return "FT_unsigned_int64";
1661 case FT_int128: return "FT_int128";
1662 case FT_signed_int128: return "FT_signed_int128";
1663 case FT_unsigned_int128: return "FT_unsigned_int128";
1665 case FT_real32: return "FT_real32";
1666 case FT_real64: return "FT_real64";
1667 case FT_real96: return "FT_real96";
1668 case FT_real128: return "FT_real128";
1670 default: return "FT_<unknown>";
1674 /* Determine the "ultimate origin" of a decl. The decl may be an
1675 inlined instance of an inlined instance of a decl which is local
1676 to an inline function, so we have to trace all of the way back
1677 through the origin chain to find out what sort of node actually
1678 served as the original seed for the given block. */
1680 static tree
1681 decl_ultimate_origin (decl)
1682 tree decl;
1684 #ifdef ENABLE_CHECKING
1685 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1686 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1687 most distant ancestor, this should never happen. */
1688 abort ();
1689 #endif
1691 return DECL_ABSTRACT_ORIGIN (decl);
1694 /* Determine the "ultimate origin" of a block. The block may be an
1695 inlined instance of an inlined instance of a block which is local
1696 to an inline function, so we have to trace all of the way back
1697 through the origin chain to find out what sort of node actually
1698 served as the original seed for the given block. */
1700 static tree
1701 block_ultimate_origin (block)
1702 tree block;
1704 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1706 if (immediate_origin == NULL)
1707 return NULL;
1708 else
1710 tree ret_val;
1711 tree lookahead = immediate_origin;
1715 ret_val = lookahead;
1716 lookahead = (TREE_CODE (ret_val) == BLOCK)
1717 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1718 : NULL;
1720 while (lookahead != NULL && lookahead != ret_val);
1721 return ret_val;
1725 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1726 of a virtual function may refer to a base class, so we check the 'this'
1727 parameter. */
1729 static tree
1730 decl_class_context (decl)
1731 tree decl;
1733 tree context = NULL_TREE;
1734 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1735 context = DECL_CONTEXT (decl);
1736 else
1737 context = TYPE_MAIN_VARIANT
1738 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1740 if (context && !TYPE_P (context))
1741 context = NULL_TREE;
1743 return context;
1746 #if 0
1747 static void
1748 output_unsigned_leb128 (value)
1749 unsigned long value;
1751 unsigned long orig_value = value;
1755 unsigned byte = (value & 0x7f);
1757 value >>= 7;
1758 if (value != 0) /* more bytes to follow */
1759 byte |= 0x80;
1760 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1761 if (flag_debug_asm && value == 0)
1762 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1763 ASM_COMMENT_START, orig_value);
1764 fputc ('\n', asm_out_file);
1766 while (value != 0);
1769 static void
1770 output_signed_leb128 (value)
1771 long value;
1773 long orig_value = value;
1774 int negative = (value < 0);
1775 int more;
1779 unsigned byte = (value & 0x7f);
1781 value >>= 7;
1782 if (negative)
1783 value |= 0xfe000000; /* manually sign extend */
1784 if (((value == 0) && ((byte & 0x40) == 0))
1785 || ((value == -1) && ((byte & 0x40) == 1)))
1786 more = 0;
1787 else
1789 byte |= 0x80;
1790 more = 1;
1792 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1793 if (flag_debug_asm && more == 0)
1794 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1795 ASM_COMMENT_START, orig_value);
1796 fputc ('\n', asm_out_file);
1798 while (more);
1800 #endif
1802 /**************** utility functions for attribute functions ******************/
1804 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1805 type code for the given type.
1807 This routine must only be called for GCC type nodes that correspond to
1808 Dwarf fundamental types.
1810 The current Dwarf draft specification calls for Dwarf fundamental types
1811 to accurately reflect the fact that a given type was either a "plain"
1812 integral type or an explicitly "signed" integral type. Unfortunately,
1813 we can't always do this, because GCC may already have thrown away the
1814 information about the precise way in which the type was originally
1815 specified, as in:
1817 typedef signed int my_type;
1819 struct s { my_type f; };
1821 Since we may be stuck here without enough information to do exactly
1822 what is called for in the Dwarf draft specification, we do the best
1823 that we can under the circumstances and always use the "plain" integral
1824 fundamental type codes for int, short, and long types. That's probably
1825 good enough. The additional accuracy called for in the current DWARF
1826 draft specification is probably never even useful in practice. */
1828 static int
1829 fundamental_type_code (type)
1830 tree type;
1832 if (TREE_CODE (type) == ERROR_MARK)
1833 return 0;
1835 switch (TREE_CODE (type))
1837 case ERROR_MARK:
1838 return FT_void;
1840 case VOID_TYPE:
1841 return FT_void;
1843 case INTEGER_TYPE:
1844 /* Carefully distinguish all the standard types of C,
1845 without messing up if the language is not C.
1846 Note that we check only for the names that contain spaces;
1847 other names might occur by coincidence in other languages. */
1848 if (TYPE_NAME (type) != 0
1849 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1850 && DECL_NAME (TYPE_NAME (type)) != 0
1851 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1853 const char *const name =
1854 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1856 if (!strcmp (name, "unsigned char"))
1857 return FT_unsigned_char;
1858 if (!strcmp (name, "signed char"))
1859 return FT_signed_char;
1860 if (!strcmp (name, "unsigned int"))
1861 return FT_unsigned_integer;
1862 if (!strcmp (name, "short int"))
1863 return FT_short;
1864 if (!strcmp (name, "short unsigned int"))
1865 return FT_unsigned_short;
1866 if (!strcmp (name, "long int"))
1867 return FT_long;
1868 if (!strcmp (name, "long unsigned int"))
1869 return FT_unsigned_long;
1870 if (!strcmp (name, "long long int"))
1871 return FT_long_long; /* Not grok'ed by svr4 SDB */
1872 if (!strcmp (name, "long long unsigned int"))
1873 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1876 /* Most integer types will be sorted out above, however, for the
1877 sake of special `array index' integer types, the following code
1878 is also provided. */
1880 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1881 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1883 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1884 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1886 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1887 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1889 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1890 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1892 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1893 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1895 if (TYPE_MODE (type) == TImode)
1896 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1898 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1899 if (TYPE_PRECISION (type) == 1)
1900 return FT_boolean;
1902 abort ();
1904 case REAL_TYPE:
1905 /* Carefully distinguish all the standard types of C,
1906 without messing up if the language is not C. */
1907 if (TYPE_NAME (type) != 0
1908 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1909 && DECL_NAME (TYPE_NAME (type)) != 0
1910 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1912 const char *const name =
1913 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1915 /* Note that here we can run afowl of a serious bug in "classic"
1916 svr4 SDB debuggers. They don't seem to understand the
1917 FT_ext_prec_float type (even though they should). */
1919 if (!strcmp (name, "long double"))
1920 return FT_ext_prec_float;
1923 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1925 /* On the SH, when compiling with -m3e or -m4-single-only, both
1926 float and double are 32 bits. But since the debugger doesn't
1927 know about the subtarget, it always thinks double is 64 bits.
1928 So we have to tell the debugger that the type is float to
1929 make the output of the 'print' command etc. readable. */
1930 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1931 return FT_float;
1932 return FT_dbl_prec_float;
1934 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1935 return FT_float;
1937 /* Note that here we can run afowl of a serious bug in "classic"
1938 svr4 SDB debuggers. They don't seem to understand the
1939 FT_ext_prec_float type (even though they should). */
1941 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1942 return FT_ext_prec_float;
1943 abort ();
1945 case COMPLEX_TYPE:
1946 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1948 case CHAR_TYPE:
1949 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1951 case BOOLEAN_TYPE:
1952 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1954 default:
1955 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1957 return 0;
1960 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1961 the Dwarf "root" type for the given input type. The Dwarf "root" type
1962 of a given type is generally the same as the given type, except that if
1963 the given type is a pointer or reference type, then the root type of
1964 the given type is the root type of the "basis" type for the pointer or
1965 reference type. (This definition of the "root" type is recursive.)
1966 Also, the root type of a `const' qualified type or a `volatile'
1967 qualified type is the root type of the given type without the
1968 qualifiers. */
1970 static tree
1971 root_type_1 (type, count)
1972 tree type;
1973 int count;
1975 /* Give up after searching 1000 levels, in case this is a recursive
1976 pointer type. Such types are possible in Ada, but it is not possible
1977 to represent them in DWARF1 debug info. */
1978 if (count > 1000)
1979 return error_mark_node;
1981 switch (TREE_CODE (type))
1983 case ERROR_MARK:
1984 return error_mark_node;
1986 case POINTER_TYPE:
1987 case REFERENCE_TYPE:
1988 return root_type_1 (TREE_TYPE (type), count+1);
1990 default:
1991 return type;
1995 static tree
1996 root_type (type)
1997 tree type;
1999 type = root_type_1 (type, 0);
2000 if (type != error_mark_node)
2001 type = type_main_variant (type);
2002 return type;
2005 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
2006 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
2008 static void
2009 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
2010 tree type;
2011 int decl_const;
2012 int decl_volatile;
2013 int count;
2015 if (TREE_CODE (type) == ERROR_MARK)
2016 return;
2018 /* Give up after searching 1000 levels, in case this is a recursive
2019 pointer type. Such types are possible in Ada, but it is not possible
2020 to represent them in DWARF1 debug info. */
2021 if (count > 1000)
2022 return;
2024 if (TYPE_READONLY (type) || decl_const)
2025 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
2026 if (TYPE_VOLATILE (type) || decl_volatile)
2027 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
2028 switch (TREE_CODE (type))
2030 case POINTER_TYPE:
2031 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
2032 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
2033 return;
2035 case REFERENCE_TYPE:
2036 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
2037 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
2038 return;
2040 case ERROR_MARK:
2041 default:
2042 return;
2046 static void
2047 write_modifier_bytes (type, decl_const, decl_volatile)
2048 tree type;
2049 int decl_const;
2050 int decl_volatile;
2052 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
2055 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
2056 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
2058 static inline int
2059 type_is_fundamental (type)
2060 tree type;
2062 switch (TREE_CODE (type))
2064 case ERROR_MARK:
2065 case VOID_TYPE:
2066 case INTEGER_TYPE:
2067 case REAL_TYPE:
2068 case COMPLEX_TYPE:
2069 case BOOLEAN_TYPE:
2070 case CHAR_TYPE:
2071 return 1;
2073 case SET_TYPE:
2074 case ARRAY_TYPE:
2075 case RECORD_TYPE:
2076 case UNION_TYPE:
2077 case QUAL_UNION_TYPE:
2078 case ENUMERAL_TYPE:
2079 case FUNCTION_TYPE:
2080 case METHOD_TYPE:
2081 case POINTER_TYPE:
2082 case REFERENCE_TYPE:
2083 case FILE_TYPE:
2084 case OFFSET_TYPE:
2085 case LANG_TYPE:
2086 case VECTOR_TYPE:
2087 return 0;
2089 default:
2090 abort ();
2092 return 0;
2095 /* Given a pointer to some ..._DECL tree node, generate an assembly language
2096 equate directive which will associate a symbolic name with the current DIE.
2098 The name used is an artificial label generated from the DECL_UID number
2099 associated with the given decl node. The name it gets equated to is the
2100 symbolic label that we (previously) output at the start of the DIE that
2101 we are currently generating.
2103 Calling this function while generating some "decl related" form of DIE
2104 makes it possible to later refer to the DIE which represents the given
2105 decl simply by re-generating the symbolic name from the ..._DECL node's
2106 UID number. */
2108 static void
2109 equate_decl_number_to_die_number (decl)
2110 tree decl;
2112 /* In the case where we are generating a DIE for some ..._DECL node
2113 which represents either some inline function declaration or some
2114 entity declared within an inline function declaration/definition,
2115 setup a symbolic name for the current DIE so that we have a name
2116 for this DIE that we can easily refer to later on within
2117 AT_abstract_origin attributes. */
2119 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
2120 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2122 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
2123 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2124 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
2127 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
2128 equate directive which will associate a symbolic name with the current DIE.
2130 The name used is an artificial label generated from the TYPE_UID number
2131 associated with the given type node. The name it gets equated to is the
2132 symbolic label that we (previously) output at the start of the DIE that
2133 we are currently generating.
2135 Calling this function while generating some "type related" form of DIE
2136 makes it easy to later refer to the DIE which represents the given type
2137 simply by re-generating the alternative name from the ..._TYPE node's
2138 UID number. */
2140 static inline void
2141 equate_type_number_to_die_number (type)
2142 tree type;
2144 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
2145 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2147 /* We are generating a DIE to represent the main variant of this type
2148 (i.e the type without any const or volatile qualifiers) so in order
2149 to get the equate to come out right, we need to get the main variant
2150 itself here. */
2152 type = type_main_variant (type);
2154 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
2155 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2156 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
2159 static void
2160 output_reg_number (rtl)
2161 rtx rtl;
2163 unsigned regno = REGNO (rtl);
2165 if (regno >= DWARF_FRAME_REGISTERS)
2167 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
2168 regno);
2169 regno = 0;
2171 fprintf (asm_out_file, "%s0x%x",
2172 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
2173 if (flag_debug_asm)
2175 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
2176 PRINT_REG (rtl, 0, asm_out_file);
2178 fputc ('\n', asm_out_file);
2181 /* The following routine is a nice and simple transducer. It converts the
2182 RTL for a variable or parameter (resident in memory) into an equivalent
2183 Dwarf representation of a mechanism for getting the address of that same
2184 variable onto the top of a hypothetical "address evaluation" stack.
2186 When creating memory location descriptors, we are effectively trans-
2187 forming the RTL for a memory-resident object into its Dwarf postfix
2188 expression equivalent. This routine just recursively descends an
2189 RTL tree, turning it into Dwarf postfix code as it goes. */
2191 static void
2192 output_mem_loc_descriptor (rtl)
2193 rtx rtl;
2195 /* Note that for a dynamically sized array, the location we will
2196 generate a description of here will be the lowest numbered location
2197 which is actually within the array. That's *not* necessarily the
2198 same as the zeroth element of the array. */
2200 #ifdef ASM_SIMPLIFY_DWARF_ADDR
2201 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
2202 #endif
2204 switch (GET_CODE (rtl))
2206 case SUBREG:
2208 /* The case of a subreg may arise when we have a local (register)
2209 variable or a formal (register) parameter which doesn't quite
2210 fill up an entire register. For now, just assume that it is
2211 legitimate to make the Dwarf info refer to the whole register
2212 which contains the given subreg. */
2214 rtl = SUBREG_REG (rtl);
2215 /* Drop thru. */
2217 case REG:
2219 /* Whenever a register number forms a part of the description of
2220 the method for calculating the (dynamic) address of a memory
2221 resident object, DWARF rules require the register number to
2222 be referred to as a "base register". This distinction is not
2223 based in any way upon what category of register the hardware
2224 believes the given register belongs to. This is strictly
2225 DWARF terminology we're dealing with here.
2227 Note that in cases where the location of a memory-resident data
2228 object could be expressed as:
2230 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
2232 the actual DWARF location descriptor that we generate may just
2233 be OP_BASEREG (basereg). This may look deceptively like the
2234 object in question was allocated to a register (rather than
2235 in memory) so DWARF consumers need to be aware of the subtle
2236 distinction between OP_REG and OP_BASEREG. */
2238 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
2239 output_reg_number (rtl);
2240 break;
2242 case MEM:
2243 output_mem_loc_descriptor (XEXP (rtl, 0));
2244 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
2245 break;
2247 case CONST:
2248 case SYMBOL_REF:
2249 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
2250 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2251 break;
2253 case PLUS:
2254 output_mem_loc_descriptor (XEXP (rtl, 0));
2255 output_mem_loc_descriptor (XEXP (rtl, 1));
2256 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2257 break;
2259 case CONST_INT:
2260 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2261 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
2262 break;
2264 case MULT:
2265 /* If a pseudo-reg is optimized away, it is possible for it to
2266 be replaced with a MEM containing a multiply. Use a GNU extension
2267 to describe it. */
2268 output_mem_loc_descriptor (XEXP (rtl, 0));
2269 output_mem_loc_descriptor (XEXP (rtl, 1));
2270 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
2271 break;
2273 default:
2274 abort ();
2278 /* Output a proper Dwarf location descriptor for a variable or parameter
2279 which is either allocated in a register or in a memory location. For
2280 a register, we just generate an OP_REG and the register number. For a
2281 memory location we provide a Dwarf postfix expression describing how to
2282 generate the (dynamic) address of the object onto the address stack. */
2284 static void
2285 output_loc_descriptor (rtl)
2286 rtx rtl;
2288 switch (GET_CODE (rtl))
2290 case SUBREG:
2292 /* The case of a subreg may arise when we have a local (register)
2293 variable or a formal (register) parameter which doesn't quite
2294 fill up an entire register. For now, just assume that it is
2295 legitimate to make the Dwarf info refer to the whole register
2296 which contains the given subreg. */
2298 rtl = SUBREG_REG (rtl);
2299 /* Drop thru. */
2301 case REG:
2302 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
2303 output_reg_number (rtl);
2304 break;
2306 case MEM:
2307 output_mem_loc_descriptor (XEXP (rtl, 0));
2308 break;
2310 default:
2311 abort (); /* Should never happen */
2315 /* Given a tree node describing an array bound (either lower or upper)
2316 output a representation for that bound. */
2318 static void
2319 output_bound_representation (bound, dim_num, u_or_l)
2320 tree bound;
2321 unsigned dim_num; /* For multi-dimensional arrays. */
2322 char u_or_l; /* Designates upper or lower bound. */
2324 switch (TREE_CODE (bound))
2327 case ERROR_MARK:
2328 return;
2330 /* All fixed-bounds are represented by INTEGER_CST nodes. */
2332 case INTEGER_CST:
2333 if (host_integerp (bound, 0))
2334 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
2335 break;
2337 default:
2339 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
2340 SAVE_EXPR nodes, in which case we can do something, or as
2341 an expression, which we cannot represent. */
2343 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2344 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2346 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
2347 current_dienum, dim_num, u_or_l);
2349 sprintf (end_label, BOUND_END_LABEL_FMT,
2350 current_dienum, dim_num, u_or_l);
2352 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2353 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2355 /* If optimization is turned on, the SAVE_EXPRs that describe
2356 how to access the upper bound values are essentially bogus.
2357 They only describe (at best) how to get at these values at
2358 the points in the generated code right after they have just
2359 been computed. Worse yet, in the typical case, the upper
2360 bound values will not even *be* computed in the optimized
2361 code, so these SAVE_EXPRs are entirely bogus.
2363 In order to compensate for this fact, we check here to see
2364 if optimization is enabled, and if so, we effectively create
2365 an empty location description for the (unknown and unknowable)
2366 upper bound.
2368 This should not cause too much trouble for existing (stupid?)
2369 debuggers because they have to deal with empty upper bounds
2370 location descriptions anyway in order to be able to deal with
2371 incomplete array types.
2373 Of course an intelligent debugger (GDB?) should be able to
2374 comprehend that a missing upper bound specification in a
2375 array type used for a storage class `auto' local array variable
2376 indicates that the upper bound is both unknown (at compile-
2377 time) and unknowable (at run-time) due to optimization. */
2379 if (! optimize)
2381 while (TREE_CODE (bound) == NOP_EXPR
2382 || TREE_CODE (bound) == CONVERT_EXPR)
2383 bound = TREE_OPERAND (bound, 0);
2385 if (TREE_CODE (bound) == SAVE_EXPR)
2386 output_loc_descriptor
2387 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
2390 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2392 break;
2397 /* Recursive function to output a sequence of value/name pairs for
2398 enumeration constants in reversed order. This is called from
2399 enumeration_type_die. */
2401 static void
2402 output_enumeral_list (link)
2403 tree link;
2405 if (link)
2407 output_enumeral_list (TREE_CHAIN (link));
2409 if (host_integerp (TREE_VALUE (link), 0))
2410 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2411 tree_low_cst (TREE_VALUE (link), 0));
2413 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
2414 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
2418 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
2419 which is not less than the value itself. */
2421 static inline HOST_WIDE_INT
2422 ceiling (value, boundary)
2423 HOST_WIDE_INT value;
2424 unsigned int boundary;
2426 return (((value + boundary - 1) / boundary) * boundary);
2429 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
2430 pointer to the declared type for the relevant field variable, or return
2431 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
2433 static inline tree
2434 field_type (decl)
2435 tree decl;
2437 tree type;
2439 if (TREE_CODE (decl) == ERROR_MARK)
2440 return integer_type_node;
2442 type = DECL_BIT_FIELD_TYPE (decl);
2443 if (type == NULL)
2444 type = TREE_TYPE (decl);
2445 return type;
2448 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2449 node, return the alignment in bits for the type, or else return
2450 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
2452 static inline unsigned int
2453 simple_type_align_in_bits (type)
2454 tree type;
2456 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
2459 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2460 node, return the size in bits for the type if it is a constant, or
2461 else return the alignment for the type if the type's size is not
2462 constant, or else return BITS_PER_WORD if the type actually turns out
2463 to be an ERROR_MARK node. */
2465 static inline unsigned HOST_WIDE_INT
2466 simple_type_size_in_bits (type)
2467 tree type;
2469 tree type_size_tree;
2471 if (TREE_CODE (type) == ERROR_MARK)
2472 return BITS_PER_WORD;
2473 type_size_tree = TYPE_SIZE (type);
2475 if (type_size_tree == NULL_TREE)
2476 return 0;
2477 if (! host_integerp (type_size_tree, 1))
2478 return TYPE_ALIGN (type);
2479 return tree_low_cst (type_size_tree, 1);
2482 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
2483 return the byte offset of the lowest addressed byte of the "containing
2484 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
2485 mine what that offset is, either because the argument turns out to be a
2486 pointer to an ERROR_MARK node, or because the offset is actually variable.
2487 (We can't handle the latter case just yet.) */
2489 static HOST_WIDE_INT
2490 field_byte_offset (decl)
2491 tree decl;
2493 unsigned int type_align_in_bytes;
2494 unsigned int type_align_in_bits;
2495 unsigned HOST_WIDE_INT type_size_in_bits;
2496 HOST_WIDE_INT object_offset_in_align_units;
2497 HOST_WIDE_INT object_offset_in_bits;
2498 HOST_WIDE_INT object_offset_in_bytes;
2499 tree type;
2500 tree field_size_tree;
2501 HOST_WIDE_INT bitpos_int;
2502 HOST_WIDE_INT deepest_bitpos;
2503 unsigned HOST_WIDE_INT field_size_in_bits;
2505 if (TREE_CODE (decl) == ERROR_MARK)
2506 return 0;
2508 if (TREE_CODE (decl) != FIELD_DECL)
2509 abort ();
2511 type = field_type (decl);
2512 field_size_tree = DECL_SIZE (decl);
2514 /* The size could be unspecified if there was an error, or for
2515 a flexible array member. */
2516 if (! field_size_tree)
2517 field_size_tree = bitsize_zero_node;
2519 /* We cannot yet cope with fields whose positions or sizes are variable,
2520 so for now, when we see such things, we simply return 0. Someday,
2521 we may be able to handle such cases, but it will be damn difficult. */
2523 if (! host_integerp (bit_position (decl), 0)
2524 || ! host_integerp (field_size_tree, 1))
2525 return 0;
2527 bitpos_int = int_bit_position (decl);
2528 field_size_in_bits = tree_low_cst (field_size_tree, 1);
2530 type_size_in_bits = simple_type_size_in_bits (type);
2531 type_align_in_bits = simple_type_align_in_bits (type);
2532 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2534 /* Note that the GCC front-end doesn't make any attempt to keep track
2535 of the starting bit offset (relative to the start of the containing
2536 structure type) of the hypothetical "containing object" for a bit-
2537 field. Thus, when computing the byte offset value for the start of
2538 the "containing object" of a bit-field, we must deduce this infor-
2539 mation on our own.
2541 This can be rather tricky to do in some cases. For example, handling
2542 the following structure type definition when compiling for an i386/i486
2543 target (which only aligns long long's to 32-bit boundaries) can be very
2544 tricky:
2546 struct S {
2547 int field1;
2548 long long field2:31;
2551 Fortunately, there is a simple rule-of-thumb which can be used in such
2552 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2553 the structure shown above. It decides to do this based upon one simple
2554 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2555 taining object" for each bit-field at the first (i.e. lowest addressed)
2556 legitimate alignment boundary (based upon the required minimum alignment
2557 for the declared type of the field) which it can possibly use, subject
2558 to the condition that there is still enough available space remaining
2559 in the containing object (when allocated at the selected point) to
2560 fully accommodate all of the bits of the bit-field itself.
2562 This simple rule makes it obvious why GCC allocates 8 bytes for each
2563 object of the structure type shown above. When looking for a place to
2564 allocate the "containing object" for `field2', the compiler simply tries
2565 to allocate a 64-bit "containing object" at each successive 32-bit
2566 boundary (starting at zero) until it finds a place to allocate that 64-
2567 bit field such that at least 31 contiguous (and previously unallocated)
2568 bits remain within that selected 64 bit field. (As it turns out, for
2569 the example above, the compiler finds that it is OK to allocate the
2570 "containing object" 64-bit field at bit-offset zero within the
2571 structure type.)
2573 Here we attempt to work backwards from the limited set of facts we're
2574 given, and we try to deduce from those facts, where GCC must have
2575 believed that the containing object started (within the structure type).
2577 The value we deduce is then used (by the callers of this routine) to
2578 generate AT_location and AT_bit_offset attributes for fields (both
2579 bit-fields and, in the case of AT_location, regular fields as well). */
2581 /* Figure out the bit-distance from the start of the structure to the
2582 "deepest" bit of the bit-field. */
2583 deepest_bitpos = bitpos_int + field_size_in_bits;
2585 /* This is the tricky part. Use some fancy footwork to deduce where the
2586 lowest addressed bit of the containing object must be. */
2587 object_offset_in_bits
2588 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2590 /* Compute the offset of the containing object in "alignment units". */
2591 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2593 /* Compute the offset of the containing object in bytes. */
2594 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2596 /* The above code assumes that the field does not cross an alignment
2597 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2598 or if the structure is packed. If this happens, then we get an object
2599 which starts after the bitfield, which means that the bit offset is
2600 negative. Gdb fails when given negative bit offsets. We avoid this
2601 by recomputing using the first bit of the bitfield. This will give
2602 us an object which does not completely contain the bitfield, but it
2603 will be aligned, and it will contain the first bit of the bitfield.
2605 However, only do this for a BYTES_BIG_ENDIAN target. For a
2606 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2607 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2608 then we end up computing the object byte offset for the wrong word of the
2609 desired bitfield, which in turn causes the field offset to be negative
2610 in bit_offset_attribute. */
2611 if (BYTES_BIG_ENDIAN
2612 && object_offset_in_bits > bitpos_int)
2614 deepest_bitpos = bitpos_int + 1;
2615 object_offset_in_bits
2616 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2617 object_offset_in_align_units = (object_offset_in_bits
2618 / type_align_in_bits);
2619 object_offset_in_bytes = (object_offset_in_align_units
2620 * type_align_in_bytes);
2623 return object_offset_in_bytes;
2626 /****************************** attributes *********************************/
2628 /* The following routines are responsible for writing out the various types
2629 of Dwarf attributes (and any following data bytes associated with them).
2630 These routines are listed in order based on the numerical codes of their
2631 associated attributes. */
2633 /* Generate an AT_sibling attribute. */
2635 static inline void
2636 sibling_attribute ()
2638 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2640 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2641 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2642 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2645 /* Output the form of location attributes suitable for whole variables and
2646 whole parameters. Note that the location attributes for struct fields
2647 are generated by the routine `data_member_location_attribute' below. */
2649 static void
2650 location_attribute (rtl)
2651 rtx rtl;
2653 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2654 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2656 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2657 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2658 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2659 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2660 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2662 /* Handle a special case. If we are about to output a location descriptor
2663 for a variable or parameter which has been optimized out of existence,
2664 don't do that. Instead we output a zero-length location descriptor
2665 value as part of the location attribute.
2667 A variable which has been optimized out of existence will have a
2668 DECL_RTL value which denotes a pseudo-reg.
2670 Currently, in some rare cases, variables can have DECL_RTL values
2671 which look like (MEM (REG pseudo-reg#)). These cases are due to
2672 bugs elsewhere in the compiler. We treat such cases
2673 as if the variable(s) in question had been optimized out of existence.
2675 Note that in all cases where we wish to express the fact that a
2676 variable has been optimized out of existence, we do not simply
2677 suppress the generation of the entire location attribute because
2678 the absence of a location attribute in certain kinds of DIEs is
2679 used to indicate something else entirely... i.e. that the DIE
2680 represents an object declaration, but not a definition. So saith
2681 the PLSIG.
2684 if (! is_pseudo_reg (rtl)
2685 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2686 output_loc_descriptor (rtl);
2688 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2691 /* Output the specialized form of location attribute used for data members
2692 of struct and union types.
2694 In the special case of a FIELD_DECL node which represents a bit-field,
2695 the "offset" part of this special location descriptor must indicate the
2696 distance in bytes from the lowest-addressed byte of the containing
2697 struct or union type to the lowest-addressed byte of the "containing
2698 object" for the bit-field. (See the `field_byte_offset' function above.)
2700 For any given bit-field, the "containing object" is a hypothetical
2701 object (of some integral or enum type) within which the given bit-field
2702 lives. The type of this hypothetical "containing object" is always the
2703 same as the declared type of the individual bit-field itself (for GCC
2704 anyway... the DWARF spec doesn't actually mandate this).
2706 Note that it is the size (in bytes) of the hypothetical "containing
2707 object" which will be given in the AT_byte_size attribute for this
2708 bit-field. (See the `byte_size_attribute' function below.) It is
2709 also used when calculating the value of the AT_bit_offset attribute.
2710 (See the `bit_offset_attribute' function below.) */
2712 static void
2713 data_member_location_attribute (t)
2714 tree t;
2716 unsigned object_offset_in_bytes;
2717 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2718 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2720 if (TREE_CODE (t) == TREE_VEC)
2721 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2722 else
2723 object_offset_in_bytes = field_byte_offset (t);
2725 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2726 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2727 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2728 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2729 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2730 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2731 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2732 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2733 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2736 /* Output an AT_const_value attribute for a variable or a parameter which
2737 does not have a "location" either in memory or in a register. These
2738 things can arise in GNU C when a constant is passed as an actual
2739 parameter to an inlined function. They can also arise in C++ where
2740 declared constants do not necessarily get memory "homes". */
2742 static void
2743 const_value_attribute (rtl)
2744 rtx rtl;
2746 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2747 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2749 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2750 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2751 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2752 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2753 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2755 switch (GET_CODE (rtl))
2757 case CONST_INT:
2758 /* Note that a CONST_INT rtx could represent either an integer or
2759 a floating-point constant. A CONST_INT is used whenever the
2760 constant will fit into a single word. In all such cases, the
2761 original mode of the constant value is wiped out, and the
2762 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2763 precise mode information for these constants, we always just
2764 output them using 4 bytes. */
2766 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2767 break;
2769 case CONST_DOUBLE:
2770 /* Note that a CONST_DOUBLE rtx could represent either an integer
2771 or a floating-point constant. A CONST_DOUBLE is used whenever
2772 the constant requires more than one word in order to be adequately
2773 represented. In all such cases, the original mode of the constant
2774 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2775 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2777 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2778 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2779 (unsigned int) CONST_DOUBLE_LOW (rtl));
2780 break;
2782 case CONST_STRING:
2783 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2784 break;
2786 case SYMBOL_REF:
2787 case LABEL_REF:
2788 case CONST:
2789 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2790 break;
2792 case PLUS:
2793 /* In cases where an inlined instance of an inline function is passed
2794 the address of an `auto' variable (which is local to the caller)
2795 we can get a situation where the DECL_RTL of the artificial
2796 local variable (for the inlining) which acts as a stand-in for
2797 the corresponding formal parameter (of the inline function)
2798 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2799 This is not exactly a compile-time constant expression, but it
2800 isn't the address of the (artificial) local variable either.
2801 Rather, it represents the *value* which the artificial local
2802 variable always has during its lifetime. We currently have no
2803 way to represent such quasi-constant values in Dwarf, so for now
2804 we just punt and generate an AT_const_value attribute with form
2805 FORM_BLOCK4 and a length of zero. */
2806 break;
2808 default:
2809 abort (); /* No other kinds of rtx should be possible here. */
2812 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2815 /* Generate *either* an AT_location attribute or else an AT_const_value
2816 data attribute for a variable or a parameter. We generate the
2817 AT_const_value attribute only in those cases where the given
2818 variable or parameter does not have a true "location" either in
2819 memory or in a register. This can happen (for example) when a
2820 constant is passed as an actual argument in a call to an inline
2821 function. (It's possible that these things can crop up in other
2822 ways also.) Note that one type of constant value which can be
2823 passed into an inlined function is a constant pointer. This can
2824 happen for example if an actual argument in an inlined function
2825 call evaluates to a compile-time constant address. */
2827 static void
2828 location_or_const_value_attribute (decl)
2829 tree decl;
2831 rtx rtl;
2833 if (TREE_CODE (decl) == ERROR_MARK)
2834 return;
2836 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2838 /* Should never happen. */
2839 abort ();
2840 return;
2843 /* Here we have to decide where we are going to say the parameter "lives"
2844 (as far as the debugger is concerned). We only have a couple of choices.
2845 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2846 normally indicates where the parameter lives during most of the activa-
2847 tion of the function. If optimization is enabled however, this could
2848 be either NULL or else a pseudo-reg. Both of those cases indicate that
2849 the parameter doesn't really live anywhere (as far as the code generation
2850 parts of GCC are concerned) during most of the function's activation.
2851 That will happen (for example) if the parameter is never referenced
2852 within the function.
2854 We could just generate a location descriptor here for all non-NULL
2855 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2856 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2857 cases where DECL_RTL is NULL or is a pseudo-reg.
2859 Note however that we can only get away with using DECL_INCOMING_RTL as
2860 a backup substitute for DECL_RTL in certain limited cases. In cases
2861 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2862 we can be sure that the parameter was passed using the same type as it
2863 is declared to have within the function, and that its DECL_INCOMING_RTL
2864 points us to a place where a value of that type is passed. In cases
2865 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2866 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2867 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2868 points us to a value of some type which is *different* from the type
2869 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2870 to generate a location attribute in such cases, the debugger would
2871 end up (for example) trying to fetch a `float' from a place which
2872 actually contains the first part of a `double'. That would lead to
2873 really incorrect and confusing output at debug-time, and we don't
2874 want that now do we?
2876 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2877 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2878 couple of cute exceptions however. On little-endian machines we can
2879 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2880 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2881 an integral type which is smaller than TREE_TYPE(decl). These cases
2882 arise when (on a little-endian machine) a non-prototyped function has
2883 a parameter declared to be of type `short' or `char'. In such cases,
2884 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2885 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2886 passed `int' value. If the debugger then uses that address to fetch a
2887 `short' or a `char' (on a little-endian machine) the result will be the
2888 correct data, so we allow for such exceptional cases below.
2890 Note that our goal here is to describe the place where the given formal
2891 parameter lives during most of the function's activation (i.e. between
2892 the end of the prologue and the start of the epilogue). We'll do that
2893 as best as we can. Note however that if the given formal parameter is
2894 modified sometime during the execution of the function, then a stack
2895 backtrace (at debug-time) will show the function as having been called
2896 with the *new* value rather than the value which was originally passed
2897 in. This happens rarely enough that it is not a major problem, but it
2898 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2899 may generate two additional attributes for any given TAG_formal_parameter
2900 DIE which will describe the "passed type" and the "passed location" for
2901 the given formal parameter in addition to the attributes we now generate
2902 to indicate the "declared type" and the "active location" for each
2903 parameter. This additional set of attributes could be used by debuggers
2904 for stack backtraces.
2906 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2907 can be NULL also. This happens (for example) for inlined-instances of
2908 inline function formal parameters which are never referenced. This really
2909 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2910 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2911 these values for inlined instances of inline function parameters, so
2912 when we see such cases, we are just out-of-luck for the time
2913 being (until integrate.c gets fixed).
2916 /* Use DECL_RTL as the "location" unless we find something better. */
2917 rtl = DECL_RTL (decl);
2919 if (TREE_CODE (decl) == PARM_DECL)
2920 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2922 /* This decl represents a formal parameter which was optimized out. */
2923 tree declared_type = type_main_variant (TREE_TYPE (decl));
2924 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2926 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2927 *all* cases where (rtl == NULL_RTX) just below. */
2929 if (declared_type == passed_type)
2930 rtl = DECL_INCOMING_RTL (decl);
2931 else if (! BYTES_BIG_ENDIAN)
2932 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2933 /* NMS WTF? */
2934 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2935 rtl = DECL_INCOMING_RTL (decl);
2938 if (rtl == NULL_RTX)
2939 return;
2941 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2942 #ifdef LEAF_REG_REMAP
2943 if (current_function_uses_only_leaf_regs)
2944 leaf_renumber_regs_insn (rtl);
2945 #endif
2947 switch (GET_CODE (rtl))
2949 case ADDRESSOF:
2950 /* The address of a variable that was optimized away; don't emit
2951 anything. */
2952 break;
2954 case CONST_INT:
2955 case CONST_DOUBLE:
2956 case CONST_STRING:
2957 case SYMBOL_REF:
2958 case LABEL_REF:
2959 case CONST:
2960 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2961 const_value_attribute (rtl);
2962 break;
2964 case MEM:
2965 case REG:
2966 case SUBREG:
2967 location_attribute (rtl);
2968 break;
2970 case CONCAT:
2971 /* ??? CONCAT is used for complex variables, which may have the real
2972 part stored in one place and the imag part stored somewhere else.
2973 DWARF1 has no way to describe a variable that lives in two different
2974 places, so we just describe where the first part lives, and hope that
2975 the second part is stored after it. */
2976 location_attribute (XEXP (rtl, 0));
2977 break;
2979 default:
2980 abort (); /* Should never happen. */
2984 /* Generate an AT_name attribute given some string value to be included as
2985 the value of the attribute. */
2987 static inline void
2988 name_attribute (name_string)
2989 const char *name_string;
2991 if (name_string && *name_string)
2993 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2994 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2998 static inline void
2999 fund_type_attribute (ft_code)
3000 unsigned ft_code;
3002 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
3003 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
3006 static void
3007 mod_fund_type_attribute (type, decl_const, decl_volatile)
3008 tree type;
3009 int decl_const;
3010 int decl_volatile;
3012 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3013 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3015 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
3016 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
3017 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
3018 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3019 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3020 write_modifier_bytes (type, decl_const, decl_volatile);
3021 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3022 fundamental_type_code (root_type (type)));
3023 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3026 static inline void
3027 user_def_type_attribute (type)
3028 tree type;
3030 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
3032 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
3033 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
3034 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
3037 static void
3038 mod_u_d_type_attribute (type, decl_const, decl_volatile)
3039 tree type;
3040 int decl_const;
3041 int decl_volatile;
3043 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3044 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3045 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
3047 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
3048 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
3049 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
3050 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3051 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3052 write_modifier_bytes (type, decl_const, decl_volatile);
3053 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
3054 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
3055 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3058 #ifdef USE_ORDERING_ATTRIBUTE
3059 static inline void
3060 ordering_attribute (ordering)
3061 unsigned ordering;
3063 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
3064 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
3066 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3068 /* Note that the block of subscript information for an array type also
3069 includes information about the element type of type given array type. */
3071 static void
3072 subscript_data_attribute (type)
3073 tree type;
3075 unsigned dimension_number;
3076 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3077 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3079 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
3080 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
3081 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
3082 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3083 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3085 /* The GNU compilers represent multidimensional array types as sequences
3086 of one dimensional array types whose element types are themselves array
3087 types. Here we squish that down, so that each multidimensional array
3088 type gets only one array_type DIE in the Dwarf debugging info. The
3089 draft Dwarf specification say that we are allowed to do this kind
3090 of compression in C (because there is no difference between an
3091 array or arrays and a multidimensional array in C) but for other
3092 source languages (e.g. Ada) we probably shouldn't do this. */
3094 for (dimension_number = 0;
3095 TREE_CODE (type) == ARRAY_TYPE;
3096 type = TREE_TYPE (type), dimension_number++)
3098 tree domain = TYPE_DOMAIN (type);
3100 /* Arrays come in three flavors. Unspecified bounds, fixed
3101 bounds, and (in GNU C only) variable bounds. Handle all
3102 three forms here. */
3104 if (domain)
3106 /* We have an array type with specified bounds. */
3108 tree lower = TYPE_MIN_VALUE (domain);
3109 tree upper = TYPE_MAX_VALUE (domain);
3111 /* Handle only fundamental types as index types for now. */
3112 if (! type_is_fundamental (domain))
3113 abort ();
3115 /* Output the representation format byte for this dimension. */
3116 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
3117 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
3118 upper && TREE_CODE (upper) == INTEGER_CST));
3120 /* Output the index type for this dimension. */
3121 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3122 fundamental_type_code (domain));
3124 /* Output the representation for the lower bound. */
3125 output_bound_representation (lower, dimension_number, 'l');
3127 /* Output the representation for the upper bound. */
3128 if (upper)
3129 output_bound_representation (upper, dimension_number, 'u');
3130 else
3131 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3133 else
3135 /* We have an array type with an unspecified length. For C and
3136 C++ we can assume that this really means that (a) the index
3137 type is an integral type, and (b) the lower bound is zero.
3138 Note that Dwarf defines the representation of an unspecified
3139 (upper) bound as being a zero-length location description. */
3141 /* Output the array-bounds format byte. */
3143 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
3145 /* Output the (assumed) index type. */
3147 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
3149 /* Output the (assumed) lower bound (constant) value. */
3151 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3153 /* Output the (empty) location description for the upper bound. */
3155 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3159 /* Output the prefix byte that says that the element type is coming up. */
3161 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
3163 /* Output a representation of the type of the elements of this array type. */
3165 type_attribute (type, 0, 0);
3167 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3170 static void
3171 byte_size_attribute (tree_node)
3172 tree tree_node;
3174 unsigned size;
3176 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
3177 switch (TREE_CODE (tree_node))
3179 case ERROR_MARK:
3180 size = 0;
3181 break;
3183 case ENUMERAL_TYPE:
3184 case RECORD_TYPE:
3185 case UNION_TYPE:
3186 case QUAL_UNION_TYPE:
3187 case ARRAY_TYPE:
3188 size = int_size_in_bytes (tree_node);
3189 break;
3191 case FIELD_DECL:
3192 /* For a data member of a struct or union, the AT_byte_size is
3193 generally given as the number of bytes normally allocated for
3194 an object of the *declared* type of the member itself. This
3195 is true even for bit-fields. */
3196 size = simple_type_size_in_bits (field_type (tree_node))
3197 / BITS_PER_UNIT;
3198 break;
3200 default:
3201 abort ();
3204 /* Note that `size' might be -1 when we get to this point. If it
3205 is, that indicates that the byte size of the entity in question
3206 is variable. We have no good way of expressing this fact in Dwarf
3207 at the present time, so just let the -1 pass on through. */
3209 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
3212 /* For a FIELD_DECL node which represents a bit-field, output an attribute
3213 which specifies the distance in bits from the highest order bit of the
3214 "containing object" for the bit-field to the highest order bit of the
3215 bit-field itself.
3217 For any given bit-field, the "containing object" is a hypothetical
3218 object (of some integral or enum type) within which the given bit-field
3219 lives. The type of this hypothetical "containing object" is always the
3220 same as the declared type of the individual bit-field itself.
3222 The determination of the exact location of the "containing object" for
3223 a bit-field is rather complicated. It's handled by the `field_byte_offset'
3224 function (above).
3226 Note that it is the size (in bytes) of the hypothetical "containing
3227 object" which will be given in the AT_byte_size attribute for this
3228 bit-field. (See `byte_size_attribute' above.) */
3230 static inline void
3231 bit_offset_attribute (decl)
3232 tree decl;
3234 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
3235 tree type = DECL_BIT_FIELD_TYPE (decl);
3236 HOST_WIDE_INT bitpos_int;
3237 HOST_WIDE_INT highest_order_object_bit_offset;
3238 HOST_WIDE_INT highest_order_field_bit_offset;
3239 HOST_WIDE_INT bit_offset;
3241 /* Must be a bit field. */
3242 if (!type
3243 || TREE_CODE (decl) != FIELD_DECL)
3244 abort ();
3246 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
3247 if we encounter such things, just return without generating any
3248 attribute whatsoever. */
3250 if (! host_integerp (bit_position (decl), 0)
3251 || ! host_integerp (DECL_SIZE (decl), 1))
3252 return;
3254 bitpos_int = int_bit_position (decl);
3256 /* Note that the bit offset is always the distance (in bits) from the
3257 highest-order bit of the "containing object" to the highest-order
3258 bit of the bit-field itself. Since the "high-order end" of any
3259 object or field is different on big-endian and little-endian machines,
3260 the computation below must take account of these differences. */
3262 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
3263 highest_order_field_bit_offset = bitpos_int;
3265 if (! BYTES_BIG_ENDIAN)
3267 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
3268 highest_order_object_bit_offset += simple_type_size_in_bits (type);
3271 bit_offset =
3272 (! BYTES_BIG_ENDIAN
3273 ? highest_order_object_bit_offset - highest_order_field_bit_offset
3274 : highest_order_field_bit_offset - highest_order_object_bit_offset);
3276 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
3277 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
3280 /* For a FIELD_DECL node which represents a bit field, output an attribute
3281 which specifies the length in bits of the given field. */
3283 static inline void
3284 bit_size_attribute (decl)
3285 tree decl;
3287 /* Must be a field and a bit field. */
3288 if (TREE_CODE (decl) != FIELD_DECL
3289 || ! DECL_BIT_FIELD_TYPE (decl))
3290 abort ();
3292 if (host_integerp (DECL_SIZE (decl), 1))
3294 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
3295 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3296 tree_low_cst (DECL_SIZE (decl), 1));
3300 /* The following routine outputs the `element_list' attribute for enumeration
3301 type DIEs. The element_lits attribute includes the names and values of
3302 all of the enumeration constants associated with the given enumeration
3303 type. */
3305 static inline void
3306 element_list_attribute (element)
3307 tree element;
3309 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3310 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3312 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
3313 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
3314 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
3315 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3316 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3318 /* Here we output a list of value/name pairs for each enumeration constant
3319 defined for this enumeration type (as required), but we do it in REVERSE
3320 order. The order is the one required by the draft #5 Dwarf specification
3321 published by the UI/PLSIG. */
3323 output_enumeral_list (element); /* Recursively output the whole list. */
3325 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3328 /* Generate an AT_stmt_list attribute. These are normally present only in
3329 DIEs with a TAG_compile_unit tag. */
3331 static inline void
3332 stmt_list_attribute (label)
3333 const char *label;
3335 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
3336 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3337 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3340 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
3341 for a subroutine DIE. */
3343 static inline void
3344 low_pc_attribute (asm_low_label)
3345 const char *asm_low_label;
3347 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
3348 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
3351 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
3352 subroutine DIE. */
3354 static inline void
3355 high_pc_attribute (asm_high_label)
3356 const char *asm_high_label;
3358 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
3359 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
3362 /* Generate an AT_body_begin attribute for a subroutine DIE. */
3364 static inline void
3365 body_begin_attribute (asm_begin_label)
3366 const char *asm_begin_label;
3368 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
3369 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
3372 /* Generate an AT_body_end attribute for a subroutine DIE. */
3374 static inline void
3375 body_end_attribute (asm_end_label)
3376 const char *asm_end_label;
3378 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
3379 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
3382 /* Generate an AT_language attribute given a LANG value. These attributes
3383 are used only within TAG_compile_unit DIEs. */
3385 static inline void
3386 language_attribute (language_code)
3387 unsigned language_code;
3389 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
3390 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
3393 static inline void
3394 member_attribute (context)
3395 tree context;
3397 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3399 /* Generate this attribute only for members in C++. */
3401 if (context != NULL && is_tagged_type (context))
3403 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
3404 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
3405 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3409 #if 0
3410 static inline void
3411 string_length_attribute (upper_bound)
3412 tree upper_bound;
3414 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3415 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3417 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
3418 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
3419 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
3420 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3421 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3422 output_bound_representation (upper_bound, 0, 'u');
3423 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3425 #endif
3427 static inline void
3428 comp_dir_attribute (dirname)
3429 const char *dirname;
3431 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
3432 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
3435 static inline void
3436 sf_names_attribute (sf_names_start_label)
3437 const char *sf_names_start_label;
3439 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
3440 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3441 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
3444 static inline void
3445 src_info_attribute (src_info_start_label)
3446 const char *src_info_start_label;
3448 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
3449 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3450 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
3453 static inline void
3454 mac_info_attribute (mac_info_start_label)
3455 const char *mac_info_start_label;
3457 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
3458 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3459 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
3462 static inline void
3463 prototyped_attribute (func_type)
3464 tree func_type;
3466 if ((strcmp (lang_hooks.name, "GNU C") == 0)
3467 && (TYPE_ARG_TYPES (func_type) != NULL))
3469 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
3470 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3474 static inline void
3475 producer_attribute (producer)
3476 const char *producer;
3478 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
3479 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
3482 static inline void
3483 inline_attribute (decl)
3484 tree decl;
3486 if (DECL_INLINE (decl))
3488 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3489 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3493 static inline void
3494 containing_type_attribute (containing_type)
3495 tree containing_type;
3497 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3499 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3500 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3501 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3504 static inline void
3505 abstract_origin_attribute (origin)
3506 tree origin;
3508 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3510 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3511 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3513 case 'd':
3514 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3515 break;
3517 case 't':
3518 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3519 break;
3521 default:
3522 abort (); /* Should never happen. */
3525 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3528 #ifdef DWARF_DECL_COORDINATES
3529 static inline void
3530 src_coords_attribute (src_fileno, src_lineno)
3531 unsigned src_fileno;
3532 unsigned src_lineno;
3534 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3535 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3536 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3538 #endif /* defined(DWARF_DECL_COORDINATES) */
3540 static inline void
3541 pure_or_virtual_attribute (func_decl)
3542 tree func_decl;
3544 if (DECL_VIRTUAL_P (func_decl))
3546 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3547 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3548 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3549 else
3550 #endif
3551 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3552 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3556 /************************* end of attributes *****************************/
3558 /********************* utility routines for DIEs *************************/
3560 /* Output an AT_name attribute and an AT_src_coords attribute for the
3561 given decl, but only if it actually has a name. */
3563 static void
3564 name_and_src_coords_attributes (decl)
3565 tree decl;
3567 tree decl_name = DECL_NAME (decl);
3569 if (decl_name && IDENTIFIER_POINTER (decl_name))
3571 name_attribute (IDENTIFIER_POINTER (decl_name));
3572 #ifdef DWARF_DECL_COORDINATES
3574 register unsigned file_index;
3576 /* This is annoying, but we have to pop out of the .debug section
3577 for a moment while we call `lookup_filename' because calling it
3578 may cause a temporary switch into the .debug_sfnames section and
3579 most svr4 assemblers are not smart enough to be able to nest
3580 section switches to any depth greater than one. Note that we
3581 also can't skirt this issue by delaying all output to the
3582 .debug_sfnames section unit the end of compilation because that
3583 would cause us to have inter-section forward references and
3584 Fred Fish sez that m68k/svr4 assemblers botch those. */
3586 ASM_OUTPUT_POP_SECTION (asm_out_file);
3587 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3588 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3590 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3592 #endif /* defined(DWARF_DECL_COORDINATES) */
3596 /* Many forms of DIEs contain a "type description" part. The following
3597 routine writes out these "type descriptor" parts. */
3599 static void
3600 type_attribute (type, decl_const, decl_volatile)
3601 tree type;
3602 int decl_const;
3603 int decl_volatile;
3605 enum tree_code code = TREE_CODE (type);
3606 int root_type_modified;
3608 if (code == ERROR_MARK)
3609 return;
3611 /* Handle a special case. For functions whose return type is void,
3612 we generate *no* type attribute. (Note that no object may have
3613 type `void', so this only applies to function return types. */
3615 if (code == VOID_TYPE)
3616 return;
3618 /* If this is a subtype, find the underlying type. Eventually,
3619 this should write out the appropriate subtype info. */
3620 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3621 && TREE_TYPE (type) != 0)
3622 type = TREE_TYPE (type), code = TREE_CODE (type);
3624 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3625 || decl_const || decl_volatile
3626 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3628 if (type_is_fundamental (root_type (type)))
3630 if (root_type_modified)
3631 mod_fund_type_attribute (type, decl_const, decl_volatile);
3632 else
3633 fund_type_attribute (fundamental_type_code (type));
3635 else
3637 if (root_type_modified)
3638 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3639 else
3640 /* We have to get the type_main_variant here (and pass that to the
3641 `user_def_type_attribute' routine) because the ..._TYPE node we
3642 have might simply be a *copy* of some original type node (where
3643 the copy was created to help us keep track of typedef names)
3644 and that copy might have a different TYPE_UID from the original
3645 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3646 is labeling a given type DIE for future reference, it always and
3647 only creates labels for DIEs representing *main variants*, and it
3648 never even knows about non-main-variants.) */
3649 user_def_type_attribute (type_main_variant (type));
3653 /* Given a tree pointer to a struct, class, union, or enum type node, return
3654 a pointer to the (string) tag name for the given type, or zero if the
3655 type was declared without a tag. */
3657 static const char *
3658 type_tag (type)
3659 tree type;
3661 const char *name = 0;
3663 if (TYPE_NAME (type) != 0)
3665 tree t = 0;
3667 /* Find the IDENTIFIER_NODE for the type name. */
3668 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3669 t = TYPE_NAME (type);
3671 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3672 a TYPE_DECL node, regardless of whether or not a `typedef' was
3673 involved. */
3674 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3675 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3676 t = DECL_NAME (TYPE_NAME (type));
3678 /* Now get the name as a string, or invent one. */
3679 if (t != 0)
3680 name = IDENTIFIER_POINTER (t);
3683 return (name == 0 || *name == '\0') ? 0 : name;
3686 static inline void
3687 dienum_push ()
3689 /* Start by checking if the pending_sibling_stack needs to be expanded.
3690 If necessary, expand it. */
3692 if (pending_siblings == pending_siblings_allocated)
3694 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3695 pending_sibling_stack
3696 = (unsigned *) xrealloc (pending_sibling_stack,
3697 pending_siblings_allocated * sizeof(unsigned));
3700 pending_siblings++;
3701 NEXT_DIE_NUM = next_unused_dienum++;
3704 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3705 NEXT_DIE_NUM. */
3707 static inline void
3708 dienum_pop ()
3710 pending_siblings--;
3713 static inline tree
3714 member_declared_type (member)
3715 tree member;
3717 return (DECL_BIT_FIELD_TYPE (member))
3718 ? DECL_BIT_FIELD_TYPE (member)
3719 : TREE_TYPE (member);
3722 /* Get the function's label, as described by its RTL.
3723 This may be different from the DECL_NAME name used
3724 in the source file. */
3726 static const char *
3727 function_start_label (decl)
3728 tree decl;
3730 rtx x;
3731 const char *fnname;
3733 x = DECL_RTL (decl);
3734 if (GET_CODE (x) != MEM)
3735 abort ();
3736 x = XEXP (x, 0);
3737 if (GET_CODE (x) != SYMBOL_REF)
3738 abort ();
3739 fnname = XSTR (x, 0);
3740 return fnname;
3744 /******************************* DIEs ************************************/
3746 /* Output routines for individual types of DIEs. */
3748 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3750 static void
3751 output_array_type_die (arg)
3752 void *arg;
3754 tree type = arg;
3756 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3757 sibling_attribute ();
3758 equate_type_number_to_die_number (type);
3759 member_attribute (TYPE_CONTEXT (type));
3761 /* I believe that we can default the array ordering. SDB will probably
3762 do the right things even if AT_ordering is not present. It's not
3763 even an issue until we start to get into multidimensional arrays
3764 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3765 dimensional arrays, then we'll have to put the AT_ordering attribute
3766 back in. (But if and when we find out that we need to put these in,
3767 we will only do so for multidimensional arrays. After all, we don't
3768 want to waste space in the .debug section now do we?) */
3770 #ifdef USE_ORDERING_ATTRIBUTE
3771 ordering_attribute (ORD_row_major);
3772 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3774 subscript_data_attribute (type);
3777 static void
3778 output_set_type_die (arg)
3779 void *arg;
3781 tree type = arg;
3783 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3784 sibling_attribute ();
3785 equate_type_number_to_die_number (type);
3786 member_attribute (TYPE_CONTEXT (type));
3787 type_attribute (TREE_TYPE (type), 0, 0);
3790 #if 0
3791 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3793 static void
3794 output_entry_point_die (arg)
3795 void *arg;
3797 tree decl = arg;
3798 tree origin = decl_ultimate_origin (decl);
3800 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3801 sibling_attribute ();
3802 dienum_push ();
3803 if (origin != NULL)
3804 abstract_origin_attribute (origin);
3805 else
3807 name_and_src_coords_attributes (decl);
3808 member_attribute (DECL_CONTEXT (decl));
3809 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3811 if (DECL_ABSTRACT (decl))
3812 equate_decl_number_to_die_number (decl);
3813 else
3814 low_pc_attribute (function_start_label (decl));
3816 #endif
3818 /* Output a DIE to represent an inlined instance of an enumeration type. */
3820 static void
3821 output_inlined_enumeration_type_die (arg)
3822 void *arg;
3824 tree type = arg;
3826 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3827 sibling_attribute ();
3828 if (!TREE_ASM_WRITTEN (type))
3829 abort ();
3830 abstract_origin_attribute (type);
3833 /* Output a DIE to represent an inlined instance of a structure type. */
3835 static void
3836 output_inlined_structure_type_die (arg)
3837 void *arg;
3839 tree type = arg;
3841 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3842 sibling_attribute ();
3843 if (!TREE_ASM_WRITTEN (type))
3844 abort ();
3845 abstract_origin_attribute (type);
3848 /* Output a DIE to represent an inlined instance of a union type. */
3850 static void
3851 output_inlined_union_type_die (arg)
3852 void *arg;
3854 tree type = arg;
3856 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3857 sibling_attribute ();
3858 if (!TREE_ASM_WRITTEN (type))
3859 abort ();
3860 abstract_origin_attribute (type);
3863 /* Output a DIE to represent an enumeration type. Note that these DIEs
3864 include all of the information about the enumeration values also.
3865 This information is encoded into the element_list attribute. */
3867 static void
3868 output_enumeration_type_die (arg)
3869 void *arg;
3871 tree type = arg;
3873 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3874 sibling_attribute ();
3875 equate_type_number_to_die_number (type);
3876 name_attribute (type_tag (type));
3877 member_attribute (TYPE_CONTEXT (type));
3879 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3880 given enum type is incomplete, do not generate the AT_byte_size
3881 attribute or the AT_element_list attribute. */
3883 if (COMPLETE_TYPE_P (type))
3885 byte_size_attribute (type);
3886 element_list_attribute (TYPE_FIELDS (type));
3890 /* Output a DIE to represent either a real live formal parameter decl or
3891 to represent just the type of some formal parameter position in some
3892 function type.
3894 Note that this routine is a bit unusual because its argument may be
3895 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3896 represents an inlining of some PARM_DECL) or else some sort of a
3897 ..._TYPE node. If it's the former then this function is being called
3898 to output a DIE to represent a formal parameter object (or some inlining
3899 thereof). If it's the latter, then this function is only being called
3900 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3901 formal argument type of some subprogram type. */
3903 static void
3904 output_formal_parameter_die (arg)
3905 void *arg;
3907 tree node = arg;
3909 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3910 sibling_attribute ();
3912 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3914 case 'd': /* We were called with some kind of a ..._DECL node. */
3916 register tree origin = decl_ultimate_origin (node);
3918 if (origin != NULL)
3919 abstract_origin_attribute (origin);
3920 else
3922 name_and_src_coords_attributes (node);
3923 type_attribute (TREE_TYPE (node),
3924 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3926 if (DECL_ABSTRACT (node))
3927 equate_decl_number_to_die_number (node);
3928 else
3929 location_or_const_value_attribute (node);
3931 break;
3933 case 't': /* We were called with some kind of a ..._TYPE node. */
3934 type_attribute (node, 0, 0);
3935 break;
3937 default:
3938 abort (); /* Should never happen. */
3942 /* Output a DIE to represent a declared function (either file-scope
3943 or block-local) which has "external linkage" (according to ANSI-C). */
3945 static void
3946 output_global_subroutine_die (arg)
3947 void *arg;
3949 tree decl = arg;
3950 tree origin = decl_ultimate_origin (decl);
3952 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3953 sibling_attribute ();
3954 dienum_push ();
3955 if (origin != NULL)
3956 abstract_origin_attribute (origin);
3957 else
3959 tree type = TREE_TYPE (decl);
3961 name_and_src_coords_attributes (decl);
3962 inline_attribute (decl);
3963 prototyped_attribute (type);
3964 member_attribute (DECL_CONTEXT (decl));
3965 type_attribute (TREE_TYPE (type), 0, 0);
3966 pure_or_virtual_attribute (decl);
3968 if (DECL_ABSTRACT (decl))
3969 equate_decl_number_to_die_number (decl);
3970 else
3972 if (! DECL_EXTERNAL (decl) && ! in_class
3973 && decl == current_function_decl)
3975 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3977 low_pc_attribute (function_start_label (decl));
3978 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3979 high_pc_attribute (label);
3980 if (use_gnu_debug_info_extensions)
3982 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3983 body_begin_attribute (label);
3984 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3985 body_end_attribute (label);
3991 /* Output a DIE to represent a declared data object (either file-scope
3992 or block-local) which has "external linkage" (according to ANSI-C). */
3994 static void
3995 output_global_variable_die (arg)
3996 void *arg;
3998 tree decl = arg;
3999 tree origin = decl_ultimate_origin (decl);
4001 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
4002 sibling_attribute ();
4003 if (origin != NULL)
4004 abstract_origin_attribute (origin);
4005 else
4007 name_and_src_coords_attributes (decl);
4008 member_attribute (DECL_CONTEXT (decl));
4009 type_attribute (TREE_TYPE (decl),
4010 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4012 if (DECL_ABSTRACT (decl))
4013 equate_decl_number_to_die_number (decl);
4014 else
4016 if (! DECL_EXTERNAL (decl) && ! in_class
4017 && current_function_decl == decl_function_context (decl))
4018 location_or_const_value_attribute (decl);
4022 static void
4023 output_label_die (arg)
4024 void *arg;
4026 tree decl = arg;
4027 tree origin = decl_ultimate_origin (decl);
4029 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
4030 sibling_attribute ();
4031 if (origin != NULL)
4032 abstract_origin_attribute (origin);
4033 else
4034 name_and_src_coords_attributes (decl);
4035 if (DECL_ABSTRACT (decl))
4036 equate_decl_number_to_die_number (decl);
4037 else
4039 rtx insn = DECL_RTL (decl);
4041 /* Deleted labels are programmer specified labels which have been
4042 eliminated because of various optimisations. We still emit them
4043 here so that it is possible to put breakpoints on them. */
4044 if (GET_CODE (insn) == CODE_LABEL
4045 || ((GET_CODE (insn) == NOTE
4046 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
4048 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4050 /* When optimization is enabled (via -O) some parts of the compiler
4051 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
4052 represent source-level labels which were explicitly declared by
4053 the user. This really shouldn't be happening though, so catch
4054 it if it ever does happen. */
4056 if (INSN_DELETED_P (insn))
4057 abort (); /* Should never happen. */
4059 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
4060 low_pc_attribute (label);
4065 static void
4066 output_lexical_block_die (arg)
4067 void *arg;
4069 tree stmt = arg;
4071 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
4072 sibling_attribute ();
4073 dienum_push ();
4074 if (! BLOCK_ABSTRACT (stmt))
4076 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4077 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4079 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4080 low_pc_attribute (begin_label);
4081 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4082 high_pc_attribute (end_label);
4086 static void
4087 output_inlined_subroutine_die (arg)
4088 void *arg;
4090 tree stmt = arg;
4092 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
4093 sibling_attribute ();
4094 dienum_push ();
4095 abstract_origin_attribute (block_ultimate_origin (stmt));
4096 if (! BLOCK_ABSTRACT (stmt))
4098 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4099 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4101 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4102 low_pc_attribute (begin_label);
4103 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4104 high_pc_attribute (end_label);
4108 /* Output a DIE to represent a declared data object (either file-scope
4109 or block-local) which has "internal linkage" (according to ANSI-C). */
4111 static void
4112 output_local_variable_die (arg)
4113 void *arg;
4115 tree decl = arg;
4116 tree origin = decl_ultimate_origin (decl);
4118 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
4119 sibling_attribute ();
4120 if (origin != NULL)
4121 abstract_origin_attribute (origin);
4122 else
4124 name_and_src_coords_attributes (decl);
4125 member_attribute (DECL_CONTEXT (decl));
4126 type_attribute (TREE_TYPE (decl),
4127 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4129 if (DECL_ABSTRACT (decl))
4130 equate_decl_number_to_die_number (decl);
4131 else
4132 location_or_const_value_attribute (decl);
4135 static void
4136 output_member_die (arg)
4137 void *arg;
4139 tree decl = arg;
4141 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
4142 sibling_attribute ();
4143 name_and_src_coords_attributes (decl);
4144 member_attribute (DECL_CONTEXT (decl));
4145 type_attribute (member_declared_type (decl),
4146 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4147 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
4149 byte_size_attribute (decl);
4150 bit_size_attribute (decl);
4151 bit_offset_attribute (decl);
4153 data_member_location_attribute (decl);
4156 #if 0
4157 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
4158 modified types instead.
4160 We keep this code here just in case these types of DIEs may be
4161 needed to represent certain things in other languages (e.g. Pascal)
4162 someday. */
4164 static void
4165 output_pointer_type_die (arg)
4166 void *arg;
4168 tree type = arg;
4170 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
4171 sibling_attribute ();
4172 equate_type_number_to_die_number (type);
4173 member_attribute (TYPE_CONTEXT (type));
4174 type_attribute (TREE_TYPE (type), 0, 0);
4177 static void
4178 output_reference_type_die (arg)
4179 void *arg;
4181 tree type = arg;
4183 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
4184 sibling_attribute ();
4185 equate_type_number_to_die_number (type);
4186 member_attribute (TYPE_CONTEXT (type));
4187 type_attribute (TREE_TYPE (type), 0, 0);
4189 #endif
4191 static void
4192 output_ptr_to_mbr_type_die (arg)
4193 void *arg;
4195 tree type = arg;
4197 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
4198 sibling_attribute ();
4199 equate_type_number_to_die_number (type);
4200 member_attribute (TYPE_CONTEXT (type));
4201 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
4202 type_attribute (TREE_TYPE (type), 0, 0);
4205 static void
4206 output_compile_unit_die (arg)
4207 void *arg;
4209 const char *main_input_filename = arg;
4210 const char *language_string = lang_hooks.name;
4212 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
4213 sibling_attribute ();
4214 dienum_push ();
4215 name_attribute (main_input_filename);
4218 char producer[250];
4220 sprintf (producer, "%s %s", language_string, version_string);
4221 producer_attribute (producer);
4224 if (strcmp (language_string, "GNU C++") == 0)
4225 language_attribute (LANG_C_PLUS_PLUS);
4226 else if (strcmp (language_string, "GNU Ada") == 0)
4227 language_attribute (LANG_ADA83);
4228 else if (strcmp (language_string, "GNU F77") == 0)
4229 language_attribute (LANG_FORTRAN77);
4230 else if (strcmp (language_string, "GNU Pascal") == 0)
4231 language_attribute (LANG_PASCAL83);
4232 else if (strcmp (language_string, "GNU Java") == 0)
4233 language_attribute (LANG_JAVA);
4234 else if (flag_traditional)
4235 language_attribute (LANG_C);
4236 else
4237 language_attribute (LANG_C89);
4238 low_pc_attribute (TEXT_BEGIN_LABEL);
4239 high_pc_attribute (TEXT_END_LABEL);
4240 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4241 stmt_list_attribute (LINE_BEGIN_LABEL);
4242 last_filename = xstrdup (main_input_filename);
4245 const char *wd = getpwd ();
4246 if (wd)
4247 comp_dir_attribute (wd);
4250 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
4252 sf_names_attribute (SFNAMES_BEGIN_LABEL);
4253 src_info_attribute (SRCINFO_BEGIN_LABEL);
4254 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4255 mac_info_attribute (MACINFO_BEGIN_LABEL);
4259 static void
4260 output_string_type_die (arg)
4261 void *arg;
4263 tree type = arg;
4265 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
4266 sibling_attribute ();
4267 equate_type_number_to_die_number (type);
4268 member_attribute (TYPE_CONTEXT (type));
4269 /* this is a fixed length string */
4270 byte_size_attribute (type);
4273 static void
4274 output_inheritance_die (arg)
4275 void *arg;
4277 tree binfo = arg;
4279 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
4280 sibling_attribute ();
4281 type_attribute (BINFO_TYPE (binfo), 0, 0);
4282 data_member_location_attribute (binfo);
4283 if (TREE_VIA_VIRTUAL (binfo))
4285 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
4286 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4288 if (TREE_VIA_PUBLIC (binfo))
4290 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
4291 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4293 else if (TREE_VIA_PROTECTED (binfo))
4295 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
4296 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4300 static void
4301 output_structure_type_die (arg)
4302 void *arg;
4304 tree type = arg;
4306 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
4307 sibling_attribute ();
4308 equate_type_number_to_die_number (type);
4309 name_attribute (type_tag (type));
4310 member_attribute (TYPE_CONTEXT (type));
4312 /* If this type has been completed, then give it a byte_size attribute
4313 and prepare to give a list of members. Otherwise, don't do either of
4314 these things. In the latter case, we will not be generating a list
4315 of members (since we don't have any idea what they might be for an
4316 incomplete type). */
4318 if (COMPLETE_TYPE_P (type))
4320 dienum_push ();
4321 byte_size_attribute (type);
4325 /* Output a DIE to represent a declared function (either file-scope
4326 or block-local) which has "internal linkage" (according to ANSI-C). */
4328 static void
4329 output_local_subroutine_die (arg)
4330 void *arg;
4332 tree decl = arg;
4333 tree origin = decl_ultimate_origin (decl);
4335 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
4336 sibling_attribute ();
4337 dienum_push ();
4338 if (origin != NULL)
4339 abstract_origin_attribute (origin);
4340 else
4342 tree type = TREE_TYPE (decl);
4344 name_and_src_coords_attributes (decl);
4345 inline_attribute (decl);
4346 prototyped_attribute (type);
4347 member_attribute (DECL_CONTEXT (decl));
4348 type_attribute (TREE_TYPE (type), 0, 0);
4349 pure_or_virtual_attribute (decl);
4351 if (DECL_ABSTRACT (decl))
4352 equate_decl_number_to_die_number (decl);
4353 else
4355 /* Avoid getting screwed up in cases where a function was declared
4356 static but where no definition was ever given for it. */
4358 if (TREE_ASM_WRITTEN (decl))
4360 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4361 low_pc_attribute (function_start_label (decl));
4362 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4363 high_pc_attribute (label);
4364 if (use_gnu_debug_info_extensions)
4366 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
4367 body_begin_attribute (label);
4368 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
4369 body_end_attribute (label);
4375 static void
4376 output_subroutine_type_die (arg)
4377 void *arg;
4379 tree type = arg;
4380 tree return_type = TREE_TYPE (type);
4382 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
4383 sibling_attribute ();
4384 dienum_push ();
4385 equate_type_number_to_die_number (type);
4386 prototyped_attribute (type);
4387 member_attribute (TYPE_CONTEXT (type));
4388 type_attribute (return_type, 0, 0);
4391 static void
4392 output_typedef_die (arg)
4393 void *arg;
4395 tree decl = arg;
4396 tree origin = decl_ultimate_origin (decl);
4398 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
4399 sibling_attribute ();
4400 if (origin != NULL)
4401 abstract_origin_attribute (origin);
4402 else
4404 name_and_src_coords_attributes (decl);
4405 member_attribute (DECL_CONTEXT (decl));
4406 type_attribute (TREE_TYPE (decl),
4407 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4409 if (DECL_ABSTRACT (decl))
4410 equate_decl_number_to_die_number (decl);
4413 static void
4414 output_union_type_die (arg)
4415 void *arg;
4417 tree type = arg;
4419 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
4420 sibling_attribute ();
4421 equate_type_number_to_die_number (type);
4422 name_attribute (type_tag (type));
4423 member_attribute (TYPE_CONTEXT (type));
4425 /* If this type has been completed, then give it a byte_size attribute
4426 and prepare to give a list of members. Otherwise, don't do either of
4427 these things. In the latter case, we will not be generating a list
4428 of members (since we don't have any idea what they might be for an
4429 incomplete type). */
4431 if (COMPLETE_TYPE_P (type))
4433 dienum_push ();
4434 byte_size_attribute (type);
4438 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
4439 at the end of an (ANSI prototyped) formal parameters list. */
4441 static void
4442 output_unspecified_parameters_die (arg)
4443 void *arg;
4445 tree decl_or_type = arg;
4447 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
4448 sibling_attribute ();
4450 /* This kludge is here only for the sake of being compatible with what
4451 the USL CI5 C compiler does. The specification of Dwarf Version 1
4452 doesn't say that TAG_unspecified_parameters DIEs should contain any
4453 attributes other than the AT_sibling attribute, but they are certainly
4454 allowed to contain additional attributes, and the CI5 compiler
4455 generates AT_name, AT_fund_type, and AT_location attributes within
4456 TAG_unspecified_parameters DIEs which appear in the child lists for
4457 DIEs representing function definitions, so we do likewise here. */
4459 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
4461 name_attribute ("...");
4462 fund_type_attribute (FT_pointer);
4463 /* location_attribute (?); */
4467 static void
4468 output_padded_null_die (arg)
4469 void *arg ATTRIBUTE_UNUSED;
4471 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
4474 /*************************** end of DIEs *********************************/
4476 /* Generate some type of DIE. This routine generates the generic outer
4477 wrapper stuff which goes around all types of DIE's (regardless of their
4478 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
4479 DIE-length word, followed by the guts of the DIE itself. After the guts
4480 of the DIE, there must always be a terminator label for the DIE. */
4482 static void
4483 output_die (die_specific_output_function, param)
4484 void (*die_specific_output_function) PARAMS ((void *));
4485 void *param;
4487 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4488 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4490 current_dienum = NEXT_DIE_NUM;
4491 NEXT_DIE_NUM = next_unused_dienum;
4493 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4494 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4496 /* Write a label which will act as the name for the start of this DIE. */
4498 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4500 /* Write the DIE-length word. */
4502 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4504 /* Fill in the guts of the DIE. */
4506 next_unused_dienum++;
4507 die_specific_output_function (param);
4509 /* Write a label which will act as the name for the end of this DIE. */
4511 ASM_OUTPUT_LABEL (asm_out_file, end_label);
4514 static void
4515 end_sibling_chain ()
4517 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4519 current_dienum = NEXT_DIE_NUM;
4520 NEXT_DIE_NUM = next_unused_dienum;
4522 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4524 /* Write a label which will act as the name for the start of this DIE. */
4526 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4528 /* Write the DIE-length word. */
4530 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4532 dienum_pop ();
4535 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4536 TAG_unspecified_parameters DIE) to represent the types of the formal
4537 parameters as specified in some function type specification (except
4538 for those which appear as part of a function *definition*).
4540 Note that we must be careful here to output all of the parameter
4541 DIEs *before* we output any DIEs needed to represent the types of
4542 the formal parameters. This keeps svr4 SDB happy because it
4543 (incorrectly) thinks that the first non-parameter DIE it sees ends
4544 the formal parameter list. */
4546 static void
4547 output_formal_types (function_or_method_type)
4548 tree function_or_method_type;
4550 tree link;
4551 tree formal_type = NULL;
4552 tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4554 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4555 get bogus recursion when outputting tagged types local to a
4556 function declaration. */
4557 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4558 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4560 /* In the case where we are generating a formal types list for a C++
4561 non-static member function type, skip over the first thing on the
4562 TYPE_ARG_TYPES list because it only represents the type of the
4563 hidden `this pointer'. The debugger should be able to figure
4564 out (without being explicitly told) that this non-static member
4565 function type takes a `this pointer' and should be able to figure
4566 what the type of that hidden parameter is from the AT_member
4567 attribute of the parent TAG_subroutine_type DIE. */
4569 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4570 first_parm_type = TREE_CHAIN (first_parm_type);
4572 /* Make our first pass over the list of formal parameter types and output
4573 a TAG_formal_parameter DIE for each one. */
4575 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4577 formal_type = TREE_VALUE (link);
4578 if (formal_type == void_type_node)
4579 break;
4581 /* Output a (nameless) DIE to represent the formal parameter itself. */
4583 output_die (output_formal_parameter_die, formal_type);
4586 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4587 DIE to the end of the parameter list. */
4589 if (formal_type != void_type_node)
4590 output_die (output_unspecified_parameters_die, function_or_method_type);
4592 /* Make our second (and final) pass over the list of formal parameter types
4593 and output DIEs to represent those types (as necessary). */
4595 for (link = TYPE_ARG_TYPES (function_or_method_type);
4596 link;
4597 link = TREE_CHAIN (link))
4599 formal_type = TREE_VALUE (link);
4600 if (formal_type == void_type_node)
4601 break;
4603 output_type (formal_type, function_or_method_type);
4606 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4609 /* Remember a type in the pending_types_list. */
4611 static void
4612 pend_type (type)
4613 tree type;
4615 if (pending_types == pending_types_allocated)
4617 pending_types_allocated += PENDING_TYPES_INCREMENT;
4618 pending_types_list
4619 = (tree *) xrealloc (pending_types_list,
4620 sizeof (tree) * pending_types_allocated);
4622 pending_types_list[pending_types++] = type;
4624 /* Mark the pending type as having been output already (even though
4625 it hasn't been). This prevents the type from being added to the
4626 pending_types_list more than once. */
4628 TREE_ASM_WRITTEN (type) = 1;
4631 /* Return non-zero if it is legitimate to output DIEs to represent a
4632 given type while we are generating the list of child DIEs for some
4633 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4635 See the comments within the function for a description of when it is
4636 considered legitimate to output DIEs for various kinds of types.
4638 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4639 or it may point to a BLOCK node (for types local to a block), or to a
4640 FUNCTION_DECL node (for types local to the heading of some function
4641 definition), or to a FUNCTION_TYPE node (for types local to the
4642 prototyped parameter list of a function type specification), or to a
4643 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4644 (in the case of C++ nested types).
4646 The `scope' parameter should likewise be NULL or should point to a
4647 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4648 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4650 This function is used only for deciding when to "pend" and when to
4651 "un-pend" types to/from the pending_types_list.
4653 Note that we sometimes make use of this "type pending" feature in a
4654 rather twisted way to temporarily delay the production of DIEs for the
4655 types of formal parameters. (We do this just to make svr4 SDB happy.)
4656 It order to delay the production of DIEs representing types of formal
4657 parameters, callers of this function supply `fake_containing_scope' as
4658 the `scope' parameter to this function. Given that fake_containing_scope
4659 is a tagged type which is *not* the containing scope for *any* other type,
4660 the desired effect is achieved, i.e. output of DIEs representing types
4661 is temporarily suspended, and any type DIEs which would have otherwise
4662 been output are instead placed onto the pending_types_list. Later on,
4663 we force these (temporarily pended) types to be output simply by calling
4664 `output_pending_types_for_scope' with an actual argument equal to the
4665 true scope of the types we temporarily pended. */
4667 static inline int
4668 type_ok_for_scope (type, scope)
4669 tree type;
4670 tree scope;
4672 /* Tagged types (i.e. struct, union, and enum types) must always be
4673 output only in the scopes where they actually belong (or else the
4674 scoping of their own tag names and the scoping of their member
4675 names will be incorrect). Non-tagged-types on the other hand can
4676 generally be output anywhere, except that svr4 SDB really doesn't
4677 want to see them nested within struct or union types, so here we
4678 say it is always OK to immediately output any such a (non-tagged)
4679 type, so long as we are not within such a context. Note that the
4680 only kinds of non-tagged types which we will be dealing with here
4681 (for C and C++ anyway) will be array types and function types. */
4683 return is_tagged_type (type)
4684 ? (TYPE_CONTEXT (type) == scope
4685 /* Ignore namespaces for the moment. */
4686 || (scope == NULL_TREE
4687 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4688 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4689 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4690 : (scope == NULL_TREE || ! is_tagged_type (scope));
4693 /* Output any pending types (from the pending_types list) which we can output
4694 now (taking into account the scope that we are working on now).
4696 For each type output, remove the given type from the pending_types_list
4697 *before* we try to output it.
4699 Note that we have to process the list in beginning-to-end order,
4700 because the call made here to output_type may cause yet more types
4701 to be added to the end of the list, and we may have to output some
4702 of them too. */
4704 static void
4705 output_pending_types_for_scope (containing_scope)
4706 tree containing_scope;
4708 unsigned i;
4710 for (i = 0; i < pending_types; )
4712 tree type = pending_types_list[i];
4714 if (type_ok_for_scope (type, containing_scope))
4716 tree *mover;
4717 tree *limit;
4719 pending_types--;
4720 limit = &pending_types_list[pending_types];
4721 for (mover = &pending_types_list[i]; mover < limit; mover++)
4722 *mover = *(mover+1);
4724 /* Un-mark the type as having been output already (because it
4725 hasn't been, really). Then call output_type to generate a
4726 Dwarf representation of it. */
4728 TREE_ASM_WRITTEN (type) = 0;
4729 output_type (type, containing_scope);
4731 /* Don't increment the loop counter in this case because we
4732 have shifted all of the subsequent pending types down one
4733 element in the pending_types_list array. */
4735 else
4736 i++;
4740 /* Remember a type in the incomplete_types_list. */
4742 static void
4743 add_incomplete_type (type)
4744 tree type;
4746 if (incomplete_types == incomplete_types_allocated)
4748 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4749 incomplete_types_list
4750 = (tree *) xrealloc (incomplete_types_list,
4751 sizeof (tree) * incomplete_types_allocated);
4754 incomplete_types_list[incomplete_types++] = type;
4757 /* Walk through the list of incomplete types again, trying once more to
4758 emit full debugging info for them. */
4760 static void
4761 retry_incomplete_types ()
4763 tree type;
4765 finalizing = 1;
4766 while (incomplete_types)
4768 --incomplete_types;
4769 type = incomplete_types_list[incomplete_types];
4770 output_type (type, NULL_TREE);
4774 static void
4775 output_type (type, containing_scope)
4776 tree type;
4777 tree containing_scope;
4779 if (type == 0 || type == error_mark_node)
4780 return;
4782 /* We are going to output a DIE to represent the unqualified version of
4783 this type (i.e. without any const or volatile qualifiers) so get
4784 the main variant (i.e. the unqualified version) of this type now. */
4786 type = type_main_variant (type);
4788 if (TREE_ASM_WRITTEN (type))
4790 if (finalizing && AGGREGATE_TYPE_P (type))
4792 tree member;
4794 /* Some of our nested types might not have been defined when we
4795 were written out before; force them out now. */
4797 for (member = TYPE_FIELDS (type); member;
4798 member = TREE_CHAIN (member))
4799 if (TREE_CODE (member) == TYPE_DECL
4800 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4801 output_type (TREE_TYPE (member), containing_scope);
4803 return;
4806 /* If this is a nested type whose containing class hasn't been
4807 written out yet, writing it out will cover this one, too. */
4809 if (TYPE_CONTEXT (type)
4810 && TYPE_P (TYPE_CONTEXT (type))
4811 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4813 output_type (TYPE_CONTEXT (type), containing_scope);
4814 return;
4817 /* Don't generate any DIEs for this type now unless it is OK to do so
4818 (based upon what `type_ok_for_scope' tells us). */
4820 if (! type_ok_for_scope (type, containing_scope))
4822 pend_type (type);
4823 return;
4826 switch (TREE_CODE (type))
4828 case ERROR_MARK:
4829 break;
4831 case VECTOR_TYPE:
4832 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4833 break;
4835 case POINTER_TYPE:
4836 case REFERENCE_TYPE:
4837 /* Prevent infinite recursion in cases where this is a recursive
4838 type. Recursive types are possible in Ada. */
4839 TREE_ASM_WRITTEN (type) = 1;
4840 /* For these types, all that is required is that we output a DIE
4841 (or a set of DIEs) to represent the "basis" type. */
4842 output_type (TREE_TYPE (type), containing_scope);
4843 break;
4845 case OFFSET_TYPE:
4846 /* This code is used for C++ pointer-to-data-member types. */
4847 /* Output a description of the relevant class type. */
4848 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4849 /* Output a description of the type of the object pointed to. */
4850 output_type (TREE_TYPE (type), containing_scope);
4851 /* Now output a DIE to represent this pointer-to-data-member type
4852 itself. */
4853 output_die (output_ptr_to_mbr_type_die, type);
4854 break;
4856 case SET_TYPE:
4857 output_type (TYPE_DOMAIN (type), containing_scope);
4858 output_die (output_set_type_die, type);
4859 break;
4861 case FILE_TYPE:
4862 output_type (TREE_TYPE (type), containing_scope);
4863 abort (); /* No way to represent these in Dwarf yet! */
4864 break;
4866 case FUNCTION_TYPE:
4867 /* Force out return type (in case it wasn't forced out already). */
4868 output_type (TREE_TYPE (type), containing_scope);
4869 output_die (output_subroutine_type_die, type);
4870 output_formal_types (type);
4871 end_sibling_chain ();
4872 break;
4874 case METHOD_TYPE:
4875 /* Force out return type (in case it wasn't forced out already). */
4876 output_type (TREE_TYPE (type), containing_scope);
4877 output_die (output_subroutine_type_die, type);
4878 output_formal_types (type);
4879 end_sibling_chain ();
4880 break;
4882 case ARRAY_TYPE:
4883 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4885 output_type (TREE_TYPE (type), containing_scope);
4886 output_die (output_string_type_die, type);
4888 else
4890 tree element_type;
4892 element_type = TREE_TYPE (type);
4893 while (TREE_CODE (element_type) == ARRAY_TYPE)
4894 element_type = TREE_TYPE (element_type);
4896 output_type (element_type, containing_scope);
4897 output_die (output_array_type_die, type);
4899 break;
4901 case ENUMERAL_TYPE:
4902 case RECORD_TYPE:
4903 case UNION_TYPE:
4904 case QUAL_UNION_TYPE:
4906 /* For a non-file-scope tagged type, we can always go ahead and
4907 output a Dwarf description of this type right now, even if
4908 the type in question is still incomplete, because if this
4909 local type *was* ever completed anywhere within its scope,
4910 that complete definition would already have been attached to
4911 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4912 node by the time we reach this point. That's true because of the
4913 way the front-end does its processing of file-scope declarations (of
4914 functions and class types) within which other types might be
4915 nested. The C and C++ front-ends always gobble up such "local
4916 scope" things en-mass before they try to output *any* debugging
4917 information for any of the stuff contained inside them and thus,
4918 we get the benefit here of what is (in effect) a pre-resolution
4919 of forward references to tagged types in local scopes.
4921 Note however that for file-scope tagged types we cannot assume
4922 that such pre-resolution of forward references has taken place.
4923 A given file-scope tagged type may appear to be incomplete when
4924 we reach this point, but it may yet be given a full definition
4925 (at file-scope) later on during compilation. In order to avoid
4926 generating a premature (and possibly incorrect) set of Dwarf
4927 DIEs for such (as yet incomplete) file-scope tagged types, we
4928 generate nothing at all for as-yet incomplete file-scope tagged
4929 types here unless we are making our special "finalization" pass
4930 for file-scope things at the very end of compilation. At that
4931 time, we will certainly know as much about each file-scope tagged
4932 type as we are ever going to know, so at that point in time, we
4933 can safely generate correct Dwarf descriptions for these file-
4934 scope tagged types. */
4936 if (!COMPLETE_TYPE_P (type)
4937 && (TYPE_CONTEXT (type) == NULL
4938 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4939 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4940 && !finalizing)
4942 /* We don't need to do this for function-local types. */
4943 if (! decl_function_context (TYPE_STUB_DECL (type)))
4944 add_incomplete_type (type);
4945 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4948 /* Prevent infinite recursion in cases where the type of some
4949 member of this type is expressed in terms of this type itself. */
4951 TREE_ASM_WRITTEN (type) = 1;
4953 /* Output a DIE to represent the tagged type itself. */
4955 switch (TREE_CODE (type))
4957 case ENUMERAL_TYPE:
4958 output_die (output_enumeration_type_die, type);
4959 return; /* a special case -- nothing left to do so just return */
4961 case RECORD_TYPE:
4962 output_die (output_structure_type_die, type);
4963 break;
4965 case UNION_TYPE:
4966 case QUAL_UNION_TYPE:
4967 output_die (output_union_type_die, type);
4968 break;
4970 default:
4971 abort (); /* Should never happen. */
4974 /* If this is not an incomplete type, output descriptions of
4975 each of its members.
4977 Note that as we output the DIEs necessary to represent the
4978 members of this record or union type, we will also be trying
4979 to output DIEs to represent the *types* of those members.
4980 However the `output_type' function (above) will specifically
4981 avoid generating type DIEs for member types *within* the list
4982 of member DIEs for this (containing) type except for those
4983 types (of members) which are explicitly marked as also being
4984 members of this (containing) type themselves. The g++ front-
4985 end can force any given type to be treated as a member of some
4986 other (containing) type by setting the TYPE_CONTEXT of the
4987 given (member) type to point to the TREE node representing the
4988 appropriate (containing) type.
4991 if (COMPLETE_TYPE_P (type))
4993 /* First output info about the base classes. */
4994 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4996 register tree bases = TYPE_BINFO_BASETYPES (type);
4997 register int n_bases = TREE_VEC_LENGTH (bases);
4998 register int i;
5000 for (i = 0; i < n_bases; i++)
5002 tree binfo = TREE_VEC_ELT (bases, i);
5003 output_type (BINFO_TYPE (binfo), containing_scope);
5004 output_die (output_inheritance_die, binfo);
5008 ++in_class;
5011 tree normal_member;
5013 /* Now output info about the data members and type members. */
5015 for (normal_member = TYPE_FIELDS (type);
5016 normal_member;
5017 normal_member = TREE_CHAIN (normal_member))
5018 output_decl (normal_member, type);
5022 tree func_member;
5024 /* Now output info about the function members (if any). */
5026 for (func_member = TYPE_METHODS (type);
5027 func_member;
5028 func_member = TREE_CHAIN (func_member))
5030 /* Don't include clones in the member list. */
5031 if (DECL_ABSTRACT_ORIGIN (func_member))
5032 continue;
5034 output_decl (func_member, type);
5038 --in_class;
5040 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
5041 scopes (at least in C++) so we must now output any nested
5042 pending types which are local just to this type. */
5044 output_pending_types_for_scope (type);
5046 end_sibling_chain (); /* Terminate member chain. */
5049 break;
5051 case VOID_TYPE:
5052 case INTEGER_TYPE:
5053 case REAL_TYPE:
5054 case COMPLEX_TYPE:
5055 case BOOLEAN_TYPE:
5056 case CHAR_TYPE:
5057 break; /* No DIEs needed for fundamental types. */
5059 case LANG_TYPE: /* No Dwarf representation currently defined. */
5060 break;
5062 default:
5063 abort ();
5066 TREE_ASM_WRITTEN (type) = 1;
5069 static void
5070 output_tagged_type_instantiation (type)
5071 tree type;
5073 if (type == 0 || type == error_mark_node)
5074 return;
5076 /* We are going to output a DIE to represent the unqualified version of
5077 this type (i.e. without any const or volatile qualifiers) so make
5078 sure that we have the main variant (i.e. the unqualified version) of
5079 this type now. */
5081 if (type != type_main_variant (type))
5082 abort ();
5084 if (!TREE_ASM_WRITTEN (type))
5085 abort ();
5087 switch (TREE_CODE (type))
5089 case ERROR_MARK:
5090 break;
5092 case ENUMERAL_TYPE:
5093 output_die (output_inlined_enumeration_type_die, type);
5094 break;
5096 case RECORD_TYPE:
5097 output_die (output_inlined_structure_type_die, type);
5098 break;
5100 case UNION_TYPE:
5101 case QUAL_UNION_TYPE:
5102 output_die (output_inlined_union_type_die, type);
5103 break;
5105 default:
5106 abort (); /* Should never happen. */
5110 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
5111 the things which are local to the given block. */
5113 static void
5114 output_block (stmt, depth)
5115 tree stmt;
5116 int depth;
5118 int must_output_die = 0;
5119 tree origin;
5120 enum tree_code origin_code;
5122 /* Ignore blocks never really used to make RTL. */
5124 if (! stmt || ! TREE_USED (stmt)
5125 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
5126 return;
5128 /* Determine the "ultimate origin" of this block. This block may be an
5129 inlined instance of an inlined instance of inline function, so we
5130 have to trace all of the way back through the origin chain to find
5131 out what sort of node actually served as the original seed for the
5132 creation of the current block. */
5134 origin = block_ultimate_origin (stmt);
5135 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
5137 /* Determine if we need to output any Dwarf DIEs at all to represent this
5138 block. */
5140 if (origin_code == FUNCTION_DECL)
5141 /* The outer scopes for inlinings *must* always be represented. We
5142 generate TAG_inlined_subroutine DIEs for them. (See below.) */
5143 must_output_die = 1;
5144 else
5146 /* In the case where the current block represents an inlining of the
5147 "body block" of an inline function, we must *NOT* output any DIE
5148 for this block because we have already output a DIE to represent
5149 the whole inlined function scope and the "body block" of any
5150 function doesn't really represent a different scope according to
5151 ANSI C rules. So we check here to make sure that this block does
5152 not represent a "body block inlining" before trying to set the
5153 `must_output_die' flag. */
5155 if (! is_body_block (origin ? origin : stmt))
5157 /* Determine if this block directly contains any "significant"
5158 local declarations which we will need to output DIEs for. */
5160 if (debug_info_level > DINFO_LEVEL_TERSE)
5161 /* We are not in terse mode so *any* local declaration counts
5162 as being a "significant" one. */
5163 must_output_die = (BLOCK_VARS (stmt) != NULL);
5164 else
5166 tree decl;
5168 /* We are in terse mode, so only local (nested) function
5169 definitions count as "significant" local declarations. */
5171 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5172 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
5174 must_output_die = 1;
5175 break;
5181 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
5182 DIE for any block which contains no significant local declarations
5183 at all. Rather, in such cases we just call `output_decls_for_scope'
5184 so that any needed Dwarf info for any sub-blocks will get properly
5185 generated. Note that in terse mode, our definition of what constitutes
5186 a "significant" local declaration gets restricted to include only
5187 inlined function instances and local (nested) function definitions. */
5189 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
5190 /* We don't care about an abstract inlined subroutine. */;
5191 else if (must_output_die)
5193 output_die ((origin_code == FUNCTION_DECL)
5194 ? output_inlined_subroutine_die
5195 : output_lexical_block_die,
5196 stmt);
5197 output_decls_for_scope (stmt, depth);
5198 end_sibling_chain ();
5200 else
5201 output_decls_for_scope (stmt, depth);
5204 /* Output all of the decls declared within a given scope (also called
5205 a `binding contour') and (recursively) all of it's sub-blocks. */
5207 static void
5208 output_decls_for_scope (stmt, depth)
5209 tree stmt;
5210 int depth;
5212 /* Ignore blocks never really used to make RTL. */
5214 if (! stmt || ! TREE_USED (stmt))
5215 return;
5217 /* Output the DIEs to represent all of the data objects, functions,
5218 typedefs, and tagged types declared directly within this block
5219 but not within any nested sub-blocks. */
5222 tree decl;
5224 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5225 output_decl (decl, stmt);
5228 output_pending_types_for_scope (stmt);
5230 /* Output the DIEs to represent all sub-blocks (and the items declared
5231 therein) of this block. */
5234 tree subblocks;
5236 for (subblocks = BLOCK_SUBBLOCKS (stmt);
5237 subblocks;
5238 subblocks = BLOCK_CHAIN (subblocks))
5239 output_block (subblocks, depth + 1);
5243 /* Is this a typedef we can avoid emitting? */
5245 static inline int
5246 is_redundant_typedef (decl)
5247 tree decl;
5249 if (TYPE_DECL_IS_STUB (decl))
5250 return 1;
5251 if (DECL_ARTIFICIAL (decl)
5252 && DECL_CONTEXT (decl)
5253 && is_tagged_type (DECL_CONTEXT (decl))
5254 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
5255 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
5256 /* Also ignore the artificial member typedef for the class name. */
5257 return 1;
5258 return 0;
5261 /* Output Dwarf .debug information for a decl described by DECL. */
5263 static void
5264 output_decl (decl, containing_scope)
5265 tree decl;
5266 tree containing_scope;
5268 /* Make a note of the decl node we are going to be working on. We may
5269 need to give the user the source coordinates of where it appeared in
5270 case we notice (later on) that something about it looks screwy. */
5272 dwarf_last_decl = decl;
5274 if (TREE_CODE (decl) == ERROR_MARK)
5275 return;
5277 /* If a structure is declared within an initialization, e.g. as the
5278 operand of a sizeof, then it will not have a name. We don't want
5279 to output a DIE for it, as the tree nodes are in the temporary obstack */
5281 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5282 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
5283 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
5284 || (TYPE_FIELDS (TREE_TYPE (decl))
5285 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
5286 return;
5288 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5290 if (DECL_IGNORED_P (decl))
5291 return;
5293 switch (TREE_CODE (decl))
5295 case CONST_DECL:
5296 /* The individual enumerators of an enum type get output when we
5297 output the Dwarf representation of the relevant enum type itself. */
5298 break;
5300 case FUNCTION_DECL:
5301 /* If we are in terse mode, don't output any DIEs to represent
5302 mere function declarations. Also, if we are conforming
5303 to the DWARF version 1 specification, don't output DIEs for
5304 mere function declarations. */
5306 if (DECL_INITIAL (decl) == NULL_TREE)
5307 #if (DWARF_VERSION > 1)
5308 if (debug_info_level <= DINFO_LEVEL_TERSE)
5309 #endif
5310 break;
5312 /* Before we describe the FUNCTION_DECL itself, make sure that we
5313 have described its return type. */
5315 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
5318 /* And its containing type. */
5319 register tree origin = decl_class_context (decl);
5320 if (origin)
5321 output_type (origin, containing_scope);
5324 /* If we're emitting an out-of-line copy of an inline function,
5325 set up to refer to the abstract instance emitted from
5326 dwarfout_deferred_inline_function. */
5327 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
5328 && ! (containing_scope && TYPE_P (containing_scope)))
5329 set_decl_origin_self (decl);
5331 /* If the following DIE will represent a function definition for a
5332 function with "extern" linkage, output a special "pubnames" DIE
5333 label just ahead of the actual DIE. A reference to this label
5334 was already generated in the .debug_pubnames section sub-entry
5335 for this function definition. */
5337 if (TREE_PUBLIC (decl))
5339 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5341 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5342 ASM_OUTPUT_LABEL (asm_out_file, label);
5345 /* Now output a DIE to represent the function itself. */
5347 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
5348 ? output_global_subroutine_die
5349 : output_local_subroutine_die,
5350 decl);
5352 /* Now output descriptions of the arguments for this function.
5353 This gets (unnecessarily?) complex because of the fact that
5354 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
5355 cases where there was a trailing `...' at the end of the formal
5356 parameter list. In order to find out if there was a trailing
5357 ellipsis or not, we must instead look at the type associated
5358 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
5359 If the chain of type nodes hanging off of this FUNCTION_TYPE node
5360 ends with a void_type_node then there should *not* be an ellipsis
5361 at the end. */
5363 /* In the case where we are describing a mere function declaration, all
5364 we need to do here (and all we *can* do here) is to describe
5365 the *types* of its formal parameters. */
5367 if (decl != current_function_decl || in_class)
5368 output_formal_types (TREE_TYPE (decl));
5369 else
5371 /* Generate DIEs to represent all known formal parameters */
5373 tree arg_decls = DECL_ARGUMENTS (decl);
5374 tree parm;
5376 /* WARNING! Kludge zone ahead! Here we have a special
5377 hack for svr4 SDB compatibility. Instead of passing the
5378 current FUNCTION_DECL node as the second parameter (i.e.
5379 the `containing_scope' parameter) to `output_decl' (as
5380 we ought to) we instead pass a pointer to our own private
5381 fake_containing_scope node. That node is a RECORD_TYPE
5382 node which NO OTHER TYPE may ever actually be a member of.
5384 This pointer will ultimately get passed into `output_type'
5385 as its `containing_scope' parameter. `Output_type' will
5386 then perform its part in the hack... i.e. it will pend
5387 the type of the formal parameter onto the pending_types
5388 list. Later on, when we are done generating the whole
5389 sequence of formal parameter DIEs for this function
5390 definition, we will un-pend all previously pended types
5391 of formal parameters for this function definition.
5393 This whole kludge prevents any type DIEs from being
5394 mixed in with the formal parameter DIEs. That's good
5395 because svr4 SDB believes that the list of formal
5396 parameter DIEs for a function ends wherever the first
5397 non-formal-parameter DIE appears. Thus, we have to
5398 keep the formal parameter DIEs segregated. They must
5399 all appear (consecutively) at the start of the list of
5400 children for the DIE representing the function definition.
5401 Then (and only then) may we output any additional DIEs
5402 needed to represent the types of these formal parameters.
5406 When generating DIEs, generate the unspecified_parameters
5407 DIE instead if we come across the arg "__builtin_va_alist"
5410 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
5411 if (TREE_CODE (parm) == PARM_DECL)
5413 if (DECL_NAME(parm) &&
5414 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
5415 "__builtin_va_alist") )
5416 output_die (output_unspecified_parameters_die, decl);
5417 else
5418 output_decl (parm, fake_containing_scope);
5422 Now that we have finished generating all of the DIEs to
5423 represent the formal parameters themselves, force out
5424 any DIEs needed to represent their types. We do this
5425 simply by un-pending all previously pended types which
5426 can legitimately go into the chain of children DIEs for
5427 the current FUNCTION_DECL.
5430 output_pending_types_for_scope (decl);
5433 Decide whether we need an unspecified_parameters DIE at the end.
5434 There are 2 more cases to do this for:
5435 1) the ansi ... declaration - this is detectable when the end
5436 of the arg list is not a void_type_node
5437 2) an unprototyped function declaration (not a definition). This
5438 just means that we have no info about the parameters at all.
5442 tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
5444 if (fn_arg_types)
5446 /* this is the prototyped case, check for ... */
5447 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
5448 output_die (output_unspecified_parameters_die, decl);
5450 else
5452 /* this is unprototyped, check for undefined (just declaration) */
5453 if (!DECL_INITIAL (decl))
5454 output_die (output_unspecified_parameters_die, decl);
5458 /* Output Dwarf info for all of the stuff within the body of the
5459 function (if it has one - it may be just a declaration). */
5462 tree outer_scope = DECL_INITIAL (decl);
5464 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
5466 /* Note that here, `outer_scope' is a pointer to the outermost
5467 BLOCK node created to represent a function.
5468 This outermost BLOCK actually represents the outermost
5469 binding contour for the function, i.e. the contour in which
5470 the function's formal parameters and labels get declared.
5472 Curiously, it appears that the front end doesn't actually
5473 put the PARM_DECL nodes for the current function onto the
5474 BLOCK_VARS list for this outer scope. (They are strung
5475 off of the DECL_ARGUMENTS list for the function instead.)
5476 The BLOCK_VARS list for the `outer_scope' does provide us
5477 with a list of the LABEL_DECL nodes for the function however,
5478 and we output DWARF info for those here.
5480 Just within the `outer_scope' there will be a BLOCK node
5481 representing the function's outermost pair of curly braces,
5482 and any blocks used for the base and member initializers of
5483 a C++ constructor function. */
5485 output_decls_for_scope (outer_scope, 0);
5487 /* Finally, force out any pending types which are local to the
5488 outermost block of this function definition. These will
5489 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
5490 node itself. */
5492 output_pending_types_for_scope (decl);
5497 /* Generate a terminator for the list of stuff `owned' by this
5498 function. */
5500 end_sibling_chain ();
5502 break;
5504 case TYPE_DECL:
5505 /* If we are in terse mode, don't generate any DIEs to represent
5506 any actual typedefs. Note that even when we are in terse mode,
5507 we must still output DIEs to represent those tagged types which
5508 are used (directly or indirectly) in the specification of either
5509 a return type or a formal parameter type of some function. */
5511 if (debug_info_level <= DINFO_LEVEL_TERSE)
5512 if (! TYPE_DECL_IS_STUB (decl)
5513 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5514 return;
5516 /* In the special case of a TYPE_DECL node representing
5517 the declaration of some type tag, if the given TYPE_DECL is
5518 marked as having been instantiated from some other (original)
5519 TYPE_DECL node (e.g. one which was generated within the original
5520 definition of an inline function) we have to generate a special
5521 (abbreviated) TAG_structure_type, TAG_union_type, or
5522 TAG_enumeration-type DIE here. */
5524 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5526 output_tagged_type_instantiation (TREE_TYPE (decl));
5527 return;
5530 output_type (TREE_TYPE (decl), containing_scope);
5532 if (! is_redundant_typedef (decl))
5533 /* Output a DIE to represent the typedef itself. */
5534 output_die (output_typedef_die, decl);
5535 break;
5537 case LABEL_DECL:
5538 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5539 output_die (output_label_die, decl);
5540 break;
5542 case VAR_DECL:
5543 /* If we are conforming to the DWARF version 1 specification, don't
5544 generated any DIEs to represent mere external object declarations. */
5546 #if (DWARF_VERSION <= 1)
5547 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5548 break;
5549 #endif
5551 /* If we are in terse mode, don't generate any DIEs to represent
5552 any variable declarations or definitions. */
5554 if (debug_info_level <= DINFO_LEVEL_TERSE)
5555 break;
5557 /* Output any DIEs that are needed to specify the type of this data
5558 object. */
5560 output_type (TREE_TYPE (decl), containing_scope);
5563 /* And its containing type. */
5564 register tree origin = decl_class_context (decl);
5565 if (origin)
5566 output_type (origin, containing_scope);
5569 /* If the following DIE will represent a data object definition for a
5570 data object with "extern" linkage, output a special "pubnames" DIE
5571 label just ahead of the actual DIE. A reference to this label
5572 was already generated in the .debug_pubnames section sub-entry
5573 for this data object definition. */
5575 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5577 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5579 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5580 ASM_OUTPUT_LABEL (asm_out_file, label);
5583 /* Now output the DIE to represent the data object itself. This gets
5584 complicated because of the possibility that the VAR_DECL really
5585 represents an inlined instance of a formal parameter for an inline
5586 function. */
5589 void (*func) PARAMS ((void *));
5590 register tree origin = decl_ultimate_origin (decl);
5592 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5593 func = output_formal_parameter_die;
5594 else
5596 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5597 func = output_global_variable_die;
5598 else
5599 func = output_local_variable_die;
5601 output_die (func, decl);
5603 break;
5605 case FIELD_DECL:
5606 /* Ignore the nameless fields that are used to skip bits. */
5607 if (DECL_NAME (decl) != 0)
5609 output_type (member_declared_type (decl), containing_scope);
5610 output_die (output_member_die, decl);
5612 break;
5614 case PARM_DECL:
5615 /* Force out the type of this formal, if it was not forced out yet.
5616 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5617 It should be able to grok the presence of type DIEs within a list
5618 of TAG_formal_parameter DIEs, but it doesn't. */
5620 output_type (TREE_TYPE (decl), containing_scope);
5621 output_die (output_formal_parameter_die, decl);
5622 break;
5624 case NAMESPACE_DECL:
5625 /* Ignore for now. */
5626 break;
5628 default:
5629 abort ();
5633 /* Output debug information for a function. */
5634 static void
5635 dwarfout_function_decl (decl)
5636 tree decl;
5638 dwarfout_file_scope_decl (decl, 0);
5641 /* Debug information for a global DECL. Called from toplev.c after
5642 compilation proper has finished. */
5643 static void
5644 dwarfout_global_decl (decl)
5645 tree decl;
5647 /* Output DWARF information for file-scope tentative data object
5648 declarations, file-scope (extern) function declarations (which
5649 had no corresponding body) and file-scope tagged type
5650 declarations and definitions which have not yet been forced out. */
5652 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
5653 dwarfout_file_scope_decl (decl, 1);
5656 /* DECL is an inline function, whose body is present, but which is not
5657 being output at this point. (We're putting that off until we need
5658 to do it.) */
5659 static void
5660 dwarfout_deferred_inline_function (decl)
5661 tree decl;
5663 /* Generate the DWARF info for the "abstract" instance of a function
5664 which we may later generate inlined and/or out-of-line instances
5665 of. */
5666 if ((DECL_INLINE (decl) || DECL_ABSTRACT (decl))
5667 && ! DECL_ABSTRACT_ORIGIN (decl))
5669 /* The front-end may not have set CURRENT_FUNCTION_DECL, but the
5670 DWARF code expects it to be set in this case. Intuitively,
5671 DECL is the function we just finished defining, so setting
5672 CURRENT_FUNCTION_DECL is sensible. */
5673 tree saved_cfd = current_function_decl;
5674 int was_abstract = DECL_ABSTRACT (decl);
5675 current_function_decl = decl;
5677 /* Let the DWARF code do its work. */
5678 set_decl_abstract_flags (decl, 1);
5679 dwarfout_file_scope_decl (decl, 0);
5680 if (! was_abstract)
5681 set_decl_abstract_flags (decl, 0);
5683 /* Reset CURRENT_FUNCTION_DECL. */
5684 current_function_decl = saved_cfd;
5688 static void
5689 dwarfout_file_scope_decl (decl, set_finalizing)
5690 tree decl;
5691 int set_finalizing;
5693 if (TREE_CODE (decl) == ERROR_MARK)
5694 return;
5696 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5698 if (DECL_IGNORED_P (decl))
5699 return;
5701 switch (TREE_CODE (decl))
5703 case FUNCTION_DECL:
5705 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5706 a builtin function. Explicit programmer-supplied declarations of
5707 these same functions should NOT be ignored however. */
5709 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5710 return;
5712 /* What we would really like to do here is to filter out all mere
5713 file-scope declarations of file-scope functions which are never
5714 referenced later within this translation unit (and keep all of
5715 ones that *are* referenced later on) but we aren't clairvoyant,
5716 so we have no idea which functions will be referenced in the
5717 future (i.e. later on within the current translation unit).
5718 So here we just ignore all file-scope function declarations
5719 which are not also definitions. If and when the debugger needs
5720 to know something about these functions, it wil have to hunt
5721 around and find the DWARF information associated with the
5722 *definition* of the function.
5724 Note that we can't just check `DECL_EXTERNAL' to find out which
5725 FUNCTION_DECL nodes represent definitions and which ones represent
5726 mere declarations. We have to check `DECL_INITIAL' instead. That's
5727 because the C front-end supports some weird semantics for "extern
5728 inline" function definitions. These can get inlined within the
5729 current translation unit (an thus, we need to generate DWARF info
5730 for their abstract instances so that the DWARF info for the
5731 concrete inlined instances can have something to refer to) but
5732 the compiler never generates any out-of-lines instances of such
5733 things (despite the fact that they *are* definitions). The
5734 important point is that the C front-end marks these "extern inline"
5735 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5736 anyway.
5738 Note that the C++ front-end also plays some similar games for inline
5739 function definitions appearing within include files which also
5740 contain `#pragma interface' pragmas. */
5742 if (DECL_INITIAL (decl) == NULL_TREE)
5743 return;
5745 if (TREE_PUBLIC (decl)
5746 && ! DECL_EXTERNAL (decl)
5747 && ! DECL_ABSTRACT (decl))
5749 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5751 /* Output a .debug_pubnames entry for a public function
5752 defined in this compilation unit. */
5754 fputc ('\n', asm_out_file);
5755 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5756 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5757 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5758 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5759 IDENTIFIER_POINTER (DECL_NAME (decl)));
5760 ASM_OUTPUT_POP_SECTION (asm_out_file);
5763 break;
5765 case VAR_DECL:
5767 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5768 object declaration and if the declaration was never even
5769 referenced from within this entire compilation unit. We
5770 suppress these DIEs in order to save space in the .debug section
5771 (by eliminating entries which are probably useless). Note that
5772 we must not suppress block-local extern declarations (whether
5773 used or not) because that would screw-up the debugger's name
5774 lookup mechanism and cause it to miss things which really ought
5775 to be in scope at a given point. */
5777 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5778 return;
5780 if (TREE_PUBLIC (decl)
5781 && ! DECL_EXTERNAL (decl)
5782 && GET_CODE (DECL_RTL (decl)) == MEM
5783 && ! DECL_ABSTRACT (decl))
5785 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5787 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5789 /* Output a .debug_pubnames entry for a public variable
5790 defined in this compilation unit. */
5792 fputc ('\n', asm_out_file);
5793 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5794 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5795 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5796 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5797 IDENTIFIER_POINTER (DECL_NAME (decl)));
5798 ASM_OUTPUT_POP_SECTION (asm_out_file);
5801 if (DECL_INITIAL (decl) == NULL)
5803 /* Output a .debug_aranges entry for a public variable
5804 which is tentatively defined in this compilation unit. */
5806 fputc ('\n', asm_out_file);
5807 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
5808 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5809 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5810 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5811 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5812 ASM_OUTPUT_POP_SECTION (asm_out_file);
5816 /* If we are in terse mode, don't generate any DIEs to represent
5817 any variable declarations or definitions. */
5819 if (debug_info_level <= DINFO_LEVEL_TERSE)
5820 return;
5822 break;
5824 case TYPE_DECL:
5825 /* Don't bother trying to generate any DIEs to represent any of the
5826 normal built-in types for the language we are compiling, except
5827 in cases where the types in question are *not* DWARF fundamental
5828 types. We make an exception in the case of non-fundamental types
5829 for the sake of objective C (and perhaps C++) because the GNU
5830 front-ends for these languages may in fact create certain "built-in"
5831 types which are (for example) RECORD_TYPEs. In such cases, we
5832 really need to output these (non-fundamental) types because other
5833 DIEs may contain references to them. */
5835 /* Also ignore language dependent types here, because they are probably
5836 also built-in types. If we didn't ignore them, then we would get
5837 references to undefined labels because output_type doesn't support
5838 them. So, for now, we need to ignore them to avoid assembler
5839 errors. */
5841 /* ??? This code is different than the equivalent code in dwarf2out.c.
5842 The dwarf2out.c code is probably more correct. */
5844 if (DECL_SOURCE_LINE (decl) == 0
5845 && (type_is_fundamental (TREE_TYPE (decl))
5846 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5847 return;
5849 /* If we are in terse mode, don't generate any DIEs to represent
5850 any actual typedefs. Note that even when we are in terse mode,
5851 we must still output DIEs to represent those tagged types which
5852 are used (directly or indirectly) in the specification of either
5853 a return type or a formal parameter type of some function. */
5855 if (debug_info_level <= DINFO_LEVEL_TERSE)
5856 if (! TYPE_DECL_IS_STUB (decl)
5857 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5858 return;
5860 break;
5862 default:
5863 return;
5866 fputc ('\n', asm_out_file);
5867 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5868 finalizing = set_finalizing;
5869 output_decl (decl, NULL_TREE);
5871 /* NOTE: The call above to `output_decl' may have caused one or more
5872 file-scope named types (i.e. tagged types) to be placed onto the
5873 pending_types_list. We have to get those types off of that list
5874 at some point, and this is the perfect time to do it. If we didn't
5875 take them off now, they might still be on the list when cc1 finally
5876 exits. That might be OK if it weren't for the fact that when we put
5877 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5878 for these types, and that causes them never to be output unless
5879 `output_pending_types_for_scope' takes them off of the list and un-sets
5880 their TREE_ASM_WRITTEN flags. */
5882 output_pending_types_for_scope (NULL_TREE);
5884 /* The above call should have totally emptied the pending_types_list
5885 if this is not a nested function or class. If this is a nested type,
5886 then the remaining pending_types will be emitted when the containing type
5887 is handled. */
5889 if (! DECL_CONTEXT (decl))
5891 if (pending_types != 0)
5892 abort ();
5895 ASM_OUTPUT_POP_SECTION (asm_out_file);
5897 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5898 current_funcdef_number++;
5901 /* Output a marker (i.e. a label) for the beginning of the generated code
5902 for a lexical block. */
5904 static void
5905 dwarfout_begin_block (line, blocknum)
5906 unsigned int line ATTRIBUTE_UNUSED;
5907 unsigned int blocknum;
5909 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5911 function_section (current_function_decl);
5912 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5913 ASM_OUTPUT_LABEL (asm_out_file, label);
5916 /* Output a marker (i.e. a label) for the end of the generated code
5917 for a lexical block. */
5919 static void
5920 dwarfout_end_block (line, blocknum)
5921 unsigned int line ATTRIBUTE_UNUSED;
5922 unsigned int blocknum;
5924 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5926 function_section (current_function_decl);
5927 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5928 ASM_OUTPUT_LABEL (asm_out_file, label);
5931 /* Output a marker (i.e. a label) for the point in the generated code where
5932 the real body of the function begins (after parameters have been moved
5933 to their home locations). */
5935 static void
5936 dwarfout_end_prologue (line)
5937 unsigned int line ATTRIBUTE_UNUSED;
5939 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5941 if (! use_gnu_debug_info_extensions)
5942 return;
5944 function_section (current_function_decl);
5945 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5946 ASM_OUTPUT_LABEL (asm_out_file, label);
5949 /* Output a marker (i.e. a label) for the point in the generated code where
5950 the real body of the function ends (just before the epilogue code). */
5952 static void
5953 dwarfout_end_function (line)
5954 unsigned int line ATTRIBUTE_UNUSED;
5956 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5958 if (! use_gnu_debug_info_extensions)
5959 return;
5960 function_section (current_function_decl);
5961 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5962 ASM_OUTPUT_LABEL (asm_out_file, label);
5965 /* Output a marker (i.e. a label) for the absolute end of the generated code
5966 for a function definition. This gets called *after* the epilogue code
5967 has been generated. */
5969 static void
5970 dwarfout_end_epilogue ()
5972 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5974 /* Output a label to mark the endpoint of the code generated for this
5975 function. */
5977 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5978 ASM_OUTPUT_LABEL (asm_out_file, label);
5981 static void
5982 shuffle_filename_entry (new_zeroth)
5983 filename_entry *new_zeroth;
5985 filename_entry temp_entry;
5986 filename_entry *limit_p;
5987 filename_entry *move_p;
5989 if (new_zeroth == &filename_table[0])
5990 return;
5992 temp_entry = *new_zeroth;
5994 /* Shift entries up in the table to make room at [0]. */
5996 limit_p = &filename_table[0];
5997 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5998 *move_p = *(move_p-1);
6000 /* Install the found entry at [0]. */
6002 filename_table[0] = temp_entry;
6005 /* Create a new (string) entry for the .debug_sfnames section. */
6007 static void
6008 generate_new_sfname_entry ()
6010 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6012 fputc ('\n', asm_out_file);
6013 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6014 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
6015 ASM_OUTPUT_LABEL (asm_out_file, label);
6016 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
6017 filename_table[0].name
6018 ? filename_table[0].name
6019 : "");
6020 ASM_OUTPUT_POP_SECTION (asm_out_file);
6023 /* Lookup a filename (in the list of filenames that we know about here in
6024 dwarfout.c) and return its "index". The index of each (known) filename
6025 is just a unique number which is associated with only that one filename.
6026 We need such numbers for the sake of generating labels (in the
6027 .debug_sfnames section) and references to those unique labels (in the
6028 .debug_srcinfo and .debug_macinfo sections).
6030 If the filename given as an argument is not found in our current list,
6031 add it to the list and assign it the next available unique index number.
6033 Whatever we do (i.e. whether we find a pre-existing filename or add a new
6034 one), we shuffle the filename found (or added) up to the zeroth entry of
6035 our list of filenames (which is always searched linearly). We do this so
6036 as to optimize the most common case for these filename lookups within
6037 dwarfout.c. The most common case by far is the case where we call
6038 lookup_filename to lookup the very same filename that we did a lookup
6039 on the last time we called lookup_filename. We make sure that this
6040 common case is fast because such cases will constitute 99.9% of the
6041 lookups we ever do (in practice).
6043 If we add a new filename entry to our table, we go ahead and generate
6044 the corresponding entry in the .debug_sfnames section right away.
6045 Doing so allows us to avoid tickling an assembler bug (present in some
6046 m68k assemblers) which yields assembly-time errors in cases where the
6047 difference of two label addresses is taken and where the two labels
6048 are in a section *other* than the one where the difference is being
6049 calculated, and where at least one of the two symbol references is a
6050 forward reference. (This bug could be tickled by our .debug_srcinfo
6051 entries if we don't output their corresponding .debug_sfnames entries
6052 before them.) */
6054 static unsigned
6055 lookup_filename (file_name)
6056 const char *file_name;
6058 filename_entry *search_p;
6059 filename_entry *limit_p = &filename_table[ft_entries];
6061 for (search_p = filename_table; search_p < limit_p; search_p++)
6062 if (!strcmp (file_name, search_p->name))
6064 /* When we get here, we have found the filename that we were
6065 looking for in the filename_table. Now we want to make sure
6066 that it gets moved to the zero'th entry in the table (if it
6067 is not already there) so that subsequent attempts to find the
6068 same filename will find it as quickly as possible. */
6070 shuffle_filename_entry (search_p);
6071 return filename_table[0].number;
6074 /* We come here whenever we have a new filename which is not registered
6075 in the current table. Here we add it to the table. */
6077 /* Prepare to add a new table entry by making sure there is enough space
6078 in the table to do so. If not, expand the current table. */
6080 if (ft_entries == ft_entries_allocated)
6082 ft_entries_allocated += FT_ENTRIES_INCREMENT;
6083 filename_table
6084 = (filename_entry *)
6085 xrealloc (filename_table,
6086 ft_entries_allocated * sizeof (filename_entry));
6089 /* Initially, add the new entry at the end of the filename table. */
6091 filename_table[ft_entries].number = ft_entries;
6092 filename_table[ft_entries].name = xstrdup (file_name);
6094 /* Shuffle the new entry into filename_table[0]. */
6096 shuffle_filename_entry (&filename_table[ft_entries]);
6098 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6099 generate_new_sfname_entry ();
6101 ft_entries++;
6102 return filename_table[0].number;
6105 static void
6106 generate_srcinfo_entry (line_entry_num, files_entry_num)
6107 unsigned line_entry_num;
6108 unsigned files_entry_num;
6110 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6112 fputc ('\n', asm_out_file);
6113 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6114 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
6115 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
6116 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
6117 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
6118 ASM_OUTPUT_POP_SECTION (asm_out_file);
6121 static void
6122 dwarfout_source_line (line, filename)
6123 unsigned int line;
6124 const char *filename;
6126 if (debug_info_level >= DINFO_LEVEL_NORMAL
6127 /* We can't emit line number info for functions in separate sections,
6128 because the assembler can't subtract labels in different sections. */
6129 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
6131 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6132 static unsigned last_line_entry_num = 0;
6133 static unsigned prev_file_entry_num = (unsigned) -1;
6134 unsigned this_file_entry_num;
6136 function_section (current_function_decl);
6137 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
6138 ASM_OUTPUT_LABEL (asm_out_file, label);
6140 fputc ('\n', asm_out_file);
6142 if (use_gnu_debug_info_extensions)
6143 this_file_entry_num = lookup_filename (filename);
6144 else
6145 this_file_entry_num = (unsigned) -1;
6147 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6148 if (this_file_entry_num != prev_file_entry_num)
6150 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
6152 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
6153 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
6157 const char *tail = strrchr (filename, '/');
6159 if (tail != NULL)
6160 filename = tail;
6163 fprintf (asm_out_file, "%s%u\t%s %s:%u\n",
6164 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
6165 filename, line);
6166 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6167 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
6168 ASM_OUTPUT_POP_SECTION (asm_out_file);
6170 if (this_file_entry_num != prev_file_entry_num)
6171 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
6172 prev_file_entry_num = this_file_entry_num;
6176 /* Generate an entry in the .debug_macinfo section. */
6178 static void
6179 generate_macinfo_entry (type_and_offset, string)
6180 const char *type_and_offset;
6181 const char *string;
6183 if (! use_gnu_debug_info_extensions)
6184 return;
6186 fputc ('\n', asm_out_file);
6187 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6188 fprintf (asm_out_file, "%s%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
6189 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
6190 ASM_OUTPUT_POP_SECTION (asm_out_file);
6193 /* Wrapper for toplev.c callback to check debug info level. */
6194 static void
6195 dwarfout_start_source_file_check (line, filename)
6196 unsigned int line;
6197 const char *filename;
6199 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6200 dwarfout_start_source_file (line, filename);
6203 static void
6204 dwarfout_start_source_file (line, filename)
6205 unsigned int line ATTRIBUTE_UNUSED;
6206 const char *filename;
6208 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6209 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
6211 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
6212 sprintf (type_and_offset, "0x%08x+%s-%s",
6213 ((unsigned) MACINFO_start << 24),
6214 /* Hack: skip leading '*' . */
6215 (*label == '*') + label,
6216 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
6217 generate_macinfo_entry (type_and_offset, "");
6220 /* Wrapper for toplev.c callback to check debug info level. */
6221 static void
6222 dwarfout_end_source_file_check (lineno)
6223 unsigned lineno;
6225 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6226 dwarfout_end_source_file (lineno);
6229 static void
6230 dwarfout_end_source_file (lineno)
6231 unsigned lineno;
6233 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6235 sprintf (type_and_offset, "0x%08x+%u",
6236 ((unsigned) MACINFO_resume << 24), lineno);
6237 generate_macinfo_entry (type_and_offset, "");
6240 /* Called from check_newline in c-parse.y. The `buffer' parameter
6241 contains the tail part of the directive line, i.e. the part which
6242 is past the initial whitespace, #, whitespace, directive-name,
6243 whitespace part. */
6245 static void
6246 dwarfout_define (lineno, buffer)
6247 unsigned lineno;
6248 const char *buffer;
6250 static int initialized = 0;
6251 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6253 if (!initialized)
6255 dwarfout_start_source_file (0, primary_filename);
6256 initialized = 1;
6258 sprintf (type_and_offset, "0x%08x+%u",
6259 ((unsigned) MACINFO_define << 24), lineno);
6260 generate_macinfo_entry (type_and_offset, buffer);
6263 /* Called from check_newline in c-parse.y. The `buffer' parameter
6264 contains the tail part of the directive line, i.e. the part which
6265 is past the initial whitespace, #, whitespace, directive-name,
6266 whitespace part. */
6268 static void
6269 dwarfout_undef (lineno, buffer)
6270 unsigned lineno;
6271 const char *buffer;
6273 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6275 sprintf (type_and_offset, "0x%08x+%u",
6276 ((unsigned) MACINFO_undef << 24), lineno);
6277 generate_macinfo_entry (type_and_offset, buffer);
6280 /* Set up for Dwarf output at the start of compilation. */
6282 static void
6283 dwarfout_init (main_input_filename)
6284 const char *main_input_filename;
6286 /* Remember the name of the primary input file. */
6288 primary_filename = main_input_filename;
6290 /* Allocate the initial hunk of the pending_sibling_stack. */
6292 pending_sibling_stack
6293 = (unsigned *)
6294 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
6295 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
6296 pending_siblings = 1;
6298 /* Allocate the initial hunk of the filename_table. */
6300 filename_table
6301 = (filename_entry *)
6302 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
6303 ft_entries_allocated = FT_ENTRIES_INCREMENT;
6304 ft_entries = 0;
6306 /* Allocate the initial hunk of the pending_types_list. */
6308 pending_types_list
6309 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
6310 pending_types_allocated = PENDING_TYPES_INCREMENT;
6311 pending_types = 0;
6313 /* Create an artificial RECORD_TYPE node which we can use in our hack
6314 to get the DIEs representing types of formal parameters to come out
6315 only *after* the DIEs for the formal parameters themselves. */
6317 fake_containing_scope = make_node (RECORD_TYPE);
6319 /* Output a starting label for the .text section. */
6321 fputc ('\n', asm_out_file);
6322 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6323 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
6324 ASM_OUTPUT_POP_SECTION (asm_out_file);
6326 /* Output a starting label for the .data section. */
6328 fputc ('\n', asm_out_file);
6329 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6330 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
6331 ASM_OUTPUT_POP_SECTION (asm_out_file);
6333 #if 0 /* GNU C doesn't currently use .data1. */
6334 /* Output a starting label for the .data1 section. */
6336 fputc ('\n', asm_out_file);
6337 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6338 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
6339 ASM_OUTPUT_POP_SECTION (asm_out_file);
6340 #endif
6342 /* Output a starting label for the .rodata section. */
6344 fputc ('\n', asm_out_file);
6345 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6346 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
6347 ASM_OUTPUT_POP_SECTION (asm_out_file);
6349 #if 0 /* GNU C doesn't currently use .rodata1. */
6350 /* Output a starting label for the .rodata1 section. */
6352 fputc ('\n', asm_out_file);
6353 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6354 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
6355 ASM_OUTPUT_POP_SECTION (asm_out_file);
6356 #endif
6358 /* Output a starting label for the .bss section. */
6360 fputc ('\n', asm_out_file);
6361 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6362 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
6363 ASM_OUTPUT_POP_SECTION (asm_out_file);
6365 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6367 if (use_gnu_debug_info_extensions)
6369 /* Output a starting label and an initial (compilation directory)
6370 entry for the .debug_sfnames section. The starting label will be
6371 referenced by the initial entry in the .debug_srcinfo section. */
6373 fputc ('\n', asm_out_file);
6374 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6375 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
6377 const char *pwd = getpwd ();
6378 char *dirname;
6380 if (!pwd)
6381 fatal_io_error ("can't get current directory");
6383 dirname = concat (pwd, "/", NULL);
6384 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
6385 free (dirname);
6387 ASM_OUTPUT_POP_SECTION (asm_out_file);
6390 if (debug_info_level >= DINFO_LEVEL_VERBOSE
6391 && use_gnu_debug_info_extensions)
6393 /* Output a starting label for the .debug_macinfo section. This
6394 label will be referenced by the AT_mac_info attribute in the
6395 TAG_compile_unit DIE. */
6397 fputc ('\n', asm_out_file);
6398 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6399 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
6400 ASM_OUTPUT_POP_SECTION (asm_out_file);
6403 /* Generate the initial entry for the .line section. */
6405 fputc ('\n', asm_out_file);
6406 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6407 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
6408 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
6409 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6410 ASM_OUTPUT_POP_SECTION (asm_out_file);
6412 if (use_gnu_debug_info_extensions)
6414 /* Generate the initial entry for the .debug_srcinfo section. */
6416 fputc ('\n', asm_out_file);
6417 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6418 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
6419 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
6420 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
6421 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6422 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
6423 #ifdef DWARF_TIMESTAMPS
6424 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
6425 #else
6426 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6427 #endif
6428 ASM_OUTPUT_POP_SECTION (asm_out_file);
6431 /* Generate the initial entry for the .debug_pubnames section. */
6433 fputc ('\n', asm_out_file);
6434 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6435 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6436 ASM_OUTPUT_POP_SECTION (asm_out_file);
6438 /* Generate the initial entry for the .debug_aranges section. */
6440 fputc ('\n', asm_out_file);
6441 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6442 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6443 DEBUG_ARANGES_END_LABEL,
6444 DEBUG_ARANGES_BEGIN_LABEL);
6445 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_BEGIN_LABEL);
6446 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 1);
6447 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6448 ASM_OUTPUT_POP_SECTION (asm_out_file);
6451 /* Setup first DIE number == 1. */
6452 NEXT_DIE_NUM = next_unused_dienum++;
6454 /* Generate the initial DIE for the .debug section. Note that the
6455 (string) value given in the AT_name attribute of the TAG_compile_unit
6456 DIE will (typically) be a relative pathname and that this pathname
6457 should be taken as being relative to the directory from which the
6458 compiler was invoked when the given (base) source file was compiled. */
6460 fputc ('\n', asm_out_file);
6461 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6462 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
6463 output_die (output_compile_unit_die, (PTR) main_input_filename);
6464 ASM_OUTPUT_POP_SECTION (asm_out_file);
6466 fputc ('\n', asm_out_file);
6469 /* Output stuff that dwarf requires at the end of every file. */
6471 static void
6472 dwarfout_finish (main_input_filename)
6473 const char *main_input_filename ATTRIBUTE_UNUSED;
6475 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6477 fputc ('\n', asm_out_file);
6478 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6479 retry_incomplete_types ();
6480 fputc ('\n', asm_out_file);
6482 /* Mark the end of the chain of siblings which represent all file-scope
6483 declarations in this compilation unit. */
6485 /* The (null) DIE which represents the terminator for the (sibling linked)
6486 list of file-scope items is *special*. Normally, we would just call
6487 end_sibling_chain at this point in order to output a word with the
6488 value `4' and that word would act as the terminator for the list of
6489 DIEs describing file-scope items. Unfortunately, if we were to simply
6490 do that, the label that would follow this DIE in the .debug section
6491 (i.e. `..D2') would *not* be properly aligned (as it must be on some
6492 machines) to a 4 byte boundary.
6494 In order to force the label `..D2' to get aligned to a 4 byte boundary,
6495 the trick used is to insert extra (otherwise useless) padding bytes
6496 into the (null) DIE that we know must precede the ..D2 label in the
6497 .debug section. The amount of padding required can be anywhere between
6498 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
6499 with the padding) would normally contain the value 4, but now it will
6500 also have to include the padding bytes, so it will instead have some
6501 value in the range 4..7.
6503 Fortunately, the rules of Dwarf say that any DIE whose length word
6504 contains *any* value less than 8 should be treated as a null DIE, so
6505 this trick works out nicely. Clever, eh? Don't give me any credit
6506 (or blame). I didn't think of this scheme. I just conformed to it.
6509 output_die (output_padded_null_die, (void *) 0);
6510 dienum_pop ();
6512 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
6513 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
6514 ASM_OUTPUT_POP_SECTION (asm_out_file);
6516 /* Output a terminator label for the .text section. */
6518 fputc ('\n', asm_out_file);
6519 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6520 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
6521 ASM_OUTPUT_POP_SECTION (asm_out_file);
6523 /* Output a terminator label for the .data section. */
6525 fputc ('\n', asm_out_file);
6526 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6527 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
6528 ASM_OUTPUT_POP_SECTION (asm_out_file);
6530 #if 0 /* GNU C doesn't currently use .data1. */
6531 /* Output a terminator label for the .data1 section. */
6533 fputc ('\n', asm_out_file);
6534 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6535 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
6536 ASM_OUTPUT_POP_SECTION (asm_out_file);
6537 #endif
6539 /* Output a terminator label for the .rodata section. */
6541 fputc ('\n', asm_out_file);
6542 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6543 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
6544 ASM_OUTPUT_POP_SECTION (asm_out_file);
6546 #if 0 /* GNU C doesn't currently use .rodata1. */
6547 /* Output a terminator label for the .rodata1 section. */
6549 fputc ('\n', asm_out_file);
6550 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6551 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
6552 ASM_OUTPUT_POP_SECTION (asm_out_file);
6553 #endif
6555 /* Output a terminator label for the .bss section. */
6557 fputc ('\n', asm_out_file);
6558 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6559 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
6560 ASM_OUTPUT_POP_SECTION (asm_out_file);
6562 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6564 /* Output a terminating entry for the .line section. */
6566 fputc ('\n', asm_out_file);
6567 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6568 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
6569 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6570 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6571 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6572 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
6573 ASM_OUTPUT_POP_SECTION (asm_out_file);
6575 if (use_gnu_debug_info_extensions)
6577 /* Output a terminating entry for the .debug_srcinfo section. */
6579 fputc ('\n', asm_out_file);
6580 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6581 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6582 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6583 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6584 ASM_OUTPUT_POP_SECTION (asm_out_file);
6587 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6589 /* Output terminating entries for the .debug_macinfo section. */
6591 dwarfout_end_source_file (0);
6593 fputc ('\n', asm_out_file);
6594 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6595 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6596 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6597 ASM_OUTPUT_POP_SECTION (asm_out_file);
6600 /* Generate the terminating entry for the .debug_pubnames section. */
6602 fputc ('\n', asm_out_file);
6603 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6604 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6605 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6606 ASM_OUTPUT_POP_SECTION (asm_out_file);
6608 /* Generate the terminating entries for the .debug_aranges section.
6610 Note that we want to do this only *after* we have output the end
6611 labels (for the various program sections) which we are going to
6612 refer to here. This allows us to work around a bug in the m68k
6613 svr4 assembler. That assembler gives bogus assembly-time errors
6614 if (within any given section) you try to take the difference of
6615 two relocatable symbols, both of which are located within some
6616 other section, and if one (or both?) of the symbols involved is
6617 being forward-referenced. By generating the .debug_aranges
6618 entries at this late point in the assembly output, we skirt the
6619 issue simply by avoiding forward-references.
6622 fputc ('\n', asm_out_file);
6623 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6625 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6626 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6628 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6629 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6631 #if 0 /* GNU C doesn't currently use .data1. */
6632 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6633 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6634 DATA1_BEGIN_LABEL);
6635 #endif
6637 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6638 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6639 RODATA_BEGIN_LABEL);
6641 #if 0 /* GNU C doesn't currently use .rodata1. */
6642 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6643 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6644 RODATA1_BEGIN_LABEL);
6645 #endif
6647 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6648 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6650 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6651 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6653 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_END_LABEL);
6654 ASM_OUTPUT_POP_SECTION (asm_out_file);
6657 /* There should not be any pending types left at the end. We need
6658 this now because it may not have been checked on the last call to
6659 dwarfout_file_scope_decl. */
6660 if (pending_types != 0)
6661 abort ();
6664 #endif /* DWARF_DEBUGGING_INFO */