Append a DIR_SEPARATOR to a path specified by the -B switch, if doing so would
[official-gcc.git] / gcc / dwarfout.c
blob6c21cbf618e70025491768a0a1b276a6914a62f7
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 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
582 regarding the GNU implementation of Dwarf. */
584 /* NOTE: In the comments in this file, many references are made to
585 so called "Debugging Information Entries". For the sake of brevity,
586 this term is abbreviated to `DIE' throughout the remainder of this
587 file. */
589 /* Note that the implementation of C++ support herein is (as yet) unfinished.
590 If you want to try to complete it, more power to you. */
592 /* How to start an assembler comment. */
593 #ifndef ASM_COMMENT_START
594 #define ASM_COMMENT_START ";#"
595 #endif
597 /* How to print out a register name. */
598 #ifndef PRINT_REG
599 #define PRINT_REG(RTX, CODE, FILE) \
600 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
601 #endif
603 /* Define a macro which returns non-zero for any tagged type which is
604 used (directly or indirectly) in the specification of either some
605 function's return type or some formal parameter of some function.
606 We use this macro when we are operating in "terse" mode to help us
607 know what tagged types have to be represented in Dwarf (even in
608 terse mode) and which ones don't.
610 A flag bit with this meaning really should be a part of the normal
611 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
612 for these nodes. For now, we have to just fake it. It it safe for
613 us to simply return zero for all complete tagged types (which will
614 get forced out anyway if they were used in the specification of some
615 formal or return type) and non-zero for all incomplete tagged types.
618 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
620 /* Define a macro which returns non-zero for a TYPE_DECL which was
621 implicitly generated for a tagged type.
623 Note that unlike the gcc front end (which generates a NULL named
624 TYPE_DECL node for each complete tagged type, each array type, and
625 each function type node created) the g++ front end generates a
626 _named_ TYPE_DECL node for each tagged type node created.
627 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
628 generate a DW_TAG_typedef DIE for them. */
629 #define TYPE_DECL_IS_STUB(decl) \
630 (DECL_NAME (decl) == NULL \
631 || (DECL_ARTIFICIAL (decl) \
632 && is_tagged_type (TREE_TYPE (decl)) \
633 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
635 extern int flag_traditional;
637 /* Maximum size (in bytes) of an artificially generated label. */
639 #define MAX_ARTIFICIAL_LABEL_BYTES 30
641 /* Structure to keep track of source filenames. */
643 struct filename_entry {
644 unsigned number;
645 const char * name;
648 typedef struct filename_entry filename_entry;
650 /* Pointer to an array of elements, each one having the structure above. */
652 static filename_entry *filename_table;
654 /* Total number of entries in the table (i.e. array) pointed to by
655 `filename_table'. This is the *total* and includes both used and
656 unused slots. */
658 static unsigned ft_entries_allocated;
660 /* Number of entries in the filename_table which are actually in use. */
662 static unsigned ft_entries;
664 /* Size (in elements) of increments by which we may expand the filename
665 table. Actually, a single hunk of space of this size should be enough
666 for most typical programs. */
668 #define FT_ENTRIES_INCREMENT 64
670 /* Local pointer to the name of the main input file. Initialized in
671 dwarfout_init. */
673 static const char *primary_filename;
675 /* Pointer to the most recent filename for which we produced some line info. */
677 static const char *last_filename;
679 /* Counter to generate unique names for DIEs. */
681 static unsigned next_unused_dienum = 1;
683 /* Number of the DIE which is currently being generated. */
685 static unsigned current_dienum;
687 /* Number to use for the special "pubname" label on the next DIE which
688 represents a function or data object defined in this compilation
689 unit which has "extern" linkage. */
691 static int next_pubname_number = 0;
693 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
695 /* Pointer to a dynamically allocated list of pre-reserved and still
696 pending sibling DIE numbers. Note that this list will grow as needed. */
698 static unsigned *pending_sibling_stack;
700 /* Counter to keep track of the number of pre-reserved and still pending
701 sibling DIE numbers. */
703 static unsigned pending_siblings;
705 /* The currently allocated size of the above list (expressed in number of
706 list elements). */
708 static unsigned pending_siblings_allocated;
710 /* Size (in elements) of increments by which we may expand the pending
711 sibling stack. Actually, a single hunk of space of this size should
712 be enough for most typical programs. */
714 #define PENDING_SIBLINGS_INCREMENT 64
716 /* Non-zero if we are performing our file-scope finalization pass and if
717 we should force out Dwarf descriptions of any and all file-scope
718 tagged types which are still incomplete types. */
720 static int finalizing = 0;
722 /* A pointer to the base of a list of pending types which we haven't
723 generated DIEs for yet, but which we will have to come back to
724 later on. */
726 static tree *pending_types_list;
728 /* Number of elements currently allocated for the pending_types_list. */
730 static unsigned pending_types_allocated;
732 /* Number of elements of pending_types_list currently in use. */
734 static unsigned pending_types;
736 /* Size (in elements) of increments by which we may expand the pending
737 types list. Actually, a single hunk of space of this size should
738 be enough for most typical programs. */
740 #define PENDING_TYPES_INCREMENT 64
742 /* A pointer to the base of a list of incomplete types which might be
743 completed at some later time. */
745 static tree *incomplete_types_list;
747 /* Number of elements currently allocated for the incomplete_types_list. */
748 static unsigned incomplete_types_allocated;
750 /* Number of elements of incomplete_types_list currently in use. */
751 static unsigned incomplete_types;
753 /* Size (in elements) of increments by which we may expand the incomplete
754 types list. Actually, a single hunk of space of this size should
755 be enough for most typical programs. */
756 #define INCOMPLETE_TYPES_INCREMENT 64
758 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
759 This is used in a hack to help us get the DIEs describing types of
760 formal parameters to come *after* all of the DIEs describing the formal
761 parameters themselves. That's necessary in order to be compatible
762 with what the brain-damaged svr4 SDB debugger requires. */
764 static tree fake_containing_scope;
766 /* The number of the current function definition that we are generating
767 debugging information for. These numbers range from 1 up to the maximum
768 number of function definitions contained within the current compilation
769 unit. These numbers are used to create unique labels for various things
770 contained within various function definitions. */
772 static unsigned current_funcdef_number = 1;
774 /* A pointer to the ..._DECL node which we have most recently been working
775 on. We keep this around just in case something about it looks screwy
776 and we want to tell the user what the source coordinates for the actual
777 declaration are. */
779 static tree dwarf_last_decl;
781 /* A flag indicating that we are emitting the member declarations of a
782 class, so member functions and variables should not be entirely emitted.
783 This is a kludge to avoid passing a second argument to output_*_die. */
785 static int in_class;
787 /* Forward declarations for functions defined in this file. */
789 static const char *dwarf_tag_name PARAMS ((unsigned));
790 static const char *dwarf_attr_name PARAMS ((unsigned));
791 static const char *dwarf_stack_op_name PARAMS ((unsigned));
792 static const char *dwarf_typemod_name PARAMS ((unsigned));
793 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
794 static const char *dwarf_fund_type_name PARAMS ((unsigned));
795 static tree decl_ultimate_origin PARAMS ((tree));
796 static tree block_ultimate_origin PARAMS ((tree));
797 static tree decl_class_context PARAMS ((tree));
798 #if 0
799 static void output_unsigned_leb128 PARAMS ((unsigned long));
800 static void output_signed_leb128 PARAMS ((long));
801 #endif
802 static int fundamental_type_code PARAMS ((tree));
803 static tree root_type_1 PARAMS ((tree, int));
804 static tree root_type PARAMS ((tree));
805 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
806 static void write_modifier_bytes PARAMS ((tree, int, int));
807 static inline int type_is_fundamental PARAMS ((tree));
808 static void equate_decl_number_to_die_number PARAMS ((tree));
809 static inline void equate_type_number_to_die_number PARAMS ((tree));
810 static void output_reg_number PARAMS ((rtx));
811 static void output_mem_loc_descriptor PARAMS ((rtx));
812 static void output_loc_descriptor PARAMS ((rtx));
813 static void output_bound_representation PARAMS ((tree, unsigned, int));
814 static void output_enumeral_list PARAMS ((tree));
815 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
816 static inline tree field_type PARAMS ((tree));
817 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
818 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
819 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
820 static inline void sibling_attribute PARAMS ((void));
821 static void location_attribute PARAMS ((rtx));
822 static void data_member_location_attribute PARAMS ((tree));
823 static void const_value_attribute PARAMS ((rtx));
824 static void location_or_const_value_attribute PARAMS ((tree));
825 static inline void name_attribute PARAMS ((const char *));
826 static inline void fund_type_attribute PARAMS ((unsigned));
827 static void mod_fund_type_attribute PARAMS ((tree, int, int));
828 static inline void user_def_type_attribute PARAMS ((tree));
829 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
830 #ifdef USE_ORDERING_ATTRIBUTE
831 static inline void ordering_attribute PARAMS ((unsigned));
832 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
833 static void subscript_data_attribute PARAMS ((tree));
834 static void byte_size_attribute PARAMS ((tree));
835 static inline void bit_offset_attribute PARAMS ((tree));
836 static inline void bit_size_attribute PARAMS ((tree));
837 static inline void element_list_attribute PARAMS ((tree));
838 static inline void stmt_list_attribute PARAMS ((const char *));
839 static inline void low_pc_attribute PARAMS ((const char *));
840 static inline void high_pc_attribute PARAMS ((const char *));
841 static inline void body_begin_attribute PARAMS ((const char *));
842 static inline void body_end_attribute PARAMS ((const char *));
843 static inline void language_attribute PARAMS ((unsigned));
844 static inline void member_attribute PARAMS ((tree));
845 #if 0
846 static inline void string_length_attribute PARAMS ((tree));
847 #endif
848 static inline void comp_dir_attribute PARAMS ((const char *));
849 static inline void sf_names_attribute PARAMS ((const char *));
850 static inline void src_info_attribute PARAMS ((const char *));
851 static inline void mac_info_attribute PARAMS ((const char *));
852 static inline void prototyped_attribute PARAMS ((tree));
853 static inline void producer_attribute PARAMS ((const char *));
854 static inline void inline_attribute PARAMS ((tree));
855 static inline void containing_type_attribute PARAMS ((tree));
856 static inline void abstract_origin_attribute PARAMS ((tree));
857 #ifdef DWARF_DECL_COORDINATES
858 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
859 #endif /* defined(DWARF_DECL_COORDINATES) */
860 static inline void pure_or_virtual_attribute PARAMS ((tree));
861 static void name_and_src_coords_attributes PARAMS ((tree));
862 static void type_attribute PARAMS ((tree, int, int));
863 static const char *type_tag PARAMS ((tree));
864 static inline void dienum_push PARAMS ((void));
865 static inline void dienum_pop PARAMS ((void));
866 static inline tree member_declared_type PARAMS ((tree));
867 static const char *function_start_label PARAMS ((tree));
868 static void output_array_type_die PARAMS ((void *));
869 static void output_set_type_die PARAMS ((void *));
870 #if 0
871 static void output_entry_point_die PARAMS ((void *));
872 #endif
873 static void output_inlined_enumeration_type_die PARAMS ((void *));
874 static void output_inlined_structure_type_die PARAMS ((void *));
875 static void output_inlined_union_type_die PARAMS ((void *));
876 static void output_enumeration_type_die PARAMS ((void *));
877 static void output_formal_parameter_die PARAMS ((void *));
878 static void output_global_subroutine_die PARAMS ((void *));
879 static void output_global_variable_die PARAMS ((void *));
880 static void output_label_die PARAMS ((void *));
881 static void output_lexical_block_die PARAMS ((void *));
882 static void output_inlined_subroutine_die PARAMS ((void *));
883 static void output_local_variable_die PARAMS ((void *));
884 static void output_member_die PARAMS ((void *));
885 #if 0
886 static void output_pointer_type_die PARAMS ((void *));
887 static void output_reference_type_die PARAMS ((void *));
888 #endif
889 static void output_ptr_to_mbr_type_die PARAMS ((void *));
890 static void output_compile_unit_die PARAMS ((void *));
891 static void output_string_type_die PARAMS ((void *));
892 static void output_inheritance_die PARAMS ((void *));
893 static void output_structure_type_die PARAMS ((void *));
894 static void output_local_subroutine_die PARAMS ((void *));
895 static void output_subroutine_type_die PARAMS ((void *));
896 static void output_typedef_die PARAMS ((void *));
897 static void output_union_type_die PARAMS ((void *));
898 static void output_unspecified_parameters_die PARAMS ((void *));
899 static void output_padded_null_die PARAMS ((void *));
900 static void output_die PARAMS ((void (*)(void *), void *));
901 static void end_sibling_chain PARAMS ((void));
902 static void output_formal_types PARAMS ((tree));
903 static void pend_type PARAMS ((tree));
904 static int type_ok_for_scope PARAMS ((tree, tree));
905 static void output_pending_types_for_scope PARAMS ((tree));
906 static void output_type PARAMS ((tree, tree));
907 static void output_tagged_type_instantiation PARAMS ((tree));
908 static void output_block PARAMS ((tree, int));
909 static void output_decls_for_scope PARAMS ((tree, int));
910 static void output_decl PARAMS ((tree, tree));
911 static void shuffle_filename_entry PARAMS ((filename_entry *));
912 static void generate_new_sfname_entry PARAMS ((void));
913 static unsigned lookup_filename PARAMS ((const char *));
914 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
915 static void generate_macinfo_entry PARAMS ((const char *, const char *));
916 static int is_pseudo_reg PARAMS ((rtx));
917 static tree type_main_variant PARAMS ((tree));
918 static int is_tagged_type PARAMS ((tree));
919 static int is_redundant_typedef PARAMS ((tree));
920 static void add_incomplete_type PARAMS ((tree));
921 static void retry_incomplete_types PARAMS ((void));
923 /* Definitions of defaults for assembler-dependent names of various
924 pseudo-ops and section names.
926 Theses may be overridden in your tm.h file (if necessary) for your
927 particular assembler. The default values provided here correspond to
928 what is expected by "standard" AT&T System V.4 assemblers. */
930 #ifndef FILE_ASM_OP
931 #define FILE_ASM_OP "\t.file\t"
932 #endif
933 #ifndef VERSION_ASM_OP
934 #define VERSION_ASM_OP "\t.version\t"
935 #endif
936 #ifndef UNALIGNED_SHORT_ASM_OP
937 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
938 #endif
939 #ifndef UNALIGNED_INT_ASM_OP
940 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
941 #endif
942 #ifndef ASM_BYTE_OP
943 #define ASM_BYTE_OP "\t.byte\t"
944 #endif
945 #ifndef SET_ASM_OP
946 #define SET_ASM_OP "\t.set\t"
947 #endif
949 /* Pseudo-ops for pushing the current section onto the section stack (and
950 simultaneously changing to a new section) and for poping back to the
951 section we were in immediately before this one. Note that most svr4
952 assemblers only maintain a one level stack... you can push all the
953 sections you want, but you can only pop out one level. (The sparc
954 svr4 assembler is an exception to this general rule.) That's
955 OK because we only use at most one level of the section stack herein. */
957 #ifndef PUSHSECTION_ASM_OP
958 #define PUSHSECTION_ASM_OP "\t.section\t"
959 #endif
960 #ifndef POPSECTION_ASM_OP
961 #define POPSECTION_ASM_OP "\t.previous"
962 #endif
964 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
965 to print the PUSHSECTION_ASM_OP and the section name. The default here
966 works for almost all svr4 assemblers, except for the sparc, where the
967 section name must be enclosed in double quotes. (See sparcv4.h.) */
969 #ifndef PUSHSECTION_FORMAT
970 #define PUSHSECTION_FORMAT "%s%s\n"
971 #endif
973 #ifndef DEBUG_SECTION
974 #define DEBUG_SECTION ".debug"
975 #endif
976 #ifndef LINE_SECTION
977 #define LINE_SECTION ".line"
978 #endif
979 #ifndef DEBUG_SFNAMES_SECTION
980 #define DEBUG_SFNAMES_SECTION ".debug_sfnames"
981 #endif
982 #ifndef DEBUG_SRCINFO_SECTION
983 #define DEBUG_SRCINFO_SECTION ".debug_srcinfo"
984 #endif
985 #ifndef DEBUG_MACINFO_SECTION
986 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
987 #endif
988 #ifndef DEBUG_PUBNAMES_SECTION
989 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
990 #endif
991 #ifndef DEBUG_ARANGES_SECTION
992 #define DEBUG_ARANGES_SECTION ".debug_aranges"
993 #endif
994 #ifndef TEXT_SECTION
995 #define TEXT_SECTION ".text"
996 #endif
997 #ifndef DATA_SECTION
998 #define DATA_SECTION ".data"
999 #endif
1000 #ifndef DATA1_SECTION
1001 #define DATA1_SECTION ".data1"
1002 #endif
1003 #ifndef RODATA_SECTION
1004 #define RODATA_SECTION ".rodata"
1005 #endif
1006 #ifndef RODATA1_SECTION
1007 #define RODATA1_SECTION ".rodata1"
1008 #endif
1009 #ifndef BSS_SECTION
1010 #define BSS_SECTION ".bss"
1011 #endif
1013 /* Definitions of defaults for formats and names of various special
1014 (artificial) labels which may be generated within this file (when
1015 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
1017 If necessary, these may be overridden from within your tm.h file,
1018 but typically, you should never need to override these.
1020 These labels have been hacked (temporarily) so that they all begin with
1021 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
1022 stock m88k/svr4 assembler, both of which need to see .L at the start of
1023 a label in order to prevent that label from going into the linker symbol
1024 table). When I get time, I'll have to fix this the right way so that we
1025 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
1026 but that will require a rather massive set of changes. For the moment,
1027 the following definitions out to produce the right results for all svr4
1028 and svr3 assemblers. -- rfg
1031 #ifndef TEXT_BEGIN_LABEL
1032 #define TEXT_BEGIN_LABEL "*.L_text_b"
1033 #endif
1034 #ifndef TEXT_END_LABEL
1035 #define TEXT_END_LABEL "*.L_text_e"
1036 #endif
1038 #ifndef DATA_BEGIN_LABEL
1039 #define DATA_BEGIN_LABEL "*.L_data_b"
1040 #endif
1041 #ifndef DATA_END_LABEL
1042 #define DATA_END_LABEL "*.L_data_e"
1043 #endif
1045 #ifndef DATA1_BEGIN_LABEL
1046 #define DATA1_BEGIN_LABEL "*.L_data1_b"
1047 #endif
1048 #ifndef DATA1_END_LABEL
1049 #define DATA1_END_LABEL "*.L_data1_e"
1050 #endif
1052 #ifndef RODATA_BEGIN_LABEL
1053 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
1054 #endif
1055 #ifndef RODATA_END_LABEL
1056 #define RODATA_END_LABEL "*.L_rodata_e"
1057 #endif
1059 #ifndef RODATA1_BEGIN_LABEL
1060 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
1061 #endif
1062 #ifndef RODATA1_END_LABEL
1063 #define RODATA1_END_LABEL "*.L_rodata1_e"
1064 #endif
1066 #ifndef BSS_BEGIN_LABEL
1067 #define BSS_BEGIN_LABEL "*.L_bss_b"
1068 #endif
1069 #ifndef BSS_END_LABEL
1070 #define BSS_END_LABEL "*.L_bss_e"
1071 #endif
1073 #ifndef LINE_BEGIN_LABEL
1074 #define LINE_BEGIN_LABEL "*.L_line_b"
1075 #endif
1076 #ifndef LINE_LAST_ENTRY_LABEL
1077 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
1078 #endif
1079 #ifndef LINE_END_LABEL
1080 #define LINE_END_LABEL "*.L_line_e"
1081 #endif
1083 #ifndef DEBUG_BEGIN_LABEL
1084 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
1085 #endif
1086 #ifndef SFNAMES_BEGIN_LABEL
1087 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
1088 #endif
1089 #ifndef SRCINFO_BEGIN_LABEL
1090 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
1091 #endif
1092 #ifndef MACINFO_BEGIN_LABEL
1093 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
1094 #endif
1096 #ifndef DEBUG_ARANGES_BEGIN_LABEL
1097 #define DEBUG_ARANGES_BEGIN_LABEL "*.L_debug_aranges_begin"
1098 #endif
1099 #ifndef DEBUG_ARANGES_END_LABEL
1100 #define DEBUG_ARANGES_END_LABEL "*.L_debug_aranges_end"
1101 #endif
1103 #ifndef DIE_BEGIN_LABEL_FMT
1104 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
1105 #endif
1106 #ifndef DIE_END_LABEL_FMT
1107 #define DIE_END_LABEL_FMT "*.L_D%u_e"
1108 #endif
1109 #ifndef PUB_DIE_LABEL_FMT
1110 #define PUB_DIE_LABEL_FMT "*.L_P%u"
1111 #endif
1112 #ifndef BLOCK_BEGIN_LABEL_FMT
1113 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
1114 #endif
1115 #ifndef BLOCK_END_LABEL_FMT
1116 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
1117 #endif
1118 #ifndef SS_BEGIN_LABEL_FMT
1119 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
1120 #endif
1121 #ifndef SS_END_LABEL_FMT
1122 #define SS_END_LABEL_FMT "*.L_s%u_e"
1123 #endif
1124 #ifndef EE_BEGIN_LABEL_FMT
1125 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
1126 #endif
1127 #ifndef EE_END_LABEL_FMT
1128 #define EE_END_LABEL_FMT "*.L_e%u_e"
1129 #endif
1130 #ifndef MT_BEGIN_LABEL_FMT
1131 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
1132 #endif
1133 #ifndef MT_END_LABEL_FMT
1134 #define MT_END_LABEL_FMT "*.L_t%u_e"
1135 #endif
1136 #ifndef LOC_BEGIN_LABEL_FMT
1137 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
1138 #endif
1139 #ifndef LOC_END_LABEL_FMT
1140 #define LOC_END_LABEL_FMT "*.L_l%u_e"
1141 #endif
1142 #ifndef BOUND_BEGIN_LABEL_FMT
1143 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
1144 #endif
1145 #ifndef BOUND_END_LABEL_FMT
1146 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
1147 #endif
1148 #ifndef DERIV_BEGIN_LABEL_FMT
1149 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
1150 #endif
1151 #ifndef DERIV_END_LABEL_FMT
1152 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
1153 #endif
1154 #ifndef SL_BEGIN_LABEL_FMT
1155 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
1156 #endif
1157 #ifndef SL_END_LABEL_FMT
1158 #define SL_END_LABEL_FMT "*.L_sl%u_e"
1159 #endif
1160 #ifndef BODY_BEGIN_LABEL_FMT
1161 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
1162 #endif
1163 #ifndef BODY_END_LABEL_FMT
1164 #define BODY_END_LABEL_FMT "*.L_b%u_e"
1165 #endif
1166 #ifndef FUNC_END_LABEL_FMT
1167 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
1168 #endif
1169 #ifndef TYPE_NAME_FMT
1170 #define TYPE_NAME_FMT "*.L_T%u"
1171 #endif
1172 #ifndef DECL_NAME_FMT
1173 #define DECL_NAME_FMT "*.L_E%u"
1174 #endif
1175 #ifndef LINE_CODE_LABEL_FMT
1176 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
1177 #endif
1178 #ifndef SFNAMES_ENTRY_LABEL_FMT
1179 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
1180 #endif
1181 #ifndef LINE_ENTRY_LABEL_FMT
1182 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
1183 #endif
1185 /* Definitions of defaults for various types of primitive assembly language
1186 output operations.
1188 If necessary, these may be overridden from within your tm.h file,
1189 but typically, you shouldn't need to override these. */
1191 #ifndef ASM_OUTPUT_PUSH_SECTION
1192 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
1193 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
1194 #endif
1196 #ifndef ASM_OUTPUT_POP_SECTION
1197 #define ASM_OUTPUT_POP_SECTION(FILE) \
1198 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
1199 #endif
1201 #ifndef ASM_OUTPUT_DWARF_DELTA2
1202 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
1203 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_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_DELTA4
1212 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
1213 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1214 assemble_name (FILE, LABEL1); \
1215 fprintf (FILE, "-"); \
1216 assemble_name (FILE, LABEL2); \
1217 fprintf (FILE, "\n"); \
1218 } while (0)
1219 #endif
1221 #ifndef ASM_OUTPUT_DWARF_TAG
1222 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
1223 do { \
1224 fprintf ((FILE), "%s0x%x", \
1225 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
1226 if (flag_debug_asm) \
1227 fprintf ((FILE), "\t%s %s", \
1228 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
1229 fputc ('\n', (FILE)); \
1230 } while (0)
1231 #endif
1233 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
1234 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
1235 do { \
1236 fprintf ((FILE), "%s0x%x", \
1237 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
1238 if (flag_debug_asm) \
1239 fprintf ((FILE), "\t%s %s", \
1240 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
1241 fputc ('\n', (FILE)); \
1242 } while (0)
1243 #endif
1245 #ifndef ASM_OUTPUT_DWARF_STACK_OP
1246 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
1247 do { \
1248 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) OP); \
1249 if (flag_debug_asm) \
1250 fprintf ((FILE), "\t%s %s", \
1251 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
1252 fputc ('\n', (FILE)); \
1253 } while (0)
1254 #endif
1256 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
1257 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
1258 do { \
1259 fprintf ((FILE), "%s0x%x", \
1260 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
1261 if (flag_debug_asm) \
1262 fprintf ((FILE), "\t%s %s", \
1263 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
1264 fputc ('\n', (FILE)); \
1265 } while (0)
1266 #endif
1268 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
1269 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
1270 do { \
1271 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) FMT); \
1272 if (flag_debug_asm) \
1273 fprintf ((FILE), "\t%s %s", \
1274 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
1275 fputc ('\n', (FILE)); \
1276 } while (0)
1277 #endif
1279 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
1280 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
1281 do { \
1282 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) MOD); \
1283 if (flag_debug_asm) \
1284 fprintf ((FILE), "\t%s %s", \
1285 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
1286 fputc ('\n', (FILE)); \
1287 } while (0)
1288 #endif
1290 #ifndef ASM_OUTPUT_DWARF_ADDR
1291 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
1292 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1293 assemble_name (FILE, LABEL); \
1294 fprintf (FILE, "\n"); \
1295 } while (0)
1296 #endif
1298 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
1299 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
1300 do { \
1301 fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1302 output_addr_const ((FILE), (RTX)); \
1303 fputc ('\n', (FILE)); \
1304 } while (0)
1305 #endif
1307 #ifndef ASM_OUTPUT_DWARF_REF
1308 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
1309 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1310 assemble_name (FILE, LABEL); \
1311 fprintf (FILE, "\n"); \
1312 } while (0)
1313 #endif
1315 #ifndef ASM_OUTPUT_DWARF_DATA1
1316 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
1317 fprintf ((FILE), "%s0x%x\n", ASM_BYTE_OP, VALUE)
1318 #endif
1320 #ifndef ASM_OUTPUT_DWARF_DATA2
1321 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
1322 fprintf ((FILE), "%s0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
1323 #endif
1325 #ifndef ASM_OUTPUT_DWARF_DATA4
1326 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
1327 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
1328 #endif
1330 #ifndef ASM_OUTPUT_DWARF_DATA8
1331 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
1332 do { \
1333 if (WORDS_BIG_ENDIAN) \
1335 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1336 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1338 else \
1340 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1341 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1343 } while (0)
1344 #endif
1346 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
1347 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
1348 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
1349 defined, we call it, then issue the line feed. If not, we supply a
1350 default defintion of calling ASM_OUTPUT_ASCII */
1352 #ifndef ASM_OUTPUT_DWARF_STRING
1353 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1354 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
1355 #else
1356 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1357 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
1358 #endif
1361 /************************ general utility functions **************************/
1363 static inline int
1364 is_pseudo_reg (rtl)
1365 register rtx rtl;
1367 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1368 || ((GET_CODE (rtl) == SUBREG)
1369 && (REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)));
1372 static inline tree
1373 type_main_variant (type)
1374 register tree type;
1376 type = TYPE_MAIN_VARIANT (type);
1378 /* There really should be only one main variant among any group of variants
1379 of a given type (and all of the MAIN_VARIANT values for all members of
1380 the group should point to that one type) but sometimes the C front-end
1381 messes this up for array types, so we work around that bug here. */
1383 if (TREE_CODE (type) == ARRAY_TYPE)
1385 while (type != TYPE_MAIN_VARIANT (type))
1386 type = TYPE_MAIN_VARIANT (type);
1389 return type;
1392 /* Return non-zero if the given type node represents a tagged type. */
1394 static inline int
1395 is_tagged_type (type)
1396 register tree type;
1398 register enum tree_code code = TREE_CODE (type);
1400 return (code == RECORD_TYPE || code == UNION_TYPE
1401 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1404 static const char *
1405 dwarf_tag_name (tag)
1406 register unsigned tag;
1408 switch (tag)
1410 case TAG_padding: return "TAG_padding";
1411 case TAG_array_type: return "TAG_array_type";
1412 case TAG_class_type: return "TAG_class_type";
1413 case TAG_entry_point: return "TAG_entry_point";
1414 case TAG_enumeration_type: return "TAG_enumeration_type";
1415 case TAG_formal_parameter: return "TAG_formal_parameter";
1416 case TAG_global_subroutine: return "TAG_global_subroutine";
1417 case TAG_global_variable: return "TAG_global_variable";
1418 case TAG_label: return "TAG_label";
1419 case TAG_lexical_block: return "TAG_lexical_block";
1420 case TAG_local_variable: return "TAG_local_variable";
1421 case TAG_member: return "TAG_member";
1422 case TAG_pointer_type: return "TAG_pointer_type";
1423 case TAG_reference_type: return "TAG_reference_type";
1424 case TAG_compile_unit: return "TAG_compile_unit";
1425 case TAG_string_type: return "TAG_string_type";
1426 case TAG_structure_type: return "TAG_structure_type";
1427 case TAG_subroutine: return "TAG_subroutine";
1428 case TAG_subroutine_type: return "TAG_subroutine_type";
1429 case TAG_typedef: return "TAG_typedef";
1430 case TAG_union_type: return "TAG_union_type";
1431 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
1432 case TAG_variant: return "TAG_variant";
1433 case TAG_common_block: return "TAG_common_block";
1434 case TAG_common_inclusion: return "TAG_common_inclusion";
1435 case TAG_inheritance: return "TAG_inheritance";
1436 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
1437 case TAG_module: return "TAG_module";
1438 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
1439 case TAG_set_type: return "TAG_set_type";
1440 case TAG_subrange_type: return "TAG_subrange_type";
1441 case TAG_with_stmt: return "TAG_with_stmt";
1443 /* GNU extensions. */
1445 case TAG_format_label: return "TAG_format_label";
1446 case TAG_namelist: return "TAG_namelist";
1447 case TAG_function_template: return "TAG_function_template";
1448 case TAG_class_template: return "TAG_class_template";
1450 default: return "TAG_<unknown>";
1454 static const char *
1455 dwarf_attr_name (attr)
1456 register unsigned attr;
1458 switch (attr)
1460 case AT_sibling: return "AT_sibling";
1461 case AT_location: return "AT_location";
1462 case AT_name: return "AT_name";
1463 case AT_fund_type: return "AT_fund_type";
1464 case AT_mod_fund_type: return "AT_mod_fund_type";
1465 case AT_user_def_type: return "AT_user_def_type";
1466 case AT_mod_u_d_type: return "AT_mod_u_d_type";
1467 case AT_ordering: return "AT_ordering";
1468 case AT_subscr_data: return "AT_subscr_data";
1469 case AT_byte_size: return "AT_byte_size";
1470 case AT_bit_offset: return "AT_bit_offset";
1471 case AT_bit_size: return "AT_bit_size";
1472 case AT_element_list: return "AT_element_list";
1473 case AT_stmt_list: return "AT_stmt_list";
1474 case AT_low_pc: return "AT_low_pc";
1475 case AT_high_pc: return "AT_high_pc";
1476 case AT_language: return "AT_language";
1477 case AT_member: return "AT_member";
1478 case AT_discr: return "AT_discr";
1479 case AT_discr_value: return "AT_discr_value";
1480 case AT_string_length: return "AT_string_length";
1481 case AT_common_reference: return "AT_common_reference";
1482 case AT_comp_dir: return "AT_comp_dir";
1483 case AT_const_value_string: return "AT_const_value_string";
1484 case AT_const_value_data2: return "AT_const_value_data2";
1485 case AT_const_value_data4: return "AT_const_value_data4";
1486 case AT_const_value_data8: return "AT_const_value_data8";
1487 case AT_const_value_block2: return "AT_const_value_block2";
1488 case AT_const_value_block4: return "AT_const_value_block4";
1489 case AT_containing_type: return "AT_containing_type";
1490 case AT_default_value_addr: return "AT_default_value_addr";
1491 case AT_default_value_data2: return "AT_default_value_data2";
1492 case AT_default_value_data4: return "AT_default_value_data4";
1493 case AT_default_value_data8: return "AT_default_value_data8";
1494 case AT_default_value_string: return "AT_default_value_string";
1495 case AT_friends: return "AT_friends";
1496 case AT_inline: return "AT_inline";
1497 case AT_is_optional: return "AT_is_optional";
1498 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1499 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1500 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1501 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1502 case AT_private: return "AT_private";
1503 case AT_producer: return "AT_producer";
1504 case AT_program: return "AT_program";
1505 case AT_protected: return "AT_protected";
1506 case AT_prototyped: return "AT_prototyped";
1507 case AT_public: return "AT_public";
1508 case AT_pure_virtual: return "AT_pure_virtual";
1509 case AT_return_addr: return "AT_return_addr";
1510 case AT_abstract_origin: return "AT_abstract_origin";
1511 case AT_start_scope: return "AT_start_scope";
1512 case AT_stride_size: return "AT_stride_size";
1513 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1514 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1515 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1516 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1517 case AT_virtual: return "AT_virtual";
1519 /* GNU extensions */
1521 case AT_sf_names: return "AT_sf_names";
1522 case AT_src_info: return "AT_src_info";
1523 case AT_mac_info: return "AT_mac_info";
1524 case AT_src_coords: return "AT_src_coords";
1525 case AT_body_begin: return "AT_body_begin";
1526 case AT_body_end: return "AT_body_end";
1528 default: return "AT_<unknown>";
1532 static const char *
1533 dwarf_stack_op_name (op)
1534 register unsigned op;
1536 switch (op)
1538 case OP_REG: return "OP_REG";
1539 case OP_BASEREG: return "OP_BASEREG";
1540 case OP_ADDR: return "OP_ADDR";
1541 case OP_CONST: return "OP_CONST";
1542 case OP_DEREF2: return "OP_DEREF2";
1543 case OP_DEREF4: return "OP_DEREF4";
1544 case OP_ADD: return "OP_ADD";
1545 default: return "OP_<unknown>";
1549 static const char *
1550 dwarf_typemod_name (mod)
1551 register unsigned mod;
1553 switch (mod)
1555 case MOD_pointer_to: return "MOD_pointer_to";
1556 case MOD_reference_to: return "MOD_reference_to";
1557 case MOD_const: return "MOD_const";
1558 case MOD_volatile: return "MOD_volatile";
1559 default: return "MOD_<unknown>";
1563 static const char *
1564 dwarf_fmt_byte_name (fmt)
1565 register unsigned fmt;
1567 switch (fmt)
1569 case FMT_FT_C_C: return "FMT_FT_C_C";
1570 case FMT_FT_C_X: return "FMT_FT_C_X";
1571 case FMT_FT_X_C: return "FMT_FT_X_C";
1572 case FMT_FT_X_X: return "FMT_FT_X_X";
1573 case FMT_UT_C_C: return "FMT_UT_C_C";
1574 case FMT_UT_C_X: return "FMT_UT_C_X";
1575 case FMT_UT_X_C: return "FMT_UT_X_C";
1576 case FMT_UT_X_X: return "FMT_UT_X_X";
1577 case FMT_ET: return "FMT_ET";
1578 default: return "FMT_<unknown>";
1582 static const char *
1583 dwarf_fund_type_name (ft)
1584 register unsigned ft;
1586 switch (ft)
1588 case FT_char: return "FT_char";
1589 case FT_signed_char: return "FT_signed_char";
1590 case FT_unsigned_char: return "FT_unsigned_char";
1591 case FT_short: return "FT_short";
1592 case FT_signed_short: return "FT_signed_short";
1593 case FT_unsigned_short: return "FT_unsigned_short";
1594 case FT_integer: return "FT_integer";
1595 case FT_signed_integer: return "FT_signed_integer";
1596 case FT_unsigned_integer: return "FT_unsigned_integer";
1597 case FT_long: return "FT_long";
1598 case FT_signed_long: return "FT_signed_long";
1599 case FT_unsigned_long: return "FT_unsigned_long";
1600 case FT_pointer: return "FT_pointer";
1601 case FT_float: return "FT_float";
1602 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1603 case FT_ext_prec_float: return "FT_ext_prec_float";
1604 case FT_complex: return "FT_complex";
1605 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1606 case FT_void: return "FT_void";
1607 case FT_boolean: return "FT_boolean";
1608 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1609 case FT_label: return "FT_label";
1611 /* GNU extensions. */
1613 case FT_long_long: return "FT_long_long";
1614 case FT_signed_long_long: return "FT_signed_long_long";
1615 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1617 case FT_int8: return "FT_int8";
1618 case FT_signed_int8: return "FT_signed_int8";
1619 case FT_unsigned_int8: return "FT_unsigned_int8";
1620 case FT_int16: return "FT_int16";
1621 case FT_signed_int16: return "FT_signed_int16";
1622 case FT_unsigned_int16: return "FT_unsigned_int16";
1623 case FT_int32: return "FT_int32";
1624 case FT_signed_int32: return "FT_signed_int32";
1625 case FT_unsigned_int32: return "FT_unsigned_int32";
1626 case FT_int64: return "FT_int64";
1627 case FT_signed_int64: return "FT_signed_int64";
1628 case FT_unsigned_int64: return "FT_unsigned_int64";
1629 case FT_int128: return "FT_int128";
1630 case FT_signed_int128: return "FT_signed_int128";
1631 case FT_unsigned_int128: return "FT_unsigned_int128";
1633 case FT_real32: return "FT_real32";
1634 case FT_real64: return "FT_real64";
1635 case FT_real96: return "FT_real96";
1636 case FT_real128: return "FT_real128";
1638 default: return "FT_<unknown>";
1642 /* Determine the "ultimate origin" of a decl. The decl may be an
1643 inlined instance of an inlined instance of a decl which is local
1644 to an inline function, so we have to trace all of the way back
1645 through the origin chain to find out what sort of node actually
1646 served as the original seed for the given block. */
1648 static tree
1649 decl_ultimate_origin (decl)
1650 register tree decl;
1652 #ifdef ENABLE_CHECKING
1653 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1654 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1655 most distant ancestor, this should never happen. */
1656 abort ();
1657 #endif
1659 return DECL_ABSTRACT_ORIGIN (decl);
1662 /* Determine the "ultimate origin" of a block. The block may be an
1663 inlined instance of an inlined instance of a block which is local
1664 to an inline function, so we have to trace all of the way back
1665 through the origin chain to find out what sort of node actually
1666 served as the original seed for the given block. */
1668 static tree
1669 block_ultimate_origin (block)
1670 register tree block;
1672 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1674 if (immediate_origin == NULL)
1675 return NULL;
1676 else
1678 register tree ret_val;
1679 register tree lookahead = immediate_origin;
1683 ret_val = lookahead;
1684 lookahead = (TREE_CODE (ret_val) == BLOCK)
1685 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1686 : NULL;
1688 while (lookahead != NULL && lookahead != ret_val);
1689 return ret_val;
1693 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1694 of a virtual function may refer to a base class, so we check the 'this'
1695 parameter. */
1697 static tree
1698 decl_class_context (decl)
1699 tree decl;
1701 tree context = NULL_TREE;
1702 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1703 context = DECL_CONTEXT (decl);
1704 else
1705 context = TYPE_MAIN_VARIANT
1706 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1708 if (context && !TYPE_P (context))
1709 context = NULL_TREE;
1711 return context;
1714 #if 0
1715 static void
1716 output_unsigned_leb128 (value)
1717 register unsigned long value;
1719 register unsigned long orig_value = value;
1723 register unsigned byte = (value & 0x7f);
1725 value >>= 7;
1726 if (value != 0) /* more bytes to follow */
1727 byte |= 0x80;
1728 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1729 if (flag_debug_asm && value == 0)
1730 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1731 ASM_COMMENT_START, orig_value);
1732 fputc ('\n', asm_out_file);
1734 while (value != 0);
1737 static void
1738 output_signed_leb128 (value)
1739 register long value;
1741 register long orig_value = value;
1742 register int negative = (value < 0);
1743 register int more;
1747 register unsigned byte = (value & 0x7f);
1749 value >>= 7;
1750 if (negative)
1751 value |= 0xfe000000; /* manually sign extend */
1752 if (((value == 0) && ((byte & 0x40) == 0))
1753 || ((value == -1) && ((byte & 0x40) == 1)))
1754 more = 0;
1755 else
1757 byte |= 0x80;
1758 more = 1;
1760 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1761 if (flag_debug_asm && more == 0)
1762 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1763 ASM_COMMENT_START, orig_value);
1764 fputc ('\n', asm_out_file);
1766 while (more);
1768 #endif
1770 /**************** utility functions for attribute functions ******************/
1772 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1773 type code for the given type.
1775 This routine must only be called for GCC type nodes that correspond to
1776 Dwarf fundamental types.
1778 The current Dwarf draft specification calls for Dwarf fundamental types
1779 to accurately reflect the fact that a given type was either a "plain"
1780 integral type or an explicitly "signed" integral type. Unfortunately,
1781 we can't always do this, because GCC may already have thrown away the
1782 information about the precise way in which the type was originally
1783 specified, as in:
1785 typedef signed int my_type;
1787 struct s { my_type f; };
1789 Since we may be stuck here without enought information to do exactly
1790 what is called for in the Dwarf draft specification, we do the best
1791 that we can under the circumstances and always use the "plain" integral
1792 fundamental type codes for int, short, and long types. That's probably
1793 good enough. The additional accuracy called for in the current DWARF
1794 draft specification is probably never even useful in practice. */
1796 static int
1797 fundamental_type_code (type)
1798 register tree type;
1800 if (TREE_CODE (type) == ERROR_MARK)
1801 return 0;
1803 switch (TREE_CODE (type))
1805 case ERROR_MARK:
1806 return FT_void;
1808 case VOID_TYPE:
1809 return FT_void;
1811 case INTEGER_TYPE:
1812 /* Carefully distinguish all the standard types of C,
1813 without messing up if the language is not C.
1814 Note that we check only for the names that contain spaces;
1815 other names might occur by coincidence in other languages. */
1816 if (TYPE_NAME (type) != 0
1817 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1818 && DECL_NAME (TYPE_NAME (type)) != 0
1819 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1821 const char *name =
1822 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1824 if (!strcmp (name, "unsigned char"))
1825 return FT_unsigned_char;
1826 if (!strcmp (name, "signed char"))
1827 return FT_signed_char;
1828 if (!strcmp (name, "unsigned int"))
1829 return FT_unsigned_integer;
1830 if (!strcmp (name, "short int"))
1831 return FT_short;
1832 if (!strcmp (name, "short unsigned int"))
1833 return FT_unsigned_short;
1834 if (!strcmp (name, "long int"))
1835 return FT_long;
1836 if (!strcmp (name, "long unsigned int"))
1837 return FT_unsigned_long;
1838 if (!strcmp (name, "long long int"))
1839 return FT_long_long; /* Not grok'ed by svr4 SDB */
1840 if (!strcmp (name, "long long unsigned int"))
1841 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1844 /* Most integer types will be sorted out above, however, for the
1845 sake of special `array index' integer types, the following code
1846 is also provided. */
1848 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1849 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1851 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1852 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1854 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1855 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1857 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1858 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1860 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1861 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1863 if (TYPE_MODE (type) == TImode)
1864 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1866 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1867 if (TYPE_PRECISION (type) == 1)
1868 return FT_boolean;
1870 abort ();
1872 case REAL_TYPE:
1873 /* Carefully distinguish all the standard types of C,
1874 without messing up if the language is not C. */
1875 if (TYPE_NAME (type) != 0
1876 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1877 && DECL_NAME (TYPE_NAME (type)) != 0
1878 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1880 const char *name =
1881 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1883 /* Note that here we can run afowl of a serious bug in "classic"
1884 svr4 SDB debuggers. They don't seem to understand the
1885 FT_ext_prec_float type (even though they should). */
1887 if (!strcmp (name, "long double"))
1888 return FT_ext_prec_float;
1891 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1893 /* On the SH, when compiling with -m3e or -m4-single-only, both
1894 float and double are 32 bits. But since the debugger doesn't
1895 know about the subtarget, it always thinks double is 64 bits.
1896 So we have to tell the debugger that the type is float to
1897 make the output of the 'print' command etc. readable. */
1898 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1899 return FT_float;
1900 return FT_dbl_prec_float;
1902 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1903 return FT_float;
1905 /* Note that here we can run afowl of a serious bug in "classic"
1906 svr4 SDB debuggers. They don't seem to understand the
1907 FT_ext_prec_float type (even though they should). */
1909 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1910 return FT_ext_prec_float;
1911 abort ();
1913 case COMPLEX_TYPE:
1914 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1916 case CHAR_TYPE:
1917 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1919 case BOOLEAN_TYPE:
1920 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1922 default:
1923 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1925 return 0;
1928 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1929 the Dwarf "root" type for the given input type. The Dwarf "root" type
1930 of a given type is generally the same as the given type, except that if
1931 the given type is a pointer or reference type, then the root type of
1932 the given type is the root type of the "basis" type for the pointer or
1933 reference type. (This definition of the "root" type is recursive.)
1934 Also, the root type of a `const' qualified type or a `volatile'
1935 qualified type is the root type of the given type without the
1936 qualifiers. */
1938 static tree
1939 root_type_1 (type, count)
1940 register tree type;
1941 register int count;
1943 /* Give up after searching 1000 levels, in case this is a recursive
1944 pointer type. Such types are possible in Ada, but it is not possible
1945 to represent them in DWARF1 debug info. */
1946 if (count > 1000)
1947 return error_mark_node;
1949 switch (TREE_CODE (type))
1951 case ERROR_MARK:
1952 return error_mark_node;
1954 case POINTER_TYPE:
1955 case REFERENCE_TYPE:
1956 return root_type_1 (TREE_TYPE (type), count+1);
1958 default:
1959 return type;
1963 static tree
1964 root_type (type)
1965 register tree type;
1967 type = root_type_1 (type, 0);
1968 if (type != error_mark_node)
1969 type = type_main_variant (type);
1970 return type;
1973 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1974 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1976 static void
1977 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1978 register tree type;
1979 register int decl_const;
1980 register int decl_volatile;
1981 register int count;
1983 if (TREE_CODE (type) == ERROR_MARK)
1984 return;
1986 /* Give up after searching 1000 levels, in case this is a recursive
1987 pointer type. Such types are possible in Ada, but it is not possible
1988 to represent them in DWARF1 debug info. */
1989 if (count > 1000)
1990 return;
1992 if (TYPE_READONLY (type) || decl_const)
1993 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1994 if (TYPE_VOLATILE (type) || decl_volatile)
1995 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1996 switch (TREE_CODE (type))
1998 case POINTER_TYPE:
1999 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
2000 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
2001 return;
2003 case REFERENCE_TYPE:
2004 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
2005 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
2006 return;
2008 case ERROR_MARK:
2009 default:
2010 return;
2014 static void
2015 write_modifier_bytes (type, decl_const, decl_volatile)
2016 register tree type;
2017 register int decl_const;
2018 register int decl_volatile;
2020 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
2023 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
2024 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
2026 static inline int
2027 type_is_fundamental (type)
2028 register tree type;
2030 switch (TREE_CODE (type))
2032 case ERROR_MARK:
2033 case VOID_TYPE:
2034 case INTEGER_TYPE:
2035 case REAL_TYPE:
2036 case COMPLEX_TYPE:
2037 case BOOLEAN_TYPE:
2038 case CHAR_TYPE:
2039 return 1;
2041 case SET_TYPE:
2042 case ARRAY_TYPE:
2043 case RECORD_TYPE:
2044 case UNION_TYPE:
2045 case QUAL_UNION_TYPE:
2046 case ENUMERAL_TYPE:
2047 case FUNCTION_TYPE:
2048 case METHOD_TYPE:
2049 case POINTER_TYPE:
2050 case REFERENCE_TYPE:
2051 case FILE_TYPE:
2052 case OFFSET_TYPE:
2053 case LANG_TYPE:
2054 case VECTOR_TYPE:
2055 return 0;
2057 default:
2058 abort ();
2060 return 0;
2063 /* Given a pointer to some ..._DECL tree node, generate an assembly language
2064 equate directive which will associate a symbolic name with the current DIE.
2066 The name used is an artificial label generated from the DECL_UID number
2067 associated with the given decl node. The name it gets equated to is the
2068 symbolic label that we (previously) output at the start of the DIE that
2069 we are currently generating.
2071 Calling this function while generating some "decl related" form of DIE
2072 makes it possible to later refer to the DIE which represents the given
2073 decl simply by re-generating the symbolic name from the ..._DECL node's
2074 UID number. */
2076 static void
2077 equate_decl_number_to_die_number (decl)
2078 register tree decl;
2080 /* In the case where we are generating a DIE for some ..._DECL node
2081 which represents either some inline function declaration or some
2082 entity declared within an inline function declaration/definition,
2083 setup a symbolic name for the current DIE so that we have a name
2084 for this DIE that we can easily refer to later on within
2085 AT_abstract_origin attributes. */
2087 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
2088 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2090 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
2091 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2092 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
2095 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
2096 equate directive which will associate a symbolic name with the current DIE.
2098 The name used is an artificial label generated from the TYPE_UID number
2099 associated with the given type node. The name it gets equated to is the
2100 symbolic label that we (previously) output at the start of the DIE that
2101 we are currently generating.
2103 Calling this function while generating some "type related" form of DIE
2104 makes it easy to later refer to the DIE which represents the given type
2105 simply by re-generating the alternative name from the ..._TYPE node's
2106 UID number. */
2108 static inline void
2109 equate_type_number_to_die_number (type)
2110 register tree type;
2112 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
2113 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2115 /* We are generating a DIE to represent the main variant of this type
2116 (i.e the type without any const or volatile qualifiers) so in order
2117 to get the equate to come out right, we need to get the main variant
2118 itself here. */
2120 type = type_main_variant (type);
2122 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
2123 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2124 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
2127 static void
2128 output_reg_number (rtl)
2129 register rtx rtl;
2131 register unsigned regno = REGNO (rtl);
2133 if (regno >= DWARF_FRAME_REGISTERS)
2135 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
2136 regno);
2137 regno = 0;
2139 fprintf (asm_out_file, "%s0x%x",
2140 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
2141 if (flag_debug_asm)
2143 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
2144 PRINT_REG (rtl, 0, asm_out_file);
2146 fputc ('\n', asm_out_file);
2149 /* The following routine is a nice and simple transducer. It converts the
2150 RTL for a variable or parameter (resident in memory) into an equivalent
2151 Dwarf representation of a mechanism for getting the address of that same
2152 variable onto the top of a hypothetical "address evaluation" stack.
2154 When creating memory location descriptors, we are effectively trans-
2155 forming the RTL for a memory-resident object into its Dwarf postfix
2156 expression equivalent. This routine just recursively descends an
2157 RTL tree, turning it into Dwarf postfix code as it goes. */
2159 static void
2160 output_mem_loc_descriptor (rtl)
2161 register rtx rtl;
2163 /* Note that for a dynamically sized array, the location we will
2164 generate a description of here will be the lowest numbered location
2165 which is actually within the array. That's *not* necessarily the
2166 same as the zeroth element of the array. */
2168 #ifdef ASM_SIMPLIFY_DWARF_ADDR
2169 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
2170 #endif
2172 switch (GET_CODE (rtl))
2174 case SUBREG:
2176 /* The case of a subreg may arise when we have a local (register)
2177 variable or a formal (register) parameter which doesn't quite
2178 fill up an entire register. For now, just assume that it is
2179 legitimate to make the Dwarf info refer to the whole register
2180 which contains the given subreg. */
2182 rtl = SUBREG_REG (rtl);
2183 /* Drop thru. */
2185 case REG:
2187 /* Whenever a register number forms a part of the description of
2188 the method for calculating the (dynamic) address of a memory
2189 resident object, DWARF rules require the register number to
2190 be referred to as a "base register". This distinction is not
2191 based in any way upon what category of register the hardware
2192 believes the given register belongs to. This is strictly
2193 DWARF terminology we're dealing with here.
2195 Note that in cases where the location of a memory-resident data
2196 object could be expressed as:
2198 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
2200 the actual DWARF location descriptor that we generate may just
2201 be OP_BASEREG (basereg). This may look deceptively like the
2202 object in question was allocated to a register (rather than
2203 in memory) so DWARF consumers need to be aware of the subtle
2204 distinction between OP_REG and OP_BASEREG. */
2206 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
2207 output_reg_number (rtl);
2208 break;
2210 case MEM:
2211 output_mem_loc_descriptor (XEXP (rtl, 0));
2212 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
2213 break;
2215 case CONST:
2216 case SYMBOL_REF:
2217 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
2218 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2219 break;
2221 case PLUS:
2222 output_mem_loc_descriptor (XEXP (rtl, 0));
2223 output_mem_loc_descriptor (XEXP (rtl, 1));
2224 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2225 break;
2227 case CONST_INT:
2228 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2229 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
2230 break;
2232 case MULT:
2233 /* If a pseudo-reg is optimized away, it is possible for it to
2234 be replaced with a MEM containing a multiply. Use a GNU extension
2235 to describe it. */
2236 output_mem_loc_descriptor (XEXP (rtl, 0));
2237 output_mem_loc_descriptor (XEXP (rtl, 1));
2238 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
2239 break;
2241 default:
2242 abort ();
2246 /* Output a proper Dwarf location descriptor for a variable or parameter
2247 which is either allocated in a register or in a memory location. For
2248 a register, we just generate an OP_REG and the register number. For a
2249 memory location we provide a Dwarf postfix expression describing how to
2250 generate the (dynamic) address of the object onto the address stack. */
2252 static void
2253 output_loc_descriptor (rtl)
2254 register rtx rtl;
2256 switch (GET_CODE (rtl))
2258 case SUBREG:
2260 /* The case of a subreg may arise when we have a local (register)
2261 variable or a formal (register) parameter which doesn't quite
2262 fill up an entire register. For now, just assume that it is
2263 legitimate to make the Dwarf info refer to the whole register
2264 which contains the given subreg. */
2266 rtl = SUBREG_REG (rtl);
2267 /* Drop thru. */
2269 case REG:
2270 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
2271 output_reg_number (rtl);
2272 break;
2274 case MEM:
2275 output_mem_loc_descriptor (XEXP (rtl, 0));
2276 break;
2278 default:
2279 abort (); /* Should never happen */
2283 /* Given a tree node describing an array bound (either lower or upper)
2284 output a representation for that bound. */
2286 static void
2287 output_bound_representation (bound, dim_num, u_or_l)
2288 register tree bound;
2289 register unsigned dim_num; /* For multi-dimensional arrays. */
2290 register char u_or_l; /* Designates upper or lower bound. */
2292 switch (TREE_CODE (bound))
2295 case ERROR_MARK:
2296 return;
2298 /* All fixed-bounds are represented by INTEGER_CST nodes. */
2300 case INTEGER_CST:
2301 if (host_integerp (bound, 0))
2302 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
2303 break;
2305 default:
2307 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
2308 SAVE_EXPR nodes, in which case we can do something, or as
2309 an expression, which we cannot represent. */
2311 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2312 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2314 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
2315 current_dienum, dim_num, u_or_l);
2317 sprintf (end_label, BOUND_END_LABEL_FMT,
2318 current_dienum, dim_num, u_or_l);
2320 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2321 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2323 /* If optimization is turned on, the SAVE_EXPRs that describe
2324 how to access the upper bound values are essentially bogus.
2325 They only describe (at best) how to get at these values at
2326 the points in the generated code right after they have just
2327 been computed. Worse yet, in the typical case, the upper
2328 bound values will not even *be* computed in the optimized
2329 code, so these SAVE_EXPRs are entirely bogus.
2331 In order to compensate for this fact, we check here to see
2332 if optimization is enabled, and if so, we effectively create
2333 an empty location description for the (unknown and unknowable)
2334 upper bound.
2336 This should not cause too much trouble for existing (stupid?)
2337 debuggers because they have to deal with empty upper bounds
2338 location descriptions anyway in order to be able to deal with
2339 incomplete array types.
2341 Of course an intelligent debugger (GDB?) should be able to
2342 comprehend that a missing upper bound specification in a
2343 array type used for a storage class `auto' local array variable
2344 indicates that the upper bound is both unknown (at compile-
2345 time) and unknowable (at run-time) due to optimization. */
2347 if (! optimize)
2349 while (TREE_CODE (bound) == NOP_EXPR
2350 || TREE_CODE (bound) == CONVERT_EXPR)
2351 bound = TREE_OPERAND (bound, 0);
2353 if (TREE_CODE (bound) == SAVE_EXPR)
2354 output_loc_descriptor
2355 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
2358 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2360 break;
2365 /* Recursive function to output a sequence of value/name pairs for
2366 enumeration constants in reversed order. This is called from
2367 enumeration_type_die. */
2369 static void
2370 output_enumeral_list (link)
2371 register tree link;
2373 if (link)
2375 output_enumeral_list (TREE_CHAIN (link));
2377 if (host_integerp (TREE_VALUE (link), 0))
2378 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2379 tree_low_cst (TREE_VALUE (link), 0));
2381 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
2382 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
2386 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
2387 which is not less than the value itself. */
2389 static inline HOST_WIDE_INT
2390 ceiling (value, boundary)
2391 register HOST_WIDE_INT value;
2392 register unsigned int boundary;
2394 return (((value + boundary - 1) / boundary) * boundary);
2397 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
2398 pointer to the declared type for the relevant field variable, or return
2399 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
2401 static inline tree
2402 field_type (decl)
2403 register tree decl;
2405 register tree type;
2407 if (TREE_CODE (decl) == ERROR_MARK)
2408 return integer_type_node;
2410 type = DECL_BIT_FIELD_TYPE (decl);
2411 if (type == NULL)
2412 type = TREE_TYPE (decl);
2413 return type;
2416 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2417 node, return the alignment in bits for the type, or else return
2418 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
2420 static inline unsigned int
2421 simple_type_align_in_bits (type)
2422 register tree type;
2424 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
2427 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2428 node, return the size in bits for the type if it is a constant, or
2429 else return the alignment for the type if the type's size is not
2430 constant, or else return BITS_PER_WORD if the type actually turns out
2431 to be an ERROR_MARK node. */
2433 static inline unsigned HOST_WIDE_INT
2434 simple_type_size_in_bits (type)
2435 register tree type;
2437 tree type_size_tree;
2439 if (TREE_CODE (type) == ERROR_MARK)
2440 return BITS_PER_WORD;
2441 type_size_tree = TYPE_SIZE (type);
2443 if (type_size_tree == NULL_TREE)
2444 return 0;
2445 if (! host_integerp (type_size_tree, 1))
2446 return TYPE_ALIGN (type);
2447 return tree_low_cst (type_size_tree, 1);
2450 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
2451 return the byte offset of the lowest addressed byte of the "containing
2452 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
2453 mine what that offset is, either because the argument turns out to be a
2454 pointer to an ERROR_MARK node, or because the offset is actually variable.
2455 (We can't handle the latter case just yet.) */
2457 static HOST_WIDE_INT
2458 field_byte_offset (decl)
2459 register tree decl;
2461 unsigned int type_align_in_bytes;
2462 unsigned int type_align_in_bits;
2463 unsigned HOST_WIDE_INT type_size_in_bits;
2464 HOST_WIDE_INT object_offset_in_align_units;
2465 HOST_WIDE_INT object_offset_in_bits;
2466 HOST_WIDE_INT object_offset_in_bytes;
2467 tree type;
2468 tree field_size_tree;
2469 HOST_WIDE_INT bitpos_int;
2470 HOST_WIDE_INT deepest_bitpos;
2471 unsigned HOST_WIDE_INT field_size_in_bits;
2473 if (TREE_CODE (decl) == ERROR_MARK)
2474 return 0;
2476 if (TREE_CODE (decl) != FIELD_DECL)
2477 abort ();
2479 type = field_type (decl);
2480 field_size_tree = DECL_SIZE (decl);
2482 /* The size could be unspecified if there was an error, or for
2483 a flexible array member. */
2484 if (! field_size_tree)
2485 field_size_tree = bitsize_zero_node;
2487 /* We cannot yet cope with fields whose positions or sizes are variable,
2488 so for now, when we see such things, we simply return 0. Someday,
2489 we may be able to handle such cases, but it will be damn difficult. */
2491 if (! host_integerp (bit_position (decl), 0)
2492 || ! host_integerp (field_size_tree, 1))
2493 return 0;
2495 bitpos_int = int_bit_position (decl);
2496 field_size_in_bits = tree_low_cst (field_size_tree, 1);
2498 type_size_in_bits = simple_type_size_in_bits (type);
2499 type_align_in_bits = simple_type_align_in_bits (type);
2500 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2502 /* Note that the GCC front-end doesn't make any attempt to keep track
2503 of the starting bit offset (relative to the start of the containing
2504 structure type) of the hypothetical "containing object" for a bit-
2505 field. Thus, when computing the byte offset value for the start of
2506 the "containing object" of a bit-field, we must deduce this infor-
2507 mation on our own.
2509 This can be rather tricky to do in some cases. For example, handling
2510 the following structure type definition when compiling for an i386/i486
2511 target (which only aligns long long's to 32-bit boundaries) can be very
2512 tricky:
2514 struct S {
2515 int field1;
2516 long long field2:31;
2519 Fortunately, there is a simple rule-of-thumb which can be used in such
2520 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2521 the structure shown above. It decides to do this based upon one simple
2522 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2523 taining object" for each bit-field at the first (i.e. lowest addressed)
2524 legitimate alignment boundary (based upon the required minimum alignment
2525 for the declared type of the field) which it can possibly use, subject
2526 to the condition that there is still enough available space remaining
2527 in the containing object (when allocated at the selected point) to
2528 fully accommodate all of the bits of the bit-field itself.
2530 This simple rule makes it obvious why GCC allocates 8 bytes for each
2531 object of the structure type shown above. When looking for a place to
2532 allocate the "containing object" for `field2', the compiler simply tries
2533 to allocate a 64-bit "containing object" at each successive 32-bit
2534 boundary (starting at zero) until it finds a place to allocate that 64-
2535 bit field such that at least 31 contiguous (and previously unallocated)
2536 bits remain within that selected 64 bit field. (As it turns out, for
2537 the example above, the compiler finds that it is OK to allocate the
2538 "containing object" 64-bit field at bit-offset zero within the
2539 structure type.)
2541 Here we attempt to work backwards from the limited set of facts we're
2542 given, and we try to deduce from those facts, where GCC must have
2543 believed that the containing object started (within the structure type).
2545 The value we deduce is then used (by the callers of this routine) to
2546 generate AT_location and AT_bit_offset attributes for fields (both
2547 bit-fields and, in the case of AT_location, regular fields as well). */
2549 /* Figure out the bit-distance from the start of the structure to the
2550 "deepest" bit of the bit-field. */
2551 deepest_bitpos = bitpos_int + field_size_in_bits;
2553 /* This is the tricky part. Use some fancy footwork to deduce where the
2554 lowest addressed bit of the containing object must be. */
2555 object_offset_in_bits
2556 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2558 /* Compute the offset of the containing object in "alignment units". */
2559 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2561 /* Compute the offset of the containing object in bytes. */
2562 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2564 /* The above code assumes that the field does not cross an alignment
2565 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2566 or if the structure is packed. If this happens, then we get an object
2567 which starts after the bitfield, which means that the bit offset is
2568 negative. Gdb fails when given negative bit offsets. We avoid this
2569 by recomputing using the first bit of the bitfield. This will give
2570 us an object which does not completely contain the bitfield, but it
2571 will be aligned, and it will contain the first bit of the bitfield.
2573 However, only do this for a BYTES_BIG_ENDIAN target. For a
2574 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2575 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2576 then we end up computing the object byte offset for the wrong word of the
2577 desired bitfield, which in turn causes the field offset to be negative
2578 in bit_offset_attribute. */
2579 if (BYTES_BIG_ENDIAN
2580 && object_offset_in_bits > bitpos_int)
2582 deepest_bitpos = bitpos_int + 1;
2583 object_offset_in_bits
2584 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2585 object_offset_in_align_units = (object_offset_in_bits
2586 / type_align_in_bits);
2587 object_offset_in_bytes = (object_offset_in_align_units
2588 * type_align_in_bytes);
2591 return object_offset_in_bytes;
2594 /****************************** attributes *********************************/
2596 /* The following routines are responsible for writing out the various types
2597 of Dwarf attributes (and any following data bytes associated with them).
2598 These routines are listed in order based on the numerical codes of their
2599 associated attributes. */
2601 /* Generate an AT_sibling attribute. */
2603 static inline void
2604 sibling_attribute ()
2606 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2608 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2609 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2610 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2613 /* Output the form of location attributes suitable for whole variables and
2614 whole parameters. Note that the location attributes for struct fields
2615 are generated by the routine `data_member_location_attribute' below. */
2617 static void
2618 location_attribute (rtl)
2619 register rtx rtl;
2621 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2622 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2624 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2625 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2626 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2627 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2628 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2630 /* Handle a special case. If we are about to output a location descriptor
2631 for a variable or parameter which has been optimized out of existence,
2632 don't do that. Instead we output a zero-length location descriptor
2633 value as part of the location attribute.
2635 A variable which has been optimized out of existence will have a
2636 DECL_RTL value which denotes a pseudo-reg.
2638 Currently, in some rare cases, variables can have DECL_RTL values
2639 which look like (MEM (REG pseudo-reg#)). These cases are due to
2640 bugs elsewhere in the compiler. We treat such cases
2641 as if the variable(s) in question had been optimized out of existence.
2643 Note that in all cases where we wish to express the fact that a
2644 variable has been optimized out of existence, we do not simply
2645 suppress the generation of the entire location attribute because
2646 the absence of a location attribute in certain kinds of DIEs is
2647 used to indicate something else entirely... i.e. that the DIE
2648 represents an object declaration, but not a definition. So saith
2649 the PLSIG.
2652 if (! is_pseudo_reg (rtl)
2653 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2654 output_loc_descriptor (rtl);
2656 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2659 /* Output the specialized form of location attribute used for data members
2660 of struct and union types.
2662 In the special case of a FIELD_DECL node which represents a bit-field,
2663 the "offset" part of this special location descriptor must indicate the
2664 distance in bytes from the lowest-addressed byte of the containing
2665 struct or union type to the lowest-addressed byte of the "containing
2666 object" for the bit-field. (See the `field_byte_offset' function above.)
2668 For any given bit-field, the "containing object" is a hypothetical
2669 object (of some integral or enum type) within which the given bit-field
2670 lives. The type of this hypothetical "containing object" is always the
2671 same as the declared type of the individual bit-field itself (for GCC
2672 anyway... the DWARF spec doesn't actually mandate this).
2674 Note that it is the size (in bytes) of the hypothetical "containing
2675 object" which will be given in the AT_byte_size attribute for this
2676 bit-field. (See the `byte_size_attribute' function below.) It is
2677 also used when calculating the value of the AT_bit_offset attribute.
2678 (See the `bit_offset_attribute' function below.) */
2680 static void
2681 data_member_location_attribute (t)
2682 register tree t;
2684 register unsigned object_offset_in_bytes;
2685 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2686 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2688 if (TREE_CODE (t) == TREE_VEC)
2689 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2690 else
2691 object_offset_in_bytes = field_byte_offset (t);
2693 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2694 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2695 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2696 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2697 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2698 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2699 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2700 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2701 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2704 /* Output an AT_const_value attribute for a variable or a parameter which
2705 does not have a "location" either in memory or in a register. These
2706 things can arise in GNU C when a constant is passed as an actual
2707 parameter to an inlined function. They can also arise in C++ where
2708 declared constants do not necessarily get memory "homes". */
2710 static void
2711 const_value_attribute (rtl)
2712 register rtx rtl;
2714 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2715 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2717 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2718 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2719 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2720 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2721 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2723 switch (GET_CODE (rtl))
2725 case CONST_INT:
2726 /* Note that a CONST_INT rtx could represent either an integer or
2727 a floating-point constant. A CONST_INT is used whenever the
2728 constant will fit into a single word. In all such cases, the
2729 original mode of the constant value is wiped out, and the
2730 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2731 precise mode information for these constants, we always just
2732 output them using 4 bytes. */
2734 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2735 break;
2737 case CONST_DOUBLE:
2738 /* Note that a CONST_DOUBLE rtx could represent either an integer
2739 or a floating-point constant. A CONST_DOUBLE is used whenever
2740 the constant requires more than one word in order to be adequately
2741 represented. In all such cases, the original mode of the constant
2742 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2743 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2745 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2746 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2747 (unsigned int) CONST_DOUBLE_LOW (rtl));
2748 break;
2750 case CONST_STRING:
2751 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2752 break;
2754 case SYMBOL_REF:
2755 case LABEL_REF:
2756 case CONST:
2757 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2758 break;
2760 case PLUS:
2761 /* In cases where an inlined instance of an inline function is passed
2762 the address of an `auto' variable (which is local to the caller)
2763 we can get a situation where the DECL_RTL of the artificial
2764 local variable (for the inlining) which acts as a stand-in for
2765 the corresponding formal parameter (of the inline function)
2766 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2767 This is not exactly a compile-time constant expression, but it
2768 isn't the address of the (artificial) local variable either.
2769 Rather, it represents the *value* which the artificial local
2770 variable always has during its lifetime. We currently have no
2771 way to represent such quasi-constant values in Dwarf, so for now
2772 we just punt and generate an AT_const_value attribute with form
2773 FORM_BLOCK4 and a length of zero. */
2774 break;
2776 default:
2777 abort (); /* No other kinds of rtx should be possible here. */
2780 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2783 /* Generate *either* an AT_location attribute or else an AT_const_value
2784 data attribute for a variable or a parameter. We generate the
2785 AT_const_value attribute only in those cases where the given
2786 variable or parameter does not have a true "location" either in
2787 memory or in a register. This can happen (for example) when a
2788 constant is passed as an actual argument in a call to an inline
2789 function. (It's possible that these things can crop up in other
2790 ways also.) Note that one type of constant value which can be
2791 passed into an inlined function is a constant pointer. This can
2792 happen for example if an actual argument in an inlined function
2793 call evaluates to a compile-time constant address. */
2795 static void
2796 location_or_const_value_attribute (decl)
2797 register tree decl;
2799 register rtx rtl;
2801 if (TREE_CODE (decl) == ERROR_MARK)
2802 return;
2804 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2806 /* Should never happen. */
2807 abort ();
2808 return;
2811 /* Here we have to decide where we are going to say the parameter "lives"
2812 (as far as the debugger is concerned). We only have a couple of choices.
2813 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2814 normally indicates where the parameter lives during most of the activa-
2815 tion of the function. If optimization is enabled however, this could
2816 be either NULL or else a pseudo-reg. Both of those cases indicate that
2817 the parameter doesn't really live anywhere (as far as the code generation
2818 parts of GCC are concerned) during most of the function's activation.
2819 That will happen (for example) if the parameter is never referenced
2820 within the function.
2822 We could just generate a location descriptor here for all non-NULL
2823 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2824 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2825 cases where DECL_RTL is NULL or is a pseudo-reg.
2827 Note however that we can only get away with using DECL_INCOMING_RTL as
2828 a backup substitute for DECL_RTL in certain limited cases. In cases
2829 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2830 we can be sure that the parameter was passed using the same type as it
2831 is declared to have within the function, and that its DECL_INCOMING_RTL
2832 points us to a place where a value of that type is passed. In cases
2833 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2834 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2835 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2836 points us to a value of some type which is *different* from the type
2837 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2838 to generate a location attribute in such cases, the debugger would
2839 end up (for example) trying to fetch a `float' from a place which
2840 actually contains the first part of a `double'. That would lead to
2841 really incorrect and confusing output at debug-time, and we don't
2842 want that now do we?
2844 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2845 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2846 couple of cute exceptions however. On little-endian machines we can
2847 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2848 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2849 an integral type which is smaller than TREE_TYPE(decl). These cases
2850 arise when (on a little-endian machine) a non-prototyped function has
2851 a parameter declared to be of type `short' or `char'. In such cases,
2852 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2853 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2854 passed `int' value. If the debugger then uses that address to fetch a
2855 `short' or a `char' (on a little-endian machine) the result will be the
2856 correct data, so we allow for such exceptional cases below.
2858 Note that our goal here is to describe the place where the given formal
2859 parameter lives during most of the function's activation (i.e. between
2860 the end of the prologue and the start of the epilogue). We'll do that
2861 as best as we can. Note however that if the given formal parameter is
2862 modified sometime during the execution of the function, then a stack
2863 backtrace (at debug-time) will show the function as having been called
2864 with the *new* value rather than the value which was originally passed
2865 in. This happens rarely enough that it is not a major problem, but it
2866 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2867 may generate two additional attributes for any given TAG_formal_parameter
2868 DIE which will describe the "passed type" and the "passed location" for
2869 the given formal parameter in addition to the attributes we now generate
2870 to indicate the "declared type" and the "active location" for each
2871 parameter. This additional set of attributes could be used by debuggers
2872 for stack backtraces.
2874 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2875 can be NULL also. This happens (for example) for inlined-instances of
2876 inline function formal parameters which are never referenced. This really
2877 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2878 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2879 these values for inlined instances of inline function parameters, so
2880 when we see such cases, we are just out-of-luck for the time
2881 being (until integrate.c gets fixed).
2884 /* Use DECL_RTL as the "location" unless we find something better. */
2885 rtl = DECL_RTL (decl);
2887 if (TREE_CODE (decl) == PARM_DECL)
2888 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2890 /* This decl represents a formal parameter which was optimized out. */
2891 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2892 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2894 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2895 *all* cases where (rtl == NULL_RTX) just below. */
2897 if (declared_type == passed_type)
2898 rtl = DECL_INCOMING_RTL (decl);
2899 else if (! BYTES_BIG_ENDIAN)
2900 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2901 /* NMS WTF? */
2902 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2903 rtl = DECL_INCOMING_RTL (decl);
2906 if (rtl == NULL_RTX)
2907 return;
2909 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2910 #ifdef LEAF_REG_REMAP
2911 if (current_function_uses_only_leaf_regs)
2912 leaf_renumber_regs_insn (rtl);
2913 #endif
2915 switch (GET_CODE (rtl))
2917 case ADDRESSOF:
2918 /* The address of a variable that was optimized away; don't emit
2919 anything. */
2920 break;
2922 case CONST_INT:
2923 case CONST_DOUBLE:
2924 case CONST_STRING:
2925 case SYMBOL_REF:
2926 case LABEL_REF:
2927 case CONST:
2928 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2929 const_value_attribute (rtl);
2930 break;
2932 case MEM:
2933 case REG:
2934 case SUBREG:
2935 location_attribute (rtl);
2936 break;
2938 case CONCAT:
2939 /* ??? CONCAT is used for complex variables, which may have the real
2940 part stored in one place and the imag part stored somewhere else.
2941 DWARF1 has no way to describe a variable that lives in two different
2942 places, so we just describe where the first part lives, and hope that
2943 the second part is stored after it. */
2944 location_attribute (XEXP (rtl, 0));
2945 break;
2947 default:
2948 abort (); /* Should never happen. */
2952 /* Generate an AT_name attribute given some string value to be included as
2953 the value of the attribute. */
2955 static inline void
2956 name_attribute (name_string)
2957 register const char *name_string;
2959 if (name_string && *name_string)
2961 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2962 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2966 static inline void
2967 fund_type_attribute (ft_code)
2968 register unsigned ft_code;
2970 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2971 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2974 static void
2975 mod_fund_type_attribute (type, decl_const, decl_volatile)
2976 register tree type;
2977 register int decl_const;
2978 register int decl_volatile;
2980 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2981 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2983 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2984 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2985 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2986 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2987 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2988 write_modifier_bytes (type, decl_const, decl_volatile);
2989 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2990 fundamental_type_code (root_type (type)));
2991 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2994 static inline void
2995 user_def_type_attribute (type)
2996 register tree type;
2998 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
3000 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
3001 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
3002 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
3005 static void
3006 mod_u_d_type_attribute (type, decl_const, decl_volatile)
3007 register tree type;
3008 register int decl_const;
3009 register int decl_volatile;
3011 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3012 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3013 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
3015 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
3016 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
3017 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
3018 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3019 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3020 write_modifier_bytes (type, decl_const, decl_volatile);
3021 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
3022 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
3023 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3026 #ifdef USE_ORDERING_ATTRIBUTE
3027 static inline void
3028 ordering_attribute (ordering)
3029 register unsigned ordering;
3031 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
3032 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
3034 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3036 /* Note that the block of subscript information for an array type also
3037 includes information about the element type of type given array type. */
3039 static void
3040 subscript_data_attribute (type)
3041 register tree type;
3043 register unsigned dimension_number;
3044 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3045 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3047 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
3048 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
3049 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
3050 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3051 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3053 /* The GNU compilers represent multidimensional array types as sequences
3054 of one dimensional array types whose element types are themselves array
3055 types. Here we squish that down, so that each multidimensional array
3056 type gets only one array_type DIE in the Dwarf debugging info. The
3057 draft Dwarf specification say that we are allowed to do this kind
3058 of compression in C (because there is no difference between an
3059 array or arrays and a multidimensional array in C) but for other
3060 source languages (e.g. Ada) we probably shouldn't do this. */
3062 for (dimension_number = 0;
3063 TREE_CODE (type) == ARRAY_TYPE;
3064 type = TREE_TYPE (type), dimension_number++)
3066 register tree domain = TYPE_DOMAIN (type);
3068 /* Arrays come in three flavors. Unspecified bounds, fixed
3069 bounds, and (in GNU C only) variable bounds. Handle all
3070 three forms here. */
3072 if (domain)
3074 /* We have an array type with specified bounds. */
3076 register tree lower = TYPE_MIN_VALUE (domain);
3077 register tree upper = TYPE_MAX_VALUE (domain);
3079 /* Handle only fundamental types as index types for now. */
3080 if (! type_is_fundamental (domain))
3081 abort ();
3083 /* Output the representation format byte for this dimension. */
3084 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
3085 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
3086 upper && TREE_CODE (upper) == INTEGER_CST));
3088 /* Output the index type for this dimension. */
3089 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3090 fundamental_type_code (domain));
3092 /* Output the representation for the lower bound. */
3093 output_bound_representation (lower, dimension_number, 'l');
3095 /* Output the representation for the upper bound. */
3096 if (upper)
3097 output_bound_representation (upper, dimension_number, 'u');
3098 else
3099 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3101 else
3103 /* We have an array type with an unspecified length. For C and
3104 C++ we can assume that this really means that (a) the index
3105 type is an integral type, and (b) the lower bound is zero.
3106 Note that Dwarf defines the representation of an unspecified
3107 (upper) bound as being a zero-length location description. */
3109 /* Output the array-bounds format byte. */
3111 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
3113 /* Output the (assumed) index type. */
3115 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
3117 /* Output the (assumed) lower bound (constant) value. */
3119 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3121 /* Output the (empty) location description for the upper bound. */
3123 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3127 /* Output the prefix byte that says that the element type is coming up. */
3129 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
3131 /* Output a representation of the type of the elements of this array type. */
3133 type_attribute (type, 0, 0);
3135 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3138 static void
3139 byte_size_attribute (tree_node)
3140 register tree tree_node;
3142 register unsigned size;
3144 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
3145 switch (TREE_CODE (tree_node))
3147 case ERROR_MARK:
3148 size = 0;
3149 break;
3151 case ENUMERAL_TYPE:
3152 case RECORD_TYPE:
3153 case UNION_TYPE:
3154 case QUAL_UNION_TYPE:
3155 case ARRAY_TYPE:
3156 size = int_size_in_bytes (tree_node);
3157 break;
3159 case FIELD_DECL:
3160 /* For a data member of a struct or union, the AT_byte_size is
3161 generally given as the number of bytes normally allocated for
3162 an object of the *declared* type of the member itself. This
3163 is true even for bit-fields. */
3164 size = simple_type_size_in_bits (field_type (tree_node))
3165 / BITS_PER_UNIT;
3166 break;
3168 default:
3169 abort ();
3172 /* Note that `size' might be -1 when we get to this point. If it
3173 is, that indicates that the byte size of the entity in question
3174 is variable. We have no good way of expressing this fact in Dwarf
3175 at the present time, so just let the -1 pass on through. */
3177 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
3180 /* For a FIELD_DECL node which represents a bit-field, output an attribute
3181 which specifies the distance in bits from the highest order bit of the
3182 "containing object" for the bit-field to the highest order bit of the
3183 bit-field itself.
3185 For any given bit-field, the "containing object" is a hypothetical
3186 object (of some integral or enum type) within which the given bit-field
3187 lives. The type of this hypothetical "containing object" is always the
3188 same as the declared type of the individual bit-field itself.
3190 The determination of the exact location of the "containing object" for
3191 a bit-field is rather complicated. It's handled by the `field_byte_offset'
3192 function (above).
3194 Note that it is the size (in bytes) of the hypothetical "containing
3195 object" which will be given in the AT_byte_size attribute for this
3196 bit-field. (See `byte_size_attribute' above.) */
3198 static inline void
3199 bit_offset_attribute (decl)
3200 register tree decl;
3202 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
3203 tree type = DECL_BIT_FIELD_TYPE (decl);
3204 HOST_WIDE_INT bitpos_int;
3205 HOST_WIDE_INT highest_order_object_bit_offset;
3206 HOST_WIDE_INT highest_order_field_bit_offset;
3207 HOST_WIDE_INT bit_offset;
3209 /* Must be a bit field. */
3210 if (!type
3211 || TREE_CODE (decl) != FIELD_DECL)
3212 abort ();
3214 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
3215 if we encounter such things, just return without generating any
3216 attribute whatsoever. */
3218 if (! host_integerp (bit_position (decl), 0)
3219 || ! host_integerp (DECL_SIZE (decl), 1))
3220 return;
3222 bitpos_int = int_bit_position (decl);
3224 /* Note that the bit offset is always the distance (in bits) from the
3225 highest-order bit of the "containing object" to the highest-order
3226 bit of the bit-field itself. Since the "high-order end" of any
3227 object or field is different on big-endian and little-endian machines,
3228 the computation below must take account of these differences. */
3230 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
3231 highest_order_field_bit_offset = bitpos_int;
3233 if (! BYTES_BIG_ENDIAN)
3235 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
3236 highest_order_object_bit_offset += simple_type_size_in_bits (type);
3239 bit_offset =
3240 (! BYTES_BIG_ENDIAN
3241 ? highest_order_object_bit_offset - highest_order_field_bit_offset
3242 : highest_order_field_bit_offset - highest_order_object_bit_offset);
3244 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
3245 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
3248 /* For a FIELD_DECL node which represents a bit field, output an attribute
3249 which specifies the length in bits of the given field. */
3251 static inline void
3252 bit_size_attribute (decl)
3253 register tree decl;
3255 /* Must be a field and a bit field. */
3256 if (TREE_CODE (decl) != FIELD_DECL
3257 || ! DECL_BIT_FIELD_TYPE (decl))
3258 abort ();
3260 if (host_integerp (DECL_SIZE (decl), 1))
3262 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
3263 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3264 tree_low_cst (DECL_SIZE (decl), 1));
3268 /* The following routine outputs the `element_list' attribute for enumeration
3269 type DIEs. The element_lits attribute includes the names and values of
3270 all of the enumeration constants associated with the given enumeration
3271 type. */
3273 static inline void
3274 element_list_attribute (element)
3275 register tree element;
3277 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3278 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3280 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
3281 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
3282 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
3283 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3284 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3286 /* Here we output a list of value/name pairs for each enumeration constant
3287 defined for this enumeration type (as required), but we do it in REVERSE
3288 order. The order is the one required by the draft #5 Dwarf specification
3289 published by the UI/PLSIG. */
3291 output_enumeral_list (element); /* Recursively output the whole list. */
3293 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3296 /* Generate an AT_stmt_list attribute. These are normally present only in
3297 DIEs with a TAG_compile_unit tag. */
3299 static inline void
3300 stmt_list_attribute (label)
3301 register const char *label;
3303 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
3304 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3305 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3308 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
3309 for a subroutine DIE. */
3311 static inline void
3312 low_pc_attribute (asm_low_label)
3313 register const char *asm_low_label;
3315 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
3316 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
3319 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
3320 subroutine DIE. */
3322 static inline void
3323 high_pc_attribute (asm_high_label)
3324 register const char *asm_high_label;
3326 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
3327 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
3330 /* Generate an AT_body_begin attribute for a subroutine DIE. */
3332 static inline void
3333 body_begin_attribute (asm_begin_label)
3334 register const char *asm_begin_label;
3336 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
3337 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
3340 /* Generate an AT_body_end attribute for a subroutine DIE. */
3342 static inline void
3343 body_end_attribute (asm_end_label)
3344 register const char *asm_end_label;
3346 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
3347 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
3350 /* Generate an AT_language attribute given a LANG value. These attributes
3351 are used only within TAG_compile_unit DIEs. */
3353 static inline void
3354 language_attribute (language_code)
3355 register unsigned language_code;
3357 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
3358 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
3361 static inline void
3362 member_attribute (context)
3363 register tree context;
3365 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3367 /* Generate this attribute only for members in C++. */
3369 if (context != NULL && is_tagged_type (context))
3371 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
3372 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
3373 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3377 #if 0
3378 static inline void
3379 string_length_attribute (upper_bound)
3380 register tree upper_bound;
3382 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3383 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3385 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
3386 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
3387 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
3388 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3389 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3390 output_bound_representation (upper_bound, 0, 'u');
3391 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3393 #endif
3395 static inline void
3396 comp_dir_attribute (dirname)
3397 register const char *dirname;
3399 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
3400 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
3403 static inline void
3404 sf_names_attribute (sf_names_start_label)
3405 register const char *sf_names_start_label;
3407 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
3408 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3409 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
3412 static inline void
3413 src_info_attribute (src_info_start_label)
3414 register const char *src_info_start_label;
3416 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
3417 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3418 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
3421 static inline void
3422 mac_info_attribute (mac_info_start_label)
3423 register const char *mac_info_start_label;
3425 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
3426 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3427 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
3430 static inline void
3431 prototyped_attribute (func_type)
3432 register tree func_type;
3434 if ((strcmp (language_string, "GNU C") == 0)
3435 && (TYPE_ARG_TYPES (func_type) != NULL))
3437 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
3438 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3442 static inline void
3443 producer_attribute (producer)
3444 register const char *producer;
3446 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
3447 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
3450 static inline void
3451 inline_attribute (decl)
3452 register tree decl;
3454 if (DECL_INLINE (decl))
3456 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3457 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3461 static inline void
3462 containing_type_attribute (containing_type)
3463 register tree containing_type;
3465 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3467 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3468 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3469 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3472 static inline void
3473 abstract_origin_attribute (origin)
3474 register tree origin;
3476 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3478 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3479 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3481 case 'd':
3482 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3483 break;
3485 case 't':
3486 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3487 break;
3489 default:
3490 abort (); /* Should never happen. */
3493 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3496 #ifdef DWARF_DECL_COORDINATES
3497 static inline void
3498 src_coords_attribute (src_fileno, src_lineno)
3499 register unsigned src_fileno;
3500 register unsigned src_lineno;
3502 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3503 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3504 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3506 #endif /* defined(DWARF_DECL_COORDINATES) */
3508 static inline void
3509 pure_or_virtual_attribute (func_decl)
3510 register tree func_decl;
3512 if (DECL_VIRTUAL_P (func_decl))
3514 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3515 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3516 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3517 else
3518 #endif
3519 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3520 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3524 /************************* end of attributes *****************************/
3526 /********************* utility routines for DIEs *************************/
3528 /* Output an AT_name attribute and an AT_src_coords attribute for the
3529 given decl, but only if it actually has a name. */
3531 static void
3532 name_and_src_coords_attributes (decl)
3533 register tree decl;
3535 register tree decl_name = DECL_NAME (decl);
3537 if (decl_name && IDENTIFIER_POINTER (decl_name))
3539 name_attribute (IDENTIFIER_POINTER (decl_name));
3540 #ifdef DWARF_DECL_COORDINATES
3542 register unsigned file_index;
3544 /* This is annoying, but we have to pop out of the .debug section
3545 for a moment while we call `lookup_filename' because calling it
3546 may cause a temporary switch into the .debug_sfnames section and
3547 most svr4 assemblers are not smart enough to be able to nest
3548 section switches to any depth greater than one. Note that we
3549 also can't skirt this issue by delaying all output to the
3550 .debug_sfnames section unit the end of compilation because that
3551 would cause us to have inter-section forward references and
3552 Fred Fish sez that m68k/svr4 assemblers botch those. */
3554 ASM_OUTPUT_POP_SECTION (asm_out_file);
3555 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3556 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3558 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3560 #endif /* defined(DWARF_DECL_COORDINATES) */
3564 /* Many forms of DIEs contain a "type description" part. The following
3565 routine writes out these "type descriptor" parts. */
3567 static void
3568 type_attribute (type, decl_const, decl_volatile)
3569 register tree type;
3570 register int decl_const;
3571 register int decl_volatile;
3573 register enum tree_code code = TREE_CODE (type);
3574 register int root_type_modified;
3576 if (code == ERROR_MARK)
3577 return;
3579 /* Handle a special case. For functions whose return type is void,
3580 we generate *no* type attribute. (Note that no object may have
3581 type `void', so this only applies to function return types. */
3583 if (code == VOID_TYPE)
3584 return;
3586 /* If this is a subtype, find the underlying type. Eventually,
3587 this should write out the appropriate subtype info. */
3588 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3589 && TREE_TYPE (type) != 0)
3590 type = TREE_TYPE (type), code = TREE_CODE (type);
3592 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3593 || decl_const || decl_volatile
3594 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3596 if (type_is_fundamental (root_type (type)))
3598 if (root_type_modified)
3599 mod_fund_type_attribute (type, decl_const, decl_volatile);
3600 else
3601 fund_type_attribute (fundamental_type_code (type));
3603 else
3605 if (root_type_modified)
3606 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3607 else
3608 /* We have to get the type_main_variant here (and pass that to the
3609 `user_def_type_attribute' routine) because the ..._TYPE node we
3610 have might simply be a *copy* of some original type node (where
3611 the copy was created to help us keep track of typedef names)
3612 and that copy might have a different TYPE_UID from the original
3613 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3614 is labeling a given type DIE for future reference, it always and
3615 only creates labels for DIEs representing *main variants*, and it
3616 never even knows about non-main-variants.) */
3617 user_def_type_attribute (type_main_variant (type));
3621 /* Given a tree pointer to a struct, class, union, or enum type node, return
3622 a pointer to the (string) tag name for the given type, or zero if the
3623 type was declared without a tag. */
3625 static const char *
3626 type_tag (type)
3627 register tree type;
3629 register const char *name = 0;
3631 if (TYPE_NAME (type) != 0)
3633 register tree t = 0;
3635 /* Find the IDENTIFIER_NODE for the type name. */
3636 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3637 t = TYPE_NAME (type);
3639 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3640 a TYPE_DECL node, regardless of whether or not a `typedef' was
3641 involved. */
3642 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3643 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3644 t = DECL_NAME (TYPE_NAME (type));
3646 /* Now get the name as a string, or invent one. */
3647 if (t != 0)
3648 name = IDENTIFIER_POINTER (t);
3651 return (name == 0 || *name == '\0') ? 0 : name;
3654 static inline void
3655 dienum_push ()
3657 /* Start by checking if the pending_sibling_stack needs to be expanded.
3658 If necessary, expand it. */
3660 if (pending_siblings == pending_siblings_allocated)
3662 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3663 pending_sibling_stack
3664 = (unsigned *) xrealloc (pending_sibling_stack,
3665 pending_siblings_allocated * sizeof(unsigned));
3668 pending_siblings++;
3669 NEXT_DIE_NUM = next_unused_dienum++;
3672 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3673 NEXT_DIE_NUM. */
3675 static inline void
3676 dienum_pop ()
3678 pending_siblings--;
3681 static inline tree
3682 member_declared_type (member)
3683 register tree member;
3685 return (DECL_BIT_FIELD_TYPE (member))
3686 ? DECL_BIT_FIELD_TYPE (member)
3687 : TREE_TYPE (member);
3690 /* Get the function's label, as described by its RTL.
3691 This may be different from the DECL_NAME name used
3692 in the source file. */
3694 static const char *
3695 function_start_label (decl)
3696 register tree decl;
3698 rtx x;
3699 const char *fnname;
3701 x = DECL_RTL (decl);
3702 if (GET_CODE (x) != MEM)
3703 abort ();
3704 x = XEXP (x, 0);
3705 if (GET_CODE (x) != SYMBOL_REF)
3706 abort ();
3707 fnname = XSTR (x, 0);
3708 return fnname;
3712 /******************************* DIEs ************************************/
3714 /* Output routines for individual types of DIEs. */
3716 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3718 static void
3719 output_array_type_die (arg)
3720 register void *arg;
3722 register tree type = arg;
3724 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3725 sibling_attribute ();
3726 equate_type_number_to_die_number (type);
3727 member_attribute (TYPE_CONTEXT (type));
3729 /* I believe that we can default the array ordering. SDB will probably
3730 do the right things even if AT_ordering is not present. It's not
3731 even an issue until we start to get into multidimensional arrays
3732 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3733 dimensional arrays, then we'll have to put the AT_ordering attribute
3734 back in. (But if and when we find out that we need to put these in,
3735 we will only do so for multidimensional arrays. After all, we don't
3736 want to waste space in the .debug section now do we?) */
3738 #ifdef USE_ORDERING_ATTRIBUTE
3739 ordering_attribute (ORD_row_major);
3740 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3742 subscript_data_attribute (type);
3745 static void
3746 output_set_type_die (arg)
3747 register void *arg;
3749 register tree type = arg;
3751 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3752 sibling_attribute ();
3753 equate_type_number_to_die_number (type);
3754 member_attribute (TYPE_CONTEXT (type));
3755 type_attribute (TREE_TYPE (type), 0, 0);
3758 #if 0
3759 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3761 static void
3762 output_entry_point_die (arg)
3763 register void *arg;
3765 register tree decl = arg;
3766 register tree origin = decl_ultimate_origin (decl);
3768 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3769 sibling_attribute ();
3770 dienum_push ();
3771 if (origin != NULL)
3772 abstract_origin_attribute (origin);
3773 else
3775 name_and_src_coords_attributes (decl);
3776 member_attribute (DECL_CONTEXT (decl));
3777 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3779 if (DECL_ABSTRACT (decl))
3780 equate_decl_number_to_die_number (decl);
3781 else
3782 low_pc_attribute (function_start_label (decl));
3784 #endif
3786 /* Output a DIE to represent an inlined instance of an enumeration type. */
3788 static void
3789 output_inlined_enumeration_type_die (arg)
3790 register void *arg;
3792 register tree type = arg;
3794 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3795 sibling_attribute ();
3796 if (!TREE_ASM_WRITTEN (type))
3797 abort ();
3798 abstract_origin_attribute (type);
3801 /* Output a DIE to represent an inlined instance of a structure type. */
3803 static void
3804 output_inlined_structure_type_die (arg)
3805 register void *arg;
3807 register tree type = arg;
3809 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3810 sibling_attribute ();
3811 if (!TREE_ASM_WRITTEN (type))
3812 abort ();
3813 abstract_origin_attribute (type);
3816 /* Output a DIE to represent an inlined instance of a union type. */
3818 static void
3819 output_inlined_union_type_die (arg)
3820 register void *arg;
3822 register tree type = arg;
3824 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3825 sibling_attribute ();
3826 if (!TREE_ASM_WRITTEN (type))
3827 abort ();
3828 abstract_origin_attribute (type);
3831 /* Output a DIE to represent an enumeration type. Note that these DIEs
3832 include all of the information about the enumeration values also.
3833 This information is encoded into the element_list attribute. */
3835 static void
3836 output_enumeration_type_die (arg)
3837 register void *arg;
3839 register tree type = arg;
3841 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3842 sibling_attribute ();
3843 equate_type_number_to_die_number (type);
3844 name_attribute (type_tag (type));
3845 member_attribute (TYPE_CONTEXT (type));
3847 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3848 given enum type is incomplete, do not generate the AT_byte_size
3849 attribute or the AT_element_list attribute. */
3851 if (COMPLETE_TYPE_P (type))
3853 byte_size_attribute (type);
3854 element_list_attribute (TYPE_FIELDS (type));
3858 /* Output a DIE to represent either a real live formal parameter decl or
3859 to represent just the type of some formal parameter position in some
3860 function type.
3862 Note that this routine is a bit unusual because its argument may be
3863 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3864 represents an inlining of some PARM_DECL) or else some sort of a
3865 ..._TYPE node. If it's the former then this function is being called
3866 to output a DIE to represent a formal parameter object (or some inlining
3867 thereof). If it's the latter, then this function is only being called
3868 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3869 formal argument type of some subprogram type. */
3871 static void
3872 output_formal_parameter_die (arg)
3873 register void *arg;
3875 register tree node = arg;
3877 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3878 sibling_attribute ();
3880 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3882 case 'd': /* We were called with some kind of a ..._DECL node. */
3884 register tree origin = decl_ultimate_origin (node);
3886 if (origin != NULL)
3887 abstract_origin_attribute (origin);
3888 else
3890 name_and_src_coords_attributes (node);
3891 type_attribute (TREE_TYPE (node),
3892 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3894 if (DECL_ABSTRACT (node))
3895 equate_decl_number_to_die_number (node);
3896 else
3897 location_or_const_value_attribute (node);
3899 break;
3901 case 't': /* We were called with some kind of a ..._TYPE node. */
3902 type_attribute (node, 0, 0);
3903 break;
3905 default:
3906 abort (); /* Should never happen. */
3910 /* Output a DIE to represent a declared function (either file-scope
3911 or block-local) which has "external linkage" (according to ANSI-C). */
3913 static void
3914 output_global_subroutine_die (arg)
3915 register void *arg;
3917 register tree decl = arg;
3918 register tree origin = decl_ultimate_origin (decl);
3920 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3921 sibling_attribute ();
3922 dienum_push ();
3923 if (origin != NULL)
3924 abstract_origin_attribute (origin);
3925 else
3927 register tree type = TREE_TYPE (decl);
3929 name_and_src_coords_attributes (decl);
3930 inline_attribute (decl);
3931 prototyped_attribute (type);
3932 member_attribute (DECL_CONTEXT (decl));
3933 type_attribute (TREE_TYPE (type), 0, 0);
3934 pure_or_virtual_attribute (decl);
3936 if (DECL_ABSTRACT (decl))
3937 equate_decl_number_to_die_number (decl);
3938 else
3940 if (! DECL_EXTERNAL (decl) && ! in_class
3941 && decl == current_function_decl)
3943 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3945 low_pc_attribute (function_start_label (decl));
3946 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3947 high_pc_attribute (label);
3948 if (use_gnu_debug_info_extensions)
3950 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3951 body_begin_attribute (label);
3952 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3953 body_end_attribute (label);
3959 /* Output a DIE to represent a declared data object (either file-scope
3960 or block-local) which has "external linkage" (according to ANSI-C). */
3962 static void
3963 output_global_variable_die (arg)
3964 register void *arg;
3966 register tree decl = arg;
3967 register tree origin = decl_ultimate_origin (decl);
3969 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3970 sibling_attribute ();
3971 if (origin != NULL)
3972 abstract_origin_attribute (origin);
3973 else
3975 name_and_src_coords_attributes (decl);
3976 member_attribute (DECL_CONTEXT (decl));
3977 type_attribute (TREE_TYPE (decl),
3978 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3980 if (DECL_ABSTRACT (decl))
3981 equate_decl_number_to_die_number (decl);
3982 else
3984 if (! DECL_EXTERNAL (decl) && ! in_class
3985 && current_function_decl == decl_function_context (decl))
3986 location_or_const_value_attribute (decl);
3990 static void
3991 output_label_die (arg)
3992 register void *arg;
3994 register tree decl = arg;
3995 register tree origin = decl_ultimate_origin (decl);
3997 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3998 sibling_attribute ();
3999 if (origin != NULL)
4000 abstract_origin_attribute (origin);
4001 else
4002 name_and_src_coords_attributes (decl);
4003 if (DECL_ABSTRACT (decl))
4004 equate_decl_number_to_die_number (decl);
4005 else
4007 register rtx insn = DECL_RTL (decl);
4009 /* Deleted labels are programmer specified labels which have been
4010 eliminated because of various optimisations. We still emit them
4011 here so that it is possible to put breakpoints on them. */
4012 if (GET_CODE (insn) == CODE_LABEL
4013 || ((GET_CODE (insn) == NOTE
4014 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
4016 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4018 /* When optimization is enabled (via -O) some parts of the compiler
4019 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
4020 represent source-level labels which were explicitly declared by
4021 the user. This really shouldn't be happening though, so catch
4022 it if it ever does happen. */
4024 if (INSN_DELETED_P (insn))
4025 abort (); /* Should never happen. */
4027 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
4028 low_pc_attribute (label);
4033 static void
4034 output_lexical_block_die (arg)
4035 register void *arg;
4037 register tree stmt = arg;
4039 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
4040 sibling_attribute ();
4041 dienum_push ();
4042 if (! BLOCK_ABSTRACT (stmt))
4044 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4045 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4047 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4048 low_pc_attribute (begin_label);
4049 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4050 high_pc_attribute (end_label);
4054 static void
4055 output_inlined_subroutine_die (arg)
4056 register void *arg;
4058 register tree stmt = arg;
4060 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
4061 sibling_attribute ();
4062 dienum_push ();
4063 abstract_origin_attribute (block_ultimate_origin (stmt));
4064 if (! BLOCK_ABSTRACT (stmt))
4066 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4067 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4069 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4070 low_pc_attribute (begin_label);
4071 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4072 high_pc_attribute (end_label);
4076 /* Output a DIE to represent a declared data object (either file-scope
4077 or block-local) which has "internal linkage" (according to ANSI-C). */
4079 static void
4080 output_local_variable_die (arg)
4081 register void *arg;
4083 register tree decl = arg;
4084 register tree origin = decl_ultimate_origin (decl);
4086 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
4087 sibling_attribute ();
4088 if (origin != NULL)
4089 abstract_origin_attribute (origin);
4090 else
4092 name_and_src_coords_attributes (decl);
4093 member_attribute (DECL_CONTEXT (decl));
4094 type_attribute (TREE_TYPE (decl),
4095 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4097 if (DECL_ABSTRACT (decl))
4098 equate_decl_number_to_die_number (decl);
4099 else
4100 location_or_const_value_attribute (decl);
4103 static void
4104 output_member_die (arg)
4105 register void *arg;
4107 register tree decl = arg;
4109 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
4110 sibling_attribute ();
4111 name_and_src_coords_attributes (decl);
4112 member_attribute (DECL_CONTEXT (decl));
4113 type_attribute (member_declared_type (decl),
4114 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4115 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
4117 byte_size_attribute (decl);
4118 bit_size_attribute (decl);
4119 bit_offset_attribute (decl);
4121 data_member_location_attribute (decl);
4124 #if 0
4125 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
4126 modified types instead.
4128 We keep this code here just in case these types of DIEs may be
4129 needed to represent certain things in other languages (e.g. Pascal)
4130 someday. */
4132 static void
4133 output_pointer_type_die (arg)
4134 register void *arg;
4136 register tree type = arg;
4138 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
4139 sibling_attribute ();
4140 equate_type_number_to_die_number (type);
4141 member_attribute (TYPE_CONTEXT (type));
4142 type_attribute (TREE_TYPE (type), 0, 0);
4145 static void
4146 output_reference_type_die (arg)
4147 register void *arg;
4149 register tree type = arg;
4151 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
4152 sibling_attribute ();
4153 equate_type_number_to_die_number (type);
4154 member_attribute (TYPE_CONTEXT (type));
4155 type_attribute (TREE_TYPE (type), 0, 0);
4157 #endif
4159 static void
4160 output_ptr_to_mbr_type_die (arg)
4161 register void *arg;
4163 register tree type = arg;
4165 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
4166 sibling_attribute ();
4167 equate_type_number_to_die_number (type);
4168 member_attribute (TYPE_CONTEXT (type));
4169 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
4170 type_attribute (TREE_TYPE (type), 0, 0);
4173 static void
4174 output_compile_unit_die (arg)
4175 register void *arg;
4177 register const char *main_input_filename = arg;
4179 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
4180 sibling_attribute ();
4181 dienum_push ();
4182 name_attribute (main_input_filename);
4185 char producer[250];
4187 sprintf (producer, "%s %s", language_string, version_string);
4188 producer_attribute (producer);
4191 if (strcmp (language_string, "GNU C++") == 0)
4192 language_attribute (LANG_C_PLUS_PLUS);
4193 else if (strcmp (language_string, "GNU Ada") == 0)
4194 language_attribute (LANG_ADA83);
4195 else if (strcmp (language_string, "GNU F77") == 0)
4196 language_attribute (LANG_FORTRAN77);
4197 else if (strcmp (language_string, "GNU Pascal") == 0)
4198 language_attribute (LANG_PASCAL83);
4199 else if (strcmp (language_string, "GNU Java") == 0)
4200 language_attribute (LANG_JAVA);
4201 else if (flag_traditional)
4202 language_attribute (LANG_C);
4203 else
4204 language_attribute (LANG_C89);
4205 low_pc_attribute (TEXT_BEGIN_LABEL);
4206 high_pc_attribute (TEXT_END_LABEL);
4207 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4208 stmt_list_attribute (LINE_BEGIN_LABEL);
4209 last_filename = xstrdup (main_input_filename);
4212 const char *wd = getpwd ();
4213 if (wd)
4214 comp_dir_attribute (wd);
4217 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
4219 sf_names_attribute (SFNAMES_BEGIN_LABEL);
4220 src_info_attribute (SRCINFO_BEGIN_LABEL);
4221 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4222 mac_info_attribute (MACINFO_BEGIN_LABEL);
4226 static void
4227 output_string_type_die (arg)
4228 register void *arg;
4230 register tree type = arg;
4232 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
4233 sibling_attribute ();
4234 equate_type_number_to_die_number (type);
4235 member_attribute (TYPE_CONTEXT (type));
4236 /* this is a fixed length string */
4237 byte_size_attribute (type);
4240 static void
4241 output_inheritance_die (arg)
4242 register void *arg;
4244 register tree binfo = arg;
4246 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
4247 sibling_attribute ();
4248 type_attribute (BINFO_TYPE (binfo), 0, 0);
4249 data_member_location_attribute (binfo);
4250 if (TREE_VIA_VIRTUAL (binfo))
4252 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
4253 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4255 if (TREE_VIA_PUBLIC (binfo))
4257 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
4258 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4260 else if (TREE_VIA_PROTECTED (binfo))
4262 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
4263 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4267 static void
4268 output_structure_type_die (arg)
4269 register void *arg;
4271 register tree type = arg;
4273 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
4274 sibling_attribute ();
4275 equate_type_number_to_die_number (type);
4276 name_attribute (type_tag (type));
4277 member_attribute (TYPE_CONTEXT (type));
4279 /* If this type has been completed, then give it a byte_size attribute
4280 and prepare to give a list of members. Otherwise, don't do either of
4281 these things. In the latter case, we will not be generating a list
4282 of members (since we don't have any idea what they might be for an
4283 incomplete type). */
4285 if (COMPLETE_TYPE_P (type))
4287 dienum_push ();
4288 byte_size_attribute (type);
4292 /* Output a DIE to represent a declared function (either file-scope
4293 or block-local) which has "internal linkage" (according to ANSI-C). */
4295 static void
4296 output_local_subroutine_die (arg)
4297 register void *arg;
4299 register tree decl = arg;
4300 register tree origin = decl_ultimate_origin (decl);
4302 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
4303 sibling_attribute ();
4304 dienum_push ();
4305 if (origin != NULL)
4306 abstract_origin_attribute (origin);
4307 else
4309 register tree type = TREE_TYPE (decl);
4311 name_and_src_coords_attributes (decl);
4312 inline_attribute (decl);
4313 prototyped_attribute (type);
4314 member_attribute (DECL_CONTEXT (decl));
4315 type_attribute (TREE_TYPE (type), 0, 0);
4316 pure_or_virtual_attribute (decl);
4318 if (DECL_ABSTRACT (decl))
4319 equate_decl_number_to_die_number (decl);
4320 else
4322 /* Avoid getting screwed up in cases where a function was declared
4323 static but where no definition was ever given for it. */
4325 if (TREE_ASM_WRITTEN (decl))
4327 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4328 low_pc_attribute (function_start_label (decl));
4329 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4330 high_pc_attribute (label);
4331 if (use_gnu_debug_info_extensions)
4333 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
4334 body_begin_attribute (label);
4335 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
4336 body_end_attribute (label);
4342 static void
4343 output_subroutine_type_die (arg)
4344 register void *arg;
4346 register tree type = arg;
4347 register tree return_type = TREE_TYPE (type);
4349 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
4350 sibling_attribute ();
4351 dienum_push ();
4352 equate_type_number_to_die_number (type);
4353 prototyped_attribute (type);
4354 member_attribute (TYPE_CONTEXT (type));
4355 type_attribute (return_type, 0, 0);
4358 static void
4359 output_typedef_die (arg)
4360 register void *arg;
4362 register tree decl = arg;
4363 register tree origin = decl_ultimate_origin (decl);
4365 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
4366 sibling_attribute ();
4367 if (origin != NULL)
4368 abstract_origin_attribute (origin);
4369 else
4371 name_and_src_coords_attributes (decl);
4372 member_attribute (DECL_CONTEXT (decl));
4373 type_attribute (TREE_TYPE (decl),
4374 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4376 if (DECL_ABSTRACT (decl))
4377 equate_decl_number_to_die_number (decl);
4380 static void
4381 output_union_type_die (arg)
4382 register void *arg;
4384 register tree type = arg;
4386 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
4387 sibling_attribute ();
4388 equate_type_number_to_die_number (type);
4389 name_attribute (type_tag (type));
4390 member_attribute (TYPE_CONTEXT (type));
4392 /* If this type has been completed, then give it a byte_size attribute
4393 and prepare to give a list of members. Otherwise, don't do either of
4394 these things. In the latter case, we will not be generating a list
4395 of members (since we don't have any idea what they might be for an
4396 incomplete type). */
4398 if (COMPLETE_TYPE_P (type))
4400 dienum_push ();
4401 byte_size_attribute (type);
4405 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
4406 at the end of an (ANSI prototyped) formal parameters list. */
4408 static void
4409 output_unspecified_parameters_die (arg)
4410 register void *arg;
4412 register tree decl_or_type = arg;
4414 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
4415 sibling_attribute ();
4417 /* This kludge is here only for the sake of being compatible with what
4418 the USL CI5 C compiler does. The specification of Dwarf Version 1
4419 doesn't say that TAG_unspecified_parameters DIEs should contain any
4420 attributes other than the AT_sibling attribute, but they are certainly
4421 allowed to contain additional attributes, and the CI5 compiler
4422 generates AT_name, AT_fund_type, and AT_location attributes within
4423 TAG_unspecified_parameters DIEs which appear in the child lists for
4424 DIEs representing function definitions, so we do likewise here. */
4426 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
4428 name_attribute ("...");
4429 fund_type_attribute (FT_pointer);
4430 /* location_attribute (?); */
4434 static void
4435 output_padded_null_die (arg)
4436 register void *arg ATTRIBUTE_UNUSED;
4438 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
4441 /*************************** end of DIEs *********************************/
4443 /* Generate some type of DIE. This routine generates the generic outer
4444 wrapper stuff which goes around all types of DIE's (regardless of their
4445 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
4446 DIE-length word, followed by the guts of the DIE itself. After the guts
4447 of the DIE, there must always be a terminator label for the DIE. */
4449 static void
4450 output_die (die_specific_output_function, param)
4451 register void (*die_specific_output_function) PARAMS ((void *));
4452 register void *param;
4454 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4455 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4457 current_dienum = NEXT_DIE_NUM;
4458 NEXT_DIE_NUM = next_unused_dienum;
4460 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4461 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4463 /* Write a label which will act as the name for the start of this DIE. */
4465 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4467 /* Write the DIE-length word. */
4469 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4471 /* Fill in the guts of the DIE. */
4473 next_unused_dienum++;
4474 die_specific_output_function (param);
4476 /* Write a label which will act as the name for the end of this DIE. */
4478 ASM_OUTPUT_LABEL (asm_out_file, end_label);
4481 static void
4482 end_sibling_chain ()
4484 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4486 current_dienum = NEXT_DIE_NUM;
4487 NEXT_DIE_NUM = next_unused_dienum;
4489 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4491 /* Write a label which will act as the name for the start of this DIE. */
4493 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4495 /* Write the DIE-length word. */
4497 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4499 dienum_pop ();
4502 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4503 TAG_unspecified_parameters DIE) to represent the types of the formal
4504 parameters as specified in some function type specification (except
4505 for those which appear as part of a function *definition*).
4507 Note that we must be careful here to output all of the parameter
4508 DIEs *before* we output any DIEs needed to represent the types of
4509 the formal parameters. This keeps svr4 SDB happy because it
4510 (incorrectly) thinks that the first non-parameter DIE it sees ends
4511 the formal parameter list. */
4513 static void
4514 output_formal_types (function_or_method_type)
4515 register tree function_or_method_type;
4517 register tree link;
4518 register tree formal_type = NULL;
4519 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4521 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4522 get bogus recursion when outputting tagged types local to a
4523 function declaration. */
4524 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4525 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4527 /* In the case where we are generating a formal types list for a C++
4528 non-static member function type, skip over the first thing on the
4529 TYPE_ARG_TYPES list because it only represents the type of the
4530 hidden `this pointer'. The debugger should be able to figure
4531 out (without being explicitly told) that this non-static member
4532 function type takes a `this pointer' and should be able to figure
4533 what the type of that hidden parameter is from the AT_member
4534 attribute of the parent TAG_subroutine_type DIE. */
4536 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4537 first_parm_type = TREE_CHAIN (first_parm_type);
4539 /* Make our first pass over the list of formal parameter types and output
4540 a TAG_formal_parameter DIE for each one. */
4542 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4544 formal_type = TREE_VALUE (link);
4545 if (formal_type == void_type_node)
4546 break;
4548 /* Output a (nameless) DIE to represent the formal parameter itself. */
4550 output_die (output_formal_parameter_die, formal_type);
4553 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4554 DIE to the end of the parameter list. */
4556 if (formal_type != void_type_node)
4557 output_die (output_unspecified_parameters_die, function_or_method_type);
4559 /* Make our second (and final) pass over the list of formal parameter types
4560 and output DIEs to represent those types (as necessary). */
4562 for (link = TYPE_ARG_TYPES (function_or_method_type);
4563 link;
4564 link = TREE_CHAIN (link))
4566 formal_type = TREE_VALUE (link);
4567 if (formal_type == void_type_node)
4568 break;
4570 output_type (formal_type, function_or_method_type);
4573 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4576 /* Remember a type in the pending_types_list. */
4578 static void
4579 pend_type (type)
4580 register tree type;
4582 if (pending_types == pending_types_allocated)
4584 pending_types_allocated += PENDING_TYPES_INCREMENT;
4585 pending_types_list
4586 = (tree *) xrealloc (pending_types_list,
4587 sizeof (tree) * pending_types_allocated);
4589 pending_types_list[pending_types++] = type;
4591 /* Mark the pending type as having been output already (even though
4592 it hasn't been). This prevents the type from being added to the
4593 pending_types_list more than once. */
4595 TREE_ASM_WRITTEN (type) = 1;
4598 /* Return non-zero if it is legitimate to output DIEs to represent a
4599 given type while we are generating the list of child DIEs for some
4600 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4602 See the comments within the function for a description of when it is
4603 considered legitimate to output DIEs for various kinds of types.
4605 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4606 or it may point to a BLOCK node (for types local to a block), or to a
4607 FUNCTION_DECL node (for types local to the heading of some function
4608 definition), or to a FUNCTION_TYPE node (for types local to the
4609 prototyped parameter list of a function type specification), or to a
4610 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4611 (in the case of C++ nested types).
4613 The `scope' parameter should likewise be NULL or should point to a
4614 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4615 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4617 This function is used only for deciding when to "pend" and when to
4618 "un-pend" types to/from the pending_types_list.
4620 Note that we sometimes make use of this "type pending" feature in a
4621 rather twisted way to temporarily delay the production of DIEs for the
4622 types of formal parameters. (We do this just to make svr4 SDB happy.)
4623 It order to delay the production of DIEs representing types of formal
4624 parameters, callers of this function supply `fake_containing_scope' as
4625 the `scope' parameter to this function. Given that fake_containing_scope
4626 is a tagged type which is *not* the containing scope for *any* other type,
4627 the desired effect is achieved, i.e. output of DIEs representing types
4628 is temporarily suspended, and any type DIEs which would have otherwise
4629 been output are instead placed onto the pending_types_list. Later on,
4630 we force these (temporarily pended) types to be output simply by calling
4631 `output_pending_types_for_scope' with an actual argument equal to the
4632 true scope of the types we temporarily pended. */
4634 static inline int
4635 type_ok_for_scope (type, scope)
4636 register tree type;
4637 register tree scope;
4639 /* Tagged types (i.e. struct, union, and enum types) must always be
4640 output only in the scopes where they actually belong (or else the
4641 scoping of their own tag names and the scoping of their member
4642 names will be incorrect). Non-tagged-types on the other hand can
4643 generally be output anywhere, except that svr4 SDB really doesn't
4644 want to see them nested within struct or union types, so here we
4645 say it is always OK to immediately output any such a (non-tagged)
4646 type, so long as we are not within such a context. Note that the
4647 only kinds of non-tagged types which we will be dealing with here
4648 (for C and C++ anyway) will be array types and function types. */
4650 return is_tagged_type (type)
4651 ? (TYPE_CONTEXT (type) == scope
4652 /* Ignore namespaces for the moment. */
4653 || (scope == NULL_TREE
4654 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4655 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4656 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4657 : (scope == NULL_TREE || ! is_tagged_type (scope));
4660 /* Output any pending types (from the pending_types list) which we can output
4661 now (taking into account the scope that we are working on now).
4663 For each type output, remove the given type from the pending_types_list
4664 *before* we try to output it.
4666 Note that we have to process the list in beginning-to-end order,
4667 because the call made here to output_type may cause yet more types
4668 to be added to the end of the list, and we may have to output some
4669 of them too. */
4671 static void
4672 output_pending_types_for_scope (containing_scope)
4673 register tree containing_scope;
4675 register unsigned i;
4677 for (i = 0; i < pending_types; )
4679 register tree type = pending_types_list[i];
4681 if (type_ok_for_scope (type, containing_scope))
4683 register tree *mover;
4684 register tree *limit;
4686 pending_types--;
4687 limit = &pending_types_list[pending_types];
4688 for (mover = &pending_types_list[i]; mover < limit; mover++)
4689 *mover = *(mover+1);
4691 /* Un-mark the type as having been output already (because it
4692 hasn't been, really). Then call output_type to generate a
4693 Dwarf representation of it. */
4695 TREE_ASM_WRITTEN (type) = 0;
4696 output_type (type, containing_scope);
4698 /* Don't increment the loop counter in this case because we
4699 have shifted all of the subsequent pending types down one
4700 element in the pending_types_list array. */
4702 else
4703 i++;
4707 /* Remember a type in the incomplete_types_list. */
4709 static void
4710 add_incomplete_type (type)
4711 tree type;
4713 if (incomplete_types == incomplete_types_allocated)
4715 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4716 incomplete_types_list
4717 = (tree *) xrealloc (incomplete_types_list,
4718 sizeof (tree) * incomplete_types_allocated);
4721 incomplete_types_list[incomplete_types++] = type;
4724 /* Walk through the list of incomplete types again, trying once more to
4725 emit full debugging info for them. */
4727 static void
4728 retry_incomplete_types ()
4730 register tree type;
4732 finalizing = 1;
4733 while (incomplete_types)
4735 --incomplete_types;
4736 type = incomplete_types_list[incomplete_types];
4737 output_type (type, NULL_TREE);
4741 static void
4742 output_type (type, containing_scope)
4743 register tree type;
4744 register tree containing_scope;
4746 if (type == 0 || type == error_mark_node)
4747 return;
4749 /* We are going to output a DIE to represent the unqualified version of
4750 this type (i.e. without any const or volatile qualifiers) so get
4751 the main variant (i.e. the unqualified version) of this type now. */
4753 type = type_main_variant (type);
4755 if (TREE_ASM_WRITTEN (type))
4757 if (finalizing && AGGREGATE_TYPE_P (type))
4759 register tree member;
4761 /* Some of our nested types might not have been defined when we
4762 were written out before; force them out now. */
4764 for (member = TYPE_FIELDS (type); member;
4765 member = TREE_CHAIN (member))
4766 if (TREE_CODE (member) == TYPE_DECL
4767 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4768 output_type (TREE_TYPE (member), containing_scope);
4770 return;
4773 /* If this is a nested type whose containing class hasn't been
4774 written out yet, writing it out will cover this one, too. */
4776 if (TYPE_CONTEXT (type)
4777 && TYPE_P (TYPE_CONTEXT (type))
4778 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4780 output_type (TYPE_CONTEXT (type), containing_scope);
4781 return;
4784 /* Don't generate any DIEs for this type now unless it is OK to do so
4785 (based upon what `type_ok_for_scope' tells us). */
4787 if (! type_ok_for_scope (type, containing_scope))
4789 pend_type (type);
4790 return;
4793 switch (TREE_CODE (type))
4795 case ERROR_MARK:
4796 break;
4798 case VECTOR_TYPE:
4799 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4800 break;
4802 case POINTER_TYPE:
4803 case REFERENCE_TYPE:
4804 /* Prevent infinite recursion in cases where this is a recursive
4805 type. Recursive types are possible in Ada. */
4806 TREE_ASM_WRITTEN (type) = 1;
4807 /* For these types, all that is required is that we output a DIE
4808 (or a set of DIEs) to represent the "basis" type. */
4809 output_type (TREE_TYPE (type), containing_scope);
4810 break;
4812 case OFFSET_TYPE:
4813 /* This code is used for C++ pointer-to-data-member types. */
4814 /* Output a description of the relevant class type. */
4815 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4816 /* Output a description of the type of the object pointed to. */
4817 output_type (TREE_TYPE (type), containing_scope);
4818 /* Now output a DIE to represent this pointer-to-data-member type
4819 itself. */
4820 output_die (output_ptr_to_mbr_type_die, type);
4821 break;
4823 case SET_TYPE:
4824 output_type (TYPE_DOMAIN (type), containing_scope);
4825 output_die (output_set_type_die, type);
4826 break;
4828 case FILE_TYPE:
4829 output_type (TREE_TYPE (type), containing_scope);
4830 abort (); /* No way to represent these in Dwarf yet! */
4831 break;
4833 case FUNCTION_TYPE:
4834 /* Force out return type (in case it wasn't forced out already). */
4835 output_type (TREE_TYPE (type), containing_scope);
4836 output_die (output_subroutine_type_die, type);
4837 output_formal_types (type);
4838 end_sibling_chain ();
4839 break;
4841 case METHOD_TYPE:
4842 /* Force out return type (in case it wasn't forced out already). */
4843 output_type (TREE_TYPE (type), containing_scope);
4844 output_die (output_subroutine_type_die, type);
4845 output_formal_types (type);
4846 end_sibling_chain ();
4847 break;
4849 case ARRAY_TYPE:
4850 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4852 output_type (TREE_TYPE (type), containing_scope);
4853 output_die (output_string_type_die, type);
4855 else
4857 register tree element_type;
4859 element_type = TREE_TYPE (type);
4860 while (TREE_CODE (element_type) == ARRAY_TYPE)
4861 element_type = TREE_TYPE (element_type);
4863 output_type (element_type, containing_scope);
4864 output_die (output_array_type_die, type);
4866 break;
4868 case ENUMERAL_TYPE:
4869 case RECORD_TYPE:
4870 case UNION_TYPE:
4871 case QUAL_UNION_TYPE:
4873 /* For a non-file-scope tagged type, we can always go ahead and
4874 output a Dwarf description of this type right now, even if
4875 the type in question is still incomplete, because if this
4876 local type *was* ever completed anywhere within its scope,
4877 that complete definition would already have been attached to
4878 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4879 node by the time we reach this point. That's true because of the
4880 way the front-end does its processing of file-scope declarations (of
4881 functions and class types) within which other types might be
4882 nested. The C and C++ front-ends always gobble up such "local
4883 scope" things en-mass before they try to output *any* debugging
4884 information for any of the stuff contained inside them and thus,
4885 we get the benefit here of what is (in effect) a pre-resolution
4886 of forward references to tagged types in local scopes.
4888 Note however that for file-scope tagged types we cannot assume
4889 that such pre-resolution of forward references has taken place.
4890 A given file-scope tagged type may appear to be incomplete when
4891 we reach this point, but it may yet be given a full definition
4892 (at file-scope) later on during compilation. In order to avoid
4893 generating a premature (and possibly incorrect) set of Dwarf
4894 DIEs for such (as yet incomplete) file-scope tagged types, we
4895 generate nothing at all for as-yet incomplete file-scope tagged
4896 types here unless we are making our special "finalization" pass
4897 for file-scope things at the very end of compilation. At that
4898 time, we will certainly know as much about each file-scope tagged
4899 type as we are ever going to know, so at that point in time, we
4900 can safely generate correct Dwarf descriptions for these file-
4901 scope tagged types. */
4903 if (!COMPLETE_TYPE_P (type)
4904 && (TYPE_CONTEXT (type) == NULL
4905 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4906 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4907 && !finalizing)
4909 /* We don't need to do this for function-local types. */
4910 if (! decl_function_context (TYPE_STUB_DECL (type)))
4911 add_incomplete_type (type);
4912 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4915 /* Prevent infinite recursion in cases where the type of some
4916 member of this type is expressed in terms of this type itself. */
4918 TREE_ASM_WRITTEN (type) = 1;
4920 /* Output a DIE to represent the tagged type itself. */
4922 switch (TREE_CODE (type))
4924 case ENUMERAL_TYPE:
4925 output_die (output_enumeration_type_die, type);
4926 return; /* a special case -- nothing left to do so just return */
4928 case RECORD_TYPE:
4929 output_die (output_structure_type_die, type);
4930 break;
4932 case UNION_TYPE:
4933 case QUAL_UNION_TYPE:
4934 output_die (output_union_type_die, type);
4935 break;
4937 default:
4938 abort (); /* Should never happen. */
4941 /* If this is not an incomplete type, output descriptions of
4942 each of its members.
4944 Note that as we output the DIEs necessary to represent the
4945 members of this record or union type, we will also be trying
4946 to output DIEs to represent the *types* of those members.
4947 However the `output_type' function (above) will specifically
4948 avoid generating type DIEs for member types *within* the list
4949 of member DIEs for this (containing) type execpt for those
4950 types (of members) which are explicitly marked as also being
4951 members of this (containing) type themselves. The g++ front-
4952 end can force any given type to be treated as a member of some
4953 other (containing) type by setting the TYPE_CONTEXT of the
4954 given (member) type to point to the TREE node representing the
4955 appropriate (containing) type.
4958 if (COMPLETE_TYPE_P (type))
4960 /* First output info about the base classes. */
4961 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4963 register tree bases = TYPE_BINFO_BASETYPES (type);
4964 register int n_bases = TREE_VEC_LENGTH (bases);
4965 register int i;
4967 for (i = 0; i < n_bases; i++)
4969 tree binfo = TREE_VEC_ELT (bases, i);
4970 output_type (BINFO_TYPE (binfo), containing_scope);
4971 output_die (output_inheritance_die, binfo);
4975 ++in_class;
4978 register tree normal_member;
4980 /* Now output info about the data members and type members. */
4982 for (normal_member = TYPE_FIELDS (type);
4983 normal_member;
4984 normal_member = TREE_CHAIN (normal_member))
4985 output_decl (normal_member, type);
4989 register tree func_member;
4991 /* Now output info about the function members (if any). */
4993 for (func_member = TYPE_METHODS (type);
4994 func_member;
4995 func_member = TREE_CHAIN (func_member))
4997 /* Don't include clones in the member list. */
4998 if (DECL_ABSTRACT_ORIGIN (func_member))
4999 continue;
5001 output_decl (func_member, type);
5005 --in_class;
5007 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
5008 scopes (at least in C++) so we must now output any nested
5009 pending types which are local just to this type. */
5011 output_pending_types_for_scope (type);
5013 end_sibling_chain (); /* Terminate member chain. */
5016 break;
5018 case VOID_TYPE:
5019 case INTEGER_TYPE:
5020 case REAL_TYPE:
5021 case COMPLEX_TYPE:
5022 case BOOLEAN_TYPE:
5023 case CHAR_TYPE:
5024 break; /* No DIEs needed for fundamental types. */
5026 case LANG_TYPE: /* No Dwarf representation currently defined. */
5027 break;
5029 default:
5030 abort ();
5033 TREE_ASM_WRITTEN (type) = 1;
5036 static void
5037 output_tagged_type_instantiation (type)
5038 register tree type;
5040 if (type == 0 || type == error_mark_node)
5041 return;
5043 /* We are going to output a DIE to represent the unqualified version of
5044 this type (i.e. without any const or volatile qualifiers) so make
5045 sure that we have the main variant (i.e. the unqualified version) of
5046 this type now. */
5048 if (type != type_main_variant (type))
5049 abort ();
5051 if (!TREE_ASM_WRITTEN (type))
5052 abort ();
5054 switch (TREE_CODE (type))
5056 case ERROR_MARK:
5057 break;
5059 case ENUMERAL_TYPE:
5060 output_die (output_inlined_enumeration_type_die, type);
5061 break;
5063 case RECORD_TYPE:
5064 output_die (output_inlined_structure_type_die, type);
5065 break;
5067 case UNION_TYPE:
5068 case QUAL_UNION_TYPE:
5069 output_die (output_inlined_union_type_die, type);
5070 break;
5072 default:
5073 abort (); /* Should never happen. */
5077 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
5078 the things which are local to the given block. */
5080 static void
5081 output_block (stmt, depth)
5082 register tree stmt;
5083 int depth;
5085 register int must_output_die = 0;
5086 register tree origin;
5087 register enum tree_code origin_code;
5089 /* Ignore blocks never really used to make RTL. */
5091 if (! stmt || ! TREE_USED (stmt)
5092 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
5093 return;
5095 /* Determine the "ultimate origin" of this block. This block may be an
5096 inlined instance of an inlined instance of inline function, so we
5097 have to trace all of the way back through the origin chain to find
5098 out what sort of node actually served as the original seed for the
5099 creation of the current block. */
5101 origin = block_ultimate_origin (stmt);
5102 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
5104 /* Determine if we need to output any Dwarf DIEs at all to represent this
5105 block. */
5107 if (origin_code == FUNCTION_DECL)
5108 /* The outer scopes for inlinings *must* always be represented. We
5109 generate TAG_inlined_subroutine DIEs for them. (See below.) */
5110 must_output_die = 1;
5111 else
5113 /* In the case where the current block represents an inlining of the
5114 "body block" of an inline function, we must *NOT* output any DIE
5115 for this block because we have already output a DIE to represent
5116 the whole inlined function scope and the "body block" of any
5117 function doesn't really represent a different scope according to
5118 ANSI C rules. So we check here to make sure that this block does
5119 not represent a "body block inlining" before trying to set the
5120 `must_output_die' flag. */
5122 if (! is_body_block (origin ? origin : stmt))
5124 /* Determine if this block directly contains any "significant"
5125 local declarations which we will need to output DIEs for. */
5127 if (debug_info_level > DINFO_LEVEL_TERSE)
5128 /* We are not in terse mode so *any* local declaration counts
5129 as being a "significant" one. */
5130 must_output_die = (BLOCK_VARS (stmt) != NULL);
5131 else
5133 register tree decl;
5135 /* We are in terse mode, so only local (nested) function
5136 definitions count as "significant" local declarations. */
5138 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5139 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
5141 must_output_die = 1;
5142 break;
5148 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
5149 DIE for any block which contains no significant local declarations
5150 at all. Rather, in such cases we just call `output_decls_for_scope'
5151 so that any needed Dwarf info for any sub-blocks will get properly
5152 generated. Note that in terse mode, our definition of what constitutes
5153 a "significant" local declaration gets restricted to include only
5154 inlined function instances and local (nested) function definitions. */
5156 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
5157 /* We don't care about an abstract inlined subroutine. */;
5158 else if (must_output_die)
5160 output_die ((origin_code == FUNCTION_DECL)
5161 ? output_inlined_subroutine_die
5162 : output_lexical_block_die,
5163 stmt);
5164 output_decls_for_scope (stmt, depth);
5165 end_sibling_chain ();
5167 else
5168 output_decls_for_scope (stmt, depth);
5171 /* Output all of the decls declared within a given scope (also called
5172 a `binding contour') and (recursively) all of it's sub-blocks. */
5174 static void
5175 output_decls_for_scope (stmt, depth)
5176 register tree stmt;
5177 int depth;
5179 /* Ignore blocks never really used to make RTL. */
5181 if (! stmt || ! TREE_USED (stmt))
5182 return;
5184 /* Output the DIEs to represent all of the data objects, functions,
5185 typedefs, and tagged types declared directly within this block
5186 but not within any nested sub-blocks. */
5189 register tree decl;
5191 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5192 output_decl (decl, stmt);
5195 output_pending_types_for_scope (stmt);
5197 /* Output the DIEs to represent all sub-blocks (and the items declared
5198 therein) of this block. */
5201 register tree subblocks;
5203 for (subblocks = BLOCK_SUBBLOCKS (stmt);
5204 subblocks;
5205 subblocks = BLOCK_CHAIN (subblocks))
5206 output_block (subblocks, depth + 1);
5210 /* Is this a typedef we can avoid emitting? */
5212 static inline int
5213 is_redundant_typedef (decl)
5214 register tree decl;
5216 if (TYPE_DECL_IS_STUB (decl))
5217 return 1;
5218 if (DECL_ARTIFICIAL (decl)
5219 && DECL_CONTEXT (decl)
5220 && is_tagged_type (DECL_CONTEXT (decl))
5221 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
5222 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
5223 /* Also ignore the artificial member typedef for the class name. */
5224 return 1;
5225 return 0;
5228 /* Output Dwarf .debug information for a decl described by DECL. */
5230 static void
5231 output_decl (decl, containing_scope)
5232 register tree decl;
5233 register tree containing_scope;
5235 /* Make a note of the decl node we are going to be working on. We may
5236 need to give the user the source coordinates of where it appeared in
5237 case we notice (later on) that something about it looks screwy. */
5239 dwarf_last_decl = decl;
5241 if (TREE_CODE (decl) == ERROR_MARK)
5242 return;
5244 /* If a structure is declared within an initialization, e.g. as the
5245 operand of a sizeof, then it will not have a name. We don't want
5246 to output a DIE for it, as the tree nodes are in the temporary obstack */
5248 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5249 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
5250 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
5251 || (TYPE_FIELDS (TREE_TYPE (decl))
5252 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
5253 return;
5255 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5257 if (DECL_IGNORED_P (decl))
5258 return;
5260 switch (TREE_CODE (decl))
5262 case CONST_DECL:
5263 /* The individual enumerators of an enum type get output when we
5264 output the Dwarf representation of the relevant enum type itself. */
5265 break;
5267 case FUNCTION_DECL:
5268 /* If we are in terse mode, don't output any DIEs to represent
5269 mere function declarations. Also, if we are conforming
5270 to the DWARF version 1 specification, don't output DIEs for
5271 mere function declarations. */
5273 if (DECL_INITIAL (decl) == NULL_TREE)
5274 #if (DWARF_VERSION > 1)
5275 if (debug_info_level <= DINFO_LEVEL_TERSE)
5276 #endif
5277 break;
5279 /* Before we describe the FUNCTION_DECL itself, make sure that we
5280 have described its return type. */
5282 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
5285 /* And its containing type. */
5286 register tree origin = decl_class_context (decl);
5287 if (origin)
5288 output_type (origin, containing_scope);
5291 /* If we're emitting an out-of-line copy of an inline function,
5292 set up to refer to the abstract instance emitted from
5293 note_deferral_of_defined_inline_function. */
5294 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
5295 && ! (containing_scope && TYPE_P (containing_scope)))
5296 set_decl_origin_self (decl);
5298 /* If the following DIE will represent a function definition for a
5299 function with "extern" linkage, output a special "pubnames" DIE
5300 label just ahead of the actual DIE. A reference to this label
5301 was already generated in the .debug_pubnames section sub-entry
5302 for this function definition. */
5304 if (TREE_PUBLIC (decl))
5306 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5308 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5309 ASM_OUTPUT_LABEL (asm_out_file, label);
5312 /* Now output a DIE to represent the function itself. */
5314 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
5315 ? output_global_subroutine_die
5316 : output_local_subroutine_die,
5317 decl);
5319 /* Now output descriptions of the arguments for this function.
5320 This gets (unnecessarily?) complex because of the fact that
5321 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
5322 cases where there was a trailing `...' at the end of the formal
5323 parameter list. In order to find out if there was a trailing
5324 ellipsis or not, we must instead look at the type associated
5325 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
5326 If the chain of type nodes hanging off of this FUNCTION_TYPE node
5327 ends with a void_type_node then there should *not* be an ellipsis
5328 at the end. */
5330 /* In the case where we are describing a mere function declaration, all
5331 we need to do here (and all we *can* do here) is to describe
5332 the *types* of its formal parameters. */
5334 if (decl != current_function_decl || in_class)
5335 output_formal_types (TREE_TYPE (decl));
5336 else
5338 /* Generate DIEs to represent all known formal parameters */
5340 register tree arg_decls = DECL_ARGUMENTS (decl);
5341 register tree parm;
5343 /* WARNING! Kludge zone ahead! Here we have a special
5344 hack for svr4 SDB compatibility. Instead of passing the
5345 current FUNCTION_DECL node as the second parameter (i.e.
5346 the `containing_scope' parameter) to `output_decl' (as
5347 we ought to) we instead pass a pointer to our own private
5348 fake_containing_scope node. That node is a RECORD_TYPE
5349 node which NO OTHER TYPE may ever actually be a member of.
5351 This pointer will ultimately get passed into `output_type'
5352 as its `containing_scope' parameter. `Output_type' will
5353 then perform its part in the hack... i.e. it will pend
5354 the type of the formal parameter onto the pending_types
5355 list. Later on, when we are done generating the whole
5356 sequence of formal parameter DIEs for this function
5357 definition, we will un-pend all previously pended types
5358 of formal parameters for this function definition.
5360 This whole kludge prevents any type DIEs from being
5361 mixed in with the formal parameter DIEs. That's good
5362 because svr4 SDB believes that the list of formal
5363 parameter DIEs for a function ends wherever the first
5364 non-formal-parameter DIE appears. Thus, we have to
5365 keep the formal parameter DIEs segregated. They must
5366 all appear (consecutively) at the start of the list of
5367 children for the DIE representing the function definition.
5368 Then (and only then) may we output any additional DIEs
5369 needed to represent the types of these formal parameters.
5373 When generating DIEs, generate the unspecified_parameters
5374 DIE instead if we come across the arg "__builtin_va_alist"
5377 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
5378 if (TREE_CODE (parm) == PARM_DECL)
5380 if (DECL_NAME(parm) &&
5381 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
5382 "__builtin_va_alist") )
5383 output_die (output_unspecified_parameters_die, decl);
5384 else
5385 output_decl (parm, fake_containing_scope);
5389 Now that we have finished generating all of the DIEs to
5390 represent the formal parameters themselves, force out
5391 any DIEs needed to represent their types. We do this
5392 simply by un-pending all previously pended types which
5393 can legitimately go into the chain of children DIEs for
5394 the current FUNCTION_DECL.
5397 output_pending_types_for_scope (decl);
5400 Decide whether we need a unspecified_parameters DIE at the end.
5401 There are 2 more cases to do this for:
5402 1) the ansi ... declaration - this is detectable when the end
5403 of the arg list is not a void_type_node
5404 2) an unprototyped function declaration (not a definition). This
5405 just means that we have no info about the parameters at all.
5409 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
5411 if (fn_arg_types)
5413 /* this is the prototyped case, check for ... */
5414 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
5415 output_die (output_unspecified_parameters_die, decl);
5417 else
5419 /* this is unprototyped, check for undefined (just declaration) */
5420 if (!DECL_INITIAL (decl))
5421 output_die (output_unspecified_parameters_die, decl);
5425 /* Output Dwarf info for all of the stuff within the body of the
5426 function (if it has one - it may be just a declaration). */
5429 register tree outer_scope = DECL_INITIAL (decl);
5431 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
5433 /* Note that here, `outer_scope' is a pointer to the outermost
5434 BLOCK node created to represent a function.
5435 This outermost BLOCK actually represents the outermost
5436 binding contour for the function, i.e. the contour in which
5437 the function's formal parameters and labels get declared.
5439 Curiously, it appears that the front end doesn't actually
5440 put the PARM_DECL nodes for the current function onto the
5441 BLOCK_VARS list for this outer scope. (They are strung
5442 off of the DECL_ARGUMENTS list for the function instead.)
5443 The BLOCK_VARS list for the `outer_scope' does provide us
5444 with a list of the LABEL_DECL nodes for the function however,
5445 and we output DWARF info for those here.
5447 Just within the `outer_scope' there will be a BLOCK node
5448 representing the function's outermost pair of curly braces,
5449 and any blocks used for the base and member initializers of
5450 a C++ constructor function. */
5452 output_decls_for_scope (outer_scope, 0);
5454 /* Finally, force out any pending types which are local to the
5455 outermost block of this function definition. These will
5456 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
5457 node itself. */
5459 output_pending_types_for_scope (decl);
5464 /* Generate a terminator for the list of stuff `owned' by this
5465 function. */
5467 end_sibling_chain ();
5469 break;
5471 case TYPE_DECL:
5472 /* If we are in terse mode, don't generate any DIEs to represent
5473 any actual typedefs. Note that even when we are in terse mode,
5474 we must still output DIEs to represent those tagged types which
5475 are used (directly or indirectly) in the specification of either
5476 a return type or a formal parameter type of some function. */
5478 if (debug_info_level <= DINFO_LEVEL_TERSE)
5479 if (! TYPE_DECL_IS_STUB (decl)
5480 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5481 return;
5483 /* In the special case of a TYPE_DECL node representing
5484 the declaration of some type tag, if the given TYPE_DECL is
5485 marked as having been instantiated from some other (original)
5486 TYPE_DECL node (e.g. one which was generated within the original
5487 definition of an inline function) we have to generate a special
5488 (abbreviated) TAG_structure_type, TAG_union_type, or
5489 TAG_enumeration-type DIE here. */
5491 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5493 output_tagged_type_instantiation (TREE_TYPE (decl));
5494 return;
5497 output_type (TREE_TYPE (decl), containing_scope);
5499 if (! is_redundant_typedef (decl))
5500 /* Output a DIE to represent the typedef itself. */
5501 output_die (output_typedef_die, decl);
5502 break;
5504 case LABEL_DECL:
5505 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5506 output_die (output_label_die, decl);
5507 break;
5509 case VAR_DECL:
5510 /* If we are conforming to the DWARF version 1 specification, don't
5511 generated any DIEs to represent mere external object declarations. */
5513 #if (DWARF_VERSION <= 1)
5514 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5515 break;
5516 #endif
5518 /* If we are in terse mode, don't generate any DIEs to represent
5519 any variable declarations or definitions. */
5521 if (debug_info_level <= DINFO_LEVEL_TERSE)
5522 break;
5524 /* Output any DIEs that are needed to specify the type of this data
5525 object. */
5527 output_type (TREE_TYPE (decl), containing_scope);
5530 /* And its containing type. */
5531 register tree origin = decl_class_context (decl);
5532 if (origin)
5533 output_type (origin, containing_scope);
5536 /* If the following DIE will represent a data object definition for a
5537 data object with "extern" linkage, output a special "pubnames" DIE
5538 label just ahead of the actual DIE. A reference to this label
5539 was already generated in the .debug_pubnames section sub-entry
5540 for this data object definition. */
5542 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5544 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5546 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5547 ASM_OUTPUT_LABEL (asm_out_file, label);
5550 /* Now output the DIE to represent the data object itself. This gets
5551 complicated because of the possibility that the VAR_DECL really
5552 represents an inlined instance of a formal parameter for an inline
5553 function. */
5556 register void (*func) PARAMS ((void *));
5557 register tree origin = decl_ultimate_origin (decl);
5559 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5560 func = output_formal_parameter_die;
5561 else
5563 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5564 func = output_global_variable_die;
5565 else
5566 func = output_local_variable_die;
5568 output_die (func, decl);
5570 break;
5572 case FIELD_DECL:
5573 /* Ignore the nameless fields that are used to skip bits. */
5574 if (DECL_NAME (decl) != 0)
5576 output_type (member_declared_type (decl), containing_scope);
5577 output_die (output_member_die, decl);
5579 break;
5581 case PARM_DECL:
5582 /* Force out the type of this formal, if it was not forced out yet.
5583 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5584 It should be able to grok the presence of type DIEs within a list
5585 of TAG_formal_parameter DIEs, but it doesn't. */
5587 output_type (TREE_TYPE (decl), containing_scope);
5588 output_die (output_formal_parameter_die, decl);
5589 break;
5591 case NAMESPACE_DECL:
5592 /* Ignore for now. */
5593 break;
5595 default:
5596 abort ();
5600 void
5601 dwarfout_file_scope_decl (decl, set_finalizing)
5602 register tree decl;
5603 register int set_finalizing;
5605 if (TREE_CODE (decl) == ERROR_MARK)
5606 return;
5608 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5610 if (DECL_IGNORED_P (decl))
5611 return;
5613 switch (TREE_CODE (decl))
5615 case FUNCTION_DECL:
5617 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5618 a builtin function. Explicit programmer-supplied declarations of
5619 these same functions should NOT be ignored however. */
5621 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5622 return;
5624 /* What we would really like to do here is to filter out all mere
5625 file-scope declarations of file-scope functions which are never
5626 referenced later within this translation unit (and keep all of
5627 ones that *are* referenced later on) but we aren't clairvoyant,
5628 so we have no idea which functions will be referenced in the
5629 future (i.e. later on within the current translation unit).
5630 So here we just ignore all file-scope function declarations
5631 which are not also definitions. If and when the debugger needs
5632 to know something about these functions, it wil have to hunt
5633 around and find the DWARF information associated with the
5634 *definition* of the function.
5636 Note that we can't just check `DECL_EXTERNAL' to find out which
5637 FUNCTION_DECL nodes represent definitions and which ones represent
5638 mere declarations. We have to check `DECL_INITIAL' instead. That's
5639 because the C front-end supports some weird semantics for "extern
5640 inline" function definitions. These can get inlined within the
5641 current translation unit (an thus, we need to generate DWARF info
5642 for their abstract instances so that the DWARF info for the
5643 concrete inlined instances can have something to refer to) but
5644 the compiler never generates any out-of-lines instances of such
5645 things (despite the fact that they *are* definitions). The
5646 important point is that the C front-end marks these "extern inline"
5647 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5648 anyway.
5650 Note that the C++ front-end also plays some similar games for inline
5651 function definitions appearing within include files which also
5652 contain `#pragma interface' pragmas. */
5654 if (DECL_INITIAL (decl) == NULL_TREE)
5655 return;
5657 if (TREE_PUBLIC (decl)
5658 && ! DECL_EXTERNAL (decl)
5659 && ! DECL_ABSTRACT (decl))
5661 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5663 /* Output a .debug_pubnames entry for a public function
5664 defined in this compilation unit. */
5666 fputc ('\n', asm_out_file);
5667 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5668 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5669 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5670 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5671 IDENTIFIER_POINTER (DECL_NAME (decl)));
5672 ASM_OUTPUT_POP_SECTION (asm_out_file);
5675 break;
5677 case VAR_DECL:
5679 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5680 object declaration and if the declaration was never even
5681 referenced from within this entire compilation unit. We
5682 suppress these DIEs in order to save space in the .debug section
5683 (by eliminating entries which are probably useless). Note that
5684 we must not suppress block-local extern declarations (whether
5685 used or not) because that would screw-up the debugger's name
5686 lookup mechanism and cause it to miss things which really ought
5687 to be in scope at a given point. */
5689 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5690 return;
5692 if (TREE_PUBLIC (decl)
5693 && ! DECL_EXTERNAL (decl)
5694 && GET_CODE (DECL_RTL (decl)) == MEM
5695 && ! DECL_ABSTRACT (decl))
5697 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5699 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5701 /* Output a .debug_pubnames entry for a public variable
5702 defined in this compilation unit. */
5704 fputc ('\n', asm_out_file);
5705 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5706 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5707 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5708 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5709 IDENTIFIER_POINTER (DECL_NAME (decl)));
5710 ASM_OUTPUT_POP_SECTION (asm_out_file);
5713 if (DECL_INITIAL (decl) == NULL)
5715 /* Output a .debug_aranges entry for a public variable
5716 which is tentatively defined in this compilation unit. */
5718 fputc ('\n', asm_out_file);
5719 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
5720 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5721 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5722 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5723 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5724 ASM_OUTPUT_POP_SECTION (asm_out_file);
5728 /* If we are in terse mode, don't generate any DIEs to represent
5729 any variable declarations or definitions. */
5731 if (debug_info_level <= DINFO_LEVEL_TERSE)
5732 return;
5734 break;
5736 case TYPE_DECL:
5737 /* Don't bother trying to generate any DIEs to represent any of the
5738 normal built-in types for the language we are compiling, except
5739 in cases where the types in question are *not* DWARF fundamental
5740 types. We make an exception in the case of non-fundamental types
5741 for the sake of objective C (and perhaps C++) because the GNU
5742 front-ends for these languages may in fact create certain "built-in"
5743 types which are (for example) RECORD_TYPEs. In such cases, we
5744 really need to output these (non-fundamental) types because other
5745 DIEs may contain references to them. */
5747 /* Also ignore language dependent types here, because they are probably
5748 also built-in types. If we didn't ignore them, then we would get
5749 references to undefined labels because output_type doesn't support
5750 them. So, for now, we need to ignore them to avoid assembler
5751 errors. */
5753 /* ??? This code is different than the equivalent code in dwarf2out.c.
5754 The dwarf2out.c code is probably more correct. */
5756 if (DECL_SOURCE_LINE (decl) == 0
5757 && (type_is_fundamental (TREE_TYPE (decl))
5758 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5759 return;
5761 /* If we are in terse mode, don't generate any DIEs to represent
5762 any actual typedefs. Note that even when we are in terse mode,
5763 we must still output DIEs to represent those tagged types which
5764 are used (directly or indirectly) in the specification of either
5765 a return type or a formal parameter type of some function. */
5767 if (debug_info_level <= DINFO_LEVEL_TERSE)
5768 if (! TYPE_DECL_IS_STUB (decl)
5769 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5770 return;
5772 break;
5774 default:
5775 return;
5778 fputc ('\n', asm_out_file);
5779 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5780 finalizing = set_finalizing;
5781 output_decl (decl, NULL_TREE);
5783 /* NOTE: The call above to `output_decl' may have caused one or more
5784 file-scope named types (i.e. tagged types) to be placed onto the
5785 pending_types_list. We have to get those types off of that list
5786 at some point, and this is the perfect time to do it. If we didn't
5787 take them off now, they might still be on the list when cc1 finally
5788 exits. That might be OK if it weren't for the fact that when we put
5789 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5790 for these types, and that causes them never to be output unless
5791 `output_pending_types_for_scope' takes them off of the list and un-sets
5792 their TREE_ASM_WRITTEN flags. */
5794 output_pending_types_for_scope (NULL_TREE);
5796 /* The above call should have totally emptied the pending_types_list
5797 if this is not a nested function or class. If this is a nested type,
5798 then the remaining pending_types will be emitted when the containing type
5799 is handled. */
5801 if (! DECL_CONTEXT (decl))
5803 if (pending_types != 0)
5804 abort ();
5807 ASM_OUTPUT_POP_SECTION (asm_out_file);
5809 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5810 current_funcdef_number++;
5813 /* Output a marker (i.e. a label) for the beginning of the generated code
5814 for a lexical block. */
5816 void
5817 dwarfout_begin_block (blocknum)
5818 register unsigned blocknum;
5820 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5822 function_section (current_function_decl);
5823 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5824 ASM_OUTPUT_LABEL (asm_out_file, label);
5827 /* Output a marker (i.e. a label) for the end of the generated code
5828 for a lexical block. */
5830 void
5831 dwarfout_end_block (blocknum)
5832 register unsigned blocknum;
5834 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5836 function_section (current_function_decl);
5837 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5838 ASM_OUTPUT_LABEL (asm_out_file, label);
5841 /* Output a marker (i.e. a label) for the point in the generated code where
5842 the real body of the function begins (after parameters have been moved
5843 to their home locations). */
5845 void
5846 dwarfout_begin_function ()
5848 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5850 if (! use_gnu_debug_info_extensions)
5851 return;
5852 function_section (current_function_decl);
5853 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5854 ASM_OUTPUT_LABEL (asm_out_file, label);
5857 /* Output a marker (i.e. a label) for the point in the generated code where
5858 the real body of the function ends (just before the epilogue code). */
5860 void
5861 dwarfout_end_function ()
5863 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5865 if (! use_gnu_debug_info_extensions)
5866 return;
5867 function_section (current_function_decl);
5868 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5869 ASM_OUTPUT_LABEL (asm_out_file, label);
5872 /* Output a marker (i.e. a label) for the absolute end of the generated code
5873 for a function definition. This gets called *after* the epilogue code
5874 has been generated. */
5876 void
5877 dwarfout_end_epilogue ()
5879 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5881 /* Output a label to mark the endpoint of the code generated for this
5882 function. */
5884 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5885 ASM_OUTPUT_LABEL (asm_out_file, label);
5888 static void
5889 shuffle_filename_entry (new_zeroth)
5890 register filename_entry *new_zeroth;
5892 filename_entry temp_entry;
5893 register filename_entry *limit_p;
5894 register filename_entry *move_p;
5896 if (new_zeroth == &filename_table[0])
5897 return;
5899 temp_entry = *new_zeroth;
5901 /* Shift entries up in the table to make room at [0]. */
5903 limit_p = &filename_table[0];
5904 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5905 *move_p = *(move_p-1);
5907 /* Install the found entry at [0]. */
5909 filename_table[0] = temp_entry;
5912 /* Create a new (string) entry for the .debug_sfnames section. */
5914 static void
5915 generate_new_sfname_entry ()
5917 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5919 fputc ('\n', asm_out_file);
5920 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
5921 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5922 ASM_OUTPUT_LABEL (asm_out_file, label);
5923 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5924 filename_table[0].name
5925 ? filename_table[0].name
5926 : "");
5927 ASM_OUTPUT_POP_SECTION (asm_out_file);
5930 /* Lookup a filename (in the list of filenames that we know about here in
5931 dwarfout.c) and return its "index". The index of each (known) filename
5932 is just a unique number which is associated with only that one filename.
5933 We need such numbers for the sake of generating labels (in the
5934 .debug_sfnames section) and references to those unique labels (in the
5935 .debug_srcinfo and .debug_macinfo sections).
5937 If the filename given as an argument is not found in our current list,
5938 add it to the list and assign it the next available unique index number.
5940 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5941 one), we shuffle the filename found (or added) up to the zeroth entry of
5942 our list of filenames (which is always searched linearly). We do this so
5943 as to optimize the most common case for these filename lookups within
5944 dwarfout.c. The most common case by far is the case where we call
5945 lookup_filename to lookup the very same filename that we did a lookup
5946 on the last time we called lookup_filename. We make sure that this
5947 common case is fast because such cases will constitute 99.9% of the
5948 lookups we ever do (in practice).
5950 If we add a new filename entry to our table, we go ahead and generate
5951 the corresponding entry in the .debug_sfnames section right away.
5952 Doing so allows us to avoid tickling an assembler bug (present in some
5953 m68k assemblers) which yields assembly-time errors in cases where the
5954 difference of two label addresses is taken and where the two labels
5955 are in a section *other* than the one where the difference is being
5956 calculated, and where at least one of the two symbol references is a
5957 forward reference. (This bug could be tickled by our .debug_srcinfo
5958 entries if we don't output their corresponding .debug_sfnames entries
5959 before them.) */
5961 static unsigned
5962 lookup_filename (file_name)
5963 const char *file_name;
5965 register filename_entry *search_p;
5966 register filename_entry *limit_p = &filename_table[ft_entries];
5968 for (search_p = filename_table; search_p < limit_p; search_p++)
5969 if (!strcmp (file_name, search_p->name))
5971 /* When we get here, we have found the filename that we were
5972 looking for in the filename_table. Now we want to make sure
5973 that it gets moved to the zero'th entry in the table (if it
5974 is not already there) so that subsequent attempts to find the
5975 same filename will find it as quickly as possible. */
5977 shuffle_filename_entry (search_p);
5978 return filename_table[0].number;
5981 /* We come here whenever we have a new filename which is not registered
5982 in the current table. Here we add it to the table. */
5984 /* Prepare to add a new table entry by making sure there is enough space
5985 in the table to do so. If not, expand the current table. */
5987 if (ft_entries == ft_entries_allocated)
5989 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5990 filename_table
5991 = (filename_entry *)
5992 xrealloc (filename_table,
5993 ft_entries_allocated * sizeof (filename_entry));
5996 /* Initially, add the new entry at the end of the filename table. */
5998 filename_table[ft_entries].number = ft_entries;
5999 filename_table[ft_entries].name = xstrdup (file_name);
6001 /* Shuffle the new entry into filename_table[0]. */
6003 shuffle_filename_entry (&filename_table[ft_entries]);
6005 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6006 generate_new_sfname_entry ();
6008 ft_entries++;
6009 return filename_table[0].number;
6012 static void
6013 generate_srcinfo_entry (line_entry_num, files_entry_num)
6014 unsigned line_entry_num;
6015 unsigned files_entry_num;
6017 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6019 fputc ('\n', asm_out_file);
6020 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6021 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
6022 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
6023 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
6024 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
6025 ASM_OUTPUT_POP_SECTION (asm_out_file);
6028 void
6029 dwarfout_line (filename, line)
6030 register const char *filename;
6031 register unsigned line;
6033 if (debug_info_level >= DINFO_LEVEL_NORMAL
6034 /* We can't emit line number info for functions in separate sections,
6035 because the assembler can't subtract labels in different sections. */
6036 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
6038 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6039 static unsigned last_line_entry_num = 0;
6040 static unsigned prev_file_entry_num = (unsigned) -1;
6041 register unsigned this_file_entry_num;
6043 function_section (current_function_decl);
6044 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
6045 ASM_OUTPUT_LABEL (asm_out_file, label);
6047 fputc ('\n', asm_out_file);
6049 if (use_gnu_debug_info_extensions)
6050 this_file_entry_num = lookup_filename (filename);
6051 else
6052 this_file_entry_num = (unsigned) -1;
6054 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6055 if (this_file_entry_num != prev_file_entry_num)
6057 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
6059 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
6060 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
6064 register const char *tail = strrchr (filename, '/');
6066 if (tail != NULL)
6067 filename = tail;
6070 fprintf (asm_out_file, "%s%u\t%s %s:%u\n",
6071 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
6072 filename, line);
6073 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6074 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
6075 ASM_OUTPUT_POP_SECTION (asm_out_file);
6077 if (this_file_entry_num != prev_file_entry_num)
6078 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
6079 prev_file_entry_num = this_file_entry_num;
6083 /* Generate an entry in the .debug_macinfo section. */
6085 static void
6086 generate_macinfo_entry (type_and_offset, string)
6087 register const char *type_and_offset;
6088 register const char *string;
6090 if (! use_gnu_debug_info_extensions)
6091 return;
6093 fputc ('\n', asm_out_file);
6094 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6095 fprintf (asm_out_file, "%s%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
6096 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
6097 ASM_OUTPUT_POP_SECTION (asm_out_file);
6100 void
6101 dwarfout_start_new_source_file (filename)
6102 register const char *filename;
6104 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6105 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
6107 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
6108 sprintf (type_and_offset, "0x%08x+%s-%s",
6109 ((unsigned) MACINFO_start << 24),
6110 /* Hack: skip leading '*' . */
6111 (*label == '*') + label,
6112 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
6113 generate_macinfo_entry (type_and_offset, "");
6116 void
6117 dwarfout_resume_previous_source_file (lineno)
6118 register unsigned lineno;
6120 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6122 sprintf (type_and_offset, "0x%08x+%u",
6123 ((unsigned) MACINFO_resume << 24), lineno);
6124 generate_macinfo_entry (type_and_offset, "");
6127 /* Called from check_newline in c-parse.y. The `buffer' parameter
6128 contains the tail part of the directive line, i.e. the part which
6129 is past the initial whitespace, #, whitespace, directive-name,
6130 whitespace part. */
6132 void
6133 dwarfout_define (lineno, buffer)
6134 register unsigned lineno;
6135 register const char *buffer;
6137 static int initialized = 0;
6138 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6140 if (!initialized)
6142 dwarfout_start_new_source_file (primary_filename);
6143 initialized = 1;
6145 sprintf (type_and_offset, "0x%08x+%u",
6146 ((unsigned) MACINFO_define << 24), lineno);
6147 generate_macinfo_entry (type_and_offset, buffer);
6150 /* Called from check_newline in c-parse.y. The `buffer' parameter
6151 contains the tail part of the directive line, i.e. the part which
6152 is past the initial whitespace, #, whitespace, directive-name,
6153 whitespace part. */
6155 void
6156 dwarfout_undef (lineno, buffer)
6157 register unsigned lineno;
6158 register const char *buffer;
6160 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6162 sprintf (type_and_offset, "0x%08x+%u",
6163 ((unsigned) MACINFO_undef << 24), lineno);
6164 generate_macinfo_entry (type_and_offset, buffer);
6167 /* Set up for Dwarf output at the start of compilation. */
6169 void
6170 dwarfout_init (asm_out_file, main_input_filename)
6171 register FILE *asm_out_file;
6172 register const char *main_input_filename;
6174 /* Remember the name of the primary input file. */
6176 primary_filename = main_input_filename;
6178 /* Allocate the initial hunk of the pending_sibling_stack. */
6180 pending_sibling_stack
6181 = (unsigned *)
6182 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
6183 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
6184 pending_siblings = 1;
6186 /* Allocate the initial hunk of the filename_table. */
6188 filename_table
6189 = (filename_entry *)
6190 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
6191 ft_entries_allocated = FT_ENTRIES_INCREMENT;
6192 ft_entries = 0;
6194 /* Allocate the initial hunk of the pending_types_list. */
6196 pending_types_list
6197 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
6198 pending_types_allocated = PENDING_TYPES_INCREMENT;
6199 pending_types = 0;
6201 /* Create an artificial RECORD_TYPE node which we can use in our hack
6202 to get the DIEs representing types of formal parameters to come out
6203 only *after* the DIEs for the formal parameters themselves. */
6205 fake_containing_scope = make_node (RECORD_TYPE);
6207 /* Output a starting label for the .text section. */
6209 fputc ('\n', asm_out_file);
6210 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
6211 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
6212 ASM_OUTPUT_POP_SECTION (asm_out_file);
6214 /* Output a starting label for the .data section. */
6216 fputc ('\n', asm_out_file);
6217 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
6218 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
6219 ASM_OUTPUT_POP_SECTION (asm_out_file);
6221 #if 0 /* GNU C doesn't currently use .data1. */
6222 /* Output a starting label for the .data1 section. */
6224 fputc ('\n', asm_out_file);
6225 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
6226 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
6227 ASM_OUTPUT_POP_SECTION (asm_out_file);
6228 #endif
6230 /* Output a starting label for the .rodata section. */
6232 fputc ('\n', asm_out_file);
6233 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
6234 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
6235 ASM_OUTPUT_POP_SECTION (asm_out_file);
6237 #if 0 /* GNU C doesn't currently use .rodata1. */
6238 /* Output a starting label for the .rodata1 section. */
6240 fputc ('\n', asm_out_file);
6241 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
6242 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
6243 ASM_OUTPUT_POP_SECTION (asm_out_file);
6244 #endif
6246 /* Output a starting label for the .bss section. */
6248 fputc ('\n', asm_out_file);
6249 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
6250 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
6251 ASM_OUTPUT_POP_SECTION (asm_out_file);
6253 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6255 if (use_gnu_debug_info_extensions)
6257 /* Output a starting label and an initial (compilation directory)
6258 entry for the .debug_sfnames section. The starting label will be
6259 referenced by the initial entry in the .debug_srcinfo section. */
6261 fputc ('\n', asm_out_file);
6262 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6263 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
6265 register const char *pwd = getpwd ();
6266 register char *dirname;
6268 if (!pwd)
6269 fatal_io_error ("can't get current directory");
6271 dirname = concat (pwd, "/", NULL);
6272 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
6273 free (dirname);
6275 ASM_OUTPUT_POP_SECTION (asm_out_file);
6278 if (debug_info_level >= DINFO_LEVEL_VERBOSE
6279 && use_gnu_debug_info_extensions)
6281 /* Output a starting label for the .debug_macinfo section. This
6282 label will be referenced by the AT_mac_info attribute in the
6283 TAG_compile_unit DIE. */
6285 fputc ('\n', asm_out_file);
6286 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6287 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
6288 ASM_OUTPUT_POP_SECTION (asm_out_file);
6291 /* Generate the initial entry for the .line section. */
6293 fputc ('\n', asm_out_file);
6294 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6295 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
6296 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
6297 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6298 ASM_OUTPUT_POP_SECTION (asm_out_file);
6300 if (use_gnu_debug_info_extensions)
6302 /* Generate the initial entry for the .debug_srcinfo section. */
6304 fputc ('\n', asm_out_file);
6305 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6306 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
6307 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
6308 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
6309 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6310 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
6311 #ifdef DWARF_TIMESTAMPS
6312 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
6313 #else
6314 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6315 #endif
6316 ASM_OUTPUT_POP_SECTION (asm_out_file);
6319 /* Generate the initial entry for the .debug_pubnames section. */
6321 fputc ('\n', asm_out_file);
6322 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6323 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6324 ASM_OUTPUT_POP_SECTION (asm_out_file);
6326 /* Generate the initial entry for the .debug_aranges section. */
6328 fputc ('\n', asm_out_file);
6329 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6330 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6331 DEBUG_ARANGES_END_LABEL,
6332 DEBUG_ARANGES_BEGIN_LABEL);
6333 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_BEGIN_LABEL);
6334 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 1);
6335 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6336 ASM_OUTPUT_POP_SECTION (asm_out_file);
6339 /* Setup first DIE number == 1. */
6340 NEXT_DIE_NUM = next_unused_dienum++;
6342 /* Generate the initial DIE for the .debug section. Note that the
6343 (string) value given in the AT_name attribute of the TAG_compile_unit
6344 DIE will (typically) be a relative pathname and that this pathname
6345 should be taken as being relative to the directory from which the
6346 compiler was invoked when the given (base) source file was compiled. */
6348 fputc ('\n', asm_out_file);
6349 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6350 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
6351 output_die (output_compile_unit_die, (PTR) main_input_filename);
6352 ASM_OUTPUT_POP_SECTION (asm_out_file);
6354 fputc ('\n', asm_out_file);
6357 /* Output stuff that dwarf requires at the end of every file. */
6359 void
6360 dwarfout_finish ()
6362 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6364 fputc ('\n', asm_out_file);
6365 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6366 retry_incomplete_types ();
6367 fputc ('\n', asm_out_file);
6369 /* Mark the end of the chain of siblings which represent all file-scope
6370 declarations in this compilation unit. */
6372 /* The (null) DIE which represents the terminator for the (sibling linked)
6373 list of file-scope items is *special*. Normally, we would just call
6374 end_sibling_chain at this point in order to output a word with the
6375 value `4' and that word would act as the terminator for the list of
6376 DIEs describing file-scope items. Unfortunately, if we were to simply
6377 do that, the label that would follow this DIE in the .debug section
6378 (i.e. `..D2') would *not* be properly aligned (as it must be on some
6379 machines) to a 4 byte boundary.
6381 In order to force the label `..D2' to get aligned to a 4 byte boundary,
6382 the trick used is to insert extra (otherwise useless) padding bytes
6383 into the (null) DIE that we know must precede the ..D2 label in the
6384 .debug section. The amount of padding required can be anywhere between
6385 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
6386 with the padding) would normally contain the value 4, but now it will
6387 also have to include the padding bytes, so it will instead have some
6388 value in the range 4..7.
6390 Fortunately, the rules of Dwarf say that any DIE whose length word
6391 contains *any* value less than 8 should be treated as a null DIE, so
6392 this trick works out nicely. Clever, eh? Don't give me any credit
6393 (or blame). I didn't think of this scheme. I just conformed to it.
6396 output_die (output_padded_null_die, (void *) 0);
6397 dienum_pop ();
6399 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
6400 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
6401 ASM_OUTPUT_POP_SECTION (asm_out_file);
6403 /* Output a terminator label for the .text section. */
6405 fputc ('\n', asm_out_file);
6406 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
6407 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
6408 ASM_OUTPUT_POP_SECTION (asm_out_file);
6410 /* Output a terminator label for the .data section. */
6412 fputc ('\n', asm_out_file);
6413 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
6414 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
6415 ASM_OUTPUT_POP_SECTION (asm_out_file);
6417 #if 0 /* GNU C doesn't currently use .data1. */
6418 /* Output a terminator label for the .data1 section. */
6420 fputc ('\n', asm_out_file);
6421 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
6422 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
6423 ASM_OUTPUT_POP_SECTION (asm_out_file);
6424 #endif
6426 /* Output a terminator label for the .rodata section. */
6428 fputc ('\n', asm_out_file);
6429 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
6430 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
6431 ASM_OUTPUT_POP_SECTION (asm_out_file);
6433 #if 0 /* GNU C doesn't currently use .rodata1. */
6434 /* Output a terminator label for the .rodata1 section. */
6436 fputc ('\n', asm_out_file);
6437 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
6438 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
6439 ASM_OUTPUT_POP_SECTION (asm_out_file);
6440 #endif
6442 /* Output a terminator label for the .bss section. */
6444 fputc ('\n', asm_out_file);
6445 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
6446 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
6447 ASM_OUTPUT_POP_SECTION (asm_out_file);
6449 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6451 /* Output a terminating entry for the .line section. */
6453 fputc ('\n', asm_out_file);
6454 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6455 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
6456 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6457 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6458 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6459 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
6460 ASM_OUTPUT_POP_SECTION (asm_out_file);
6462 if (use_gnu_debug_info_extensions)
6464 /* Output a terminating entry for the .debug_srcinfo section. */
6466 fputc ('\n', asm_out_file);
6467 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6468 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6469 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6470 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6471 ASM_OUTPUT_POP_SECTION (asm_out_file);
6474 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6476 /* Output terminating entries for the .debug_macinfo section. */
6478 dwarfout_resume_previous_source_file (0);
6480 fputc ('\n', asm_out_file);
6481 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6482 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6483 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6484 ASM_OUTPUT_POP_SECTION (asm_out_file);
6487 /* Generate the terminating entry for the .debug_pubnames section. */
6489 fputc ('\n', asm_out_file);
6490 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6491 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6492 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6493 ASM_OUTPUT_POP_SECTION (asm_out_file);
6495 /* Generate the terminating entries for the .debug_aranges section.
6497 Note that we want to do this only *after* we have output the end
6498 labels (for the various program sections) which we are going to
6499 refer to here. This allows us to work around a bug in the m68k
6500 svr4 assembler. That assembler gives bogus assembly-time errors
6501 if (within any given section) you try to take the difference of
6502 two relocatable symbols, both of which are located within some
6503 other section, and if one (or both?) of the symbols involved is
6504 being forward-referenced. By generating the .debug_aranges
6505 entries at this late point in the assembly output, we skirt the
6506 issue simply by avoiding forward-references.
6509 fputc ('\n', asm_out_file);
6510 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6512 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6513 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6515 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6516 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6518 #if 0 /* GNU C doesn't currently use .data1. */
6519 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6520 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6521 DATA1_BEGIN_LABEL);
6522 #endif
6524 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6525 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6526 RODATA_BEGIN_LABEL);
6528 #if 0 /* GNU C doesn't currently use .rodata1. */
6529 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6530 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6531 RODATA1_BEGIN_LABEL);
6532 #endif
6534 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6535 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6537 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6538 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6540 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_END_LABEL);
6541 ASM_OUTPUT_POP_SECTION (asm_out_file);
6544 /* There should not be any pending types left at the end. We need
6545 this now because it may not have been checked on the last call to
6546 dwarfout_file_scope_decl. */
6547 if (pending_types != 0)
6548 abort ();
6551 #endif /* DWARF_DEBUGGING_INFO */