* c-common.c (decl_attributes): Take a pointer to the node to
[official-gcc.git] / gcc / dwarfout.c
blob3263f107c5f49d3bb65488115fd5c955f6347ba9
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"
580 #include "debug.h"
582 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
583 regarding the GNU implementation of Dwarf. */
585 /* NOTE: In the comments in this file, many references are made to
586 so called "Debugging Information Entries". For the sake of brevity,
587 this term is abbreviated to `DIE' throughout the remainder of this
588 file. */
590 /* Note that the implementation of C++ support herein is (as yet) unfinished.
591 If you want to try to complete it, more power to you. */
593 /* How to start an assembler comment. */
594 #ifndef ASM_COMMENT_START
595 #define ASM_COMMENT_START ";#"
596 #endif
598 /* How to print out a register name. */
599 #ifndef PRINT_REG
600 #define PRINT_REG(RTX, CODE, FILE) \
601 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
602 #endif
604 /* Define a macro which returns non-zero for any tagged type which is
605 used (directly or indirectly) in the specification of either some
606 function's return type or some formal parameter of some function.
607 We use this macro when we are operating in "terse" mode to help us
608 know what tagged types have to be represented in Dwarf (even in
609 terse mode) and which ones don't.
611 A flag bit with this meaning really should be a part of the normal
612 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
613 for these nodes. For now, we have to just fake it. It it safe for
614 us to simply return zero for all complete tagged types (which will
615 get forced out anyway if they were used in the specification of some
616 formal or return type) and non-zero for all incomplete tagged types.
619 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
621 /* Define a macro which returns non-zero for a TYPE_DECL which was
622 implicitly generated for a tagged type.
624 Note that unlike the gcc front end (which generates a NULL named
625 TYPE_DECL node for each complete tagged type, each array type, and
626 each function type node created) the g++ front end generates a
627 _named_ TYPE_DECL node for each tagged type node created.
628 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
629 generate a DW_TAG_typedef DIE for them. */
630 #define TYPE_DECL_IS_STUB(decl) \
631 (DECL_NAME (decl) == NULL \
632 || (DECL_ARTIFICIAL (decl) \
633 && is_tagged_type (TREE_TYPE (decl)) \
634 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
636 extern int flag_traditional;
638 /* Maximum size (in bytes) of an artificially generated label. */
640 #define MAX_ARTIFICIAL_LABEL_BYTES 30
642 /* Structure to keep track of source filenames. */
644 struct filename_entry {
645 unsigned number;
646 const char * name;
649 typedef struct filename_entry filename_entry;
651 /* Pointer to an array of elements, each one having the structure above. */
653 static filename_entry *filename_table;
655 /* Total number of entries in the table (i.e. array) pointed to by
656 `filename_table'. This is the *total* and includes both used and
657 unused slots. */
659 static unsigned ft_entries_allocated;
661 /* Number of entries in the filename_table which are actually in use. */
663 static unsigned ft_entries;
665 /* Size (in elements) of increments by which we may expand the filename
666 table. Actually, a single hunk of space of this size should be enough
667 for most typical programs. */
669 #define FT_ENTRIES_INCREMENT 64
671 /* Local pointer to the name of the main input file. Initialized in
672 dwarfout_init. */
674 static const char *primary_filename;
676 /* Pointer to the most recent filename for which we produced some line info. */
678 static const char *last_filename;
680 /* Counter to generate unique names for DIEs. */
682 static unsigned next_unused_dienum = 1;
684 /* Number of the DIE which is currently being generated. */
686 static unsigned current_dienum;
688 /* Number to use for the special "pubname" label on the next DIE which
689 represents a function or data object defined in this compilation
690 unit which has "extern" linkage. */
692 static int next_pubname_number = 0;
694 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
696 /* Pointer to a dynamically allocated list of pre-reserved and still
697 pending sibling DIE numbers. Note that this list will grow as needed. */
699 static unsigned *pending_sibling_stack;
701 /* Counter to keep track of the number of pre-reserved and still pending
702 sibling DIE numbers. */
704 static unsigned pending_siblings;
706 /* The currently allocated size of the above list (expressed in number of
707 list elements). */
709 static unsigned pending_siblings_allocated;
711 /* Size (in elements) of increments by which we may expand the pending
712 sibling stack. Actually, a single hunk of space of this size should
713 be enough for most typical programs. */
715 #define PENDING_SIBLINGS_INCREMENT 64
717 /* Non-zero if we are performing our file-scope finalization pass and if
718 we should force out Dwarf descriptions of any and all file-scope
719 tagged types which are still incomplete types. */
721 static int finalizing = 0;
723 /* A pointer to the base of a list of pending types which we haven't
724 generated DIEs for yet, but which we will have to come back to
725 later on. */
727 static tree *pending_types_list;
729 /* Number of elements currently allocated for the pending_types_list. */
731 static unsigned pending_types_allocated;
733 /* Number of elements of pending_types_list currently in use. */
735 static unsigned pending_types;
737 /* Size (in elements) of increments by which we may expand the pending
738 types list. Actually, a single hunk of space of this size should
739 be enough for most typical programs. */
741 #define PENDING_TYPES_INCREMENT 64
743 /* A pointer to the base of a list of incomplete types which might be
744 completed at some later time. */
746 static tree *incomplete_types_list;
748 /* Number of elements currently allocated for the incomplete_types_list. */
749 static unsigned incomplete_types_allocated;
751 /* Number of elements of incomplete_types_list currently in use. */
752 static unsigned incomplete_types;
754 /* Size (in elements) of increments by which we may expand the incomplete
755 types list. Actually, a single hunk of space of this size should
756 be enough for most typical programs. */
757 #define INCOMPLETE_TYPES_INCREMENT 64
759 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
760 This is used in a hack to help us get the DIEs describing types of
761 formal parameters to come *after* all of the DIEs describing the formal
762 parameters themselves. That's necessary in order to be compatible
763 with what the brain-damaged svr4 SDB debugger requires. */
765 static tree fake_containing_scope;
767 /* The number of the current function definition that we are generating
768 debugging information for. These numbers range from 1 up to the maximum
769 number of function definitions contained within the current compilation
770 unit. These numbers are used to create unique labels for various things
771 contained within various function definitions. */
773 static unsigned current_funcdef_number = 1;
775 /* A pointer to the ..._DECL node which we have most recently been working
776 on. We keep this around just in case something about it looks screwy
777 and we want to tell the user what the source coordinates for the actual
778 declaration are. */
780 static tree dwarf_last_decl;
782 /* A flag indicating that we are emitting the member declarations of a
783 class, so member functions and variables should not be entirely emitted.
784 This is a kludge to avoid passing a second argument to output_*_die. */
786 static int in_class;
788 /* Forward declarations for functions defined in this file. */
790 static void dwarfout_init PARAMS ((FILE *, const char *));
791 static void dwarfout_finish PARAMS ((FILE *, const char *));
792 static void dwarfout_define PARAMS ((unsigned int, const char *));
793 static void dwarfout_undef PARAMS ((unsigned int, const char *));
794 static void dwarfout_start_source_file PARAMS ((unsigned, const char *));
795 static void dwarfout_start_source_file_check PARAMS ((unsigned, const char *));
796 static void dwarfout_end_source_file PARAMS ((unsigned));
797 static void dwarfout_end_source_file_check PARAMS ((unsigned));
798 static void dwarfout_begin_block PARAMS ((FILE *, unsigned, unsigned));
799 static void dwarfout_end_block PARAMS ((FILE *, unsigned, unsigned));
800 static const char *dwarf_tag_name PARAMS ((unsigned));
801 static const char *dwarf_attr_name PARAMS ((unsigned));
802 static const char *dwarf_stack_op_name PARAMS ((unsigned));
803 static const char *dwarf_typemod_name PARAMS ((unsigned));
804 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
805 static const char *dwarf_fund_type_name PARAMS ((unsigned));
806 static tree decl_ultimate_origin PARAMS ((tree));
807 static tree block_ultimate_origin PARAMS ((tree));
808 static tree decl_class_context PARAMS ((tree));
809 #if 0
810 static void output_unsigned_leb128 PARAMS ((unsigned long));
811 static void output_signed_leb128 PARAMS ((long));
812 #endif
813 static int fundamental_type_code PARAMS ((tree));
814 static tree root_type_1 PARAMS ((tree, int));
815 static tree root_type PARAMS ((tree));
816 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
817 static void write_modifier_bytes PARAMS ((tree, int, int));
818 static inline int type_is_fundamental PARAMS ((tree));
819 static void equate_decl_number_to_die_number PARAMS ((tree));
820 static inline void equate_type_number_to_die_number PARAMS ((tree));
821 static void output_reg_number PARAMS ((rtx));
822 static void output_mem_loc_descriptor PARAMS ((rtx));
823 static void output_loc_descriptor PARAMS ((rtx));
824 static void output_bound_representation PARAMS ((tree, unsigned, int));
825 static void output_enumeral_list PARAMS ((tree));
826 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
827 static inline tree field_type PARAMS ((tree));
828 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
829 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
830 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
831 static inline void sibling_attribute PARAMS ((void));
832 static void location_attribute PARAMS ((rtx));
833 static void data_member_location_attribute PARAMS ((tree));
834 static void const_value_attribute PARAMS ((rtx));
835 static void location_or_const_value_attribute PARAMS ((tree));
836 static inline void name_attribute PARAMS ((const char *));
837 static inline void fund_type_attribute PARAMS ((unsigned));
838 static void mod_fund_type_attribute PARAMS ((tree, int, int));
839 static inline void user_def_type_attribute PARAMS ((tree));
840 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
841 #ifdef USE_ORDERING_ATTRIBUTE
842 static inline void ordering_attribute PARAMS ((unsigned));
843 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
844 static void subscript_data_attribute PARAMS ((tree));
845 static void byte_size_attribute PARAMS ((tree));
846 static inline void bit_offset_attribute PARAMS ((tree));
847 static inline void bit_size_attribute PARAMS ((tree));
848 static inline void element_list_attribute PARAMS ((tree));
849 static inline void stmt_list_attribute PARAMS ((const char *));
850 static inline void low_pc_attribute PARAMS ((const char *));
851 static inline void high_pc_attribute PARAMS ((const char *));
852 static inline void body_begin_attribute PARAMS ((const char *));
853 static inline void body_end_attribute PARAMS ((const char *));
854 static inline void language_attribute PARAMS ((unsigned));
855 static inline void member_attribute PARAMS ((tree));
856 #if 0
857 static inline void string_length_attribute PARAMS ((tree));
858 #endif
859 static inline void comp_dir_attribute PARAMS ((const char *));
860 static inline void sf_names_attribute PARAMS ((const char *));
861 static inline void src_info_attribute PARAMS ((const char *));
862 static inline void mac_info_attribute PARAMS ((const char *));
863 static inline void prototyped_attribute PARAMS ((tree));
864 static inline void producer_attribute PARAMS ((const char *));
865 static inline void inline_attribute PARAMS ((tree));
866 static inline void containing_type_attribute PARAMS ((tree));
867 static inline void abstract_origin_attribute PARAMS ((tree));
868 #ifdef DWARF_DECL_COORDINATES
869 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
870 #endif /* defined(DWARF_DECL_COORDINATES) */
871 static inline void pure_or_virtual_attribute PARAMS ((tree));
872 static void name_and_src_coords_attributes PARAMS ((tree));
873 static void type_attribute PARAMS ((tree, int, int));
874 static const char *type_tag PARAMS ((tree));
875 static inline void dienum_push PARAMS ((void));
876 static inline void dienum_pop PARAMS ((void));
877 static inline tree member_declared_type PARAMS ((tree));
878 static const char *function_start_label PARAMS ((tree));
879 static void output_array_type_die PARAMS ((void *));
880 static void output_set_type_die PARAMS ((void *));
881 #if 0
882 static void output_entry_point_die PARAMS ((void *));
883 #endif
884 static void output_inlined_enumeration_type_die PARAMS ((void *));
885 static void output_inlined_structure_type_die PARAMS ((void *));
886 static void output_inlined_union_type_die PARAMS ((void *));
887 static void output_enumeration_type_die PARAMS ((void *));
888 static void output_formal_parameter_die PARAMS ((void *));
889 static void output_global_subroutine_die PARAMS ((void *));
890 static void output_global_variable_die PARAMS ((void *));
891 static void output_label_die PARAMS ((void *));
892 static void output_lexical_block_die PARAMS ((void *));
893 static void output_inlined_subroutine_die PARAMS ((void *));
894 static void output_local_variable_die PARAMS ((void *));
895 static void output_member_die PARAMS ((void *));
896 #if 0
897 static void output_pointer_type_die PARAMS ((void *));
898 static void output_reference_type_die PARAMS ((void *));
899 #endif
900 static void output_ptr_to_mbr_type_die PARAMS ((void *));
901 static void output_compile_unit_die PARAMS ((void *));
902 static void output_string_type_die PARAMS ((void *));
903 static void output_inheritance_die PARAMS ((void *));
904 static void output_structure_type_die PARAMS ((void *));
905 static void output_local_subroutine_die PARAMS ((void *));
906 static void output_subroutine_type_die PARAMS ((void *));
907 static void output_typedef_die PARAMS ((void *));
908 static void output_union_type_die PARAMS ((void *));
909 static void output_unspecified_parameters_die PARAMS ((void *));
910 static void output_padded_null_die PARAMS ((void *));
911 static void output_die PARAMS ((void (*)(void *), void *));
912 static void end_sibling_chain PARAMS ((void));
913 static void output_formal_types PARAMS ((tree));
914 static void pend_type PARAMS ((tree));
915 static int type_ok_for_scope PARAMS ((tree, tree));
916 static void output_pending_types_for_scope PARAMS ((tree));
917 static void output_type PARAMS ((tree, tree));
918 static void output_tagged_type_instantiation PARAMS ((tree));
919 static void output_block PARAMS ((tree, int));
920 static void output_decls_for_scope PARAMS ((tree, int));
921 static void output_decl PARAMS ((tree, tree));
922 static void shuffle_filename_entry PARAMS ((filename_entry *));
923 static void generate_new_sfname_entry PARAMS ((void));
924 static unsigned lookup_filename PARAMS ((const char *));
925 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
926 static void generate_macinfo_entry PARAMS ((const char *, const char *));
927 static int is_pseudo_reg PARAMS ((rtx));
928 static tree type_main_variant PARAMS ((tree));
929 static int is_tagged_type PARAMS ((tree));
930 static int is_redundant_typedef PARAMS ((tree));
931 static void add_incomplete_type PARAMS ((tree));
932 static void retry_incomplete_types PARAMS ((void));
934 /* Definitions of defaults for assembler-dependent names of various
935 pseudo-ops and section names.
937 Theses may be overridden in your tm.h file (if necessary) for your
938 particular assembler. The default values provided here correspond to
939 what is expected by "standard" AT&T System V.4 assemblers. */
941 #ifndef FILE_ASM_OP
942 #define FILE_ASM_OP "\t.file\t"
943 #endif
944 #ifndef VERSION_ASM_OP
945 #define VERSION_ASM_OP "\t.version\t"
946 #endif
947 #ifndef UNALIGNED_SHORT_ASM_OP
948 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
949 #endif
950 #ifndef UNALIGNED_INT_ASM_OP
951 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
952 #endif
953 #ifndef ASM_BYTE_OP
954 #define ASM_BYTE_OP "\t.byte\t"
955 #endif
956 #ifndef SET_ASM_OP
957 #define SET_ASM_OP "\t.set\t"
958 #endif
960 /* Pseudo-ops for pushing the current section onto the section stack (and
961 simultaneously changing to a new section) and for poping back to the
962 section we were in immediately before this one. Note that most svr4
963 assemblers only maintain a one level stack... you can push all the
964 sections you want, but you can only pop out one level. (The sparc
965 svr4 assembler is an exception to this general rule.) That's
966 OK because we only use at most one level of the section stack herein. */
968 #ifndef PUSHSECTION_ASM_OP
969 #define PUSHSECTION_ASM_OP "\t.section\t"
970 #endif
971 #ifndef POPSECTION_ASM_OP
972 #define POPSECTION_ASM_OP "\t.previous"
973 #endif
975 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
976 to print the PUSHSECTION_ASM_OP and the section name. The default here
977 works for almost all svr4 assemblers, except for the sparc, where the
978 section name must be enclosed in double quotes. (See sparcv4.h.) */
980 #ifndef PUSHSECTION_FORMAT
981 #define PUSHSECTION_FORMAT "%s%s\n"
982 #endif
984 #ifndef DEBUG_SECTION
985 #define DEBUG_SECTION ".debug"
986 #endif
987 #ifndef LINE_SECTION
988 #define LINE_SECTION ".line"
989 #endif
990 #ifndef DEBUG_SFNAMES_SECTION
991 #define DEBUG_SFNAMES_SECTION ".debug_sfnames"
992 #endif
993 #ifndef DEBUG_SRCINFO_SECTION
994 #define DEBUG_SRCINFO_SECTION ".debug_srcinfo"
995 #endif
996 #ifndef DEBUG_MACINFO_SECTION
997 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
998 #endif
999 #ifndef DEBUG_PUBNAMES_SECTION
1000 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
1001 #endif
1002 #ifndef DEBUG_ARANGES_SECTION
1003 #define DEBUG_ARANGES_SECTION ".debug_aranges"
1004 #endif
1005 #ifndef TEXT_SECTION
1006 #define TEXT_SECTION ".text"
1007 #endif
1008 #ifndef DATA_SECTION
1009 #define DATA_SECTION ".data"
1010 #endif
1011 #ifndef DATA1_SECTION
1012 #define DATA1_SECTION ".data1"
1013 #endif
1014 #ifndef RODATA_SECTION
1015 #define RODATA_SECTION ".rodata"
1016 #endif
1017 #ifndef RODATA1_SECTION
1018 #define RODATA1_SECTION ".rodata1"
1019 #endif
1020 #ifndef BSS_SECTION
1021 #define BSS_SECTION ".bss"
1022 #endif
1024 /* Definitions of defaults for formats and names of various special
1025 (artificial) labels which may be generated within this file (when
1026 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
1028 If necessary, these may be overridden from within your tm.h file,
1029 but typically, you should never need to override these.
1031 These labels have been hacked (temporarily) so that they all begin with
1032 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
1033 stock m88k/svr4 assembler, both of which need to see .L at the start of
1034 a label in order to prevent that label from going into the linker symbol
1035 table). When I get time, I'll have to fix this the right way so that we
1036 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
1037 but that will require a rather massive set of changes. For the moment,
1038 the following definitions out to produce the right results for all svr4
1039 and svr3 assemblers. -- rfg
1042 #ifndef TEXT_BEGIN_LABEL
1043 #define TEXT_BEGIN_LABEL "*.L_text_b"
1044 #endif
1045 #ifndef TEXT_END_LABEL
1046 #define TEXT_END_LABEL "*.L_text_e"
1047 #endif
1049 #ifndef DATA_BEGIN_LABEL
1050 #define DATA_BEGIN_LABEL "*.L_data_b"
1051 #endif
1052 #ifndef DATA_END_LABEL
1053 #define DATA_END_LABEL "*.L_data_e"
1054 #endif
1056 #ifndef DATA1_BEGIN_LABEL
1057 #define DATA1_BEGIN_LABEL "*.L_data1_b"
1058 #endif
1059 #ifndef DATA1_END_LABEL
1060 #define DATA1_END_LABEL "*.L_data1_e"
1061 #endif
1063 #ifndef RODATA_BEGIN_LABEL
1064 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
1065 #endif
1066 #ifndef RODATA_END_LABEL
1067 #define RODATA_END_LABEL "*.L_rodata_e"
1068 #endif
1070 #ifndef RODATA1_BEGIN_LABEL
1071 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
1072 #endif
1073 #ifndef RODATA1_END_LABEL
1074 #define RODATA1_END_LABEL "*.L_rodata1_e"
1075 #endif
1077 #ifndef BSS_BEGIN_LABEL
1078 #define BSS_BEGIN_LABEL "*.L_bss_b"
1079 #endif
1080 #ifndef BSS_END_LABEL
1081 #define BSS_END_LABEL "*.L_bss_e"
1082 #endif
1084 #ifndef LINE_BEGIN_LABEL
1085 #define LINE_BEGIN_LABEL "*.L_line_b"
1086 #endif
1087 #ifndef LINE_LAST_ENTRY_LABEL
1088 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
1089 #endif
1090 #ifndef LINE_END_LABEL
1091 #define LINE_END_LABEL "*.L_line_e"
1092 #endif
1094 #ifndef DEBUG_BEGIN_LABEL
1095 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
1096 #endif
1097 #ifndef SFNAMES_BEGIN_LABEL
1098 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
1099 #endif
1100 #ifndef SRCINFO_BEGIN_LABEL
1101 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
1102 #endif
1103 #ifndef MACINFO_BEGIN_LABEL
1104 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
1105 #endif
1107 #ifndef DEBUG_ARANGES_BEGIN_LABEL
1108 #define DEBUG_ARANGES_BEGIN_LABEL "*.L_debug_aranges_begin"
1109 #endif
1110 #ifndef DEBUG_ARANGES_END_LABEL
1111 #define DEBUG_ARANGES_END_LABEL "*.L_debug_aranges_end"
1112 #endif
1114 #ifndef DIE_BEGIN_LABEL_FMT
1115 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
1116 #endif
1117 #ifndef DIE_END_LABEL_FMT
1118 #define DIE_END_LABEL_FMT "*.L_D%u_e"
1119 #endif
1120 #ifndef PUB_DIE_LABEL_FMT
1121 #define PUB_DIE_LABEL_FMT "*.L_P%u"
1122 #endif
1123 #ifndef BLOCK_BEGIN_LABEL_FMT
1124 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
1125 #endif
1126 #ifndef BLOCK_END_LABEL_FMT
1127 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
1128 #endif
1129 #ifndef SS_BEGIN_LABEL_FMT
1130 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
1131 #endif
1132 #ifndef SS_END_LABEL_FMT
1133 #define SS_END_LABEL_FMT "*.L_s%u_e"
1134 #endif
1135 #ifndef EE_BEGIN_LABEL_FMT
1136 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
1137 #endif
1138 #ifndef EE_END_LABEL_FMT
1139 #define EE_END_LABEL_FMT "*.L_e%u_e"
1140 #endif
1141 #ifndef MT_BEGIN_LABEL_FMT
1142 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
1143 #endif
1144 #ifndef MT_END_LABEL_FMT
1145 #define MT_END_LABEL_FMT "*.L_t%u_e"
1146 #endif
1147 #ifndef LOC_BEGIN_LABEL_FMT
1148 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
1149 #endif
1150 #ifndef LOC_END_LABEL_FMT
1151 #define LOC_END_LABEL_FMT "*.L_l%u_e"
1152 #endif
1153 #ifndef BOUND_BEGIN_LABEL_FMT
1154 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
1155 #endif
1156 #ifndef BOUND_END_LABEL_FMT
1157 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
1158 #endif
1159 #ifndef DERIV_BEGIN_LABEL_FMT
1160 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
1161 #endif
1162 #ifndef DERIV_END_LABEL_FMT
1163 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
1164 #endif
1165 #ifndef SL_BEGIN_LABEL_FMT
1166 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
1167 #endif
1168 #ifndef SL_END_LABEL_FMT
1169 #define SL_END_LABEL_FMT "*.L_sl%u_e"
1170 #endif
1171 #ifndef BODY_BEGIN_LABEL_FMT
1172 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
1173 #endif
1174 #ifndef BODY_END_LABEL_FMT
1175 #define BODY_END_LABEL_FMT "*.L_b%u_e"
1176 #endif
1177 #ifndef FUNC_END_LABEL_FMT
1178 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
1179 #endif
1180 #ifndef TYPE_NAME_FMT
1181 #define TYPE_NAME_FMT "*.L_T%u"
1182 #endif
1183 #ifndef DECL_NAME_FMT
1184 #define DECL_NAME_FMT "*.L_E%u"
1185 #endif
1186 #ifndef LINE_CODE_LABEL_FMT
1187 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
1188 #endif
1189 #ifndef SFNAMES_ENTRY_LABEL_FMT
1190 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
1191 #endif
1192 #ifndef LINE_ENTRY_LABEL_FMT
1193 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
1194 #endif
1196 /* Definitions of defaults for various types of primitive assembly language
1197 output operations.
1199 If necessary, these may be overridden from within your tm.h file,
1200 but typically, you shouldn't need to override these. */
1202 #ifndef ASM_OUTPUT_PUSH_SECTION
1203 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
1204 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
1205 #endif
1207 #ifndef ASM_OUTPUT_POP_SECTION
1208 #define ASM_OUTPUT_POP_SECTION(FILE) \
1209 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
1210 #endif
1212 #ifndef ASM_OUTPUT_DWARF_DELTA2
1213 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
1214 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
1215 assemble_name (FILE, LABEL1); \
1216 fprintf (FILE, "-"); \
1217 assemble_name (FILE, LABEL2); \
1218 fprintf (FILE, "\n"); \
1219 } while (0)
1220 #endif
1222 #ifndef ASM_OUTPUT_DWARF_DELTA4
1223 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
1224 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1225 assemble_name (FILE, LABEL1); \
1226 fprintf (FILE, "-"); \
1227 assemble_name (FILE, LABEL2); \
1228 fprintf (FILE, "\n"); \
1229 } while (0)
1230 #endif
1232 #ifndef ASM_OUTPUT_DWARF_TAG
1233 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
1234 do { \
1235 fprintf ((FILE), "%s0x%x", \
1236 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
1237 if (flag_debug_asm) \
1238 fprintf ((FILE), "\t%s %s", \
1239 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
1240 fputc ('\n', (FILE)); \
1241 } while (0)
1242 #endif
1244 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
1245 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
1246 do { \
1247 fprintf ((FILE), "%s0x%x", \
1248 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
1249 if (flag_debug_asm) \
1250 fprintf ((FILE), "\t%s %s", \
1251 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
1252 fputc ('\n', (FILE)); \
1253 } while (0)
1254 #endif
1256 #ifndef ASM_OUTPUT_DWARF_STACK_OP
1257 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
1258 do { \
1259 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) OP); \
1260 if (flag_debug_asm) \
1261 fprintf ((FILE), "\t%s %s", \
1262 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
1263 fputc ('\n', (FILE)); \
1264 } while (0)
1265 #endif
1267 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
1268 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
1269 do { \
1270 fprintf ((FILE), "%s0x%x", \
1271 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
1272 if (flag_debug_asm) \
1273 fprintf ((FILE), "\t%s %s", \
1274 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
1275 fputc ('\n', (FILE)); \
1276 } while (0)
1277 #endif
1279 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
1280 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
1281 do { \
1282 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) FMT); \
1283 if (flag_debug_asm) \
1284 fprintf ((FILE), "\t%s %s", \
1285 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
1286 fputc ('\n', (FILE)); \
1287 } while (0)
1288 #endif
1290 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
1291 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
1292 do { \
1293 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) MOD); \
1294 if (flag_debug_asm) \
1295 fprintf ((FILE), "\t%s %s", \
1296 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
1297 fputc ('\n', (FILE)); \
1298 } while (0)
1299 #endif
1301 #ifndef ASM_OUTPUT_DWARF_ADDR
1302 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
1303 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1304 assemble_name (FILE, LABEL); \
1305 fprintf (FILE, "\n"); \
1306 } while (0)
1307 #endif
1309 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
1310 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
1311 do { \
1312 fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1313 output_addr_const ((FILE), (RTX)); \
1314 fputc ('\n', (FILE)); \
1315 } while (0)
1316 #endif
1318 #ifndef ASM_OUTPUT_DWARF_REF
1319 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
1320 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1321 assemble_name (FILE, LABEL); \
1322 fprintf (FILE, "\n"); \
1323 } while (0)
1324 #endif
1326 #ifndef ASM_OUTPUT_DWARF_DATA1
1327 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
1328 fprintf ((FILE), "%s0x%x\n", ASM_BYTE_OP, VALUE)
1329 #endif
1331 #ifndef ASM_OUTPUT_DWARF_DATA2
1332 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
1333 fprintf ((FILE), "%s0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
1334 #endif
1336 #ifndef ASM_OUTPUT_DWARF_DATA4
1337 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
1338 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
1339 #endif
1341 #ifndef ASM_OUTPUT_DWARF_DATA8
1342 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
1343 do { \
1344 if (WORDS_BIG_ENDIAN) \
1346 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1347 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1349 else \
1351 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1352 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1354 } while (0)
1355 #endif
1357 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
1358 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
1359 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
1360 defined, we call it, then issue the line feed. If not, we supply a
1361 default defintion of calling ASM_OUTPUT_ASCII */
1363 #ifndef ASM_OUTPUT_DWARF_STRING
1364 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1365 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
1366 #else
1367 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1368 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
1369 #endif
1372 /* The debug hooks structure. */
1373 struct gcc_debug_hooks dwarf_debug_hooks =
1375 dwarfout_init,
1376 dwarfout_finish,
1377 dwarfout_define,
1378 dwarfout_undef,
1379 dwarfout_start_source_file_check,
1380 dwarfout_end_source_file_check,
1381 dwarfout_begin_block,
1382 dwarfout_end_block
1385 /************************ general utility functions **************************/
1387 static inline int
1388 is_pseudo_reg (rtl)
1389 register rtx rtl;
1391 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1392 || ((GET_CODE (rtl) == SUBREG)
1393 && (REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)));
1396 static inline tree
1397 type_main_variant (type)
1398 register tree type;
1400 type = TYPE_MAIN_VARIANT (type);
1402 /* There really should be only one main variant among any group of variants
1403 of a given type (and all of the MAIN_VARIANT values for all members of
1404 the group should point to that one type) but sometimes the C front-end
1405 messes this up for array types, so we work around that bug here. */
1407 if (TREE_CODE (type) == ARRAY_TYPE)
1409 while (type != TYPE_MAIN_VARIANT (type))
1410 type = TYPE_MAIN_VARIANT (type);
1413 return type;
1416 /* Return non-zero if the given type node represents a tagged type. */
1418 static inline int
1419 is_tagged_type (type)
1420 register tree type;
1422 register enum tree_code code = TREE_CODE (type);
1424 return (code == RECORD_TYPE || code == UNION_TYPE
1425 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1428 static const char *
1429 dwarf_tag_name (tag)
1430 register unsigned tag;
1432 switch (tag)
1434 case TAG_padding: return "TAG_padding";
1435 case TAG_array_type: return "TAG_array_type";
1436 case TAG_class_type: return "TAG_class_type";
1437 case TAG_entry_point: return "TAG_entry_point";
1438 case TAG_enumeration_type: return "TAG_enumeration_type";
1439 case TAG_formal_parameter: return "TAG_formal_parameter";
1440 case TAG_global_subroutine: return "TAG_global_subroutine";
1441 case TAG_global_variable: return "TAG_global_variable";
1442 case TAG_label: return "TAG_label";
1443 case TAG_lexical_block: return "TAG_lexical_block";
1444 case TAG_local_variable: return "TAG_local_variable";
1445 case TAG_member: return "TAG_member";
1446 case TAG_pointer_type: return "TAG_pointer_type";
1447 case TAG_reference_type: return "TAG_reference_type";
1448 case TAG_compile_unit: return "TAG_compile_unit";
1449 case TAG_string_type: return "TAG_string_type";
1450 case TAG_structure_type: return "TAG_structure_type";
1451 case TAG_subroutine: return "TAG_subroutine";
1452 case TAG_subroutine_type: return "TAG_subroutine_type";
1453 case TAG_typedef: return "TAG_typedef";
1454 case TAG_union_type: return "TAG_union_type";
1455 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
1456 case TAG_variant: return "TAG_variant";
1457 case TAG_common_block: return "TAG_common_block";
1458 case TAG_common_inclusion: return "TAG_common_inclusion";
1459 case TAG_inheritance: return "TAG_inheritance";
1460 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
1461 case TAG_module: return "TAG_module";
1462 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
1463 case TAG_set_type: return "TAG_set_type";
1464 case TAG_subrange_type: return "TAG_subrange_type";
1465 case TAG_with_stmt: return "TAG_with_stmt";
1467 /* GNU extensions. */
1469 case TAG_format_label: return "TAG_format_label";
1470 case TAG_namelist: return "TAG_namelist";
1471 case TAG_function_template: return "TAG_function_template";
1472 case TAG_class_template: return "TAG_class_template";
1474 default: return "TAG_<unknown>";
1478 static const char *
1479 dwarf_attr_name (attr)
1480 register unsigned attr;
1482 switch (attr)
1484 case AT_sibling: return "AT_sibling";
1485 case AT_location: return "AT_location";
1486 case AT_name: return "AT_name";
1487 case AT_fund_type: return "AT_fund_type";
1488 case AT_mod_fund_type: return "AT_mod_fund_type";
1489 case AT_user_def_type: return "AT_user_def_type";
1490 case AT_mod_u_d_type: return "AT_mod_u_d_type";
1491 case AT_ordering: return "AT_ordering";
1492 case AT_subscr_data: return "AT_subscr_data";
1493 case AT_byte_size: return "AT_byte_size";
1494 case AT_bit_offset: return "AT_bit_offset";
1495 case AT_bit_size: return "AT_bit_size";
1496 case AT_element_list: return "AT_element_list";
1497 case AT_stmt_list: return "AT_stmt_list";
1498 case AT_low_pc: return "AT_low_pc";
1499 case AT_high_pc: return "AT_high_pc";
1500 case AT_language: return "AT_language";
1501 case AT_member: return "AT_member";
1502 case AT_discr: return "AT_discr";
1503 case AT_discr_value: return "AT_discr_value";
1504 case AT_string_length: return "AT_string_length";
1505 case AT_common_reference: return "AT_common_reference";
1506 case AT_comp_dir: return "AT_comp_dir";
1507 case AT_const_value_string: return "AT_const_value_string";
1508 case AT_const_value_data2: return "AT_const_value_data2";
1509 case AT_const_value_data4: return "AT_const_value_data4";
1510 case AT_const_value_data8: return "AT_const_value_data8";
1511 case AT_const_value_block2: return "AT_const_value_block2";
1512 case AT_const_value_block4: return "AT_const_value_block4";
1513 case AT_containing_type: return "AT_containing_type";
1514 case AT_default_value_addr: return "AT_default_value_addr";
1515 case AT_default_value_data2: return "AT_default_value_data2";
1516 case AT_default_value_data4: return "AT_default_value_data4";
1517 case AT_default_value_data8: return "AT_default_value_data8";
1518 case AT_default_value_string: return "AT_default_value_string";
1519 case AT_friends: return "AT_friends";
1520 case AT_inline: return "AT_inline";
1521 case AT_is_optional: return "AT_is_optional";
1522 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1523 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1524 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1525 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1526 case AT_private: return "AT_private";
1527 case AT_producer: return "AT_producer";
1528 case AT_program: return "AT_program";
1529 case AT_protected: return "AT_protected";
1530 case AT_prototyped: return "AT_prototyped";
1531 case AT_public: return "AT_public";
1532 case AT_pure_virtual: return "AT_pure_virtual";
1533 case AT_return_addr: return "AT_return_addr";
1534 case AT_abstract_origin: return "AT_abstract_origin";
1535 case AT_start_scope: return "AT_start_scope";
1536 case AT_stride_size: return "AT_stride_size";
1537 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1538 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1539 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1540 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1541 case AT_virtual: return "AT_virtual";
1543 /* GNU extensions */
1545 case AT_sf_names: return "AT_sf_names";
1546 case AT_src_info: return "AT_src_info";
1547 case AT_mac_info: return "AT_mac_info";
1548 case AT_src_coords: return "AT_src_coords";
1549 case AT_body_begin: return "AT_body_begin";
1550 case AT_body_end: return "AT_body_end";
1552 default: return "AT_<unknown>";
1556 static const char *
1557 dwarf_stack_op_name (op)
1558 register unsigned op;
1560 switch (op)
1562 case OP_REG: return "OP_REG";
1563 case OP_BASEREG: return "OP_BASEREG";
1564 case OP_ADDR: return "OP_ADDR";
1565 case OP_CONST: return "OP_CONST";
1566 case OP_DEREF2: return "OP_DEREF2";
1567 case OP_DEREF4: return "OP_DEREF4";
1568 case OP_ADD: return "OP_ADD";
1569 default: return "OP_<unknown>";
1573 static const char *
1574 dwarf_typemod_name (mod)
1575 register unsigned mod;
1577 switch (mod)
1579 case MOD_pointer_to: return "MOD_pointer_to";
1580 case MOD_reference_to: return "MOD_reference_to";
1581 case MOD_const: return "MOD_const";
1582 case MOD_volatile: return "MOD_volatile";
1583 default: return "MOD_<unknown>";
1587 static const char *
1588 dwarf_fmt_byte_name (fmt)
1589 register unsigned fmt;
1591 switch (fmt)
1593 case FMT_FT_C_C: return "FMT_FT_C_C";
1594 case FMT_FT_C_X: return "FMT_FT_C_X";
1595 case FMT_FT_X_C: return "FMT_FT_X_C";
1596 case FMT_FT_X_X: return "FMT_FT_X_X";
1597 case FMT_UT_C_C: return "FMT_UT_C_C";
1598 case FMT_UT_C_X: return "FMT_UT_C_X";
1599 case FMT_UT_X_C: return "FMT_UT_X_C";
1600 case FMT_UT_X_X: return "FMT_UT_X_X";
1601 case FMT_ET: return "FMT_ET";
1602 default: return "FMT_<unknown>";
1606 static const char *
1607 dwarf_fund_type_name (ft)
1608 register unsigned ft;
1610 switch (ft)
1612 case FT_char: return "FT_char";
1613 case FT_signed_char: return "FT_signed_char";
1614 case FT_unsigned_char: return "FT_unsigned_char";
1615 case FT_short: return "FT_short";
1616 case FT_signed_short: return "FT_signed_short";
1617 case FT_unsigned_short: return "FT_unsigned_short";
1618 case FT_integer: return "FT_integer";
1619 case FT_signed_integer: return "FT_signed_integer";
1620 case FT_unsigned_integer: return "FT_unsigned_integer";
1621 case FT_long: return "FT_long";
1622 case FT_signed_long: return "FT_signed_long";
1623 case FT_unsigned_long: return "FT_unsigned_long";
1624 case FT_pointer: return "FT_pointer";
1625 case FT_float: return "FT_float";
1626 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1627 case FT_ext_prec_float: return "FT_ext_prec_float";
1628 case FT_complex: return "FT_complex";
1629 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1630 case FT_void: return "FT_void";
1631 case FT_boolean: return "FT_boolean";
1632 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1633 case FT_label: return "FT_label";
1635 /* GNU extensions. */
1637 case FT_long_long: return "FT_long_long";
1638 case FT_signed_long_long: return "FT_signed_long_long";
1639 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1641 case FT_int8: return "FT_int8";
1642 case FT_signed_int8: return "FT_signed_int8";
1643 case FT_unsigned_int8: return "FT_unsigned_int8";
1644 case FT_int16: return "FT_int16";
1645 case FT_signed_int16: return "FT_signed_int16";
1646 case FT_unsigned_int16: return "FT_unsigned_int16";
1647 case FT_int32: return "FT_int32";
1648 case FT_signed_int32: return "FT_signed_int32";
1649 case FT_unsigned_int32: return "FT_unsigned_int32";
1650 case FT_int64: return "FT_int64";
1651 case FT_signed_int64: return "FT_signed_int64";
1652 case FT_unsigned_int64: return "FT_unsigned_int64";
1653 case FT_int128: return "FT_int128";
1654 case FT_signed_int128: return "FT_signed_int128";
1655 case FT_unsigned_int128: return "FT_unsigned_int128";
1657 case FT_real32: return "FT_real32";
1658 case FT_real64: return "FT_real64";
1659 case FT_real96: return "FT_real96";
1660 case FT_real128: return "FT_real128";
1662 default: return "FT_<unknown>";
1666 /* Determine the "ultimate origin" of a decl. The decl may be an
1667 inlined instance of an inlined instance of a decl which is local
1668 to an inline function, so we have to trace all of the way back
1669 through the origin chain to find out what sort of node actually
1670 served as the original seed for the given block. */
1672 static tree
1673 decl_ultimate_origin (decl)
1674 register tree decl;
1676 #ifdef ENABLE_CHECKING
1677 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1678 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1679 most distant ancestor, this should never happen. */
1680 abort ();
1681 #endif
1683 return DECL_ABSTRACT_ORIGIN (decl);
1686 /* Determine the "ultimate origin" of a block. The block may be an
1687 inlined instance of an inlined instance of a block which is local
1688 to an inline function, so we have to trace all of the way back
1689 through the origin chain to find out what sort of node actually
1690 served as the original seed for the given block. */
1692 static tree
1693 block_ultimate_origin (block)
1694 register tree block;
1696 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1698 if (immediate_origin == NULL)
1699 return NULL;
1700 else
1702 register tree ret_val;
1703 register tree lookahead = immediate_origin;
1707 ret_val = lookahead;
1708 lookahead = (TREE_CODE (ret_val) == BLOCK)
1709 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1710 : NULL;
1712 while (lookahead != NULL && lookahead != ret_val);
1713 return ret_val;
1717 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1718 of a virtual function may refer to a base class, so we check the 'this'
1719 parameter. */
1721 static tree
1722 decl_class_context (decl)
1723 tree decl;
1725 tree context = NULL_TREE;
1726 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1727 context = DECL_CONTEXT (decl);
1728 else
1729 context = TYPE_MAIN_VARIANT
1730 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1732 if (context && !TYPE_P (context))
1733 context = NULL_TREE;
1735 return context;
1738 #if 0
1739 static void
1740 output_unsigned_leb128 (value)
1741 register unsigned long value;
1743 register unsigned long orig_value = value;
1747 register unsigned byte = (value & 0x7f);
1749 value >>= 7;
1750 if (value != 0) /* more bytes to follow */
1751 byte |= 0x80;
1752 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1753 if (flag_debug_asm && value == 0)
1754 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1755 ASM_COMMENT_START, orig_value);
1756 fputc ('\n', asm_out_file);
1758 while (value != 0);
1761 static void
1762 output_signed_leb128 (value)
1763 register long value;
1765 register long orig_value = value;
1766 register int negative = (value < 0);
1767 register int more;
1771 register unsigned byte = (value & 0x7f);
1773 value >>= 7;
1774 if (negative)
1775 value |= 0xfe000000; /* manually sign extend */
1776 if (((value == 0) && ((byte & 0x40) == 0))
1777 || ((value == -1) && ((byte & 0x40) == 1)))
1778 more = 0;
1779 else
1781 byte |= 0x80;
1782 more = 1;
1784 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1785 if (flag_debug_asm && more == 0)
1786 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1787 ASM_COMMENT_START, orig_value);
1788 fputc ('\n', asm_out_file);
1790 while (more);
1792 #endif
1794 /**************** utility functions for attribute functions ******************/
1796 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1797 type code for the given type.
1799 This routine must only be called for GCC type nodes that correspond to
1800 Dwarf fundamental types.
1802 The current Dwarf draft specification calls for Dwarf fundamental types
1803 to accurately reflect the fact that a given type was either a "plain"
1804 integral type or an explicitly "signed" integral type. Unfortunately,
1805 we can't always do this, because GCC may already have thrown away the
1806 information about the precise way in which the type was originally
1807 specified, as in:
1809 typedef signed int my_type;
1811 struct s { my_type f; };
1813 Since we may be stuck here without enought information to do exactly
1814 what is called for in the Dwarf draft specification, we do the best
1815 that we can under the circumstances and always use the "plain" integral
1816 fundamental type codes for int, short, and long types. That's probably
1817 good enough. The additional accuracy called for in the current DWARF
1818 draft specification is probably never even useful in practice. */
1820 static int
1821 fundamental_type_code (type)
1822 register tree type;
1824 if (TREE_CODE (type) == ERROR_MARK)
1825 return 0;
1827 switch (TREE_CODE (type))
1829 case ERROR_MARK:
1830 return FT_void;
1832 case VOID_TYPE:
1833 return FT_void;
1835 case INTEGER_TYPE:
1836 /* Carefully distinguish all the standard types of C,
1837 without messing up if the language is not C.
1838 Note that we check only for the names that contain spaces;
1839 other names might occur by coincidence in other languages. */
1840 if (TYPE_NAME (type) != 0
1841 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1842 && DECL_NAME (TYPE_NAME (type)) != 0
1843 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1845 const char *name =
1846 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1848 if (!strcmp (name, "unsigned char"))
1849 return FT_unsigned_char;
1850 if (!strcmp (name, "signed char"))
1851 return FT_signed_char;
1852 if (!strcmp (name, "unsigned int"))
1853 return FT_unsigned_integer;
1854 if (!strcmp (name, "short int"))
1855 return FT_short;
1856 if (!strcmp (name, "short unsigned int"))
1857 return FT_unsigned_short;
1858 if (!strcmp (name, "long int"))
1859 return FT_long;
1860 if (!strcmp (name, "long unsigned int"))
1861 return FT_unsigned_long;
1862 if (!strcmp (name, "long long int"))
1863 return FT_long_long; /* Not grok'ed by svr4 SDB */
1864 if (!strcmp (name, "long long unsigned int"))
1865 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1868 /* Most integer types will be sorted out above, however, for the
1869 sake of special `array index' integer types, the following code
1870 is also provided. */
1872 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1873 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1875 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1876 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1878 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1879 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1881 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1882 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1884 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1885 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1887 if (TYPE_MODE (type) == TImode)
1888 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1890 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1891 if (TYPE_PRECISION (type) == 1)
1892 return FT_boolean;
1894 abort ();
1896 case REAL_TYPE:
1897 /* Carefully distinguish all the standard types of C,
1898 without messing up if the language is not C. */
1899 if (TYPE_NAME (type) != 0
1900 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1901 && DECL_NAME (TYPE_NAME (type)) != 0
1902 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1904 const char *name =
1905 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1907 /* Note that here we can run afowl of a serious bug in "classic"
1908 svr4 SDB debuggers. They don't seem to understand the
1909 FT_ext_prec_float type (even though they should). */
1911 if (!strcmp (name, "long double"))
1912 return FT_ext_prec_float;
1915 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1917 /* On the SH, when compiling with -m3e or -m4-single-only, both
1918 float and double are 32 bits. But since the debugger doesn't
1919 know about the subtarget, it always thinks double is 64 bits.
1920 So we have to tell the debugger that the type is float to
1921 make the output of the 'print' command etc. readable. */
1922 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1923 return FT_float;
1924 return FT_dbl_prec_float;
1926 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1927 return FT_float;
1929 /* Note that here we can run afowl of a serious bug in "classic"
1930 svr4 SDB debuggers. They don't seem to understand the
1931 FT_ext_prec_float type (even though they should). */
1933 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1934 return FT_ext_prec_float;
1935 abort ();
1937 case COMPLEX_TYPE:
1938 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1940 case CHAR_TYPE:
1941 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1943 case BOOLEAN_TYPE:
1944 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1946 default:
1947 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1949 return 0;
1952 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1953 the Dwarf "root" type for the given input type. The Dwarf "root" type
1954 of a given type is generally the same as the given type, except that if
1955 the given type is a pointer or reference type, then the root type of
1956 the given type is the root type of the "basis" type for the pointer or
1957 reference type. (This definition of the "root" type is recursive.)
1958 Also, the root type of a `const' qualified type or a `volatile'
1959 qualified type is the root type of the given type without the
1960 qualifiers. */
1962 static tree
1963 root_type_1 (type, count)
1964 register tree type;
1965 register int count;
1967 /* Give up after searching 1000 levels, in case this is a recursive
1968 pointer type. Such types are possible in Ada, but it is not possible
1969 to represent them in DWARF1 debug info. */
1970 if (count > 1000)
1971 return error_mark_node;
1973 switch (TREE_CODE (type))
1975 case ERROR_MARK:
1976 return error_mark_node;
1978 case POINTER_TYPE:
1979 case REFERENCE_TYPE:
1980 return root_type_1 (TREE_TYPE (type), count+1);
1982 default:
1983 return type;
1987 static tree
1988 root_type (type)
1989 register tree type;
1991 type = root_type_1 (type, 0);
1992 if (type != error_mark_node)
1993 type = type_main_variant (type);
1994 return type;
1997 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1998 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
2000 static void
2001 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
2002 register tree type;
2003 register int decl_const;
2004 register int decl_volatile;
2005 register int count;
2007 if (TREE_CODE (type) == ERROR_MARK)
2008 return;
2010 /* Give up after searching 1000 levels, in case this is a recursive
2011 pointer type. Such types are possible in Ada, but it is not possible
2012 to represent them in DWARF1 debug info. */
2013 if (count > 1000)
2014 return;
2016 if (TYPE_READONLY (type) || decl_const)
2017 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
2018 if (TYPE_VOLATILE (type) || decl_volatile)
2019 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
2020 switch (TREE_CODE (type))
2022 case POINTER_TYPE:
2023 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
2024 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
2025 return;
2027 case REFERENCE_TYPE:
2028 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
2029 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
2030 return;
2032 case ERROR_MARK:
2033 default:
2034 return;
2038 static void
2039 write_modifier_bytes (type, decl_const, decl_volatile)
2040 register tree type;
2041 register int decl_const;
2042 register int decl_volatile;
2044 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
2047 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
2048 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
2050 static inline int
2051 type_is_fundamental (type)
2052 register tree type;
2054 switch (TREE_CODE (type))
2056 case ERROR_MARK:
2057 case VOID_TYPE:
2058 case INTEGER_TYPE:
2059 case REAL_TYPE:
2060 case COMPLEX_TYPE:
2061 case BOOLEAN_TYPE:
2062 case CHAR_TYPE:
2063 return 1;
2065 case SET_TYPE:
2066 case ARRAY_TYPE:
2067 case RECORD_TYPE:
2068 case UNION_TYPE:
2069 case QUAL_UNION_TYPE:
2070 case ENUMERAL_TYPE:
2071 case FUNCTION_TYPE:
2072 case METHOD_TYPE:
2073 case POINTER_TYPE:
2074 case REFERENCE_TYPE:
2075 case FILE_TYPE:
2076 case OFFSET_TYPE:
2077 case LANG_TYPE:
2078 case VECTOR_TYPE:
2079 return 0;
2081 default:
2082 abort ();
2084 return 0;
2087 /* Given a pointer to some ..._DECL tree node, generate an assembly language
2088 equate directive which will associate a symbolic name with the current DIE.
2090 The name used is an artificial label generated from the DECL_UID number
2091 associated with the given decl node. The name it gets equated to is the
2092 symbolic label that we (previously) output at the start of the DIE that
2093 we are currently generating.
2095 Calling this function while generating some "decl related" form of DIE
2096 makes it possible to later refer to the DIE which represents the given
2097 decl simply by re-generating the symbolic name from the ..._DECL node's
2098 UID number. */
2100 static void
2101 equate_decl_number_to_die_number (decl)
2102 register tree decl;
2104 /* In the case where we are generating a DIE for some ..._DECL node
2105 which represents either some inline function declaration or some
2106 entity declared within an inline function declaration/definition,
2107 setup a symbolic name for the current DIE so that we have a name
2108 for this DIE that we can easily refer to later on within
2109 AT_abstract_origin attributes. */
2111 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
2112 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2114 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
2115 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2116 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
2119 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
2120 equate directive which will associate a symbolic name with the current DIE.
2122 The name used is an artificial label generated from the TYPE_UID number
2123 associated with the given type node. The name it gets equated to is the
2124 symbolic label that we (previously) output at the start of the DIE that
2125 we are currently generating.
2127 Calling this function while generating some "type related" form of DIE
2128 makes it easy to later refer to the DIE which represents the given type
2129 simply by re-generating the alternative name from the ..._TYPE node's
2130 UID number. */
2132 static inline void
2133 equate_type_number_to_die_number (type)
2134 register tree type;
2136 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
2137 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2139 /* We are generating a DIE to represent the main variant of this type
2140 (i.e the type without any const or volatile qualifiers) so in order
2141 to get the equate to come out right, we need to get the main variant
2142 itself here. */
2144 type = type_main_variant (type);
2146 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
2147 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2148 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
2151 static void
2152 output_reg_number (rtl)
2153 register rtx rtl;
2155 register unsigned regno = REGNO (rtl);
2157 if (regno >= DWARF_FRAME_REGISTERS)
2159 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
2160 regno);
2161 regno = 0;
2163 fprintf (asm_out_file, "%s0x%x",
2164 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
2165 if (flag_debug_asm)
2167 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
2168 PRINT_REG (rtl, 0, asm_out_file);
2170 fputc ('\n', asm_out_file);
2173 /* The following routine is a nice and simple transducer. It converts the
2174 RTL for a variable or parameter (resident in memory) into an equivalent
2175 Dwarf representation of a mechanism for getting the address of that same
2176 variable onto the top of a hypothetical "address evaluation" stack.
2178 When creating memory location descriptors, we are effectively trans-
2179 forming the RTL for a memory-resident object into its Dwarf postfix
2180 expression equivalent. This routine just recursively descends an
2181 RTL tree, turning it into Dwarf postfix code as it goes. */
2183 static void
2184 output_mem_loc_descriptor (rtl)
2185 register rtx rtl;
2187 /* Note that for a dynamically sized array, the location we will
2188 generate a description of here will be the lowest numbered location
2189 which is actually within the array. That's *not* necessarily the
2190 same as the zeroth element of the array. */
2192 #ifdef ASM_SIMPLIFY_DWARF_ADDR
2193 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
2194 #endif
2196 switch (GET_CODE (rtl))
2198 case SUBREG:
2200 /* The case of a subreg may arise when we have a local (register)
2201 variable or a formal (register) parameter which doesn't quite
2202 fill up an entire register. For now, just assume that it is
2203 legitimate to make the Dwarf info refer to the whole register
2204 which contains the given subreg. */
2206 rtl = SUBREG_REG (rtl);
2207 /* Drop thru. */
2209 case REG:
2211 /* Whenever a register number forms a part of the description of
2212 the method for calculating the (dynamic) address of a memory
2213 resident object, DWARF rules require the register number to
2214 be referred to as a "base register". This distinction is not
2215 based in any way upon what category of register the hardware
2216 believes the given register belongs to. This is strictly
2217 DWARF terminology we're dealing with here.
2219 Note that in cases where the location of a memory-resident data
2220 object could be expressed as:
2222 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
2224 the actual DWARF location descriptor that we generate may just
2225 be OP_BASEREG (basereg). This may look deceptively like the
2226 object in question was allocated to a register (rather than
2227 in memory) so DWARF consumers need to be aware of the subtle
2228 distinction between OP_REG and OP_BASEREG. */
2230 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
2231 output_reg_number (rtl);
2232 break;
2234 case MEM:
2235 output_mem_loc_descriptor (XEXP (rtl, 0));
2236 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
2237 break;
2239 case CONST:
2240 case SYMBOL_REF:
2241 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
2242 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2243 break;
2245 case PLUS:
2246 output_mem_loc_descriptor (XEXP (rtl, 0));
2247 output_mem_loc_descriptor (XEXP (rtl, 1));
2248 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2249 break;
2251 case CONST_INT:
2252 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2253 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
2254 break;
2256 case MULT:
2257 /* If a pseudo-reg is optimized away, it is possible for it to
2258 be replaced with a MEM containing a multiply. Use a GNU extension
2259 to describe it. */
2260 output_mem_loc_descriptor (XEXP (rtl, 0));
2261 output_mem_loc_descriptor (XEXP (rtl, 1));
2262 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
2263 break;
2265 default:
2266 abort ();
2270 /* Output a proper Dwarf location descriptor for a variable or parameter
2271 which is either allocated in a register or in a memory location. For
2272 a register, we just generate an OP_REG and the register number. For a
2273 memory location we provide a Dwarf postfix expression describing how to
2274 generate the (dynamic) address of the object onto the address stack. */
2276 static void
2277 output_loc_descriptor (rtl)
2278 register rtx rtl;
2280 switch (GET_CODE (rtl))
2282 case SUBREG:
2284 /* The case of a subreg may arise when we have a local (register)
2285 variable or a formal (register) parameter which doesn't quite
2286 fill up an entire register. For now, just assume that it is
2287 legitimate to make the Dwarf info refer to the whole register
2288 which contains the given subreg. */
2290 rtl = SUBREG_REG (rtl);
2291 /* Drop thru. */
2293 case REG:
2294 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
2295 output_reg_number (rtl);
2296 break;
2298 case MEM:
2299 output_mem_loc_descriptor (XEXP (rtl, 0));
2300 break;
2302 default:
2303 abort (); /* Should never happen */
2307 /* Given a tree node describing an array bound (either lower or upper)
2308 output a representation for that bound. */
2310 static void
2311 output_bound_representation (bound, dim_num, u_or_l)
2312 register tree bound;
2313 register unsigned dim_num; /* For multi-dimensional arrays. */
2314 register char u_or_l; /* Designates upper or lower bound. */
2316 switch (TREE_CODE (bound))
2319 case ERROR_MARK:
2320 return;
2322 /* All fixed-bounds are represented by INTEGER_CST nodes. */
2324 case INTEGER_CST:
2325 if (host_integerp (bound, 0))
2326 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
2327 break;
2329 default:
2331 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
2332 SAVE_EXPR nodes, in which case we can do something, or as
2333 an expression, which we cannot represent. */
2335 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2336 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2338 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
2339 current_dienum, dim_num, u_or_l);
2341 sprintf (end_label, BOUND_END_LABEL_FMT,
2342 current_dienum, dim_num, u_or_l);
2344 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2345 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2347 /* If optimization is turned on, the SAVE_EXPRs that describe
2348 how to access the upper bound values are essentially bogus.
2349 They only describe (at best) how to get at these values at
2350 the points in the generated code right after they have just
2351 been computed. Worse yet, in the typical case, the upper
2352 bound values will not even *be* computed in the optimized
2353 code, so these SAVE_EXPRs are entirely bogus.
2355 In order to compensate for this fact, we check here to see
2356 if optimization is enabled, and if so, we effectively create
2357 an empty location description for the (unknown and unknowable)
2358 upper bound.
2360 This should not cause too much trouble for existing (stupid?)
2361 debuggers because they have to deal with empty upper bounds
2362 location descriptions anyway in order to be able to deal with
2363 incomplete array types.
2365 Of course an intelligent debugger (GDB?) should be able to
2366 comprehend that a missing upper bound specification in a
2367 array type used for a storage class `auto' local array variable
2368 indicates that the upper bound is both unknown (at compile-
2369 time) and unknowable (at run-time) due to optimization. */
2371 if (! optimize)
2373 while (TREE_CODE (bound) == NOP_EXPR
2374 || TREE_CODE (bound) == CONVERT_EXPR)
2375 bound = TREE_OPERAND (bound, 0);
2377 if (TREE_CODE (bound) == SAVE_EXPR)
2378 output_loc_descriptor
2379 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
2382 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2384 break;
2389 /* Recursive function to output a sequence of value/name pairs for
2390 enumeration constants in reversed order. This is called from
2391 enumeration_type_die. */
2393 static void
2394 output_enumeral_list (link)
2395 register tree link;
2397 if (link)
2399 output_enumeral_list (TREE_CHAIN (link));
2401 if (host_integerp (TREE_VALUE (link), 0))
2402 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2403 tree_low_cst (TREE_VALUE (link), 0));
2405 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
2406 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
2410 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
2411 which is not less than the value itself. */
2413 static inline HOST_WIDE_INT
2414 ceiling (value, boundary)
2415 register HOST_WIDE_INT value;
2416 register unsigned int boundary;
2418 return (((value + boundary - 1) / boundary) * boundary);
2421 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
2422 pointer to the declared type for the relevant field variable, or return
2423 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
2425 static inline tree
2426 field_type (decl)
2427 register tree decl;
2429 register tree type;
2431 if (TREE_CODE (decl) == ERROR_MARK)
2432 return integer_type_node;
2434 type = DECL_BIT_FIELD_TYPE (decl);
2435 if (type == NULL)
2436 type = TREE_TYPE (decl);
2437 return type;
2440 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2441 node, return the alignment in bits for the type, or else return
2442 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
2444 static inline unsigned int
2445 simple_type_align_in_bits (type)
2446 register tree type;
2448 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
2451 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2452 node, return the size in bits for the type if it is a constant, or
2453 else return the alignment for the type if the type's size is not
2454 constant, or else return BITS_PER_WORD if the type actually turns out
2455 to be an ERROR_MARK node. */
2457 static inline unsigned HOST_WIDE_INT
2458 simple_type_size_in_bits (type)
2459 register tree type;
2461 tree type_size_tree;
2463 if (TREE_CODE (type) == ERROR_MARK)
2464 return BITS_PER_WORD;
2465 type_size_tree = TYPE_SIZE (type);
2467 if (type_size_tree == NULL_TREE)
2468 return 0;
2469 if (! host_integerp (type_size_tree, 1))
2470 return TYPE_ALIGN (type);
2471 return tree_low_cst (type_size_tree, 1);
2474 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
2475 return the byte offset of the lowest addressed byte of the "containing
2476 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
2477 mine what that offset is, either because the argument turns out to be a
2478 pointer to an ERROR_MARK node, or because the offset is actually variable.
2479 (We can't handle the latter case just yet.) */
2481 static HOST_WIDE_INT
2482 field_byte_offset (decl)
2483 register tree decl;
2485 unsigned int type_align_in_bytes;
2486 unsigned int type_align_in_bits;
2487 unsigned HOST_WIDE_INT type_size_in_bits;
2488 HOST_WIDE_INT object_offset_in_align_units;
2489 HOST_WIDE_INT object_offset_in_bits;
2490 HOST_WIDE_INT object_offset_in_bytes;
2491 tree type;
2492 tree field_size_tree;
2493 HOST_WIDE_INT bitpos_int;
2494 HOST_WIDE_INT deepest_bitpos;
2495 unsigned HOST_WIDE_INT field_size_in_bits;
2497 if (TREE_CODE (decl) == ERROR_MARK)
2498 return 0;
2500 if (TREE_CODE (decl) != FIELD_DECL)
2501 abort ();
2503 type = field_type (decl);
2504 field_size_tree = DECL_SIZE (decl);
2506 /* The size could be unspecified if there was an error, or for
2507 a flexible array member. */
2508 if (! field_size_tree)
2509 field_size_tree = bitsize_zero_node;
2511 /* We cannot yet cope with fields whose positions or sizes are variable,
2512 so for now, when we see such things, we simply return 0. Someday,
2513 we may be able to handle such cases, but it will be damn difficult. */
2515 if (! host_integerp (bit_position (decl), 0)
2516 || ! host_integerp (field_size_tree, 1))
2517 return 0;
2519 bitpos_int = int_bit_position (decl);
2520 field_size_in_bits = tree_low_cst (field_size_tree, 1);
2522 type_size_in_bits = simple_type_size_in_bits (type);
2523 type_align_in_bits = simple_type_align_in_bits (type);
2524 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2526 /* Note that the GCC front-end doesn't make any attempt to keep track
2527 of the starting bit offset (relative to the start of the containing
2528 structure type) of the hypothetical "containing object" for a bit-
2529 field. Thus, when computing the byte offset value for the start of
2530 the "containing object" of a bit-field, we must deduce this infor-
2531 mation on our own.
2533 This can be rather tricky to do in some cases. For example, handling
2534 the following structure type definition when compiling for an i386/i486
2535 target (which only aligns long long's to 32-bit boundaries) can be very
2536 tricky:
2538 struct S {
2539 int field1;
2540 long long field2:31;
2543 Fortunately, there is a simple rule-of-thumb which can be used in such
2544 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2545 the structure shown above. It decides to do this based upon one simple
2546 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2547 taining object" for each bit-field at the first (i.e. lowest addressed)
2548 legitimate alignment boundary (based upon the required minimum alignment
2549 for the declared type of the field) which it can possibly use, subject
2550 to the condition that there is still enough available space remaining
2551 in the containing object (when allocated at the selected point) to
2552 fully accommodate all of the bits of the bit-field itself.
2554 This simple rule makes it obvious why GCC allocates 8 bytes for each
2555 object of the structure type shown above. When looking for a place to
2556 allocate the "containing object" for `field2', the compiler simply tries
2557 to allocate a 64-bit "containing object" at each successive 32-bit
2558 boundary (starting at zero) until it finds a place to allocate that 64-
2559 bit field such that at least 31 contiguous (and previously unallocated)
2560 bits remain within that selected 64 bit field. (As it turns out, for
2561 the example above, the compiler finds that it is OK to allocate the
2562 "containing object" 64-bit field at bit-offset zero within the
2563 structure type.)
2565 Here we attempt to work backwards from the limited set of facts we're
2566 given, and we try to deduce from those facts, where GCC must have
2567 believed that the containing object started (within the structure type).
2569 The value we deduce is then used (by the callers of this routine) to
2570 generate AT_location and AT_bit_offset attributes for fields (both
2571 bit-fields and, in the case of AT_location, regular fields as well). */
2573 /* Figure out the bit-distance from the start of the structure to the
2574 "deepest" bit of the bit-field. */
2575 deepest_bitpos = bitpos_int + field_size_in_bits;
2577 /* This is the tricky part. Use some fancy footwork to deduce where the
2578 lowest addressed bit of the containing object must be. */
2579 object_offset_in_bits
2580 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2582 /* Compute the offset of the containing object in "alignment units". */
2583 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2585 /* Compute the offset of the containing object in bytes. */
2586 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2588 /* The above code assumes that the field does not cross an alignment
2589 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2590 or if the structure is packed. If this happens, then we get an object
2591 which starts after the bitfield, which means that the bit offset is
2592 negative. Gdb fails when given negative bit offsets. We avoid this
2593 by recomputing using the first bit of the bitfield. This will give
2594 us an object which does not completely contain the bitfield, but it
2595 will be aligned, and it will contain the first bit of the bitfield.
2597 However, only do this for a BYTES_BIG_ENDIAN target. For a
2598 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2599 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2600 then we end up computing the object byte offset for the wrong word of the
2601 desired bitfield, which in turn causes the field offset to be negative
2602 in bit_offset_attribute. */
2603 if (BYTES_BIG_ENDIAN
2604 && object_offset_in_bits > bitpos_int)
2606 deepest_bitpos = bitpos_int + 1;
2607 object_offset_in_bits
2608 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2609 object_offset_in_align_units = (object_offset_in_bits
2610 / type_align_in_bits);
2611 object_offset_in_bytes = (object_offset_in_align_units
2612 * type_align_in_bytes);
2615 return object_offset_in_bytes;
2618 /****************************** attributes *********************************/
2620 /* The following routines are responsible for writing out the various types
2621 of Dwarf attributes (and any following data bytes associated with them).
2622 These routines are listed in order based on the numerical codes of their
2623 associated attributes. */
2625 /* Generate an AT_sibling attribute. */
2627 static inline void
2628 sibling_attribute ()
2630 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2632 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2633 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2634 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2637 /* Output the form of location attributes suitable for whole variables and
2638 whole parameters. Note that the location attributes for struct fields
2639 are generated by the routine `data_member_location_attribute' below. */
2641 static void
2642 location_attribute (rtl)
2643 register rtx rtl;
2645 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2646 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2648 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2649 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2650 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2651 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2652 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2654 /* Handle a special case. If we are about to output a location descriptor
2655 for a variable or parameter which has been optimized out of existence,
2656 don't do that. Instead we output a zero-length location descriptor
2657 value as part of the location attribute.
2659 A variable which has been optimized out of existence will have a
2660 DECL_RTL value which denotes a pseudo-reg.
2662 Currently, in some rare cases, variables can have DECL_RTL values
2663 which look like (MEM (REG pseudo-reg#)). These cases are due to
2664 bugs elsewhere in the compiler. We treat such cases
2665 as if the variable(s) in question had been optimized out of existence.
2667 Note that in all cases where we wish to express the fact that a
2668 variable has been optimized out of existence, we do not simply
2669 suppress the generation of the entire location attribute because
2670 the absence of a location attribute in certain kinds of DIEs is
2671 used to indicate something else entirely... i.e. that the DIE
2672 represents an object declaration, but not a definition. So saith
2673 the PLSIG.
2676 if (! is_pseudo_reg (rtl)
2677 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2678 output_loc_descriptor (rtl);
2680 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2683 /* Output the specialized form of location attribute used for data members
2684 of struct and union types.
2686 In the special case of a FIELD_DECL node which represents a bit-field,
2687 the "offset" part of this special location descriptor must indicate the
2688 distance in bytes from the lowest-addressed byte of the containing
2689 struct or union type to the lowest-addressed byte of the "containing
2690 object" for the bit-field. (See the `field_byte_offset' function above.)
2692 For any given bit-field, the "containing object" is a hypothetical
2693 object (of some integral or enum type) within which the given bit-field
2694 lives. The type of this hypothetical "containing object" is always the
2695 same as the declared type of the individual bit-field itself (for GCC
2696 anyway... the DWARF spec doesn't actually mandate this).
2698 Note that it is the size (in bytes) of the hypothetical "containing
2699 object" which will be given in the AT_byte_size attribute for this
2700 bit-field. (See the `byte_size_attribute' function below.) It is
2701 also used when calculating the value of the AT_bit_offset attribute.
2702 (See the `bit_offset_attribute' function below.) */
2704 static void
2705 data_member_location_attribute (t)
2706 register tree t;
2708 register unsigned object_offset_in_bytes;
2709 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2710 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2712 if (TREE_CODE (t) == TREE_VEC)
2713 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2714 else
2715 object_offset_in_bytes = field_byte_offset (t);
2717 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2718 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2719 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2720 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2721 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2722 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2723 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2724 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2725 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2728 /* Output an AT_const_value attribute for a variable or a parameter which
2729 does not have a "location" either in memory or in a register. These
2730 things can arise in GNU C when a constant is passed as an actual
2731 parameter to an inlined function. They can also arise in C++ where
2732 declared constants do not necessarily get memory "homes". */
2734 static void
2735 const_value_attribute (rtl)
2736 register rtx rtl;
2738 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2739 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2741 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2742 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2743 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2744 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2745 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2747 switch (GET_CODE (rtl))
2749 case CONST_INT:
2750 /* Note that a CONST_INT rtx could represent either an integer or
2751 a floating-point constant. A CONST_INT is used whenever the
2752 constant will fit into a single word. In all such cases, the
2753 original mode of the constant value is wiped out, and the
2754 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2755 precise mode information for these constants, we always just
2756 output them using 4 bytes. */
2758 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2759 break;
2761 case CONST_DOUBLE:
2762 /* Note that a CONST_DOUBLE rtx could represent either an integer
2763 or a floating-point constant. A CONST_DOUBLE is used whenever
2764 the constant requires more than one word in order to be adequately
2765 represented. In all such cases, the original mode of the constant
2766 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2767 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2769 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2770 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2771 (unsigned int) CONST_DOUBLE_LOW (rtl));
2772 break;
2774 case CONST_STRING:
2775 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2776 break;
2778 case SYMBOL_REF:
2779 case LABEL_REF:
2780 case CONST:
2781 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2782 break;
2784 case PLUS:
2785 /* In cases where an inlined instance of an inline function is passed
2786 the address of an `auto' variable (which is local to the caller)
2787 we can get a situation where the DECL_RTL of the artificial
2788 local variable (for the inlining) which acts as a stand-in for
2789 the corresponding formal parameter (of the inline function)
2790 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2791 This is not exactly a compile-time constant expression, but it
2792 isn't the address of the (artificial) local variable either.
2793 Rather, it represents the *value* which the artificial local
2794 variable always has during its lifetime. We currently have no
2795 way to represent such quasi-constant values in Dwarf, so for now
2796 we just punt and generate an AT_const_value attribute with form
2797 FORM_BLOCK4 and a length of zero. */
2798 break;
2800 default:
2801 abort (); /* No other kinds of rtx should be possible here. */
2804 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2807 /* Generate *either* an AT_location attribute or else an AT_const_value
2808 data attribute for a variable or a parameter. We generate the
2809 AT_const_value attribute only in those cases where the given
2810 variable or parameter does not have a true "location" either in
2811 memory or in a register. This can happen (for example) when a
2812 constant is passed as an actual argument in a call to an inline
2813 function. (It's possible that these things can crop up in other
2814 ways also.) Note that one type of constant value which can be
2815 passed into an inlined function is a constant pointer. This can
2816 happen for example if an actual argument in an inlined function
2817 call evaluates to a compile-time constant address. */
2819 static void
2820 location_or_const_value_attribute (decl)
2821 register tree decl;
2823 register rtx rtl;
2825 if (TREE_CODE (decl) == ERROR_MARK)
2826 return;
2828 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2830 /* Should never happen. */
2831 abort ();
2832 return;
2835 /* Here we have to decide where we are going to say the parameter "lives"
2836 (as far as the debugger is concerned). We only have a couple of choices.
2837 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2838 normally indicates where the parameter lives during most of the activa-
2839 tion of the function. If optimization is enabled however, this could
2840 be either NULL or else a pseudo-reg. Both of those cases indicate that
2841 the parameter doesn't really live anywhere (as far as the code generation
2842 parts of GCC are concerned) during most of the function's activation.
2843 That will happen (for example) if the parameter is never referenced
2844 within the function.
2846 We could just generate a location descriptor here for all non-NULL
2847 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2848 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2849 cases where DECL_RTL is NULL or is a pseudo-reg.
2851 Note however that we can only get away with using DECL_INCOMING_RTL as
2852 a backup substitute for DECL_RTL in certain limited cases. In cases
2853 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2854 we can be sure that the parameter was passed using the same type as it
2855 is declared to have within the function, and that its DECL_INCOMING_RTL
2856 points us to a place where a value of that type is passed. In cases
2857 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2858 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2859 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2860 points us to a value of some type which is *different* from the type
2861 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2862 to generate a location attribute in such cases, the debugger would
2863 end up (for example) trying to fetch a `float' from a place which
2864 actually contains the first part of a `double'. That would lead to
2865 really incorrect and confusing output at debug-time, and we don't
2866 want that now do we?
2868 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2869 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2870 couple of cute exceptions however. On little-endian machines we can
2871 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2872 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2873 an integral type which is smaller than TREE_TYPE(decl). These cases
2874 arise when (on a little-endian machine) a non-prototyped function has
2875 a parameter declared to be of type `short' or `char'. In such cases,
2876 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2877 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2878 passed `int' value. If the debugger then uses that address to fetch a
2879 `short' or a `char' (on a little-endian machine) the result will be the
2880 correct data, so we allow for such exceptional cases below.
2882 Note that our goal here is to describe the place where the given formal
2883 parameter lives during most of the function's activation (i.e. between
2884 the end of the prologue and the start of the epilogue). We'll do that
2885 as best as we can. Note however that if the given formal parameter is
2886 modified sometime during the execution of the function, then a stack
2887 backtrace (at debug-time) will show the function as having been called
2888 with the *new* value rather than the value which was originally passed
2889 in. This happens rarely enough that it is not a major problem, but it
2890 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2891 may generate two additional attributes for any given TAG_formal_parameter
2892 DIE which will describe the "passed type" and the "passed location" for
2893 the given formal parameter in addition to the attributes we now generate
2894 to indicate the "declared type" and the "active location" for each
2895 parameter. This additional set of attributes could be used by debuggers
2896 for stack backtraces.
2898 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2899 can be NULL also. This happens (for example) for inlined-instances of
2900 inline function formal parameters which are never referenced. This really
2901 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2902 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2903 these values for inlined instances of inline function parameters, so
2904 when we see such cases, we are just out-of-luck for the time
2905 being (until integrate.c gets fixed).
2908 /* Use DECL_RTL as the "location" unless we find something better. */
2909 rtl = DECL_RTL (decl);
2911 if (TREE_CODE (decl) == PARM_DECL)
2912 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2914 /* This decl represents a formal parameter which was optimized out. */
2915 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2916 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2918 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2919 *all* cases where (rtl == NULL_RTX) just below. */
2921 if (declared_type == passed_type)
2922 rtl = DECL_INCOMING_RTL (decl);
2923 else if (! BYTES_BIG_ENDIAN)
2924 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2925 /* NMS WTF? */
2926 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2927 rtl = DECL_INCOMING_RTL (decl);
2930 if (rtl == NULL_RTX)
2931 return;
2933 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2934 #ifdef LEAF_REG_REMAP
2935 if (current_function_uses_only_leaf_regs)
2936 leaf_renumber_regs_insn (rtl);
2937 #endif
2939 switch (GET_CODE (rtl))
2941 case ADDRESSOF:
2942 /* The address of a variable that was optimized away; don't emit
2943 anything. */
2944 break;
2946 case CONST_INT:
2947 case CONST_DOUBLE:
2948 case CONST_STRING:
2949 case SYMBOL_REF:
2950 case LABEL_REF:
2951 case CONST:
2952 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2953 const_value_attribute (rtl);
2954 break;
2956 case MEM:
2957 case REG:
2958 case SUBREG:
2959 location_attribute (rtl);
2960 break;
2962 case CONCAT:
2963 /* ??? CONCAT is used for complex variables, which may have the real
2964 part stored in one place and the imag part stored somewhere else.
2965 DWARF1 has no way to describe a variable that lives in two different
2966 places, so we just describe where the first part lives, and hope that
2967 the second part is stored after it. */
2968 location_attribute (XEXP (rtl, 0));
2969 break;
2971 default:
2972 abort (); /* Should never happen. */
2976 /* Generate an AT_name attribute given some string value to be included as
2977 the value of the attribute. */
2979 static inline void
2980 name_attribute (name_string)
2981 register const char *name_string;
2983 if (name_string && *name_string)
2985 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2986 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2990 static inline void
2991 fund_type_attribute (ft_code)
2992 register unsigned ft_code;
2994 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2995 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2998 static void
2999 mod_fund_type_attribute (type, decl_const, decl_volatile)
3000 register tree type;
3001 register int decl_const;
3002 register int decl_volatile;
3004 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3005 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3007 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
3008 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
3009 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
3010 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3011 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3012 write_modifier_bytes (type, decl_const, decl_volatile);
3013 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3014 fundamental_type_code (root_type (type)));
3015 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3018 static inline void
3019 user_def_type_attribute (type)
3020 register tree type;
3022 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
3024 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
3025 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
3026 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
3029 static void
3030 mod_u_d_type_attribute (type, decl_const, decl_volatile)
3031 register tree type;
3032 register int decl_const;
3033 register int decl_volatile;
3035 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3036 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3037 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
3039 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
3040 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
3041 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
3042 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3043 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3044 write_modifier_bytes (type, decl_const, decl_volatile);
3045 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
3046 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
3047 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3050 #ifdef USE_ORDERING_ATTRIBUTE
3051 static inline void
3052 ordering_attribute (ordering)
3053 register unsigned ordering;
3055 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
3056 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
3058 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3060 /* Note that the block of subscript information for an array type also
3061 includes information about the element type of type given array type. */
3063 static void
3064 subscript_data_attribute (type)
3065 register tree type;
3067 register unsigned dimension_number;
3068 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3069 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3071 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
3072 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
3073 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
3074 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3075 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3077 /* The GNU compilers represent multidimensional array types as sequences
3078 of one dimensional array types whose element types are themselves array
3079 types. Here we squish that down, so that each multidimensional array
3080 type gets only one array_type DIE in the Dwarf debugging info. The
3081 draft Dwarf specification say that we are allowed to do this kind
3082 of compression in C (because there is no difference between an
3083 array or arrays and a multidimensional array in C) but for other
3084 source languages (e.g. Ada) we probably shouldn't do this. */
3086 for (dimension_number = 0;
3087 TREE_CODE (type) == ARRAY_TYPE;
3088 type = TREE_TYPE (type), dimension_number++)
3090 register tree domain = TYPE_DOMAIN (type);
3092 /* Arrays come in three flavors. Unspecified bounds, fixed
3093 bounds, and (in GNU C only) variable bounds. Handle all
3094 three forms here. */
3096 if (domain)
3098 /* We have an array type with specified bounds. */
3100 register tree lower = TYPE_MIN_VALUE (domain);
3101 register tree upper = TYPE_MAX_VALUE (domain);
3103 /* Handle only fundamental types as index types for now. */
3104 if (! type_is_fundamental (domain))
3105 abort ();
3107 /* Output the representation format byte for this dimension. */
3108 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
3109 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
3110 upper && TREE_CODE (upper) == INTEGER_CST));
3112 /* Output the index type for this dimension. */
3113 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3114 fundamental_type_code (domain));
3116 /* Output the representation for the lower bound. */
3117 output_bound_representation (lower, dimension_number, 'l');
3119 /* Output the representation for the upper bound. */
3120 if (upper)
3121 output_bound_representation (upper, dimension_number, 'u');
3122 else
3123 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3125 else
3127 /* We have an array type with an unspecified length. For C and
3128 C++ we can assume that this really means that (a) the index
3129 type is an integral type, and (b) the lower bound is zero.
3130 Note that Dwarf defines the representation of an unspecified
3131 (upper) bound as being a zero-length location description. */
3133 /* Output the array-bounds format byte. */
3135 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
3137 /* Output the (assumed) index type. */
3139 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
3141 /* Output the (assumed) lower bound (constant) value. */
3143 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3145 /* Output the (empty) location description for the upper bound. */
3147 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3151 /* Output the prefix byte that says that the element type is coming up. */
3153 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
3155 /* Output a representation of the type of the elements of this array type. */
3157 type_attribute (type, 0, 0);
3159 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3162 static void
3163 byte_size_attribute (tree_node)
3164 register tree tree_node;
3166 register unsigned size;
3168 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
3169 switch (TREE_CODE (tree_node))
3171 case ERROR_MARK:
3172 size = 0;
3173 break;
3175 case ENUMERAL_TYPE:
3176 case RECORD_TYPE:
3177 case UNION_TYPE:
3178 case QUAL_UNION_TYPE:
3179 case ARRAY_TYPE:
3180 size = int_size_in_bytes (tree_node);
3181 break;
3183 case FIELD_DECL:
3184 /* For a data member of a struct or union, the AT_byte_size is
3185 generally given as the number of bytes normally allocated for
3186 an object of the *declared* type of the member itself. This
3187 is true even for bit-fields. */
3188 size = simple_type_size_in_bits (field_type (tree_node))
3189 / BITS_PER_UNIT;
3190 break;
3192 default:
3193 abort ();
3196 /* Note that `size' might be -1 when we get to this point. If it
3197 is, that indicates that the byte size of the entity in question
3198 is variable. We have no good way of expressing this fact in Dwarf
3199 at the present time, so just let the -1 pass on through. */
3201 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
3204 /* For a FIELD_DECL node which represents a bit-field, output an attribute
3205 which specifies the distance in bits from the highest order bit of the
3206 "containing object" for the bit-field to the highest order bit of the
3207 bit-field itself.
3209 For any given bit-field, the "containing object" is a hypothetical
3210 object (of some integral or enum type) within which the given bit-field
3211 lives. The type of this hypothetical "containing object" is always the
3212 same as the declared type of the individual bit-field itself.
3214 The determination of the exact location of the "containing object" for
3215 a bit-field is rather complicated. It's handled by the `field_byte_offset'
3216 function (above).
3218 Note that it is the size (in bytes) of the hypothetical "containing
3219 object" which will be given in the AT_byte_size attribute for this
3220 bit-field. (See `byte_size_attribute' above.) */
3222 static inline void
3223 bit_offset_attribute (decl)
3224 register tree decl;
3226 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
3227 tree type = DECL_BIT_FIELD_TYPE (decl);
3228 HOST_WIDE_INT bitpos_int;
3229 HOST_WIDE_INT highest_order_object_bit_offset;
3230 HOST_WIDE_INT highest_order_field_bit_offset;
3231 HOST_WIDE_INT bit_offset;
3233 /* Must be a bit field. */
3234 if (!type
3235 || TREE_CODE (decl) != FIELD_DECL)
3236 abort ();
3238 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
3239 if we encounter such things, just return without generating any
3240 attribute whatsoever. */
3242 if (! host_integerp (bit_position (decl), 0)
3243 || ! host_integerp (DECL_SIZE (decl), 1))
3244 return;
3246 bitpos_int = int_bit_position (decl);
3248 /* Note that the bit offset is always the distance (in bits) from the
3249 highest-order bit of the "containing object" to the highest-order
3250 bit of the bit-field itself. Since the "high-order end" of any
3251 object or field is different on big-endian and little-endian machines,
3252 the computation below must take account of these differences. */
3254 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
3255 highest_order_field_bit_offset = bitpos_int;
3257 if (! BYTES_BIG_ENDIAN)
3259 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
3260 highest_order_object_bit_offset += simple_type_size_in_bits (type);
3263 bit_offset =
3264 (! BYTES_BIG_ENDIAN
3265 ? highest_order_object_bit_offset - highest_order_field_bit_offset
3266 : highest_order_field_bit_offset - highest_order_object_bit_offset);
3268 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
3269 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
3272 /* For a FIELD_DECL node which represents a bit field, output an attribute
3273 which specifies the length in bits of the given field. */
3275 static inline void
3276 bit_size_attribute (decl)
3277 register tree decl;
3279 /* Must be a field and a bit field. */
3280 if (TREE_CODE (decl) != FIELD_DECL
3281 || ! DECL_BIT_FIELD_TYPE (decl))
3282 abort ();
3284 if (host_integerp (DECL_SIZE (decl), 1))
3286 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
3287 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3288 tree_low_cst (DECL_SIZE (decl), 1));
3292 /* The following routine outputs the `element_list' attribute for enumeration
3293 type DIEs. The element_lits attribute includes the names and values of
3294 all of the enumeration constants associated with the given enumeration
3295 type. */
3297 static inline void
3298 element_list_attribute (element)
3299 register tree element;
3301 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3302 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3304 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
3305 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
3306 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
3307 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3308 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3310 /* Here we output a list of value/name pairs for each enumeration constant
3311 defined for this enumeration type (as required), but we do it in REVERSE
3312 order. The order is the one required by the draft #5 Dwarf specification
3313 published by the UI/PLSIG. */
3315 output_enumeral_list (element); /* Recursively output the whole list. */
3317 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3320 /* Generate an AT_stmt_list attribute. These are normally present only in
3321 DIEs with a TAG_compile_unit tag. */
3323 static inline void
3324 stmt_list_attribute (label)
3325 register const char *label;
3327 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
3328 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3329 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3332 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
3333 for a subroutine DIE. */
3335 static inline void
3336 low_pc_attribute (asm_low_label)
3337 register const char *asm_low_label;
3339 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
3340 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
3343 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
3344 subroutine DIE. */
3346 static inline void
3347 high_pc_attribute (asm_high_label)
3348 register const char *asm_high_label;
3350 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
3351 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
3354 /* Generate an AT_body_begin attribute for a subroutine DIE. */
3356 static inline void
3357 body_begin_attribute (asm_begin_label)
3358 register const char *asm_begin_label;
3360 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
3361 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
3364 /* Generate an AT_body_end attribute for a subroutine DIE. */
3366 static inline void
3367 body_end_attribute (asm_end_label)
3368 register const char *asm_end_label;
3370 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
3371 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
3374 /* Generate an AT_language attribute given a LANG value. These attributes
3375 are used only within TAG_compile_unit DIEs. */
3377 static inline void
3378 language_attribute (language_code)
3379 register unsigned language_code;
3381 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
3382 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
3385 static inline void
3386 member_attribute (context)
3387 register tree context;
3389 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3391 /* Generate this attribute only for members in C++. */
3393 if (context != NULL && is_tagged_type (context))
3395 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
3396 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
3397 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3401 #if 0
3402 static inline void
3403 string_length_attribute (upper_bound)
3404 register tree upper_bound;
3406 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3407 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3409 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
3410 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
3411 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
3412 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3413 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3414 output_bound_representation (upper_bound, 0, 'u');
3415 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3417 #endif
3419 static inline void
3420 comp_dir_attribute (dirname)
3421 register const char *dirname;
3423 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
3424 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
3427 static inline void
3428 sf_names_attribute (sf_names_start_label)
3429 register const char *sf_names_start_label;
3431 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
3432 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3433 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
3436 static inline void
3437 src_info_attribute (src_info_start_label)
3438 register const char *src_info_start_label;
3440 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
3441 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3442 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
3445 static inline void
3446 mac_info_attribute (mac_info_start_label)
3447 register const char *mac_info_start_label;
3449 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
3450 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3451 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
3454 static inline void
3455 prototyped_attribute (func_type)
3456 register tree func_type;
3458 if ((strcmp (language_string, "GNU C") == 0)
3459 && (TYPE_ARG_TYPES (func_type) != NULL))
3461 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
3462 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3466 static inline void
3467 producer_attribute (producer)
3468 register const char *producer;
3470 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
3471 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
3474 static inline void
3475 inline_attribute (decl)
3476 register tree decl;
3478 if (DECL_INLINE (decl))
3480 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3481 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3485 static inline void
3486 containing_type_attribute (containing_type)
3487 register tree containing_type;
3489 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3491 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3492 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3493 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3496 static inline void
3497 abstract_origin_attribute (origin)
3498 register tree origin;
3500 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3502 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3503 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3505 case 'd':
3506 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3507 break;
3509 case 't':
3510 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3511 break;
3513 default:
3514 abort (); /* Should never happen. */
3517 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3520 #ifdef DWARF_DECL_COORDINATES
3521 static inline void
3522 src_coords_attribute (src_fileno, src_lineno)
3523 register unsigned src_fileno;
3524 register unsigned src_lineno;
3526 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3527 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3528 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3530 #endif /* defined(DWARF_DECL_COORDINATES) */
3532 static inline void
3533 pure_or_virtual_attribute (func_decl)
3534 register tree func_decl;
3536 if (DECL_VIRTUAL_P (func_decl))
3538 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3539 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3540 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3541 else
3542 #endif
3543 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3544 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3548 /************************* end of attributes *****************************/
3550 /********************* utility routines for DIEs *************************/
3552 /* Output an AT_name attribute and an AT_src_coords attribute for the
3553 given decl, but only if it actually has a name. */
3555 static void
3556 name_and_src_coords_attributes (decl)
3557 register tree decl;
3559 register tree decl_name = DECL_NAME (decl);
3561 if (decl_name && IDENTIFIER_POINTER (decl_name))
3563 name_attribute (IDENTIFIER_POINTER (decl_name));
3564 #ifdef DWARF_DECL_COORDINATES
3566 register unsigned file_index;
3568 /* This is annoying, but we have to pop out of the .debug section
3569 for a moment while we call `lookup_filename' because calling it
3570 may cause a temporary switch into the .debug_sfnames section and
3571 most svr4 assemblers are not smart enough to be able to nest
3572 section switches to any depth greater than one. Note that we
3573 also can't skirt this issue by delaying all output to the
3574 .debug_sfnames section unit the end of compilation because that
3575 would cause us to have inter-section forward references and
3576 Fred Fish sez that m68k/svr4 assemblers botch those. */
3578 ASM_OUTPUT_POP_SECTION (asm_out_file);
3579 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3580 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3582 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3584 #endif /* defined(DWARF_DECL_COORDINATES) */
3588 /* Many forms of DIEs contain a "type description" part. The following
3589 routine writes out these "type descriptor" parts. */
3591 static void
3592 type_attribute (type, decl_const, decl_volatile)
3593 register tree type;
3594 register int decl_const;
3595 register int decl_volatile;
3597 register enum tree_code code = TREE_CODE (type);
3598 register int root_type_modified;
3600 if (code == ERROR_MARK)
3601 return;
3603 /* Handle a special case. For functions whose return type is void,
3604 we generate *no* type attribute. (Note that no object may have
3605 type `void', so this only applies to function return types. */
3607 if (code == VOID_TYPE)
3608 return;
3610 /* If this is a subtype, find the underlying type. Eventually,
3611 this should write out the appropriate subtype info. */
3612 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3613 && TREE_TYPE (type) != 0)
3614 type = TREE_TYPE (type), code = TREE_CODE (type);
3616 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3617 || decl_const || decl_volatile
3618 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3620 if (type_is_fundamental (root_type (type)))
3622 if (root_type_modified)
3623 mod_fund_type_attribute (type, decl_const, decl_volatile);
3624 else
3625 fund_type_attribute (fundamental_type_code (type));
3627 else
3629 if (root_type_modified)
3630 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3631 else
3632 /* We have to get the type_main_variant here (and pass that to the
3633 `user_def_type_attribute' routine) because the ..._TYPE node we
3634 have might simply be a *copy* of some original type node (where
3635 the copy was created to help us keep track of typedef names)
3636 and that copy might have a different TYPE_UID from the original
3637 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3638 is labeling a given type DIE for future reference, it always and
3639 only creates labels for DIEs representing *main variants*, and it
3640 never even knows about non-main-variants.) */
3641 user_def_type_attribute (type_main_variant (type));
3645 /* Given a tree pointer to a struct, class, union, or enum type node, return
3646 a pointer to the (string) tag name for the given type, or zero if the
3647 type was declared without a tag. */
3649 static const char *
3650 type_tag (type)
3651 register tree type;
3653 register const char *name = 0;
3655 if (TYPE_NAME (type) != 0)
3657 register tree t = 0;
3659 /* Find the IDENTIFIER_NODE for the type name. */
3660 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3661 t = TYPE_NAME (type);
3663 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3664 a TYPE_DECL node, regardless of whether or not a `typedef' was
3665 involved. */
3666 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3667 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3668 t = DECL_NAME (TYPE_NAME (type));
3670 /* Now get the name as a string, or invent one. */
3671 if (t != 0)
3672 name = IDENTIFIER_POINTER (t);
3675 return (name == 0 || *name == '\0') ? 0 : name;
3678 static inline void
3679 dienum_push ()
3681 /* Start by checking if the pending_sibling_stack needs to be expanded.
3682 If necessary, expand it. */
3684 if (pending_siblings == pending_siblings_allocated)
3686 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3687 pending_sibling_stack
3688 = (unsigned *) xrealloc (pending_sibling_stack,
3689 pending_siblings_allocated * sizeof(unsigned));
3692 pending_siblings++;
3693 NEXT_DIE_NUM = next_unused_dienum++;
3696 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3697 NEXT_DIE_NUM. */
3699 static inline void
3700 dienum_pop ()
3702 pending_siblings--;
3705 static inline tree
3706 member_declared_type (member)
3707 register tree member;
3709 return (DECL_BIT_FIELD_TYPE (member))
3710 ? DECL_BIT_FIELD_TYPE (member)
3711 : TREE_TYPE (member);
3714 /* Get the function's label, as described by its RTL.
3715 This may be different from the DECL_NAME name used
3716 in the source file. */
3718 static const char *
3719 function_start_label (decl)
3720 register tree decl;
3722 rtx x;
3723 const char *fnname;
3725 x = DECL_RTL (decl);
3726 if (GET_CODE (x) != MEM)
3727 abort ();
3728 x = XEXP (x, 0);
3729 if (GET_CODE (x) != SYMBOL_REF)
3730 abort ();
3731 fnname = XSTR (x, 0);
3732 return fnname;
3736 /******************************* DIEs ************************************/
3738 /* Output routines for individual types of DIEs. */
3740 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3742 static void
3743 output_array_type_die (arg)
3744 register void *arg;
3746 register tree type = arg;
3748 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3749 sibling_attribute ();
3750 equate_type_number_to_die_number (type);
3751 member_attribute (TYPE_CONTEXT (type));
3753 /* I believe that we can default the array ordering. SDB will probably
3754 do the right things even if AT_ordering is not present. It's not
3755 even an issue until we start to get into multidimensional arrays
3756 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3757 dimensional arrays, then we'll have to put the AT_ordering attribute
3758 back in. (But if and when we find out that we need to put these in,
3759 we will only do so for multidimensional arrays. After all, we don't
3760 want to waste space in the .debug section now do we?) */
3762 #ifdef USE_ORDERING_ATTRIBUTE
3763 ordering_attribute (ORD_row_major);
3764 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3766 subscript_data_attribute (type);
3769 static void
3770 output_set_type_die (arg)
3771 register void *arg;
3773 register tree type = arg;
3775 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3776 sibling_attribute ();
3777 equate_type_number_to_die_number (type);
3778 member_attribute (TYPE_CONTEXT (type));
3779 type_attribute (TREE_TYPE (type), 0, 0);
3782 #if 0
3783 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3785 static void
3786 output_entry_point_die (arg)
3787 register void *arg;
3789 register tree decl = arg;
3790 register tree origin = decl_ultimate_origin (decl);
3792 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3793 sibling_attribute ();
3794 dienum_push ();
3795 if (origin != NULL)
3796 abstract_origin_attribute (origin);
3797 else
3799 name_and_src_coords_attributes (decl);
3800 member_attribute (DECL_CONTEXT (decl));
3801 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3803 if (DECL_ABSTRACT (decl))
3804 equate_decl_number_to_die_number (decl);
3805 else
3806 low_pc_attribute (function_start_label (decl));
3808 #endif
3810 /* Output a DIE to represent an inlined instance of an enumeration type. */
3812 static void
3813 output_inlined_enumeration_type_die (arg)
3814 register void *arg;
3816 register tree type = arg;
3818 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3819 sibling_attribute ();
3820 if (!TREE_ASM_WRITTEN (type))
3821 abort ();
3822 abstract_origin_attribute (type);
3825 /* Output a DIE to represent an inlined instance of a structure type. */
3827 static void
3828 output_inlined_structure_type_die (arg)
3829 register void *arg;
3831 register tree type = arg;
3833 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3834 sibling_attribute ();
3835 if (!TREE_ASM_WRITTEN (type))
3836 abort ();
3837 abstract_origin_attribute (type);
3840 /* Output a DIE to represent an inlined instance of a union type. */
3842 static void
3843 output_inlined_union_type_die (arg)
3844 register void *arg;
3846 register tree type = arg;
3848 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3849 sibling_attribute ();
3850 if (!TREE_ASM_WRITTEN (type))
3851 abort ();
3852 abstract_origin_attribute (type);
3855 /* Output a DIE to represent an enumeration type. Note that these DIEs
3856 include all of the information about the enumeration values also.
3857 This information is encoded into the element_list attribute. */
3859 static void
3860 output_enumeration_type_die (arg)
3861 register void *arg;
3863 register tree type = arg;
3865 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3866 sibling_attribute ();
3867 equate_type_number_to_die_number (type);
3868 name_attribute (type_tag (type));
3869 member_attribute (TYPE_CONTEXT (type));
3871 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3872 given enum type is incomplete, do not generate the AT_byte_size
3873 attribute or the AT_element_list attribute. */
3875 if (COMPLETE_TYPE_P (type))
3877 byte_size_attribute (type);
3878 element_list_attribute (TYPE_FIELDS (type));
3882 /* Output a DIE to represent either a real live formal parameter decl or
3883 to represent just the type of some formal parameter position in some
3884 function type.
3886 Note that this routine is a bit unusual because its argument may be
3887 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3888 represents an inlining of some PARM_DECL) or else some sort of a
3889 ..._TYPE node. If it's the former then this function is being called
3890 to output a DIE to represent a formal parameter object (or some inlining
3891 thereof). If it's the latter, then this function is only being called
3892 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3893 formal argument type of some subprogram type. */
3895 static void
3896 output_formal_parameter_die (arg)
3897 register void *arg;
3899 register tree node = arg;
3901 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3902 sibling_attribute ();
3904 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3906 case 'd': /* We were called with some kind of a ..._DECL node. */
3908 register tree origin = decl_ultimate_origin (node);
3910 if (origin != NULL)
3911 abstract_origin_attribute (origin);
3912 else
3914 name_and_src_coords_attributes (node);
3915 type_attribute (TREE_TYPE (node),
3916 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3918 if (DECL_ABSTRACT (node))
3919 equate_decl_number_to_die_number (node);
3920 else
3921 location_or_const_value_attribute (node);
3923 break;
3925 case 't': /* We were called with some kind of a ..._TYPE node. */
3926 type_attribute (node, 0, 0);
3927 break;
3929 default:
3930 abort (); /* Should never happen. */
3934 /* Output a DIE to represent a declared function (either file-scope
3935 or block-local) which has "external linkage" (according to ANSI-C). */
3937 static void
3938 output_global_subroutine_die (arg)
3939 register void *arg;
3941 register tree decl = arg;
3942 register tree origin = decl_ultimate_origin (decl);
3944 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3945 sibling_attribute ();
3946 dienum_push ();
3947 if (origin != NULL)
3948 abstract_origin_attribute (origin);
3949 else
3951 register tree type = TREE_TYPE (decl);
3953 name_and_src_coords_attributes (decl);
3954 inline_attribute (decl);
3955 prototyped_attribute (type);
3956 member_attribute (DECL_CONTEXT (decl));
3957 type_attribute (TREE_TYPE (type), 0, 0);
3958 pure_or_virtual_attribute (decl);
3960 if (DECL_ABSTRACT (decl))
3961 equate_decl_number_to_die_number (decl);
3962 else
3964 if (! DECL_EXTERNAL (decl) && ! in_class
3965 && decl == current_function_decl)
3967 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3969 low_pc_attribute (function_start_label (decl));
3970 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3971 high_pc_attribute (label);
3972 if (use_gnu_debug_info_extensions)
3974 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3975 body_begin_attribute (label);
3976 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3977 body_end_attribute (label);
3983 /* Output a DIE to represent a declared data object (either file-scope
3984 or block-local) which has "external linkage" (according to ANSI-C). */
3986 static void
3987 output_global_variable_die (arg)
3988 register void *arg;
3990 register tree decl = arg;
3991 register tree origin = decl_ultimate_origin (decl);
3993 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3994 sibling_attribute ();
3995 if (origin != NULL)
3996 abstract_origin_attribute (origin);
3997 else
3999 name_and_src_coords_attributes (decl);
4000 member_attribute (DECL_CONTEXT (decl));
4001 type_attribute (TREE_TYPE (decl),
4002 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4004 if (DECL_ABSTRACT (decl))
4005 equate_decl_number_to_die_number (decl);
4006 else
4008 if (! DECL_EXTERNAL (decl) && ! in_class
4009 && current_function_decl == decl_function_context (decl))
4010 location_or_const_value_attribute (decl);
4014 static void
4015 output_label_die (arg)
4016 register void *arg;
4018 register tree decl = arg;
4019 register tree origin = decl_ultimate_origin (decl);
4021 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
4022 sibling_attribute ();
4023 if (origin != NULL)
4024 abstract_origin_attribute (origin);
4025 else
4026 name_and_src_coords_attributes (decl);
4027 if (DECL_ABSTRACT (decl))
4028 equate_decl_number_to_die_number (decl);
4029 else
4031 register rtx insn = DECL_RTL (decl);
4033 /* Deleted labels are programmer specified labels which have been
4034 eliminated because of various optimisations. We still emit them
4035 here so that it is possible to put breakpoints on them. */
4036 if (GET_CODE (insn) == CODE_LABEL
4037 || ((GET_CODE (insn) == NOTE
4038 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
4040 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4042 /* When optimization is enabled (via -O) some parts of the compiler
4043 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
4044 represent source-level labels which were explicitly declared by
4045 the user. This really shouldn't be happening though, so catch
4046 it if it ever does happen. */
4048 if (INSN_DELETED_P (insn))
4049 abort (); /* Should never happen. */
4051 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
4052 low_pc_attribute (label);
4057 static void
4058 output_lexical_block_die (arg)
4059 register void *arg;
4061 register tree stmt = arg;
4063 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
4064 sibling_attribute ();
4065 dienum_push ();
4066 if (! BLOCK_ABSTRACT (stmt))
4068 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4069 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4071 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4072 low_pc_attribute (begin_label);
4073 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4074 high_pc_attribute (end_label);
4078 static void
4079 output_inlined_subroutine_die (arg)
4080 register void *arg;
4082 register tree stmt = arg;
4084 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
4085 sibling_attribute ();
4086 dienum_push ();
4087 abstract_origin_attribute (block_ultimate_origin (stmt));
4088 if (! BLOCK_ABSTRACT (stmt))
4090 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4091 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4093 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4094 low_pc_attribute (begin_label);
4095 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4096 high_pc_attribute (end_label);
4100 /* Output a DIE to represent a declared data object (either file-scope
4101 or block-local) which has "internal linkage" (according to ANSI-C). */
4103 static void
4104 output_local_variable_die (arg)
4105 register void *arg;
4107 register tree decl = arg;
4108 register tree origin = decl_ultimate_origin (decl);
4110 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
4111 sibling_attribute ();
4112 if (origin != NULL)
4113 abstract_origin_attribute (origin);
4114 else
4116 name_and_src_coords_attributes (decl);
4117 member_attribute (DECL_CONTEXT (decl));
4118 type_attribute (TREE_TYPE (decl),
4119 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4121 if (DECL_ABSTRACT (decl))
4122 equate_decl_number_to_die_number (decl);
4123 else
4124 location_or_const_value_attribute (decl);
4127 static void
4128 output_member_die (arg)
4129 register void *arg;
4131 register tree decl = arg;
4133 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
4134 sibling_attribute ();
4135 name_and_src_coords_attributes (decl);
4136 member_attribute (DECL_CONTEXT (decl));
4137 type_attribute (member_declared_type (decl),
4138 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4139 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
4141 byte_size_attribute (decl);
4142 bit_size_attribute (decl);
4143 bit_offset_attribute (decl);
4145 data_member_location_attribute (decl);
4148 #if 0
4149 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
4150 modified types instead.
4152 We keep this code here just in case these types of DIEs may be
4153 needed to represent certain things in other languages (e.g. Pascal)
4154 someday. */
4156 static void
4157 output_pointer_type_die (arg)
4158 register void *arg;
4160 register tree type = arg;
4162 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
4163 sibling_attribute ();
4164 equate_type_number_to_die_number (type);
4165 member_attribute (TYPE_CONTEXT (type));
4166 type_attribute (TREE_TYPE (type), 0, 0);
4169 static void
4170 output_reference_type_die (arg)
4171 register void *arg;
4173 register tree type = arg;
4175 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
4176 sibling_attribute ();
4177 equate_type_number_to_die_number (type);
4178 member_attribute (TYPE_CONTEXT (type));
4179 type_attribute (TREE_TYPE (type), 0, 0);
4181 #endif
4183 static void
4184 output_ptr_to_mbr_type_die (arg)
4185 register void *arg;
4187 register tree type = arg;
4189 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
4190 sibling_attribute ();
4191 equate_type_number_to_die_number (type);
4192 member_attribute (TYPE_CONTEXT (type));
4193 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
4194 type_attribute (TREE_TYPE (type), 0, 0);
4197 static void
4198 output_compile_unit_die (arg)
4199 register void *arg;
4201 register const char *main_input_filename = arg;
4203 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
4204 sibling_attribute ();
4205 dienum_push ();
4206 name_attribute (main_input_filename);
4209 char producer[250];
4211 sprintf (producer, "%s %s", language_string, version_string);
4212 producer_attribute (producer);
4215 if (strcmp (language_string, "GNU C++") == 0)
4216 language_attribute (LANG_C_PLUS_PLUS);
4217 else if (strcmp (language_string, "GNU Ada") == 0)
4218 language_attribute (LANG_ADA83);
4219 else if (strcmp (language_string, "GNU F77") == 0)
4220 language_attribute (LANG_FORTRAN77);
4221 else if (strcmp (language_string, "GNU Pascal") == 0)
4222 language_attribute (LANG_PASCAL83);
4223 else if (strcmp (language_string, "GNU Java") == 0)
4224 language_attribute (LANG_JAVA);
4225 else if (flag_traditional)
4226 language_attribute (LANG_C);
4227 else
4228 language_attribute (LANG_C89);
4229 low_pc_attribute (TEXT_BEGIN_LABEL);
4230 high_pc_attribute (TEXT_END_LABEL);
4231 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4232 stmt_list_attribute (LINE_BEGIN_LABEL);
4233 last_filename = xstrdup (main_input_filename);
4236 const char *wd = getpwd ();
4237 if (wd)
4238 comp_dir_attribute (wd);
4241 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
4243 sf_names_attribute (SFNAMES_BEGIN_LABEL);
4244 src_info_attribute (SRCINFO_BEGIN_LABEL);
4245 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4246 mac_info_attribute (MACINFO_BEGIN_LABEL);
4250 static void
4251 output_string_type_die (arg)
4252 register void *arg;
4254 register tree type = arg;
4256 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
4257 sibling_attribute ();
4258 equate_type_number_to_die_number (type);
4259 member_attribute (TYPE_CONTEXT (type));
4260 /* this is a fixed length string */
4261 byte_size_attribute (type);
4264 static void
4265 output_inheritance_die (arg)
4266 register void *arg;
4268 register tree binfo = arg;
4270 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
4271 sibling_attribute ();
4272 type_attribute (BINFO_TYPE (binfo), 0, 0);
4273 data_member_location_attribute (binfo);
4274 if (TREE_VIA_VIRTUAL (binfo))
4276 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
4277 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4279 if (TREE_VIA_PUBLIC (binfo))
4281 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
4282 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4284 else if (TREE_VIA_PROTECTED (binfo))
4286 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
4287 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4291 static void
4292 output_structure_type_die (arg)
4293 register void *arg;
4295 register tree type = arg;
4297 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
4298 sibling_attribute ();
4299 equate_type_number_to_die_number (type);
4300 name_attribute (type_tag (type));
4301 member_attribute (TYPE_CONTEXT (type));
4303 /* If this type has been completed, then give it a byte_size attribute
4304 and prepare to give a list of members. Otherwise, don't do either of
4305 these things. In the latter case, we will not be generating a list
4306 of members (since we don't have any idea what they might be for an
4307 incomplete type). */
4309 if (COMPLETE_TYPE_P (type))
4311 dienum_push ();
4312 byte_size_attribute (type);
4316 /* Output a DIE to represent a declared function (either file-scope
4317 or block-local) which has "internal linkage" (according to ANSI-C). */
4319 static void
4320 output_local_subroutine_die (arg)
4321 register void *arg;
4323 register tree decl = arg;
4324 register tree origin = decl_ultimate_origin (decl);
4326 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
4327 sibling_attribute ();
4328 dienum_push ();
4329 if (origin != NULL)
4330 abstract_origin_attribute (origin);
4331 else
4333 register tree type = TREE_TYPE (decl);
4335 name_and_src_coords_attributes (decl);
4336 inline_attribute (decl);
4337 prototyped_attribute (type);
4338 member_attribute (DECL_CONTEXT (decl));
4339 type_attribute (TREE_TYPE (type), 0, 0);
4340 pure_or_virtual_attribute (decl);
4342 if (DECL_ABSTRACT (decl))
4343 equate_decl_number_to_die_number (decl);
4344 else
4346 /* Avoid getting screwed up in cases where a function was declared
4347 static but where no definition was ever given for it. */
4349 if (TREE_ASM_WRITTEN (decl))
4351 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4352 low_pc_attribute (function_start_label (decl));
4353 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4354 high_pc_attribute (label);
4355 if (use_gnu_debug_info_extensions)
4357 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
4358 body_begin_attribute (label);
4359 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
4360 body_end_attribute (label);
4366 static void
4367 output_subroutine_type_die (arg)
4368 register void *arg;
4370 register tree type = arg;
4371 register tree return_type = TREE_TYPE (type);
4373 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
4374 sibling_attribute ();
4375 dienum_push ();
4376 equate_type_number_to_die_number (type);
4377 prototyped_attribute (type);
4378 member_attribute (TYPE_CONTEXT (type));
4379 type_attribute (return_type, 0, 0);
4382 static void
4383 output_typedef_die (arg)
4384 register void *arg;
4386 register tree decl = arg;
4387 register tree origin = decl_ultimate_origin (decl);
4389 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
4390 sibling_attribute ();
4391 if (origin != NULL)
4392 abstract_origin_attribute (origin);
4393 else
4395 name_and_src_coords_attributes (decl);
4396 member_attribute (DECL_CONTEXT (decl));
4397 type_attribute (TREE_TYPE (decl),
4398 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4400 if (DECL_ABSTRACT (decl))
4401 equate_decl_number_to_die_number (decl);
4404 static void
4405 output_union_type_die (arg)
4406 register void *arg;
4408 register tree type = arg;
4410 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
4411 sibling_attribute ();
4412 equate_type_number_to_die_number (type);
4413 name_attribute (type_tag (type));
4414 member_attribute (TYPE_CONTEXT (type));
4416 /* If this type has been completed, then give it a byte_size attribute
4417 and prepare to give a list of members. Otherwise, don't do either of
4418 these things. In the latter case, we will not be generating a list
4419 of members (since we don't have any idea what they might be for an
4420 incomplete type). */
4422 if (COMPLETE_TYPE_P (type))
4424 dienum_push ();
4425 byte_size_attribute (type);
4429 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
4430 at the end of an (ANSI prototyped) formal parameters list. */
4432 static void
4433 output_unspecified_parameters_die (arg)
4434 register void *arg;
4436 register tree decl_or_type = arg;
4438 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
4439 sibling_attribute ();
4441 /* This kludge is here only for the sake of being compatible with what
4442 the USL CI5 C compiler does. The specification of Dwarf Version 1
4443 doesn't say that TAG_unspecified_parameters DIEs should contain any
4444 attributes other than the AT_sibling attribute, but they are certainly
4445 allowed to contain additional attributes, and the CI5 compiler
4446 generates AT_name, AT_fund_type, and AT_location attributes within
4447 TAG_unspecified_parameters DIEs which appear in the child lists for
4448 DIEs representing function definitions, so we do likewise here. */
4450 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
4452 name_attribute ("...");
4453 fund_type_attribute (FT_pointer);
4454 /* location_attribute (?); */
4458 static void
4459 output_padded_null_die (arg)
4460 register void *arg ATTRIBUTE_UNUSED;
4462 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
4465 /*************************** end of DIEs *********************************/
4467 /* Generate some type of DIE. This routine generates the generic outer
4468 wrapper stuff which goes around all types of DIE's (regardless of their
4469 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
4470 DIE-length word, followed by the guts of the DIE itself. After the guts
4471 of the DIE, there must always be a terminator label for the DIE. */
4473 static void
4474 output_die (die_specific_output_function, param)
4475 register void (*die_specific_output_function) PARAMS ((void *));
4476 register void *param;
4478 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4479 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4481 current_dienum = NEXT_DIE_NUM;
4482 NEXT_DIE_NUM = next_unused_dienum;
4484 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4485 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4487 /* Write a label which will act as the name for the start of this DIE. */
4489 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4491 /* Write the DIE-length word. */
4493 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4495 /* Fill in the guts of the DIE. */
4497 next_unused_dienum++;
4498 die_specific_output_function (param);
4500 /* Write a label which will act as the name for the end of this DIE. */
4502 ASM_OUTPUT_LABEL (asm_out_file, end_label);
4505 static void
4506 end_sibling_chain ()
4508 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4510 current_dienum = NEXT_DIE_NUM;
4511 NEXT_DIE_NUM = next_unused_dienum;
4513 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4515 /* Write a label which will act as the name for the start of this DIE. */
4517 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4519 /* Write the DIE-length word. */
4521 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4523 dienum_pop ();
4526 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4527 TAG_unspecified_parameters DIE) to represent the types of the formal
4528 parameters as specified in some function type specification (except
4529 for those which appear as part of a function *definition*).
4531 Note that we must be careful here to output all of the parameter
4532 DIEs *before* we output any DIEs needed to represent the types of
4533 the formal parameters. This keeps svr4 SDB happy because it
4534 (incorrectly) thinks that the first non-parameter DIE it sees ends
4535 the formal parameter list. */
4537 static void
4538 output_formal_types (function_or_method_type)
4539 register tree function_or_method_type;
4541 register tree link;
4542 register tree formal_type = NULL;
4543 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4545 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4546 get bogus recursion when outputting tagged types local to a
4547 function declaration. */
4548 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4549 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4551 /* In the case where we are generating a formal types list for a C++
4552 non-static member function type, skip over the first thing on the
4553 TYPE_ARG_TYPES list because it only represents the type of the
4554 hidden `this pointer'. The debugger should be able to figure
4555 out (without being explicitly told) that this non-static member
4556 function type takes a `this pointer' and should be able to figure
4557 what the type of that hidden parameter is from the AT_member
4558 attribute of the parent TAG_subroutine_type DIE. */
4560 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4561 first_parm_type = TREE_CHAIN (first_parm_type);
4563 /* Make our first pass over the list of formal parameter types and output
4564 a TAG_formal_parameter DIE for each one. */
4566 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4568 formal_type = TREE_VALUE (link);
4569 if (formal_type == void_type_node)
4570 break;
4572 /* Output a (nameless) DIE to represent the formal parameter itself. */
4574 output_die (output_formal_parameter_die, formal_type);
4577 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4578 DIE to the end of the parameter list. */
4580 if (formal_type != void_type_node)
4581 output_die (output_unspecified_parameters_die, function_or_method_type);
4583 /* Make our second (and final) pass over the list of formal parameter types
4584 and output DIEs to represent those types (as necessary). */
4586 for (link = TYPE_ARG_TYPES (function_or_method_type);
4587 link;
4588 link = TREE_CHAIN (link))
4590 formal_type = TREE_VALUE (link);
4591 if (formal_type == void_type_node)
4592 break;
4594 output_type (formal_type, function_or_method_type);
4597 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4600 /* Remember a type in the pending_types_list. */
4602 static void
4603 pend_type (type)
4604 register tree type;
4606 if (pending_types == pending_types_allocated)
4608 pending_types_allocated += PENDING_TYPES_INCREMENT;
4609 pending_types_list
4610 = (tree *) xrealloc (pending_types_list,
4611 sizeof (tree) * pending_types_allocated);
4613 pending_types_list[pending_types++] = type;
4615 /* Mark the pending type as having been output already (even though
4616 it hasn't been). This prevents the type from being added to the
4617 pending_types_list more than once. */
4619 TREE_ASM_WRITTEN (type) = 1;
4622 /* Return non-zero if it is legitimate to output DIEs to represent a
4623 given type while we are generating the list of child DIEs for some
4624 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4626 See the comments within the function for a description of when it is
4627 considered legitimate to output DIEs for various kinds of types.
4629 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4630 or it may point to a BLOCK node (for types local to a block), or to a
4631 FUNCTION_DECL node (for types local to the heading of some function
4632 definition), or to a FUNCTION_TYPE node (for types local to the
4633 prototyped parameter list of a function type specification), or to a
4634 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4635 (in the case of C++ nested types).
4637 The `scope' parameter should likewise be NULL or should point to a
4638 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4639 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4641 This function is used only for deciding when to "pend" and when to
4642 "un-pend" types to/from the pending_types_list.
4644 Note that we sometimes make use of this "type pending" feature in a
4645 rather twisted way to temporarily delay the production of DIEs for the
4646 types of formal parameters. (We do this just to make svr4 SDB happy.)
4647 It order to delay the production of DIEs representing types of formal
4648 parameters, callers of this function supply `fake_containing_scope' as
4649 the `scope' parameter to this function. Given that fake_containing_scope
4650 is a tagged type which is *not* the containing scope for *any* other type,
4651 the desired effect is achieved, i.e. output of DIEs representing types
4652 is temporarily suspended, and any type DIEs which would have otherwise
4653 been output are instead placed onto the pending_types_list. Later on,
4654 we force these (temporarily pended) types to be output simply by calling
4655 `output_pending_types_for_scope' with an actual argument equal to the
4656 true scope of the types we temporarily pended. */
4658 static inline int
4659 type_ok_for_scope (type, scope)
4660 register tree type;
4661 register tree scope;
4663 /* Tagged types (i.e. struct, union, and enum types) must always be
4664 output only in the scopes where they actually belong (or else the
4665 scoping of their own tag names and the scoping of their member
4666 names will be incorrect). Non-tagged-types on the other hand can
4667 generally be output anywhere, except that svr4 SDB really doesn't
4668 want to see them nested within struct or union types, so here we
4669 say it is always OK to immediately output any such a (non-tagged)
4670 type, so long as we are not within such a context. Note that the
4671 only kinds of non-tagged types which we will be dealing with here
4672 (for C and C++ anyway) will be array types and function types. */
4674 return is_tagged_type (type)
4675 ? (TYPE_CONTEXT (type) == scope
4676 /* Ignore namespaces for the moment. */
4677 || (scope == NULL_TREE
4678 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4679 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4680 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4681 : (scope == NULL_TREE || ! is_tagged_type (scope));
4684 /* Output any pending types (from the pending_types list) which we can output
4685 now (taking into account the scope that we are working on now).
4687 For each type output, remove the given type from the pending_types_list
4688 *before* we try to output it.
4690 Note that we have to process the list in beginning-to-end order,
4691 because the call made here to output_type may cause yet more types
4692 to be added to the end of the list, and we may have to output some
4693 of them too. */
4695 static void
4696 output_pending_types_for_scope (containing_scope)
4697 register tree containing_scope;
4699 register unsigned i;
4701 for (i = 0; i < pending_types; )
4703 register tree type = pending_types_list[i];
4705 if (type_ok_for_scope (type, containing_scope))
4707 register tree *mover;
4708 register tree *limit;
4710 pending_types--;
4711 limit = &pending_types_list[pending_types];
4712 for (mover = &pending_types_list[i]; mover < limit; mover++)
4713 *mover = *(mover+1);
4715 /* Un-mark the type as having been output already (because it
4716 hasn't been, really). Then call output_type to generate a
4717 Dwarf representation of it. */
4719 TREE_ASM_WRITTEN (type) = 0;
4720 output_type (type, containing_scope);
4722 /* Don't increment the loop counter in this case because we
4723 have shifted all of the subsequent pending types down one
4724 element in the pending_types_list array. */
4726 else
4727 i++;
4731 /* Remember a type in the incomplete_types_list. */
4733 static void
4734 add_incomplete_type (type)
4735 tree type;
4737 if (incomplete_types == incomplete_types_allocated)
4739 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4740 incomplete_types_list
4741 = (tree *) xrealloc (incomplete_types_list,
4742 sizeof (tree) * incomplete_types_allocated);
4745 incomplete_types_list[incomplete_types++] = type;
4748 /* Walk through the list of incomplete types again, trying once more to
4749 emit full debugging info for them. */
4751 static void
4752 retry_incomplete_types ()
4754 register tree type;
4756 finalizing = 1;
4757 while (incomplete_types)
4759 --incomplete_types;
4760 type = incomplete_types_list[incomplete_types];
4761 output_type (type, NULL_TREE);
4765 static void
4766 output_type (type, containing_scope)
4767 register tree type;
4768 register tree containing_scope;
4770 if (type == 0 || type == error_mark_node)
4771 return;
4773 /* We are going to output a DIE to represent the unqualified version of
4774 this type (i.e. without any const or volatile qualifiers) so get
4775 the main variant (i.e. the unqualified version) of this type now. */
4777 type = type_main_variant (type);
4779 if (TREE_ASM_WRITTEN (type))
4781 if (finalizing && AGGREGATE_TYPE_P (type))
4783 register tree member;
4785 /* Some of our nested types might not have been defined when we
4786 were written out before; force them out now. */
4788 for (member = TYPE_FIELDS (type); member;
4789 member = TREE_CHAIN (member))
4790 if (TREE_CODE (member) == TYPE_DECL
4791 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4792 output_type (TREE_TYPE (member), containing_scope);
4794 return;
4797 /* If this is a nested type whose containing class hasn't been
4798 written out yet, writing it out will cover this one, too. */
4800 if (TYPE_CONTEXT (type)
4801 && TYPE_P (TYPE_CONTEXT (type))
4802 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4804 output_type (TYPE_CONTEXT (type), containing_scope);
4805 return;
4808 /* Don't generate any DIEs for this type now unless it is OK to do so
4809 (based upon what `type_ok_for_scope' tells us). */
4811 if (! type_ok_for_scope (type, containing_scope))
4813 pend_type (type);
4814 return;
4817 switch (TREE_CODE (type))
4819 case ERROR_MARK:
4820 break;
4822 case VECTOR_TYPE:
4823 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4824 break;
4826 case POINTER_TYPE:
4827 case REFERENCE_TYPE:
4828 /* Prevent infinite recursion in cases where this is a recursive
4829 type. Recursive types are possible in Ada. */
4830 TREE_ASM_WRITTEN (type) = 1;
4831 /* For these types, all that is required is that we output a DIE
4832 (or a set of DIEs) to represent the "basis" type. */
4833 output_type (TREE_TYPE (type), containing_scope);
4834 break;
4836 case OFFSET_TYPE:
4837 /* This code is used for C++ pointer-to-data-member types. */
4838 /* Output a description of the relevant class type. */
4839 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4840 /* Output a description of the type of the object pointed to. */
4841 output_type (TREE_TYPE (type), containing_scope);
4842 /* Now output a DIE to represent this pointer-to-data-member type
4843 itself. */
4844 output_die (output_ptr_to_mbr_type_die, type);
4845 break;
4847 case SET_TYPE:
4848 output_type (TYPE_DOMAIN (type), containing_scope);
4849 output_die (output_set_type_die, type);
4850 break;
4852 case FILE_TYPE:
4853 output_type (TREE_TYPE (type), containing_scope);
4854 abort (); /* No way to represent these in Dwarf yet! */
4855 break;
4857 case FUNCTION_TYPE:
4858 /* Force out return type (in case it wasn't forced out already). */
4859 output_type (TREE_TYPE (type), containing_scope);
4860 output_die (output_subroutine_type_die, type);
4861 output_formal_types (type);
4862 end_sibling_chain ();
4863 break;
4865 case METHOD_TYPE:
4866 /* Force out return type (in case it wasn't forced out already). */
4867 output_type (TREE_TYPE (type), containing_scope);
4868 output_die (output_subroutine_type_die, type);
4869 output_formal_types (type);
4870 end_sibling_chain ();
4871 break;
4873 case ARRAY_TYPE:
4874 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4876 output_type (TREE_TYPE (type), containing_scope);
4877 output_die (output_string_type_die, type);
4879 else
4881 register tree element_type;
4883 element_type = TREE_TYPE (type);
4884 while (TREE_CODE (element_type) == ARRAY_TYPE)
4885 element_type = TREE_TYPE (element_type);
4887 output_type (element_type, containing_scope);
4888 output_die (output_array_type_die, type);
4890 break;
4892 case ENUMERAL_TYPE:
4893 case RECORD_TYPE:
4894 case UNION_TYPE:
4895 case QUAL_UNION_TYPE:
4897 /* For a non-file-scope tagged type, we can always go ahead and
4898 output a Dwarf description of this type right now, even if
4899 the type in question is still incomplete, because if this
4900 local type *was* ever completed anywhere within its scope,
4901 that complete definition would already have been attached to
4902 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4903 node by the time we reach this point. That's true because of the
4904 way the front-end does its processing of file-scope declarations (of
4905 functions and class types) within which other types might be
4906 nested. The C and C++ front-ends always gobble up such "local
4907 scope" things en-mass before they try to output *any* debugging
4908 information for any of the stuff contained inside them and thus,
4909 we get the benefit here of what is (in effect) a pre-resolution
4910 of forward references to tagged types in local scopes.
4912 Note however that for file-scope tagged types we cannot assume
4913 that such pre-resolution of forward references has taken place.
4914 A given file-scope tagged type may appear to be incomplete when
4915 we reach this point, but it may yet be given a full definition
4916 (at file-scope) later on during compilation. In order to avoid
4917 generating a premature (and possibly incorrect) set of Dwarf
4918 DIEs for such (as yet incomplete) file-scope tagged types, we
4919 generate nothing at all for as-yet incomplete file-scope tagged
4920 types here unless we are making our special "finalization" pass
4921 for file-scope things at the very end of compilation. At that
4922 time, we will certainly know as much about each file-scope tagged
4923 type as we are ever going to know, so at that point in time, we
4924 can safely generate correct Dwarf descriptions for these file-
4925 scope tagged types. */
4927 if (!COMPLETE_TYPE_P (type)
4928 && (TYPE_CONTEXT (type) == NULL
4929 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4930 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4931 && !finalizing)
4933 /* We don't need to do this for function-local types. */
4934 if (! decl_function_context (TYPE_STUB_DECL (type)))
4935 add_incomplete_type (type);
4936 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4939 /* Prevent infinite recursion in cases where the type of some
4940 member of this type is expressed in terms of this type itself. */
4942 TREE_ASM_WRITTEN (type) = 1;
4944 /* Output a DIE to represent the tagged type itself. */
4946 switch (TREE_CODE (type))
4948 case ENUMERAL_TYPE:
4949 output_die (output_enumeration_type_die, type);
4950 return; /* a special case -- nothing left to do so just return */
4952 case RECORD_TYPE:
4953 output_die (output_structure_type_die, type);
4954 break;
4956 case UNION_TYPE:
4957 case QUAL_UNION_TYPE:
4958 output_die (output_union_type_die, type);
4959 break;
4961 default:
4962 abort (); /* Should never happen. */
4965 /* If this is not an incomplete type, output descriptions of
4966 each of its members.
4968 Note that as we output the DIEs necessary to represent the
4969 members of this record or union type, we will also be trying
4970 to output DIEs to represent the *types* of those members.
4971 However the `output_type' function (above) will specifically
4972 avoid generating type DIEs for member types *within* the list
4973 of member DIEs for this (containing) type execpt for those
4974 types (of members) which are explicitly marked as also being
4975 members of this (containing) type themselves. The g++ front-
4976 end can force any given type to be treated as a member of some
4977 other (containing) type by setting the TYPE_CONTEXT of the
4978 given (member) type to point to the TREE node representing the
4979 appropriate (containing) type.
4982 if (COMPLETE_TYPE_P (type))
4984 /* First output info about the base classes. */
4985 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4987 register tree bases = TYPE_BINFO_BASETYPES (type);
4988 register int n_bases = TREE_VEC_LENGTH (bases);
4989 register int i;
4991 for (i = 0; i < n_bases; i++)
4993 tree binfo = TREE_VEC_ELT (bases, i);
4994 output_type (BINFO_TYPE (binfo), containing_scope);
4995 output_die (output_inheritance_die, binfo);
4999 ++in_class;
5002 register tree normal_member;
5004 /* Now output info about the data members and type members. */
5006 for (normal_member = TYPE_FIELDS (type);
5007 normal_member;
5008 normal_member = TREE_CHAIN (normal_member))
5009 output_decl (normal_member, type);
5013 register tree func_member;
5015 /* Now output info about the function members (if any). */
5017 for (func_member = TYPE_METHODS (type);
5018 func_member;
5019 func_member = TREE_CHAIN (func_member))
5021 /* Don't include clones in the member list. */
5022 if (DECL_ABSTRACT_ORIGIN (func_member))
5023 continue;
5025 output_decl (func_member, type);
5029 --in_class;
5031 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
5032 scopes (at least in C++) so we must now output any nested
5033 pending types which are local just to this type. */
5035 output_pending_types_for_scope (type);
5037 end_sibling_chain (); /* Terminate member chain. */
5040 break;
5042 case VOID_TYPE:
5043 case INTEGER_TYPE:
5044 case REAL_TYPE:
5045 case COMPLEX_TYPE:
5046 case BOOLEAN_TYPE:
5047 case CHAR_TYPE:
5048 break; /* No DIEs needed for fundamental types. */
5050 case LANG_TYPE: /* No Dwarf representation currently defined. */
5051 break;
5053 default:
5054 abort ();
5057 TREE_ASM_WRITTEN (type) = 1;
5060 static void
5061 output_tagged_type_instantiation (type)
5062 register tree type;
5064 if (type == 0 || type == error_mark_node)
5065 return;
5067 /* We are going to output a DIE to represent the unqualified version of
5068 this type (i.e. without any const or volatile qualifiers) so make
5069 sure that we have the main variant (i.e. the unqualified version) of
5070 this type now. */
5072 if (type != type_main_variant (type))
5073 abort ();
5075 if (!TREE_ASM_WRITTEN (type))
5076 abort ();
5078 switch (TREE_CODE (type))
5080 case ERROR_MARK:
5081 break;
5083 case ENUMERAL_TYPE:
5084 output_die (output_inlined_enumeration_type_die, type);
5085 break;
5087 case RECORD_TYPE:
5088 output_die (output_inlined_structure_type_die, type);
5089 break;
5091 case UNION_TYPE:
5092 case QUAL_UNION_TYPE:
5093 output_die (output_inlined_union_type_die, type);
5094 break;
5096 default:
5097 abort (); /* Should never happen. */
5101 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
5102 the things which are local to the given block. */
5104 static void
5105 output_block (stmt, depth)
5106 register tree stmt;
5107 int depth;
5109 register int must_output_die = 0;
5110 register tree origin;
5111 register enum tree_code origin_code;
5113 /* Ignore blocks never really used to make RTL. */
5115 if (! stmt || ! TREE_USED (stmt)
5116 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
5117 return;
5119 /* Determine the "ultimate origin" of this block. This block may be an
5120 inlined instance of an inlined instance of inline function, so we
5121 have to trace all of the way back through the origin chain to find
5122 out what sort of node actually served as the original seed for the
5123 creation of the current block. */
5125 origin = block_ultimate_origin (stmt);
5126 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
5128 /* Determine if we need to output any Dwarf DIEs at all to represent this
5129 block. */
5131 if (origin_code == FUNCTION_DECL)
5132 /* The outer scopes for inlinings *must* always be represented. We
5133 generate TAG_inlined_subroutine DIEs for them. (See below.) */
5134 must_output_die = 1;
5135 else
5137 /* In the case where the current block represents an inlining of the
5138 "body block" of an inline function, we must *NOT* output any DIE
5139 for this block because we have already output a DIE to represent
5140 the whole inlined function scope and the "body block" of any
5141 function doesn't really represent a different scope according to
5142 ANSI C rules. So we check here to make sure that this block does
5143 not represent a "body block inlining" before trying to set the
5144 `must_output_die' flag. */
5146 if (! is_body_block (origin ? origin : stmt))
5148 /* Determine if this block directly contains any "significant"
5149 local declarations which we will need to output DIEs for. */
5151 if (debug_info_level > DINFO_LEVEL_TERSE)
5152 /* We are not in terse mode so *any* local declaration counts
5153 as being a "significant" one. */
5154 must_output_die = (BLOCK_VARS (stmt) != NULL);
5155 else
5157 register tree decl;
5159 /* We are in terse mode, so only local (nested) function
5160 definitions count as "significant" local declarations. */
5162 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5163 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
5165 must_output_die = 1;
5166 break;
5172 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
5173 DIE for any block which contains no significant local declarations
5174 at all. Rather, in such cases we just call `output_decls_for_scope'
5175 so that any needed Dwarf info for any sub-blocks will get properly
5176 generated. Note that in terse mode, our definition of what constitutes
5177 a "significant" local declaration gets restricted to include only
5178 inlined function instances and local (nested) function definitions. */
5180 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
5181 /* We don't care about an abstract inlined subroutine. */;
5182 else if (must_output_die)
5184 output_die ((origin_code == FUNCTION_DECL)
5185 ? output_inlined_subroutine_die
5186 : output_lexical_block_die,
5187 stmt);
5188 output_decls_for_scope (stmt, depth);
5189 end_sibling_chain ();
5191 else
5192 output_decls_for_scope (stmt, depth);
5195 /* Output all of the decls declared within a given scope (also called
5196 a `binding contour') and (recursively) all of it's sub-blocks. */
5198 static void
5199 output_decls_for_scope (stmt, depth)
5200 register tree stmt;
5201 int depth;
5203 /* Ignore blocks never really used to make RTL. */
5205 if (! stmt || ! TREE_USED (stmt))
5206 return;
5208 /* Output the DIEs to represent all of the data objects, functions,
5209 typedefs, and tagged types declared directly within this block
5210 but not within any nested sub-blocks. */
5213 register tree decl;
5215 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5216 output_decl (decl, stmt);
5219 output_pending_types_for_scope (stmt);
5221 /* Output the DIEs to represent all sub-blocks (and the items declared
5222 therein) of this block. */
5225 register tree subblocks;
5227 for (subblocks = BLOCK_SUBBLOCKS (stmt);
5228 subblocks;
5229 subblocks = BLOCK_CHAIN (subblocks))
5230 output_block (subblocks, depth + 1);
5234 /* Is this a typedef we can avoid emitting? */
5236 static inline int
5237 is_redundant_typedef (decl)
5238 register tree decl;
5240 if (TYPE_DECL_IS_STUB (decl))
5241 return 1;
5242 if (DECL_ARTIFICIAL (decl)
5243 && DECL_CONTEXT (decl)
5244 && is_tagged_type (DECL_CONTEXT (decl))
5245 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
5246 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
5247 /* Also ignore the artificial member typedef for the class name. */
5248 return 1;
5249 return 0;
5252 /* Output Dwarf .debug information for a decl described by DECL. */
5254 static void
5255 output_decl (decl, containing_scope)
5256 register tree decl;
5257 register tree containing_scope;
5259 /* Make a note of the decl node we are going to be working on. We may
5260 need to give the user the source coordinates of where it appeared in
5261 case we notice (later on) that something about it looks screwy. */
5263 dwarf_last_decl = decl;
5265 if (TREE_CODE (decl) == ERROR_MARK)
5266 return;
5268 /* If a structure is declared within an initialization, e.g. as the
5269 operand of a sizeof, then it will not have a name. We don't want
5270 to output a DIE for it, as the tree nodes are in the temporary obstack */
5272 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5273 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
5274 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
5275 || (TYPE_FIELDS (TREE_TYPE (decl))
5276 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
5277 return;
5279 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5281 if (DECL_IGNORED_P (decl))
5282 return;
5284 switch (TREE_CODE (decl))
5286 case CONST_DECL:
5287 /* The individual enumerators of an enum type get output when we
5288 output the Dwarf representation of the relevant enum type itself. */
5289 break;
5291 case FUNCTION_DECL:
5292 /* If we are in terse mode, don't output any DIEs to represent
5293 mere function declarations. Also, if we are conforming
5294 to the DWARF version 1 specification, don't output DIEs for
5295 mere function declarations. */
5297 if (DECL_INITIAL (decl) == NULL_TREE)
5298 #if (DWARF_VERSION > 1)
5299 if (debug_info_level <= DINFO_LEVEL_TERSE)
5300 #endif
5301 break;
5303 /* Before we describe the FUNCTION_DECL itself, make sure that we
5304 have described its return type. */
5306 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
5309 /* And its containing type. */
5310 register tree origin = decl_class_context (decl);
5311 if (origin)
5312 output_type (origin, containing_scope);
5315 /* If we're emitting an out-of-line copy of an inline function,
5316 set up to refer to the abstract instance emitted from
5317 note_deferral_of_defined_inline_function. */
5318 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
5319 && ! (containing_scope && TYPE_P (containing_scope)))
5320 set_decl_origin_self (decl);
5322 /* If the following DIE will represent a function definition for a
5323 function with "extern" linkage, output a special "pubnames" DIE
5324 label just ahead of the actual DIE. A reference to this label
5325 was already generated in the .debug_pubnames section sub-entry
5326 for this function definition. */
5328 if (TREE_PUBLIC (decl))
5330 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5332 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5333 ASM_OUTPUT_LABEL (asm_out_file, label);
5336 /* Now output a DIE to represent the function itself. */
5338 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
5339 ? output_global_subroutine_die
5340 : output_local_subroutine_die,
5341 decl);
5343 /* Now output descriptions of the arguments for this function.
5344 This gets (unnecessarily?) complex because of the fact that
5345 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
5346 cases where there was a trailing `...' at the end of the formal
5347 parameter list. In order to find out if there was a trailing
5348 ellipsis or not, we must instead look at the type associated
5349 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
5350 If the chain of type nodes hanging off of this FUNCTION_TYPE node
5351 ends with a void_type_node then there should *not* be an ellipsis
5352 at the end. */
5354 /* In the case where we are describing a mere function declaration, all
5355 we need to do here (and all we *can* do here) is to describe
5356 the *types* of its formal parameters. */
5358 if (decl != current_function_decl || in_class)
5359 output_formal_types (TREE_TYPE (decl));
5360 else
5362 /* Generate DIEs to represent all known formal parameters */
5364 register tree arg_decls = DECL_ARGUMENTS (decl);
5365 register tree parm;
5367 /* WARNING! Kludge zone ahead! Here we have a special
5368 hack for svr4 SDB compatibility. Instead of passing the
5369 current FUNCTION_DECL node as the second parameter (i.e.
5370 the `containing_scope' parameter) to `output_decl' (as
5371 we ought to) we instead pass a pointer to our own private
5372 fake_containing_scope node. That node is a RECORD_TYPE
5373 node which NO OTHER TYPE may ever actually be a member of.
5375 This pointer will ultimately get passed into `output_type'
5376 as its `containing_scope' parameter. `Output_type' will
5377 then perform its part in the hack... i.e. it will pend
5378 the type of the formal parameter onto the pending_types
5379 list. Later on, when we are done generating the whole
5380 sequence of formal parameter DIEs for this function
5381 definition, we will un-pend all previously pended types
5382 of formal parameters for this function definition.
5384 This whole kludge prevents any type DIEs from being
5385 mixed in with the formal parameter DIEs. That's good
5386 because svr4 SDB believes that the list of formal
5387 parameter DIEs for a function ends wherever the first
5388 non-formal-parameter DIE appears. Thus, we have to
5389 keep the formal parameter DIEs segregated. They must
5390 all appear (consecutively) at the start of the list of
5391 children for the DIE representing the function definition.
5392 Then (and only then) may we output any additional DIEs
5393 needed to represent the types of these formal parameters.
5397 When generating DIEs, generate the unspecified_parameters
5398 DIE instead if we come across the arg "__builtin_va_alist"
5401 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
5402 if (TREE_CODE (parm) == PARM_DECL)
5404 if (DECL_NAME(parm) &&
5405 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
5406 "__builtin_va_alist") )
5407 output_die (output_unspecified_parameters_die, decl);
5408 else
5409 output_decl (parm, fake_containing_scope);
5413 Now that we have finished generating all of the DIEs to
5414 represent the formal parameters themselves, force out
5415 any DIEs needed to represent their types. We do this
5416 simply by un-pending all previously pended types which
5417 can legitimately go into the chain of children DIEs for
5418 the current FUNCTION_DECL.
5421 output_pending_types_for_scope (decl);
5424 Decide whether we need a unspecified_parameters DIE at the end.
5425 There are 2 more cases to do this for:
5426 1) the ansi ... declaration - this is detectable when the end
5427 of the arg list is not a void_type_node
5428 2) an unprototyped function declaration (not a definition). This
5429 just means that we have no info about the parameters at all.
5433 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
5435 if (fn_arg_types)
5437 /* this is the prototyped case, check for ... */
5438 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
5439 output_die (output_unspecified_parameters_die, decl);
5441 else
5443 /* this is unprototyped, check for undefined (just declaration) */
5444 if (!DECL_INITIAL (decl))
5445 output_die (output_unspecified_parameters_die, decl);
5449 /* Output Dwarf info for all of the stuff within the body of the
5450 function (if it has one - it may be just a declaration). */
5453 register tree outer_scope = DECL_INITIAL (decl);
5455 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
5457 /* Note that here, `outer_scope' is a pointer to the outermost
5458 BLOCK node created to represent a function.
5459 This outermost BLOCK actually represents the outermost
5460 binding contour for the function, i.e. the contour in which
5461 the function's formal parameters and labels get declared.
5463 Curiously, it appears that the front end doesn't actually
5464 put the PARM_DECL nodes for the current function onto the
5465 BLOCK_VARS list for this outer scope. (They are strung
5466 off of the DECL_ARGUMENTS list for the function instead.)
5467 The BLOCK_VARS list for the `outer_scope' does provide us
5468 with a list of the LABEL_DECL nodes for the function however,
5469 and we output DWARF info for those here.
5471 Just within the `outer_scope' there will be a BLOCK node
5472 representing the function's outermost pair of curly braces,
5473 and any blocks used for the base and member initializers of
5474 a C++ constructor function. */
5476 output_decls_for_scope (outer_scope, 0);
5478 /* Finally, force out any pending types which are local to the
5479 outermost block of this function definition. These will
5480 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
5481 node itself. */
5483 output_pending_types_for_scope (decl);
5488 /* Generate a terminator for the list of stuff `owned' by this
5489 function. */
5491 end_sibling_chain ();
5493 break;
5495 case TYPE_DECL:
5496 /* If we are in terse mode, don't generate any DIEs to represent
5497 any actual typedefs. Note that even when we are in terse mode,
5498 we must still output DIEs to represent those tagged types which
5499 are used (directly or indirectly) in the specification of either
5500 a return type or a formal parameter type of some function. */
5502 if (debug_info_level <= DINFO_LEVEL_TERSE)
5503 if (! TYPE_DECL_IS_STUB (decl)
5504 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5505 return;
5507 /* In the special case of a TYPE_DECL node representing
5508 the declaration of some type tag, if the given TYPE_DECL is
5509 marked as having been instantiated from some other (original)
5510 TYPE_DECL node (e.g. one which was generated within the original
5511 definition of an inline function) we have to generate a special
5512 (abbreviated) TAG_structure_type, TAG_union_type, or
5513 TAG_enumeration-type DIE here. */
5515 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5517 output_tagged_type_instantiation (TREE_TYPE (decl));
5518 return;
5521 output_type (TREE_TYPE (decl), containing_scope);
5523 if (! is_redundant_typedef (decl))
5524 /* Output a DIE to represent the typedef itself. */
5525 output_die (output_typedef_die, decl);
5526 break;
5528 case LABEL_DECL:
5529 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5530 output_die (output_label_die, decl);
5531 break;
5533 case VAR_DECL:
5534 /* If we are conforming to the DWARF version 1 specification, don't
5535 generated any DIEs to represent mere external object declarations. */
5537 #if (DWARF_VERSION <= 1)
5538 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5539 break;
5540 #endif
5542 /* If we are in terse mode, don't generate any DIEs to represent
5543 any variable declarations or definitions. */
5545 if (debug_info_level <= DINFO_LEVEL_TERSE)
5546 break;
5548 /* Output any DIEs that are needed to specify the type of this data
5549 object. */
5551 output_type (TREE_TYPE (decl), containing_scope);
5554 /* And its containing type. */
5555 register tree origin = decl_class_context (decl);
5556 if (origin)
5557 output_type (origin, containing_scope);
5560 /* If the following DIE will represent a data object definition for a
5561 data object with "extern" linkage, output a special "pubnames" DIE
5562 label just ahead of the actual DIE. A reference to this label
5563 was already generated in the .debug_pubnames section sub-entry
5564 for this data object definition. */
5566 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5568 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5570 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5571 ASM_OUTPUT_LABEL (asm_out_file, label);
5574 /* Now output the DIE to represent the data object itself. This gets
5575 complicated because of the possibility that the VAR_DECL really
5576 represents an inlined instance of a formal parameter for an inline
5577 function. */
5580 register void (*func) PARAMS ((void *));
5581 register tree origin = decl_ultimate_origin (decl);
5583 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5584 func = output_formal_parameter_die;
5585 else
5587 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5588 func = output_global_variable_die;
5589 else
5590 func = output_local_variable_die;
5592 output_die (func, decl);
5594 break;
5596 case FIELD_DECL:
5597 /* Ignore the nameless fields that are used to skip bits. */
5598 if (DECL_NAME (decl) != 0)
5600 output_type (member_declared_type (decl), containing_scope);
5601 output_die (output_member_die, decl);
5603 break;
5605 case PARM_DECL:
5606 /* Force out the type of this formal, if it was not forced out yet.
5607 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5608 It should be able to grok the presence of type DIEs within a list
5609 of TAG_formal_parameter DIEs, but it doesn't. */
5611 output_type (TREE_TYPE (decl), containing_scope);
5612 output_die (output_formal_parameter_die, decl);
5613 break;
5615 case NAMESPACE_DECL:
5616 /* Ignore for now. */
5617 break;
5619 default:
5620 abort ();
5624 void
5625 dwarfout_file_scope_decl (decl, set_finalizing)
5626 register tree decl;
5627 register int set_finalizing;
5629 if (TREE_CODE (decl) == ERROR_MARK)
5630 return;
5632 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5634 if (DECL_IGNORED_P (decl))
5635 return;
5637 switch (TREE_CODE (decl))
5639 case FUNCTION_DECL:
5641 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5642 a builtin function. Explicit programmer-supplied declarations of
5643 these same functions should NOT be ignored however. */
5645 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5646 return;
5648 /* What we would really like to do here is to filter out all mere
5649 file-scope declarations of file-scope functions which are never
5650 referenced later within this translation unit (and keep all of
5651 ones that *are* referenced later on) but we aren't clairvoyant,
5652 so we have no idea which functions will be referenced in the
5653 future (i.e. later on within the current translation unit).
5654 So here we just ignore all file-scope function declarations
5655 which are not also definitions. If and when the debugger needs
5656 to know something about these functions, it wil have to hunt
5657 around and find the DWARF information associated with the
5658 *definition* of the function.
5660 Note that we can't just check `DECL_EXTERNAL' to find out which
5661 FUNCTION_DECL nodes represent definitions and which ones represent
5662 mere declarations. We have to check `DECL_INITIAL' instead. That's
5663 because the C front-end supports some weird semantics for "extern
5664 inline" function definitions. These can get inlined within the
5665 current translation unit (an thus, we need to generate DWARF info
5666 for their abstract instances so that the DWARF info for the
5667 concrete inlined instances can have something to refer to) but
5668 the compiler never generates any out-of-lines instances of such
5669 things (despite the fact that they *are* definitions). The
5670 important point is that the C front-end marks these "extern inline"
5671 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5672 anyway.
5674 Note that the C++ front-end also plays some similar games for inline
5675 function definitions appearing within include files which also
5676 contain `#pragma interface' pragmas. */
5678 if (DECL_INITIAL (decl) == NULL_TREE)
5679 return;
5681 if (TREE_PUBLIC (decl)
5682 && ! DECL_EXTERNAL (decl)
5683 && ! DECL_ABSTRACT (decl))
5685 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5687 /* Output a .debug_pubnames entry for a public function
5688 defined in this compilation unit. */
5690 fputc ('\n', asm_out_file);
5691 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5692 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5693 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5694 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5695 IDENTIFIER_POINTER (DECL_NAME (decl)));
5696 ASM_OUTPUT_POP_SECTION (asm_out_file);
5699 break;
5701 case VAR_DECL:
5703 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5704 object declaration and if the declaration was never even
5705 referenced from within this entire compilation unit. We
5706 suppress these DIEs in order to save space in the .debug section
5707 (by eliminating entries which are probably useless). Note that
5708 we must not suppress block-local extern declarations (whether
5709 used or not) because that would screw-up the debugger's name
5710 lookup mechanism and cause it to miss things which really ought
5711 to be in scope at a given point. */
5713 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5714 return;
5716 if (TREE_PUBLIC (decl)
5717 && ! DECL_EXTERNAL (decl)
5718 && GET_CODE (DECL_RTL (decl)) == MEM
5719 && ! DECL_ABSTRACT (decl))
5721 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5723 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5725 /* Output a .debug_pubnames entry for a public variable
5726 defined in this compilation unit. */
5728 fputc ('\n', asm_out_file);
5729 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5730 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5731 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5732 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5733 IDENTIFIER_POINTER (DECL_NAME (decl)));
5734 ASM_OUTPUT_POP_SECTION (asm_out_file);
5737 if (DECL_INITIAL (decl) == NULL)
5739 /* Output a .debug_aranges entry for a public variable
5740 which is tentatively defined in this compilation unit. */
5742 fputc ('\n', asm_out_file);
5743 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
5744 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5745 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5746 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5747 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5748 ASM_OUTPUT_POP_SECTION (asm_out_file);
5752 /* If we are in terse mode, don't generate any DIEs to represent
5753 any variable declarations or definitions. */
5755 if (debug_info_level <= DINFO_LEVEL_TERSE)
5756 return;
5758 break;
5760 case TYPE_DECL:
5761 /* Don't bother trying to generate any DIEs to represent any of the
5762 normal built-in types for the language we are compiling, except
5763 in cases where the types in question are *not* DWARF fundamental
5764 types. We make an exception in the case of non-fundamental types
5765 for the sake of objective C (and perhaps C++) because the GNU
5766 front-ends for these languages may in fact create certain "built-in"
5767 types which are (for example) RECORD_TYPEs. In such cases, we
5768 really need to output these (non-fundamental) types because other
5769 DIEs may contain references to them. */
5771 /* Also ignore language dependent types here, because they are probably
5772 also built-in types. If we didn't ignore them, then we would get
5773 references to undefined labels because output_type doesn't support
5774 them. So, for now, we need to ignore them to avoid assembler
5775 errors. */
5777 /* ??? This code is different than the equivalent code in dwarf2out.c.
5778 The dwarf2out.c code is probably more correct. */
5780 if (DECL_SOURCE_LINE (decl) == 0
5781 && (type_is_fundamental (TREE_TYPE (decl))
5782 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5783 return;
5785 /* If we are in terse mode, don't generate any DIEs to represent
5786 any actual typedefs. Note that even when we are in terse mode,
5787 we must still output DIEs to represent those tagged types which
5788 are used (directly or indirectly) in the specification of either
5789 a return type or a formal parameter type of some function. */
5791 if (debug_info_level <= DINFO_LEVEL_TERSE)
5792 if (! TYPE_DECL_IS_STUB (decl)
5793 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5794 return;
5796 break;
5798 default:
5799 return;
5802 fputc ('\n', asm_out_file);
5803 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5804 finalizing = set_finalizing;
5805 output_decl (decl, NULL_TREE);
5807 /* NOTE: The call above to `output_decl' may have caused one or more
5808 file-scope named types (i.e. tagged types) to be placed onto the
5809 pending_types_list. We have to get those types off of that list
5810 at some point, and this is the perfect time to do it. If we didn't
5811 take them off now, they might still be on the list when cc1 finally
5812 exits. That might be OK if it weren't for the fact that when we put
5813 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5814 for these types, and that causes them never to be output unless
5815 `output_pending_types_for_scope' takes them off of the list and un-sets
5816 their TREE_ASM_WRITTEN flags. */
5818 output_pending_types_for_scope (NULL_TREE);
5820 /* The above call should have totally emptied the pending_types_list
5821 if this is not a nested function or class. If this is a nested type,
5822 then the remaining pending_types will be emitted when the containing type
5823 is handled. */
5825 if (! DECL_CONTEXT (decl))
5827 if (pending_types != 0)
5828 abort ();
5831 ASM_OUTPUT_POP_SECTION (asm_out_file);
5833 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5834 current_funcdef_number++;
5837 /* Output a marker (i.e. a label) for the beginning of the generated code
5838 for a lexical block. */
5840 static void
5841 dwarfout_begin_block (file, line, blocknum)
5842 FILE *file ATTRIBUTE_UNUSED;
5843 unsigned int line ATTRIBUTE_UNUSED;
5844 unsigned int blocknum;
5846 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5848 function_section (current_function_decl);
5849 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5850 ASM_OUTPUT_LABEL (asm_out_file, label);
5853 /* Output a marker (i.e. a label) for the end of the generated code
5854 for a lexical block. */
5856 static void
5857 dwarfout_end_block (file, line, blocknum)
5858 FILE *file ATTRIBUTE_UNUSED;
5859 unsigned int line ATTRIBUTE_UNUSED;
5860 unsigned int blocknum;
5862 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5864 function_section (current_function_decl);
5865 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5866 ASM_OUTPUT_LABEL (asm_out_file, label);
5869 /* Output a marker (i.e. a label) for the point in the generated code where
5870 the real body of the function begins (after parameters have been moved
5871 to their home locations). */
5873 void
5874 dwarfout_begin_function ()
5876 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5878 if (! use_gnu_debug_info_extensions)
5879 return;
5880 function_section (current_function_decl);
5881 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5882 ASM_OUTPUT_LABEL (asm_out_file, label);
5885 /* Output a marker (i.e. a label) for the point in the generated code where
5886 the real body of the function ends (just before the epilogue code). */
5888 void
5889 dwarfout_end_function ()
5891 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5893 if (! use_gnu_debug_info_extensions)
5894 return;
5895 function_section (current_function_decl);
5896 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5897 ASM_OUTPUT_LABEL (asm_out_file, label);
5900 /* Output a marker (i.e. a label) for the absolute end of the generated code
5901 for a function definition. This gets called *after* the epilogue code
5902 has been generated. */
5904 void
5905 dwarfout_end_epilogue ()
5907 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5909 /* Output a label to mark the endpoint of the code generated for this
5910 function. */
5912 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5913 ASM_OUTPUT_LABEL (asm_out_file, label);
5916 static void
5917 shuffle_filename_entry (new_zeroth)
5918 register filename_entry *new_zeroth;
5920 filename_entry temp_entry;
5921 register filename_entry *limit_p;
5922 register filename_entry *move_p;
5924 if (new_zeroth == &filename_table[0])
5925 return;
5927 temp_entry = *new_zeroth;
5929 /* Shift entries up in the table to make room at [0]. */
5931 limit_p = &filename_table[0];
5932 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5933 *move_p = *(move_p-1);
5935 /* Install the found entry at [0]. */
5937 filename_table[0] = temp_entry;
5940 /* Create a new (string) entry for the .debug_sfnames section. */
5942 static void
5943 generate_new_sfname_entry ()
5945 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5947 fputc ('\n', asm_out_file);
5948 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
5949 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5950 ASM_OUTPUT_LABEL (asm_out_file, label);
5951 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5952 filename_table[0].name
5953 ? filename_table[0].name
5954 : "");
5955 ASM_OUTPUT_POP_SECTION (asm_out_file);
5958 /* Lookup a filename (in the list of filenames that we know about here in
5959 dwarfout.c) and return its "index". The index of each (known) filename
5960 is just a unique number which is associated with only that one filename.
5961 We need such numbers for the sake of generating labels (in the
5962 .debug_sfnames section) and references to those unique labels (in the
5963 .debug_srcinfo and .debug_macinfo sections).
5965 If the filename given as an argument is not found in our current list,
5966 add it to the list and assign it the next available unique index number.
5968 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5969 one), we shuffle the filename found (or added) up to the zeroth entry of
5970 our list of filenames (which is always searched linearly). We do this so
5971 as to optimize the most common case for these filename lookups within
5972 dwarfout.c. The most common case by far is the case where we call
5973 lookup_filename to lookup the very same filename that we did a lookup
5974 on the last time we called lookup_filename. We make sure that this
5975 common case is fast because such cases will constitute 99.9% of the
5976 lookups we ever do (in practice).
5978 If we add a new filename entry to our table, we go ahead and generate
5979 the corresponding entry in the .debug_sfnames section right away.
5980 Doing so allows us to avoid tickling an assembler bug (present in some
5981 m68k assemblers) which yields assembly-time errors in cases where the
5982 difference of two label addresses is taken and where the two labels
5983 are in a section *other* than the one where the difference is being
5984 calculated, and where at least one of the two symbol references is a
5985 forward reference. (This bug could be tickled by our .debug_srcinfo
5986 entries if we don't output their corresponding .debug_sfnames entries
5987 before them.) */
5989 static unsigned
5990 lookup_filename (file_name)
5991 const char *file_name;
5993 register filename_entry *search_p;
5994 register filename_entry *limit_p = &filename_table[ft_entries];
5996 for (search_p = filename_table; search_p < limit_p; search_p++)
5997 if (!strcmp (file_name, search_p->name))
5999 /* When we get here, we have found the filename that we were
6000 looking for in the filename_table. Now we want to make sure
6001 that it gets moved to the zero'th entry in the table (if it
6002 is not already there) so that subsequent attempts to find the
6003 same filename will find it as quickly as possible. */
6005 shuffle_filename_entry (search_p);
6006 return filename_table[0].number;
6009 /* We come here whenever we have a new filename which is not registered
6010 in the current table. Here we add it to the table. */
6012 /* Prepare to add a new table entry by making sure there is enough space
6013 in the table to do so. If not, expand the current table. */
6015 if (ft_entries == ft_entries_allocated)
6017 ft_entries_allocated += FT_ENTRIES_INCREMENT;
6018 filename_table
6019 = (filename_entry *)
6020 xrealloc (filename_table,
6021 ft_entries_allocated * sizeof (filename_entry));
6024 /* Initially, add the new entry at the end of the filename table. */
6026 filename_table[ft_entries].number = ft_entries;
6027 filename_table[ft_entries].name = xstrdup (file_name);
6029 /* Shuffle the new entry into filename_table[0]. */
6031 shuffle_filename_entry (&filename_table[ft_entries]);
6033 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6034 generate_new_sfname_entry ();
6036 ft_entries++;
6037 return filename_table[0].number;
6040 static void
6041 generate_srcinfo_entry (line_entry_num, files_entry_num)
6042 unsigned line_entry_num;
6043 unsigned files_entry_num;
6045 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6047 fputc ('\n', asm_out_file);
6048 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6049 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
6050 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
6051 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
6052 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
6053 ASM_OUTPUT_POP_SECTION (asm_out_file);
6056 void
6057 dwarfout_line (filename, line)
6058 register const char *filename;
6059 register unsigned line;
6061 if (debug_info_level >= DINFO_LEVEL_NORMAL
6062 /* We can't emit line number info for functions in separate sections,
6063 because the assembler can't subtract labels in different sections. */
6064 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
6066 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6067 static unsigned last_line_entry_num = 0;
6068 static unsigned prev_file_entry_num = (unsigned) -1;
6069 register unsigned this_file_entry_num;
6071 function_section (current_function_decl);
6072 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
6073 ASM_OUTPUT_LABEL (asm_out_file, label);
6075 fputc ('\n', asm_out_file);
6077 if (use_gnu_debug_info_extensions)
6078 this_file_entry_num = lookup_filename (filename);
6079 else
6080 this_file_entry_num = (unsigned) -1;
6082 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6083 if (this_file_entry_num != prev_file_entry_num)
6085 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
6087 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
6088 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
6092 register const char *tail = strrchr (filename, '/');
6094 if (tail != NULL)
6095 filename = tail;
6098 fprintf (asm_out_file, "%s%u\t%s %s:%u\n",
6099 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
6100 filename, line);
6101 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6102 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
6103 ASM_OUTPUT_POP_SECTION (asm_out_file);
6105 if (this_file_entry_num != prev_file_entry_num)
6106 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
6107 prev_file_entry_num = this_file_entry_num;
6111 /* Generate an entry in the .debug_macinfo section. */
6113 static void
6114 generate_macinfo_entry (type_and_offset, string)
6115 register const char *type_and_offset;
6116 register const char *string;
6118 if (! use_gnu_debug_info_extensions)
6119 return;
6121 fputc ('\n', asm_out_file);
6122 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6123 fprintf (asm_out_file, "%s%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
6124 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
6125 ASM_OUTPUT_POP_SECTION (asm_out_file);
6128 /* Wrapper for toplev.c callback to check debug info level. */
6129 static void
6130 dwarfout_start_source_file_check (line, filename)
6131 unsigned int line;
6132 register const char *filename;
6134 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6135 dwarfout_start_source_file (line, filename);
6138 static void
6139 dwarfout_start_source_file (line, filename)
6140 unsigned int line ATTRIBUTE_UNUSED;
6141 register const char *filename;
6143 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6144 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
6146 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
6147 sprintf (type_and_offset, "0x%08x+%s-%s",
6148 ((unsigned) MACINFO_start << 24),
6149 /* Hack: skip leading '*' . */
6150 (*label == '*') + label,
6151 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
6152 generate_macinfo_entry (type_and_offset, "");
6155 /* Wrapper for toplev.c callback to check debug info level. */
6156 static void
6157 dwarfout_end_source_file_check (lineno)
6158 register unsigned lineno;
6160 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6161 dwarfout_end_source_file (lineno);
6164 static void
6165 dwarfout_end_source_file (lineno)
6166 register unsigned lineno;
6168 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6170 sprintf (type_and_offset, "0x%08x+%u",
6171 ((unsigned) MACINFO_resume << 24), lineno);
6172 generate_macinfo_entry (type_and_offset, "");
6175 /* Called from check_newline in c-parse.y. The `buffer' parameter
6176 contains the tail part of the directive line, i.e. the part which
6177 is past the initial whitespace, #, whitespace, directive-name,
6178 whitespace part. */
6180 static void
6181 dwarfout_define (lineno, buffer)
6182 register unsigned lineno;
6183 register const char *buffer;
6185 static int initialized = 0;
6186 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6188 if (!initialized)
6190 dwarfout_start_source_file (0, primary_filename);
6191 initialized = 1;
6193 sprintf (type_and_offset, "0x%08x+%u",
6194 ((unsigned) MACINFO_define << 24), lineno);
6195 generate_macinfo_entry (type_and_offset, buffer);
6198 /* Called from check_newline in c-parse.y. The `buffer' parameter
6199 contains the tail part of the directive line, i.e. the part which
6200 is past the initial whitespace, #, whitespace, directive-name,
6201 whitespace part. */
6203 static void
6204 dwarfout_undef (lineno, buffer)
6205 register unsigned lineno;
6206 register const char *buffer;
6208 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6210 sprintf (type_and_offset, "0x%08x+%u",
6211 ((unsigned) MACINFO_undef << 24), lineno);
6212 generate_macinfo_entry (type_and_offset, buffer);
6215 /* Set up for Dwarf output at the start of compilation. */
6217 static void
6218 dwarfout_init (asm_out_file, main_input_filename)
6219 register FILE *asm_out_file;
6220 register const char *main_input_filename;
6222 /* Remember the name of the primary input file. */
6224 primary_filename = main_input_filename;
6226 /* Allocate the initial hunk of the pending_sibling_stack. */
6228 pending_sibling_stack
6229 = (unsigned *)
6230 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
6231 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
6232 pending_siblings = 1;
6234 /* Allocate the initial hunk of the filename_table. */
6236 filename_table
6237 = (filename_entry *)
6238 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
6239 ft_entries_allocated = FT_ENTRIES_INCREMENT;
6240 ft_entries = 0;
6242 /* Allocate the initial hunk of the pending_types_list. */
6244 pending_types_list
6245 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
6246 pending_types_allocated = PENDING_TYPES_INCREMENT;
6247 pending_types = 0;
6249 /* Create an artificial RECORD_TYPE node which we can use in our hack
6250 to get the DIEs representing types of formal parameters to come out
6251 only *after* the DIEs for the formal parameters themselves. */
6253 fake_containing_scope = make_node (RECORD_TYPE);
6255 /* Output a starting label for the .text section. */
6257 fputc ('\n', asm_out_file);
6258 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
6259 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
6260 ASM_OUTPUT_POP_SECTION (asm_out_file);
6262 /* Output a starting label for the .data section. */
6264 fputc ('\n', asm_out_file);
6265 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
6266 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
6267 ASM_OUTPUT_POP_SECTION (asm_out_file);
6269 #if 0 /* GNU C doesn't currently use .data1. */
6270 /* Output a starting label for the .data1 section. */
6272 fputc ('\n', asm_out_file);
6273 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
6274 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
6275 ASM_OUTPUT_POP_SECTION (asm_out_file);
6276 #endif
6278 /* Output a starting label for the .rodata section. */
6280 fputc ('\n', asm_out_file);
6281 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
6282 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
6283 ASM_OUTPUT_POP_SECTION (asm_out_file);
6285 #if 0 /* GNU C doesn't currently use .rodata1. */
6286 /* Output a starting label for the .rodata1 section. */
6288 fputc ('\n', asm_out_file);
6289 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
6290 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
6291 ASM_OUTPUT_POP_SECTION (asm_out_file);
6292 #endif
6294 /* Output a starting label for the .bss section. */
6296 fputc ('\n', asm_out_file);
6297 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
6298 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
6299 ASM_OUTPUT_POP_SECTION (asm_out_file);
6301 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6303 if (use_gnu_debug_info_extensions)
6305 /* Output a starting label and an initial (compilation directory)
6306 entry for the .debug_sfnames section. The starting label will be
6307 referenced by the initial entry in the .debug_srcinfo section. */
6309 fputc ('\n', asm_out_file);
6310 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6311 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
6313 register const char *pwd = getpwd ();
6314 register char *dirname;
6316 if (!pwd)
6317 fatal_io_error ("can't get current directory");
6319 dirname = concat (pwd, "/", NULL);
6320 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
6321 free (dirname);
6323 ASM_OUTPUT_POP_SECTION (asm_out_file);
6326 if (debug_info_level >= DINFO_LEVEL_VERBOSE
6327 && use_gnu_debug_info_extensions)
6329 /* Output a starting label for the .debug_macinfo section. This
6330 label will be referenced by the AT_mac_info attribute in the
6331 TAG_compile_unit DIE. */
6333 fputc ('\n', asm_out_file);
6334 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6335 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
6336 ASM_OUTPUT_POP_SECTION (asm_out_file);
6339 /* Generate the initial entry for the .line section. */
6341 fputc ('\n', asm_out_file);
6342 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6343 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
6344 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
6345 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6346 ASM_OUTPUT_POP_SECTION (asm_out_file);
6348 if (use_gnu_debug_info_extensions)
6350 /* Generate the initial entry for the .debug_srcinfo section. */
6352 fputc ('\n', asm_out_file);
6353 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6354 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
6355 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
6356 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
6357 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6358 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
6359 #ifdef DWARF_TIMESTAMPS
6360 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
6361 #else
6362 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6363 #endif
6364 ASM_OUTPUT_POP_SECTION (asm_out_file);
6367 /* Generate the initial entry for the .debug_pubnames section. */
6369 fputc ('\n', asm_out_file);
6370 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6371 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6372 ASM_OUTPUT_POP_SECTION (asm_out_file);
6374 /* Generate the initial entry for the .debug_aranges section. */
6376 fputc ('\n', asm_out_file);
6377 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6378 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6379 DEBUG_ARANGES_END_LABEL,
6380 DEBUG_ARANGES_BEGIN_LABEL);
6381 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_BEGIN_LABEL);
6382 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 1);
6383 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6384 ASM_OUTPUT_POP_SECTION (asm_out_file);
6387 /* Setup first DIE number == 1. */
6388 NEXT_DIE_NUM = next_unused_dienum++;
6390 /* Generate the initial DIE for the .debug section. Note that the
6391 (string) value given in the AT_name attribute of the TAG_compile_unit
6392 DIE will (typically) be a relative pathname and that this pathname
6393 should be taken as being relative to the directory from which the
6394 compiler was invoked when the given (base) source file was compiled. */
6396 fputc ('\n', asm_out_file);
6397 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6398 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
6399 output_die (output_compile_unit_die, (PTR) main_input_filename);
6400 ASM_OUTPUT_POP_SECTION (asm_out_file);
6402 fputc ('\n', asm_out_file);
6405 /* Output stuff that dwarf requires at the end of every file. */
6407 static void
6408 dwarfout_finish (asm_out_file, main_input_filename)
6409 register FILE *asm_out_file;
6410 register const char *main_input_filename ATTRIBUTE_UNUSED;
6412 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6414 fputc ('\n', asm_out_file);
6415 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6416 retry_incomplete_types ();
6417 fputc ('\n', asm_out_file);
6419 /* Mark the end of the chain of siblings which represent all file-scope
6420 declarations in this compilation unit. */
6422 /* The (null) DIE which represents the terminator for the (sibling linked)
6423 list of file-scope items is *special*. Normally, we would just call
6424 end_sibling_chain at this point in order to output a word with the
6425 value `4' and that word would act as the terminator for the list of
6426 DIEs describing file-scope items. Unfortunately, if we were to simply
6427 do that, the label that would follow this DIE in the .debug section
6428 (i.e. `..D2') would *not* be properly aligned (as it must be on some
6429 machines) to a 4 byte boundary.
6431 In order to force the label `..D2' to get aligned to a 4 byte boundary,
6432 the trick used is to insert extra (otherwise useless) padding bytes
6433 into the (null) DIE that we know must precede the ..D2 label in the
6434 .debug section. The amount of padding required can be anywhere between
6435 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
6436 with the padding) would normally contain the value 4, but now it will
6437 also have to include the padding bytes, so it will instead have some
6438 value in the range 4..7.
6440 Fortunately, the rules of Dwarf say that any DIE whose length word
6441 contains *any* value less than 8 should be treated as a null DIE, so
6442 this trick works out nicely. Clever, eh? Don't give me any credit
6443 (or blame). I didn't think of this scheme. I just conformed to it.
6446 output_die (output_padded_null_die, (void *) 0);
6447 dienum_pop ();
6449 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
6450 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
6451 ASM_OUTPUT_POP_SECTION (asm_out_file);
6453 /* Output a terminator label for the .text section. */
6455 fputc ('\n', asm_out_file);
6456 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
6457 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
6458 ASM_OUTPUT_POP_SECTION (asm_out_file);
6460 /* Output a terminator label for the .data section. */
6462 fputc ('\n', asm_out_file);
6463 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
6464 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
6465 ASM_OUTPUT_POP_SECTION (asm_out_file);
6467 #if 0 /* GNU C doesn't currently use .data1. */
6468 /* Output a terminator label for the .data1 section. */
6470 fputc ('\n', asm_out_file);
6471 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
6472 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
6473 ASM_OUTPUT_POP_SECTION (asm_out_file);
6474 #endif
6476 /* Output a terminator label for the .rodata section. */
6478 fputc ('\n', asm_out_file);
6479 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
6480 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
6481 ASM_OUTPUT_POP_SECTION (asm_out_file);
6483 #if 0 /* GNU C doesn't currently use .rodata1. */
6484 /* Output a terminator label for the .rodata1 section. */
6486 fputc ('\n', asm_out_file);
6487 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
6488 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
6489 ASM_OUTPUT_POP_SECTION (asm_out_file);
6490 #endif
6492 /* Output a terminator label for the .bss section. */
6494 fputc ('\n', asm_out_file);
6495 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
6496 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
6497 ASM_OUTPUT_POP_SECTION (asm_out_file);
6499 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6501 /* Output a terminating entry for the .line section. */
6503 fputc ('\n', asm_out_file);
6504 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6505 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
6506 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6507 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6508 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6509 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
6510 ASM_OUTPUT_POP_SECTION (asm_out_file);
6512 if (use_gnu_debug_info_extensions)
6514 /* Output a terminating entry for the .debug_srcinfo section. */
6516 fputc ('\n', asm_out_file);
6517 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6518 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6519 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6520 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6521 ASM_OUTPUT_POP_SECTION (asm_out_file);
6524 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6526 /* Output terminating entries for the .debug_macinfo section. */
6528 dwarfout_end_source_file (0);
6530 fputc ('\n', asm_out_file);
6531 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6532 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6533 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6534 ASM_OUTPUT_POP_SECTION (asm_out_file);
6537 /* Generate the terminating entry for the .debug_pubnames section. */
6539 fputc ('\n', asm_out_file);
6540 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6541 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6542 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6543 ASM_OUTPUT_POP_SECTION (asm_out_file);
6545 /* Generate the terminating entries for the .debug_aranges section.
6547 Note that we want to do this only *after* we have output the end
6548 labels (for the various program sections) which we are going to
6549 refer to here. This allows us to work around a bug in the m68k
6550 svr4 assembler. That assembler gives bogus assembly-time errors
6551 if (within any given section) you try to take the difference of
6552 two relocatable symbols, both of which are located within some
6553 other section, and if one (or both?) of the symbols involved is
6554 being forward-referenced. By generating the .debug_aranges
6555 entries at this late point in the assembly output, we skirt the
6556 issue simply by avoiding forward-references.
6559 fputc ('\n', asm_out_file);
6560 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6562 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6563 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6565 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6566 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6568 #if 0 /* GNU C doesn't currently use .data1. */
6569 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6570 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6571 DATA1_BEGIN_LABEL);
6572 #endif
6574 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6575 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6576 RODATA_BEGIN_LABEL);
6578 #if 0 /* GNU C doesn't currently use .rodata1. */
6579 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6580 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6581 RODATA1_BEGIN_LABEL);
6582 #endif
6584 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6585 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6587 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6588 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6590 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_END_LABEL);
6591 ASM_OUTPUT_POP_SECTION (asm_out_file);
6594 /* There should not be any pending types left at the end. We need
6595 this now because it may not have been checked on the last call to
6596 dwarfout_file_scope_decl. */
6597 if (pending_types != 0)
6598 abort ();
6601 #endif /* DWARF_DEBUGGING_INFO */