* config/alpha/x-vms (USE_COLLECT2): Set to empty.
[official-gcc.git] / gcc / dwarfout.c
blob0ff75f585f7492cb47f8c3b70fe7074e0ccd037e
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 "dwarf2asm.h"
578 #include "toplev.h"
579 #include "tm_p.h"
580 #include "debug.h"
581 #include "langhooks.h"
583 /* NOTE: In the comments in this file, many references are made to
584 so called "Debugging Information Entries". For the sake of brevity,
585 this term is abbreviated to `DIE' throughout the remainder of this
586 file. */
588 /* Note that the implementation of C++ support herein is (as yet) unfinished.
589 If you want to try to complete it, more power to you. */
591 /* How to start an assembler comment. */
592 #ifndef ASM_COMMENT_START
593 #define ASM_COMMENT_START ";#"
594 #endif
596 /* How to print out a register name. */
597 #ifndef PRINT_REG
598 #define PRINT_REG(RTX, CODE, FILE) \
599 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
600 #endif
602 /* Define a macro which returns non-zero for any tagged type which is
603 used (directly or indirectly) in the specification of either some
604 function's return type or some formal parameter of some function.
605 We use this macro when we are operating in "terse" mode to help us
606 know what tagged types have to be represented in Dwarf (even in
607 terse mode) and which ones don't.
609 A flag bit with this meaning really should be a part of the normal
610 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
611 for these nodes. For now, we have to just fake it. It it safe for
612 us to simply return zero for all complete tagged types (which will
613 get forced out anyway if they were used in the specification of some
614 formal or return type) and non-zero for all incomplete tagged types.
617 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
619 /* Define a macro which returns non-zero for a TYPE_DECL which was
620 implicitly generated for a tagged type.
622 Note that unlike the gcc front end (which generates a NULL named
623 TYPE_DECL node for each complete tagged type, each array type, and
624 each function type node created) the g++ front end generates a
625 _named_ TYPE_DECL node for each tagged type node created.
626 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
627 generate a DW_TAG_typedef DIE for them. */
628 #define TYPE_DECL_IS_STUB(decl) \
629 (DECL_NAME (decl) == NULL \
630 || (DECL_ARTIFICIAL (decl) \
631 && is_tagged_type (TREE_TYPE (decl)) \
632 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
634 extern int flag_traditional;
636 /* Maximum size (in bytes) of an artificially generated label. */
638 #define MAX_ARTIFICIAL_LABEL_BYTES 30
640 /* Structure to keep track of source filenames. */
642 struct filename_entry {
643 unsigned number;
644 const char * name;
647 typedef struct filename_entry filename_entry;
649 /* Pointer to an array of elements, each one having the structure above. */
651 static filename_entry *filename_table;
653 /* Total number of entries in the table (i.e. array) pointed to by
654 `filename_table'. This is the *total* and includes both used and
655 unused slots. */
657 static unsigned ft_entries_allocated;
659 /* Number of entries in the filename_table which are actually in use. */
661 static unsigned ft_entries;
663 /* Size (in elements) of increments by which we may expand the filename
664 table. Actually, a single hunk of space of this size should be enough
665 for most typical programs. */
667 #define FT_ENTRIES_INCREMENT 64
669 /* Local pointer to the name of the main input file. Initialized in
670 dwarfout_init. */
672 static const char *primary_filename;
674 /* Pointer to the most recent filename for which we produced some line info. */
676 static const char *last_filename;
678 /* Counter to generate unique names for DIEs. */
680 static unsigned next_unused_dienum = 1;
682 /* Number of the DIE which is currently being generated. */
684 static unsigned current_dienum;
686 /* Number to use for the special "pubname" label on the next DIE which
687 represents a function or data object defined in this compilation
688 unit which has "extern" linkage. */
690 static int next_pubname_number = 0;
692 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
694 /* Pointer to a dynamically allocated list of pre-reserved and still
695 pending sibling DIE numbers. Note that this list will grow as needed. */
697 static unsigned *pending_sibling_stack;
699 /* Counter to keep track of the number of pre-reserved and still pending
700 sibling DIE numbers. */
702 static unsigned pending_siblings;
704 /* The currently allocated size of the above list (expressed in number of
705 list elements). */
707 static unsigned pending_siblings_allocated;
709 /* Size (in elements) of increments by which we may expand the pending
710 sibling stack. Actually, a single hunk of space of this size should
711 be enough for most typical programs. */
713 #define PENDING_SIBLINGS_INCREMENT 64
715 /* Non-zero if we are performing our file-scope finalization pass and if
716 we should force out Dwarf descriptions of any and all file-scope
717 tagged types which are still incomplete types. */
719 static int finalizing = 0;
721 /* A pointer to the base of a list of pending types which we haven't
722 generated DIEs for yet, but which we will have to come back to
723 later on. */
725 static tree *pending_types_list;
727 /* Number of elements currently allocated for the pending_types_list. */
729 static unsigned pending_types_allocated;
731 /* Number of elements of pending_types_list currently in use. */
733 static unsigned pending_types;
735 /* Size (in elements) of increments by which we may expand the pending
736 types list. Actually, a single hunk of space of this size should
737 be enough for most typical programs. */
739 #define PENDING_TYPES_INCREMENT 64
741 /* A pointer to the base of a list of incomplete types which might be
742 completed at some later time. */
744 static tree *incomplete_types_list;
746 /* Number of elements currently allocated for the incomplete_types_list. */
747 static unsigned incomplete_types_allocated;
749 /* Number of elements of incomplete_types_list currently in use. */
750 static unsigned incomplete_types;
752 /* Size (in elements) of increments by which we may expand the incomplete
753 types list. Actually, a single hunk of space of this size should
754 be enough for most typical programs. */
755 #define INCOMPLETE_TYPES_INCREMENT 64
757 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
758 This is used in a hack to help us get the DIEs describing types of
759 formal parameters to come *after* all of the DIEs describing the formal
760 parameters themselves. That's necessary in order to be compatible
761 with what the brain-damaged svr4 SDB debugger requires. */
763 static tree fake_containing_scope;
765 /* The number of the current function definition that we are generating
766 debugging information for. These numbers range from 1 up to the maximum
767 number of function definitions contained within the current compilation
768 unit. These numbers are used to create unique labels for various things
769 contained within various function definitions. */
771 static unsigned current_funcdef_number = 1;
773 /* A pointer to the ..._DECL node which we have most recently been working
774 on. We keep this around just in case something about it looks screwy
775 and we want to tell the user what the source coordinates for the actual
776 declaration are. */
778 static tree dwarf_last_decl;
780 /* A flag indicating that we are emitting the member declarations of a
781 class, so member functions and variables should not be entirely emitted.
782 This is a kludge to avoid passing a second argument to output_*_die. */
784 static int in_class;
786 /* Forward declarations for functions defined in this file. */
788 static void dwarfout_init PARAMS ((const char *));
789 static void dwarfout_finish PARAMS ((const char *));
790 static void dwarfout_define PARAMS ((unsigned int, const char *));
791 static void dwarfout_undef PARAMS ((unsigned int, const char *));
792 static void dwarfout_start_source_file PARAMS ((unsigned, const char *));
793 static void dwarfout_start_source_file_check PARAMS ((unsigned, const char *));
794 static void dwarfout_end_source_file PARAMS ((unsigned));
795 static void dwarfout_end_source_file_check PARAMS ((unsigned));
796 static void dwarfout_begin_block PARAMS ((unsigned, unsigned));
797 static void dwarfout_end_block PARAMS ((unsigned, unsigned));
798 static void dwarfout_end_epilogue PARAMS ((void));
799 static void dwarfout_source_line PARAMS ((unsigned int, const char *));
800 static void dwarfout_end_prologue PARAMS ((unsigned int));
801 static void dwarfout_end_function PARAMS ((unsigned int));
802 static void dwarfout_function_decl PARAMS ((tree));
803 static void dwarfout_global_decl PARAMS ((tree));
804 static void dwarfout_deferred_inline_function PARAMS ((tree));
805 static void dwarfout_file_scope_decl PARAMS ((tree , int));
806 static const char *dwarf_tag_name PARAMS ((unsigned));
807 static const char *dwarf_attr_name PARAMS ((unsigned));
808 static const char *dwarf_stack_op_name PARAMS ((unsigned));
809 static const char *dwarf_typemod_name PARAMS ((unsigned));
810 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
811 static const char *dwarf_fund_type_name PARAMS ((unsigned));
812 static tree decl_ultimate_origin PARAMS ((tree));
813 static tree block_ultimate_origin PARAMS ((tree));
814 static tree decl_class_context PARAMS ((tree));
815 #if 0
816 static void output_unsigned_leb128 PARAMS ((unsigned long));
817 static void output_signed_leb128 PARAMS ((long));
818 #endif
819 static int fundamental_type_code PARAMS ((tree));
820 static tree root_type_1 PARAMS ((tree, int));
821 static tree root_type PARAMS ((tree));
822 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
823 static void write_modifier_bytes PARAMS ((tree, int, int));
824 static inline int type_is_fundamental PARAMS ((tree));
825 static void equate_decl_number_to_die_number PARAMS ((tree));
826 static inline void equate_type_number_to_die_number PARAMS ((tree));
827 static void output_reg_number PARAMS ((rtx));
828 static void output_mem_loc_descriptor PARAMS ((rtx));
829 static void output_loc_descriptor PARAMS ((rtx));
830 static void output_bound_representation PARAMS ((tree, unsigned, int));
831 static void output_enumeral_list PARAMS ((tree));
832 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
833 static inline tree field_type PARAMS ((tree));
834 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
835 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
836 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
837 static inline void sibling_attribute PARAMS ((void));
838 static void location_attribute PARAMS ((rtx));
839 static void data_member_location_attribute PARAMS ((tree));
840 static void const_value_attribute PARAMS ((rtx));
841 static void location_or_const_value_attribute PARAMS ((tree));
842 static inline void name_attribute PARAMS ((const char *));
843 static inline void fund_type_attribute PARAMS ((unsigned));
844 static void mod_fund_type_attribute PARAMS ((tree, int, int));
845 static inline void user_def_type_attribute PARAMS ((tree));
846 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
847 #ifdef USE_ORDERING_ATTRIBUTE
848 static inline void ordering_attribute PARAMS ((unsigned));
849 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
850 static void subscript_data_attribute PARAMS ((tree));
851 static void byte_size_attribute PARAMS ((tree));
852 static inline void bit_offset_attribute PARAMS ((tree));
853 static inline void bit_size_attribute PARAMS ((tree));
854 static inline void element_list_attribute PARAMS ((tree));
855 static inline void stmt_list_attribute PARAMS ((const char *));
856 static inline void low_pc_attribute PARAMS ((const char *));
857 static inline void high_pc_attribute PARAMS ((const char *));
858 static inline void body_begin_attribute PARAMS ((const char *));
859 static inline void body_end_attribute PARAMS ((const char *));
860 static inline void language_attribute PARAMS ((unsigned));
861 static inline void member_attribute PARAMS ((tree));
862 #if 0
863 static inline void string_length_attribute PARAMS ((tree));
864 #endif
865 static inline void comp_dir_attribute PARAMS ((const char *));
866 static inline void sf_names_attribute PARAMS ((const char *));
867 static inline void src_info_attribute PARAMS ((const char *));
868 static inline void mac_info_attribute PARAMS ((const char *));
869 static inline void prototyped_attribute PARAMS ((tree));
870 static inline void producer_attribute PARAMS ((const char *));
871 static inline void inline_attribute PARAMS ((tree));
872 static inline void containing_type_attribute PARAMS ((tree));
873 static inline void abstract_origin_attribute PARAMS ((tree));
874 #ifdef DWARF_DECL_COORDINATES
875 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
876 #endif /* defined(DWARF_DECL_COORDINATES) */
877 static inline void pure_or_virtual_attribute PARAMS ((tree));
878 static void name_and_src_coords_attributes PARAMS ((tree));
879 static void type_attribute PARAMS ((tree, int, int));
880 static const char *type_tag PARAMS ((tree));
881 static inline void dienum_push PARAMS ((void));
882 static inline void dienum_pop PARAMS ((void));
883 static inline tree member_declared_type PARAMS ((tree));
884 static const char *function_start_label PARAMS ((tree));
885 static void output_array_type_die PARAMS ((void *));
886 static void output_set_type_die PARAMS ((void *));
887 #if 0
888 static void output_entry_point_die PARAMS ((void *));
889 #endif
890 static void output_inlined_enumeration_type_die PARAMS ((void *));
891 static void output_inlined_structure_type_die PARAMS ((void *));
892 static void output_inlined_union_type_die PARAMS ((void *));
893 static void output_enumeration_type_die PARAMS ((void *));
894 static void output_formal_parameter_die PARAMS ((void *));
895 static void output_global_subroutine_die PARAMS ((void *));
896 static void output_global_variable_die PARAMS ((void *));
897 static void output_label_die PARAMS ((void *));
898 static void output_lexical_block_die PARAMS ((void *));
899 static void output_inlined_subroutine_die PARAMS ((void *));
900 static void output_local_variable_die PARAMS ((void *));
901 static void output_member_die PARAMS ((void *));
902 #if 0
903 static void output_pointer_type_die PARAMS ((void *));
904 static void output_reference_type_die PARAMS ((void *));
905 #endif
906 static void output_ptr_to_mbr_type_die PARAMS ((void *));
907 static void output_compile_unit_die PARAMS ((void *));
908 static void output_string_type_die PARAMS ((void *));
909 static void output_inheritance_die PARAMS ((void *));
910 static void output_structure_type_die PARAMS ((void *));
911 static void output_local_subroutine_die PARAMS ((void *));
912 static void output_subroutine_type_die PARAMS ((void *));
913 static void output_typedef_die PARAMS ((void *));
914 static void output_union_type_die PARAMS ((void *));
915 static void output_unspecified_parameters_die PARAMS ((void *));
916 static void output_padded_null_die PARAMS ((void *));
917 static void output_die PARAMS ((void (*)(void *), void *));
918 static void end_sibling_chain PARAMS ((void));
919 static void output_formal_types PARAMS ((tree));
920 static void pend_type PARAMS ((tree));
921 static int type_ok_for_scope PARAMS ((tree, tree));
922 static void output_pending_types_for_scope PARAMS ((tree));
923 static void output_type PARAMS ((tree, tree));
924 static void output_tagged_type_instantiation PARAMS ((tree));
925 static void output_block PARAMS ((tree, int));
926 static void output_decls_for_scope PARAMS ((tree, int));
927 static void output_decl PARAMS ((tree, tree));
928 static void shuffle_filename_entry PARAMS ((filename_entry *));
929 static void generate_new_sfname_entry PARAMS ((void));
930 static unsigned lookup_filename PARAMS ((const char *));
931 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
932 static void generate_macinfo_entry PARAMS ((unsigned int, rtx,
933 const char *));
934 static int is_pseudo_reg PARAMS ((rtx));
935 static tree type_main_variant PARAMS ((tree));
936 static int is_tagged_type PARAMS ((tree));
937 static int is_redundant_typedef PARAMS ((tree));
938 static void add_incomplete_type PARAMS ((tree));
939 static void retry_incomplete_types PARAMS ((void));
941 /* Definitions of defaults for assembler-dependent names of various
942 pseudo-ops and section names.
944 Theses may be overridden in your tm.h file (if necessary) for your
945 particular assembler. The default values provided here correspond to
946 what is expected by "standard" AT&T System V.4 assemblers. */
948 #ifndef FILE_ASM_OP
949 #define FILE_ASM_OP "\t.file\t"
950 #endif
951 #ifndef VERSION_ASM_OP
952 #define VERSION_ASM_OP "\t.version\t"
953 #endif
954 #ifndef SET_ASM_OP
955 #define SET_ASM_OP "\t.set\t"
956 #endif
958 /* Pseudo-ops for pushing the current section onto the section stack (and
959 simultaneously changing to a new section) and for poping back to the
960 section we were in immediately before this one. Note that most svr4
961 assemblers only maintain a one level stack... you can push all the
962 sections you want, but you can only pop out one level. (The sparc
963 svr4 assembler is an exception to this general rule.) That's
964 OK because we only use at most one level of the section stack herein. */
966 #ifndef PUSHSECTION_ASM_OP
967 #define PUSHSECTION_ASM_OP "\t.section\t"
968 #endif
969 #ifndef POPSECTION_ASM_OP
970 #define POPSECTION_ASM_OP "\t.previous"
971 #endif
973 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
974 to print the PUSHSECTION_ASM_OP and the section name. The default here
975 works for almost all svr4 assemblers, except for the sparc, where the
976 section name must be enclosed in double quotes. (See sparcv4.h.) */
978 #ifndef PUSHSECTION_FORMAT
979 #define PUSHSECTION_FORMAT "%s%s\n"
980 #endif
982 #ifndef DEBUG_SECTION
983 #define DEBUG_SECTION ".debug"
984 #endif
985 #ifndef LINE_SECTION
986 #define LINE_SECTION ".line"
987 #endif
988 #ifndef DEBUG_SFNAMES_SECTION
989 #define DEBUG_SFNAMES_SECTION ".debug_sfnames"
990 #endif
991 #ifndef DEBUG_SRCINFO_SECTION
992 #define DEBUG_SRCINFO_SECTION ".debug_srcinfo"
993 #endif
994 #ifndef DEBUG_MACINFO_SECTION
995 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
996 #endif
997 #ifndef DEBUG_PUBNAMES_SECTION
998 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
999 #endif
1000 #ifndef DEBUG_ARANGES_SECTION
1001 #define DEBUG_ARANGES_SECTION ".debug_aranges"
1002 #endif
1003 #ifndef TEXT_SECTION_NAME
1004 #define TEXT_SECTION_NAME ".text"
1005 #endif
1006 #ifndef DATA_SECTION_NAME
1007 #define DATA_SECTION_NAME ".data"
1008 #endif
1009 #ifndef DATA1_SECTION_NAME
1010 #define DATA1_SECTION_NAME ".data1"
1011 #endif
1012 #ifndef RODATA_SECTION_NAME
1013 #define RODATA_SECTION_NAME ".rodata"
1014 #endif
1015 #ifndef RODATA1_SECTION_NAME
1016 #define RODATA1_SECTION_NAME ".rodata1"
1017 #endif
1018 #ifndef BSS_SECTION_NAME
1019 #define BSS_SECTION_NAME ".bss"
1020 #endif
1022 /* Definitions of defaults for formats and names of various special
1023 (artificial) labels which may be generated within this file (when
1024 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
1026 If necessary, these may be overridden from within your tm.h file,
1027 but typically, you should never need to override these.
1029 These labels have been hacked (temporarily) so that they all begin with
1030 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
1031 stock m88k/svr4 assembler, both of which need to see .L at the start of
1032 a label in order to prevent that label from going into the linker symbol
1033 table). When I get time, I'll have to fix this the right way so that we
1034 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
1035 but that will require a rather massive set of changes. For the moment,
1036 the following definitions out to produce the right results for all svr4
1037 and svr3 assemblers. -- rfg
1040 #ifndef TEXT_BEGIN_LABEL
1041 #define TEXT_BEGIN_LABEL "*.L_text_b"
1042 #endif
1043 #ifndef TEXT_END_LABEL
1044 #define TEXT_END_LABEL "*.L_text_e"
1045 #endif
1047 #ifndef DATA_BEGIN_LABEL
1048 #define DATA_BEGIN_LABEL "*.L_data_b"
1049 #endif
1050 #ifndef DATA_END_LABEL
1051 #define DATA_END_LABEL "*.L_data_e"
1052 #endif
1054 #ifndef DATA1_BEGIN_LABEL
1055 #define DATA1_BEGIN_LABEL "*.L_data1_b"
1056 #endif
1057 #ifndef DATA1_END_LABEL
1058 #define DATA1_END_LABEL "*.L_data1_e"
1059 #endif
1061 #ifndef RODATA_BEGIN_LABEL
1062 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
1063 #endif
1064 #ifndef RODATA_END_LABEL
1065 #define RODATA_END_LABEL "*.L_rodata_e"
1066 #endif
1068 #ifndef RODATA1_BEGIN_LABEL
1069 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
1070 #endif
1071 #ifndef RODATA1_END_LABEL
1072 #define RODATA1_END_LABEL "*.L_rodata1_e"
1073 #endif
1075 #ifndef BSS_BEGIN_LABEL
1076 #define BSS_BEGIN_LABEL "*.L_bss_b"
1077 #endif
1078 #ifndef BSS_END_LABEL
1079 #define BSS_END_LABEL "*.L_bss_e"
1080 #endif
1082 #ifndef LINE_BEGIN_LABEL
1083 #define LINE_BEGIN_LABEL "*.L_line_b"
1084 #endif
1085 #ifndef LINE_LAST_ENTRY_LABEL
1086 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
1087 #endif
1088 #ifndef LINE_END_LABEL
1089 #define LINE_END_LABEL "*.L_line_e"
1090 #endif
1092 #ifndef DEBUG_BEGIN_LABEL
1093 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
1094 #endif
1095 #ifndef SFNAMES_BEGIN_LABEL
1096 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
1097 #endif
1098 #ifndef SRCINFO_BEGIN_LABEL
1099 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
1100 #endif
1101 #ifndef MACINFO_BEGIN_LABEL
1102 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
1103 #endif
1105 #ifndef DEBUG_ARANGES_BEGIN_LABEL
1106 #define DEBUG_ARANGES_BEGIN_LABEL "*.L_debug_aranges_begin"
1107 #endif
1108 #ifndef DEBUG_ARANGES_END_LABEL
1109 #define DEBUG_ARANGES_END_LABEL "*.L_debug_aranges_end"
1110 #endif
1112 #ifndef DIE_BEGIN_LABEL_FMT
1113 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
1114 #endif
1115 #ifndef DIE_END_LABEL_FMT
1116 #define DIE_END_LABEL_FMT "*.L_D%u_e"
1117 #endif
1118 #ifndef PUB_DIE_LABEL_FMT
1119 #define PUB_DIE_LABEL_FMT "*.L_P%u"
1120 #endif
1121 #ifndef BLOCK_BEGIN_LABEL_FMT
1122 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
1123 #endif
1124 #ifndef BLOCK_END_LABEL_FMT
1125 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
1126 #endif
1127 #ifndef SS_BEGIN_LABEL_FMT
1128 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
1129 #endif
1130 #ifndef SS_END_LABEL_FMT
1131 #define SS_END_LABEL_FMT "*.L_s%u_e"
1132 #endif
1133 #ifndef EE_BEGIN_LABEL_FMT
1134 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
1135 #endif
1136 #ifndef EE_END_LABEL_FMT
1137 #define EE_END_LABEL_FMT "*.L_e%u_e"
1138 #endif
1139 #ifndef MT_BEGIN_LABEL_FMT
1140 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
1141 #endif
1142 #ifndef MT_END_LABEL_FMT
1143 #define MT_END_LABEL_FMT "*.L_t%u_e"
1144 #endif
1145 #ifndef LOC_BEGIN_LABEL_FMT
1146 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
1147 #endif
1148 #ifndef LOC_END_LABEL_FMT
1149 #define LOC_END_LABEL_FMT "*.L_l%u_e"
1150 #endif
1151 #ifndef BOUND_BEGIN_LABEL_FMT
1152 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
1153 #endif
1154 #ifndef BOUND_END_LABEL_FMT
1155 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
1156 #endif
1157 #ifndef DERIV_BEGIN_LABEL_FMT
1158 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
1159 #endif
1160 #ifndef DERIV_END_LABEL_FMT
1161 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
1162 #endif
1163 #ifndef SL_BEGIN_LABEL_FMT
1164 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
1165 #endif
1166 #ifndef SL_END_LABEL_FMT
1167 #define SL_END_LABEL_FMT "*.L_sl%u_e"
1168 #endif
1169 #ifndef BODY_BEGIN_LABEL_FMT
1170 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
1171 #endif
1172 #ifndef BODY_END_LABEL_FMT
1173 #define BODY_END_LABEL_FMT "*.L_b%u_e"
1174 #endif
1175 #ifndef FUNC_END_LABEL_FMT
1176 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
1177 #endif
1178 #ifndef TYPE_NAME_FMT
1179 #define TYPE_NAME_FMT "*.L_T%u"
1180 #endif
1181 #ifndef DECL_NAME_FMT
1182 #define DECL_NAME_FMT "*.L_E%u"
1183 #endif
1184 #ifndef LINE_CODE_LABEL_FMT
1185 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
1186 #endif
1187 #ifndef SFNAMES_ENTRY_LABEL_FMT
1188 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
1189 #endif
1190 #ifndef LINE_ENTRY_LABEL_FMT
1191 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
1192 #endif
1194 /* Definitions of defaults for various types of primitive assembly language
1195 output operations.
1197 If necessary, these may be overridden from within your tm.h file,
1198 but typically, you shouldn't need to override these. */
1200 #ifndef ASM_OUTPUT_PUSH_SECTION
1201 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
1202 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
1203 #endif
1205 #ifndef ASM_OUTPUT_POP_SECTION
1206 #define ASM_OUTPUT_POP_SECTION(FILE) \
1207 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
1208 #endif
1210 #ifndef ASM_OUTPUT_DWARF_DELTA2
1211 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
1212 dw2_asm_output_delta (2, LABEL1, LABEL2, NULL)
1213 #endif
1215 #ifndef ASM_OUTPUT_DWARF_DELTA4
1216 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
1217 dw2_asm_output_delta (4, LABEL1, LABEL2, NULL)
1218 #endif
1220 #ifndef ASM_OUTPUT_DWARF_TAG
1221 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
1222 dw2_asm_output_data (2, TAG, "%s", dwarf_tag_name (TAG));
1223 #endif
1225 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
1226 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
1227 dw2_asm_output_data (2, ATTR, "%s", dwarf_attr_name (ATTR))
1228 #endif
1230 #ifndef ASM_OUTPUT_DWARF_STACK_OP
1231 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
1232 dw2_asm_output_data (1, OP, "%s", dwarf_stack_op_name (OP))
1233 #endif
1235 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
1236 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
1237 dw2_asm_output_data (2, FT, "%s", dwarf_fund_type_name (FT))
1238 #endif
1240 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
1241 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
1242 dw2_asm_output_data (1, FMT, "%s", dwarf_fmt_byte_name (FMT));
1243 #endif
1245 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
1246 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
1247 dw2_asm_output_data (1, MOD, "%s", dwarf_typemod_name (MOD));
1248 #endif
1250 #ifndef ASM_OUTPUT_DWARF_ADDR
1251 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
1252 dw2_asm_output_addr (4, LABEL, NULL)
1253 #endif
1255 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
1256 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
1257 dw2_asm_output_addr_rtx (4, RTX, NULL)
1258 #endif
1260 #ifndef ASM_OUTPUT_DWARF_REF
1261 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
1262 dw2_asm_output_addr (4, LABEL, NULL)
1263 #endif
1265 #ifndef ASM_OUTPUT_DWARF_DATA1
1266 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
1267 dw2_asm_output_data (1, VALUE, NULL)
1268 #endif
1270 #ifndef ASM_OUTPUT_DWARF_DATA2
1271 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
1272 dw2_asm_output_data (2, VALUE, NULL)
1273 #endif
1275 #ifndef ASM_OUTPUT_DWARF_DATA4
1276 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
1277 dw2_asm_output_data (4, VALUE, NULL)
1278 #endif
1280 #ifndef ASM_OUTPUT_DWARF_DATA8
1281 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
1282 dw2_asm_output_data (8, VALUE, NULL)
1283 #endif
1285 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
1286 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
1287 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
1288 defined, we call it, then issue the line feed. If not, we supply a
1289 default definition of calling ASM_OUTPUT_ASCII */
1291 #ifndef ASM_OUTPUT_DWARF_STRING
1292 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1293 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
1294 #else
1295 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1296 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
1297 #endif
1300 /* The debug hooks structure. */
1301 struct gcc_debug_hooks dwarf_debug_hooks =
1303 dwarfout_init,
1304 dwarfout_finish,
1305 dwarfout_define,
1306 dwarfout_undef,
1307 dwarfout_start_source_file_check,
1308 dwarfout_end_source_file_check,
1309 dwarfout_begin_block,
1310 dwarfout_end_block,
1311 debug_true_tree, /* ignore_block */
1312 dwarfout_source_line, /* source_line */
1313 dwarfout_source_line, /* begin_prologue */
1314 dwarfout_end_prologue,
1315 dwarfout_end_epilogue,
1316 debug_nothing_tree, /* begin_function */
1317 dwarfout_end_function,
1318 dwarfout_function_decl,
1319 dwarfout_global_decl,
1320 dwarfout_deferred_inline_function,
1321 debug_nothing_tree, /* outlining_inline_function */
1322 debug_nothing_rtx /* label */
1325 /************************ general utility functions **************************/
1327 static inline int
1328 is_pseudo_reg (rtl)
1329 rtx rtl;
1331 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1332 || ((GET_CODE (rtl) == SUBREG)
1333 && (REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)));
1336 static inline tree
1337 type_main_variant (type)
1338 tree type;
1340 type = TYPE_MAIN_VARIANT (type);
1342 /* There really should be only one main variant among any group of variants
1343 of a given type (and all of the MAIN_VARIANT values for all members of
1344 the group should point to that one type) but sometimes the C front-end
1345 messes this up for array types, so we work around that bug here. */
1347 if (TREE_CODE (type) == ARRAY_TYPE)
1349 while (type != TYPE_MAIN_VARIANT (type))
1350 type = TYPE_MAIN_VARIANT (type);
1353 return type;
1356 /* Return non-zero if the given type node represents a tagged type. */
1358 static inline int
1359 is_tagged_type (type)
1360 tree type;
1362 enum tree_code code = TREE_CODE (type);
1364 return (code == RECORD_TYPE || code == UNION_TYPE
1365 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1368 static const char *
1369 dwarf_tag_name (tag)
1370 unsigned tag;
1372 switch (tag)
1374 case TAG_padding: return "TAG_padding";
1375 case TAG_array_type: return "TAG_array_type";
1376 case TAG_class_type: return "TAG_class_type";
1377 case TAG_entry_point: return "TAG_entry_point";
1378 case TAG_enumeration_type: return "TAG_enumeration_type";
1379 case TAG_formal_parameter: return "TAG_formal_parameter";
1380 case TAG_global_subroutine: return "TAG_global_subroutine";
1381 case TAG_global_variable: return "TAG_global_variable";
1382 case TAG_label: return "TAG_label";
1383 case TAG_lexical_block: return "TAG_lexical_block";
1384 case TAG_local_variable: return "TAG_local_variable";
1385 case TAG_member: return "TAG_member";
1386 case TAG_pointer_type: return "TAG_pointer_type";
1387 case TAG_reference_type: return "TAG_reference_type";
1388 case TAG_compile_unit: return "TAG_compile_unit";
1389 case TAG_string_type: return "TAG_string_type";
1390 case TAG_structure_type: return "TAG_structure_type";
1391 case TAG_subroutine: return "TAG_subroutine";
1392 case TAG_subroutine_type: return "TAG_subroutine_type";
1393 case TAG_typedef: return "TAG_typedef";
1394 case TAG_union_type: return "TAG_union_type";
1395 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
1396 case TAG_variant: return "TAG_variant";
1397 case TAG_common_block: return "TAG_common_block";
1398 case TAG_common_inclusion: return "TAG_common_inclusion";
1399 case TAG_inheritance: return "TAG_inheritance";
1400 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
1401 case TAG_module: return "TAG_module";
1402 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
1403 case TAG_set_type: return "TAG_set_type";
1404 case TAG_subrange_type: return "TAG_subrange_type";
1405 case TAG_with_stmt: return "TAG_with_stmt";
1407 /* GNU extensions. */
1409 case TAG_format_label: return "TAG_format_label";
1410 case TAG_namelist: return "TAG_namelist";
1411 case TAG_function_template: return "TAG_function_template";
1412 case TAG_class_template: return "TAG_class_template";
1414 default: return "TAG_<unknown>";
1418 static const char *
1419 dwarf_attr_name (attr)
1420 unsigned attr;
1422 switch (attr)
1424 case AT_sibling: return "AT_sibling";
1425 case AT_location: return "AT_location";
1426 case AT_name: return "AT_name";
1427 case AT_fund_type: return "AT_fund_type";
1428 case AT_mod_fund_type: return "AT_mod_fund_type";
1429 case AT_user_def_type: return "AT_user_def_type";
1430 case AT_mod_u_d_type: return "AT_mod_u_d_type";
1431 case AT_ordering: return "AT_ordering";
1432 case AT_subscr_data: return "AT_subscr_data";
1433 case AT_byte_size: return "AT_byte_size";
1434 case AT_bit_offset: return "AT_bit_offset";
1435 case AT_bit_size: return "AT_bit_size";
1436 case AT_element_list: return "AT_element_list";
1437 case AT_stmt_list: return "AT_stmt_list";
1438 case AT_low_pc: return "AT_low_pc";
1439 case AT_high_pc: return "AT_high_pc";
1440 case AT_language: return "AT_language";
1441 case AT_member: return "AT_member";
1442 case AT_discr: return "AT_discr";
1443 case AT_discr_value: return "AT_discr_value";
1444 case AT_string_length: return "AT_string_length";
1445 case AT_common_reference: return "AT_common_reference";
1446 case AT_comp_dir: return "AT_comp_dir";
1447 case AT_const_value_string: return "AT_const_value_string";
1448 case AT_const_value_data2: return "AT_const_value_data2";
1449 case AT_const_value_data4: return "AT_const_value_data4";
1450 case AT_const_value_data8: return "AT_const_value_data8";
1451 case AT_const_value_block2: return "AT_const_value_block2";
1452 case AT_const_value_block4: return "AT_const_value_block4";
1453 case AT_containing_type: return "AT_containing_type";
1454 case AT_default_value_addr: return "AT_default_value_addr";
1455 case AT_default_value_data2: return "AT_default_value_data2";
1456 case AT_default_value_data4: return "AT_default_value_data4";
1457 case AT_default_value_data8: return "AT_default_value_data8";
1458 case AT_default_value_string: return "AT_default_value_string";
1459 case AT_friends: return "AT_friends";
1460 case AT_inline: return "AT_inline";
1461 case AT_is_optional: return "AT_is_optional";
1462 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1463 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1464 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1465 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1466 case AT_private: return "AT_private";
1467 case AT_producer: return "AT_producer";
1468 case AT_program: return "AT_program";
1469 case AT_protected: return "AT_protected";
1470 case AT_prototyped: return "AT_prototyped";
1471 case AT_public: return "AT_public";
1472 case AT_pure_virtual: return "AT_pure_virtual";
1473 case AT_return_addr: return "AT_return_addr";
1474 case AT_abstract_origin: return "AT_abstract_origin";
1475 case AT_start_scope: return "AT_start_scope";
1476 case AT_stride_size: return "AT_stride_size";
1477 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1478 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1479 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1480 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1481 case AT_virtual: return "AT_virtual";
1483 /* GNU extensions */
1485 case AT_sf_names: return "AT_sf_names";
1486 case AT_src_info: return "AT_src_info";
1487 case AT_mac_info: return "AT_mac_info";
1488 case AT_src_coords: return "AT_src_coords";
1489 case AT_body_begin: return "AT_body_begin";
1490 case AT_body_end: return "AT_body_end";
1492 default: return "AT_<unknown>";
1496 static const char *
1497 dwarf_stack_op_name (op)
1498 unsigned op;
1500 switch (op)
1502 case OP_REG: return "OP_REG";
1503 case OP_BASEREG: return "OP_BASEREG";
1504 case OP_ADDR: return "OP_ADDR";
1505 case OP_CONST: return "OP_CONST";
1506 case OP_DEREF2: return "OP_DEREF2";
1507 case OP_DEREF4: return "OP_DEREF4";
1508 case OP_ADD: return "OP_ADD";
1509 default: return "OP_<unknown>";
1513 static const char *
1514 dwarf_typemod_name (mod)
1515 unsigned mod;
1517 switch (mod)
1519 case MOD_pointer_to: return "MOD_pointer_to";
1520 case MOD_reference_to: return "MOD_reference_to";
1521 case MOD_const: return "MOD_const";
1522 case MOD_volatile: return "MOD_volatile";
1523 default: return "MOD_<unknown>";
1527 static const char *
1528 dwarf_fmt_byte_name (fmt)
1529 unsigned fmt;
1531 switch (fmt)
1533 case FMT_FT_C_C: return "FMT_FT_C_C";
1534 case FMT_FT_C_X: return "FMT_FT_C_X";
1535 case FMT_FT_X_C: return "FMT_FT_X_C";
1536 case FMT_FT_X_X: return "FMT_FT_X_X";
1537 case FMT_UT_C_C: return "FMT_UT_C_C";
1538 case FMT_UT_C_X: return "FMT_UT_C_X";
1539 case FMT_UT_X_C: return "FMT_UT_X_C";
1540 case FMT_UT_X_X: return "FMT_UT_X_X";
1541 case FMT_ET: return "FMT_ET";
1542 default: return "FMT_<unknown>";
1546 static const char *
1547 dwarf_fund_type_name (ft)
1548 unsigned ft;
1550 switch (ft)
1552 case FT_char: return "FT_char";
1553 case FT_signed_char: return "FT_signed_char";
1554 case FT_unsigned_char: return "FT_unsigned_char";
1555 case FT_short: return "FT_short";
1556 case FT_signed_short: return "FT_signed_short";
1557 case FT_unsigned_short: return "FT_unsigned_short";
1558 case FT_integer: return "FT_integer";
1559 case FT_signed_integer: return "FT_signed_integer";
1560 case FT_unsigned_integer: return "FT_unsigned_integer";
1561 case FT_long: return "FT_long";
1562 case FT_signed_long: return "FT_signed_long";
1563 case FT_unsigned_long: return "FT_unsigned_long";
1564 case FT_pointer: return "FT_pointer";
1565 case FT_float: return "FT_float";
1566 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1567 case FT_ext_prec_float: return "FT_ext_prec_float";
1568 case FT_complex: return "FT_complex";
1569 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1570 case FT_void: return "FT_void";
1571 case FT_boolean: return "FT_boolean";
1572 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1573 case FT_label: return "FT_label";
1575 /* GNU extensions. */
1577 case FT_long_long: return "FT_long_long";
1578 case FT_signed_long_long: return "FT_signed_long_long";
1579 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1581 case FT_int8: return "FT_int8";
1582 case FT_signed_int8: return "FT_signed_int8";
1583 case FT_unsigned_int8: return "FT_unsigned_int8";
1584 case FT_int16: return "FT_int16";
1585 case FT_signed_int16: return "FT_signed_int16";
1586 case FT_unsigned_int16: return "FT_unsigned_int16";
1587 case FT_int32: return "FT_int32";
1588 case FT_signed_int32: return "FT_signed_int32";
1589 case FT_unsigned_int32: return "FT_unsigned_int32";
1590 case FT_int64: return "FT_int64";
1591 case FT_signed_int64: return "FT_signed_int64";
1592 case FT_unsigned_int64: return "FT_unsigned_int64";
1593 case FT_int128: return "FT_int128";
1594 case FT_signed_int128: return "FT_signed_int128";
1595 case FT_unsigned_int128: return "FT_unsigned_int128";
1597 case FT_real32: return "FT_real32";
1598 case FT_real64: return "FT_real64";
1599 case FT_real96: return "FT_real96";
1600 case FT_real128: return "FT_real128";
1602 default: return "FT_<unknown>";
1606 /* Determine the "ultimate origin" of a decl. The decl may be an
1607 inlined instance of an inlined instance of a decl which is local
1608 to an inline function, so we have to trace all of the way back
1609 through the origin chain to find out what sort of node actually
1610 served as the original seed for the given block. */
1612 static tree
1613 decl_ultimate_origin (decl)
1614 tree decl;
1616 #ifdef ENABLE_CHECKING
1617 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1618 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1619 most distant ancestor, this should never happen. */
1620 abort ();
1621 #endif
1623 return DECL_ABSTRACT_ORIGIN (decl);
1626 /* Determine the "ultimate origin" of a block. The block may be an
1627 inlined instance of an inlined instance of a block which is local
1628 to an inline function, so we have to trace all of the way back
1629 through the origin chain to find out what sort of node actually
1630 served as the original seed for the given block. */
1632 static tree
1633 block_ultimate_origin (block)
1634 tree block;
1636 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1638 if (immediate_origin == NULL)
1639 return NULL;
1640 else
1642 tree ret_val;
1643 tree lookahead = immediate_origin;
1647 ret_val = lookahead;
1648 lookahead = (TREE_CODE (ret_val) == BLOCK)
1649 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1650 : NULL;
1652 while (lookahead != NULL && lookahead != ret_val);
1653 return ret_val;
1657 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1658 of a virtual function may refer to a base class, so we check the 'this'
1659 parameter. */
1661 static tree
1662 decl_class_context (decl)
1663 tree decl;
1665 tree context = NULL_TREE;
1666 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1667 context = DECL_CONTEXT (decl);
1668 else
1669 context = TYPE_MAIN_VARIANT
1670 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1672 if (context && !TYPE_P (context))
1673 context = NULL_TREE;
1675 return context;
1678 #if 0
1679 static void
1680 output_unsigned_leb128 (value)
1681 unsigned long value;
1683 unsigned long orig_value = value;
1687 unsigned byte = (value & 0x7f);
1689 value >>= 7;
1690 if (value != 0) /* more bytes to follow */
1691 byte |= 0x80;
1692 dw2_asm_output_data (1, byte, "\t%s ULEB128 number - value = %lu",
1693 orig_value);
1695 while (value != 0);
1698 static void
1699 output_signed_leb128 (value)
1700 long value;
1702 long orig_value = value;
1703 int negative = (value < 0);
1704 int more;
1708 unsigned byte = (value & 0x7f);
1710 value >>= 7;
1711 if (negative)
1712 value |= 0xfe000000; /* manually sign extend */
1713 if (((value == 0) && ((byte & 0x40) == 0))
1714 || ((value == -1) && ((byte & 0x40) == 1)))
1715 more = 0;
1716 else
1718 byte |= 0x80;
1719 more = 1;
1721 dw2_asm_output_data (1, byte, "\t%s SLEB128 number - value = %ld",
1722 orig_value);
1724 while (more);
1726 #endif
1728 /**************** utility functions for attribute functions ******************/
1730 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1731 type code for the given type.
1733 This routine must only be called for GCC type nodes that correspond to
1734 Dwarf fundamental types.
1736 The current Dwarf draft specification calls for Dwarf fundamental types
1737 to accurately reflect the fact that a given type was either a "plain"
1738 integral type or an explicitly "signed" integral type. Unfortunately,
1739 we can't always do this, because GCC may already have thrown away the
1740 information about the precise way in which the type was originally
1741 specified, as in:
1743 typedef signed int my_type;
1745 struct s { my_type f; };
1747 Since we may be stuck here without enough information to do exactly
1748 what is called for in the Dwarf draft specification, we do the best
1749 that we can under the circumstances and always use the "plain" integral
1750 fundamental type codes for int, short, and long types. That's probably
1751 good enough. The additional accuracy called for in the current DWARF
1752 draft specification is probably never even useful in practice. */
1754 static int
1755 fundamental_type_code (type)
1756 tree type;
1758 if (TREE_CODE (type) == ERROR_MARK)
1759 return 0;
1761 switch (TREE_CODE (type))
1763 case ERROR_MARK:
1764 return FT_void;
1766 case VOID_TYPE:
1767 return FT_void;
1769 case INTEGER_TYPE:
1770 /* Carefully distinguish all the standard types of C,
1771 without messing up if the language is not C.
1772 Note that we check only for the names that contain spaces;
1773 other names might occur by coincidence in other languages. */
1774 if (TYPE_NAME (type) != 0
1775 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1776 && DECL_NAME (TYPE_NAME (type)) != 0
1777 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1779 const char *const name =
1780 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1782 if (!strcmp (name, "unsigned char"))
1783 return FT_unsigned_char;
1784 if (!strcmp (name, "signed char"))
1785 return FT_signed_char;
1786 if (!strcmp (name, "unsigned int"))
1787 return FT_unsigned_integer;
1788 if (!strcmp (name, "short int"))
1789 return FT_short;
1790 if (!strcmp (name, "short unsigned int"))
1791 return FT_unsigned_short;
1792 if (!strcmp (name, "long int"))
1793 return FT_long;
1794 if (!strcmp (name, "long unsigned int"))
1795 return FT_unsigned_long;
1796 if (!strcmp (name, "long long int"))
1797 return FT_long_long; /* Not grok'ed by svr4 SDB */
1798 if (!strcmp (name, "long long unsigned int"))
1799 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1802 /* Most integer types will be sorted out above, however, for the
1803 sake of special `array index' integer types, the following code
1804 is also provided. */
1806 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1807 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1809 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1810 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1812 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1813 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1815 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1816 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1818 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1819 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1821 if (TYPE_MODE (type) == TImode)
1822 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1824 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1825 if (TYPE_PRECISION (type) == 1)
1826 return FT_boolean;
1828 abort ();
1830 case REAL_TYPE:
1831 /* Carefully distinguish all the standard types of C,
1832 without messing up if the language is not C. */
1833 if (TYPE_NAME (type) != 0
1834 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1835 && DECL_NAME (TYPE_NAME (type)) != 0
1836 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1838 const char *const name =
1839 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1841 /* Note that here we can run afoul of a serious bug in "classic"
1842 svr4 SDB debuggers. They don't seem to understand the
1843 FT_ext_prec_float type (even though they should). */
1845 if (!strcmp (name, "long double"))
1846 return FT_ext_prec_float;
1849 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1851 /* On the SH, when compiling with -m3e or -m4-single-only, both
1852 float and double are 32 bits. But since the debugger doesn't
1853 know about the subtarget, it always thinks double is 64 bits.
1854 So we have to tell the debugger that the type is float to
1855 make the output of the 'print' command etc. readable. */
1856 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1857 return FT_float;
1858 return FT_dbl_prec_float;
1860 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1861 return FT_float;
1863 /* Note that here we can run afoul of a serious bug in "classic"
1864 svr4 SDB debuggers. They don't seem to understand the
1865 FT_ext_prec_float type (even though they should). */
1867 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1868 return FT_ext_prec_float;
1869 abort ();
1871 case COMPLEX_TYPE:
1872 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1874 case CHAR_TYPE:
1875 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1877 case BOOLEAN_TYPE:
1878 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1880 default:
1881 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1883 return 0;
1886 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1887 the Dwarf "root" type for the given input type. The Dwarf "root" type
1888 of a given type is generally the same as the given type, except that if
1889 the given type is a pointer or reference type, then the root type of
1890 the given type is the root type of the "basis" type for the pointer or
1891 reference type. (This definition of the "root" type is recursive.)
1892 Also, the root type of a `const' qualified type or a `volatile'
1893 qualified type is the root type of the given type without the
1894 qualifiers. */
1896 static tree
1897 root_type_1 (type, count)
1898 tree type;
1899 int count;
1901 /* Give up after searching 1000 levels, in case this is a recursive
1902 pointer type. Such types are possible in Ada, but it is not possible
1903 to represent them in DWARF1 debug info. */
1904 if (count > 1000)
1905 return error_mark_node;
1907 switch (TREE_CODE (type))
1909 case ERROR_MARK:
1910 return error_mark_node;
1912 case POINTER_TYPE:
1913 case REFERENCE_TYPE:
1914 return root_type_1 (TREE_TYPE (type), count+1);
1916 default:
1917 return type;
1921 static tree
1922 root_type (type)
1923 tree type;
1925 type = root_type_1 (type, 0);
1926 if (type != error_mark_node)
1927 type = type_main_variant (type);
1928 return type;
1931 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1932 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1934 static void
1935 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1936 tree type;
1937 int decl_const;
1938 int decl_volatile;
1939 int count;
1941 if (TREE_CODE (type) == ERROR_MARK)
1942 return;
1944 /* Give up after searching 1000 levels, in case this is a recursive
1945 pointer type. Such types are possible in Ada, but it is not possible
1946 to represent them in DWARF1 debug info. */
1947 if (count > 1000)
1948 return;
1950 if (TYPE_READONLY (type) || decl_const)
1951 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1952 if (TYPE_VOLATILE (type) || decl_volatile)
1953 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1954 switch (TREE_CODE (type))
1956 case POINTER_TYPE:
1957 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1958 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1959 return;
1961 case REFERENCE_TYPE:
1962 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1963 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1964 return;
1966 case ERROR_MARK:
1967 default:
1968 return;
1972 static void
1973 write_modifier_bytes (type, decl_const, decl_volatile)
1974 tree type;
1975 int decl_const;
1976 int decl_volatile;
1978 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1981 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1982 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1984 static inline int
1985 type_is_fundamental (type)
1986 tree type;
1988 switch (TREE_CODE (type))
1990 case ERROR_MARK:
1991 case VOID_TYPE:
1992 case INTEGER_TYPE:
1993 case REAL_TYPE:
1994 case COMPLEX_TYPE:
1995 case BOOLEAN_TYPE:
1996 case CHAR_TYPE:
1997 return 1;
1999 case SET_TYPE:
2000 case ARRAY_TYPE:
2001 case RECORD_TYPE:
2002 case UNION_TYPE:
2003 case QUAL_UNION_TYPE:
2004 case ENUMERAL_TYPE:
2005 case FUNCTION_TYPE:
2006 case METHOD_TYPE:
2007 case POINTER_TYPE:
2008 case REFERENCE_TYPE:
2009 case FILE_TYPE:
2010 case OFFSET_TYPE:
2011 case LANG_TYPE:
2012 case VECTOR_TYPE:
2013 return 0;
2015 default:
2016 abort ();
2018 return 0;
2021 /* Given a pointer to some ..._DECL tree node, generate an assembly language
2022 equate directive which will associate a symbolic name with the current DIE.
2024 The name used is an artificial label generated from the DECL_UID number
2025 associated with the given decl node. The name it gets equated to is the
2026 symbolic label that we (previously) output at the start of the DIE that
2027 we are currently generating.
2029 Calling this function while generating some "decl related" form of DIE
2030 makes it possible to later refer to the DIE which represents the given
2031 decl simply by re-generating the symbolic name from the ..._DECL node's
2032 UID number. */
2034 static void
2035 equate_decl_number_to_die_number (decl)
2036 tree decl;
2038 /* In the case where we are generating a DIE for some ..._DECL node
2039 which represents either some inline function declaration or some
2040 entity declared within an inline function declaration/definition,
2041 setup a symbolic name for the current DIE so that we have a name
2042 for this DIE that we can easily refer to later on within
2043 AT_abstract_origin attributes. */
2045 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
2046 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2048 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
2049 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2050 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
2053 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
2054 equate directive which will associate a symbolic name with the current DIE.
2056 The name used is an artificial label generated from the TYPE_UID number
2057 associated with the given type node. The name it gets equated to is the
2058 symbolic label that we (previously) output at the start of the DIE that
2059 we are currently generating.
2061 Calling this function while generating some "type related" form of DIE
2062 makes it easy to later refer to the DIE which represents the given type
2063 simply by re-generating the alternative name from the ..._TYPE node's
2064 UID number. */
2066 static inline void
2067 equate_type_number_to_die_number (type)
2068 tree type;
2070 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
2071 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2073 /* We are generating a DIE to represent the main variant of this type
2074 (i.e the type without any const or volatile qualifiers) so in order
2075 to get the equate to come out right, we need to get the main variant
2076 itself here. */
2078 type = type_main_variant (type);
2080 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
2081 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2082 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
2085 static void
2086 output_reg_number (rtl)
2087 rtx rtl;
2089 unsigned regno = REGNO (rtl);
2091 if (regno >= DWARF_FRAME_REGISTERS)
2093 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
2094 regno);
2095 regno = 0;
2097 dw2_assemble_integer (4, GEN_INT (DBX_REGISTER_NUMBER (regno)));
2098 if (flag_debug_asm)
2100 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
2101 PRINT_REG (rtl, 0, asm_out_file);
2103 fputc ('\n', asm_out_file);
2106 /* The following routine is a nice and simple transducer. It converts the
2107 RTL for a variable or parameter (resident in memory) into an equivalent
2108 Dwarf representation of a mechanism for getting the address of that same
2109 variable onto the top of a hypothetical "address evaluation" stack.
2111 When creating memory location descriptors, we are effectively trans-
2112 forming the RTL for a memory-resident object into its Dwarf postfix
2113 expression equivalent. This routine just recursively descends an
2114 RTL tree, turning it into Dwarf postfix code as it goes. */
2116 static void
2117 output_mem_loc_descriptor (rtl)
2118 rtx rtl;
2120 /* Note that for a dynamically sized array, the location we will
2121 generate a description of here will be the lowest numbered location
2122 which is actually within the array. That's *not* necessarily the
2123 same as the zeroth element of the array. */
2125 #ifdef ASM_SIMPLIFY_DWARF_ADDR
2126 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
2127 #endif
2129 switch (GET_CODE (rtl))
2131 case SUBREG:
2133 /* The case of a subreg may arise when we have a local (register)
2134 variable or a formal (register) parameter which doesn't quite
2135 fill up an entire register. For now, just assume that it is
2136 legitimate to make the Dwarf info refer to the whole register
2137 which contains the given subreg. */
2139 rtl = SUBREG_REG (rtl);
2140 /* Drop thru. */
2142 case REG:
2144 /* Whenever a register number forms a part of the description of
2145 the method for calculating the (dynamic) address of a memory
2146 resident object, DWARF rules require the register number to
2147 be referred to as a "base register". This distinction is not
2148 based in any way upon what category of register the hardware
2149 believes the given register belongs to. This is strictly
2150 DWARF terminology we're dealing with here.
2152 Note that in cases where the location of a memory-resident data
2153 object could be expressed as:
2155 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
2157 the actual DWARF location descriptor that we generate may just
2158 be OP_BASEREG (basereg). This may look deceptively like the
2159 object in question was allocated to a register (rather than
2160 in memory) so DWARF consumers need to be aware of the subtle
2161 distinction between OP_REG and OP_BASEREG. */
2163 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
2164 output_reg_number (rtl);
2165 break;
2167 case MEM:
2168 output_mem_loc_descriptor (XEXP (rtl, 0));
2169 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
2170 break;
2172 case CONST:
2173 case SYMBOL_REF:
2174 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
2175 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2176 break;
2178 case PLUS:
2179 output_mem_loc_descriptor (XEXP (rtl, 0));
2180 output_mem_loc_descriptor (XEXP (rtl, 1));
2181 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2182 break;
2184 case CONST_INT:
2185 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2186 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
2187 break;
2189 case MULT:
2190 /* If a pseudo-reg is optimized away, it is possible for it to
2191 be replaced with a MEM containing a multiply. Use a GNU extension
2192 to describe it. */
2193 output_mem_loc_descriptor (XEXP (rtl, 0));
2194 output_mem_loc_descriptor (XEXP (rtl, 1));
2195 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
2196 break;
2198 default:
2199 abort ();
2203 /* Output a proper Dwarf location descriptor for a variable or parameter
2204 which is either allocated in a register or in a memory location. For
2205 a register, we just generate an OP_REG and the register number. For a
2206 memory location we provide a Dwarf postfix expression describing how to
2207 generate the (dynamic) address of the object onto the address stack. */
2209 static void
2210 output_loc_descriptor (rtl)
2211 rtx rtl;
2213 switch (GET_CODE (rtl))
2215 case SUBREG:
2217 /* The case of a subreg may arise when we have a local (register)
2218 variable or a formal (register) parameter which doesn't quite
2219 fill up an entire register. For now, just assume that it is
2220 legitimate to make the Dwarf info refer to the whole register
2221 which contains the given subreg. */
2223 rtl = SUBREG_REG (rtl);
2224 /* Drop thru. */
2226 case REG:
2227 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
2228 output_reg_number (rtl);
2229 break;
2231 case MEM:
2232 output_mem_loc_descriptor (XEXP (rtl, 0));
2233 break;
2235 default:
2236 abort (); /* Should never happen */
2240 /* Given a tree node describing an array bound (either lower or upper)
2241 output a representation for that bound. */
2243 static void
2244 output_bound_representation (bound, dim_num, u_or_l)
2245 tree bound;
2246 unsigned dim_num; /* For multi-dimensional arrays. */
2247 char u_or_l; /* Designates upper or lower bound. */
2249 switch (TREE_CODE (bound))
2252 case ERROR_MARK:
2253 return;
2255 /* All fixed-bounds are represented by INTEGER_CST nodes. */
2257 case INTEGER_CST:
2258 if (host_integerp (bound, 0))
2259 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
2260 break;
2262 default:
2264 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
2265 SAVE_EXPR nodes, in which case we can do something, or as
2266 an expression, which we cannot represent. */
2268 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2269 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2271 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
2272 current_dienum, dim_num, u_or_l);
2274 sprintf (end_label, BOUND_END_LABEL_FMT,
2275 current_dienum, dim_num, u_or_l);
2277 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2278 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2280 /* If optimization is turned on, the SAVE_EXPRs that describe
2281 how to access the upper bound values are essentially bogus.
2282 They only describe (at best) how to get at these values at
2283 the points in the generated code right after they have just
2284 been computed. Worse yet, in the typical case, the upper
2285 bound values will not even *be* computed in the optimized
2286 code, so these SAVE_EXPRs are entirely bogus.
2288 In order to compensate for this fact, we check here to see
2289 if optimization is enabled, and if so, we effectively create
2290 an empty location description for the (unknown and unknowable)
2291 upper bound.
2293 This should not cause too much trouble for existing (stupid?)
2294 debuggers because they have to deal with empty upper bounds
2295 location descriptions anyway in order to be able to deal with
2296 incomplete array types.
2298 Of course an intelligent debugger (GDB?) should be able to
2299 comprehend that a missing upper bound specification in a
2300 array type used for a storage class `auto' local array variable
2301 indicates that the upper bound is both unknown (at compile-
2302 time) and unknowable (at run-time) due to optimization. */
2304 if (! optimize)
2306 while (TREE_CODE (bound) == NOP_EXPR
2307 || TREE_CODE (bound) == CONVERT_EXPR)
2308 bound = TREE_OPERAND (bound, 0);
2310 if (TREE_CODE (bound) == SAVE_EXPR)
2311 output_loc_descriptor
2312 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
2315 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2317 break;
2322 /* Recursive function to output a sequence of value/name pairs for
2323 enumeration constants in reversed order. This is called from
2324 enumeration_type_die. */
2326 static void
2327 output_enumeral_list (link)
2328 tree link;
2330 if (link)
2332 output_enumeral_list (TREE_CHAIN (link));
2334 if (host_integerp (TREE_VALUE (link), 0))
2335 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2336 tree_low_cst (TREE_VALUE (link), 0));
2338 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
2339 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
2343 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
2344 which is not less than the value itself. */
2346 static inline HOST_WIDE_INT
2347 ceiling (value, boundary)
2348 HOST_WIDE_INT value;
2349 unsigned int boundary;
2351 return (((value + boundary - 1) / boundary) * boundary);
2354 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
2355 pointer to the declared type for the relevant field variable, or return
2356 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
2358 static inline tree
2359 field_type (decl)
2360 tree decl;
2362 tree type;
2364 if (TREE_CODE (decl) == ERROR_MARK)
2365 return integer_type_node;
2367 type = DECL_BIT_FIELD_TYPE (decl);
2368 if (type == NULL)
2369 type = TREE_TYPE (decl);
2370 return type;
2373 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2374 node, return the alignment in bits for the type, or else return
2375 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
2377 static inline unsigned int
2378 simple_type_align_in_bits (type)
2379 tree type;
2381 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
2384 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2385 node, return the size in bits for the type if it is a constant, or
2386 else return the alignment for the type if the type's size is not
2387 constant, or else return BITS_PER_WORD if the type actually turns out
2388 to be an ERROR_MARK node. */
2390 static inline unsigned HOST_WIDE_INT
2391 simple_type_size_in_bits (type)
2392 tree type;
2394 tree type_size_tree;
2396 if (TREE_CODE (type) == ERROR_MARK)
2397 return BITS_PER_WORD;
2398 type_size_tree = TYPE_SIZE (type);
2400 if (type_size_tree == NULL_TREE)
2401 return 0;
2402 if (! host_integerp (type_size_tree, 1))
2403 return TYPE_ALIGN (type);
2404 return tree_low_cst (type_size_tree, 1);
2407 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
2408 return the byte offset of the lowest addressed byte of the "containing
2409 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
2410 mine what that offset is, either because the argument turns out to be a
2411 pointer to an ERROR_MARK node, or because the offset is actually variable.
2412 (We can't handle the latter case just yet.) */
2414 static HOST_WIDE_INT
2415 field_byte_offset (decl)
2416 tree decl;
2418 unsigned int type_align_in_bytes;
2419 unsigned int type_align_in_bits;
2420 unsigned HOST_WIDE_INT type_size_in_bits;
2421 HOST_WIDE_INT object_offset_in_align_units;
2422 HOST_WIDE_INT object_offset_in_bits;
2423 HOST_WIDE_INT object_offset_in_bytes;
2424 tree type;
2425 tree field_size_tree;
2426 HOST_WIDE_INT bitpos_int;
2427 HOST_WIDE_INT deepest_bitpos;
2428 unsigned HOST_WIDE_INT field_size_in_bits;
2430 if (TREE_CODE (decl) == ERROR_MARK)
2431 return 0;
2433 if (TREE_CODE (decl) != FIELD_DECL)
2434 abort ();
2436 type = field_type (decl);
2437 field_size_tree = DECL_SIZE (decl);
2439 /* The size could be unspecified if there was an error, or for
2440 a flexible array member. */
2441 if (! field_size_tree)
2442 field_size_tree = bitsize_zero_node;
2444 /* We cannot yet cope with fields whose positions or sizes are variable,
2445 so for now, when we see such things, we simply return 0. Someday,
2446 we may be able to handle such cases, but it will be damn difficult. */
2448 if (! host_integerp (bit_position (decl), 0)
2449 || ! host_integerp (field_size_tree, 1))
2450 return 0;
2452 bitpos_int = int_bit_position (decl);
2453 field_size_in_bits = tree_low_cst (field_size_tree, 1);
2455 type_size_in_bits = simple_type_size_in_bits (type);
2456 type_align_in_bits = simple_type_align_in_bits (type);
2457 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2459 /* Note that the GCC front-end doesn't make any attempt to keep track
2460 of the starting bit offset (relative to the start of the containing
2461 structure type) of the hypothetical "containing object" for a bit-
2462 field. Thus, when computing the byte offset value for the start of
2463 the "containing object" of a bit-field, we must deduce this infor-
2464 mation on our own.
2466 This can be rather tricky to do in some cases. For example, handling
2467 the following structure type definition when compiling for an i386/i486
2468 target (which only aligns long long's to 32-bit boundaries) can be very
2469 tricky:
2471 struct S {
2472 int field1;
2473 long long field2:31;
2476 Fortunately, there is a simple rule-of-thumb which can be used in such
2477 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2478 the structure shown above. It decides to do this based upon one simple
2479 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2480 taining object" for each bit-field at the first (i.e. lowest addressed)
2481 legitimate alignment boundary (based upon the required minimum alignment
2482 for the declared type of the field) which it can possibly use, subject
2483 to the condition that there is still enough available space remaining
2484 in the containing object (when allocated at the selected point) to
2485 fully accommodate all of the bits of the bit-field itself.
2487 This simple rule makes it obvious why GCC allocates 8 bytes for each
2488 object of the structure type shown above. When looking for a place to
2489 allocate the "containing object" for `field2', the compiler simply tries
2490 to allocate a 64-bit "containing object" at each successive 32-bit
2491 boundary (starting at zero) until it finds a place to allocate that 64-
2492 bit field such that at least 31 contiguous (and previously unallocated)
2493 bits remain within that selected 64 bit field. (As it turns out, for
2494 the example above, the compiler finds that it is OK to allocate the
2495 "containing object" 64-bit field at bit-offset zero within the
2496 structure type.)
2498 Here we attempt to work backwards from the limited set of facts we're
2499 given, and we try to deduce from those facts, where GCC must have
2500 believed that the containing object started (within the structure type).
2502 The value we deduce is then used (by the callers of this routine) to
2503 generate AT_location and AT_bit_offset attributes for fields (both
2504 bit-fields and, in the case of AT_location, regular fields as well). */
2506 /* Figure out the bit-distance from the start of the structure to the
2507 "deepest" bit of the bit-field. */
2508 deepest_bitpos = bitpos_int + field_size_in_bits;
2510 /* This is the tricky part. Use some fancy footwork to deduce where the
2511 lowest addressed bit of the containing object must be. */
2512 object_offset_in_bits
2513 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2515 /* Compute the offset of the containing object in "alignment units". */
2516 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2518 /* Compute the offset of the containing object in bytes. */
2519 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2521 /* The above code assumes that the field does not cross an alignment
2522 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2523 or if the structure is packed. If this happens, then we get an object
2524 which starts after the bitfield, which means that the bit offset is
2525 negative. Gdb fails when given negative bit offsets. We avoid this
2526 by recomputing using the first bit of the bitfield. This will give
2527 us an object which does not completely contain the bitfield, but it
2528 will be aligned, and it will contain the first bit of the bitfield.
2530 However, only do this for a BYTES_BIG_ENDIAN target. For a
2531 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2532 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2533 then we end up computing the object byte offset for the wrong word of the
2534 desired bitfield, which in turn causes the field offset to be negative
2535 in bit_offset_attribute. */
2536 if (BYTES_BIG_ENDIAN
2537 && object_offset_in_bits > bitpos_int)
2539 deepest_bitpos = bitpos_int + 1;
2540 object_offset_in_bits
2541 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2542 object_offset_in_align_units = (object_offset_in_bits
2543 / type_align_in_bits);
2544 object_offset_in_bytes = (object_offset_in_align_units
2545 * type_align_in_bytes);
2548 return object_offset_in_bytes;
2551 /****************************** attributes *********************************/
2553 /* The following routines are responsible for writing out the various types
2554 of Dwarf attributes (and any following data bytes associated with them).
2555 These routines are listed in order based on the numerical codes of their
2556 associated attributes. */
2558 /* Generate an AT_sibling attribute. */
2560 static inline void
2561 sibling_attribute ()
2563 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2565 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2566 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2567 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2570 /* Output the form of location attributes suitable for whole variables and
2571 whole parameters. Note that the location attributes for struct fields
2572 are generated by the routine `data_member_location_attribute' below. */
2574 static void
2575 location_attribute (rtl)
2576 rtx rtl;
2578 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2579 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2581 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2582 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2583 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2584 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2585 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2587 /* Handle a special case. If we are about to output a location descriptor
2588 for a variable or parameter which has been optimized out of existence,
2589 don't do that. Instead we output a zero-length location descriptor
2590 value as part of the location attribute.
2592 A variable which has been optimized out of existence will have a
2593 DECL_RTL value which denotes a pseudo-reg.
2595 Currently, in some rare cases, variables can have DECL_RTL values
2596 which look like (MEM (REG pseudo-reg#)). These cases are due to
2597 bugs elsewhere in the compiler. We treat such cases
2598 as if the variable(s) in question had been optimized out of existence.
2600 Note that in all cases where we wish to express the fact that a
2601 variable has been optimized out of existence, we do not simply
2602 suppress the generation of the entire location attribute because
2603 the absence of a location attribute in certain kinds of DIEs is
2604 used to indicate something else entirely... i.e. that the DIE
2605 represents an object declaration, but not a definition. So saith
2606 the PLSIG.
2609 if (! is_pseudo_reg (rtl)
2610 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2611 output_loc_descriptor (rtl);
2613 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2616 /* Output the specialized form of location attribute used for data members
2617 of struct and union types.
2619 In the special case of a FIELD_DECL node which represents a bit-field,
2620 the "offset" part of this special location descriptor must indicate the
2621 distance in bytes from the lowest-addressed byte of the containing
2622 struct or union type to the lowest-addressed byte of the "containing
2623 object" for the bit-field. (See the `field_byte_offset' function above.)
2625 For any given bit-field, the "containing object" is a hypothetical
2626 object (of some integral or enum type) within which the given bit-field
2627 lives. The type of this hypothetical "containing object" is always the
2628 same as the declared type of the individual bit-field itself (for GCC
2629 anyway... the DWARF spec doesn't actually mandate this).
2631 Note that it is the size (in bytes) of the hypothetical "containing
2632 object" which will be given in the AT_byte_size attribute for this
2633 bit-field. (See the `byte_size_attribute' function below.) It is
2634 also used when calculating the value of the AT_bit_offset attribute.
2635 (See the `bit_offset_attribute' function below.) */
2637 static void
2638 data_member_location_attribute (t)
2639 tree t;
2641 unsigned object_offset_in_bytes;
2642 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2643 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2645 if (TREE_CODE (t) == TREE_VEC)
2646 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2647 else
2648 object_offset_in_bytes = field_byte_offset (t);
2650 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2651 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2652 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2653 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2654 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2655 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2656 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2657 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2658 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2661 /* Output an AT_const_value attribute for a variable or a parameter which
2662 does not have a "location" either in memory or in a register. These
2663 things can arise in GNU C when a constant is passed as an actual
2664 parameter to an inlined function. They can also arise in C++ where
2665 declared constants do not necessarily get memory "homes". */
2667 static void
2668 const_value_attribute (rtl)
2669 rtx rtl;
2671 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2672 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2674 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2675 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2676 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2677 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2678 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2680 switch (GET_CODE (rtl))
2682 case CONST_INT:
2683 /* Note that a CONST_INT rtx could represent either an integer or
2684 a floating-point constant. A CONST_INT is used whenever the
2685 constant will fit into a single word. In all such cases, the
2686 original mode of the constant value is wiped out, and the
2687 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2688 precise mode information for these constants, we always just
2689 output them using 4 bytes. */
2691 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2692 break;
2694 case CONST_DOUBLE:
2695 /* Note that a CONST_DOUBLE rtx could represent either an integer
2696 or a floating-point constant. A CONST_DOUBLE is used whenever
2697 the constant requires more than one word in order to be adequately
2698 represented. In all such cases, the original mode of the constant
2699 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2700 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2702 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2703 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2704 (unsigned int) CONST_DOUBLE_LOW (rtl));
2705 break;
2707 case CONST_STRING:
2708 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2709 break;
2711 case SYMBOL_REF:
2712 case LABEL_REF:
2713 case CONST:
2714 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2715 break;
2717 case PLUS:
2718 /* In cases where an inlined instance of an inline function is passed
2719 the address of an `auto' variable (which is local to the caller)
2720 we can get a situation where the DECL_RTL of the artificial
2721 local variable (for the inlining) which acts as a stand-in for
2722 the corresponding formal parameter (of the inline function)
2723 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2724 This is not exactly a compile-time constant expression, but it
2725 isn't the address of the (artificial) local variable either.
2726 Rather, it represents the *value* which the artificial local
2727 variable always has during its lifetime. We currently have no
2728 way to represent such quasi-constant values in Dwarf, so for now
2729 we just punt and generate an AT_const_value attribute with form
2730 FORM_BLOCK4 and a length of zero. */
2731 break;
2733 default:
2734 abort (); /* No other kinds of rtx should be possible here. */
2737 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2740 /* Generate *either* an AT_location attribute or else an AT_const_value
2741 data attribute for a variable or a parameter. We generate the
2742 AT_const_value attribute only in those cases where the given
2743 variable or parameter does not have a true "location" either in
2744 memory or in a register. This can happen (for example) when a
2745 constant is passed as an actual argument in a call to an inline
2746 function. (It's possible that these things can crop up in other
2747 ways also.) Note that one type of constant value which can be
2748 passed into an inlined function is a constant pointer. This can
2749 happen for example if an actual argument in an inlined function
2750 call evaluates to a compile-time constant address. */
2752 static void
2753 location_or_const_value_attribute (decl)
2754 tree decl;
2756 rtx rtl;
2758 if (TREE_CODE (decl) == ERROR_MARK)
2759 return;
2761 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2763 /* Should never happen. */
2764 abort ();
2765 return;
2768 /* Here we have to decide where we are going to say the parameter "lives"
2769 (as far as the debugger is concerned). We only have a couple of choices.
2770 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2771 normally indicates where the parameter lives during most of the activa-
2772 tion of the function. If optimization is enabled however, this could
2773 be either NULL or else a pseudo-reg. Both of those cases indicate that
2774 the parameter doesn't really live anywhere (as far as the code generation
2775 parts of GCC are concerned) during most of the function's activation.
2776 That will happen (for example) if the parameter is never referenced
2777 within the function.
2779 We could just generate a location descriptor here for all non-NULL
2780 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2781 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2782 cases where DECL_RTL is NULL or is a pseudo-reg.
2784 Note however that we can only get away with using DECL_INCOMING_RTL as
2785 a backup substitute for DECL_RTL in certain limited cases. In cases
2786 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2787 we can be sure that the parameter was passed using the same type as it
2788 is declared to have within the function, and that its DECL_INCOMING_RTL
2789 points us to a place where a value of that type is passed. In cases
2790 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2791 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2792 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2793 points us to a value of some type which is *different* from the type
2794 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2795 to generate a location attribute in such cases, the debugger would
2796 end up (for example) trying to fetch a `float' from a place which
2797 actually contains the first part of a `double'. That would lead to
2798 really incorrect and confusing output at debug-time, and we don't
2799 want that now do we?
2801 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2802 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2803 couple of cute exceptions however. On little-endian machines we can
2804 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2805 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2806 an integral type which is smaller than TREE_TYPE(decl). These cases
2807 arise when (on a little-endian machine) a non-prototyped function has
2808 a parameter declared to be of type `short' or `char'. In such cases,
2809 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2810 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2811 passed `int' value. If the debugger then uses that address to fetch a
2812 `short' or a `char' (on a little-endian machine) the result will be the
2813 correct data, so we allow for such exceptional cases below.
2815 Note that our goal here is to describe the place where the given formal
2816 parameter lives during most of the function's activation (i.e. between
2817 the end of the prologue and the start of the epilogue). We'll do that
2818 as best as we can. Note however that if the given formal parameter is
2819 modified sometime during the execution of the function, then a stack
2820 backtrace (at debug-time) will show the function as having been called
2821 with the *new* value rather than the value which was originally passed
2822 in. This happens rarely enough that it is not a major problem, but it
2823 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2824 may generate two additional attributes for any given TAG_formal_parameter
2825 DIE which will describe the "passed type" and the "passed location" for
2826 the given formal parameter in addition to the attributes we now generate
2827 to indicate the "declared type" and the "active location" for each
2828 parameter. This additional set of attributes could be used by debuggers
2829 for stack backtraces.
2831 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2832 can be NULL also. This happens (for example) for inlined-instances of
2833 inline function formal parameters which are never referenced. This really
2834 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2835 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2836 these values for inlined instances of inline function parameters, so
2837 when we see such cases, we are just out-of-luck for the time
2838 being (until integrate.c gets fixed).
2841 /* Use DECL_RTL as the "location" unless we find something better. */
2842 rtl = DECL_RTL (decl);
2844 if (TREE_CODE (decl) == PARM_DECL)
2845 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2847 /* This decl represents a formal parameter which was optimized out. */
2848 tree declared_type = type_main_variant (TREE_TYPE (decl));
2849 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2851 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2852 *all* cases where (rtl == NULL_RTX) just below. */
2854 if (declared_type == passed_type)
2855 rtl = DECL_INCOMING_RTL (decl);
2856 else if (! BYTES_BIG_ENDIAN)
2857 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2858 /* NMS WTF? */
2859 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2860 rtl = DECL_INCOMING_RTL (decl);
2863 if (rtl == NULL_RTX)
2864 return;
2866 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2867 #ifdef LEAF_REG_REMAP
2868 if (current_function_uses_only_leaf_regs)
2869 leaf_renumber_regs_insn (rtl);
2870 #endif
2872 switch (GET_CODE (rtl))
2874 case ADDRESSOF:
2875 /* The address of a variable that was optimized away; don't emit
2876 anything. */
2877 break;
2879 case CONST_INT:
2880 case CONST_DOUBLE:
2881 case CONST_STRING:
2882 case SYMBOL_REF:
2883 case LABEL_REF:
2884 case CONST:
2885 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2886 const_value_attribute (rtl);
2887 break;
2889 case MEM:
2890 case REG:
2891 case SUBREG:
2892 location_attribute (rtl);
2893 break;
2895 case CONCAT:
2896 /* ??? CONCAT is used for complex variables, which may have the real
2897 part stored in one place and the imag part stored somewhere else.
2898 DWARF1 has no way to describe a variable that lives in two different
2899 places, so we just describe where the first part lives, and hope that
2900 the second part is stored after it. */
2901 location_attribute (XEXP (rtl, 0));
2902 break;
2904 default:
2905 abort (); /* Should never happen. */
2909 /* Generate an AT_name attribute given some string value to be included as
2910 the value of the attribute. */
2912 static inline void
2913 name_attribute (name_string)
2914 const char *name_string;
2916 if (name_string && *name_string)
2918 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2919 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2923 static inline void
2924 fund_type_attribute (ft_code)
2925 unsigned ft_code;
2927 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2928 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2931 static void
2932 mod_fund_type_attribute (type, decl_const, decl_volatile)
2933 tree type;
2934 int decl_const;
2935 int decl_volatile;
2937 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2938 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2940 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2941 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2942 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2943 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2944 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2945 write_modifier_bytes (type, decl_const, decl_volatile);
2946 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2947 fundamental_type_code (root_type (type)));
2948 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2951 static inline void
2952 user_def_type_attribute (type)
2953 tree type;
2955 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2957 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2958 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2959 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2962 static void
2963 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2964 tree type;
2965 int decl_const;
2966 int decl_volatile;
2968 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2969 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2970 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2972 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2973 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2974 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2975 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2976 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2977 write_modifier_bytes (type, decl_const, decl_volatile);
2978 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2979 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2980 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2983 #ifdef USE_ORDERING_ATTRIBUTE
2984 static inline void
2985 ordering_attribute (ordering)
2986 unsigned ordering;
2988 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2989 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2991 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2993 /* Note that the block of subscript information for an array type also
2994 includes information about the element type of type given array type. */
2996 static void
2997 subscript_data_attribute (type)
2998 tree type;
3000 unsigned dimension_number;
3001 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3002 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3004 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
3005 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
3006 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
3007 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3008 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3010 /* The GNU compilers represent multidimensional array types as sequences
3011 of one dimensional array types whose element types are themselves array
3012 types. Here we squish that down, so that each multidimensional array
3013 type gets only one array_type DIE in the Dwarf debugging info. The
3014 draft Dwarf specification say that we are allowed to do this kind
3015 of compression in C (because there is no difference between an
3016 array or arrays and a multidimensional array in C) but for other
3017 source languages (e.g. Ada) we probably shouldn't do this. */
3019 for (dimension_number = 0;
3020 TREE_CODE (type) == ARRAY_TYPE;
3021 type = TREE_TYPE (type), dimension_number++)
3023 tree domain = TYPE_DOMAIN (type);
3025 /* Arrays come in three flavors. Unspecified bounds, fixed
3026 bounds, and (in GNU C only) variable bounds. Handle all
3027 three forms here. */
3029 if (domain)
3031 /* We have an array type with specified bounds. */
3033 tree lower = TYPE_MIN_VALUE (domain);
3034 tree upper = TYPE_MAX_VALUE (domain);
3036 /* Handle only fundamental types as index types for now. */
3037 if (! type_is_fundamental (domain))
3038 abort ();
3040 /* Output the representation format byte for this dimension. */
3041 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
3042 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
3043 upper && TREE_CODE (upper) == INTEGER_CST));
3045 /* Output the index type for this dimension. */
3046 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3047 fundamental_type_code (domain));
3049 /* Output the representation for the lower bound. */
3050 output_bound_representation (lower, dimension_number, 'l');
3052 /* Output the representation for the upper bound. */
3053 if (upper)
3054 output_bound_representation (upper, dimension_number, 'u');
3055 else
3056 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3058 else
3060 /* We have an array type with an unspecified length. For C and
3061 C++ we can assume that this really means that (a) the index
3062 type is an integral type, and (b) the lower bound is zero.
3063 Note that Dwarf defines the representation of an unspecified
3064 (upper) bound as being a zero-length location description. */
3066 /* Output the array-bounds format byte. */
3068 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
3070 /* Output the (assumed) index type. */
3072 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
3074 /* Output the (assumed) lower bound (constant) value. */
3076 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3078 /* Output the (empty) location description for the upper bound. */
3080 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3084 /* Output the prefix byte that says that the element type is coming up. */
3086 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
3088 /* Output a representation of the type of the elements of this array type. */
3090 type_attribute (type, 0, 0);
3092 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3095 static void
3096 byte_size_attribute (tree_node)
3097 tree tree_node;
3099 unsigned size;
3101 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
3102 switch (TREE_CODE (tree_node))
3104 case ERROR_MARK:
3105 size = 0;
3106 break;
3108 case ENUMERAL_TYPE:
3109 case RECORD_TYPE:
3110 case UNION_TYPE:
3111 case QUAL_UNION_TYPE:
3112 case ARRAY_TYPE:
3113 size = int_size_in_bytes (tree_node);
3114 break;
3116 case FIELD_DECL:
3117 /* For a data member of a struct or union, the AT_byte_size is
3118 generally given as the number of bytes normally allocated for
3119 an object of the *declared* type of the member itself. This
3120 is true even for bit-fields. */
3121 size = simple_type_size_in_bits (field_type (tree_node))
3122 / BITS_PER_UNIT;
3123 break;
3125 default:
3126 abort ();
3129 /* Note that `size' might be -1 when we get to this point. If it
3130 is, that indicates that the byte size of the entity in question
3131 is variable. We have no good way of expressing this fact in Dwarf
3132 at the present time, so just let the -1 pass on through. */
3134 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
3137 /* For a FIELD_DECL node which represents a bit-field, output an attribute
3138 which specifies the distance in bits from the highest order bit of the
3139 "containing object" for the bit-field to the highest order bit of the
3140 bit-field itself.
3142 For any given bit-field, the "containing object" is a hypothetical
3143 object (of some integral or enum type) within which the given bit-field
3144 lives. The type of this hypothetical "containing object" is always the
3145 same as the declared type of the individual bit-field itself.
3147 The determination of the exact location of the "containing object" for
3148 a bit-field is rather complicated. It's handled by the `field_byte_offset'
3149 function (above).
3151 Note that it is the size (in bytes) of the hypothetical "containing
3152 object" which will be given in the AT_byte_size attribute for this
3153 bit-field. (See `byte_size_attribute' above.) */
3155 static inline void
3156 bit_offset_attribute (decl)
3157 tree decl;
3159 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
3160 tree type = DECL_BIT_FIELD_TYPE (decl);
3161 HOST_WIDE_INT bitpos_int;
3162 HOST_WIDE_INT highest_order_object_bit_offset;
3163 HOST_WIDE_INT highest_order_field_bit_offset;
3164 HOST_WIDE_INT bit_offset;
3166 /* Must be a bit field. */
3167 if (!type
3168 || TREE_CODE (decl) != FIELD_DECL)
3169 abort ();
3171 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
3172 if we encounter such things, just return without generating any
3173 attribute whatsoever. */
3175 if (! host_integerp (bit_position (decl), 0)
3176 || ! host_integerp (DECL_SIZE (decl), 1))
3177 return;
3179 bitpos_int = int_bit_position (decl);
3181 /* Note that the bit offset is always the distance (in bits) from the
3182 highest-order bit of the "containing object" to the highest-order
3183 bit of the bit-field itself. Since the "high-order end" of any
3184 object or field is different on big-endian and little-endian machines,
3185 the computation below must take account of these differences. */
3187 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
3188 highest_order_field_bit_offset = bitpos_int;
3190 if (! BYTES_BIG_ENDIAN)
3192 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
3193 highest_order_object_bit_offset += simple_type_size_in_bits (type);
3196 bit_offset =
3197 (! BYTES_BIG_ENDIAN
3198 ? highest_order_object_bit_offset - highest_order_field_bit_offset
3199 : highest_order_field_bit_offset - highest_order_object_bit_offset);
3201 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
3202 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
3205 /* For a FIELD_DECL node which represents a bit field, output an attribute
3206 which specifies the length in bits of the given field. */
3208 static inline void
3209 bit_size_attribute (decl)
3210 tree decl;
3212 /* Must be a field and a bit field. */
3213 if (TREE_CODE (decl) != FIELD_DECL
3214 || ! DECL_BIT_FIELD_TYPE (decl))
3215 abort ();
3217 if (host_integerp (DECL_SIZE (decl), 1))
3219 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
3220 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3221 tree_low_cst (DECL_SIZE (decl), 1));
3225 /* The following routine outputs the `element_list' attribute for enumeration
3226 type DIEs. The element_lits attribute includes the names and values of
3227 all of the enumeration constants associated with the given enumeration
3228 type. */
3230 static inline void
3231 element_list_attribute (element)
3232 tree element;
3234 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3235 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3237 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
3238 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
3239 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
3240 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3241 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3243 /* Here we output a list of value/name pairs for each enumeration constant
3244 defined for this enumeration type (as required), but we do it in REVERSE
3245 order. The order is the one required by the draft #5 Dwarf specification
3246 published by the UI/PLSIG. */
3248 output_enumeral_list (element); /* Recursively output the whole list. */
3250 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3253 /* Generate an AT_stmt_list attribute. These are normally present only in
3254 DIEs with a TAG_compile_unit tag. */
3256 static inline void
3257 stmt_list_attribute (label)
3258 const char *label;
3260 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
3261 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3262 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3265 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
3266 for a subroutine DIE. */
3268 static inline void
3269 low_pc_attribute (asm_low_label)
3270 const char *asm_low_label;
3272 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
3273 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
3276 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
3277 subroutine DIE. */
3279 static inline void
3280 high_pc_attribute (asm_high_label)
3281 const char *asm_high_label;
3283 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
3284 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
3287 /* Generate an AT_body_begin attribute for a subroutine DIE. */
3289 static inline void
3290 body_begin_attribute (asm_begin_label)
3291 const char *asm_begin_label;
3293 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
3294 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
3297 /* Generate an AT_body_end attribute for a subroutine DIE. */
3299 static inline void
3300 body_end_attribute (asm_end_label)
3301 const char *asm_end_label;
3303 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
3304 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
3307 /* Generate an AT_language attribute given a LANG value. These attributes
3308 are used only within TAG_compile_unit DIEs. */
3310 static inline void
3311 language_attribute (language_code)
3312 unsigned language_code;
3314 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
3315 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
3318 static inline void
3319 member_attribute (context)
3320 tree context;
3322 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3324 /* Generate this attribute only for members in C++. */
3326 if (context != NULL && is_tagged_type (context))
3328 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
3329 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
3330 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3334 #if 0
3335 static inline void
3336 string_length_attribute (upper_bound)
3337 tree upper_bound;
3339 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3340 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3342 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
3343 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
3344 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
3345 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3346 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3347 output_bound_representation (upper_bound, 0, 'u');
3348 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3350 #endif
3352 static inline void
3353 comp_dir_attribute (dirname)
3354 const char *dirname;
3356 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
3357 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
3360 static inline void
3361 sf_names_attribute (sf_names_start_label)
3362 const char *sf_names_start_label;
3364 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
3365 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3366 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
3369 static inline void
3370 src_info_attribute (src_info_start_label)
3371 const char *src_info_start_label;
3373 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
3374 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3375 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
3378 static inline void
3379 mac_info_attribute (mac_info_start_label)
3380 const char *mac_info_start_label;
3382 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
3383 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3384 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
3387 static inline void
3388 prototyped_attribute (func_type)
3389 tree func_type;
3391 if ((strcmp (lang_hooks.name, "GNU C") == 0)
3392 && (TYPE_ARG_TYPES (func_type) != NULL))
3394 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
3395 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3399 static inline void
3400 producer_attribute (producer)
3401 const char *producer;
3403 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
3404 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
3407 static inline void
3408 inline_attribute (decl)
3409 tree decl;
3411 if (DECL_INLINE (decl))
3413 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3414 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3418 static inline void
3419 containing_type_attribute (containing_type)
3420 tree containing_type;
3422 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3424 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3425 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3426 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3429 static inline void
3430 abstract_origin_attribute (origin)
3431 tree origin;
3433 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3435 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3436 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3438 case 'd':
3439 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3440 break;
3442 case 't':
3443 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3444 break;
3446 default:
3447 abort (); /* Should never happen. */
3450 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3453 #ifdef DWARF_DECL_COORDINATES
3454 static inline void
3455 src_coords_attribute (src_fileno, src_lineno)
3456 unsigned src_fileno;
3457 unsigned src_lineno;
3459 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3460 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3461 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3463 #endif /* defined(DWARF_DECL_COORDINATES) */
3465 static inline void
3466 pure_or_virtual_attribute (func_decl)
3467 tree func_decl;
3469 if (DECL_VIRTUAL_P (func_decl))
3471 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3472 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3473 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3474 else
3475 #endif
3476 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3477 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3481 /************************* end of attributes *****************************/
3483 /********************* utility routines for DIEs *************************/
3485 /* Output an AT_name attribute and an AT_src_coords attribute for the
3486 given decl, but only if it actually has a name. */
3488 static void
3489 name_and_src_coords_attributes (decl)
3490 tree decl;
3492 tree decl_name = DECL_NAME (decl);
3494 if (decl_name && IDENTIFIER_POINTER (decl_name))
3496 name_attribute (IDENTIFIER_POINTER (decl_name));
3497 #ifdef DWARF_DECL_COORDINATES
3499 register unsigned file_index;
3501 /* This is annoying, but we have to pop out of the .debug section
3502 for a moment while we call `lookup_filename' because calling it
3503 may cause a temporary switch into the .debug_sfnames section and
3504 most svr4 assemblers are not smart enough to be able to nest
3505 section switches to any depth greater than one. Note that we
3506 also can't skirt this issue by delaying all output to the
3507 .debug_sfnames section unit the end of compilation because that
3508 would cause us to have inter-section forward references and
3509 Fred Fish sez that m68k/svr4 assemblers botch those. */
3511 ASM_OUTPUT_POP_SECTION (asm_out_file);
3512 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3513 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3515 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3517 #endif /* defined(DWARF_DECL_COORDINATES) */
3521 /* Many forms of DIEs contain a "type description" part. The following
3522 routine writes out these "type descriptor" parts. */
3524 static void
3525 type_attribute (type, decl_const, decl_volatile)
3526 tree type;
3527 int decl_const;
3528 int decl_volatile;
3530 enum tree_code code = TREE_CODE (type);
3531 int root_type_modified;
3533 if (code == ERROR_MARK)
3534 return;
3536 /* Handle a special case. For functions whose return type is void,
3537 we generate *no* type attribute. (Note that no object may have
3538 type `void', so this only applies to function return types. */
3540 if (code == VOID_TYPE)
3541 return;
3543 /* If this is a subtype, find the underlying type. Eventually,
3544 this should write out the appropriate subtype info. */
3545 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3546 && TREE_TYPE (type) != 0)
3547 type = TREE_TYPE (type), code = TREE_CODE (type);
3549 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3550 || decl_const || decl_volatile
3551 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3553 if (type_is_fundamental (root_type (type)))
3555 if (root_type_modified)
3556 mod_fund_type_attribute (type, decl_const, decl_volatile);
3557 else
3558 fund_type_attribute (fundamental_type_code (type));
3560 else
3562 if (root_type_modified)
3563 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3564 else
3565 /* We have to get the type_main_variant here (and pass that to the
3566 `user_def_type_attribute' routine) because the ..._TYPE node we
3567 have might simply be a *copy* of some original type node (where
3568 the copy was created to help us keep track of typedef names)
3569 and that copy might have a different TYPE_UID from the original
3570 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3571 is labeling a given type DIE for future reference, it always and
3572 only creates labels for DIEs representing *main variants*, and it
3573 never even knows about non-main-variants.) */
3574 user_def_type_attribute (type_main_variant (type));
3578 /* Given a tree pointer to a struct, class, union, or enum type node, return
3579 a pointer to the (string) tag name for the given type, or zero if the
3580 type was declared without a tag. */
3582 static const char *
3583 type_tag (type)
3584 tree type;
3586 const char *name = 0;
3588 if (TYPE_NAME (type) != 0)
3590 tree t = 0;
3592 /* Find the IDENTIFIER_NODE for the type name. */
3593 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3594 t = TYPE_NAME (type);
3596 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3597 a TYPE_DECL node, regardless of whether or not a `typedef' was
3598 involved. */
3599 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3600 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3601 t = DECL_NAME (TYPE_NAME (type));
3603 /* Now get the name as a string, or invent one. */
3604 if (t != 0)
3605 name = IDENTIFIER_POINTER (t);
3608 return (name == 0 || *name == '\0') ? 0 : name;
3611 static inline void
3612 dienum_push ()
3614 /* Start by checking if the pending_sibling_stack needs to be expanded.
3615 If necessary, expand it. */
3617 if (pending_siblings == pending_siblings_allocated)
3619 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3620 pending_sibling_stack
3621 = (unsigned *) xrealloc (pending_sibling_stack,
3622 pending_siblings_allocated * sizeof(unsigned));
3625 pending_siblings++;
3626 NEXT_DIE_NUM = next_unused_dienum++;
3629 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3630 NEXT_DIE_NUM. */
3632 static inline void
3633 dienum_pop ()
3635 pending_siblings--;
3638 static inline tree
3639 member_declared_type (member)
3640 tree member;
3642 return (DECL_BIT_FIELD_TYPE (member))
3643 ? DECL_BIT_FIELD_TYPE (member)
3644 : TREE_TYPE (member);
3647 /* Get the function's label, as described by its RTL.
3648 This may be different from the DECL_NAME name used
3649 in the source file. */
3651 static const char *
3652 function_start_label (decl)
3653 tree decl;
3655 rtx x;
3656 const char *fnname;
3658 x = DECL_RTL (decl);
3659 if (GET_CODE (x) != MEM)
3660 abort ();
3661 x = XEXP (x, 0);
3662 if (GET_CODE (x) != SYMBOL_REF)
3663 abort ();
3664 fnname = XSTR (x, 0);
3665 return fnname;
3669 /******************************* DIEs ************************************/
3671 /* Output routines for individual types of DIEs. */
3673 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3675 static void
3676 output_array_type_die (arg)
3677 void *arg;
3679 tree type = arg;
3681 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3682 sibling_attribute ();
3683 equate_type_number_to_die_number (type);
3684 member_attribute (TYPE_CONTEXT (type));
3686 /* I believe that we can default the array ordering. SDB will probably
3687 do the right things even if AT_ordering is not present. It's not
3688 even an issue until we start to get into multidimensional arrays
3689 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3690 dimensional arrays, then we'll have to put the AT_ordering attribute
3691 back in. (But if and when we find out that we need to put these in,
3692 we will only do so for multidimensional arrays. After all, we don't
3693 want to waste space in the .debug section now do we?) */
3695 #ifdef USE_ORDERING_ATTRIBUTE
3696 ordering_attribute (ORD_row_major);
3697 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3699 subscript_data_attribute (type);
3702 static void
3703 output_set_type_die (arg)
3704 void *arg;
3706 tree type = arg;
3708 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3709 sibling_attribute ();
3710 equate_type_number_to_die_number (type);
3711 member_attribute (TYPE_CONTEXT (type));
3712 type_attribute (TREE_TYPE (type), 0, 0);
3715 #if 0
3716 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3718 static void
3719 output_entry_point_die (arg)
3720 void *arg;
3722 tree decl = arg;
3723 tree origin = decl_ultimate_origin (decl);
3725 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3726 sibling_attribute ();
3727 dienum_push ();
3728 if (origin != NULL)
3729 abstract_origin_attribute (origin);
3730 else
3732 name_and_src_coords_attributes (decl);
3733 member_attribute (DECL_CONTEXT (decl));
3734 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3736 if (DECL_ABSTRACT (decl))
3737 equate_decl_number_to_die_number (decl);
3738 else
3739 low_pc_attribute (function_start_label (decl));
3741 #endif
3743 /* Output a DIE to represent an inlined instance of an enumeration type. */
3745 static void
3746 output_inlined_enumeration_type_die (arg)
3747 void *arg;
3749 tree type = arg;
3751 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3752 sibling_attribute ();
3753 if (!TREE_ASM_WRITTEN (type))
3754 abort ();
3755 abstract_origin_attribute (type);
3758 /* Output a DIE to represent an inlined instance of a structure type. */
3760 static void
3761 output_inlined_structure_type_die (arg)
3762 void *arg;
3764 tree type = arg;
3766 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3767 sibling_attribute ();
3768 if (!TREE_ASM_WRITTEN (type))
3769 abort ();
3770 abstract_origin_attribute (type);
3773 /* Output a DIE to represent an inlined instance of a union type. */
3775 static void
3776 output_inlined_union_type_die (arg)
3777 void *arg;
3779 tree type = arg;
3781 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3782 sibling_attribute ();
3783 if (!TREE_ASM_WRITTEN (type))
3784 abort ();
3785 abstract_origin_attribute (type);
3788 /* Output a DIE to represent an enumeration type. Note that these DIEs
3789 include all of the information about the enumeration values also.
3790 This information is encoded into the element_list attribute. */
3792 static void
3793 output_enumeration_type_die (arg)
3794 void *arg;
3796 tree type = arg;
3798 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3799 sibling_attribute ();
3800 equate_type_number_to_die_number (type);
3801 name_attribute (type_tag (type));
3802 member_attribute (TYPE_CONTEXT (type));
3804 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3805 given enum type is incomplete, do not generate the AT_byte_size
3806 attribute or the AT_element_list attribute. */
3808 if (COMPLETE_TYPE_P (type))
3810 byte_size_attribute (type);
3811 element_list_attribute (TYPE_FIELDS (type));
3815 /* Output a DIE to represent either a real live formal parameter decl or
3816 to represent just the type of some formal parameter position in some
3817 function type.
3819 Note that this routine is a bit unusual because its argument may be
3820 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3821 represents an inlining of some PARM_DECL) or else some sort of a
3822 ..._TYPE node. If it's the former then this function is being called
3823 to output a DIE to represent a formal parameter object (or some inlining
3824 thereof). If it's the latter, then this function is only being called
3825 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3826 formal argument type of some subprogram type. */
3828 static void
3829 output_formal_parameter_die (arg)
3830 void *arg;
3832 tree node = arg;
3834 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3835 sibling_attribute ();
3837 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3839 case 'd': /* We were called with some kind of a ..._DECL node. */
3841 register tree origin = decl_ultimate_origin (node);
3843 if (origin != NULL)
3844 abstract_origin_attribute (origin);
3845 else
3847 name_and_src_coords_attributes (node);
3848 type_attribute (TREE_TYPE (node),
3849 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3851 if (DECL_ABSTRACT (node))
3852 equate_decl_number_to_die_number (node);
3853 else
3854 location_or_const_value_attribute (node);
3856 break;
3858 case 't': /* We were called with some kind of a ..._TYPE node. */
3859 type_attribute (node, 0, 0);
3860 break;
3862 default:
3863 abort (); /* Should never happen. */
3867 /* Output a DIE to represent a declared function (either file-scope
3868 or block-local) which has "external linkage" (according to ANSI-C). */
3870 static void
3871 output_global_subroutine_die (arg)
3872 void *arg;
3874 tree decl = arg;
3875 tree origin = decl_ultimate_origin (decl);
3877 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3878 sibling_attribute ();
3879 dienum_push ();
3880 if (origin != NULL)
3881 abstract_origin_attribute (origin);
3882 else
3884 tree type = TREE_TYPE (decl);
3886 name_and_src_coords_attributes (decl);
3887 inline_attribute (decl);
3888 prototyped_attribute (type);
3889 member_attribute (DECL_CONTEXT (decl));
3890 type_attribute (TREE_TYPE (type), 0, 0);
3891 pure_or_virtual_attribute (decl);
3893 if (DECL_ABSTRACT (decl))
3894 equate_decl_number_to_die_number (decl);
3895 else
3897 if (! DECL_EXTERNAL (decl) && ! in_class
3898 && decl == current_function_decl)
3900 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3902 low_pc_attribute (function_start_label (decl));
3903 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3904 high_pc_attribute (label);
3905 if (use_gnu_debug_info_extensions)
3907 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3908 body_begin_attribute (label);
3909 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3910 body_end_attribute (label);
3916 /* Output a DIE to represent a declared data object (either file-scope
3917 or block-local) which has "external linkage" (according to ANSI-C). */
3919 static void
3920 output_global_variable_die (arg)
3921 void *arg;
3923 tree decl = arg;
3924 tree origin = decl_ultimate_origin (decl);
3926 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3927 sibling_attribute ();
3928 if (origin != NULL)
3929 abstract_origin_attribute (origin);
3930 else
3932 name_and_src_coords_attributes (decl);
3933 member_attribute (DECL_CONTEXT (decl));
3934 type_attribute (TREE_TYPE (decl),
3935 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3937 if (DECL_ABSTRACT (decl))
3938 equate_decl_number_to_die_number (decl);
3939 else
3941 if (! DECL_EXTERNAL (decl) && ! in_class
3942 && current_function_decl == decl_function_context (decl))
3943 location_or_const_value_attribute (decl);
3947 static void
3948 output_label_die (arg)
3949 void *arg;
3951 tree decl = arg;
3952 tree origin = decl_ultimate_origin (decl);
3954 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3955 sibling_attribute ();
3956 if (origin != NULL)
3957 abstract_origin_attribute (origin);
3958 else
3959 name_and_src_coords_attributes (decl);
3960 if (DECL_ABSTRACT (decl))
3961 equate_decl_number_to_die_number (decl);
3962 else
3964 rtx insn = DECL_RTL (decl);
3966 /* Deleted labels are programmer specified labels which have been
3967 eliminated because of various optimisations. We still emit them
3968 here so that it is possible to put breakpoints on them. */
3969 if (GET_CODE (insn) == CODE_LABEL
3970 || ((GET_CODE (insn) == NOTE
3971 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
3973 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3975 /* When optimization is enabled (via -O) some parts of the compiler
3976 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3977 represent source-level labels which were explicitly declared by
3978 the user. This really shouldn't be happening though, so catch
3979 it if it ever does happen. */
3981 if (INSN_DELETED_P (insn))
3982 abort (); /* Should never happen. */
3984 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
3985 low_pc_attribute (label);
3990 static void
3991 output_lexical_block_die (arg)
3992 void *arg;
3994 tree stmt = arg;
3996 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3997 sibling_attribute ();
3998 dienum_push ();
3999 if (! BLOCK_ABSTRACT (stmt))
4001 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4002 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4004 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4005 low_pc_attribute (begin_label);
4006 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4007 high_pc_attribute (end_label);
4011 static void
4012 output_inlined_subroutine_die (arg)
4013 void *arg;
4015 tree stmt = arg;
4017 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
4018 sibling_attribute ();
4019 dienum_push ();
4020 abstract_origin_attribute (block_ultimate_origin (stmt));
4021 if (! BLOCK_ABSTRACT (stmt))
4023 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4024 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4026 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4027 low_pc_attribute (begin_label);
4028 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4029 high_pc_attribute (end_label);
4033 /* Output a DIE to represent a declared data object (either file-scope
4034 or block-local) which has "internal linkage" (according to ANSI-C). */
4036 static void
4037 output_local_variable_die (arg)
4038 void *arg;
4040 tree decl = arg;
4041 tree origin = decl_ultimate_origin (decl);
4043 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
4044 sibling_attribute ();
4045 if (origin != NULL)
4046 abstract_origin_attribute (origin);
4047 else
4049 name_and_src_coords_attributes (decl);
4050 member_attribute (DECL_CONTEXT (decl));
4051 type_attribute (TREE_TYPE (decl),
4052 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4054 if (DECL_ABSTRACT (decl))
4055 equate_decl_number_to_die_number (decl);
4056 else
4057 location_or_const_value_attribute (decl);
4060 static void
4061 output_member_die (arg)
4062 void *arg;
4064 tree decl = arg;
4066 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
4067 sibling_attribute ();
4068 name_and_src_coords_attributes (decl);
4069 member_attribute (DECL_CONTEXT (decl));
4070 type_attribute (member_declared_type (decl),
4071 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4072 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
4074 byte_size_attribute (decl);
4075 bit_size_attribute (decl);
4076 bit_offset_attribute (decl);
4078 data_member_location_attribute (decl);
4081 #if 0
4082 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
4083 modified types instead.
4085 We keep this code here just in case these types of DIEs may be
4086 needed to represent certain things in other languages (e.g. Pascal)
4087 someday. */
4089 static void
4090 output_pointer_type_die (arg)
4091 void *arg;
4093 tree type = arg;
4095 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
4096 sibling_attribute ();
4097 equate_type_number_to_die_number (type);
4098 member_attribute (TYPE_CONTEXT (type));
4099 type_attribute (TREE_TYPE (type), 0, 0);
4102 static void
4103 output_reference_type_die (arg)
4104 void *arg;
4106 tree type = arg;
4108 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
4109 sibling_attribute ();
4110 equate_type_number_to_die_number (type);
4111 member_attribute (TYPE_CONTEXT (type));
4112 type_attribute (TREE_TYPE (type), 0, 0);
4114 #endif
4116 static void
4117 output_ptr_to_mbr_type_die (arg)
4118 void *arg;
4120 tree type = arg;
4122 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
4123 sibling_attribute ();
4124 equate_type_number_to_die_number (type);
4125 member_attribute (TYPE_CONTEXT (type));
4126 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
4127 type_attribute (TREE_TYPE (type), 0, 0);
4130 static void
4131 output_compile_unit_die (arg)
4132 void *arg;
4134 const char *main_input_filename = arg;
4135 const char *language_string = lang_hooks.name;
4137 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
4138 sibling_attribute ();
4139 dienum_push ();
4140 name_attribute (main_input_filename);
4143 char producer[250];
4145 sprintf (producer, "%s %s", language_string, version_string);
4146 producer_attribute (producer);
4149 if (strcmp (language_string, "GNU C++") == 0)
4150 language_attribute (LANG_C_PLUS_PLUS);
4151 else if (strcmp (language_string, "GNU Ada") == 0)
4152 language_attribute (LANG_ADA83);
4153 else if (strcmp (language_string, "GNU F77") == 0)
4154 language_attribute (LANG_FORTRAN77);
4155 else if (strcmp (language_string, "GNU Pascal") == 0)
4156 language_attribute (LANG_PASCAL83);
4157 else if (strcmp (language_string, "GNU Java") == 0)
4158 language_attribute (LANG_JAVA);
4159 else if (flag_traditional)
4160 language_attribute (LANG_C);
4161 else
4162 language_attribute (LANG_C89);
4163 low_pc_attribute (TEXT_BEGIN_LABEL);
4164 high_pc_attribute (TEXT_END_LABEL);
4165 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4166 stmt_list_attribute (LINE_BEGIN_LABEL);
4167 last_filename = xstrdup (main_input_filename);
4170 const char *wd = getpwd ();
4171 if (wd)
4172 comp_dir_attribute (wd);
4175 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
4177 sf_names_attribute (SFNAMES_BEGIN_LABEL);
4178 src_info_attribute (SRCINFO_BEGIN_LABEL);
4179 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4180 mac_info_attribute (MACINFO_BEGIN_LABEL);
4184 static void
4185 output_string_type_die (arg)
4186 void *arg;
4188 tree type = arg;
4190 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
4191 sibling_attribute ();
4192 equate_type_number_to_die_number (type);
4193 member_attribute (TYPE_CONTEXT (type));
4194 /* this is a fixed length string */
4195 byte_size_attribute (type);
4198 static void
4199 output_inheritance_die (arg)
4200 void *arg;
4202 tree binfo = arg;
4204 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
4205 sibling_attribute ();
4206 type_attribute (BINFO_TYPE (binfo), 0, 0);
4207 data_member_location_attribute (binfo);
4208 if (TREE_VIA_VIRTUAL (binfo))
4210 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
4211 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4213 if (TREE_VIA_PUBLIC (binfo))
4215 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
4216 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4218 else if (TREE_VIA_PROTECTED (binfo))
4220 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
4221 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4225 static void
4226 output_structure_type_die (arg)
4227 void *arg;
4229 tree type = arg;
4231 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
4232 sibling_attribute ();
4233 equate_type_number_to_die_number (type);
4234 name_attribute (type_tag (type));
4235 member_attribute (TYPE_CONTEXT (type));
4237 /* If this type has been completed, then give it a byte_size attribute
4238 and prepare to give a list of members. Otherwise, don't do either of
4239 these things. In the latter case, we will not be generating a list
4240 of members (since we don't have any idea what they might be for an
4241 incomplete type). */
4243 if (COMPLETE_TYPE_P (type))
4245 dienum_push ();
4246 byte_size_attribute (type);
4250 /* Output a DIE to represent a declared function (either file-scope
4251 or block-local) which has "internal linkage" (according to ANSI-C). */
4253 static void
4254 output_local_subroutine_die (arg)
4255 void *arg;
4257 tree decl = arg;
4258 tree origin = decl_ultimate_origin (decl);
4260 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
4261 sibling_attribute ();
4262 dienum_push ();
4263 if (origin != NULL)
4264 abstract_origin_attribute (origin);
4265 else
4267 tree type = TREE_TYPE (decl);
4269 name_and_src_coords_attributes (decl);
4270 inline_attribute (decl);
4271 prototyped_attribute (type);
4272 member_attribute (DECL_CONTEXT (decl));
4273 type_attribute (TREE_TYPE (type), 0, 0);
4274 pure_or_virtual_attribute (decl);
4276 if (DECL_ABSTRACT (decl))
4277 equate_decl_number_to_die_number (decl);
4278 else
4280 /* Avoid getting screwed up in cases where a function was declared
4281 static but where no definition was ever given for it. */
4283 if (TREE_ASM_WRITTEN (decl))
4285 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4286 low_pc_attribute (function_start_label (decl));
4287 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4288 high_pc_attribute (label);
4289 if (use_gnu_debug_info_extensions)
4291 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
4292 body_begin_attribute (label);
4293 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
4294 body_end_attribute (label);
4300 static void
4301 output_subroutine_type_die (arg)
4302 void *arg;
4304 tree type = arg;
4305 tree return_type = TREE_TYPE (type);
4307 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
4308 sibling_attribute ();
4309 dienum_push ();
4310 equate_type_number_to_die_number (type);
4311 prototyped_attribute (type);
4312 member_attribute (TYPE_CONTEXT (type));
4313 type_attribute (return_type, 0, 0);
4316 static void
4317 output_typedef_die (arg)
4318 void *arg;
4320 tree decl = arg;
4321 tree origin = decl_ultimate_origin (decl);
4323 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
4324 sibling_attribute ();
4325 if (origin != NULL)
4326 abstract_origin_attribute (origin);
4327 else
4329 name_and_src_coords_attributes (decl);
4330 member_attribute (DECL_CONTEXT (decl));
4331 type_attribute (TREE_TYPE (decl),
4332 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4334 if (DECL_ABSTRACT (decl))
4335 equate_decl_number_to_die_number (decl);
4338 static void
4339 output_union_type_die (arg)
4340 void *arg;
4342 tree type = arg;
4344 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
4345 sibling_attribute ();
4346 equate_type_number_to_die_number (type);
4347 name_attribute (type_tag (type));
4348 member_attribute (TYPE_CONTEXT (type));
4350 /* If this type has been completed, then give it a byte_size attribute
4351 and prepare to give a list of members. Otherwise, don't do either of
4352 these things. In the latter case, we will not be generating a list
4353 of members (since we don't have any idea what they might be for an
4354 incomplete type). */
4356 if (COMPLETE_TYPE_P (type))
4358 dienum_push ();
4359 byte_size_attribute (type);
4363 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
4364 at the end of an (ANSI prototyped) formal parameters list. */
4366 static void
4367 output_unspecified_parameters_die (arg)
4368 void *arg;
4370 tree decl_or_type = arg;
4372 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
4373 sibling_attribute ();
4375 /* This kludge is here only for the sake of being compatible with what
4376 the USL CI5 C compiler does. The specification of Dwarf Version 1
4377 doesn't say that TAG_unspecified_parameters DIEs should contain any
4378 attributes other than the AT_sibling attribute, but they are certainly
4379 allowed to contain additional attributes, and the CI5 compiler
4380 generates AT_name, AT_fund_type, and AT_location attributes within
4381 TAG_unspecified_parameters DIEs which appear in the child lists for
4382 DIEs representing function definitions, so we do likewise here. */
4384 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
4386 name_attribute ("...");
4387 fund_type_attribute (FT_pointer);
4388 /* location_attribute (?); */
4392 static void
4393 output_padded_null_die (arg)
4394 void *arg ATTRIBUTE_UNUSED;
4396 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
4399 /*************************** end of DIEs *********************************/
4401 /* Generate some type of DIE. This routine generates the generic outer
4402 wrapper stuff which goes around all types of DIE's (regardless of their
4403 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
4404 DIE-length word, followed by the guts of the DIE itself. After the guts
4405 of the DIE, there must always be a terminator label for the DIE. */
4407 static void
4408 output_die (die_specific_output_function, param)
4409 void (*die_specific_output_function) PARAMS ((void *));
4410 void *param;
4412 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4413 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4415 current_dienum = NEXT_DIE_NUM;
4416 NEXT_DIE_NUM = next_unused_dienum;
4418 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4419 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4421 /* Write a label which will act as the name for the start of this DIE. */
4423 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4425 /* Write the DIE-length word. */
4427 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4429 /* Fill in the guts of the DIE. */
4431 next_unused_dienum++;
4432 die_specific_output_function (param);
4434 /* Write a label which will act as the name for the end of this DIE. */
4436 ASM_OUTPUT_LABEL (asm_out_file, end_label);
4439 static void
4440 end_sibling_chain ()
4442 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4444 current_dienum = NEXT_DIE_NUM;
4445 NEXT_DIE_NUM = next_unused_dienum;
4447 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4449 /* Write a label which will act as the name for the start of this DIE. */
4451 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4453 /* Write the DIE-length word. */
4455 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4457 dienum_pop ();
4460 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4461 TAG_unspecified_parameters DIE) to represent the types of the formal
4462 parameters as specified in some function type specification (except
4463 for those which appear as part of a function *definition*).
4465 Note that we must be careful here to output all of the parameter
4466 DIEs *before* we output any DIEs needed to represent the types of
4467 the formal parameters. This keeps svr4 SDB happy because it
4468 (incorrectly) thinks that the first non-parameter DIE it sees ends
4469 the formal parameter list. */
4471 static void
4472 output_formal_types (function_or_method_type)
4473 tree function_or_method_type;
4475 tree link;
4476 tree formal_type = NULL;
4477 tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4479 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4480 get bogus recursion when outputting tagged types local to a
4481 function declaration. */
4482 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4483 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4485 /* In the case where we are generating a formal types list for a C++
4486 non-static member function type, skip over the first thing on the
4487 TYPE_ARG_TYPES list because it only represents the type of the
4488 hidden `this pointer'. The debugger should be able to figure
4489 out (without being explicitly told) that this non-static member
4490 function type takes a `this pointer' and should be able to figure
4491 what the type of that hidden parameter is from the AT_member
4492 attribute of the parent TAG_subroutine_type DIE. */
4494 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4495 first_parm_type = TREE_CHAIN (first_parm_type);
4497 /* Make our first pass over the list of formal parameter types and output
4498 a TAG_formal_parameter DIE for each one. */
4500 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4502 formal_type = TREE_VALUE (link);
4503 if (formal_type == void_type_node)
4504 break;
4506 /* Output a (nameless) DIE to represent the formal parameter itself. */
4508 output_die (output_formal_parameter_die, formal_type);
4511 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4512 DIE to the end of the parameter list. */
4514 if (formal_type != void_type_node)
4515 output_die (output_unspecified_parameters_die, function_or_method_type);
4517 /* Make our second (and final) pass over the list of formal parameter types
4518 and output DIEs to represent those types (as necessary). */
4520 for (link = TYPE_ARG_TYPES (function_or_method_type);
4521 link;
4522 link = TREE_CHAIN (link))
4524 formal_type = TREE_VALUE (link);
4525 if (formal_type == void_type_node)
4526 break;
4528 output_type (formal_type, function_or_method_type);
4531 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4534 /* Remember a type in the pending_types_list. */
4536 static void
4537 pend_type (type)
4538 tree type;
4540 if (pending_types == pending_types_allocated)
4542 pending_types_allocated += PENDING_TYPES_INCREMENT;
4543 pending_types_list
4544 = (tree *) xrealloc (pending_types_list,
4545 sizeof (tree) * pending_types_allocated);
4547 pending_types_list[pending_types++] = type;
4549 /* Mark the pending type as having been output already (even though
4550 it hasn't been). This prevents the type from being added to the
4551 pending_types_list more than once. */
4553 TREE_ASM_WRITTEN (type) = 1;
4556 /* Return non-zero if it is legitimate to output DIEs to represent a
4557 given type while we are generating the list of child DIEs for some
4558 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4560 See the comments within the function for a description of when it is
4561 considered legitimate to output DIEs for various kinds of types.
4563 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4564 or it may point to a BLOCK node (for types local to a block), or to a
4565 FUNCTION_DECL node (for types local to the heading of some function
4566 definition), or to a FUNCTION_TYPE node (for types local to the
4567 prototyped parameter list of a function type specification), or to a
4568 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4569 (in the case of C++ nested types).
4571 The `scope' parameter should likewise be NULL or should point to a
4572 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4573 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4575 This function is used only for deciding when to "pend" and when to
4576 "un-pend" types to/from the pending_types_list.
4578 Note that we sometimes make use of this "type pending" feature in a
4579 rather twisted way to temporarily delay the production of DIEs for the
4580 types of formal parameters. (We do this just to make svr4 SDB happy.)
4581 It order to delay the production of DIEs representing types of formal
4582 parameters, callers of this function supply `fake_containing_scope' as
4583 the `scope' parameter to this function. Given that fake_containing_scope
4584 is a tagged type which is *not* the containing scope for *any* other type,
4585 the desired effect is achieved, i.e. output of DIEs representing types
4586 is temporarily suspended, and any type DIEs which would have otherwise
4587 been output are instead placed onto the pending_types_list. Later on,
4588 we force these (temporarily pended) types to be output simply by calling
4589 `output_pending_types_for_scope' with an actual argument equal to the
4590 true scope of the types we temporarily pended. */
4592 static inline int
4593 type_ok_for_scope (type, scope)
4594 tree type;
4595 tree scope;
4597 /* Tagged types (i.e. struct, union, and enum types) must always be
4598 output only in the scopes where they actually belong (or else the
4599 scoping of their own tag names and the scoping of their member
4600 names will be incorrect). Non-tagged-types on the other hand can
4601 generally be output anywhere, except that svr4 SDB really doesn't
4602 want to see them nested within struct or union types, so here we
4603 say it is always OK to immediately output any such a (non-tagged)
4604 type, so long as we are not within such a context. Note that the
4605 only kinds of non-tagged types which we will be dealing with here
4606 (for C and C++ anyway) will be array types and function types. */
4608 return is_tagged_type (type)
4609 ? (TYPE_CONTEXT (type) == scope
4610 /* Ignore namespaces for the moment. */
4611 || (scope == NULL_TREE
4612 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4613 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4614 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4615 : (scope == NULL_TREE || ! is_tagged_type (scope));
4618 /* Output any pending types (from the pending_types list) which we can output
4619 now (taking into account the scope that we are working on now).
4621 For each type output, remove the given type from the pending_types_list
4622 *before* we try to output it.
4624 Note that we have to process the list in beginning-to-end order,
4625 because the call made here to output_type may cause yet more types
4626 to be added to the end of the list, and we may have to output some
4627 of them too. */
4629 static void
4630 output_pending_types_for_scope (containing_scope)
4631 tree containing_scope;
4633 unsigned i;
4635 for (i = 0; i < pending_types; )
4637 tree type = pending_types_list[i];
4639 if (type_ok_for_scope (type, containing_scope))
4641 tree *mover;
4642 tree *limit;
4644 pending_types--;
4645 limit = &pending_types_list[pending_types];
4646 for (mover = &pending_types_list[i]; mover < limit; mover++)
4647 *mover = *(mover+1);
4649 /* Un-mark the type as having been output already (because it
4650 hasn't been, really). Then call output_type to generate a
4651 Dwarf representation of it. */
4653 TREE_ASM_WRITTEN (type) = 0;
4654 output_type (type, containing_scope);
4656 /* Don't increment the loop counter in this case because we
4657 have shifted all of the subsequent pending types down one
4658 element in the pending_types_list array. */
4660 else
4661 i++;
4665 /* Remember a type in the incomplete_types_list. */
4667 static void
4668 add_incomplete_type (type)
4669 tree type;
4671 if (incomplete_types == incomplete_types_allocated)
4673 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4674 incomplete_types_list
4675 = (tree *) xrealloc (incomplete_types_list,
4676 sizeof (tree) * incomplete_types_allocated);
4679 incomplete_types_list[incomplete_types++] = type;
4682 /* Walk through the list of incomplete types again, trying once more to
4683 emit full debugging info for them. */
4685 static void
4686 retry_incomplete_types ()
4688 tree type;
4690 finalizing = 1;
4691 while (incomplete_types)
4693 --incomplete_types;
4694 type = incomplete_types_list[incomplete_types];
4695 output_type (type, NULL_TREE);
4699 static void
4700 output_type (type, containing_scope)
4701 tree type;
4702 tree containing_scope;
4704 if (type == 0 || type == error_mark_node)
4705 return;
4707 /* We are going to output a DIE to represent the unqualified version of
4708 this type (i.e. without any const or volatile qualifiers) so get
4709 the main variant (i.e. the unqualified version) of this type now. */
4711 type = type_main_variant (type);
4713 if (TREE_ASM_WRITTEN (type))
4715 if (finalizing && AGGREGATE_TYPE_P (type))
4717 tree member;
4719 /* Some of our nested types might not have been defined when we
4720 were written out before; force them out now. */
4722 for (member = TYPE_FIELDS (type); member;
4723 member = TREE_CHAIN (member))
4724 if (TREE_CODE (member) == TYPE_DECL
4725 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4726 output_type (TREE_TYPE (member), containing_scope);
4728 return;
4731 /* If this is a nested type whose containing class hasn't been
4732 written out yet, writing it out will cover this one, too. */
4734 if (TYPE_CONTEXT (type)
4735 && TYPE_P (TYPE_CONTEXT (type))
4736 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4738 output_type (TYPE_CONTEXT (type), containing_scope);
4739 return;
4742 /* Don't generate any DIEs for this type now unless it is OK to do so
4743 (based upon what `type_ok_for_scope' tells us). */
4745 if (! type_ok_for_scope (type, containing_scope))
4747 pend_type (type);
4748 return;
4751 switch (TREE_CODE (type))
4753 case ERROR_MARK:
4754 break;
4756 case VECTOR_TYPE:
4757 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4758 break;
4760 case POINTER_TYPE:
4761 case REFERENCE_TYPE:
4762 /* Prevent infinite recursion in cases where this is a recursive
4763 type. Recursive types are possible in Ada. */
4764 TREE_ASM_WRITTEN (type) = 1;
4765 /* For these types, all that is required is that we output a DIE
4766 (or a set of DIEs) to represent the "basis" type. */
4767 output_type (TREE_TYPE (type), containing_scope);
4768 break;
4770 case OFFSET_TYPE:
4771 /* This code is used for C++ pointer-to-data-member types. */
4772 /* Output a description of the relevant class type. */
4773 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4774 /* Output a description of the type of the object pointed to. */
4775 output_type (TREE_TYPE (type), containing_scope);
4776 /* Now output a DIE to represent this pointer-to-data-member type
4777 itself. */
4778 output_die (output_ptr_to_mbr_type_die, type);
4779 break;
4781 case SET_TYPE:
4782 output_type (TYPE_DOMAIN (type), containing_scope);
4783 output_die (output_set_type_die, type);
4784 break;
4786 case FILE_TYPE:
4787 output_type (TREE_TYPE (type), containing_scope);
4788 abort (); /* No way to represent these in Dwarf yet! */
4789 break;
4791 case FUNCTION_TYPE:
4792 /* Force out return type (in case it wasn't forced out already). */
4793 output_type (TREE_TYPE (type), containing_scope);
4794 output_die (output_subroutine_type_die, type);
4795 output_formal_types (type);
4796 end_sibling_chain ();
4797 break;
4799 case METHOD_TYPE:
4800 /* Force out return type (in case it wasn't forced out already). */
4801 output_type (TREE_TYPE (type), containing_scope);
4802 output_die (output_subroutine_type_die, type);
4803 output_formal_types (type);
4804 end_sibling_chain ();
4805 break;
4807 case ARRAY_TYPE:
4808 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4810 output_type (TREE_TYPE (type), containing_scope);
4811 output_die (output_string_type_die, type);
4813 else
4815 tree element_type;
4817 element_type = TREE_TYPE (type);
4818 while (TREE_CODE (element_type) == ARRAY_TYPE)
4819 element_type = TREE_TYPE (element_type);
4821 output_type (element_type, containing_scope);
4822 output_die (output_array_type_die, type);
4824 break;
4826 case ENUMERAL_TYPE:
4827 case RECORD_TYPE:
4828 case UNION_TYPE:
4829 case QUAL_UNION_TYPE:
4831 /* For a non-file-scope tagged type, we can always go ahead and
4832 output a Dwarf description of this type right now, even if
4833 the type in question is still incomplete, because if this
4834 local type *was* ever completed anywhere within its scope,
4835 that complete definition would already have been attached to
4836 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4837 node by the time we reach this point. That's true because of the
4838 way the front-end does its processing of file-scope declarations (of
4839 functions and class types) within which other types might be
4840 nested. The C and C++ front-ends always gobble up such "local
4841 scope" things en-mass before they try to output *any* debugging
4842 information for any of the stuff contained inside them and thus,
4843 we get the benefit here of what is (in effect) a pre-resolution
4844 of forward references to tagged types in local scopes.
4846 Note however that for file-scope tagged types we cannot assume
4847 that such pre-resolution of forward references has taken place.
4848 A given file-scope tagged type may appear to be incomplete when
4849 we reach this point, but it may yet be given a full definition
4850 (at file-scope) later on during compilation. In order to avoid
4851 generating a premature (and possibly incorrect) set of Dwarf
4852 DIEs for such (as yet incomplete) file-scope tagged types, we
4853 generate nothing at all for as-yet incomplete file-scope tagged
4854 types here unless we are making our special "finalization" pass
4855 for file-scope things at the very end of compilation. At that
4856 time, we will certainly know as much about each file-scope tagged
4857 type as we are ever going to know, so at that point in time, we
4858 can safely generate correct Dwarf descriptions for these file-
4859 scope tagged types. */
4861 if (!COMPLETE_TYPE_P (type)
4862 && (TYPE_CONTEXT (type) == NULL
4863 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4864 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4865 && !finalizing)
4867 /* We don't need to do this for function-local types. */
4868 if (! decl_function_context (TYPE_STUB_DECL (type)))
4869 add_incomplete_type (type);
4870 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4873 /* Prevent infinite recursion in cases where the type of some
4874 member of this type is expressed in terms of this type itself. */
4876 TREE_ASM_WRITTEN (type) = 1;
4878 /* Output a DIE to represent the tagged type itself. */
4880 switch (TREE_CODE (type))
4882 case ENUMERAL_TYPE:
4883 output_die (output_enumeration_type_die, type);
4884 return; /* a special case -- nothing left to do so just return */
4886 case RECORD_TYPE:
4887 output_die (output_structure_type_die, type);
4888 break;
4890 case UNION_TYPE:
4891 case QUAL_UNION_TYPE:
4892 output_die (output_union_type_die, type);
4893 break;
4895 default:
4896 abort (); /* Should never happen. */
4899 /* If this is not an incomplete type, output descriptions of
4900 each of its members.
4902 Note that as we output the DIEs necessary to represent the
4903 members of this record or union type, we will also be trying
4904 to output DIEs to represent the *types* of those members.
4905 However the `output_type' function (above) will specifically
4906 avoid generating type DIEs for member types *within* the list
4907 of member DIEs for this (containing) type except for those
4908 types (of members) which are explicitly marked as also being
4909 members of this (containing) type themselves. The g++ front-
4910 end can force any given type to be treated as a member of some
4911 other (containing) type by setting the TYPE_CONTEXT of the
4912 given (member) type to point to the TREE node representing the
4913 appropriate (containing) type.
4916 if (COMPLETE_TYPE_P (type))
4918 /* First output info about the base classes. */
4919 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4921 register tree bases = TYPE_BINFO_BASETYPES (type);
4922 register int n_bases = TREE_VEC_LENGTH (bases);
4923 register int i;
4925 for (i = 0; i < n_bases; i++)
4927 tree binfo = TREE_VEC_ELT (bases, i);
4928 output_type (BINFO_TYPE (binfo), containing_scope);
4929 output_die (output_inheritance_die, binfo);
4933 ++in_class;
4936 tree normal_member;
4938 /* Now output info about the data members and type members. */
4940 for (normal_member = TYPE_FIELDS (type);
4941 normal_member;
4942 normal_member = TREE_CHAIN (normal_member))
4943 output_decl (normal_member, type);
4947 tree func_member;
4949 /* Now output info about the function members (if any). */
4951 for (func_member = TYPE_METHODS (type);
4952 func_member;
4953 func_member = TREE_CHAIN (func_member))
4955 /* Don't include clones in the member list. */
4956 if (DECL_ABSTRACT_ORIGIN (func_member))
4957 continue;
4959 output_decl (func_member, type);
4963 --in_class;
4965 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4966 scopes (at least in C++) so we must now output any nested
4967 pending types which are local just to this type. */
4969 output_pending_types_for_scope (type);
4971 end_sibling_chain (); /* Terminate member chain. */
4974 break;
4976 case VOID_TYPE:
4977 case INTEGER_TYPE:
4978 case REAL_TYPE:
4979 case COMPLEX_TYPE:
4980 case BOOLEAN_TYPE:
4981 case CHAR_TYPE:
4982 break; /* No DIEs needed for fundamental types. */
4984 case LANG_TYPE: /* No Dwarf representation currently defined. */
4985 break;
4987 default:
4988 abort ();
4991 TREE_ASM_WRITTEN (type) = 1;
4994 static void
4995 output_tagged_type_instantiation (type)
4996 tree type;
4998 if (type == 0 || type == error_mark_node)
4999 return;
5001 /* We are going to output a DIE to represent the unqualified version of
5002 this type (i.e. without any const or volatile qualifiers) so make
5003 sure that we have the main variant (i.e. the unqualified version) of
5004 this type now. */
5006 if (type != type_main_variant (type))
5007 abort ();
5009 if (!TREE_ASM_WRITTEN (type))
5010 abort ();
5012 switch (TREE_CODE (type))
5014 case ERROR_MARK:
5015 break;
5017 case ENUMERAL_TYPE:
5018 output_die (output_inlined_enumeration_type_die, type);
5019 break;
5021 case RECORD_TYPE:
5022 output_die (output_inlined_structure_type_die, type);
5023 break;
5025 case UNION_TYPE:
5026 case QUAL_UNION_TYPE:
5027 output_die (output_inlined_union_type_die, type);
5028 break;
5030 default:
5031 abort (); /* Should never happen. */
5035 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
5036 the things which are local to the given block. */
5038 static void
5039 output_block (stmt, depth)
5040 tree stmt;
5041 int depth;
5043 int must_output_die = 0;
5044 tree origin;
5045 enum tree_code origin_code;
5047 /* Ignore blocks never really used to make RTL. */
5049 if (! stmt || ! TREE_USED (stmt)
5050 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
5051 return;
5053 /* Determine the "ultimate origin" of this block. This block may be an
5054 inlined instance of an inlined instance of inline function, so we
5055 have to trace all of the way back through the origin chain to find
5056 out what sort of node actually served as the original seed for the
5057 creation of the current block. */
5059 origin = block_ultimate_origin (stmt);
5060 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
5062 /* Determine if we need to output any Dwarf DIEs at all to represent this
5063 block. */
5065 if (origin_code == FUNCTION_DECL)
5066 /* The outer scopes for inlinings *must* always be represented. We
5067 generate TAG_inlined_subroutine DIEs for them. (See below.) */
5068 must_output_die = 1;
5069 else
5071 /* In the case where the current block represents an inlining of the
5072 "body block" of an inline function, we must *NOT* output any DIE
5073 for this block because we have already output a DIE to represent
5074 the whole inlined function scope and the "body block" of any
5075 function doesn't really represent a different scope according to
5076 ANSI C rules. So we check here to make sure that this block does
5077 not represent a "body block inlining" before trying to set the
5078 `must_output_die' flag. */
5080 if (! is_body_block (origin ? origin : stmt))
5082 /* Determine if this block directly contains any "significant"
5083 local declarations which we will need to output DIEs for. */
5085 if (debug_info_level > DINFO_LEVEL_TERSE)
5086 /* We are not in terse mode so *any* local declaration counts
5087 as being a "significant" one. */
5088 must_output_die = (BLOCK_VARS (stmt) != NULL);
5089 else
5091 tree decl;
5093 /* We are in terse mode, so only local (nested) function
5094 definitions count as "significant" local declarations. */
5096 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5097 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
5099 must_output_die = 1;
5100 break;
5106 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
5107 DIE for any block which contains no significant local declarations
5108 at all. Rather, in such cases we just call `output_decls_for_scope'
5109 so that any needed Dwarf info for any sub-blocks will get properly
5110 generated. Note that in terse mode, our definition of what constitutes
5111 a "significant" local declaration gets restricted to include only
5112 inlined function instances and local (nested) function definitions. */
5114 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
5115 /* We don't care about an abstract inlined subroutine. */;
5116 else if (must_output_die)
5118 output_die ((origin_code == FUNCTION_DECL)
5119 ? output_inlined_subroutine_die
5120 : output_lexical_block_die,
5121 stmt);
5122 output_decls_for_scope (stmt, depth);
5123 end_sibling_chain ();
5125 else
5126 output_decls_for_scope (stmt, depth);
5129 /* Output all of the decls declared within a given scope (also called
5130 a `binding contour') and (recursively) all of it's sub-blocks. */
5132 static void
5133 output_decls_for_scope (stmt, depth)
5134 tree stmt;
5135 int depth;
5137 /* Ignore blocks never really used to make RTL. */
5139 if (! stmt || ! TREE_USED (stmt))
5140 return;
5142 /* Output the DIEs to represent all of the data objects, functions,
5143 typedefs, and tagged types declared directly within this block
5144 but not within any nested sub-blocks. */
5147 tree decl;
5149 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5150 output_decl (decl, stmt);
5153 output_pending_types_for_scope (stmt);
5155 /* Output the DIEs to represent all sub-blocks (and the items declared
5156 therein) of this block. */
5159 tree subblocks;
5161 for (subblocks = BLOCK_SUBBLOCKS (stmt);
5162 subblocks;
5163 subblocks = BLOCK_CHAIN (subblocks))
5164 output_block (subblocks, depth + 1);
5168 /* Is this a typedef we can avoid emitting? */
5170 static inline int
5171 is_redundant_typedef (decl)
5172 tree decl;
5174 if (TYPE_DECL_IS_STUB (decl))
5175 return 1;
5176 if (DECL_ARTIFICIAL (decl)
5177 && DECL_CONTEXT (decl)
5178 && is_tagged_type (DECL_CONTEXT (decl))
5179 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
5180 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
5181 /* Also ignore the artificial member typedef for the class name. */
5182 return 1;
5183 return 0;
5186 /* Output Dwarf .debug information for a decl described by DECL. */
5188 static void
5189 output_decl (decl, containing_scope)
5190 tree decl;
5191 tree containing_scope;
5193 /* Make a note of the decl node we are going to be working on. We may
5194 need to give the user the source coordinates of where it appeared in
5195 case we notice (later on) that something about it looks screwy. */
5197 dwarf_last_decl = decl;
5199 if (TREE_CODE (decl) == ERROR_MARK)
5200 return;
5202 /* If a structure is declared within an initialization, e.g. as the
5203 operand of a sizeof, then it will not have a name. We don't want
5204 to output a DIE for it, as the tree nodes are in the temporary obstack */
5206 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5207 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
5208 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
5209 || (TYPE_FIELDS (TREE_TYPE (decl))
5210 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
5211 return;
5213 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5215 if (DECL_IGNORED_P (decl))
5216 return;
5218 switch (TREE_CODE (decl))
5220 case CONST_DECL:
5221 /* The individual enumerators of an enum type get output when we
5222 output the Dwarf representation of the relevant enum type itself. */
5223 break;
5225 case FUNCTION_DECL:
5226 /* If we are in terse mode, don't output any DIEs to represent
5227 mere function declarations. Also, if we are conforming
5228 to the DWARF version 1 specification, don't output DIEs for
5229 mere function declarations. */
5231 if (DECL_INITIAL (decl) == NULL_TREE)
5232 #if (DWARF_VERSION > 1)
5233 if (debug_info_level <= DINFO_LEVEL_TERSE)
5234 #endif
5235 break;
5237 /* Before we describe the FUNCTION_DECL itself, make sure that we
5238 have described its return type. */
5240 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
5243 /* And its containing type. */
5244 register tree origin = decl_class_context (decl);
5245 if (origin)
5246 output_type (origin, containing_scope);
5249 /* If we're emitting an out-of-line copy of an inline function,
5250 set up to refer to the abstract instance emitted from
5251 dwarfout_deferred_inline_function. */
5252 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
5253 && ! (containing_scope && TYPE_P (containing_scope)))
5254 set_decl_origin_self (decl);
5256 /* If the following DIE will represent a function definition for a
5257 function with "extern" linkage, output a special "pubnames" DIE
5258 label just ahead of the actual DIE. A reference to this label
5259 was already generated in the .debug_pubnames section sub-entry
5260 for this function definition. */
5262 if (TREE_PUBLIC (decl))
5264 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5266 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5267 ASM_OUTPUT_LABEL (asm_out_file, label);
5270 /* Now output a DIE to represent the function itself. */
5272 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
5273 ? output_global_subroutine_die
5274 : output_local_subroutine_die,
5275 decl);
5277 /* Now output descriptions of the arguments for this function.
5278 This gets (unnecessarily?) complex because of the fact that
5279 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
5280 cases where there was a trailing `...' at the end of the formal
5281 parameter list. In order to find out if there was a trailing
5282 ellipsis or not, we must instead look at the type associated
5283 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
5284 If the chain of type nodes hanging off of this FUNCTION_TYPE node
5285 ends with a void_type_node then there should *not* be an ellipsis
5286 at the end. */
5288 /* In the case where we are describing a mere function declaration, all
5289 we need to do here (and all we *can* do here) is to describe
5290 the *types* of its formal parameters. */
5292 if (decl != current_function_decl || in_class)
5293 output_formal_types (TREE_TYPE (decl));
5294 else
5296 /* Generate DIEs to represent all known formal parameters */
5298 tree arg_decls = DECL_ARGUMENTS (decl);
5299 tree parm;
5301 /* WARNING! Kludge zone ahead! Here we have a special
5302 hack for svr4 SDB compatibility. Instead of passing the
5303 current FUNCTION_DECL node as the second parameter (i.e.
5304 the `containing_scope' parameter) to `output_decl' (as
5305 we ought to) we instead pass a pointer to our own private
5306 fake_containing_scope node. That node is a RECORD_TYPE
5307 node which NO OTHER TYPE may ever actually be a member of.
5309 This pointer will ultimately get passed into `output_type'
5310 as its `containing_scope' parameter. `Output_type' will
5311 then perform its part in the hack... i.e. it will pend
5312 the type of the formal parameter onto the pending_types
5313 list. Later on, when we are done generating the whole
5314 sequence of formal parameter DIEs for this function
5315 definition, we will un-pend all previously pended types
5316 of formal parameters for this function definition.
5318 This whole kludge prevents any type DIEs from being
5319 mixed in with the formal parameter DIEs. That's good
5320 because svr4 SDB believes that the list of formal
5321 parameter DIEs for a function ends wherever the first
5322 non-formal-parameter DIE appears. Thus, we have to
5323 keep the formal parameter DIEs segregated. They must
5324 all appear (consecutively) at the start of the list of
5325 children for the DIE representing the function definition.
5326 Then (and only then) may we output any additional DIEs
5327 needed to represent the types of these formal parameters.
5331 When generating DIEs, generate the unspecified_parameters
5332 DIE instead if we come across the arg "__builtin_va_alist"
5335 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
5336 if (TREE_CODE (parm) == PARM_DECL)
5338 if (DECL_NAME(parm) &&
5339 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
5340 "__builtin_va_alist") )
5341 output_die (output_unspecified_parameters_die, decl);
5342 else
5343 output_decl (parm, fake_containing_scope);
5347 Now that we have finished generating all of the DIEs to
5348 represent the formal parameters themselves, force out
5349 any DIEs needed to represent their types. We do this
5350 simply by un-pending all previously pended types which
5351 can legitimately go into the chain of children DIEs for
5352 the current FUNCTION_DECL.
5355 output_pending_types_for_scope (decl);
5358 Decide whether we need an unspecified_parameters DIE at the end.
5359 There are 2 more cases to do this for:
5360 1) the ansi ... declaration - this is detectable when the end
5361 of the arg list is not a void_type_node
5362 2) an unprototyped function declaration (not a definition). This
5363 just means that we have no info about the parameters at all.
5367 tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
5369 if (fn_arg_types)
5371 /* this is the prototyped case, check for ... */
5372 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
5373 output_die (output_unspecified_parameters_die, decl);
5375 else
5377 /* this is unprototyped, check for undefined (just declaration) */
5378 if (!DECL_INITIAL (decl))
5379 output_die (output_unspecified_parameters_die, decl);
5383 /* Output Dwarf info for all of the stuff within the body of the
5384 function (if it has one - it may be just a declaration). */
5387 tree outer_scope = DECL_INITIAL (decl);
5389 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
5391 /* Note that here, `outer_scope' is a pointer to the outermost
5392 BLOCK node created to represent a function.
5393 This outermost BLOCK actually represents the outermost
5394 binding contour for the function, i.e. the contour in which
5395 the function's formal parameters and labels get declared.
5397 Curiously, it appears that the front end doesn't actually
5398 put the PARM_DECL nodes for the current function onto the
5399 BLOCK_VARS list for this outer scope. (They are strung
5400 off of the DECL_ARGUMENTS list for the function instead.)
5401 The BLOCK_VARS list for the `outer_scope' does provide us
5402 with a list of the LABEL_DECL nodes for the function however,
5403 and we output DWARF info for those here.
5405 Just within the `outer_scope' there will be a BLOCK node
5406 representing the function's outermost pair of curly braces,
5407 and any blocks used for the base and member initializers of
5408 a C++ constructor function. */
5410 output_decls_for_scope (outer_scope, 0);
5412 /* Finally, force out any pending types which are local to the
5413 outermost block of this function definition. These will
5414 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
5415 node itself. */
5417 output_pending_types_for_scope (decl);
5422 /* Generate a terminator for the list of stuff `owned' by this
5423 function. */
5425 end_sibling_chain ();
5427 break;
5429 case TYPE_DECL:
5430 /* If we are in terse mode, don't generate any DIEs to represent
5431 any actual typedefs. Note that even when we are in terse mode,
5432 we must still output DIEs to represent those tagged types which
5433 are used (directly or indirectly) in the specification of either
5434 a return type or a formal parameter type of some function. */
5436 if (debug_info_level <= DINFO_LEVEL_TERSE)
5437 if (! TYPE_DECL_IS_STUB (decl)
5438 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5439 return;
5441 /* In the special case of a TYPE_DECL node representing
5442 the declaration of some type tag, if the given TYPE_DECL is
5443 marked as having been instantiated from some other (original)
5444 TYPE_DECL node (e.g. one which was generated within the original
5445 definition of an inline function) we have to generate a special
5446 (abbreviated) TAG_structure_type, TAG_union_type, or
5447 TAG_enumeration-type DIE here. */
5449 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5451 output_tagged_type_instantiation (TREE_TYPE (decl));
5452 return;
5455 output_type (TREE_TYPE (decl), containing_scope);
5457 if (! is_redundant_typedef (decl))
5458 /* Output a DIE to represent the typedef itself. */
5459 output_die (output_typedef_die, decl);
5460 break;
5462 case LABEL_DECL:
5463 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5464 output_die (output_label_die, decl);
5465 break;
5467 case VAR_DECL:
5468 /* If we are conforming to the DWARF version 1 specification, don't
5469 generated any DIEs to represent mere external object declarations. */
5471 #if (DWARF_VERSION <= 1)
5472 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5473 break;
5474 #endif
5476 /* If we are in terse mode, don't generate any DIEs to represent
5477 any variable declarations or definitions. */
5479 if (debug_info_level <= DINFO_LEVEL_TERSE)
5480 break;
5482 /* Output any DIEs that are needed to specify the type of this data
5483 object. */
5485 output_type (TREE_TYPE (decl), containing_scope);
5488 /* And its containing type. */
5489 register tree origin = decl_class_context (decl);
5490 if (origin)
5491 output_type (origin, containing_scope);
5494 /* If the following DIE will represent a data object definition for a
5495 data object with "extern" linkage, output a special "pubnames" DIE
5496 label just ahead of the actual DIE. A reference to this label
5497 was already generated in the .debug_pubnames section sub-entry
5498 for this data object definition. */
5500 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5502 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5504 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5505 ASM_OUTPUT_LABEL (asm_out_file, label);
5508 /* Now output the DIE to represent the data object itself. This gets
5509 complicated because of the possibility that the VAR_DECL really
5510 represents an inlined instance of a formal parameter for an inline
5511 function. */
5514 void (*func) PARAMS ((void *));
5515 register tree origin = decl_ultimate_origin (decl);
5517 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5518 func = output_formal_parameter_die;
5519 else
5521 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5522 func = output_global_variable_die;
5523 else
5524 func = output_local_variable_die;
5526 output_die (func, decl);
5528 break;
5530 case FIELD_DECL:
5531 /* Ignore the nameless fields that are used to skip bits. */
5532 if (DECL_NAME (decl) != 0)
5534 output_type (member_declared_type (decl), containing_scope);
5535 output_die (output_member_die, decl);
5537 break;
5539 case PARM_DECL:
5540 /* Force out the type of this formal, if it was not forced out yet.
5541 Note that here we can run afoul of a bug in "classic" svr4 SDB.
5542 It should be able to grok the presence of type DIEs within a list
5543 of TAG_formal_parameter DIEs, but it doesn't. */
5545 output_type (TREE_TYPE (decl), containing_scope);
5546 output_die (output_formal_parameter_die, decl);
5547 break;
5549 case NAMESPACE_DECL:
5550 /* Ignore for now. */
5551 break;
5553 default:
5554 abort ();
5558 /* Output debug information for a function. */
5559 static void
5560 dwarfout_function_decl (decl)
5561 tree decl;
5563 dwarfout_file_scope_decl (decl, 0);
5566 /* Debug information for a global DECL. Called from toplev.c after
5567 compilation proper has finished. */
5568 static void
5569 dwarfout_global_decl (decl)
5570 tree decl;
5572 /* Output DWARF information for file-scope tentative data object
5573 declarations, file-scope (extern) function declarations (which
5574 had no corresponding body) and file-scope tagged type
5575 declarations and definitions which have not yet been forced out. */
5577 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
5578 dwarfout_file_scope_decl (decl, 1);
5581 /* DECL is an inline function, whose body is present, but which is not
5582 being output at this point. (We're putting that off until we need
5583 to do it.) */
5584 static void
5585 dwarfout_deferred_inline_function (decl)
5586 tree decl;
5588 /* Generate the DWARF info for the "abstract" instance of a function
5589 which we may later generate inlined and/or out-of-line instances
5590 of. */
5591 if ((DECL_INLINE (decl) || DECL_ABSTRACT (decl))
5592 && ! DECL_ABSTRACT_ORIGIN (decl))
5594 /* The front-end may not have set CURRENT_FUNCTION_DECL, but the
5595 DWARF code expects it to be set in this case. Intuitively,
5596 DECL is the function we just finished defining, so setting
5597 CURRENT_FUNCTION_DECL is sensible. */
5598 tree saved_cfd = current_function_decl;
5599 int was_abstract = DECL_ABSTRACT (decl);
5600 current_function_decl = decl;
5602 /* Let the DWARF code do its work. */
5603 set_decl_abstract_flags (decl, 1);
5604 dwarfout_file_scope_decl (decl, 0);
5605 if (! was_abstract)
5606 set_decl_abstract_flags (decl, 0);
5608 /* Reset CURRENT_FUNCTION_DECL. */
5609 current_function_decl = saved_cfd;
5613 static void
5614 dwarfout_file_scope_decl (decl, set_finalizing)
5615 tree decl;
5616 int set_finalizing;
5618 if (TREE_CODE (decl) == ERROR_MARK)
5619 return;
5621 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5623 if (DECL_IGNORED_P (decl))
5624 return;
5626 switch (TREE_CODE (decl))
5628 case FUNCTION_DECL:
5630 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5631 a builtin function. Explicit programmer-supplied declarations of
5632 these same functions should NOT be ignored however. */
5634 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5635 return;
5637 /* What we would really like to do here is to filter out all mere
5638 file-scope declarations of file-scope functions which are never
5639 referenced later within this translation unit (and keep all of
5640 ones that *are* referenced later on) but we aren't clairvoyant,
5641 so we have no idea which functions will be referenced in the
5642 future (i.e. later on within the current translation unit).
5643 So here we just ignore all file-scope function declarations
5644 which are not also definitions. If and when the debugger needs
5645 to know something about these functions, it will have to hunt
5646 around and find the DWARF information associated with the
5647 *definition* of the function.
5649 Note that we can't just check `DECL_EXTERNAL' to find out which
5650 FUNCTION_DECL nodes represent definitions and which ones represent
5651 mere declarations. We have to check `DECL_INITIAL' instead. That's
5652 because the C front-end supports some weird semantics for "extern
5653 inline" function definitions. These can get inlined within the
5654 current translation unit (an thus, we need to generate DWARF info
5655 for their abstract instances so that the DWARF info for the
5656 concrete inlined instances can have something to refer to) but
5657 the compiler never generates any out-of-lines instances of such
5658 things (despite the fact that they *are* definitions). The
5659 important point is that the C front-end marks these "extern inline"
5660 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5661 anyway.
5663 Note that the C++ front-end also plays some similar games for inline
5664 function definitions appearing within include files which also
5665 contain `#pragma interface' pragmas. */
5667 if (DECL_INITIAL (decl) == NULL_TREE)
5668 return;
5670 if (TREE_PUBLIC (decl)
5671 && ! DECL_EXTERNAL (decl)
5672 && ! DECL_ABSTRACT (decl))
5674 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5676 /* Output a .debug_pubnames entry for a public function
5677 defined in this compilation unit. */
5679 fputc ('\n', asm_out_file);
5680 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5681 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5682 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5683 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5684 IDENTIFIER_POINTER (DECL_NAME (decl)));
5685 ASM_OUTPUT_POP_SECTION (asm_out_file);
5688 break;
5690 case VAR_DECL:
5692 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5693 object declaration and if the declaration was never even
5694 referenced from within this entire compilation unit. We
5695 suppress these DIEs in order to save space in the .debug section
5696 (by eliminating entries which are probably useless). Note that
5697 we must not suppress block-local extern declarations (whether
5698 used or not) because that would screw-up the debugger's name
5699 lookup mechanism and cause it to miss things which really ought
5700 to be in scope at a given point. */
5702 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5703 return;
5705 if (TREE_PUBLIC (decl)
5706 && ! DECL_EXTERNAL (decl)
5707 && GET_CODE (DECL_RTL (decl)) == MEM
5708 && ! DECL_ABSTRACT (decl))
5710 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5712 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5714 /* Output a .debug_pubnames entry for a public variable
5715 defined in this compilation unit. */
5717 fputc ('\n', asm_out_file);
5718 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5719 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5720 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5721 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5722 IDENTIFIER_POINTER (DECL_NAME (decl)));
5723 ASM_OUTPUT_POP_SECTION (asm_out_file);
5726 if (DECL_INITIAL (decl) == NULL)
5728 /* Output a .debug_aranges entry for a public variable
5729 which is tentatively defined in this compilation unit. */
5731 fputc ('\n', asm_out_file);
5732 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
5733 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5734 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5735 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5736 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5737 ASM_OUTPUT_POP_SECTION (asm_out_file);
5741 /* If we are in terse mode, don't generate any DIEs to represent
5742 any variable declarations or definitions. */
5744 if (debug_info_level <= DINFO_LEVEL_TERSE)
5745 return;
5747 break;
5749 case TYPE_DECL:
5750 /* Don't bother trying to generate any DIEs to represent any of the
5751 normal built-in types for the language we are compiling, except
5752 in cases where the types in question are *not* DWARF fundamental
5753 types. We make an exception in the case of non-fundamental types
5754 for the sake of objective C (and perhaps C++) because the GNU
5755 front-ends for these languages may in fact create certain "built-in"
5756 types which are (for example) RECORD_TYPEs. In such cases, we
5757 really need to output these (non-fundamental) types because other
5758 DIEs may contain references to them. */
5760 /* Also ignore language dependent types here, because they are probably
5761 also built-in types. If we didn't ignore them, then we would get
5762 references to undefined labels because output_type doesn't support
5763 them. So, for now, we need to ignore them to avoid assembler
5764 errors. */
5766 /* ??? This code is different than the equivalent code in dwarf2out.c.
5767 The dwarf2out.c code is probably more correct. */
5769 if (DECL_SOURCE_LINE (decl) == 0
5770 && (type_is_fundamental (TREE_TYPE (decl))
5771 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5772 return;
5774 /* If we are in terse mode, don't generate any DIEs to represent
5775 any actual typedefs. Note that even when we are in terse mode,
5776 we must still output DIEs to represent those tagged types which
5777 are used (directly or indirectly) in the specification of either
5778 a return type or a formal parameter type of some function. */
5780 if (debug_info_level <= DINFO_LEVEL_TERSE)
5781 if (! TYPE_DECL_IS_STUB (decl)
5782 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5783 return;
5785 break;
5787 default:
5788 return;
5791 fputc ('\n', asm_out_file);
5792 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5793 finalizing = set_finalizing;
5794 output_decl (decl, NULL_TREE);
5796 /* NOTE: The call above to `output_decl' may have caused one or more
5797 file-scope named types (i.e. tagged types) to be placed onto the
5798 pending_types_list. We have to get those types off of that list
5799 at some point, and this is the perfect time to do it. If we didn't
5800 take them off now, they might still be on the list when cc1 finally
5801 exits. That might be OK if it weren't for the fact that when we put
5802 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5803 for these types, and that causes them never to be output unless
5804 `output_pending_types_for_scope' takes them off of the list and un-sets
5805 their TREE_ASM_WRITTEN flags. */
5807 output_pending_types_for_scope (NULL_TREE);
5809 /* The above call should have totally emptied the pending_types_list
5810 if this is not a nested function or class. If this is a nested type,
5811 then the remaining pending_types will be emitted when the containing type
5812 is handled. */
5814 if (! DECL_CONTEXT (decl))
5816 if (pending_types != 0)
5817 abort ();
5820 ASM_OUTPUT_POP_SECTION (asm_out_file);
5822 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5823 current_funcdef_number++;
5826 /* Output a marker (i.e. a label) for the beginning of the generated code
5827 for a lexical block. */
5829 static void
5830 dwarfout_begin_block (line, blocknum)
5831 unsigned int line ATTRIBUTE_UNUSED;
5832 unsigned int blocknum;
5834 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5836 function_section (current_function_decl);
5837 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5838 ASM_OUTPUT_LABEL (asm_out_file, label);
5841 /* Output a marker (i.e. a label) for the end of the generated code
5842 for a lexical block. */
5844 static void
5845 dwarfout_end_block (line, blocknum)
5846 unsigned int line ATTRIBUTE_UNUSED;
5847 unsigned int blocknum;
5849 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5851 function_section (current_function_decl);
5852 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5853 ASM_OUTPUT_LABEL (asm_out_file, label);
5856 /* Output a marker (i.e. a label) for the point in the generated code where
5857 the real body of the function begins (after parameters have been moved
5858 to their home locations). */
5860 static void
5861 dwarfout_end_prologue (line)
5862 unsigned int line ATTRIBUTE_UNUSED;
5864 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5866 if (! use_gnu_debug_info_extensions)
5867 return;
5869 function_section (current_function_decl);
5870 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5871 ASM_OUTPUT_LABEL (asm_out_file, label);
5874 /* Output a marker (i.e. a label) for the point in the generated code where
5875 the real body of the function ends (just before the epilogue code). */
5877 static void
5878 dwarfout_end_function (line)
5879 unsigned int line ATTRIBUTE_UNUSED;
5881 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5883 if (! use_gnu_debug_info_extensions)
5884 return;
5885 function_section (current_function_decl);
5886 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5887 ASM_OUTPUT_LABEL (asm_out_file, label);
5890 /* Output a marker (i.e. a label) for the absolute end of the generated code
5891 for a function definition. This gets called *after* the epilogue code
5892 has been generated. */
5894 static void
5895 dwarfout_end_epilogue ()
5897 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5899 /* Output a label to mark the endpoint of the code generated for this
5900 function. */
5902 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5903 ASM_OUTPUT_LABEL (asm_out_file, label);
5906 static void
5907 shuffle_filename_entry (new_zeroth)
5908 filename_entry *new_zeroth;
5910 filename_entry temp_entry;
5911 filename_entry *limit_p;
5912 filename_entry *move_p;
5914 if (new_zeroth == &filename_table[0])
5915 return;
5917 temp_entry = *new_zeroth;
5919 /* Shift entries up in the table to make room at [0]. */
5921 limit_p = &filename_table[0];
5922 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5923 *move_p = *(move_p-1);
5925 /* Install the found entry at [0]. */
5927 filename_table[0] = temp_entry;
5930 /* Create a new (string) entry for the .debug_sfnames section. */
5932 static void
5933 generate_new_sfname_entry ()
5935 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5937 fputc ('\n', asm_out_file);
5938 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
5939 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5940 ASM_OUTPUT_LABEL (asm_out_file, label);
5941 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5942 filename_table[0].name
5943 ? filename_table[0].name
5944 : "");
5945 ASM_OUTPUT_POP_SECTION (asm_out_file);
5948 /* Lookup a filename (in the list of filenames that we know about here in
5949 dwarfout.c) and return its "index". The index of each (known) filename
5950 is just a unique number which is associated with only that one filename.
5951 We need such numbers for the sake of generating labels (in the
5952 .debug_sfnames section) and references to those unique labels (in the
5953 .debug_srcinfo and .debug_macinfo sections).
5955 If the filename given as an argument is not found in our current list,
5956 add it to the list and assign it the next available unique index number.
5958 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5959 one), we shuffle the filename found (or added) up to the zeroth entry of
5960 our list of filenames (which is always searched linearly). We do this so
5961 as to optimize the most common case for these filename lookups within
5962 dwarfout.c. The most common case by far is the case where we call
5963 lookup_filename to lookup the very same filename that we did a lookup
5964 on the last time we called lookup_filename. We make sure that this
5965 common case is fast because such cases will constitute 99.9% of the
5966 lookups we ever do (in practice).
5968 If we add a new filename entry to our table, we go ahead and generate
5969 the corresponding entry in the .debug_sfnames section right away.
5970 Doing so allows us to avoid tickling an assembler bug (present in some
5971 m68k assemblers) which yields assembly-time errors in cases where the
5972 difference of two label addresses is taken and where the two labels
5973 are in a section *other* than the one where the difference is being
5974 calculated, and where at least one of the two symbol references is a
5975 forward reference. (This bug could be tickled by our .debug_srcinfo
5976 entries if we don't output their corresponding .debug_sfnames entries
5977 before them.) */
5979 static unsigned
5980 lookup_filename (file_name)
5981 const char *file_name;
5983 filename_entry *search_p;
5984 filename_entry *limit_p = &filename_table[ft_entries];
5986 for (search_p = filename_table; search_p < limit_p; search_p++)
5987 if (!strcmp (file_name, search_p->name))
5989 /* When we get here, we have found the filename that we were
5990 looking for in the filename_table. Now we want to make sure
5991 that it gets moved to the zero'th entry in the table (if it
5992 is not already there) so that subsequent attempts to find the
5993 same filename will find it as quickly as possible. */
5995 shuffle_filename_entry (search_p);
5996 return filename_table[0].number;
5999 /* We come here whenever we have a new filename which is not registered
6000 in the current table. Here we add it to the table. */
6002 /* Prepare to add a new table entry by making sure there is enough space
6003 in the table to do so. If not, expand the current table. */
6005 if (ft_entries == ft_entries_allocated)
6007 ft_entries_allocated += FT_ENTRIES_INCREMENT;
6008 filename_table
6009 = (filename_entry *)
6010 xrealloc (filename_table,
6011 ft_entries_allocated * sizeof (filename_entry));
6014 /* Initially, add the new entry at the end of the filename table. */
6016 filename_table[ft_entries].number = ft_entries;
6017 filename_table[ft_entries].name = xstrdup (file_name);
6019 /* Shuffle the new entry into filename_table[0]. */
6021 shuffle_filename_entry (&filename_table[ft_entries]);
6023 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6024 generate_new_sfname_entry ();
6026 ft_entries++;
6027 return filename_table[0].number;
6030 static void
6031 generate_srcinfo_entry (line_entry_num, files_entry_num)
6032 unsigned line_entry_num;
6033 unsigned files_entry_num;
6035 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6037 fputc ('\n', asm_out_file);
6038 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6039 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
6040 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
6041 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
6042 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
6043 ASM_OUTPUT_POP_SECTION (asm_out_file);
6046 static void
6047 dwarfout_source_line (line, filename)
6048 unsigned int line;
6049 const char *filename;
6051 if (debug_info_level >= DINFO_LEVEL_NORMAL
6052 /* We can't emit line number info for functions in separate sections,
6053 because the assembler can't subtract labels in different sections. */
6054 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
6056 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6057 static unsigned last_line_entry_num = 0;
6058 static unsigned prev_file_entry_num = (unsigned) -1;
6059 unsigned this_file_entry_num;
6061 function_section (current_function_decl);
6062 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
6063 ASM_OUTPUT_LABEL (asm_out_file, label);
6065 fputc ('\n', asm_out_file);
6067 if (use_gnu_debug_info_extensions)
6068 this_file_entry_num = lookup_filename (filename);
6069 else
6070 this_file_entry_num = (unsigned) -1;
6072 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6073 if (this_file_entry_num != prev_file_entry_num)
6075 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
6077 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
6078 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
6082 const char *tail = strrchr (filename, '/');
6084 if (tail != NULL)
6085 filename = tail;
6088 dw2_asm_output_data (4, line, "%s:%u", filename, line);
6089 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6090 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
6091 ASM_OUTPUT_POP_SECTION (asm_out_file);
6093 if (this_file_entry_num != prev_file_entry_num)
6094 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
6095 prev_file_entry_num = this_file_entry_num;
6099 /* Generate an entry in the .debug_macinfo section. */
6101 static void
6102 generate_macinfo_entry (type, offset, string)
6103 unsigned int type;
6104 rtx offset;
6105 const char *string;
6107 if (! use_gnu_debug_info_extensions)
6108 return;
6110 fputc ('\n', asm_out_file);
6111 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6112 assemble_integer (gen_rtx_PLUS (SImode, GEN_INT (type << 24), offset),
6113 4, BITS_PER_UNIT, 1);
6114 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
6115 ASM_OUTPUT_POP_SECTION (asm_out_file);
6118 /* Wrapper for toplev.c callback to check debug info level. */
6119 static void
6120 dwarfout_start_source_file_check (line, filename)
6121 unsigned int line;
6122 const char *filename;
6124 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6125 dwarfout_start_source_file (line, filename);
6128 static void
6129 dwarfout_start_source_file (line, filename)
6130 unsigned int line ATTRIBUTE_UNUSED;
6131 const char *filename;
6133 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6134 const char *label1, *label2;
6136 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
6137 label1 = (*label == '*') + label;
6138 label2 = (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL;
6139 generate_macinfo_entry (MACINFO_start,
6140 gen_rtx_MINUS (Pmode,
6141 gen_rtx_SYMBOL_REF (Pmode, label1),
6142 gen_rtx_SYMBOL_REF (Pmode, label2)),
6143 "");
6146 /* Wrapper for toplev.c callback to check debug info level. */
6147 static void
6148 dwarfout_end_source_file_check (lineno)
6149 unsigned lineno;
6151 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6152 dwarfout_end_source_file (lineno);
6155 static void
6156 dwarfout_end_source_file (lineno)
6157 unsigned lineno;
6159 generate_macinfo_entry (MACINFO_resume, GEN_INT (lineno), "");
6162 /* Called from check_newline in c-parse.y. The `buffer' parameter
6163 contains the tail part of the directive line, i.e. the part which
6164 is past the initial whitespace, #, whitespace, directive-name,
6165 whitespace part. */
6167 static void
6168 dwarfout_define (lineno, buffer)
6169 unsigned lineno;
6170 const char *buffer;
6172 static int initialized = 0;
6174 if (!initialized)
6176 dwarfout_start_source_file (0, primary_filename);
6177 initialized = 1;
6179 generate_macinfo_entry (MACINFO_define, GEN_INT (lineno), buffer);
6182 /* Called from check_newline in c-parse.y. The `buffer' parameter
6183 contains the tail part of the directive line, i.e. the part which
6184 is past the initial whitespace, #, whitespace, directive-name,
6185 whitespace part. */
6187 static void
6188 dwarfout_undef (lineno, buffer)
6189 unsigned lineno;
6190 const char *buffer;
6192 generate_macinfo_entry (MACINFO_undef, GEN_INT (lineno), buffer);
6195 /* Set up for Dwarf output at the start of compilation. */
6197 static void
6198 dwarfout_init (main_input_filename)
6199 const char *main_input_filename;
6201 /* Remember the name of the primary input file. */
6203 primary_filename = main_input_filename;
6205 /* Allocate the initial hunk of the pending_sibling_stack. */
6207 pending_sibling_stack
6208 = (unsigned *)
6209 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
6210 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
6211 pending_siblings = 1;
6213 /* Allocate the initial hunk of the filename_table. */
6215 filename_table
6216 = (filename_entry *)
6217 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
6218 ft_entries_allocated = FT_ENTRIES_INCREMENT;
6219 ft_entries = 0;
6221 /* Allocate the initial hunk of the pending_types_list. */
6223 pending_types_list
6224 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
6225 pending_types_allocated = PENDING_TYPES_INCREMENT;
6226 pending_types = 0;
6228 /* Create an artificial RECORD_TYPE node which we can use in our hack
6229 to get the DIEs representing types of formal parameters to come out
6230 only *after* the DIEs for the formal parameters themselves. */
6232 fake_containing_scope = make_node (RECORD_TYPE);
6234 /* Output a starting label for the .text section. */
6236 fputc ('\n', asm_out_file);
6237 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6238 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
6239 ASM_OUTPUT_POP_SECTION (asm_out_file);
6241 /* Output a starting label for the .data section. */
6243 fputc ('\n', asm_out_file);
6244 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6245 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
6246 ASM_OUTPUT_POP_SECTION (asm_out_file);
6248 #if 0 /* GNU C doesn't currently use .data1. */
6249 /* Output a starting label for the .data1 section. */
6251 fputc ('\n', asm_out_file);
6252 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6253 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
6254 ASM_OUTPUT_POP_SECTION (asm_out_file);
6255 #endif
6257 /* Output a starting label for the .rodata section. */
6259 fputc ('\n', asm_out_file);
6260 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6261 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
6262 ASM_OUTPUT_POP_SECTION (asm_out_file);
6264 #if 0 /* GNU C doesn't currently use .rodata1. */
6265 /* Output a starting label for the .rodata1 section. */
6267 fputc ('\n', asm_out_file);
6268 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6269 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
6270 ASM_OUTPUT_POP_SECTION (asm_out_file);
6271 #endif
6273 /* Output a starting label for the .bss section. */
6275 fputc ('\n', asm_out_file);
6276 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6277 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
6278 ASM_OUTPUT_POP_SECTION (asm_out_file);
6280 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6282 if (use_gnu_debug_info_extensions)
6284 /* Output a starting label and an initial (compilation directory)
6285 entry for the .debug_sfnames section. The starting label will be
6286 referenced by the initial entry in the .debug_srcinfo section. */
6288 fputc ('\n', asm_out_file);
6289 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6290 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
6292 const char *pwd = getpwd ();
6293 char *dirname;
6295 if (!pwd)
6296 fatal_io_error ("can't get current directory");
6298 dirname = concat (pwd, "/", NULL);
6299 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
6300 free (dirname);
6302 ASM_OUTPUT_POP_SECTION (asm_out_file);
6305 if (debug_info_level >= DINFO_LEVEL_VERBOSE
6306 && use_gnu_debug_info_extensions)
6308 /* Output a starting label for the .debug_macinfo section. This
6309 label will be referenced by the AT_mac_info attribute in the
6310 TAG_compile_unit DIE. */
6312 fputc ('\n', asm_out_file);
6313 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6314 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
6315 ASM_OUTPUT_POP_SECTION (asm_out_file);
6318 /* Generate the initial entry for the .line section. */
6320 fputc ('\n', asm_out_file);
6321 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6322 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
6323 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
6324 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6325 ASM_OUTPUT_POP_SECTION (asm_out_file);
6327 if (use_gnu_debug_info_extensions)
6329 /* Generate the initial entry for the .debug_srcinfo section. */
6331 fputc ('\n', asm_out_file);
6332 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6333 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
6334 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
6335 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
6336 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6337 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
6338 #ifdef DWARF_TIMESTAMPS
6339 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
6340 #else
6341 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6342 #endif
6343 ASM_OUTPUT_POP_SECTION (asm_out_file);
6346 /* Generate the initial entry for the .debug_pubnames section. */
6348 fputc ('\n', asm_out_file);
6349 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6350 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6351 ASM_OUTPUT_POP_SECTION (asm_out_file);
6353 /* Generate the initial entry for the .debug_aranges section. */
6355 fputc ('\n', asm_out_file);
6356 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6357 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6358 DEBUG_ARANGES_END_LABEL,
6359 DEBUG_ARANGES_BEGIN_LABEL);
6360 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_BEGIN_LABEL);
6361 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 1);
6362 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6363 ASM_OUTPUT_POP_SECTION (asm_out_file);
6366 /* Setup first DIE number == 1. */
6367 NEXT_DIE_NUM = next_unused_dienum++;
6369 /* Generate the initial DIE for the .debug section. Note that the
6370 (string) value given in the AT_name attribute of the TAG_compile_unit
6371 DIE will (typically) be a relative pathname and that this pathname
6372 should be taken as being relative to the directory from which the
6373 compiler was invoked when the given (base) source file was compiled. */
6375 fputc ('\n', asm_out_file);
6376 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6377 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
6378 output_die (output_compile_unit_die, (PTR) main_input_filename);
6379 ASM_OUTPUT_POP_SECTION (asm_out_file);
6381 fputc ('\n', asm_out_file);
6384 /* Output stuff that dwarf requires at the end of every file. */
6386 static void
6387 dwarfout_finish (main_input_filename)
6388 const char *main_input_filename ATTRIBUTE_UNUSED;
6390 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6392 fputc ('\n', asm_out_file);
6393 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6394 retry_incomplete_types ();
6395 fputc ('\n', asm_out_file);
6397 /* Mark the end of the chain of siblings which represent all file-scope
6398 declarations in this compilation unit. */
6400 /* The (null) DIE which represents the terminator for the (sibling linked)
6401 list of file-scope items is *special*. Normally, we would just call
6402 end_sibling_chain at this point in order to output a word with the
6403 value `4' and that word would act as the terminator for the list of
6404 DIEs describing file-scope items. Unfortunately, if we were to simply
6405 do that, the label that would follow this DIE in the .debug section
6406 (i.e. `..D2') would *not* be properly aligned (as it must be on some
6407 machines) to a 4 byte boundary.
6409 In order to force the label `..D2' to get aligned to a 4 byte boundary,
6410 the trick used is to insert extra (otherwise useless) padding bytes
6411 into the (null) DIE that we know must precede the ..D2 label in the
6412 .debug section. The amount of padding required can be anywhere between
6413 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
6414 with the padding) would normally contain the value 4, but now it will
6415 also have to include the padding bytes, so it will instead have some
6416 value in the range 4..7.
6418 Fortunately, the rules of Dwarf say that any DIE whose length word
6419 contains *any* value less than 8 should be treated as a null DIE, so
6420 this trick works out nicely. Clever, eh? Don't give me any credit
6421 (or blame). I didn't think of this scheme. I just conformed to it.
6424 output_die (output_padded_null_die, (void *) 0);
6425 dienum_pop ();
6427 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
6428 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
6429 ASM_OUTPUT_POP_SECTION (asm_out_file);
6431 /* Output a terminator label for the .text section. */
6433 fputc ('\n', asm_out_file);
6434 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6435 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
6436 ASM_OUTPUT_POP_SECTION (asm_out_file);
6438 /* Output a terminator label for the .data section. */
6440 fputc ('\n', asm_out_file);
6441 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6442 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
6443 ASM_OUTPUT_POP_SECTION (asm_out_file);
6445 #if 0 /* GNU C doesn't currently use .data1. */
6446 /* Output a terminator label for the .data1 section. */
6448 fputc ('\n', asm_out_file);
6449 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6450 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
6451 ASM_OUTPUT_POP_SECTION (asm_out_file);
6452 #endif
6454 /* Output a terminator label for the .rodata section. */
6456 fputc ('\n', asm_out_file);
6457 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6458 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
6459 ASM_OUTPUT_POP_SECTION (asm_out_file);
6461 #if 0 /* GNU C doesn't currently use .rodata1. */
6462 /* Output a terminator label for the .rodata1 section. */
6464 fputc ('\n', asm_out_file);
6465 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6466 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
6467 ASM_OUTPUT_POP_SECTION (asm_out_file);
6468 #endif
6470 /* Output a terminator label for the .bss section. */
6472 fputc ('\n', asm_out_file);
6473 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6474 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
6475 ASM_OUTPUT_POP_SECTION (asm_out_file);
6477 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6479 /* Output a terminating entry for the .line section. */
6481 fputc ('\n', asm_out_file);
6482 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6483 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
6484 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6485 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6486 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6487 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
6488 ASM_OUTPUT_POP_SECTION (asm_out_file);
6490 if (use_gnu_debug_info_extensions)
6492 /* Output a terminating entry for the .debug_srcinfo section. */
6494 fputc ('\n', asm_out_file);
6495 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6496 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6497 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6498 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6499 ASM_OUTPUT_POP_SECTION (asm_out_file);
6502 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6504 /* Output terminating entries for the .debug_macinfo section. */
6506 dwarfout_end_source_file (0);
6508 fputc ('\n', asm_out_file);
6509 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6510 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6511 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6512 ASM_OUTPUT_POP_SECTION (asm_out_file);
6515 /* Generate the terminating entry for the .debug_pubnames section. */
6517 fputc ('\n', asm_out_file);
6518 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6519 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6520 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6521 ASM_OUTPUT_POP_SECTION (asm_out_file);
6523 /* Generate the terminating entries for the .debug_aranges section.
6525 Note that we want to do this only *after* we have output the end
6526 labels (for the various program sections) which we are going to
6527 refer to here. This allows us to work around a bug in the m68k
6528 svr4 assembler. That assembler gives bogus assembly-time errors
6529 if (within any given section) you try to take the difference of
6530 two relocatable symbols, both of which are located within some
6531 other section, and if one (or both?) of the symbols involved is
6532 being forward-referenced. By generating the .debug_aranges
6533 entries at this late point in the assembly output, we skirt the
6534 issue simply by avoiding forward-references.
6537 fputc ('\n', asm_out_file);
6538 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6540 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6541 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6543 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6544 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6546 #if 0 /* GNU C doesn't currently use .data1. */
6547 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6548 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6549 DATA1_BEGIN_LABEL);
6550 #endif
6552 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6553 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6554 RODATA_BEGIN_LABEL);
6556 #if 0 /* GNU C doesn't currently use .rodata1. */
6557 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6558 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6559 RODATA1_BEGIN_LABEL);
6560 #endif
6562 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6563 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6565 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6566 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6568 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_END_LABEL);
6569 ASM_OUTPUT_POP_SECTION (asm_out_file);
6572 /* There should not be any pending types left at the end. We need
6573 this now because it may not have been checked on the last call to
6574 dwarfout_file_scope_decl. */
6575 if (pending_types != 0)
6576 abort ();
6579 #endif /* DWARF_DEBUGGING_INFO */