Update version
[official-gcc.git] / gcc / dwarfout.c
blobc1546f5dcf18cd1a272443d8ec6adc9ba3d67229
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 GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 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 "dwarfout.h"
578 #include "toplev.h"
579 #include "tm_p.h"
581 /* NOTE: In the comments in this file, many references are made to
582 so called "Debugging Information Entries". For the sake of brevity,
583 this term is abbreviated to `DIE' throughout the remainder of this
584 file. */
586 /* Note that the implementation of C++ support herein is (as yet) unfinished.
587 If you want to try to complete it, more power to you. */
589 /* How to start an assembler comment. */
590 #ifndef ASM_COMMENT_START
591 #define ASM_COMMENT_START ";#"
592 #endif
594 /* How to print out a register name. */
595 #ifndef PRINT_REG
596 #define PRINT_REG(RTX, CODE, FILE) \
597 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
598 #endif
600 /* Define a macro which returns non-zero for any tagged type which is
601 used (directly or indirectly) in the specification of either some
602 function's return type or some formal parameter of some function.
603 We use this macro when we are operating in "terse" mode to help us
604 know what tagged types have to be represented in Dwarf (even in
605 terse mode) and which ones don't.
607 A flag bit with this meaning really should be a part of the normal
608 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
609 for these nodes. For now, we have to just fake it. It it safe for
610 us to simply return zero for all complete tagged types (which will
611 get forced out anyway if they were used in the specification of some
612 formal or return type) and non-zero for all incomplete tagged types.
615 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
617 /* Define a macro which returns non-zero for a TYPE_DECL which was
618 implicitly generated for a tagged type.
620 Note that unlike the gcc front end (which generates a NULL named
621 TYPE_DECL node for each complete tagged type, each array type, and
622 each function type node created) the g++ front end generates a
623 _named_ TYPE_DECL node for each tagged type node created.
624 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
625 generate a DW_TAG_typedef DIE for them. */
626 #define TYPE_DECL_IS_STUB(decl) \
627 (DECL_NAME (decl) == NULL \
628 || (DECL_ARTIFICIAL (decl) \
629 && is_tagged_type (TREE_TYPE (decl)) \
630 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
632 extern int flag_traditional;
634 /* Maximum size (in bytes) of an artificially generated label. */
636 #define MAX_ARTIFICIAL_LABEL_BYTES 30
638 /* Structure to keep track of source filenames. */
640 struct filename_entry {
641 unsigned number;
642 const char * name;
645 typedef struct filename_entry filename_entry;
647 /* Pointer to an array of elements, each one having the structure above. */
649 static filename_entry *filename_table;
651 /* Total number of entries in the table (i.e. array) pointed to by
652 `filename_table'. This is the *total* and includes both used and
653 unused slots. */
655 static unsigned ft_entries_allocated;
657 /* Number of entries in the filename_table which are actually in use. */
659 static unsigned ft_entries;
661 /* Size (in elements) of increments by which we may expand the filename
662 table. Actually, a single hunk of space of this size should be enough
663 for most typical programs. */
665 #define FT_ENTRIES_INCREMENT 64
667 /* Local pointer to the name of the main input file. Initialized in
668 dwarfout_init. */
670 static const char *primary_filename;
672 /* Pointer to the most recent filename for which we produced some line info. */
674 static const char *last_filename;
676 /* Counter to generate unique names for DIEs. */
678 static unsigned next_unused_dienum = 1;
680 /* Number of the DIE which is currently being generated. */
682 static unsigned current_dienum;
684 /* Number to use for the special "pubname" label on the next DIE which
685 represents a function or data object defined in this compilation
686 unit which has "extern" linkage. */
688 static int next_pubname_number = 0;
690 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
692 /* Pointer to a dynamically allocated list of pre-reserved and still
693 pending sibling DIE numbers. Note that this list will grow as needed. */
695 static unsigned *pending_sibling_stack;
697 /* Counter to keep track of the number of pre-reserved and still pending
698 sibling DIE numbers. */
700 static unsigned pending_siblings;
702 /* The currently allocated size of the above list (expressed in number of
703 list elements). */
705 static unsigned pending_siblings_allocated;
707 /* Size (in elements) of increments by which we may expand the pending
708 sibling stack. Actually, a single hunk of space of this size should
709 be enough for most typical programs. */
711 #define PENDING_SIBLINGS_INCREMENT 64
713 /* Non-zero if we are performing our file-scope finalization pass and if
714 we should force out Dwarf descriptions of any and all file-scope
715 tagged types which are still incomplete types. */
717 static int finalizing = 0;
719 /* A pointer to the base of a list of pending types which we haven't
720 generated DIEs for yet, but which we will have to come back to
721 later on. */
723 static tree *pending_types_list;
725 /* Number of elements currently allocated for the pending_types_list. */
727 static unsigned pending_types_allocated;
729 /* Number of elements of pending_types_list currently in use. */
731 static unsigned pending_types;
733 /* Size (in elements) of increments by which we may expand the pending
734 types list. Actually, a single hunk of space of this size should
735 be enough for most typical programs. */
737 #define PENDING_TYPES_INCREMENT 64
739 /* A pointer to the base of a list of incomplete types which might be
740 completed at some later time. */
742 static tree *incomplete_types_list;
744 /* Number of elements currently allocated for the incomplete_types_list. */
745 static unsigned incomplete_types_allocated;
747 /* Number of elements of incomplete_types_list currently in use. */
748 static unsigned incomplete_types;
750 /* Size (in elements) of increments by which we may expand the incomplete
751 types list. Actually, a single hunk of space of this size should
752 be enough for most typical programs. */
753 #define INCOMPLETE_TYPES_INCREMENT 64
755 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
756 This is used in a hack to help us get the DIEs describing types of
757 formal parameters to come *after* all of the DIEs describing the formal
758 parameters themselves. That's necessary in order to be compatible
759 with what the brain-damaged svr4 SDB debugger requires. */
761 static tree fake_containing_scope;
763 /* The number of the current function definition that we are generating
764 debugging information for. These numbers range from 1 up to the maximum
765 number of function definitions contained within the current compilation
766 unit. These numbers are used to create unique labels for various things
767 contained within various function definitions. */
769 static unsigned current_funcdef_number = 1;
771 /* A pointer to the ..._DECL node which we have most recently been working
772 on. We keep this around just in case something about it looks screwy
773 and we want to tell the user what the source coordinates for the actual
774 declaration are. */
776 static tree dwarf_last_decl;
778 /* A flag indicating that we are emitting the member declarations of a
779 class, so member functions and variables should not be entirely emitted.
780 This is a kludge to avoid passing a second argument to output_*_die. */
782 static int in_class;
784 /* Forward declarations for functions defined in this file. */
786 static const char *dwarf_tag_name PARAMS ((unsigned));
787 static const char *dwarf_attr_name PARAMS ((unsigned));
788 static const char *dwarf_stack_op_name PARAMS ((unsigned));
789 static const char *dwarf_typemod_name PARAMS ((unsigned));
790 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
791 static const char *dwarf_fund_type_name PARAMS ((unsigned));
792 static tree decl_ultimate_origin PARAMS ((tree));
793 static tree block_ultimate_origin PARAMS ((tree));
794 static tree decl_class_context PARAMS ((tree));
795 #if 0
796 static void output_unsigned_leb128 PARAMS ((unsigned long));
797 static void output_signed_leb128 PARAMS ((long));
798 #endif
799 static int fundamental_type_code PARAMS ((tree));
800 static tree root_type_1 PARAMS ((tree, int));
801 static tree root_type PARAMS ((tree));
802 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
803 static void write_modifier_bytes PARAMS ((tree, int, int));
804 static inline int type_is_fundamental PARAMS ((tree));
805 static void equate_decl_number_to_die_number PARAMS ((tree));
806 static inline void equate_type_number_to_die_number PARAMS ((tree));
807 static void output_reg_number PARAMS ((rtx));
808 static void output_mem_loc_descriptor PARAMS ((rtx));
809 static void output_loc_descriptor PARAMS ((rtx));
810 static void output_bound_representation PARAMS ((tree, unsigned, int));
811 static void output_enumeral_list PARAMS ((tree));
812 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
813 static inline tree field_type PARAMS ((tree));
814 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
815 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
816 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
817 static inline void sibling_attribute PARAMS ((void));
818 static void location_attribute PARAMS ((rtx));
819 static void data_member_location_attribute PARAMS ((tree));
820 static void const_value_attribute PARAMS ((rtx));
821 static void location_or_const_value_attribute PARAMS ((tree));
822 static inline void name_attribute PARAMS ((const char *));
823 static inline void fund_type_attribute PARAMS ((unsigned));
824 static void mod_fund_type_attribute PARAMS ((tree, int, int));
825 static inline void user_def_type_attribute PARAMS ((tree));
826 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
827 #ifdef USE_ORDERING_ATTRIBUTE
828 static inline void ordering_attribute PARAMS ((unsigned));
829 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
830 static void subscript_data_attribute PARAMS ((tree));
831 static void byte_size_attribute PARAMS ((tree));
832 static inline void bit_offset_attribute PARAMS ((tree));
833 static inline void bit_size_attribute PARAMS ((tree));
834 static inline void element_list_attribute PARAMS ((tree));
835 static inline void stmt_list_attribute PARAMS ((const char *));
836 static inline void low_pc_attribute PARAMS ((const char *));
837 static inline void high_pc_attribute PARAMS ((const char *));
838 static inline void body_begin_attribute PARAMS ((const char *));
839 static inline void body_end_attribute PARAMS ((const char *));
840 static inline void language_attribute PARAMS ((unsigned));
841 static inline void member_attribute PARAMS ((tree));
842 #if 0
843 static inline void string_length_attribute PARAMS ((tree));
844 #endif
845 static inline void comp_dir_attribute PARAMS ((const char *));
846 static inline void sf_names_attribute PARAMS ((const char *));
847 static inline void src_info_attribute PARAMS ((const char *));
848 static inline void mac_info_attribute PARAMS ((const char *));
849 static inline void prototyped_attribute PARAMS ((tree));
850 static inline void producer_attribute PARAMS ((const char *));
851 static inline void inline_attribute PARAMS ((tree));
852 static inline void containing_type_attribute PARAMS ((tree));
853 static inline void abstract_origin_attribute PARAMS ((tree));
854 #ifdef DWARF_DECL_COORDINATES
855 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
856 #endif /* defined(DWARF_DECL_COORDINATES) */
857 static inline void pure_or_virtual_attribute PARAMS ((tree));
858 static void name_and_src_coords_attributes PARAMS ((tree));
859 static void type_attribute PARAMS ((tree, int, int));
860 static const char *type_tag PARAMS ((tree));
861 static inline void dienum_push PARAMS ((void));
862 static inline void dienum_pop PARAMS ((void));
863 static inline tree member_declared_type PARAMS ((tree));
864 static const char *function_start_label PARAMS ((tree));
865 static void output_array_type_die PARAMS ((void *));
866 static void output_set_type_die PARAMS ((void *));
867 #if 0
868 static void output_entry_point_die PARAMS ((void *));
869 #endif
870 static void output_inlined_enumeration_type_die PARAMS ((void *));
871 static void output_inlined_structure_type_die PARAMS ((void *));
872 static void output_inlined_union_type_die PARAMS ((void *));
873 static void output_enumeration_type_die PARAMS ((void *));
874 static void output_formal_parameter_die PARAMS ((void *));
875 static void output_global_subroutine_die PARAMS ((void *));
876 static void output_global_variable_die PARAMS ((void *));
877 static void output_label_die PARAMS ((void *));
878 static void output_lexical_block_die PARAMS ((void *));
879 static void output_inlined_subroutine_die PARAMS ((void *));
880 static void output_local_variable_die PARAMS ((void *));
881 static void output_member_die PARAMS ((void *));
882 #if 0
883 static void output_pointer_type_die PARAMS ((void *));
884 static void output_reference_type_die PARAMS ((void *));
885 #endif
886 static void output_ptr_to_mbr_type_die PARAMS ((void *));
887 static void output_compile_unit_die PARAMS ((void *));
888 static void output_string_type_die PARAMS ((void *));
889 static void output_inheritance_die PARAMS ((void *));
890 static void output_structure_type_die PARAMS ((void *));
891 static void output_local_subroutine_die PARAMS ((void *));
892 static void output_subroutine_type_die PARAMS ((void *));
893 static void output_typedef_die PARAMS ((void *));
894 static void output_union_type_die PARAMS ((void *));
895 static void output_unspecified_parameters_die PARAMS ((void *));
896 static void output_padded_null_die PARAMS ((void *));
897 static void output_die PARAMS ((void (*)(void *), void *));
898 static void end_sibling_chain PARAMS ((void));
899 static void output_formal_types PARAMS ((tree));
900 static void pend_type PARAMS ((tree));
901 static int type_ok_for_scope PARAMS ((tree, tree));
902 static void output_pending_types_for_scope PARAMS ((tree));
903 static void output_type PARAMS ((tree, tree));
904 static void output_tagged_type_instantiation PARAMS ((tree));
905 static void output_block PARAMS ((tree, int));
906 static void output_decls_for_scope PARAMS ((tree, int));
907 static void output_decl PARAMS ((tree, tree));
908 static void shuffle_filename_entry PARAMS ((filename_entry *));
909 static void generate_new_sfname_entry PARAMS ((void));
910 static unsigned lookup_filename PARAMS ((const char *));
911 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
912 static void generate_macinfo_entry PARAMS ((const char *, const char *));
913 static int is_pseudo_reg PARAMS ((rtx));
914 static tree type_main_variant PARAMS ((tree));
915 static int is_tagged_type PARAMS ((tree));
916 static int is_redundant_typedef PARAMS ((tree));
917 static void add_incomplete_type PARAMS ((tree));
918 static void retry_incomplete_types PARAMS ((void));
920 /* Definitions of defaults for assembler-dependent names of various
921 pseudo-ops and section names.
923 Theses may be overridden in your tm.h file (if necessary) for your
924 particular assembler. The default values provided here correspond to
925 what is expected by "standard" AT&T System V.4 assemblers. */
927 #ifndef FILE_ASM_OP
928 #define FILE_ASM_OP "\t.file\t"
929 #endif
930 #ifndef VERSION_ASM_OP
931 #define VERSION_ASM_OP "\t.version\t"
932 #endif
933 #ifndef UNALIGNED_SHORT_ASM_OP
934 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
935 #endif
936 #ifndef UNALIGNED_INT_ASM_OP
937 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
938 #endif
939 #ifndef ASM_BYTE_OP
940 #define ASM_BYTE_OP "\t.byte\t"
941 #endif
942 #ifndef SET_ASM_OP
943 #define SET_ASM_OP "\t.set\t"
944 #endif
946 /* Pseudo-ops for pushing the current section onto the section stack (and
947 simultaneously changing to a new section) and for poping back to the
948 section we were in immediately before this one. Note that most svr4
949 assemblers only maintain a one level stack... you can push all the
950 sections you want, but you can only pop out one level. (The sparc
951 svr4 assembler is an exception to this general rule.) That's
952 OK because we only use at most one level of the section stack herein. */
954 #ifndef PUSHSECTION_ASM_OP
955 #define PUSHSECTION_ASM_OP "\t.section\t"
956 #endif
957 #ifndef POPSECTION_ASM_OP
958 #define POPSECTION_ASM_OP "\t.previous"
959 #endif
961 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
962 to print the PUSHSECTION_ASM_OP and the section name. The default here
963 works for almost all svr4 assemblers, except for the sparc, where the
964 section name must be enclosed in double quotes. (See sparcv4.h.) */
966 #ifndef PUSHSECTION_FORMAT
967 #define PUSHSECTION_FORMAT "%s%s\n"
968 #endif
970 #ifndef DEBUG_SECTION
971 #define DEBUG_SECTION ".debug"
972 #endif
973 #ifndef LINE_SECTION
974 #define LINE_SECTION ".line"
975 #endif
976 #ifndef SFNAMES_SECTION
977 #define SFNAMES_SECTION ".debug_sfnames"
978 #endif
979 #ifndef SRCINFO_SECTION
980 #define SRCINFO_SECTION ".debug_srcinfo"
981 #endif
982 #ifndef MACINFO_SECTION
983 #define MACINFO_SECTION ".debug_macinfo"
984 #endif
985 #ifndef PUBNAMES_SECTION
986 #define PUBNAMES_SECTION ".debug_pubnames"
987 #endif
988 #ifndef ARANGES_SECTION
989 #define ARANGES_SECTION ".debug_aranges"
990 #endif
991 #ifndef TEXT_SECTION
992 #define TEXT_SECTION ".text"
993 #endif
994 #ifndef DATA_SECTION
995 #define DATA_SECTION ".data"
996 #endif
997 #ifndef DATA1_SECTION
998 #define DATA1_SECTION ".data1"
999 #endif
1000 #ifndef RODATA_SECTION
1001 #define RODATA_SECTION ".rodata"
1002 #endif
1003 #ifndef RODATA1_SECTION
1004 #define RODATA1_SECTION ".rodata1"
1005 #endif
1006 #ifndef BSS_SECTION
1007 #define BSS_SECTION ".bss"
1008 #endif
1010 /* Definitions of defaults for formats and names of various special
1011 (artificial) labels which may be generated within this file (when
1012 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
1014 If necessary, these may be overridden from within your tm.h file,
1015 but typically, you should never need to override these.
1017 These labels have been hacked (temporarily) so that they all begin with
1018 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
1019 stock m88k/svr4 assembler, both of which need to see .L at the start of
1020 a label in order to prevent that label from going into the linker symbol
1021 table). When I get time, I'll have to fix this the right way so that we
1022 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
1023 but that will require a rather massive set of changes. For the moment,
1024 the following definitions out to produce the right results for all svr4
1025 and svr3 assemblers. -- rfg
1028 #ifndef TEXT_BEGIN_LABEL
1029 #define TEXT_BEGIN_LABEL "*.L_text_b"
1030 #endif
1031 #ifndef TEXT_END_LABEL
1032 #define TEXT_END_LABEL "*.L_text_e"
1033 #endif
1035 #ifndef DATA_BEGIN_LABEL
1036 #define DATA_BEGIN_LABEL "*.L_data_b"
1037 #endif
1038 #ifndef DATA_END_LABEL
1039 #define DATA_END_LABEL "*.L_data_e"
1040 #endif
1042 #ifndef DATA1_BEGIN_LABEL
1043 #define DATA1_BEGIN_LABEL "*.L_data1_b"
1044 #endif
1045 #ifndef DATA1_END_LABEL
1046 #define DATA1_END_LABEL "*.L_data1_e"
1047 #endif
1049 #ifndef RODATA_BEGIN_LABEL
1050 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
1051 #endif
1052 #ifndef RODATA_END_LABEL
1053 #define RODATA_END_LABEL "*.L_rodata_e"
1054 #endif
1056 #ifndef RODATA1_BEGIN_LABEL
1057 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
1058 #endif
1059 #ifndef RODATA1_END_LABEL
1060 #define RODATA1_END_LABEL "*.L_rodata1_e"
1061 #endif
1063 #ifndef BSS_BEGIN_LABEL
1064 #define BSS_BEGIN_LABEL "*.L_bss_b"
1065 #endif
1066 #ifndef BSS_END_LABEL
1067 #define BSS_END_LABEL "*.L_bss_e"
1068 #endif
1070 #ifndef LINE_BEGIN_LABEL
1071 #define LINE_BEGIN_LABEL "*.L_line_b"
1072 #endif
1073 #ifndef LINE_LAST_ENTRY_LABEL
1074 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
1075 #endif
1076 #ifndef LINE_END_LABEL
1077 #define LINE_END_LABEL "*.L_line_e"
1078 #endif
1080 #ifndef DEBUG_BEGIN_LABEL
1081 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
1082 #endif
1083 #ifndef SFNAMES_BEGIN_LABEL
1084 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
1085 #endif
1086 #ifndef SRCINFO_BEGIN_LABEL
1087 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
1088 #endif
1089 #ifndef MACINFO_BEGIN_LABEL
1090 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
1091 #endif
1093 #ifndef DIE_BEGIN_LABEL_FMT
1094 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
1095 #endif
1096 #ifndef DIE_END_LABEL_FMT
1097 #define DIE_END_LABEL_FMT "*.L_D%u_e"
1098 #endif
1099 #ifndef PUB_DIE_LABEL_FMT
1100 #define PUB_DIE_LABEL_FMT "*.L_P%u"
1101 #endif
1102 #ifndef BLOCK_BEGIN_LABEL_FMT
1103 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
1104 #endif
1105 #ifndef BLOCK_END_LABEL_FMT
1106 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
1107 #endif
1108 #ifndef SS_BEGIN_LABEL_FMT
1109 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
1110 #endif
1111 #ifndef SS_END_LABEL_FMT
1112 #define SS_END_LABEL_FMT "*.L_s%u_e"
1113 #endif
1114 #ifndef EE_BEGIN_LABEL_FMT
1115 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
1116 #endif
1117 #ifndef EE_END_LABEL_FMT
1118 #define EE_END_LABEL_FMT "*.L_e%u_e"
1119 #endif
1120 #ifndef MT_BEGIN_LABEL_FMT
1121 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
1122 #endif
1123 #ifndef MT_END_LABEL_FMT
1124 #define MT_END_LABEL_FMT "*.L_t%u_e"
1125 #endif
1126 #ifndef LOC_BEGIN_LABEL_FMT
1127 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
1128 #endif
1129 #ifndef LOC_END_LABEL_FMT
1130 #define LOC_END_LABEL_FMT "*.L_l%u_e"
1131 #endif
1132 #ifndef BOUND_BEGIN_LABEL_FMT
1133 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
1134 #endif
1135 #ifndef BOUND_END_LABEL_FMT
1136 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
1137 #endif
1138 #ifndef DERIV_BEGIN_LABEL_FMT
1139 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
1140 #endif
1141 #ifndef DERIV_END_LABEL_FMT
1142 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
1143 #endif
1144 #ifndef SL_BEGIN_LABEL_FMT
1145 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
1146 #endif
1147 #ifndef SL_END_LABEL_FMT
1148 #define SL_END_LABEL_FMT "*.L_sl%u_e"
1149 #endif
1150 #ifndef BODY_BEGIN_LABEL_FMT
1151 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
1152 #endif
1153 #ifndef BODY_END_LABEL_FMT
1154 #define BODY_END_LABEL_FMT "*.L_b%u_e"
1155 #endif
1156 #ifndef FUNC_END_LABEL_FMT
1157 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
1158 #endif
1159 #ifndef TYPE_NAME_FMT
1160 #define TYPE_NAME_FMT "*.L_T%u"
1161 #endif
1162 #ifndef DECL_NAME_FMT
1163 #define DECL_NAME_FMT "*.L_E%u"
1164 #endif
1165 #ifndef LINE_CODE_LABEL_FMT
1166 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
1167 #endif
1168 #ifndef SFNAMES_ENTRY_LABEL_FMT
1169 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
1170 #endif
1171 #ifndef LINE_ENTRY_LABEL_FMT
1172 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
1173 #endif
1175 /* Definitions of defaults for various types of primitive assembly language
1176 output operations.
1178 If necessary, these may be overridden from within your tm.h file,
1179 but typically, you shouldn't need to override these. */
1181 #ifndef ASM_OUTPUT_PUSH_SECTION
1182 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
1183 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
1184 #endif
1186 #ifndef ASM_OUTPUT_POP_SECTION
1187 #define ASM_OUTPUT_POP_SECTION(FILE) \
1188 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
1189 #endif
1191 #ifndef ASM_OUTPUT_DWARF_DELTA2
1192 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
1193 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
1194 assemble_name (FILE, LABEL1); \
1195 fprintf (FILE, "-"); \
1196 assemble_name (FILE, LABEL2); \
1197 fprintf (FILE, "\n"); \
1198 } while (0)
1199 #endif
1201 #ifndef ASM_OUTPUT_DWARF_DELTA4
1202 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
1203 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1204 assemble_name (FILE, LABEL1); \
1205 fprintf (FILE, "-"); \
1206 assemble_name (FILE, LABEL2); \
1207 fprintf (FILE, "\n"); \
1208 } while (0)
1209 #endif
1211 #ifndef ASM_OUTPUT_DWARF_TAG
1212 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
1213 do { \
1214 fprintf ((FILE), "%s0x%x", \
1215 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
1216 if (flag_debug_asm) \
1217 fprintf ((FILE), "\t%s %s", \
1218 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
1219 fputc ('\n', (FILE)); \
1220 } while (0)
1221 #endif
1223 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
1224 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
1225 do { \
1226 fprintf ((FILE), "%s0x%x", \
1227 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
1228 if (flag_debug_asm) \
1229 fprintf ((FILE), "\t%s %s", \
1230 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
1231 fputc ('\n', (FILE)); \
1232 } while (0)
1233 #endif
1235 #ifndef ASM_OUTPUT_DWARF_STACK_OP
1236 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
1237 do { \
1238 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) OP); \
1239 if (flag_debug_asm) \
1240 fprintf ((FILE), "\t%s %s", \
1241 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
1242 fputc ('\n', (FILE)); \
1243 } while (0)
1244 #endif
1246 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
1247 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
1248 do { \
1249 fprintf ((FILE), "%s0x%x", \
1250 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
1251 if (flag_debug_asm) \
1252 fprintf ((FILE), "\t%s %s", \
1253 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
1254 fputc ('\n', (FILE)); \
1255 } while (0)
1256 #endif
1258 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
1259 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
1260 do { \
1261 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) FMT); \
1262 if (flag_debug_asm) \
1263 fprintf ((FILE), "\t%s %s", \
1264 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
1265 fputc ('\n', (FILE)); \
1266 } while (0)
1267 #endif
1269 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
1270 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
1271 do { \
1272 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) MOD); \
1273 if (flag_debug_asm) \
1274 fprintf ((FILE), "\t%s %s", \
1275 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
1276 fputc ('\n', (FILE)); \
1277 } while (0)
1278 #endif
1280 #ifndef ASM_OUTPUT_DWARF_ADDR
1281 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
1282 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1283 assemble_name (FILE, LABEL); \
1284 fprintf (FILE, "\n"); \
1285 } while (0)
1286 #endif
1288 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
1289 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
1290 do { \
1291 fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1292 output_addr_const ((FILE), (RTX)); \
1293 fputc ('\n', (FILE)); \
1294 } while (0)
1295 #endif
1297 #ifndef ASM_OUTPUT_DWARF_REF
1298 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
1299 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1300 assemble_name (FILE, LABEL); \
1301 fprintf (FILE, "\n"); \
1302 } while (0)
1303 #endif
1305 #ifndef ASM_OUTPUT_DWARF_DATA1
1306 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
1307 fprintf ((FILE), "%s0x%x\n", ASM_BYTE_OP, VALUE)
1308 #endif
1310 #ifndef ASM_OUTPUT_DWARF_DATA2
1311 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
1312 fprintf ((FILE), "%s0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
1313 #endif
1315 #ifndef ASM_OUTPUT_DWARF_DATA4
1316 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
1317 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
1318 #endif
1320 #ifndef ASM_OUTPUT_DWARF_DATA8
1321 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
1322 do { \
1323 if (WORDS_BIG_ENDIAN) \
1325 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1326 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1328 else \
1330 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1331 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1333 } while (0)
1334 #endif
1336 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
1337 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
1338 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
1339 defined, we call it, then issue the line feed. If not, we supply a
1340 default defintion of calling ASM_OUTPUT_ASCII */
1342 #ifndef ASM_OUTPUT_DWARF_STRING
1343 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1344 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
1345 #else
1346 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1347 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
1348 #endif
1351 /************************ general utility functions **************************/
1353 static inline int
1354 is_pseudo_reg (rtl)
1355 register rtx rtl;
1357 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1358 || ((GET_CODE (rtl) == SUBREG)
1359 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
1362 static inline tree
1363 type_main_variant (type)
1364 register tree type;
1366 type = TYPE_MAIN_VARIANT (type);
1368 /* There really should be only one main variant among any group of variants
1369 of a given type (and all of the MAIN_VARIANT values for all members of
1370 the group should point to that one type) but sometimes the C front-end
1371 messes this up for array types, so we work around that bug here. */
1373 if (TREE_CODE (type) == ARRAY_TYPE)
1375 while (type != TYPE_MAIN_VARIANT (type))
1376 type = TYPE_MAIN_VARIANT (type);
1379 return type;
1382 /* Return non-zero if the given type node represents a tagged type. */
1384 static inline int
1385 is_tagged_type (type)
1386 register tree type;
1388 register enum tree_code code = TREE_CODE (type);
1390 return (code == RECORD_TYPE || code == UNION_TYPE
1391 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1394 static const char *
1395 dwarf_tag_name (tag)
1396 register unsigned tag;
1398 switch (tag)
1400 case TAG_padding: return "TAG_padding";
1401 case TAG_array_type: return "TAG_array_type";
1402 case TAG_class_type: return "TAG_class_type";
1403 case TAG_entry_point: return "TAG_entry_point";
1404 case TAG_enumeration_type: return "TAG_enumeration_type";
1405 case TAG_formal_parameter: return "TAG_formal_parameter";
1406 case TAG_global_subroutine: return "TAG_global_subroutine";
1407 case TAG_global_variable: return "TAG_global_variable";
1408 case TAG_label: return "TAG_label";
1409 case TAG_lexical_block: return "TAG_lexical_block";
1410 case TAG_local_variable: return "TAG_local_variable";
1411 case TAG_member: return "TAG_member";
1412 case TAG_pointer_type: return "TAG_pointer_type";
1413 case TAG_reference_type: return "TAG_reference_type";
1414 case TAG_compile_unit: return "TAG_compile_unit";
1415 case TAG_string_type: return "TAG_string_type";
1416 case TAG_structure_type: return "TAG_structure_type";
1417 case TAG_subroutine: return "TAG_subroutine";
1418 case TAG_subroutine_type: return "TAG_subroutine_type";
1419 case TAG_typedef: return "TAG_typedef";
1420 case TAG_union_type: return "TAG_union_type";
1421 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
1422 case TAG_variant: return "TAG_variant";
1423 case TAG_common_block: return "TAG_common_block";
1424 case TAG_common_inclusion: return "TAG_common_inclusion";
1425 case TAG_inheritance: return "TAG_inheritance";
1426 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
1427 case TAG_module: return "TAG_module";
1428 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
1429 case TAG_set_type: return "TAG_set_type";
1430 case TAG_subrange_type: return "TAG_subrange_type";
1431 case TAG_with_stmt: return "TAG_with_stmt";
1433 /* GNU extensions. */
1435 case TAG_format_label: return "TAG_format_label";
1436 case TAG_namelist: return "TAG_namelist";
1437 case TAG_function_template: return "TAG_function_template";
1438 case TAG_class_template: return "TAG_class_template";
1440 default: return "TAG_<unknown>";
1444 static const char *
1445 dwarf_attr_name (attr)
1446 register unsigned attr;
1448 switch (attr)
1450 case AT_sibling: return "AT_sibling";
1451 case AT_location: return "AT_location";
1452 case AT_name: return "AT_name";
1453 case AT_fund_type: return "AT_fund_type";
1454 case AT_mod_fund_type: return "AT_mod_fund_type";
1455 case AT_user_def_type: return "AT_user_def_type";
1456 case AT_mod_u_d_type: return "AT_mod_u_d_type";
1457 case AT_ordering: return "AT_ordering";
1458 case AT_subscr_data: return "AT_subscr_data";
1459 case AT_byte_size: return "AT_byte_size";
1460 case AT_bit_offset: return "AT_bit_offset";
1461 case AT_bit_size: return "AT_bit_size";
1462 case AT_element_list: return "AT_element_list";
1463 case AT_stmt_list: return "AT_stmt_list";
1464 case AT_low_pc: return "AT_low_pc";
1465 case AT_high_pc: return "AT_high_pc";
1466 case AT_language: return "AT_language";
1467 case AT_member: return "AT_member";
1468 case AT_discr: return "AT_discr";
1469 case AT_discr_value: return "AT_discr_value";
1470 case AT_string_length: return "AT_string_length";
1471 case AT_common_reference: return "AT_common_reference";
1472 case AT_comp_dir: return "AT_comp_dir";
1473 case AT_const_value_string: return "AT_const_value_string";
1474 case AT_const_value_data2: return "AT_const_value_data2";
1475 case AT_const_value_data4: return "AT_const_value_data4";
1476 case AT_const_value_data8: return "AT_const_value_data8";
1477 case AT_const_value_block2: return "AT_const_value_block2";
1478 case AT_const_value_block4: return "AT_const_value_block4";
1479 case AT_containing_type: return "AT_containing_type";
1480 case AT_default_value_addr: return "AT_default_value_addr";
1481 case AT_default_value_data2: return "AT_default_value_data2";
1482 case AT_default_value_data4: return "AT_default_value_data4";
1483 case AT_default_value_data8: return "AT_default_value_data8";
1484 case AT_default_value_string: return "AT_default_value_string";
1485 case AT_friends: return "AT_friends";
1486 case AT_inline: return "AT_inline";
1487 case AT_is_optional: return "AT_is_optional";
1488 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1489 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1490 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1491 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1492 case AT_private: return "AT_private";
1493 case AT_producer: return "AT_producer";
1494 case AT_program: return "AT_program";
1495 case AT_protected: return "AT_protected";
1496 case AT_prototyped: return "AT_prototyped";
1497 case AT_public: return "AT_public";
1498 case AT_pure_virtual: return "AT_pure_virtual";
1499 case AT_return_addr: return "AT_return_addr";
1500 case AT_abstract_origin: return "AT_abstract_origin";
1501 case AT_start_scope: return "AT_start_scope";
1502 case AT_stride_size: return "AT_stride_size";
1503 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1504 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1505 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1506 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1507 case AT_virtual: return "AT_virtual";
1509 /* GNU extensions */
1511 case AT_sf_names: return "AT_sf_names";
1512 case AT_src_info: return "AT_src_info";
1513 case AT_mac_info: return "AT_mac_info";
1514 case AT_src_coords: return "AT_src_coords";
1515 case AT_body_begin: return "AT_body_begin";
1516 case AT_body_end: return "AT_body_end";
1518 default: return "AT_<unknown>";
1522 static const char *
1523 dwarf_stack_op_name (op)
1524 register unsigned op;
1526 switch (op)
1528 case OP_REG: return "OP_REG";
1529 case OP_BASEREG: return "OP_BASEREG";
1530 case OP_ADDR: return "OP_ADDR";
1531 case OP_CONST: return "OP_CONST";
1532 case OP_DEREF2: return "OP_DEREF2";
1533 case OP_DEREF4: return "OP_DEREF4";
1534 case OP_ADD: return "OP_ADD";
1535 default: return "OP_<unknown>";
1539 static const char *
1540 dwarf_typemod_name (mod)
1541 register unsigned mod;
1543 switch (mod)
1545 case MOD_pointer_to: return "MOD_pointer_to";
1546 case MOD_reference_to: return "MOD_reference_to";
1547 case MOD_const: return "MOD_const";
1548 case MOD_volatile: return "MOD_volatile";
1549 default: return "MOD_<unknown>";
1553 static const char *
1554 dwarf_fmt_byte_name (fmt)
1555 register unsigned fmt;
1557 switch (fmt)
1559 case FMT_FT_C_C: return "FMT_FT_C_C";
1560 case FMT_FT_C_X: return "FMT_FT_C_X";
1561 case FMT_FT_X_C: return "FMT_FT_X_C";
1562 case FMT_FT_X_X: return "FMT_FT_X_X";
1563 case FMT_UT_C_C: return "FMT_UT_C_C";
1564 case FMT_UT_C_X: return "FMT_UT_C_X";
1565 case FMT_UT_X_C: return "FMT_UT_X_C";
1566 case FMT_UT_X_X: return "FMT_UT_X_X";
1567 case FMT_ET: return "FMT_ET";
1568 default: return "FMT_<unknown>";
1572 static const char *
1573 dwarf_fund_type_name (ft)
1574 register unsigned ft;
1576 switch (ft)
1578 case FT_char: return "FT_char";
1579 case FT_signed_char: return "FT_signed_char";
1580 case FT_unsigned_char: return "FT_unsigned_char";
1581 case FT_short: return "FT_short";
1582 case FT_signed_short: return "FT_signed_short";
1583 case FT_unsigned_short: return "FT_unsigned_short";
1584 case FT_integer: return "FT_integer";
1585 case FT_signed_integer: return "FT_signed_integer";
1586 case FT_unsigned_integer: return "FT_unsigned_integer";
1587 case FT_long: return "FT_long";
1588 case FT_signed_long: return "FT_signed_long";
1589 case FT_unsigned_long: return "FT_unsigned_long";
1590 case FT_pointer: return "FT_pointer";
1591 case FT_float: return "FT_float";
1592 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1593 case FT_ext_prec_float: return "FT_ext_prec_float";
1594 case FT_complex: return "FT_complex";
1595 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1596 case FT_void: return "FT_void";
1597 case FT_boolean: return "FT_boolean";
1598 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1599 case FT_label: return "FT_label";
1601 /* GNU extensions. */
1603 case FT_long_long: return "FT_long_long";
1604 case FT_signed_long_long: return "FT_signed_long_long";
1605 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1607 case FT_int8: return "FT_int8";
1608 case FT_signed_int8: return "FT_signed_int8";
1609 case FT_unsigned_int8: return "FT_unsigned_int8";
1610 case FT_int16: return "FT_int16";
1611 case FT_signed_int16: return "FT_signed_int16";
1612 case FT_unsigned_int16: return "FT_unsigned_int16";
1613 case FT_int32: return "FT_int32";
1614 case FT_signed_int32: return "FT_signed_int32";
1615 case FT_unsigned_int32: return "FT_unsigned_int32";
1616 case FT_int64: return "FT_int64";
1617 case FT_signed_int64: return "FT_signed_int64";
1618 case FT_unsigned_int64: return "FT_unsigned_int64";
1619 case FT_int128: return "FT_int128";
1620 case FT_signed_int128: return "FT_signed_int128";
1621 case FT_unsigned_int128: return "FT_unsigned_int128";
1623 case FT_real32: return "FT_real32";
1624 case FT_real64: return "FT_real64";
1625 case FT_real96: return "FT_real96";
1626 case FT_real128: return "FT_real128";
1628 default: return "FT_<unknown>";
1632 /* Determine the "ultimate origin" of a decl. The decl may be an
1633 inlined instance of an inlined instance of a decl which is local
1634 to an inline function, so we have to trace all of the way back
1635 through the origin chain to find out what sort of node actually
1636 served as the original seed for the given block. */
1638 static tree
1639 decl_ultimate_origin (decl)
1640 register tree decl;
1642 #ifdef ENABLE_CHECKING
1643 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1644 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1645 most distant ancestor, this should never happen. */
1646 abort ();
1647 #endif
1649 return DECL_ABSTRACT_ORIGIN (decl);
1652 /* Determine the "ultimate origin" of a block. The block may be an
1653 inlined instance of an inlined instance of a block which is local
1654 to an inline function, so we have to trace all of the way back
1655 through the origin chain to find out what sort of node actually
1656 served as the original seed for the given block. */
1658 static tree
1659 block_ultimate_origin (block)
1660 register tree block;
1662 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1664 if (immediate_origin == NULL)
1665 return NULL;
1666 else
1668 register tree ret_val;
1669 register tree lookahead = immediate_origin;
1673 ret_val = lookahead;
1674 lookahead = (TREE_CODE (ret_val) == BLOCK)
1675 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1676 : NULL;
1678 while (lookahead != NULL && lookahead != ret_val);
1679 return ret_val;
1683 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1684 of a virtual function may refer to a base class, so we check the 'this'
1685 parameter. */
1687 static tree
1688 decl_class_context (decl)
1689 tree decl;
1691 tree context = NULL_TREE;
1692 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1693 context = DECL_CONTEXT (decl);
1694 else
1695 context = TYPE_MAIN_VARIANT
1696 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1698 if (context && !TYPE_P (context))
1699 context = NULL_TREE;
1701 return context;
1704 #if 0
1705 static void
1706 output_unsigned_leb128 (value)
1707 register unsigned long value;
1709 register unsigned long orig_value = value;
1713 register unsigned byte = (value & 0x7f);
1715 value >>= 7;
1716 if (value != 0) /* more bytes to follow */
1717 byte |= 0x80;
1718 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1719 if (flag_debug_asm && value == 0)
1720 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1721 ASM_COMMENT_START, orig_value);
1722 fputc ('\n', asm_out_file);
1724 while (value != 0);
1727 static void
1728 output_signed_leb128 (value)
1729 register long value;
1731 register long orig_value = value;
1732 register int negative = (value < 0);
1733 register int more;
1737 register unsigned byte = (value & 0x7f);
1739 value >>= 7;
1740 if (negative)
1741 value |= 0xfe000000; /* manually sign extend */
1742 if (((value == 0) && ((byte & 0x40) == 0))
1743 || ((value == -1) && ((byte & 0x40) == 1)))
1744 more = 0;
1745 else
1747 byte |= 0x80;
1748 more = 1;
1750 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1751 if (flag_debug_asm && more == 0)
1752 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1753 ASM_COMMENT_START, orig_value);
1754 fputc ('\n', asm_out_file);
1756 while (more);
1758 #endif
1760 /**************** utility functions for attribute functions ******************/
1762 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1763 type code for the given type.
1765 This routine must only be called for GCC type nodes that correspond to
1766 Dwarf fundamental types.
1768 The current Dwarf draft specification calls for Dwarf fundamental types
1769 to accurately reflect the fact that a given type was either a "plain"
1770 integral type or an explicitly "signed" integral type. Unfortunately,
1771 we can't always do this, because GCC may already have thrown away the
1772 information about the precise way in which the type was originally
1773 specified, as in:
1775 typedef signed int my_type;
1777 struct s { my_type f; };
1779 Since we may be stuck here without enought information to do exactly
1780 what is called for in the Dwarf draft specification, we do the best
1781 that we can under the circumstances and always use the "plain" integral
1782 fundamental type codes for int, short, and long types. That's probably
1783 good enough. The additional accuracy called for in the current DWARF
1784 draft specification is probably never even useful in practice. */
1786 static int
1787 fundamental_type_code (type)
1788 register tree type;
1790 if (TREE_CODE (type) == ERROR_MARK)
1791 return 0;
1793 switch (TREE_CODE (type))
1795 case ERROR_MARK:
1796 return FT_void;
1798 case VOID_TYPE:
1799 return FT_void;
1801 case INTEGER_TYPE:
1802 /* Carefully distinguish all the standard types of C,
1803 without messing up if the language is not C.
1804 Note that we check only for the names that contain spaces;
1805 other names might occur by coincidence in other languages. */
1806 if (TYPE_NAME (type) != 0
1807 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1808 && DECL_NAME (TYPE_NAME (type)) != 0
1809 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1811 const char *name =
1812 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1814 if (!strcmp (name, "unsigned char"))
1815 return FT_unsigned_char;
1816 if (!strcmp (name, "signed char"))
1817 return FT_signed_char;
1818 if (!strcmp (name, "unsigned int"))
1819 return FT_unsigned_integer;
1820 if (!strcmp (name, "short int"))
1821 return FT_short;
1822 if (!strcmp (name, "short unsigned int"))
1823 return FT_unsigned_short;
1824 if (!strcmp (name, "long int"))
1825 return FT_long;
1826 if (!strcmp (name, "long unsigned int"))
1827 return FT_unsigned_long;
1828 if (!strcmp (name, "long long int"))
1829 return FT_long_long; /* Not grok'ed by svr4 SDB */
1830 if (!strcmp (name, "long long unsigned int"))
1831 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1834 /* Most integer types will be sorted out above, however, for the
1835 sake of special `array index' integer types, the following code
1836 is also provided. */
1838 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1839 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1841 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1842 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1844 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1845 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1847 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1848 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1850 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1851 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1853 if (TYPE_MODE (type) == TImode)
1854 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1856 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1857 if (TYPE_PRECISION (type) == 1)
1858 return FT_boolean;
1860 abort ();
1862 case REAL_TYPE:
1863 /* Carefully distinguish all the standard types of C,
1864 without messing up if the language is not C. */
1865 if (TYPE_NAME (type) != 0
1866 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1867 && DECL_NAME (TYPE_NAME (type)) != 0
1868 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1870 const char *name =
1871 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1873 /* Note that here we can run afowl of a serious bug in "classic"
1874 svr4 SDB debuggers. They don't seem to understand the
1875 FT_ext_prec_float type (even though they should). */
1877 if (!strcmp (name, "long double"))
1878 return FT_ext_prec_float;
1881 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1883 /* On the SH, when compiling with -m3e or -m4-single-only, both
1884 float and double are 32 bits. But since the debugger doesn't
1885 know about the subtarget, it always thinks double is 64 bits.
1886 So we have to tell the debugger that the type is float to
1887 make the output of the 'print' command etc. readable. */
1888 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1889 return FT_float;
1890 return FT_dbl_prec_float;
1892 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1893 return FT_float;
1895 /* Note that here we can run afowl of a serious bug in "classic"
1896 svr4 SDB debuggers. They don't seem to understand the
1897 FT_ext_prec_float type (even though they should). */
1899 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1900 return FT_ext_prec_float;
1901 abort ();
1903 case COMPLEX_TYPE:
1904 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1906 case CHAR_TYPE:
1907 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1909 case BOOLEAN_TYPE:
1910 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1912 default:
1913 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1915 return 0;
1918 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1919 the Dwarf "root" type for the given input type. The Dwarf "root" type
1920 of a given type is generally the same as the given type, except that if
1921 the given type is a pointer or reference type, then the root type of
1922 the given type is the root type of the "basis" type for the pointer or
1923 reference type. (This definition of the "root" type is recursive.)
1924 Also, the root type of a `const' qualified type or a `volatile'
1925 qualified type is the root type of the given type without the
1926 qualifiers. */
1928 static tree
1929 root_type_1 (type, count)
1930 register tree type;
1931 register int count;
1933 /* Give up after searching 1000 levels, in case this is a recursive
1934 pointer type. Such types are possible in Ada, but it is not possible
1935 to represent them in DWARF1 debug info. */
1936 if (count > 1000)
1937 return error_mark_node;
1939 switch (TREE_CODE (type))
1941 case ERROR_MARK:
1942 return error_mark_node;
1944 case POINTER_TYPE:
1945 case REFERENCE_TYPE:
1946 return root_type_1 (TREE_TYPE (type), count+1);
1948 default:
1949 return type;
1953 static tree
1954 root_type (type)
1955 register tree type;
1957 type = root_type_1 (type, 0);
1958 if (type != error_mark_node)
1959 type = type_main_variant (type);
1960 return type;
1963 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1964 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1966 static void
1967 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1968 register tree type;
1969 register int decl_const;
1970 register int decl_volatile;
1971 register int count;
1973 if (TREE_CODE (type) == ERROR_MARK)
1974 return;
1976 /* Give up after searching 1000 levels, in case this is a recursive
1977 pointer type. Such types are possible in Ada, but it is not possible
1978 to represent them in DWARF1 debug info. */
1979 if (count > 1000)
1980 return;
1982 if (TYPE_READONLY (type) || decl_const)
1983 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1984 if (TYPE_VOLATILE (type) || decl_volatile)
1985 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1986 switch (TREE_CODE (type))
1988 case POINTER_TYPE:
1989 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1990 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1991 return;
1993 case REFERENCE_TYPE:
1994 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1995 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1996 return;
1998 case ERROR_MARK:
1999 default:
2000 return;
2004 static void
2005 write_modifier_bytes (type, decl_const, decl_volatile)
2006 register tree type;
2007 register int decl_const;
2008 register int decl_volatile;
2010 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
2013 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
2014 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
2016 static inline int
2017 type_is_fundamental (type)
2018 register tree type;
2020 switch (TREE_CODE (type))
2022 case ERROR_MARK:
2023 case VOID_TYPE:
2024 case INTEGER_TYPE:
2025 case REAL_TYPE:
2026 case COMPLEX_TYPE:
2027 case BOOLEAN_TYPE:
2028 case CHAR_TYPE:
2029 return 1;
2031 case SET_TYPE:
2032 case ARRAY_TYPE:
2033 case RECORD_TYPE:
2034 case UNION_TYPE:
2035 case QUAL_UNION_TYPE:
2036 case ENUMERAL_TYPE:
2037 case FUNCTION_TYPE:
2038 case METHOD_TYPE:
2039 case POINTER_TYPE:
2040 case REFERENCE_TYPE:
2041 case FILE_TYPE:
2042 case OFFSET_TYPE:
2043 case LANG_TYPE:
2044 case VECTOR_TYPE:
2045 return 0;
2047 default:
2048 abort ();
2050 return 0;
2053 /* Given a pointer to some ..._DECL 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 DECL_UID number
2057 associated with the given decl 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 "decl related" form of DIE
2062 makes it possible to later refer to the DIE which represents the given
2063 decl simply by re-generating the symbolic name from the ..._DECL node's
2064 UID number. */
2066 static void
2067 equate_decl_number_to_die_number (decl)
2068 register tree decl;
2070 /* In the case where we are generating a DIE for some ..._DECL node
2071 which represents either some inline function declaration or some
2072 entity declared within an inline function declaration/definition,
2073 setup a symbolic name for the current DIE so that we have a name
2074 for this DIE that we can easily refer to later on within
2075 AT_abstract_origin attributes. */
2077 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
2078 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2080 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
2081 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2082 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
2085 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
2086 equate directive which will associate a symbolic name with the current DIE.
2088 The name used is an artificial label generated from the TYPE_UID number
2089 associated with the given type node. The name it gets equated to is the
2090 symbolic label that we (previously) output at the start of the DIE that
2091 we are currently generating.
2093 Calling this function while generating some "type related" form of DIE
2094 makes it easy to later refer to the DIE which represents the given type
2095 simply by re-generating the alternative name from the ..._TYPE node's
2096 UID number. */
2098 static inline void
2099 equate_type_number_to_die_number (type)
2100 register tree type;
2102 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
2103 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2105 /* We are generating a DIE to represent the main variant of this type
2106 (i.e the type without any const or volatile qualifiers) so in order
2107 to get the equate to come out right, we need to get the main variant
2108 itself here. */
2110 type = type_main_variant (type);
2112 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
2113 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2114 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
2117 static void
2118 output_reg_number (rtl)
2119 register rtx rtl;
2121 register unsigned regno = REGNO (rtl);
2123 if (regno >= DWARF_FRAME_REGISTERS)
2125 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
2126 regno);
2127 regno = 0;
2129 fprintf (asm_out_file, "%s0x%x",
2130 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
2131 if (flag_debug_asm)
2133 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
2134 PRINT_REG (rtl, 0, asm_out_file);
2136 fputc ('\n', asm_out_file);
2139 /* The following routine is a nice and simple transducer. It converts the
2140 RTL for a variable or parameter (resident in memory) into an equivalent
2141 Dwarf representation of a mechanism for getting the address of that same
2142 variable onto the top of a hypothetical "address evaluation" stack.
2144 When creating memory location descriptors, we are effectively trans-
2145 forming the RTL for a memory-resident object into its Dwarf postfix
2146 expression equivalent. This routine just recursively descends an
2147 RTL tree, turning it into Dwarf postfix code as it goes. */
2149 static void
2150 output_mem_loc_descriptor (rtl)
2151 register rtx rtl;
2153 /* Note that for a dynamically sized array, the location we will
2154 generate a description of here will be the lowest numbered location
2155 which is actually within the array. That's *not* necessarily the
2156 same as the zeroth element of the array. */
2158 #ifdef ASM_SIMPLIFY_DWARF_ADDR
2159 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
2160 #endif
2162 switch (GET_CODE (rtl))
2164 case SUBREG:
2166 /* The case of a subreg may arise when we have a local (register)
2167 variable or a formal (register) parameter which doesn't quite
2168 fill up an entire register. For now, just assume that it is
2169 legitimate to make the Dwarf info refer to the whole register
2170 which contains the given subreg. */
2172 rtl = XEXP (rtl, 0);
2173 /* Drop thru. */
2175 case REG:
2177 /* Whenever a register number forms a part of the description of
2178 the method for calculating the (dynamic) address of a memory
2179 resident object, DWARF rules require the register number to
2180 be referred to as a "base register". This distinction is not
2181 based in any way upon what category of register the hardware
2182 believes the given register belongs to. This is strictly
2183 DWARF terminology we're dealing with here.
2185 Note that in cases where the location of a memory-resident data
2186 object could be expressed as:
2188 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
2190 the actual DWARF location descriptor that we generate may just
2191 be OP_BASEREG (basereg). This may look deceptively like the
2192 object in question was allocated to a register (rather than
2193 in memory) so DWARF consumers need to be aware of the subtle
2194 distinction between OP_REG and OP_BASEREG. */
2196 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
2197 output_reg_number (rtl);
2198 break;
2200 case MEM:
2201 output_mem_loc_descriptor (XEXP (rtl, 0));
2202 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
2203 break;
2205 case CONST:
2206 case SYMBOL_REF:
2207 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
2208 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2209 break;
2211 case PLUS:
2212 output_mem_loc_descriptor (XEXP (rtl, 0));
2213 output_mem_loc_descriptor (XEXP (rtl, 1));
2214 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2215 break;
2217 case CONST_INT:
2218 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2219 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
2220 break;
2222 case MULT:
2223 /* If a pseudo-reg is optimized away, it is possible for it to
2224 be replaced with a MEM containing a multiply. Use a GNU extension
2225 to describe it. */
2226 output_mem_loc_descriptor (XEXP (rtl, 0));
2227 output_mem_loc_descriptor (XEXP (rtl, 1));
2228 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
2229 break;
2231 default:
2232 abort ();
2236 /* Output a proper Dwarf location descriptor for a variable or parameter
2237 which is either allocated in a register or in a memory location. For
2238 a register, we just generate an OP_REG and the register number. For a
2239 memory location we provide a Dwarf postfix expression describing how to
2240 generate the (dynamic) address of the object onto the address stack. */
2242 static void
2243 output_loc_descriptor (rtl)
2244 register rtx rtl;
2246 switch (GET_CODE (rtl))
2248 case SUBREG:
2250 /* The case of a subreg may arise when we have a local (register)
2251 variable or a formal (register) parameter which doesn't quite
2252 fill up an entire register. For now, just assume that it is
2253 legitimate to make the Dwarf info refer to the whole register
2254 which contains the given subreg. */
2256 rtl = XEXP (rtl, 0);
2257 /* Drop thru. */
2259 case REG:
2260 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
2261 output_reg_number (rtl);
2262 break;
2264 case MEM:
2265 output_mem_loc_descriptor (XEXP (rtl, 0));
2266 break;
2268 default:
2269 abort (); /* Should never happen */
2273 /* Given a tree node describing an array bound (either lower or upper)
2274 output a representation for that bound. */
2276 static void
2277 output_bound_representation (bound, dim_num, u_or_l)
2278 register tree bound;
2279 register unsigned dim_num; /* For multi-dimensional arrays. */
2280 register char u_or_l; /* Designates upper or lower bound. */
2282 switch (TREE_CODE (bound))
2285 case ERROR_MARK:
2286 return;
2288 /* All fixed-bounds are represented by INTEGER_CST nodes. */
2290 case INTEGER_CST:
2291 if (host_integerp (bound, 0))
2292 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
2293 break;
2295 default:
2297 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
2298 SAVE_EXPR nodes, in which case we can do something, or as
2299 an expression, which we cannot represent. */
2301 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2302 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2304 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
2305 current_dienum, dim_num, u_or_l);
2307 sprintf (end_label, BOUND_END_LABEL_FMT,
2308 current_dienum, dim_num, u_or_l);
2310 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2311 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2313 /* If optimization is turned on, the SAVE_EXPRs that describe
2314 how to access the upper bound values are essentially bogus.
2315 They only describe (at best) how to get at these values at
2316 the points in the generated code right after they have just
2317 been computed. Worse yet, in the typical case, the upper
2318 bound values will not even *be* computed in the optimized
2319 code, so these SAVE_EXPRs are entirely bogus.
2321 In order to compensate for this fact, we check here to see
2322 if optimization is enabled, and if so, we effectively create
2323 an empty location description for the (unknown and unknowable)
2324 upper bound.
2326 This should not cause too much trouble for existing (stupid?)
2327 debuggers because they have to deal with empty upper bounds
2328 location descriptions anyway in order to be able to deal with
2329 incomplete array types.
2331 Of course an intelligent debugger (GDB?) should be able to
2332 comprehend that a missing upper bound specification in a
2333 array type used for a storage class `auto' local array variable
2334 indicates that the upper bound is both unknown (at compile-
2335 time) and unknowable (at run-time) due to optimization. */
2337 if (! optimize)
2339 while (TREE_CODE (bound) == NOP_EXPR
2340 || TREE_CODE (bound) == CONVERT_EXPR)
2341 bound = TREE_OPERAND (bound, 0);
2343 if (TREE_CODE (bound) == SAVE_EXPR)
2344 output_loc_descriptor
2345 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
2348 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2350 break;
2355 /* Recursive function to output a sequence of value/name pairs for
2356 enumeration constants in reversed order. This is called from
2357 enumeration_type_die. */
2359 static void
2360 output_enumeral_list (link)
2361 register tree link;
2363 if (link)
2365 output_enumeral_list (TREE_CHAIN (link));
2367 if (host_integerp (TREE_VALUE (link), 0))
2368 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2369 tree_low_cst (TREE_VALUE (link), 0));
2371 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
2372 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
2376 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
2377 which is not less than the value itself. */
2379 static inline HOST_WIDE_INT
2380 ceiling (value, boundary)
2381 register HOST_WIDE_INT value;
2382 register unsigned int boundary;
2384 return (((value + boundary - 1) / boundary) * boundary);
2387 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
2388 pointer to the declared type for the relevant field variable, or return
2389 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
2391 static inline tree
2392 field_type (decl)
2393 register tree decl;
2395 register tree type;
2397 if (TREE_CODE (decl) == ERROR_MARK)
2398 return integer_type_node;
2400 type = DECL_BIT_FIELD_TYPE (decl);
2401 if (type == NULL)
2402 type = TREE_TYPE (decl);
2403 return type;
2406 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2407 node, return the alignment in bits for the type, or else return
2408 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
2410 static inline unsigned int
2411 simple_type_align_in_bits (type)
2412 register tree type;
2414 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
2417 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2418 node, return the size in bits for the type if it is a constant, or
2419 else return the alignment for the type if the type's size is not
2420 constant, or else return BITS_PER_WORD if the type actually turns out
2421 to be an ERROR_MARK node. */
2423 static inline unsigned HOST_WIDE_INT
2424 simple_type_size_in_bits (type)
2425 register tree type;
2427 tree type_size_tree;
2429 if (TREE_CODE (type) == ERROR_MARK)
2430 return BITS_PER_WORD;
2431 type_size_tree = TYPE_SIZE (type);
2433 if (type_size_tree == NULL_TREE)
2434 return 0;
2435 if (! host_integerp (type_size_tree, 1))
2436 return TYPE_ALIGN (type);
2437 return tree_low_cst (type_size_tree, 1);
2440 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
2441 return the byte offset of the lowest addressed byte of the "containing
2442 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
2443 mine what that offset is, either because the argument turns out to be a
2444 pointer to an ERROR_MARK node, or because the offset is actually variable.
2445 (We can't handle the latter case just yet.) */
2447 static HOST_WIDE_INT
2448 field_byte_offset (decl)
2449 register tree decl;
2451 unsigned int type_align_in_bytes;
2452 unsigned int type_align_in_bits;
2453 unsigned HOST_WIDE_INT type_size_in_bits;
2454 HOST_WIDE_INT object_offset_in_align_units;
2455 HOST_WIDE_INT object_offset_in_bits;
2456 HOST_WIDE_INT object_offset_in_bytes;
2457 tree type;
2458 tree field_size_tree;
2459 HOST_WIDE_INT bitpos_int;
2460 HOST_WIDE_INT deepest_bitpos;
2461 unsigned HOST_WIDE_INT field_size_in_bits;
2463 if (TREE_CODE (decl) == ERROR_MARK)
2464 return 0;
2466 if (TREE_CODE (decl) != FIELD_DECL)
2467 abort ();
2469 type = field_type (decl);
2470 field_size_tree = DECL_SIZE (decl);
2472 /* The size could be unspecified if there was an error, or for
2473 a flexible array member. */
2474 if (! field_size_tree)
2475 field_size_tree = bitsize_zero_node;
2477 /* We cannot yet cope with fields whose positions or sizes are variable,
2478 so for now, when we see such things, we simply return 0. Someday,
2479 we may be able to handle such cases, but it will be damn difficult. */
2481 if (! host_integerp (bit_position (decl), 0)
2482 || ! host_integerp (field_size_tree, 1))
2483 return 0;
2485 bitpos_int = int_bit_position (decl);
2486 field_size_in_bits = tree_low_cst (field_size_tree, 1);
2488 type_size_in_bits = simple_type_size_in_bits (type);
2489 type_align_in_bits = simple_type_align_in_bits (type);
2490 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2492 /* Note that the GCC front-end doesn't make any attempt to keep track
2493 of the starting bit offset (relative to the start of the containing
2494 structure type) of the hypothetical "containing object" for a bit-
2495 field. Thus, when computing the byte offset value for the start of
2496 the "containing object" of a bit-field, we must deduce this infor-
2497 mation on our own.
2499 This can be rather tricky to do in some cases. For example, handling
2500 the following structure type definition when compiling for an i386/i486
2501 target (which only aligns long long's to 32-bit boundaries) can be very
2502 tricky:
2504 struct S {
2505 int field1;
2506 long long field2:31;
2509 Fortunately, there is a simple rule-of-thumb which can be used in such
2510 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2511 the structure shown above. It decides to do this based upon one simple
2512 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2513 taining object" for each bit-field at the first (i.e. lowest addressed)
2514 legitimate alignment boundary (based upon the required minimum alignment
2515 for the declared type of the field) which it can possibly use, subject
2516 to the condition that there is still enough available space remaining
2517 in the containing object (when allocated at the selected point) to
2518 fully accommodate all of the bits of the bit-field itself.
2520 This simple rule makes it obvious why GCC allocates 8 bytes for each
2521 object of the structure type shown above. When looking for a place to
2522 allocate the "containing object" for `field2', the compiler simply tries
2523 to allocate a 64-bit "containing object" at each successive 32-bit
2524 boundary (starting at zero) until it finds a place to allocate that 64-
2525 bit field such that at least 31 contiguous (and previously unallocated)
2526 bits remain within that selected 64 bit field. (As it turns out, for
2527 the example above, the compiler finds that it is OK to allocate the
2528 "containing object" 64-bit field at bit-offset zero within the
2529 structure type.)
2531 Here we attempt to work backwards from the limited set of facts we're
2532 given, and we try to deduce from those facts, where GCC must have
2533 believed that the containing object started (within the structure type).
2535 The value we deduce is then used (by the callers of this routine) to
2536 generate AT_location and AT_bit_offset attributes for fields (both
2537 bit-fields and, in the case of AT_location, regular fields as well). */
2539 /* Figure out the bit-distance from the start of the structure to the
2540 "deepest" bit of the bit-field. */
2541 deepest_bitpos = bitpos_int + field_size_in_bits;
2543 /* This is the tricky part. Use some fancy footwork to deduce where the
2544 lowest addressed bit of the containing object must be. */
2545 object_offset_in_bits
2546 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2548 /* Compute the offset of the containing object in "alignment units". */
2549 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2551 /* Compute the offset of the containing object in bytes. */
2552 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2554 /* The above code assumes that the field does not cross an alignment
2555 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2556 or if the structure is packed. If this happens, then we get an object
2557 which starts after the bitfield, which means that the bit offset is
2558 negative. Gdb fails when given negative bit offsets. We avoid this
2559 by recomputing using the first bit of the bitfield. This will give
2560 us an object which does not completely contain the bitfield, but it
2561 will be aligned, and it will contain the first bit of the bitfield.
2563 However, only do this for a BYTES_BIG_ENDIAN target. For a
2564 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2565 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2566 then we end up computing the object byte offset for the wrong word of the
2567 desired bitfield, which in turn causes the field offset to be negative
2568 in bit_offset_attribute. */
2569 if (BYTES_BIG_ENDIAN
2570 && object_offset_in_bits > bitpos_int)
2572 deepest_bitpos = bitpos_int + 1;
2573 object_offset_in_bits
2574 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2575 object_offset_in_align_units = (object_offset_in_bits
2576 / type_align_in_bits);
2577 object_offset_in_bytes = (object_offset_in_align_units
2578 * type_align_in_bytes);
2581 return object_offset_in_bytes;
2584 /****************************** attributes *********************************/
2586 /* The following routines are responsible for writing out the various types
2587 of Dwarf attributes (and any following data bytes associated with them).
2588 These routines are listed in order based on the numerical codes of their
2589 associated attributes. */
2591 /* Generate an AT_sibling attribute. */
2593 static inline void
2594 sibling_attribute ()
2596 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2598 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2599 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2600 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2603 /* Output the form of location attributes suitable for whole variables and
2604 whole parameters. Note that the location attributes for struct fields
2605 are generated by the routine `data_member_location_attribute' below. */
2607 static void
2608 location_attribute (rtl)
2609 register rtx rtl;
2611 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2612 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2614 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2615 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2616 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2617 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2618 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2620 /* Handle a special case. If we are about to output a location descriptor
2621 for a variable or parameter which has been optimized out of existence,
2622 don't do that. Instead we output a zero-length location descriptor
2623 value as part of the location attribute.
2625 A variable which has been optimized out of existence will have a
2626 DECL_RTL value which denotes a pseudo-reg.
2628 Currently, in some rare cases, variables can have DECL_RTL values
2629 which look like (MEM (REG pseudo-reg#)). These cases are due to
2630 bugs elsewhere in the compiler. We treat such cases
2631 as if the variable(s) in question had been optimized out of existence.
2633 Note that in all cases where we wish to express the fact that a
2634 variable has been optimized out of existence, we do not simply
2635 suppress the generation of the entire location attribute because
2636 the absence of a location attribute in certain kinds of DIEs is
2637 used to indicate something else entirely... i.e. that the DIE
2638 represents an object declaration, but not a definition. So saith
2639 the PLSIG.
2642 if (! is_pseudo_reg (rtl)
2643 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2644 output_loc_descriptor (rtl);
2646 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2649 /* Output the specialized form of location attribute used for data members
2650 of struct and union types.
2652 In the special case of a FIELD_DECL node which represents a bit-field,
2653 the "offset" part of this special location descriptor must indicate the
2654 distance in bytes from the lowest-addressed byte of the containing
2655 struct or union type to the lowest-addressed byte of the "containing
2656 object" for the bit-field. (See the `field_byte_offset' function above.)
2658 For any given bit-field, the "containing object" is a hypothetical
2659 object (of some integral or enum type) within which the given bit-field
2660 lives. The type of this hypothetical "containing object" is always the
2661 same as the declared type of the individual bit-field itself (for GCC
2662 anyway... the DWARF spec doesn't actually mandate this).
2664 Note that it is the size (in bytes) of the hypothetical "containing
2665 object" which will be given in the AT_byte_size attribute for this
2666 bit-field. (See the `byte_size_attribute' function below.) It is
2667 also used when calculating the value of the AT_bit_offset attribute.
2668 (See the `bit_offset_attribute' function below.) */
2670 static void
2671 data_member_location_attribute (t)
2672 register tree t;
2674 register unsigned object_offset_in_bytes;
2675 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2676 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2678 if (TREE_CODE (t) == TREE_VEC)
2679 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2680 else
2681 object_offset_in_bytes = field_byte_offset (t);
2683 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2684 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2685 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2686 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2687 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2688 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2689 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2690 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2691 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2694 /* Output an AT_const_value attribute for a variable or a parameter which
2695 does not have a "location" either in memory or in a register. These
2696 things can arise in GNU C when a constant is passed as an actual
2697 parameter to an inlined function. They can also arise in C++ where
2698 declared constants do not necessarily get memory "homes". */
2700 static void
2701 const_value_attribute (rtl)
2702 register rtx rtl;
2704 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2705 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2707 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2708 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2709 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2710 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2711 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2713 switch (GET_CODE (rtl))
2715 case CONST_INT:
2716 /* Note that a CONST_INT rtx could represent either an integer or
2717 a floating-point constant. A CONST_INT is used whenever the
2718 constant will fit into a single word. In all such cases, the
2719 original mode of the constant value is wiped out, and the
2720 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2721 precise mode information for these constants, we always just
2722 output them using 4 bytes. */
2724 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2725 break;
2727 case CONST_DOUBLE:
2728 /* Note that a CONST_DOUBLE rtx could represent either an integer
2729 or a floating-point constant. A CONST_DOUBLE is used whenever
2730 the constant requires more than one word in order to be adequately
2731 represented. In all such cases, the original mode of the constant
2732 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2733 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2735 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2736 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2737 (unsigned int) CONST_DOUBLE_LOW (rtl));
2738 break;
2740 case CONST_STRING:
2741 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2742 break;
2744 case SYMBOL_REF:
2745 case LABEL_REF:
2746 case CONST:
2747 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2748 break;
2750 case PLUS:
2751 /* In cases where an inlined instance of an inline function is passed
2752 the address of an `auto' variable (which is local to the caller)
2753 we can get a situation where the DECL_RTL of the artificial
2754 local variable (for the inlining) which acts as a stand-in for
2755 the corresponding formal parameter (of the inline function)
2756 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2757 This is not exactly a compile-time constant expression, but it
2758 isn't the address of the (artificial) local variable either.
2759 Rather, it represents the *value* which the artificial local
2760 variable always has during its lifetime. We currently have no
2761 way to represent such quasi-constant values in Dwarf, so for now
2762 we just punt and generate an AT_const_value attribute with form
2763 FORM_BLOCK4 and a length of zero. */
2764 break;
2766 default:
2767 abort (); /* No other kinds of rtx should be possible here. */
2770 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2773 /* Generate *either* an AT_location attribute or else an AT_const_value
2774 data attribute for a variable or a parameter. We generate the
2775 AT_const_value attribute only in those cases where the given
2776 variable or parameter does not have a true "location" either in
2777 memory or in a register. This can happen (for example) when a
2778 constant is passed as an actual argument in a call to an inline
2779 function. (It's possible that these things can crop up in other
2780 ways also.) Note that one type of constant value which can be
2781 passed into an inlined function is a constant pointer. This can
2782 happen for example if an actual argument in an inlined function
2783 call evaluates to a compile-time constant address. */
2785 static void
2786 location_or_const_value_attribute (decl)
2787 register tree decl;
2789 register rtx rtl;
2791 if (TREE_CODE (decl) == ERROR_MARK)
2792 return;
2794 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2796 /* Should never happen. */
2797 abort ();
2798 return;
2801 /* Here we have to decide where we are going to say the parameter "lives"
2802 (as far as the debugger is concerned). We only have a couple of choices.
2803 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2804 normally indicates where the parameter lives during most of the activa-
2805 tion of the function. If optimization is enabled however, this could
2806 be either NULL or else a pseudo-reg. Both of those cases indicate that
2807 the parameter doesn't really live anywhere (as far as the code generation
2808 parts of GCC are concerned) during most of the function's activation.
2809 That will happen (for example) if the parameter is never referenced
2810 within the function.
2812 We could just generate a location descriptor here for all non-NULL
2813 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2814 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2815 cases where DECL_RTL is NULL or is a pseudo-reg.
2817 Note however that we can only get away with using DECL_INCOMING_RTL as
2818 a backup substitute for DECL_RTL in certain limited cases. In cases
2819 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2820 we can be sure that the parameter was passed using the same type as it
2821 is declared to have within the function, and that its DECL_INCOMING_RTL
2822 points us to a place where a value of that type is passed. In cases
2823 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2824 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2825 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2826 points us to a value of some type which is *different* from the type
2827 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2828 to generate a location attribute in such cases, the debugger would
2829 end up (for example) trying to fetch a `float' from a place which
2830 actually contains the first part of a `double'. That would lead to
2831 really incorrect and confusing output at debug-time, and we don't
2832 want that now do we?
2834 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2835 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2836 couple of cute exceptions however. On little-endian machines we can
2837 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2838 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2839 an integral type which is smaller than TREE_TYPE(decl). These cases
2840 arise when (on a little-endian machine) a non-prototyped function has
2841 a parameter declared to be of type `short' or `char'. In such cases,
2842 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2843 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2844 passed `int' value. If the debugger then uses that address to fetch a
2845 `short' or a `char' (on a little-endian machine) the result will be the
2846 correct data, so we allow for such exceptional cases below.
2848 Note that our goal here is to describe the place where the given formal
2849 parameter lives during most of the function's activation (i.e. between
2850 the end of the prologue and the start of the epilogue). We'll do that
2851 as best as we can. Note however that if the given formal parameter is
2852 modified sometime during the execution of the function, then a stack
2853 backtrace (at debug-time) will show the function as having been called
2854 with the *new* value rather than the value which was originally passed
2855 in. This happens rarely enough that it is not a major problem, but it
2856 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2857 may generate two additional attributes for any given TAG_formal_parameter
2858 DIE which will describe the "passed type" and the "passed location" for
2859 the given formal parameter in addition to the attributes we now generate
2860 to indicate the "declared type" and the "active location" for each
2861 parameter. This additional set of attributes could be used by debuggers
2862 for stack backtraces.
2864 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2865 can be NULL also. This happens (for example) for inlined-instances of
2866 inline function formal parameters which are never referenced. This really
2867 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2868 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2869 these values for inlined instances of inline function parameters, so
2870 when we see such cases, we are just out-of-luck for the time
2871 being (until integrate.c gets fixed).
2874 /* Use DECL_RTL as the "location" unless we find something better. */
2875 rtl = DECL_RTL (decl);
2877 if (TREE_CODE (decl) == PARM_DECL)
2878 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2880 /* This decl represents a formal parameter which was optimized out. */
2881 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2882 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2884 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2885 *all* cases where (rtl == NULL_RTX) just below. */
2887 if (declared_type == passed_type)
2888 rtl = DECL_INCOMING_RTL (decl);
2889 else if (! BYTES_BIG_ENDIAN)
2890 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2891 /* NMS WTF? */
2892 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2893 rtl = DECL_INCOMING_RTL (decl);
2896 if (rtl == NULL_RTX)
2897 return;
2899 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2900 #ifdef LEAF_REG_REMAP
2901 if (current_function_uses_only_leaf_regs)
2902 leaf_renumber_regs_insn (rtl);
2903 #endif
2905 switch (GET_CODE (rtl))
2907 case ADDRESSOF:
2908 /* The address of a variable that was optimized away; don't emit
2909 anything. */
2910 break;
2912 case CONST_INT:
2913 case CONST_DOUBLE:
2914 case CONST_STRING:
2915 case SYMBOL_REF:
2916 case LABEL_REF:
2917 case CONST:
2918 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2919 const_value_attribute (rtl);
2920 break;
2922 case MEM:
2923 case REG:
2924 case SUBREG:
2925 location_attribute (rtl);
2926 break;
2928 case CONCAT:
2929 /* ??? CONCAT is used for complex variables, which may have the real
2930 part stored in one place and the imag part stored somewhere else.
2931 DWARF1 has no way to describe a variable that lives in two different
2932 places, so we just describe where the first part lives, and hope that
2933 the second part is stored after it. */
2934 location_attribute (XEXP (rtl, 0));
2935 break;
2937 default:
2938 abort (); /* Should never happen. */
2942 /* Generate an AT_name attribute given some string value to be included as
2943 the value of the attribute. */
2945 static inline void
2946 name_attribute (name_string)
2947 register const char *name_string;
2949 if (name_string && *name_string)
2951 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2952 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2956 static inline void
2957 fund_type_attribute (ft_code)
2958 register unsigned ft_code;
2960 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2961 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2964 static void
2965 mod_fund_type_attribute (type, decl_const, decl_volatile)
2966 register tree type;
2967 register int decl_const;
2968 register int decl_volatile;
2970 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2971 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2973 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2974 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2975 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2976 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2977 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2978 write_modifier_bytes (type, decl_const, decl_volatile);
2979 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2980 fundamental_type_code (root_type (type)));
2981 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2984 static inline void
2985 user_def_type_attribute (type)
2986 register tree type;
2988 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2990 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2991 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2992 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2995 static void
2996 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2997 register tree type;
2998 register int decl_const;
2999 register int decl_volatile;
3001 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3002 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3003 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
3005 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
3006 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
3007 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
3008 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3009 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3010 write_modifier_bytes (type, decl_const, decl_volatile);
3011 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
3012 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
3013 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3016 #ifdef USE_ORDERING_ATTRIBUTE
3017 static inline void
3018 ordering_attribute (ordering)
3019 register unsigned ordering;
3021 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
3022 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
3024 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3026 /* Note that the block of subscript information for an array type also
3027 includes information about the element type of type given array type. */
3029 static void
3030 subscript_data_attribute (type)
3031 register tree type;
3033 register unsigned dimension_number;
3034 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3035 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3037 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
3038 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
3039 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
3040 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3041 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3043 /* The GNU compilers represent multidimensional array types as sequences
3044 of one dimensional array types whose element types are themselves array
3045 types. Here we squish that down, so that each multidimensional array
3046 type gets only one array_type DIE in the Dwarf debugging info. The
3047 draft Dwarf specification say that we are allowed to do this kind
3048 of compression in C (because there is no difference between an
3049 array or arrays and a multidimensional array in C) but for other
3050 source languages (e.g. Ada) we probably shouldn't do this. */
3052 for (dimension_number = 0;
3053 TREE_CODE (type) == ARRAY_TYPE;
3054 type = TREE_TYPE (type), dimension_number++)
3056 register tree domain = TYPE_DOMAIN (type);
3058 /* Arrays come in three flavors. Unspecified bounds, fixed
3059 bounds, and (in GNU C only) variable bounds. Handle all
3060 three forms here. */
3062 if (domain)
3064 /* We have an array type with specified bounds. */
3066 register tree lower = TYPE_MIN_VALUE (domain);
3067 register tree upper = TYPE_MAX_VALUE (domain);
3069 /* Handle only fundamental types as index types for now. */
3070 if (! type_is_fundamental (domain))
3071 abort ();
3073 /* Output the representation format byte for this dimension. */
3074 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
3075 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
3076 upper && TREE_CODE (upper) == INTEGER_CST));
3078 /* Output the index type for this dimension. */
3079 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3080 fundamental_type_code (domain));
3082 /* Output the representation for the lower bound. */
3083 output_bound_representation (lower, dimension_number, 'l');
3085 /* Output the representation for the upper bound. */
3086 if (upper)
3087 output_bound_representation (upper, dimension_number, 'u');
3088 else
3089 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3091 else
3093 /* We have an array type with an unspecified length. For C and
3094 C++ we can assume that this really means that (a) the index
3095 type is an integral type, and (b) the lower bound is zero.
3096 Note that Dwarf defines the representation of an unspecified
3097 (upper) bound as being a zero-length location description. */
3099 /* Output the array-bounds format byte. */
3101 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
3103 /* Output the (assumed) index type. */
3105 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
3107 /* Output the (assumed) lower bound (constant) value. */
3109 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3111 /* Output the (empty) location description for the upper bound. */
3113 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3117 /* Output the prefix byte that says that the element type is coming up. */
3119 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
3121 /* Output a representation of the type of the elements of this array type. */
3123 type_attribute (type, 0, 0);
3125 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3128 static void
3129 byte_size_attribute (tree_node)
3130 register tree tree_node;
3132 register unsigned size;
3134 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
3135 switch (TREE_CODE (tree_node))
3137 case ERROR_MARK:
3138 size = 0;
3139 break;
3141 case ENUMERAL_TYPE:
3142 case RECORD_TYPE:
3143 case UNION_TYPE:
3144 case QUAL_UNION_TYPE:
3145 case ARRAY_TYPE:
3146 size = int_size_in_bytes (tree_node);
3147 break;
3149 case FIELD_DECL:
3150 /* For a data member of a struct or union, the AT_byte_size is
3151 generally given as the number of bytes normally allocated for
3152 an object of the *declared* type of the member itself. This
3153 is true even for bit-fields. */
3154 size = simple_type_size_in_bits (field_type (tree_node))
3155 / BITS_PER_UNIT;
3156 break;
3158 default:
3159 abort ();
3162 /* Note that `size' might be -1 when we get to this point. If it
3163 is, that indicates that the byte size of the entity in question
3164 is variable. We have no good way of expressing this fact in Dwarf
3165 at the present time, so just let the -1 pass on through. */
3167 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
3170 /* For a FIELD_DECL node which represents a bit-field, output an attribute
3171 which specifies the distance in bits from the highest order bit of the
3172 "containing object" for the bit-field to the highest order bit of the
3173 bit-field itself.
3175 For any given bit-field, the "containing object" is a hypothetical
3176 object (of some integral or enum type) within which the given bit-field
3177 lives. The type of this hypothetical "containing object" is always the
3178 same as the declared type of the individual bit-field itself.
3180 The determination of the exact location of the "containing object" for
3181 a bit-field is rather complicated. It's handled by the `field_byte_offset'
3182 function (above).
3184 Note that it is the size (in bytes) of the hypothetical "containing
3185 object" which will be given in the AT_byte_size attribute for this
3186 bit-field. (See `byte_size_attribute' above.) */
3188 static inline void
3189 bit_offset_attribute (decl)
3190 register tree decl;
3192 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
3193 tree type = DECL_BIT_FIELD_TYPE (decl);
3194 HOST_WIDE_INT bitpos_int;
3195 HOST_WIDE_INT highest_order_object_bit_offset;
3196 HOST_WIDE_INT highest_order_field_bit_offset;
3197 HOST_WIDE_INT bit_offset;
3199 /* Must be a bit field. */
3200 if (!type
3201 || TREE_CODE (decl) != FIELD_DECL)
3202 abort ();
3204 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
3205 if we encounter such things, just return without generating any
3206 attribute whatsoever. */
3208 if (! host_integerp (bit_position (decl), 0)
3209 || ! host_integerp (DECL_SIZE (decl), 1))
3210 return;
3212 bitpos_int = int_bit_position (decl);
3214 /* Note that the bit offset is always the distance (in bits) from the
3215 highest-order bit of the "containing object" to the highest-order
3216 bit of the bit-field itself. Since the "high-order end" of any
3217 object or field is different on big-endian and little-endian machines,
3218 the computation below must take account of these differences. */
3220 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
3221 highest_order_field_bit_offset = bitpos_int;
3223 if (! BYTES_BIG_ENDIAN)
3225 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
3226 highest_order_object_bit_offset += simple_type_size_in_bits (type);
3229 bit_offset =
3230 (! BYTES_BIG_ENDIAN
3231 ? highest_order_object_bit_offset - highest_order_field_bit_offset
3232 : highest_order_field_bit_offset - highest_order_object_bit_offset);
3234 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
3235 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
3238 /* For a FIELD_DECL node which represents a bit field, output an attribute
3239 which specifies the length in bits of the given field. */
3241 static inline void
3242 bit_size_attribute (decl)
3243 register tree decl;
3245 /* Must be a field and a bit field. */
3246 if (TREE_CODE (decl) != FIELD_DECL
3247 || ! DECL_BIT_FIELD_TYPE (decl))
3248 abort ();
3250 if (host_integerp (DECL_SIZE (decl), 1))
3252 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
3253 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3254 tree_low_cst (DECL_SIZE (decl), 1));
3258 /* The following routine outputs the `element_list' attribute for enumeration
3259 type DIEs. The element_lits attribute includes the names and values of
3260 all of the enumeration constants associated with the given enumeration
3261 type. */
3263 static inline void
3264 element_list_attribute (element)
3265 register tree element;
3267 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3268 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3270 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
3271 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
3272 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
3273 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3274 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3276 /* Here we output a list of value/name pairs for each enumeration constant
3277 defined for this enumeration type (as required), but we do it in REVERSE
3278 order. The order is the one required by the draft #5 Dwarf specification
3279 published by the UI/PLSIG. */
3281 output_enumeral_list (element); /* Recursively output the whole list. */
3283 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3286 /* Generate an AT_stmt_list attribute. These are normally present only in
3287 DIEs with a TAG_compile_unit tag. */
3289 static inline void
3290 stmt_list_attribute (label)
3291 register const char *label;
3293 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
3294 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3295 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3298 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
3299 for a subroutine DIE. */
3301 static inline void
3302 low_pc_attribute (asm_low_label)
3303 register const char *asm_low_label;
3305 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
3306 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
3309 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
3310 subroutine DIE. */
3312 static inline void
3313 high_pc_attribute (asm_high_label)
3314 register const char *asm_high_label;
3316 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
3317 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
3320 /* Generate an AT_body_begin attribute for a subroutine DIE. */
3322 static inline void
3323 body_begin_attribute (asm_begin_label)
3324 register const char *asm_begin_label;
3326 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
3327 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
3330 /* Generate an AT_body_end attribute for a subroutine DIE. */
3332 static inline void
3333 body_end_attribute (asm_end_label)
3334 register const char *asm_end_label;
3336 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
3337 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
3340 /* Generate an AT_language attribute given a LANG value. These attributes
3341 are used only within TAG_compile_unit DIEs. */
3343 static inline void
3344 language_attribute (language_code)
3345 register unsigned language_code;
3347 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
3348 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
3351 static inline void
3352 member_attribute (context)
3353 register tree context;
3355 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3357 /* Generate this attribute only for members in C++. */
3359 if (context != NULL && is_tagged_type (context))
3361 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
3362 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
3363 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3367 #if 0
3368 static inline void
3369 string_length_attribute (upper_bound)
3370 register tree upper_bound;
3372 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3373 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3375 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
3376 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
3377 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
3378 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3379 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3380 output_bound_representation (upper_bound, 0, 'u');
3381 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3383 #endif
3385 static inline void
3386 comp_dir_attribute (dirname)
3387 register const char *dirname;
3389 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
3390 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
3393 static inline void
3394 sf_names_attribute (sf_names_start_label)
3395 register const char *sf_names_start_label;
3397 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
3398 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3399 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
3402 static inline void
3403 src_info_attribute (src_info_start_label)
3404 register const char *src_info_start_label;
3406 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
3407 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3408 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
3411 static inline void
3412 mac_info_attribute (mac_info_start_label)
3413 register const char *mac_info_start_label;
3415 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
3416 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3417 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
3420 static inline void
3421 prototyped_attribute (func_type)
3422 register tree func_type;
3424 if ((strcmp (language_string, "GNU C") == 0)
3425 && (TYPE_ARG_TYPES (func_type) != NULL))
3427 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
3428 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3432 static inline void
3433 producer_attribute (producer)
3434 register const char *producer;
3436 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
3437 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
3440 static inline void
3441 inline_attribute (decl)
3442 register tree decl;
3444 if (DECL_INLINE (decl))
3446 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3447 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3451 static inline void
3452 containing_type_attribute (containing_type)
3453 register tree containing_type;
3455 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3457 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3458 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3459 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3462 static inline void
3463 abstract_origin_attribute (origin)
3464 register tree origin;
3466 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3468 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3469 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3471 case 'd':
3472 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3473 break;
3475 case 't':
3476 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3477 break;
3479 default:
3480 abort (); /* Should never happen. */
3483 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3486 #ifdef DWARF_DECL_COORDINATES
3487 static inline void
3488 src_coords_attribute (src_fileno, src_lineno)
3489 register unsigned src_fileno;
3490 register unsigned src_lineno;
3492 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3493 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3494 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3496 #endif /* defined(DWARF_DECL_COORDINATES) */
3498 static inline void
3499 pure_or_virtual_attribute (func_decl)
3500 register tree func_decl;
3502 if (DECL_VIRTUAL_P (func_decl))
3504 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3505 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3506 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3507 else
3508 #endif
3509 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3510 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3514 /************************* end of attributes *****************************/
3516 /********************* utility routines for DIEs *************************/
3518 /* Output an AT_name attribute and an AT_src_coords attribute for the
3519 given decl, but only if it actually has a name. */
3521 static void
3522 name_and_src_coords_attributes (decl)
3523 register tree decl;
3525 register tree decl_name = DECL_NAME (decl);
3527 if (decl_name && IDENTIFIER_POINTER (decl_name))
3529 name_attribute (IDENTIFIER_POINTER (decl_name));
3530 #ifdef DWARF_DECL_COORDINATES
3532 register unsigned file_index;
3534 /* This is annoying, but we have to pop out of the .debug section
3535 for a moment while we call `lookup_filename' because calling it
3536 may cause a temporary switch into the .debug_sfnames section and
3537 most svr4 assemblers are not smart enough to be able to nest
3538 section switches to any depth greater than one. Note that we
3539 also can't skirt this issue by delaying all output to the
3540 .debug_sfnames section unit the end of compilation because that
3541 would cause us to have inter-section forward references and
3542 Fred Fish sez that m68k/svr4 assemblers botch those. */
3544 ASM_OUTPUT_POP_SECTION (asm_out_file);
3545 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3546 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3548 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3550 #endif /* defined(DWARF_DECL_COORDINATES) */
3554 /* Many forms of DIEs contain a "type description" part. The following
3555 routine writes out these "type descriptor" parts. */
3557 static void
3558 type_attribute (type, decl_const, decl_volatile)
3559 register tree type;
3560 register int decl_const;
3561 register int decl_volatile;
3563 register enum tree_code code = TREE_CODE (type);
3564 register int root_type_modified;
3566 if (code == ERROR_MARK)
3567 return;
3569 /* Handle a special case. For functions whose return type is void,
3570 we generate *no* type attribute. (Note that no object may have
3571 type `void', so this only applies to function return types. */
3573 if (code == VOID_TYPE)
3574 return;
3576 /* If this is a subtype, find the underlying type. Eventually,
3577 this should write out the appropriate subtype info. */
3578 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3579 && TREE_TYPE (type) != 0)
3580 type = TREE_TYPE (type), code = TREE_CODE (type);
3582 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3583 || decl_const || decl_volatile
3584 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3586 if (type_is_fundamental (root_type (type)))
3588 if (root_type_modified)
3589 mod_fund_type_attribute (type, decl_const, decl_volatile);
3590 else
3591 fund_type_attribute (fundamental_type_code (type));
3593 else
3595 if (root_type_modified)
3596 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3597 else
3598 /* We have to get the type_main_variant here (and pass that to the
3599 `user_def_type_attribute' routine) because the ..._TYPE node we
3600 have might simply be a *copy* of some original type node (where
3601 the copy was created to help us keep track of typedef names)
3602 and that copy might have a different TYPE_UID from the original
3603 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3604 is labeling a given type DIE for future reference, it always and
3605 only creates labels for DIEs representing *main variants*, and it
3606 never even knows about non-main-variants.) */
3607 user_def_type_attribute (type_main_variant (type));
3611 /* Given a tree pointer to a struct, class, union, or enum type node, return
3612 a pointer to the (string) tag name for the given type, or zero if the
3613 type was declared without a tag. */
3615 static const char *
3616 type_tag (type)
3617 register tree type;
3619 register const char *name = 0;
3621 if (TYPE_NAME (type) != 0)
3623 register tree t = 0;
3625 /* Find the IDENTIFIER_NODE for the type name. */
3626 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3627 t = TYPE_NAME (type);
3629 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3630 a TYPE_DECL node, regardless of whether or not a `typedef' was
3631 involved. */
3632 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3633 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3634 t = DECL_NAME (TYPE_NAME (type));
3636 /* Now get the name as a string, or invent one. */
3637 if (t != 0)
3638 name = IDENTIFIER_POINTER (t);
3641 return (name == 0 || *name == '\0') ? 0 : name;
3644 static inline void
3645 dienum_push ()
3647 /* Start by checking if the pending_sibling_stack needs to be expanded.
3648 If necessary, expand it. */
3650 if (pending_siblings == pending_siblings_allocated)
3652 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3653 pending_sibling_stack
3654 = (unsigned *) xrealloc (pending_sibling_stack,
3655 pending_siblings_allocated * sizeof(unsigned));
3658 pending_siblings++;
3659 NEXT_DIE_NUM = next_unused_dienum++;
3662 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3663 NEXT_DIE_NUM. */
3665 static inline void
3666 dienum_pop ()
3668 pending_siblings--;
3671 static inline tree
3672 member_declared_type (member)
3673 register tree member;
3675 return (DECL_BIT_FIELD_TYPE (member))
3676 ? DECL_BIT_FIELD_TYPE (member)
3677 : TREE_TYPE (member);
3680 /* Get the function's label, as described by its RTL.
3681 This may be different from the DECL_NAME name used
3682 in the source file. */
3684 static const char *
3685 function_start_label (decl)
3686 register tree decl;
3688 rtx x;
3689 const char *fnname;
3691 x = DECL_RTL (decl);
3692 if (GET_CODE (x) != MEM)
3693 abort ();
3694 x = XEXP (x, 0);
3695 if (GET_CODE (x) != SYMBOL_REF)
3696 abort ();
3697 fnname = XSTR (x, 0);
3698 return fnname;
3702 /******************************* DIEs ************************************/
3704 /* Output routines for individual types of DIEs. */
3706 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3708 static void
3709 output_array_type_die (arg)
3710 register void *arg;
3712 register tree type = arg;
3714 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3715 sibling_attribute ();
3716 equate_type_number_to_die_number (type);
3717 member_attribute (TYPE_CONTEXT (type));
3719 /* I believe that we can default the array ordering. SDB will probably
3720 do the right things even if AT_ordering is not present. It's not
3721 even an issue until we start to get into multidimensional arrays
3722 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3723 dimensional arrays, then we'll have to put the AT_ordering attribute
3724 back in. (But if and when we find out that we need to put these in,
3725 we will only do so for multidimensional arrays. After all, we don't
3726 want to waste space in the .debug section now do we?) */
3728 #ifdef USE_ORDERING_ATTRIBUTE
3729 ordering_attribute (ORD_row_major);
3730 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3732 subscript_data_attribute (type);
3735 static void
3736 output_set_type_die (arg)
3737 register void *arg;
3739 register tree type = arg;
3741 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3742 sibling_attribute ();
3743 equate_type_number_to_die_number (type);
3744 member_attribute (TYPE_CONTEXT (type));
3745 type_attribute (TREE_TYPE (type), 0, 0);
3748 #if 0
3749 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3751 static void
3752 output_entry_point_die (arg)
3753 register void *arg;
3755 register tree decl = arg;
3756 register tree origin = decl_ultimate_origin (decl);
3758 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3759 sibling_attribute ();
3760 dienum_push ();
3761 if (origin != NULL)
3762 abstract_origin_attribute (origin);
3763 else
3765 name_and_src_coords_attributes (decl);
3766 member_attribute (DECL_CONTEXT (decl));
3767 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3769 if (DECL_ABSTRACT (decl))
3770 equate_decl_number_to_die_number (decl);
3771 else
3772 low_pc_attribute (function_start_label (decl));
3774 #endif
3776 /* Output a DIE to represent an inlined instance of an enumeration type. */
3778 static void
3779 output_inlined_enumeration_type_die (arg)
3780 register void *arg;
3782 register tree type = arg;
3784 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3785 sibling_attribute ();
3786 if (!TREE_ASM_WRITTEN (type))
3787 abort ();
3788 abstract_origin_attribute (type);
3791 /* Output a DIE to represent an inlined instance of a structure type. */
3793 static void
3794 output_inlined_structure_type_die (arg)
3795 register void *arg;
3797 register tree type = arg;
3799 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3800 sibling_attribute ();
3801 if (!TREE_ASM_WRITTEN (type))
3802 abort ();
3803 abstract_origin_attribute (type);
3806 /* Output a DIE to represent an inlined instance of a union type. */
3808 static void
3809 output_inlined_union_type_die (arg)
3810 register void *arg;
3812 register tree type = arg;
3814 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3815 sibling_attribute ();
3816 if (!TREE_ASM_WRITTEN (type))
3817 abort ();
3818 abstract_origin_attribute (type);
3821 /* Output a DIE to represent an enumeration type. Note that these DIEs
3822 include all of the information about the enumeration values also.
3823 This information is encoded into the element_list attribute. */
3825 static void
3826 output_enumeration_type_die (arg)
3827 register void *arg;
3829 register tree type = arg;
3831 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3832 sibling_attribute ();
3833 equate_type_number_to_die_number (type);
3834 name_attribute (type_tag (type));
3835 member_attribute (TYPE_CONTEXT (type));
3837 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3838 given enum type is incomplete, do not generate the AT_byte_size
3839 attribute or the AT_element_list attribute. */
3841 if (COMPLETE_TYPE_P (type))
3843 byte_size_attribute (type);
3844 element_list_attribute (TYPE_FIELDS (type));
3848 /* Output a DIE to represent either a real live formal parameter decl or
3849 to represent just the type of some formal parameter position in some
3850 function type.
3852 Note that this routine is a bit unusual because its argument may be
3853 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3854 represents an inlining of some PARM_DECL) or else some sort of a
3855 ..._TYPE node. If it's the former then this function is being called
3856 to output a DIE to represent a formal parameter object (or some inlining
3857 thereof). If it's the latter, then this function is only being called
3858 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3859 formal argument type of some subprogram type. */
3861 static void
3862 output_formal_parameter_die (arg)
3863 register void *arg;
3865 register tree node = arg;
3867 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3868 sibling_attribute ();
3870 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3872 case 'd': /* We were called with some kind of a ..._DECL node. */
3874 register tree origin = decl_ultimate_origin (node);
3876 if (origin != NULL)
3877 abstract_origin_attribute (origin);
3878 else
3880 name_and_src_coords_attributes (node);
3881 type_attribute (TREE_TYPE (node),
3882 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3884 if (DECL_ABSTRACT (node))
3885 equate_decl_number_to_die_number (node);
3886 else
3887 location_or_const_value_attribute (node);
3889 break;
3891 case 't': /* We were called with some kind of a ..._TYPE node. */
3892 type_attribute (node, 0, 0);
3893 break;
3895 default:
3896 abort (); /* Should never happen. */
3900 /* Output a DIE to represent a declared function (either file-scope
3901 or block-local) which has "external linkage" (according to ANSI-C). */
3903 static void
3904 output_global_subroutine_die (arg)
3905 register void *arg;
3907 register tree decl = arg;
3908 register tree origin = decl_ultimate_origin (decl);
3910 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3911 sibling_attribute ();
3912 dienum_push ();
3913 if (origin != NULL)
3914 abstract_origin_attribute (origin);
3915 else
3917 register tree type = TREE_TYPE (decl);
3919 name_and_src_coords_attributes (decl);
3920 inline_attribute (decl);
3921 prototyped_attribute (type);
3922 member_attribute (DECL_CONTEXT (decl));
3923 type_attribute (TREE_TYPE (type), 0, 0);
3924 pure_or_virtual_attribute (decl);
3926 if (DECL_ABSTRACT (decl))
3927 equate_decl_number_to_die_number (decl);
3928 else
3930 if (! DECL_EXTERNAL (decl) && ! in_class
3931 && decl == current_function_decl)
3933 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3935 low_pc_attribute (function_start_label (decl));
3936 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3937 high_pc_attribute (label);
3938 if (use_gnu_debug_info_extensions)
3940 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3941 body_begin_attribute (label);
3942 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3943 body_end_attribute (label);
3949 /* Output a DIE to represent a declared data object (either file-scope
3950 or block-local) which has "external linkage" (according to ANSI-C). */
3952 static void
3953 output_global_variable_die (arg)
3954 register void *arg;
3956 register tree decl = arg;
3957 register tree origin = decl_ultimate_origin (decl);
3959 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3960 sibling_attribute ();
3961 if (origin != NULL)
3962 abstract_origin_attribute (origin);
3963 else
3965 name_and_src_coords_attributes (decl);
3966 member_attribute (DECL_CONTEXT (decl));
3967 type_attribute (TREE_TYPE (decl),
3968 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3970 if (DECL_ABSTRACT (decl))
3971 equate_decl_number_to_die_number (decl);
3972 else
3974 if (! DECL_EXTERNAL (decl) && ! in_class
3975 && current_function_decl == decl_function_context (decl))
3976 location_or_const_value_attribute (decl);
3980 static void
3981 output_label_die (arg)
3982 register void *arg;
3984 register tree decl = arg;
3985 register tree origin = decl_ultimate_origin (decl);
3987 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3988 sibling_attribute ();
3989 if (origin != NULL)
3990 abstract_origin_attribute (origin);
3991 else
3992 name_and_src_coords_attributes (decl);
3993 if (DECL_ABSTRACT (decl))
3994 equate_decl_number_to_die_number (decl);
3995 else
3997 register rtx insn = DECL_RTL (decl);
3999 /* Deleted labels are programmer specified labels which have been
4000 eliminated because of various optimisations. We still emit them
4001 here so that it is possible to put breakpoints on them. */
4002 if (GET_CODE (insn) == CODE_LABEL
4003 || ((GET_CODE (insn) == NOTE
4004 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
4006 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4008 /* When optimization is enabled (via -O) some parts of the compiler
4009 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
4010 represent source-level labels which were explicitly declared by
4011 the user. This really shouldn't be happening though, so catch
4012 it if it ever does happen. */
4014 if (INSN_DELETED_P (insn))
4015 abort (); /* Should never happen. */
4017 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
4018 low_pc_attribute (label);
4023 static void
4024 output_lexical_block_die (arg)
4025 register void *arg;
4027 register tree stmt = arg;
4029 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
4030 sibling_attribute ();
4031 dienum_push ();
4032 if (! BLOCK_ABSTRACT (stmt))
4034 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4035 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4037 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4038 low_pc_attribute (begin_label);
4039 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4040 high_pc_attribute (end_label);
4044 static void
4045 output_inlined_subroutine_die (arg)
4046 register void *arg;
4048 register tree stmt = arg;
4050 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
4051 sibling_attribute ();
4052 dienum_push ();
4053 abstract_origin_attribute (block_ultimate_origin (stmt));
4054 if (! BLOCK_ABSTRACT (stmt))
4056 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4057 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4059 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4060 low_pc_attribute (begin_label);
4061 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4062 high_pc_attribute (end_label);
4066 /* Output a DIE to represent a declared data object (either file-scope
4067 or block-local) which has "internal linkage" (according to ANSI-C). */
4069 static void
4070 output_local_variable_die (arg)
4071 register void *arg;
4073 register tree decl = arg;
4074 register tree origin = decl_ultimate_origin (decl);
4076 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
4077 sibling_attribute ();
4078 if (origin != NULL)
4079 abstract_origin_attribute (origin);
4080 else
4082 name_and_src_coords_attributes (decl);
4083 member_attribute (DECL_CONTEXT (decl));
4084 type_attribute (TREE_TYPE (decl),
4085 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4087 if (DECL_ABSTRACT (decl))
4088 equate_decl_number_to_die_number (decl);
4089 else
4090 location_or_const_value_attribute (decl);
4093 static void
4094 output_member_die (arg)
4095 register void *arg;
4097 register tree decl = arg;
4099 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
4100 sibling_attribute ();
4101 name_and_src_coords_attributes (decl);
4102 member_attribute (DECL_CONTEXT (decl));
4103 type_attribute (member_declared_type (decl),
4104 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4105 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
4107 byte_size_attribute (decl);
4108 bit_size_attribute (decl);
4109 bit_offset_attribute (decl);
4111 data_member_location_attribute (decl);
4114 #if 0
4115 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
4116 modified types instead.
4118 We keep this code here just in case these types of DIEs may be
4119 needed to represent certain things in other languages (e.g. Pascal)
4120 someday. */
4122 static void
4123 output_pointer_type_die (arg)
4124 register void *arg;
4126 register tree type = arg;
4128 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
4129 sibling_attribute ();
4130 equate_type_number_to_die_number (type);
4131 member_attribute (TYPE_CONTEXT (type));
4132 type_attribute (TREE_TYPE (type), 0, 0);
4135 static void
4136 output_reference_type_die (arg)
4137 register void *arg;
4139 register tree type = arg;
4141 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
4142 sibling_attribute ();
4143 equate_type_number_to_die_number (type);
4144 member_attribute (TYPE_CONTEXT (type));
4145 type_attribute (TREE_TYPE (type), 0, 0);
4147 #endif
4149 static void
4150 output_ptr_to_mbr_type_die (arg)
4151 register void *arg;
4153 register tree type = arg;
4155 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
4156 sibling_attribute ();
4157 equate_type_number_to_die_number (type);
4158 member_attribute (TYPE_CONTEXT (type));
4159 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
4160 type_attribute (TREE_TYPE (type), 0, 0);
4163 static void
4164 output_compile_unit_die (arg)
4165 register void *arg;
4167 register const char *main_input_filename = arg;
4169 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
4170 sibling_attribute ();
4171 dienum_push ();
4172 name_attribute (main_input_filename);
4175 char producer[250];
4177 sprintf (producer, "%s %s", language_string, version_string);
4178 producer_attribute (producer);
4181 if (strcmp (language_string, "GNU C++") == 0)
4182 language_attribute (LANG_C_PLUS_PLUS);
4183 else if (strcmp (language_string, "GNU Ada") == 0)
4184 language_attribute (LANG_ADA83);
4185 else if (strcmp (language_string, "GNU F77") == 0)
4186 language_attribute (LANG_FORTRAN77);
4187 else if (strcmp (language_string, "GNU Pascal") == 0)
4188 language_attribute (LANG_PASCAL83);
4189 else if (strcmp (language_string, "GNU Java") == 0)
4190 language_attribute (LANG_JAVA);
4191 else if (flag_traditional)
4192 language_attribute (LANG_C);
4193 else
4194 language_attribute (LANG_C89);
4195 low_pc_attribute (TEXT_BEGIN_LABEL);
4196 high_pc_attribute (TEXT_END_LABEL);
4197 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4198 stmt_list_attribute (LINE_BEGIN_LABEL);
4199 last_filename = xstrdup (main_input_filename);
4202 const char *wd = getpwd ();
4203 if (wd)
4204 comp_dir_attribute (wd);
4207 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
4209 sf_names_attribute (SFNAMES_BEGIN_LABEL);
4210 src_info_attribute (SRCINFO_BEGIN_LABEL);
4211 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4212 mac_info_attribute (MACINFO_BEGIN_LABEL);
4216 static void
4217 output_string_type_die (arg)
4218 register void *arg;
4220 register tree type = arg;
4222 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
4223 sibling_attribute ();
4224 equate_type_number_to_die_number (type);
4225 member_attribute (TYPE_CONTEXT (type));
4226 /* this is a fixed length string */
4227 byte_size_attribute (type);
4230 static void
4231 output_inheritance_die (arg)
4232 register void *arg;
4234 register tree binfo = arg;
4236 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
4237 sibling_attribute ();
4238 type_attribute (BINFO_TYPE (binfo), 0, 0);
4239 data_member_location_attribute (binfo);
4240 if (TREE_VIA_VIRTUAL (binfo))
4242 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
4243 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4245 if (TREE_VIA_PUBLIC (binfo))
4247 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
4248 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4250 else if (TREE_VIA_PROTECTED (binfo))
4252 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
4253 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4257 static void
4258 output_structure_type_die (arg)
4259 register void *arg;
4261 register tree type = arg;
4263 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
4264 sibling_attribute ();
4265 equate_type_number_to_die_number (type);
4266 name_attribute (type_tag (type));
4267 member_attribute (TYPE_CONTEXT (type));
4269 /* If this type has been completed, then give it a byte_size attribute
4270 and prepare to give a list of members. Otherwise, don't do either of
4271 these things. In the latter case, we will not be generating a list
4272 of members (since we don't have any idea what they might be for an
4273 incomplete type). */
4275 if (COMPLETE_TYPE_P (type))
4277 dienum_push ();
4278 byte_size_attribute (type);
4282 /* Output a DIE to represent a declared function (either file-scope
4283 or block-local) which has "internal linkage" (according to ANSI-C). */
4285 static void
4286 output_local_subroutine_die (arg)
4287 register void *arg;
4289 register tree decl = arg;
4290 register tree origin = decl_ultimate_origin (decl);
4292 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
4293 sibling_attribute ();
4294 dienum_push ();
4295 if (origin != NULL)
4296 abstract_origin_attribute (origin);
4297 else
4299 register tree type = TREE_TYPE (decl);
4301 name_and_src_coords_attributes (decl);
4302 inline_attribute (decl);
4303 prototyped_attribute (type);
4304 member_attribute (DECL_CONTEXT (decl));
4305 type_attribute (TREE_TYPE (type), 0, 0);
4306 pure_or_virtual_attribute (decl);
4308 if (DECL_ABSTRACT (decl))
4309 equate_decl_number_to_die_number (decl);
4310 else
4312 /* Avoid getting screwed up in cases where a function was declared
4313 static but where no definition was ever given for it. */
4315 if (TREE_ASM_WRITTEN (decl))
4317 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4318 low_pc_attribute (function_start_label (decl));
4319 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4320 high_pc_attribute (label);
4321 if (use_gnu_debug_info_extensions)
4323 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
4324 body_begin_attribute (label);
4325 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
4326 body_end_attribute (label);
4332 static void
4333 output_subroutine_type_die (arg)
4334 register void *arg;
4336 register tree type = arg;
4337 register tree return_type = TREE_TYPE (type);
4339 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
4340 sibling_attribute ();
4341 dienum_push ();
4342 equate_type_number_to_die_number (type);
4343 prototyped_attribute (type);
4344 member_attribute (TYPE_CONTEXT (type));
4345 type_attribute (return_type, 0, 0);
4348 static void
4349 output_typedef_die (arg)
4350 register void *arg;
4352 register tree decl = arg;
4353 register tree origin = decl_ultimate_origin (decl);
4355 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
4356 sibling_attribute ();
4357 if (origin != NULL)
4358 abstract_origin_attribute (origin);
4359 else
4361 name_and_src_coords_attributes (decl);
4362 member_attribute (DECL_CONTEXT (decl));
4363 type_attribute (TREE_TYPE (decl),
4364 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4366 if (DECL_ABSTRACT (decl))
4367 equate_decl_number_to_die_number (decl);
4370 static void
4371 output_union_type_die (arg)
4372 register void *arg;
4374 register tree type = arg;
4376 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
4377 sibling_attribute ();
4378 equate_type_number_to_die_number (type);
4379 name_attribute (type_tag (type));
4380 member_attribute (TYPE_CONTEXT (type));
4382 /* If this type has been completed, then give it a byte_size attribute
4383 and prepare to give a list of members. Otherwise, don't do either of
4384 these things. In the latter case, we will not be generating a list
4385 of members (since we don't have any idea what they might be for an
4386 incomplete type). */
4388 if (COMPLETE_TYPE_P (type))
4390 dienum_push ();
4391 byte_size_attribute (type);
4395 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
4396 at the end of an (ANSI prototyped) formal parameters list. */
4398 static void
4399 output_unspecified_parameters_die (arg)
4400 register void *arg;
4402 register tree decl_or_type = arg;
4404 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
4405 sibling_attribute ();
4407 /* This kludge is here only for the sake of being compatible with what
4408 the USL CI5 C compiler does. The specification of Dwarf Version 1
4409 doesn't say that TAG_unspecified_parameters DIEs should contain any
4410 attributes other than the AT_sibling attribute, but they are certainly
4411 allowed to contain additional attributes, and the CI5 compiler
4412 generates AT_name, AT_fund_type, and AT_location attributes within
4413 TAG_unspecified_parameters DIEs which appear in the child lists for
4414 DIEs representing function definitions, so we do likewise here. */
4416 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
4418 name_attribute ("...");
4419 fund_type_attribute (FT_pointer);
4420 /* location_attribute (?); */
4424 static void
4425 output_padded_null_die (arg)
4426 register void *arg ATTRIBUTE_UNUSED;
4428 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
4431 /*************************** end of DIEs *********************************/
4433 /* Generate some type of DIE. This routine generates the generic outer
4434 wrapper stuff which goes around all types of DIE's (regardless of their
4435 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
4436 DIE-length word, followed by the guts of the DIE itself. After the guts
4437 of the DIE, there must always be a terminator label for the DIE. */
4439 static void
4440 output_die (die_specific_output_function, param)
4441 register void (*die_specific_output_function) PARAMS ((void *));
4442 register void *param;
4444 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4445 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4447 current_dienum = NEXT_DIE_NUM;
4448 NEXT_DIE_NUM = next_unused_dienum;
4450 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4451 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4453 /* Write a label which will act as the name for the start of this DIE. */
4455 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4457 /* Write the DIE-length word. */
4459 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4461 /* Fill in the guts of the DIE. */
4463 next_unused_dienum++;
4464 die_specific_output_function (param);
4466 /* Write a label which will act as the name for the end of this DIE. */
4468 ASM_OUTPUT_LABEL (asm_out_file, end_label);
4471 static void
4472 end_sibling_chain ()
4474 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4476 current_dienum = NEXT_DIE_NUM;
4477 NEXT_DIE_NUM = next_unused_dienum;
4479 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4481 /* Write a label which will act as the name for the start of this DIE. */
4483 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4485 /* Write the DIE-length word. */
4487 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4489 dienum_pop ();
4492 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4493 TAG_unspecified_parameters DIE) to represent the types of the formal
4494 parameters as specified in some function type specification (except
4495 for those which appear as part of a function *definition*).
4497 Note that we must be careful here to output all of the parameter
4498 DIEs *before* we output any DIEs needed to represent the types of
4499 the formal parameters. This keeps svr4 SDB happy because it
4500 (incorrectly) thinks that the first non-parameter DIE it sees ends
4501 the formal parameter list. */
4503 static void
4504 output_formal_types (function_or_method_type)
4505 register tree function_or_method_type;
4507 register tree link;
4508 register tree formal_type = NULL;
4509 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4511 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4512 get bogus recursion when outputting tagged types local to a
4513 function declaration. */
4514 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4515 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4517 /* In the case where we are generating a formal types list for a C++
4518 non-static member function type, skip over the first thing on the
4519 TYPE_ARG_TYPES list because it only represents the type of the
4520 hidden `this pointer'. The debugger should be able to figure
4521 out (without being explicitly told) that this non-static member
4522 function type takes a `this pointer' and should be able to figure
4523 what the type of that hidden parameter is from the AT_member
4524 attribute of the parent TAG_subroutine_type DIE. */
4526 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4527 first_parm_type = TREE_CHAIN (first_parm_type);
4529 /* Make our first pass over the list of formal parameter types and output
4530 a TAG_formal_parameter DIE for each one. */
4532 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4534 formal_type = TREE_VALUE (link);
4535 if (formal_type == void_type_node)
4536 break;
4538 /* Output a (nameless) DIE to represent the formal parameter itself. */
4540 output_die (output_formal_parameter_die, formal_type);
4543 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4544 DIE to the end of the parameter list. */
4546 if (formal_type != void_type_node)
4547 output_die (output_unspecified_parameters_die, function_or_method_type);
4549 /* Make our second (and final) pass over the list of formal parameter types
4550 and output DIEs to represent those types (as necessary). */
4552 for (link = TYPE_ARG_TYPES (function_or_method_type);
4553 link;
4554 link = TREE_CHAIN (link))
4556 formal_type = TREE_VALUE (link);
4557 if (formal_type == void_type_node)
4558 break;
4560 output_type (formal_type, function_or_method_type);
4563 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4566 /* Remember a type in the pending_types_list. */
4568 static void
4569 pend_type (type)
4570 register tree type;
4572 if (pending_types == pending_types_allocated)
4574 pending_types_allocated += PENDING_TYPES_INCREMENT;
4575 pending_types_list
4576 = (tree *) xrealloc (pending_types_list,
4577 sizeof (tree) * pending_types_allocated);
4579 pending_types_list[pending_types++] = type;
4581 /* Mark the pending type as having been output already (even though
4582 it hasn't been). This prevents the type from being added to the
4583 pending_types_list more than once. */
4585 TREE_ASM_WRITTEN (type) = 1;
4588 /* Return non-zero if it is legitimate to output DIEs to represent a
4589 given type while we are generating the list of child DIEs for some
4590 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4592 See the comments within the function for a description of when it is
4593 considered legitimate to output DIEs for various kinds of types.
4595 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4596 or it may point to a BLOCK node (for types local to a block), or to a
4597 FUNCTION_DECL node (for types local to the heading of some function
4598 definition), or to a FUNCTION_TYPE node (for types local to the
4599 prototyped parameter list of a function type specification), or to a
4600 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4601 (in the case of C++ nested types).
4603 The `scope' parameter should likewise be NULL or should point to a
4604 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4605 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4607 This function is used only for deciding when to "pend" and when to
4608 "un-pend" types to/from the pending_types_list.
4610 Note that we sometimes make use of this "type pending" feature in a
4611 rather twisted way to temporarily delay the production of DIEs for the
4612 types of formal parameters. (We do this just to make svr4 SDB happy.)
4613 It order to delay the production of DIEs representing types of formal
4614 parameters, callers of this function supply `fake_containing_scope' as
4615 the `scope' parameter to this function. Given that fake_containing_scope
4616 is a tagged type which is *not* the containing scope for *any* other type,
4617 the desired effect is achieved, i.e. output of DIEs representing types
4618 is temporarily suspended, and any type DIEs which would have otherwise
4619 been output are instead placed onto the pending_types_list. Later on,
4620 we force these (temporarily pended) types to be output simply by calling
4621 `output_pending_types_for_scope' with an actual argument equal to the
4622 true scope of the types we temporarily pended. */
4624 static inline int
4625 type_ok_for_scope (type, scope)
4626 register tree type;
4627 register tree scope;
4629 /* Tagged types (i.e. struct, union, and enum types) must always be
4630 output only in the scopes where they actually belong (or else the
4631 scoping of their own tag names and the scoping of their member
4632 names will be incorrect). Non-tagged-types on the other hand can
4633 generally be output anywhere, except that svr4 SDB really doesn't
4634 want to see them nested within struct or union types, so here we
4635 say it is always OK to immediately output any such a (non-tagged)
4636 type, so long as we are not within such a context. Note that the
4637 only kinds of non-tagged types which we will be dealing with here
4638 (for C and C++ anyway) will be array types and function types. */
4640 return is_tagged_type (type)
4641 ? (TYPE_CONTEXT (type) == scope
4642 /* Ignore namespaces for the moment. */
4643 || (scope == NULL_TREE
4644 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4645 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4646 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4647 : (scope == NULL_TREE || ! is_tagged_type (scope));
4650 /* Output any pending types (from the pending_types list) which we can output
4651 now (taking into account the scope that we are working on now).
4653 For each type output, remove the given type from the pending_types_list
4654 *before* we try to output it.
4656 Note that we have to process the list in beginning-to-end order,
4657 because the call made here to output_type may cause yet more types
4658 to be added to the end of the list, and we may have to output some
4659 of them too. */
4661 static void
4662 output_pending_types_for_scope (containing_scope)
4663 register tree containing_scope;
4665 register unsigned i;
4667 for (i = 0; i < pending_types; )
4669 register tree type = pending_types_list[i];
4671 if (type_ok_for_scope (type, containing_scope))
4673 register tree *mover;
4674 register tree *limit;
4676 pending_types--;
4677 limit = &pending_types_list[pending_types];
4678 for (mover = &pending_types_list[i]; mover < limit; mover++)
4679 *mover = *(mover+1);
4681 /* Un-mark the type as having been output already (because it
4682 hasn't been, really). Then call output_type to generate a
4683 Dwarf representation of it. */
4685 TREE_ASM_WRITTEN (type) = 0;
4686 output_type (type, containing_scope);
4688 /* Don't increment the loop counter in this case because we
4689 have shifted all of the subsequent pending types down one
4690 element in the pending_types_list array. */
4692 else
4693 i++;
4697 /* Remember a type in the incomplete_types_list. */
4699 static void
4700 add_incomplete_type (type)
4701 tree type;
4703 if (incomplete_types == incomplete_types_allocated)
4705 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4706 incomplete_types_list
4707 = (tree *) xrealloc (incomplete_types_list,
4708 sizeof (tree) * incomplete_types_allocated);
4711 incomplete_types_list[incomplete_types++] = type;
4714 /* Walk through the list of incomplete types again, trying once more to
4715 emit full debugging info for them. */
4717 static void
4718 retry_incomplete_types ()
4720 register tree type;
4722 finalizing = 1;
4723 while (incomplete_types)
4725 --incomplete_types;
4726 type = incomplete_types_list[incomplete_types];
4727 output_type (type, NULL_TREE);
4731 static void
4732 output_type (type, containing_scope)
4733 register tree type;
4734 register tree containing_scope;
4736 if (type == 0 || type == error_mark_node)
4737 return;
4739 /* We are going to output a DIE to represent the unqualified version of
4740 this type (i.e. without any const or volatile qualifiers) so get
4741 the main variant (i.e. the unqualified version) of this type now. */
4743 type = type_main_variant (type);
4745 if (TREE_ASM_WRITTEN (type))
4747 if (finalizing && AGGREGATE_TYPE_P (type))
4749 register tree member;
4751 /* Some of our nested types might not have been defined when we
4752 were written out before; force them out now. */
4754 for (member = TYPE_FIELDS (type); member;
4755 member = TREE_CHAIN (member))
4756 if (TREE_CODE (member) == TYPE_DECL
4757 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4758 output_type (TREE_TYPE (member), containing_scope);
4760 return;
4763 /* If this is a nested type whose containing class hasn't been
4764 written out yet, writing it out will cover this one, too. */
4766 if (TYPE_CONTEXT (type)
4767 && TYPE_P (TYPE_CONTEXT (type))
4768 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4770 output_type (TYPE_CONTEXT (type), containing_scope);
4771 return;
4774 /* Don't generate any DIEs for this type now unless it is OK to do so
4775 (based upon what `type_ok_for_scope' tells us). */
4777 if (! type_ok_for_scope (type, containing_scope))
4779 pend_type (type);
4780 return;
4783 switch (TREE_CODE (type))
4785 case ERROR_MARK:
4786 break;
4788 case VECTOR_TYPE:
4789 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4790 break;
4792 case POINTER_TYPE:
4793 case REFERENCE_TYPE:
4794 /* Prevent infinite recursion in cases where this is a recursive
4795 type. Recursive types are possible in Ada. */
4796 TREE_ASM_WRITTEN (type) = 1;
4797 /* For these types, all that is required is that we output a DIE
4798 (or a set of DIEs) to represent the "basis" type. */
4799 output_type (TREE_TYPE (type), containing_scope);
4800 break;
4802 case OFFSET_TYPE:
4803 /* This code is used for C++ pointer-to-data-member types. */
4804 /* Output a description of the relevant class type. */
4805 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4806 /* Output a description of the type of the object pointed to. */
4807 output_type (TREE_TYPE (type), containing_scope);
4808 /* Now output a DIE to represent this pointer-to-data-member type
4809 itself. */
4810 output_die (output_ptr_to_mbr_type_die, type);
4811 break;
4813 case SET_TYPE:
4814 output_type (TYPE_DOMAIN (type), containing_scope);
4815 output_die (output_set_type_die, type);
4816 break;
4818 case FILE_TYPE:
4819 output_type (TREE_TYPE (type), containing_scope);
4820 abort (); /* No way to represent these in Dwarf yet! */
4821 break;
4823 case FUNCTION_TYPE:
4824 /* Force out return type (in case it wasn't forced out already). */
4825 output_type (TREE_TYPE (type), containing_scope);
4826 output_die (output_subroutine_type_die, type);
4827 output_formal_types (type);
4828 end_sibling_chain ();
4829 break;
4831 case METHOD_TYPE:
4832 /* Force out return type (in case it wasn't forced out already). */
4833 output_type (TREE_TYPE (type), containing_scope);
4834 output_die (output_subroutine_type_die, type);
4835 output_formal_types (type);
4836 end_sibling_chain ();
4837 break;
4839 case ARRAY_TYPE:
4840 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4842 output_type (TREE_TYPE (type), containing_scope);
4843 output_die (output_string_type_die, type);
4845 else
4847 register tree element_type;
4849 element_type = TREE_TYPE (type);
4850 while (TREE_CODE (element_type) == ARRAY_TYPE)
4851 element_type = TREE_TYPE (element_type);
4853 output_type (element_type, containing_scope);
4854 output_die (output_array_type_die, type);
4856 break;
4858 case ENUMERAL_TYPE:
4859 case RECORD_TYPE:
4860 case UNION_TYPE:
4861 case QUAL_UNION_TYPE:
4863 /* For a non-file-scope tagged type, we can always go ahead and
4864 output a Dwarf description of this type right now, even if
4865 the type in question is still incomplete, because if this
4866 local type *was* ever completed anywhere within its scope,
4867 that complete definition would already have been attached to
4868 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4869 node by the time we reach this point. That's true because of the
4870 way the front-end does its processing of file-scope declarations (of
4871 functions and class types) within which other types might be
4872 nested. The C and C++ front-ends always gobble up such "local
4873 scope" things en-mass before they try to output *any* debugging
4874 information for any of the stuff contained inside them and thus,
4875 we get the benefit here of what is (in effect) a pre-resolution
4876 of forward references to tagged types in local scopes.
4878 Note however that for file-scope tagged types we cannot assume
4879 that such pre-resolution of forward references has taken place.
4880 A given file-scope tagged type may appear to be incomplete when
4881 we reach this point, but it may yet be given a full definition
4882 (at file-scope) later on during compilation. In order to avoid
4883 generating a premature (and possibly incorrect) set of Dwarf
4884 DIEs for such (as yet incomplete) file-scope tagged types, we
4885 generate nothing at all for as-yet incomplete file-scope tagged
4886 types here unless we are making our special "finalization" pass
4887 for file-scope things at the very end of compilation. At that
4888 time, we will certainly know as much about each file-scope tagged
4889 type as we are ever going to know, so at that point in time, we
4890 can safely generate correct Dwarf descriptions for these file-
4891 scope tagged types. */
4893 if (!COMPLETE_TYPE_P (type)
4894 && (TYPE_CONTEXT (type) == NULL
4895 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4896 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4897 && !finalizing)
4899 /* We don't need to do this for function-local types. */
4900 if (! decl_function_context (TYPE_STUB_DECL (type)))
4901 add_incomplete_type (type);
4902 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4905 /* Prevent infinite recursion in cases where the type of some
4906 member of this type is expressed in terms of this type itself. */
4908 TREE_ASM_WRITTEN (type) = 1;
4910 /* Output a DIE to represent the tagged type itself. */
4912 switch (TREE_CODE (type))
4914 case ENUMERAL_TYPE:
4915 output_die (output_enumeration_type_die, type);
4916 return; /* a special case -- nothing left to do so just return */
4918 case RECORD_TYPE:
4919 output_die (output_structure_type_die, type);
4920 break;
4922 case UNION_TYPE:
4923 case QUAL_UNION_TYPE:
4924 output_die (output_union_type_die, type);
4925 break;
4927 default:
4928 abort (); /* Should never happen. */
4931 /* If this is not an incomplete type, output descriptions of
4932 each of its members.
4934 Note that as we output the DIEs necessary to represent the
4935 members of this record or union type, we will also be trying
4936 to output DIEs to represent the *types* of those members.
4937 However the `output_type' function (above) will specifically
4938 avoid generating type DIEs for member types *within* the list
4939 of member DIEs for this (containing) type execpt for those
4940 types (of members) which are explicitly marked as also being
4941 members of this (containing) type themselves. The g++ front-
4942 end can force any given type to be treated as a member of some
4943 other (containing) type by setting the TYPE_CONTEXT of the
4944 given (member) type to point to the TREE node representing the
4945 appropriate (containing) type.
4948 if (COMPLETE_TYPE_P (type))
4950 /* First output info about the base classes. */
4951 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4953 register tree bases = TYPE_BINFO_BASETYPES (type);
4954 register int n_bases = TREE_VEC_LENGTH (bases);
4955 register int i;
4957 for (i = 0; i < n_bases; i++)
4959 tree binfo = TREE_VEC_ELT (bases, i);
4960 output_type (BINFO_TYPE (binfo), containing_scope);
4961 output_die (output_inheritance_die, binfo);
4965 ++in_class;
4968 register tree normal_member;
4970 /* Now output info about the data members and type members. */
4972 for (normal_member = TYPE_FIELDS (type);
4973 normal_member;
4974 normal_member = TREE_CHAIN (normal_member))
4975 output_decl (normal_member, type);
4979 register tree func_member;
4981 /* Now output info about the function members (if any). */
4983 for (func_member = TYPE_METHODS (type);
4984 func_member;
4985 func_member = TREE_CHAIN (func_member))
4987 /* Don't include clones in the member list. */
4988 if (DECL_ABSTRACT_ORIGIN (func_member))
4989 continue;
4991 output_decl (func_member, type);
4995 --in_class;
4997 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4998 scopes (at least in C++) so we must now output any nested
4999 pending types which are local just to this type. */
5001 output_pending_types_for_scope (type);
5003 end_sibling_chain (); /* Terminate member chain. */
5006 break;
5008 case VOID_TYPE:
5009 case INTEGER_TYPE:
5010 case REAL_TYPE:
5011 case COMPLEX_TYPE:
5012 case BOOLEAN_TYPE:
5013 case CHAR_TYPE:
5014 break; /* No DIEs needed for fundamental types. */
5016 case LANG_TYPE: /* No Dwarf representation currently defined. */
5017 break;
5019 default:
5020 abort ();
5023 TREE_ASM_WRITTEN (type) = 1;
5026 static void
5027 output_tagged_type_instantiation (type)
5028 register tree type;
5030 if (type == 0 || type == error_mark_node)
5031 return;
5033 /* We are going to output a DIE to represent the unqualified version of
5034 this type (i.e. without any const or volatile qualifiers) so make
5035 sure that we have the main variant (i.e. the unqualified version) of
5036 this type now. */
5038 if (type != type_main_variant (type))
5039 abort ();
5041 if (!TREE_ASM_WRITTEN (type))
5042 abort ();
5044 switch (TREE_CODE (type))
5046 case ERROR_MARK:
5047 break;
5049 case ENUMERAL_TYPE:
5050 output_die (output_inlined_enumeration_type_die, type);
5051 break;
5053 case RECORD_TYPE:
5054 output_die (output_inlined_structure_type_die, type);
5055 break;
5057 case UNION_TYPE:
5058 case QUAL_UNION_TYPE:
5059 output_die (output_inlined_union_type_die, type);
5060 break;
5062 default:
5063 abort (); /* Should never happen. */
5067 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
5068 the things which are local to the given block. */
5070 static void
5071 output_block (stmt, depth)
5072 register tree stmt;
5073 int depth;
5075 register int must_output_die = 0;
5076 register tree origin;
5077 register enum tree_code origin_code;
5079 /* Ignore blocks never really used to make RTL. */
5081 if (! stmt || ! TREE_USED (stmt)
5082 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
5083 return;
5085 /* Determine the "ultimate origin" of this block. This block may be an
5086 inlined instance of an inlined instance of inline function, so we
5087 have to trace all of the way back through the origin chain to find
5088 out what sort of node actually served as the original seed for the
5089 creation of the current block. */
5091 origin = block_ultimate_origin (stmt);
5092 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
5094 /* Determine if we need to output any Dwarf DIEs at all to represent this
5095 block. */
5097 if (origin_code == FUNCTION_DECL)
5098 /* The outer scopes for inlinings *must* always be represented. We
5099 generate TAG_inlined_subroutine DIEs for them. (See below.) */
5100 must_output_die = 1;
5101 else
5103 /* In the case where the current block represents an inlining of the
5104 "body block" of an inline function, we must *NOT* output any DIE
5105 for this block because we have already output a DIE to represent
5106 the whole inlined function scope and the "body block" of any
5107 function doesn't really represent a different scope according to
5108 ANSI C rules. So we check here to make sure that this block does
5109 not represent a "body block inlining" before trying to set the
5110 `must_output_die' flag. */
5112 if (! is_body_block (origin ? origin : stmt))
5114 /* Determine if this block directly contains any "significant"
5115 local declarations which we will need to output DIEs for. */
5117 if (debug_info_level > DINFO_LEVEL_TERSE)
5118 /* We are not in terse mode so *any* local declaration counts
5119 as being a "significant" one. */
5120 must_output_die = (BLOCK_VARS (stmt) != NULL);
5121 else
5123 register tree decl;
5125 /* We are in terse mode, so only local (nested) function
5126 definitions count as "significant" local declarations. */
5128 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5129 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
5131 must_output_die = 1;
5132 break;
5138 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
5139 DIE for any block which contains no significant local declarations
5140 at all. Rather, in such cases we just call `output_decls_for_scope'
5141 so that any needed Dwarf info for any sub-blocks will get properly
5142 generated. Note that in terse mode, our definition of what constitutes
5143 a "significant" local declaration gets restricted to include only
5144 inlined function instances and local (nested) function definitions. */
5146 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
5147 /* We don't care about an abstract inlined subroutine. */;
5148 else if (must_output_die)
5150 output_die ((origin_code == FUNCTION_DECL)
5151 ? output_inlined_subroutine_die
5152 : output_lexical_block_die,
5153 stmt);
5154 output_decls_for_scope (stmt, depth);
5155 end_sibling_chain ();
5157 else
5158 output_decls_for_scope (stmt, depth);
5161 /* Output all of the decls declared within a given scope (also called
5162 a `binding contour') and (recursively) all of it's sub-blocks. */
5164 static void
5165 output_decls_for_scope (stmt, depth)
5166 register tree stmt;
5167 int depth;
5169 /* Ignore blocks never really used to make RTL. */
5171 if (! stmt || ! TREE_USED (stmt))
5172 return;
5174 /* Output the DIEs to represent all of the data objects, functions,
5175 typedefs, and tagged types declared directly within this block
5176 but not within any nested sub-blocks. */
5179 register tree decl;
5181 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5182 output_decl (decl, stmt);
5185 output_pending_types_for_scope (stmt);
5187 /* Output the DIEs to represent all sub-blocks (and the items declared
5188 therein) of this block. */
5191 register tree subblocks;
5193 for (subblocks = BLOCK_SUBBLOCKS (stmt);
5194 subblocks;
5195 subblocks = BLOCK_CHAIN (subblocks))
5196 output_block (subblocks, depth + 1);
5200 /* Is this a typedef we can avoid emitting? */
5202 static inline int
5203 is_redundant_typedef (decl)
5204 register tree decl;
5206 if (TYPE_DECL_IS_STUB (decl))
5207 return 1;
5208 if (DECL_ARTIFICIAL (decl)
5209 && DECL_CONTEXT (decl)
5210 && is_tagged_type (DECL_CONTEXT (decl))
5211 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
5212 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
5213 /* Also ignore the artificial member typedef for the class name. */
5214 return 1;
5215 return 0;
5218 /* Output Dwarf .debug information for a decl described by DECL. */
5220 static void
5221 output_decl (decl, containing_scope)
5222 register tree decl;
5223 register tree containing_scope;
5225 /* Make a note of the decl node we are going to be working on. We may
5226 need to give the user the source coordinates of where it appeared in
5227 case we notice (later on) that something about it looks screwy. */
5229 dwarf_last_decl = decl;
5231 if (TREE_CODE (decl) == ERROR_MARK)
5232 return;
5234 /* If a structure is declared within an initialization, e.g. as the
5235 operand of a sizeof, then it will not have a name. We don't want
5236 to output a DIE for it, as the tree nodes are in the temporary obstack */
5238 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5239 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
5240 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
5241 || (TYPE_FIELDS (TREE_TYPE (decl))
5242 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
5243 return;
5245 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5247 if (DECL_IGNORED_P (decl))
5248 return;
5250 switch (TREE_CODE (decl))
5252 case CONST_DECL:
5253 /* The individual enumerators of an enum type get output when we
5254 output the Dwarf representation of the relevant enum type itself. */
5255 break;
5257 case FUNCTION_DECL:
5258 /* If we are in terse mode, don't output any DIEs to represent
5259 mere function declarations. Also, if we are conforming
5260 to the DWARF version 1 specification, don't output DIEs for
5261 mere function declarations. */
5263 if (DECL_INITIAL (decl) == NULL_TREE)
5264 #if (DWARF_VERSION > 1)
5265 if (debug_info_level <= DINFO_LEVEL_TERSE)
5266 #endif
5267 break;
5269 /* Before we describe the FUNCTION_DECL itself, make sure that we
5270 have described its return type. */
5272 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
5275 /* And its containing type. */
5276 register tree origin = decl_class_context (decl);
5277 if (origin)
5278 output_type (origin, containing_scope);
5281 /* If we're emitting an out-of-line copy of an inline function,
5282 set up to refer to the abstract instance emitted from
5283 note_deferral_of_defined_inline_function. */
5284 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
5285 && ! (containing_scope && TYPE_P (containing_scope)))
5286 set_decl_origin_self (decl);
5288 /* If the following DIE will represent a function definition for a
5289 function with "extern" linkage, output a special "pubnames" DIE
5290 label just ahead of the actual DIE. A reference to this label
5291 was already generated in the .debug_pubnames section sub-entry
5292 for this function definition. */
5294 if (TREE_PUBLIC (decl))
5296 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5298 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5299 ASM_OUTPUT_LABEL (asm_out_file, label);
5302 /* Now output a DIE to represent the function itself. */
5304 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
5305 ? output_global_subroutine_die
5306 : output_local_subroutine_die,
5307 decl);
5309 /* Now output descriptions of the arguments for this function.
5310 This gets (unnecessarily?) complex because of the fact that
5311 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
5312 cases where there was a trailing `...' at the end of the formal
5313 parameter list. In order to find out if there was a trailing
5314 ellipsis or not, we must instead look at the type associated
5315 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
5316 If the chain of type nodes hanging off of this FUNCTION_TYPE node
5317 ends with a void_type_node then there should *not* be an ellipsis
5318 at the end. */
5320 /* In the case where we are describing a mere function declaration, all
5321 we need to do here (and all we *can* do here) is to describe
5322 the *types* of its formal parameters. */
5324 if (decl != current_function_decl || in_class)
5325 output_formal_types (TREE_TYPE (decl));
5326 else
5328 /* Generate DIEs to represent all known formal parameters */
5330 register tree arg_decls = DECL_ARGUMENTS (decl);
5331 register tree parm;
5333 /* WARNING! Kludge zone ahead! Here we have a special
5334 hack for svr4 SDB compatibility. Instead of passing the
5335 current FUNCTION_DECL node as the second parameter (i.e.
5336 the `containing_scope' parameter) to `output_decl' (as
5337 we ought to) we instead pass a pointer to our own private
5338 fake_containing_scope node. That node is a RECORD_TYPE
5339 node which NO OTHER TYPE may ever actually be a member of.
5341 This pointer will ultimately get passed into `output_type'
5342 as its `containing_scope' parameter. `Output_type' will
5343 then perform its part in the hack... i.e. it will pend
5344 the type of the formal parameter onto the pending_types
5345 list. Later on, when we are done generating the whole
5346 sequence of formal parameter DIEs for this function
5347 definition, we will un-pend all previously pended types
5348 of formal parameters for this function definition.
5350 This whole kludge prevents any type DIEs from being
5351 mixed in with the formal parameter DIEs. That's good
5352 because svr4 SDB believes that the list of formal
5353 parameter DIEs for a function ends wherever the first
5354 non-formal-parameter DIE appears. Thus, we have to
5355 keep the formal parameter DIEs segregated. They must
5356 all appear (consecutively) at the start of the list of
5357 children for the DIE representing the function definition.
5358 Then (and only then) may we output any additional DIEs
5359 needed to represent the types of these formal parameters.
5363 When generating DIEs, generate the unspecified_parameters
5364 DIE instead if we come across the arg "__builtin_va_alist"
5367 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
5368 if (TREE_CODE (parm) == PARM_DECL)
5370 if (DECL_NAME(parm) &&
5371 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
5372 "__builtin_va_alist") )
5373 output_die (output_unspecified_parameters_die, decl);
5374 else
5375 output_decl (parm, fake_containing_scope);
5379 Now that we have finished generating all of the DIEs to
5380 represent the formal parameters themselves, force out
5381 any DIEs needed to represent their types. We do this
5382 simply by un-pending all previously pended types which
5383 can legitimately go into the chain of children DIEs for
5384 the current FUNCTION_DECL.
5387 output_pending_types_for_scope (decl);
5390 Decide whether we need a unspecified_parameters DIE at the end.
5391 There are 2 more cases to do this for:
5392 1) the ansi ... declaration - this is detectable when the end
5393 of the arg list is not a void_type_node
5394 2) an unprototyped function declaration (not a definition). This
5395 just means that we have no info about the parameters at all.
5399 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
5401 if (fn_arg_types)
5403 /* this is the prototyped case, check for ... */
5404 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
5405 output_die (output_unspecified_parameters_die, decl);
5407 else
5409 /* this is unprototyped, check for undefined (just declaration) */
5410 if (!DECL_INITIAL (decl))
5411 output_die (output_unspecified_parameters_die, decl);
5415 /* Output Dwarf info for all of the stuff within the body of the
5416 function (if it has one - it may be just a declaration). */
5419 register tree outer_scope = DECL_INITIAL (decl);
5421 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
5423 /* Note that here, `outer_scope' is a pointer to the outermost
5424 BLOCK node created to represent a function.
5425 This outermost BLOCK actually represents the outermost
5426 binding contour for the function, i.e. the contour in which
5427 the function's formal parameters and labels get declared.
5429 Curiously, it appears that the front end doesn't actually
5430 put the PARM_DECL nodes for the current function onto the
5431 BLOCK_VARS list for this outer scope. (They are strung
5432 off of the DECL_ARGUMENTS list for the function instead.)
5433 The BLOCK_VARS list for the `outer_scope' does provide us
5434 with a list of the LABEL_DECL nodes for the function however,
5435 and we output DWARF info for those here.
5437 Just within the `outer_scope' there will be a BLOCK node
5438 representing the function's outermost pair of curly braces,
5439 and any blocks used for the base and member initializers of
5440 a C++ constructor function. */
5442 output_decls_for_scope (outer_scope, 0);
5444 /* Finally, force out any pending types which are local to the
5445 outermost block of this function definition. These will
5446 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
5447 node itself. */
5449 output_pending_types_for_scope (decl);
5454 /* Generate a terminator for the list of stuff `owned' by this
5455 function. */
5457 end_sibling_chain ();
5459 break;
5461 case TYPE_DECL:
5462 /* If we are in terse mode, don't generate any DIEs to represent
5463 any actual typedefs. Note that even when we are in terse mode,
5464 we must still output DIEs to represent those tagged types which
5465 are used (directly or indirectly) in the specification of either
5466 a return type or a formal parameter type of some function. */
5468 if (debug_info_level <= DINFO_LEVEL_TERSE)
5469 if (! TYPE_DECL_IS_STUB (decl)
5470 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5471 return;
5473 /* In the special case of a TYPE_DECL node representing
5474 the declaration of some type tag, if the given TYPE_DECL is
5475 marked as having been instantiated from some other (original)
5476 TYPE_DECL node (e.g. one which was generated within the original
5477 definition of an inline function) we have to generate a special
5478 (abbreviated) TAG_structure_type, TAG_union_type, or
5479 TAG_enumeration-type DIE here. */
5481 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5483 output_tagged_type_instantiation (TREE_TYPE (decl));
5484 return;
5487 output_type (TREE_TYPE (decl), containing_scope);
5489 if (! is_redundant_typedef (decl))
5490 /* Output a DIE to represent the typedef itself. */
5491 output_die (output_typedef_die, decl);
5492 break;
5494 case LABEL_DECL:
5495 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5496 output_die (output_label_die, decl);
5497 break;
5499 case VAR_DECL:
5500 /* If we are conforming to the DWARF version 1 specification, don't
5501 generated any DIEs to represent mere external object declarations. */
5503 #if (DWARF_VERSION <= 1)
5504 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5505 break;
5506 #endif
5508 /* If we are in terse mode, don't generate any DIEs to represent
5509 any variable declarations or definitions. */
5511 if (debug_info_level <= DINFO_LEVEL_TERSE)
5512 break;
5514 /* Output any DIEs that are needed to specify the type of this data
5515 object. */
5517 output_type (TREE_TYPE (decl), containing_scope);
5520 /* And its containing type. */
5521 register tree origin = decl_class_context (decl);
5522 if (origin)
5523 output_type (origin, containing_scope);
5526 /* If the following DIE will represent a data object definition for a
5527 data object with "extern" linkage, output a special "pubnames" DIE
5528 label just ahead of the actual DIE. A reference to this label
5529 was already generated in the .debug_pubnames section sub-entry
5530 for this data object definition. */
5532 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5534 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5536 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5537 ASM_OUTPUT_LABEL (asm_out_file, label);
5540 /* Now output the DIE to represent the data object itself. This gets
5541 complicated because of the possibility that the VAR_DECL really
5542 represents an inlined instance of a formal parameter for an inline
5543 function. */
5546 register void (*func) PARAMS ((void *));
5547 register tree origin = decl_ultimate_origin (decl);
5549 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5550 func = output_formal_parameter_die;
5551 else
5553 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5554 func = output_global_variable_die;
5555 else
5556 func = output_local_variable_die;
5558 output_die (func, decl);
5560 break;
5562 case FIELD_DECL:
5563 /* Ignore the nameless fields that are used to skip bits. */
5564 if (DECL_NAME (decl) != 0)
5566 output_type (member_declared_type (decl), containing_scope);
5567 output_die (output_member_die, decl);
5569 break;
5571 case PARM_DECL:
5572 /* Force out the type of this formal, if it was not forced out yet.
5573 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5574 It should be able to grok the presence of type DIEs within a list
5575 of TAG_formal_parameter DIEs, but it doesn't. */
5577 output_type (TREE_TYPE (decl), containing_scope);
5578 output_die (output_formal_parameter_die, decl);
5579 break;
5581 case NAMESPACE_DECL:
5582 /* Ignore for now. */
5583 break;
5585 default:
5586 abort ();
5590 void
5591 dwarfout_file_scope_decl (decl, set_finalizing)
5592 register tree decl;
5593 register int set_finalizing;
5595 if (TREE_CODE (decl) == ERROR_MARK)
5596 return;
5598 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5600 if (DECL_IGNORED_P (decl))
5601 return;
5603 switch (TREE_CODE (decl))
5605 case FUNCTION_DECL:
5607 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5608 a builtin function. Explicit programmer-supplied declarations of
5609 these same functions should NOT be ignored however. */
5611 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5612 return;
5614 /* What we would really like to do here is to filter out all mere
5615 file-scope declarations of file-scope functions which are never
5616 referenced later within this translation unit (and keep all of
5617 ones that *are* referenced later on) but we aren't clairvoyant,
5618 so we have no idea which functions will be referenced in the
5619 future (i.e. later on within the current translation unit).
5620 So here we just ignore all file-scope function declarations
5621 which are not also definitions. If and when the debugger needs
5622 to know something about these functions, it wil have to hunt
5623 around and find the DWARF information associated with the
5624 *definition* of the function.
5626 Note that we can't just check `DECL_EXTERNAL' to find out which
5627 FUNCTION_DECL nodes represent definitions and which ones represent
5628 mere declarations. We have to check `DECL_INITIAL' instead. That's
5629 because the C front-end supports some weird semantics for "extern
5630 inline" function definitions. These can get inlined within the
5631 current translation unit (an thus, we need to generate DWARF info
5632 for their abstract instances so that the DWARF info for the
5633 concrete inlined instances can have something to refer to) but
5634 the compiler never generates any out-of-lines instances of such
5635 things (despite the fact that they *are* definitions). The
5636 important point is that the C front-end marks these "extern inline"
5637 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5638 anyway.
5640 Note that the C++ front-end also plays some similar games for inline
5641 function definitions appearing within include files which also
5642 contain `#pragma interface' pragmas. */
5644 if (DECL_INITIAL (decl) == NULL_TREE)
5645 return;
5647 if (TREE_PUBLIC (decl)
5648 && ! DECL_EXTERNAL (decl)
5649 && ! DECL_ABSTRACT (decl))
5651 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5653 /* Output a .debug_pubnames entry for a public function
5654 defined in this compilation unit. */
5656 fputc ('\n', asm_out_file);
5657 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5658 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5659 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5660 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5661 IDENTIFIER_POINTER (DECL_NAME (decl)));
5662 ASM_OUTPUT_POP_SECTION (asm_out_file);
5665 break;
5667 case VAR_DECL:
5669 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5670 object declaration and if the declaration was never even
5671 referenced from within this entire compilation unit. We
5672 suppress these DIEs in order to save space in the .debug section
5673 (by eliminating entries which are probably useless). Note that
5674 we must not suppress block-local extern declarations (whether
5675 used or not) because that would screw-up the debugger's name
5676 lookup mechanism and cause it to miss things which really ought
5677 to be in scope at a given point. */
5679 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5680 return;
5682 if (TREE_PUBLIC (decl)
5683 && ! DECL_EXTERNAL (decl)
5684 && GET_CODE (DECL_RTL (decl)) == MEM
5685 && ! DECL_ABSTRACT (decl))
5687 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5689 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5691 /* Output a .debug_pubnames entry for a public variable
5692 defined in this compilation unit. */
5694 fputc ('\n', asm_out_file);
5695 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5696 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5697 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5698 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5699 IDENTIFIER_POINTER (DECL_NAME (decl)));
5700 ASM_OUTPUT_POP_SECTION (asm_out_file);
5703 if (DECL_INITIAL (decl) == NULL)
5705 /* Output a .debug_aranges entry for a public variable
5706 which is tentatively defined in this compilation unit. */
5708 fputc ('\n', asm_out_file);
5709 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5710 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5711 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5712 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5713 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5714 ASM_OUTPUT_POP_SECTION (asm_out_file);
5718 /* If we are in terse mode, don't generate any DIEs to represent
5719 any variable declarations or definitions. */
5721 if (debug_info_level <= DINFO_LEVEL_TERSE)
5722 return;
5724 break;
5726 case TYPE_DECL:
5727 /* Don't bother trying to generate any DIEs to represent any of the
5728 normal built-in types for the language we are compiling, except
5729 in cases where the types in question are *not* DWARF fundamental
5730 types. We make an exception in the case of non-fundamental types
5731 for the sake of objective C (and perhaps C++) because the GNU
5732 front-ends for these languages may in fact create certain "built-in"
5733 types which are (for example) RECORD_TYPEs. In such cases, we
5734 really need to output these (non-fundamental) types because other
5735 DIEs may contain references to them. */
5737 /* Also ignore language dependent types here, because they are probably
5738 also built-in types. If we didn't ignore them, then we would get
5739 references to undefined labels because output_type doesn't support
5740 them. So, for now, we need to ignore them to avoid assembler
5741 errors. */
5743 /* ??? This code is different than the equivalent code in dwarf2out.c.
5744 The dwarf2out.c code is probably more correct. */
5746 if (DECL_SOURCE_LINE (decl) == 0
5747 && (type_is_fundamental (TREE_TYPE (decl))
5748 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5749 return;
5751 /* If we are in terse mode, don't generate any DIEs to represent
5752 any actual typedefs. Note that even when we are in terse mode,
5753 we must still output DIEs to represent those tagged types which
5754 are used (directly or indirectly) in the specification of either
5755 a return type or a formal parameter type of some function. */
5757 if (debug_info_level <= DINFO_LEVEL_TERSE)
5758 if (! TYPE_DECL_IS_STUB (decl)
5759 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5760 return;
5762 break;
5764 default:
5765 return;
5768 fputc ('\n', asm_out_file);
5769 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5770 finalizing = set_finalizing;
5771 output_decl (decl, NULL_TREE);
5773 /* NOTE: The call above to `output_decl' may have caused one or more
5774 file-scope named types (i.e. tagged types) to be placed onto the
5775 pending_types_list. We have to get those types off of that list
5776 at some point, and this is the perfect time to do it. If we didn't
5777 take them off now, they might still be on the list when cc1 finally
5778 exits. That might be OK if it weren't for the fact that when we put
5779 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5780 for these types, and that causes them never to be output unless
5781 `output_pending_types_for_scope' takes them off of the list and un-sets
5782 their TREE_ASM_WRITTEN flags. */
5784 output_pending_types_for_scope (NULL_TREE);
5786 /* The above call should have totally emptied the pending_types_list
5787 if this is not a nested function or class. If this is a nested type,
5788 then the remaining pending_types will be emitted when the containing type
5789 is handled. */
5791 if (! DECL_CONTEXT (decl))
5793 if (pending_types != 0)
5794 abort ();
5797 ASM_OUTPUT_POP_SECTION (asm_out_file);
5799 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5800 current_funcdef_number++;
5803 /* Output a marker (i.e. a label) for the beginning of the generated code
5804 for a lexical block. */
5806 void
5807 dwarfout_begin_block (blocknum)
5808 register unsigned blocknum;
5810 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5812 function_section (current_function_decl);
5813 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5814 ASM_OUTPUT_LABEL (asm_out_file, label);
5817 /* Output a marker (i.e. a label) for the end of the generated code
5818 for a lexical block. */
5820 void
5821 dwarfout_end_block (blocknum)
5822 register unsigned blocknum;
5824 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5826 function_section (current_function_decl);
5827 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5828 ASM_OUTPUT_LABEL (asm_out_file, label);
5831 /* Output a marker (i.e. a label) for the point in the generated code where
5832 the real body of the function begins (after parameters have been moved
5833 to their home locations). */
5835 void
5836 dwarfout_begin_function ()
5838 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5840 if (! use_gnu_debug_info_extensions)
5841 return;
5842 function_section (current_function_decl);
5843 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5844 ASM_OUTPUT_LABEL (asm_out_file, label);
5847 /* Output a marker (i.e. a label) for the point in the generated code where
5848 the real body of the function ends (just before the epilogue code). */
5850 void
5851 dwarfout_end_function ()
5853 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5855 if (! use_gnu_debug_info_extensions)
5856 return;
5857 function_section (current_function_decl);
5858 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5859 ASM_OUTPUT_LABEL (asm_out_file, label);
5862 /* Output a marker (i.e. a label) for the absolute end of the generated code
5863 for a function definition. This gets called *after* the epilogue code
5864 has been generated. */
5866 void
5867 dwarfout_end_epilogue ()
5869 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5871 /* Output a label to mark the endpoint of the code generated for this
5872 function. */
5874 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5875 ASM_OUTPUT_LABEL (asm_out_file, label);
5878 static void
5879 shuffle_filename_entry (new_zeroth)
5880 register filename_entry *new_zeroth;
5882 filename_entry temp_entry;
5883 register filename_entry *limit_p;
5884 register filename_entry *move_p;
5886 if (new_zeroth == &filename_table[0])
5887 return;
5889 temp_entry = *new_zeroth;
5891 /* Shift entries up in the table to make room at [0]. */
5893 limit_p = &filename_table[0];
5894 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5895 *move_p = *(move_p-1);
5897 /* Install the found entry at [0]. */
5899 filename_table[0] = temp_entry;
5902 /* Create a new (string) entry for the .debug_sfnames section. */
5904 static void
5905 generate_new_sfname_entry ()
5907 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5909 fputc ('\n', asm_out_file);
5910 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5911 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5912 ASM_OUTPUT_LABEL (asm_out_file, label);
5913 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5914 filename_table[0].name
5915 ? filename_table[0].name
5916 : "");
5917 ASM_OUTPUT_POP_SECTION (asm_out_file);
5920 /* Lookup a filename (in the list of filenames that we know about here in
5921 dwarfout.c) and return its "index". The index of each (known) filename
5922 is just a unique number which is associated with only that one filename.
5923 We need such numbers for the sake of generating labels (in the
5924 .debug_sfnames section) and references to those unique labels (in the
5925 .debug_srcinfo and .debug_macinfo sections).
5927 If the filename given as an argument is not found in our current list,
5928 add it to the list and assign it the next available unique index number.
5930 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5931 one), we shuffle the filename found (or added) up to the zeroth entry of
5932 our list of filenames (which is always searched linearly). We do this so
5933 as to optimize the most common case for these filename lookups within
5934 dwarfout.c. The most common case by far is the case where we call
5935 lookup_filename to lookup the very same filename that we did a lookup
5936 on the last time we called lookup_filename. We make sure that this
5937 common case is fast because such cases will constitute 99.9% of the
5938 lookups we ever do (in practice).
5940 If we add a new filename entry to our table, we go ahead and generate
5941 the corresponding entry in the .debug_sfnames section right away.
5942 Doing so allows us to avoid tickling an assembler bug (present in some
5943 m68k assemblers) which yields assembly-time errors in cases where the
5944 difference of two label addresses is taken and where the two labels
5945 are in a section *other* than the one where the difference is being
5946 calculated, and where at least one of the two symbol references is a
5947 forward reference. (This bug could be tickled by our .debug_srcinfo
5948 entries if we don't output their corresponding .debug_sfnames entries
5949 before them.) */
5951 static unsigned
5952 lookup_filename (file_name)
5953 const char *file_name;
5955 register filename_entry *search_p;
5956 register filename_entry *limit_p = &filename_table[ft_entries];
5958 for (search_p = filename_table; search_p < limit_p; search_p++)
5959 if (!strcmp (file_name, search_p->name))
5961 /* When we get here, we have found the filename that we were
5962 looking for in the filename_table. Now we want to make sure
5963 that it gets moved to the zero'th entry in the table (if it
5964 is not already there) so that subsequent attempts to find the
5965 same filename will find it as quickly as possible. */
5967 shuffle_filename_entry (search_p);
5968 return filename_table[0].number;
5971 /* We come here whenever we have a new filename which is not registered
5972 in the current table. Here we add it to the table. */
5974 /* Prepare to add a new table entry by making sure there is enough space
5975 in the table to do so. If not, expand the current table. */
5977 if (ft_entries == ft_entries_allocated)
5979 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5980 filename_table
5981 = (filename_entry *)
5982 xrealloc (filename_table,
5983 ft_entries_allocated * sizeof (filename_entry));
5986 /* Initially, add the new entry at the end of the filename table. */
5988 filename_table[ft_entries].number = ft_entries;
5989 filename_table[ft_entries].name = xstrdup (file_name);
5991 /* Shuffle the new entry into filename_table[0]. */
5993 shuffle_filename_entry (&filename_table[ft_entries]);
5995 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5996 generate_new_sfname_entry ();
5998 ft_entries++;
5999 return filename_table[0].number;
6002 static void
6003 generate_srcinfo_entry (line_entry_num, files_entry_num)
6004 unsigned line_entry_num;
6005 unsigned files_entry_num;
6007 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6009 fputc ('\n', asm_out_file);
6010 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
6011 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
6012 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
6013 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
6014 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
6015 ASM_OUTPUT_POP_SECTION (asm_out_file);
6018 void
6019 dwarfout_line (filename, line)
6020 register const char *filename;
6021 register unsigned line;
6023 if (debug_info_level >= DINFO_LEVEL_NORMAL
6024 /* We can't emit line number info for functions in separate sections,
6025 because the assembler can't subtract labels in different sections. */
6026 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
6028 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6029 static unsigned last_line_entry_num = 0;
6030 static unsigned prev_file_entry_num = (unsigned) -1;
6031 register unsigned this_file_entry_num;
6033 function_section (current_function_decl);
6034 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
6035 ASM_OUTPUT_LABEL (asm_out_file, label);
6037 fputc ('\n', asm_out_file);
6039 if (use_gnu_debug_info_extensions)
6040 this_file_entry_num = lookup_filename (filename);
6041 else
6042 this_file_entry_num = (unsigned) -1;
6044 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6045 if (this_file_entry_num != prev_file_entry_num)
6047 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
6049 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
6050 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
6054 register const char *tail = strrchr (filename, '/');
6056 if (tail != NULL)
6057 filename = tail;
6060 fprintf (asm_out_file, "%s%u\t%s %s:%u\n",
6061 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
6062 filename, line);
6063 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6064 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
6065 ASM_OUTPUT_POP_SECTION (asm_out_file);
6067 if (this_file_entry_num != prev_file_entry_num)
6068 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
6069 prev_file_entry_num = this_file_entry_num;
6073 /* Generate an entry in the .debug_macinfo section. */
6075 static void
6076 generate_macinfo_entry (type_and_offset, string)
6077 register const char *type_and_offset;
6078 register const char *string;
6080 if (! use_gnu_debug_info_extensions)
6081 return;
6083 fputc ('\n', asm_out_file);
6084 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
6085 fprintf (asm_out_file, "%s%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
6086 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
6087 ASM_OUTPUT_POP_SECTION (asm_out_file);
6090 void
6091 dwarfout_start_new_source_file (filename)
6092 register const char *filename;
6094 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6095 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
6097 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
6098 sprintf (type_and_offset, "0x%08x+%s-%s",
6099 ((unsigned) MACINFO_start << 24),
6100 /* Hack: skip leading '*' . */
6101 (*label == '*') + label,
6102 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
6103 generate_macinfo_entry (type_and_offset, "");
6106 void
6107 dwarfout_resume_previous_source_file (lineno)
6108 register unsigned lineno;
6110 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6112 sprintf (type_and_offset, "0x%08x+%u",
6113 ((unsigned) MACINFO_resume << 24), lineno);
6114 generate_macinfo_entry (type_and_offset, "");
6117 /* Called from check_newline in c-parse.y. The `buffer' parameter
6118 contains the tail part of the directive line, i.e. the part which
6119 is past the initial whitespace, #, whitespace, directive-name,
6120 whitespace part. */
6122 void
6123 dwarfout_define (lineno, buffer)
6124 register unsigned lineno;
6125 register const char *buffer;
6127 static int initialized = 0;
6128 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6130 if (!initialized)
6132 dwarfout_start_new_source_file (primary_filename);
6133 initialized = 1;
6135 sprintf (type_and_offset, "0x%08x+%u",
6136 ((unsigned) MACINFO_define << 24), lineno);
6137 generate_macinfo_entry (type_and_offset, buffer);
6140 /* Called from check_newline in c-parse.y. The `buffer' parameter
6141 contains the tail part of the directive line, i.e. the part which
6142 is past the initial whitespace, #, whitespace, directive-name,
6143 whitespace part. */
6145 void
6146 dwarfout_undef (lineno, buffer)
6147 register unsigned lineno;
6148 register const char *buffer;
6150 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6152 sprintf (type_and_offset, "0x%08x+%u",
6153 ((unsigned) MACINFO_undef << 24), lineno);
6154 generate_macinfo_entry (type_and_offset, buffer);
6157 /* Set up for Dwarf output at the start of compilation. */
6159 void
6160 dwarfout_init (asm_out_file, main_input_filename)
6161 register FILE *asm_out_file;
6162 register const char *main_input_filename;
6164 /* Remember the name of the primary input file. */
6166 primary_filename = main_input_filename;
6168 /* Allocate the initial hunk of the pending_sibling_stack. */
6170 pending_sibling_stack
6171 = (unsigned *)
6172 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
6173 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
6174 pending_siblings = 1;
6176 /* Allocate the initial hunk of the filename_table. */
6178 filename_table
6179 = (filename_entry *)
6180 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
6181 ft_entries_allocated = FT_ENTRIES_INCREMENT;
6182 ft_entries = 0;
6184 /* Allocate the initial hunk of the pending_types_list. */
6186 pending_types_list
6187 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
6188 pending_types_allocated = PENDING_TYPES_INCREMENT;
6189 pending_types = 0;
6191 /* Create an artificial RECORD_TYPE node which we can use in our hack
6192 to get the DIEs representing types of formal parameters to come out
6193 only *after* the DIEs for the formal parameters themselves. */
6195 fake_containing_scope = make_node (RECORD_TYPE);
6197 /* Output a starting label for the .text section. */
6199 fputc ('\n', asm_out_file);
6200 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
6201 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
6202 ASM_OUTPUT_POP_SECTION (asm_out_file);
6204 /* Output a starting label for the .data section. */
6206 fputc ('\n', asm_out_file);
6207 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
6208 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
6209 ASM_OUTPUT_POP_SECTION (asm_out_file);
6211 #if 0 /* GNU C doesn't currently use .data1. */
6212 /* Output a starting label for the .data1 section. */
6214 fputc ('\n', asm_out_file);
6215 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
6216 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
6217 ASM_OUTPUT_POP_SECTION (asm_out_file);
6218 #endif
6220 /* Output a starting label for the .rodata section. */
6222 fputc ('\n', asm_out_file);
6223 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
6224 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
6225 ASM_OUTPUT_POP_SECTION (asm_out_file);
6227 #if 0 /* GNU C doesn't currently use .rodata1. */
6228 /* Output a starting label for the .rodata1 section. */
6230 fputc ('\n', asm_out_file);
6231 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
6232 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
6233 ASM_OUTPUT_POP_SECTION (asm_out_file);
6234 #endif
6236 /* Output a starting label for the .bss section. */
6238 fputc ('\n', asm_out_file);
6239 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
6240 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
6241 ASM_OUTPUT_POP_SECTION (asm_out_file);
6243 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6245 if (use_gnu_debug_info_extensions)
6247 /* Output a starting label and an initial (compilation directory)
6248 entry for the .debug_sfnames section. The starting label will be
6249 referenced by the initial entry in the .debug_srcinfo section. */
6251 fputc ('\n', asm_out_file);
6252 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
6253 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
6255 register const char *pwd = getpwd ();
6256 register char *dirname;
6258 if (!pwd)
6259 fatal_io_error ("can't get current directory");
6261 dirname = concat (pwd, "/", NULL);
6262 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
6263 free (dirname);
6265 ASM_OUTPUT_POP_SECTION (asm_out_file);
6268 if (debug_info_level >= DINFO_LEVEL_VERBOSE
6269 && use_gnu_debug_info_extensions)
6271 /* Output a starting label for the .debug_macinfo section. This
6272 label will be referenced by the AT_mac_info attribute in the
6273 TAG_compile_unit DIE. */
6275 fputc ('\n', asm_out_file);
6276 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
6277 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
6278 ASM_OUTPUT_POP_SECTION (asm_out_file);
6281 /* Generate the initial entry for the .line section. */
6283 fputc ('\n', asm_out_file);
6284 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6285 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
6286 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
6287 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6288 ASM_OUTPUT_POP_SECTION (asm_out_file);
6290 if (use_gnu_debug_info_extensions)
6292 /* Generate the initial entry for the .debug_srcinfo section. */
6294 fputc ('\n', asm_out_file);
6295 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
6296 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
6297 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
6298 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
6299 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6300 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
6301 #ifdef DWARF_TIMESTAMPS
6302 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
6303 #else
6304 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6305 #endif
6306 ASM_OUTPUT_POP_SECTION (asm_out_file);
6309 /* Generate the initial entry for the .debug_pubnames section. */
6311 fputc ('\n', asm_out_file);
6312 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
6313 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6314 ASM_OUTPUT_POP_SECTION (asm_out_file);
6316 /* Generate the initial entry for the .debug_aranges section. */
6318 fputc ('\n', asm_out_file);
6319 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
6320 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6321 ASM_OUTPUT_POP_SECTION (asm_out_file);
6324 /* Setup first DIE number == 1. */
6325 NEXT_DIE_NUM = next_unused_dienum++;
6327 /* Generate the initial DIE for the .debug section. Note that the
6328 (string) value given in the AT_name attribute of the TAG_compile_unit
6329 DIE will (typically) be a relative pathname and that this pathname
6330 should be taken as being relative to the directory from which the
6331 compiler was invoked when the given (base) source file was compiled. */
6333 fputc ('\n', asm_out_file);
6334 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6335 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
6336 output_die (output_compile_unit_die, main_input_filename);
6337 ASM_OUTPUT_POP_SECTION (asm_out_file);
6339 fputc ('\n', asm_out_file);
6342 /* Output stuff that dwarf requires at the end of every file. */
6344 void
6345 dwarfout_finish ()
6347 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6349 fputc ('\n', asm_out_file);
6350 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6351 retry_incomplete_types ();
6352 fputc ('\n', asm_out_file);
6354 /* Mark the end of the chain of siblings which represent all file-scope
6355 declarations in this compilation unit. */
6357 /* The (null) DIE which represents the terminator for the (sibling linked)
6358 list of file-scope items is *special*. Normally, we would just call
6359 end_sibling_chain at this point in order to output a word with the
6360 value `4' and that word would act as the terminator for the list of
6361 DIEs describing file-scope items. Unfortunately, if we were to simply
6362 do that, the label that would follow this DIE in the .debug section
6363 (i.e. `..D2') would *not* be properly aligned (as it must be on some
6364 machines) to a 4 byte boundary.
6366 In order to force the label `..D2' to get aligned to a 4 byte boundary,
6367 the trick used is to insert extra (otherwise useless) padding bytes
6368 into the (null) DIE that we know must precede the ..D2 label in the
6369 .debug section. The amount of padding required can be anywhere between
6370 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
6371 with the padding) would normally contain the value 4, but now it will
6372 also have to include the padding bytes, so it will instead have some
6373 value in the range 4..7.
6375 Fortunately, the rules of Dwarf say that any DIE whose length word
6376 contains *any* value less than 8 should be treated as a null DIE, so
6377 this trick works out nicely. Clever, eh? Don't give me any credit
6378 (or blame). I didn't think of this scheme. I just conformed to it.
6381 output_die (output_padded_null_die, (void *) 0);
6382 dienum_pop ();
6384 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
6385 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
6386 ASM_OUTPUT_POP_SECTION (asm_out_file);
6388 /* Output a terminator label for the .text section. */
6390 fputc ('\n', asm_out_file);
6391 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
6392 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
6393 ASM_OUTPUT_POP_SECTION (asm_out_file);
6395 /* Output a terminator label for the .data section. */
6397 fputc ('\n', asm_out_file);
6398 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
6399 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
6400 ASM_OUTPUT_POP_SECTION (asm_out_file);
6402 #if 0 /* GNU C doesn't currently use .data1. */
6403 /* Output a terminator label for the .data1 section. */
6405 fputc ('\n', asm_out_file);
6406 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
6407 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
6408 ASM_OUTPUT_POP_SECTION (asm_out_file);
6409 #endif
6411 /* Output a terminator label for the .rodata section. */
6413 fputc ('\n', asm_out_file);
6414 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
6415 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
6416 ASM_OUTPUT_POP_SECTION (asm_out_file);
6418 #if 0 /* GNU C doesn't currently use .rodata1. */
6419 /* Output a terminator label for the .rodata1 section. */
6421 fputc ('\n', asm_out_file);
6422 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
6423 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
6424 ASM_OUTPUT_POP_SECTION (asm_out_file);
6425 #endif
6427 /* Output a terminator label for the .bss section. */
6429 fputc ('\n', asm_out_file);
6430 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
6431 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
6432 ASM_OUTPUT_POP_SECTION (asm_out_file);
6434 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6436 /* Output a terminating entry for the .line section. */
6438 fputc ('\n', asm_out_file);
6439 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6440 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
6441 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6442 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6443 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6444 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
6445 ASM_OUTPUT_POP_SECTION (asm_out_file);
6447 if (use_gnu_debug_info_extensions)
6449 /* Output a terminating entry for the .debug_srcinfo section. */
6451 fputc ('\n', asm_out_file);
6452 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
6453 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6454 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6455 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6456 ASM_OUTPUT_POP_SECTION (asm_out_file);
6459 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6461 /* Output terminating entries for the .debug_macinfo section. */
6463 dwarfout_resume_previous_source_file (0);
6465 fputc ('\n', asm_out_file);
6466 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
6467 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6468 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6469 ASM_OUTPUT_POP_SECTION (asm_out_file);
6472 /* Generate the terminating entry for the .debug_pubnames section. */
6474 fputc ('\n', asm_out_file);
6475 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
6476 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6477 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6478 ASM_OUTPUT_POP_SECTION (asm_out_file);
6480 /* Generate the terminating entries for the .debug_aranges section.
6482 Note that we want to do this only *after* we have output the end
6483 labels (for the various program sections) which we are going to
6484 refer to here. This allows us to work around a bug in the m68k
6485 svr4 assembler. That assembler gives bogus assembly-time errors
6486 if (within any given section) you try to take the difference of
6487 two relocatable symbols, both of which are located within some
6488 other section, and if one (or both?) of the symbols involved is
6489 being forward-referenced. By generating the .debug_aranges
6490 entries at this late point in the assembly output, we skirt the
6491 issue simply by avoiding forward-references.
6494 fputc ('\n', asm_out_file);
6495 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
6497 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6498 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6500 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6501 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6503 #if 0 /* GNU C doesn't currently use .data1. */
6504 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6505 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6506 DATA1_BEGIN_LABEL);
6507 #endif
6509 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6510 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6511 RODATA_BEGIN_LABEL);
6513 #if 0 /* GNU C doesn't currently use .rodata1. */
6514 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6515 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6516 RODATA1_BEGIN_LABEL);
6517 #endif
6519 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6520 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6522 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6523 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6525 ASM_OUTPUT_POP_SECTION (asm_out_file);
6528 /* There should not be any pending types left at the end. We need
6529 this now because it may not have been checked on the last call to
6530 dwarfout_file_scope_decl. */
6531 if (pending_types != 0)
6532 abort ();
6535 #endif /* DWARF_DEBUGGING_INFO */