* Makefile.in (rtlanal.o): Depend on $(TM_P_H).
[official-gcc.git] / gcc / dwarfout.c
blobf5f2e3d6d6c608ee4fd95bdce2687c92311f5ca2
1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
25 Notes on the GNU Implementation of DWARF Debugging Information
26 --------------------------------------------------------------
27 Last Major Update: Sun Jul 17 08:17:42 PDT 1994 by rfg@segfault.us.com
28 ------------------------------------------------------------
30 This file describes special and unique aspects of the GNU implementation of
31 the DWARF Version 1 debugging information language, as provided in the GNU
32 version 2.x compiler(s).
34 For general information about the DWARF debugging information language,
35 you should obtain the DWARF version 1.1 specification document (and perhaps
36 also the DWARF version 2 draft specification document) developed by the
37 (now defunct) UNIX International Programming Languages Special Interest Group.
39 To obtain a copy of the DWARF Version 1 and/or DWARF Version 2
40 specification, visit the web page for the DWARF Version 2 committee, at
42 http://www.eagercon.com/dwarf/dwarf2std.htm
44 The generation of DWARF debugging information by the GNU version 2.x C
45 compiler has now been tested rather extensively for m88k, i386, i860, and
46 Sparc targets. The DWARF output of the GNU C compiler appears to inter-
47 operate well with the standard SVR4 SDB debugger on these kinds of target
48 systems (but of course, there are no guarantees).
50 DWARF 1 generation for the GNU g++ compiler is implemented, but limited.
51 C++ users should definitely use DWARF 2 instead.
53 Future plans for the dwarfout.c module of the GNU compiler(s) includes the
54 addition of full support for GNU FORTRAN. (This should, in theory, be a
55 lot simpler to add than adding support for g++... but we'll see.)
57 Many features of the DWARF version 2 specification have been adapted to
58 (and used in) the GNU implementation of DWARF (version 1). In most of
59 these cases, a DWARF version 2 approach is used in place of (or in addition
60 to) DWARF version 1 stuff simply because it is apparent that DWARF version
61 1 is not sufficiently expressive to provide the kinds of information which
62 may be necessary to support really robust debugging. In all of these cases
63 however, the use of DWARF version 2 features should not interfere in any
64 way with the interoperability (of GNU compilers) with generally available
65 "classic" (pre version 1) DWARF consumer tools (e.g. SVR4 SDB).
67 The DWARF generation enhancement for the GNU compiler(s) was initially
68 donated to the Free Software Foundation by Network Computing Devices.
69 (Thanks NCD!) Additional development and maintenance of dwarfout.c has
70 been largely supported (i.e. funded) by Intel Corporation. (Thanks Intel!)
72 If you have questions or comments about the DWARF generation feature, please
73 send mail to me <rfg@netcom.com>. I will be happy to investigate any bugs
74 reported and I may even provide fixes (but of course, I can make no promises).
76 The DWARF debugging information produced by GCC may deviate in a few minor
77 (but perhaps significant) respects from the DWARF debugging information
78 currently produced by other C compilers. A serious attempt has been made
79 however to conform to the published specifications, to existing practice,
80 and to generally accepted norms in the GNU implementation of DWARF.
82 ** IMPORTANT NOTE ** ** IMPORTANT NOTE ** ** IMPORTANT NOTE **
84 Under normal circumstances, the DWARF information generated by the GNU
85 compilers (in an assembly language file) is essentially impossible for
86 a human being to read. This fact can make it very difficult to debug
87 certain DWARF-related problems. In order to overcome this difficulty,
88 a feature has been added to dwarfout.c (enabled by the -dA
89 option) which causes additional comments to be placed into the assembly
90 language output file, out to the right-hand side of most bits of DWARF
91 material. The comments indicate (far more clearly that the obscure
92 DWARF hex codes do) what is actually being encoded in DWARF. Thus, the
93 -dA option can be highly useful for those who must study the
94 DWARF output from the GNU compilers in detail.
96 ---------
98 (Footnote: Within this file, the term `Debugging Information Entry' will
99 be abbreviated as `DIE'.)
102 Release Notes (aka known bugs)
103 -------------------------------
105 In one very obscure case involving dynamically sized arrays, the DWARF
106 "location information" for such an array may make it appear that the
107 array has been totally optimized out of existence, when in fact it
108 *must* actually exist. (This only happens when you are using *both* -g
109 *and* -O.) This is due to aggressive dead store elimination in the
110 compiler, and to the fact that the DECL_RTL expressions associated with
111 variables are not always updated to correctly reflect the effects of
112 GCC's aggressive dead store elimination.
114 -------------------------------
116 When attempting to set a breakpoint at the "start" of a function compiled
117 with -g1, the debugger currently has no way of knowing exactly where the
118 end of the prologue code for the function is. Thus, for most targets,
119 all the debugger can do is to set the breakpoint at the AT_low_pc address
120 for the function. But if you stop there and then try to look at one or
121 more of the formal parameter values, they may not have been "homed" yet,
122 so you may get inaccurate answers (or perhaps even addressing errors).
124 Some people may consider this simply a non-feature, but I consider it a
125 bug, and I hope to provide some GNU-specific attributes (on function
126 DIEs) which will specify the address of the end of the prologue and the
127 address of the beginning of the epilogue in a future release.
129 -------------------------------
131 It is believed at this time that old bugs relating to the AT_bit_offset
132 values for bit-fields have been fixed.
134 There may still be some very obscure bugs relating to the DWARF description
135 of type `long long' bit-fields for target machines (e.g. 80x86 machines)
136 where the alignment of type `long long' data objects is different from
137 (and less than) the size of a type `long long' data object.
139 Please report any problems with the DWARF description of bit-fields as you
140 would any other GCC bug. (Procedures for bug reporting are given in the
141 GNU C compiler manual.)
143 --------------------------------
145 At this time, GCC does not know how to handle the GNU C "nested functions"
146 extension. (See the GCC manual for more info on this extension to ANSI C.)
148 --------------------------------
150 The GNU compilers now represent inline functions (and inlined instances
151 thereof) in exactly the manner described by the current DWARF version 2
152 (draft) specification. The version 1 specification for handling inline
153 functions (and inlined instances) was known to be brain-damaged (by the
154 PLSIG) when the version 1 spec was finalized, but it was simply too late
155 in the cycle to get it removed before the version 1 spec was formally
156 released to the public (by UI).
158 --------------------------------
160 At this time, GCC does not generate the kind of really precise information
161 about the exact declared types of entities with signed integral types which
162 is required by the current DWARF draft specification.
164 Specifically, the current DWARF draft specification seems to require that
165 the type of an non-unsigned integral bit-field member of a struct or union
166 type be represented as either a "signed" type or as a "plain" type,
167 depending upon the exact set of keywords that were used in the
168 type specification for the given bit-field member. It was felt (by the
169 UI/PLSIG) that this distinction between "plain" and "signed" integral types
170 could have some significance (in the case of bit-fields) because ANSI C
171 does not constrain the signedness of a plain bit-field, whereas it does
172 constrain the signedness of an explicitly "signed" bit-field. For this
173 reason, the current DWARF specification calls for compilers to produce
174 type information (for *all* integral typed entities... not just bit-fields)
175 which explicitly indicates the signedness of the relevant type to be
176 "signed" or "plain" or "unsigned".
178 Unfortunately, the GNU DWARF implementation is currently incapable of making
179 such distinctions.
181 --------------------------------
184 Known Interoperability Problems
185 -------------------------------
187 Although the GNU implementation of DWARF conforms (for the most part) with
188 the current UI/PLSIG DWARF version 1 specification (with many compatible
189 version 2 features added in as "vendor specific extensions" just for good
190 measure) there are a few known cases where GCC's DWARF output can cause
191 some confusion for "classic" (pre version 1) DWARF consumers such as the
192 System V Release 4 SDB debugger. These cases are described in this section.
194 --------------------------------
196 The DWARF version 1 specification includes the fundamental type codes
197 FT_ext_prec_float, FT_complex, FT_dbl_prec_complex, and FT_ext_prec_complex.
198 Since GNU C is only a C compiler (and since C doesn't provide any "complex"
199 data types) the only one of these fundamental type codes which GCC ever
200 generates is FT_ext_prec_float. This fundamental type code is generated
201 by GCC for the `long double' data type. Unfortunately, due to an apparent
202 bug in the SVR4 SDB debugger, SDB can become very confused wherever any
203 attempt is made to print a variable, parameter, or field whose type was
204 given in terms of FT_ext_prec_float.
206 (Actually, SVR4 SDB fails to understand *any* of the four fundamental type
207 codes mentioned here. This will fact will cause additional problems when
208 there is a GNU FORTRAN front-end.)
210 --------------------------------
212 In general, it appears that SVR4 SDB is not able to effectively ignore
213 fundamental type codes in the "implementation defined" range. This can
214 cause problems when a program being debugged uses the `long long' data
215 type (or the signed or unsigned varieties thereof) because these types
216 are not defined by ANSI C, and thus, GCC must use its own private fundamental
217 type codes (from the implementation-defined range) to represent these types.
219 --------------------------------
222 General GNU DWARF extensions
223 ----------------------------
225 In the current DWARF version 1 specification, no mechanism is specified by
226 which accurate information about executable code from include files can be
227 properly (and fully) described. (The DWARF version 2 specification *does*
228 specify such a mechanism, but it is about 10 times more complicated than
229 it needs to be so I'm not terribly anxious to try to implement it right
230 away.)
232 In the GNU implementation of DWARF version 1, a fully downward-compatible
233 extension has been implemented which permits the GNU compilers to specify
234 which executable lines come from which files. This extension places
235 additional information (about source file names) in GNU-specific sections
236 (which should be totally ignored by all non-GNU DWARF consumers) so that
237 this extended information can be provided (to GNU DWARF consumers) in a way
238 which is totally transparent (and invisible) to non-GNU DWARF consumers
239 (e.g. the SVR4 SDB debugger). The additional information is placed *only*
240 in specialized GNU-specific sections, where it should never even be seen
241 by non-GNU DWARF consumers.
243 To understand this GNU DWARF extension, imagine that the sequence of entries
244 in the .lines section is broken up into several subsections. Each contiguous
245 sequence of .line entries which relates to a sequence of lines (or statements)
246 from one particular file (either a `base' file or an `include' file) could
247 be called a `line entries chunk' (LEC).
249 For each LEC there is one entry in the .debug_srcinfo section.
251 Each normal entry in the .debug_srcinfo section consists of two 4-byte
252 words of data as follows:
254 (1) The starting address (relative to the entire .line section)
255 of the first .line entry in the relevant LEC.
257 (2) The starting address (relative to the entire .debug_sfnames
258 section) of a NUL terminated string representing the
259 relevant filename. (This filename name be either a
260 relative or an absolute filename, depending upon how the
261 given source file was located during compilation.)
263 Obviously, each .debug_srcinfo entry allows you to find the relevant filename,
264 and it also points you to the first .line entry that was generated as a result
265 of having compiled a given source line from the given source file.
267 Each subsequent .line entry should also be assumed to have been produced
268 as a result of compiling yet more lines from the same file. The end of
269 any given LEC is easily found by looking at the first 4-byte pointer in
270 the *next* .debug_srcinfo entry. That next .debug_srcinfo entry points
271 to a new and different LEC, so the preceding LEC (implicitly) must have
272 ended with the last .line section entry which occurs at the 2 1/2 words
273 just before the address given in the first pointer of the new .debug_srcinfo
274 entry.
276 The following picture may help to clarify this feature. Let's assume that
277 `LE' stands for `.line entry'. Also, assume that `* 'stands for a pointer.
280 .line section .debug_srcinfo section .debug_sfnames section
281 ----------------------------------------------------------------
283 LE <---------------------- *
284 LE * -----------------> "foobar.c" <---
285 LE |
286 LE |
287 LE <---------------------- * |
288 LE * -----------------> "foobar.h" <| |
289 LE | |
290 LE | |
291 LE <---------------------- * | |
292 LE * -----------------> "inner.h" | |
293 LE | |
294 LE <---------------------- * | |
295 LE * ------------------------------- |
296 LE |
297 LE |
298 LE |
299 LE |
300 LE <---------------------- * |
301 LE * -----------------------------------
306 In effect, each entry in the .debug_srcinfo section points to *both* a
307 filename (in the .debug_sfnames section) and to the start of a block of
308 consecutive LEs (in the .line section).
310 Note that just like in the .line section, there are specialized first and
311 last entries in the .debug_srcinfo section for each object file. These
312 special first and last entries for the .debug_srcinfo section are very
313 different from the normal .debug_srcinfo section entries. They provide
314 additional information which may be helpful to a debugger when it is
315 interpreting the data in the .debug_srcinfo, .debug_sfnames, and .line
316 sections.
318 The first entry in the .debug_srcinfo section for each compilation unit
319 consists of five 4-byte words of data. The contents of these five words
320 should be interpreted (by debuggers) as follows:
322 (1) The starting address (relative to the entire .line section)
323 of the .line section for this compilation unit.
325 (2) The starting address (relative to the entire .debug_sfnames
326 section) of the .debug_sfnames section for this compilation
327 unit.
329 (3) The starting address (in the execution virtual address space)
330 of the .text section for this compilation unit.
332 (4) The ending address plus one (in the execution virtual address
333 space) of the .text section for this compilation unit.
335 (5) The date/time (in seconds since midnight 1/1/70) at which the
336 compilation of this compilation unit occurred. This value
337 should be interpreted as an unsigned quantity because gcc
338 might be configured to generate a default value of 0xffffffff
339 in this field (in cases where it is desired to have object
340 files created at different times from identical source files
341 be byte-for-byte identical). By default, these timestamps
342 are *not* generated by dwarfout.c (so that object files
343 compiled at different times will be byte-for-byte identical).
344 If you wish to enable this "timestamp" feature however, you
345 can simply place a #define for the symbol `DWARF_TIMESTAMPS'
346 in your target configuration file and then rebuild the GNU
347 compiler(s).
349 Note that the first string placed into the .debug_sfnames section for each
350 compilation unit is the name of the directory in which compilation occurred.
351 This string ends with a `/' (to help indicate that it is the pathname of a
352 directory). Thus, the second word of each specialized initial .debug_srcinfo
353 entry for each compilation unit may be used as a pointer to the (string)
354 name of the compilation directory, and that string may in turn be used to
355 "absolutize" any relative pathnames which may appear later on in the
356 .debug_sfnames section entries for the same compilation unit.
358 The fifth and last word of each specialized starting entry for a compilation
359 unit in the .debug_srcinfo section may (depending upon your configuration)
360 indicate the date/time of compilation, and this may be used (by a debugger)
361 to determine if any of the source files which contributed code to this
362 compilation unit are newer than the object code for the compilation unit
363 itself. If so, the debugger may wish to print an "out-of-date" warning
364 about the compilation unit.
366 The .debug_srcinfo section associated with each compilation will also have
367 a specialized terminating entry. This terminating .debug_srcinfo section
368 entry will consist of the following two 4-byte words of data:
370 (1) The offset, measured from the start of the .line section to
371 the beginning of the terminating entry for the .line section.
373 (2) A word containing the value 0xffffffff.
375 --------------------------------
377 In the current DWARF version 1 specification, no mechanism is specified by
378 which information about macro definitions and un-definitions may be provided
379 to the DWARF consumer.
381 The DWARF version 2 (draft) specification does specify such a mechanism.
382 That specification was based on the GNU ("vendor specific extension")
383 which provided some support for macro definitions and un-definitions,
384 but the "official" DWARF version 2 (draft) specification mechanism for
385 handling macros and the GNU implementation have diverged somewhat. I
386 plan to update the GNU implementation to conform to the "official"
387 DWARF version 2 (draft) specification as soon as I get time to do that.
389 Note that in the GNU implementation, additional information about macro
390 definitions and un-definitions is *only* provided when the -g3 level of
391 debug-info production is selected. (The default level is -g2 and the
392 plain old -g option is considered to be identical to -g2.)
394 GCC records information about macro definitions and undefinitions primarily
395 in a section called the .debug_macinfo section. Normal entries in the
396 .debug_macinfo section consist of the following three parts:
398 (1) A special "type" byte.
400 (2) A 3-byte line-number/filename-offset field.
402 (3) A NUL terminated string.
404 The interpretation of the second and third parts is dependent upon the
405 value of the leading (type) byte.
407 The type byte may have one of four values depending upon the type of the
408 .debug_macinfo entry which follows. The 1-byte MACINFO type codes presently
409 used, and their meanings are as follows:
411 MACINFO_start A base file or an include file starts here.
412 MACINFO_resume The current base or include file ends here.
413 MACINFO_define A #define directive occurs here.
414 MACINFO_undef A #undef directive occur here.
416 (Note that the MACINFO_... codes mentioned here are simply symbolic names
417 for constants which are defined in the GNU dwarf.h file.)
419 For MACINFO_define and MACINFO_undef entries, the second (3-byte) field
420 contains the number of the source line (relative to the start of the current
421 base source file or the current include files) when the #define or #undef
422 directive appears. For a MACINFO_define entry, the following string field
423 contains the name of the macro which is defined, followed by its definition.
424 Note that the definition is always separated from the name of the macro
425 by at least one whitespace character. For a MACINFO_undef entry, the
426 string which follows the 3-byte line number field contains just the name
427 of the macro which is being undef'ed.
429 For a MACINFO_start entry, the 3-byte field following the type byte contains
430 the offset, relative to the start of the .debug_sfnames section for the
431 current compilation unit, of a string which names the new source file which
432 is beginning its inclusion at this point. Following that 3-byte field,
433 each MACINFO_start entry always contains a zero length NUL terminated
434 string.
436 For a MACINFO_resume entry, the 3-byte field following the type byte contains
437 the line number WITHIN THE INCLUDING FILE at which the inclusion of the
438 current file (whose inclusion ends here) was initiated. Following that
439 3-byte field, each MACINFO_resume entry always contains a zero length NUL
440 terminated string.
442 Each set of .debug_macinfo entries for each compilation unit is terminated
443 by a special .debug_macinfo entry consisting of a 4-byte zero value followed
444 by a single NUL byte.
446 --------------------------------
448 In the current DWARF draft specification, no provision is made for providing
449 a separate level of (limited) debugging information necessary to support
450 tracebacks (only) through fully-debugged code (e.g. code in system libraries).
452 A proposal to define such a level was submitted (by me) to the UI/PLSIG.
453 This proposal was rejected by the UI/PLSIG for inclusion into the DWARF
454 version 1 specification for two reasons. First, it was felt (by the PLSIG)
455 that the issues involved in supporting a "traceback only" subset of DWARF
456 were not well understood. Second, and perhaps more importantly, the PLSIG
457 is already having enough trouble agreeing on what it means to be "conforming"
458 to the DWARF specification, and it was felt that trying to specify multiple
459 different *levels* of conformance would only complicate our discussions of
460 this already divisive issue. Nonetheless, the GNU implementation of DWARF
461 provides an abbreviated "traceback only" level of debug-info production for
462 use with fully-debugged "system library" code. This level should only be
463 used for fully debugged system library code, and even then, it should only
464 be used where there is a very strong need to conserve disk space. This
465 abbreviated level of debug-info production can be used by specifying the
466 -g1 option on the compilation command line.
468 --------------------------------
470 As mentioned above, the GNU implementation of DWARF currently uses the DWARF
471 version 2 (draft) approach for inline functions (and inlined instances
472 thereof). This is used in preference to the version 1 approach because
473 (quite simply) the version 1 approach is highly brain-damaged and probably
474 unworkable.
476 --------------------------------
479 GNU DWARF Representation of GNU C Extensions to ANSI C
480 ------------------------------------------------------
482 The file dwarfout.c has been designed and implemented so as to provide
483 some reasonable DWARF representation for each and every declarative
484 construct which is accepted by the GNU C compiler. Since the GNU C
485 compiler accepts a superset of ANSI C, this means that there are some
486 cases in which the DWARF information produced by GCC must take some
487 liberties in improvising DWARF representations for declarations which
488 are only valid in (extended) GNU C.
490 In particular, GNU C provides at least three significant extensions to
491 ANSI C when it comes to declarations. These are (1) inline functions,
492 and (2) dynamic arrays, and (3) incomplete enum types. (See the GCC
493 manual for more information on these GNU extensions to ANSI C.) When
494 used, these GNU C extensions are represented (in the generated DWARF
495 output of GCC) in the most natural and intuitively obvious ways.
497 In the case of inline functions, the DWARF representation is exactly as
498 called for in the DWARF version 2 (draft) specification for an identical
499 function written in C++; i.e. we "reuse" the representation of inline
500 functions which has been defined for C++ to support this GNU C extension.
502 In the case of dynamic arrays, we use the most obvious representational
503 mechanism available; i.e. an array type in which the upper bound of
504 some dimension (usually the first and only dimension) is a variable
505 rather than a constant. (See the DWARF version 1 specification for more
506 details.)
508 In the case of incomplete enum types, such types are represented simply
509 as TAG_enumeration_type DIEs which DO NOT contain either AT_byte_size
510 attributes or AT_element_list attributes.
512 --------------------------------
515 Future Directions
516 -----------------
518 The codes, formats, and other paraphernalia necessary to provide proper
519 support for symbolic debugging for the C++ language are still being worked
520 on by the UI/PLSIG. The vast majority of the additions to DWARF which will
521 be needed to completely support C++ have already been hashed out and agreed
522 upon, but a few small issues (e.g. anonymous unions, access declarations)
523 are still being discussed. Also, we in the PLSIG are still discussing
524 whether or not we need to do anything special for C++ templates. (At this
525 time it is not yet clear whether we even need to do anything special for
526 these.)
528 With regard to FORTRAN, the UI/PLSIG has defined what is believed to be a
529 complete and sufficient set of codes and rules for adequately representing
530 all of FORTRAN 77, and most of Fortran 90 in DWARF. While some support for
531 this has been implemented in dwarfout.c, further implementation and testing
532 is needed.
534 GNU DWARF support for other languages (i.e. Pascal and Modula) is a moot
535 issue until there are GNU front-ends for these other languages.
537 As currently defined, DWARF only describes a (binary) language which can
538 be used to communicate symbolic debugging information from a compiler
539 through an assembler and a linker, to a debugger. There is no clear
540 specification of what processing should be (or must be) done by the
541 assembler and/or the linker. Fortunately, the role of the assembler
542 is easily inferred (by anyone knowledgeable about assemblers) just by
543 looking at examples of assembly-level DWARF code. Sadly though, the
544 allowable (or required) processing steps performed by a linker are
545 harder to infer and (perhaps) even harder to agree upon. There are
546 several forms of very useful `post-processing' steps which intelligent
547 linkers *could* (in theory) perform on object files containing DWARF,
548 but any and all such link-time transformations are currently both disallowed
549 and unspecified.
551 In particular, possible link-time transformations of DWARF code which could
552 provide significant benefits include (but are not limited to):
554 Commonization of duplicate DIEs obtained from multiple input
555 (object) files.
557 Cross-compilation type checking based upon DWARF type information
558 for objects and functions.
560 Other possible `compacting' transformations designed to save disk
561 space and to reduce linker & debugger I/O activity.
565 #include "config.h"
567 #ifdef DWARF_DEBUGGING_INFO
568 #include "system.h"
569 #include "dwarf.h"
570 #include "tree.h"
571 #include "flags.h"
572 #include "rtl.h"
573 #include "hard-reg-set.h"
574 #include "insn-config.h"
575 #include "reload.h"
576 #include "output.h"
577 #include "toplev.h"
578 #include "tm_p.h"
579 #include "debug.h"
581 /* NOTE: In the comments in this file, many references are made to
582 so called "Debugging Information Entries". For the sake of brevity,
583 this term is abbreviated to `DIE' throughout the remainder of this
584 file. */
586 /* Note that the implementation of C++ support herein is (as yet) unfinished.
587 If you want to try to complete it, more power to you. */
589 /* How to start an assembler comment. */
590 #ifndef ASM_COMMENT_START
591 #define ASM_COMMENT_START ";#"
592 #endif
594 /* How to print out a register name. */
595 #ifndef PRINT_REG
596 #define PRINT_REG(RTX, CODE, FILE) \
597 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
598 #endif
600 /* Define a macro which returns non-zero for any tagged type which is
601 used (directly or indirectly) in the specification of either some
602 function's return type or some formal parameter of some function.
603 We use this macro when we are operating in "terse" mode to help us
604 know what tagged types have to be represented in Dwarf (even in
605 terse mode) and which ones don't.
607 A flag bit with this meaning really should be a part of the normal
608 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
609 for these nodes. For now, we have to just fake it. It it safe for
610 us to simply return zero for all complete tagged types (which will
611 get forced out anyway if they were used in the specification of some
612 formal or return type) and non-zero for all incomplete tagged types.
615 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
617 /* Define a macro which returns non-zero for a TYPE_DECL which was
618 implicitly generated for a tagged type.
620 Note that unlike the gcc front end (which generates a NULL named
621 TYPE_DECL node for each complete tagged type, each array type, and
622 each function type node created) the g++ front end generates a
623 _named_ TYPE_DECL node for each tagged type node created.
624 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
625 generate a DW_TAG_typedef DIE for them. */
626 #define TYPE_DECL_IS_STUB(decl) \
627 (DECL_NAME (decl) == NULL \
628 || (DECL_ARTIFICIAL (decl) \
629 && is_tagged_type (TREE_TYPE (decl)) \
630 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
632 extern int flag_traditional;
634 /* Maximum size (in bytes) of an artificially generated label. */
636 #define MAX_ARTIFICIAL_LABEL_BYTES 30
638 /* Structure to keep track of source filenames. */
640 struct filename_entry {
641 unsigned number;
642 const char * name;
645 typedef struct filename_entry filename_entry;
647 /* Pointer to an array of elements, each one having the structure above. */
649 static filename_entry *filename_table;
651 /* Total number of entries in the table (i.e. array) pointed to by
652 `filename_table'. This is the *total* and includes both used and
653 unused slots. */
655 static unsigned ft_entries_allocated;
657 /* Number of entries in the filename_table which are actually in use. */
659 static unsigned ft_entries;
661 /* Size (in elements) of increments by which we may expand the filename
662 table. Actually, a single hunk of space of this size should be enough
663 for most typical programs. */
665 #define FT_ENTRIES_INCREMENT 64
667 /* Local pointer to the name of the main input file. Initialized in
668 dwarfout_init. */
670 static const char *primary_filename;
672 /* Pointer to the most recent filename for which we produced some line info. */
674 static const char *last_filename;
676 /* Counter to generate unique names for DIEs. */
678 static unsigned next_unused_dienum = 1;
680 /* Number of the DIE which is currently being generated. */
682 static unsigned current_dienum;
684 /* Number to use for the special "pubname" label on the next DIE which
685 represents a function or data object defined in this compilation
686 unit which has "extern" linkage. */
688 static int next_pubname_number = 0;
690 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
692 /* Pointer to a dynamically allocated list of pre-reserved and still
693 pending sibling DIE numbers. Note that this list will grow as needed. */
695 static unsigned *pending_sibling_stack;
697 /* Counter to keep track of the number of pre-reserved and still pending
698 sibling DIE numbers. */
700 static unsigned pending_siblings;
702 /* The currently allocated size of the above list (expressed in number of
703 list elements). */
705 static unsigned pending_siblings_allocated;
707 /* Size (in elements) of increments by which we may expand the pending
708 sibling stack. Actually, a single hunk of space of this size should
709 be enough for most typical programs. */
711 #define PENDING_SIBLINGS_INCREMENT 64
713 /* Non-zero if we are performing our file-scope finalization pass and if
714 we should force out Dwarf descriptions of any and all file-scope
715 tagged types which are still incomplete types. */
717 static int finalizing = 0;
719 /* A pointer to the base of a list of pending types which we haven't
720 generated DIEs for yet, but which we will have to come back to
721 later on. */
723 static tree *pending_types_list;
725 /* Number of elements currently allocated for the pending_types_list. */
727 static unsigned pending_types_allocated;
729 /* Number of elements of pending_types_list currently in use. */
731 static unsigned pending_types;
733 /* Size (in elements) of increments by which we may expand the pending
734 types list. Actually, a single hunk of space of this size should
735 be enough for most typical programs. */
737 #define PENDING_TYPES_INCREMENT 64
739 /* A pointer to the base of a list of incomplete types which might be
740 completed at some later time. */
742 static tree *incomplete_types_list;
744 /* Number of elements currently allocated for the incomplete_types_list. */
745 static unsigned incomplete_types_allocated;
747 /* Number of elements of incomplete_types_list currently in use. */
748 static unsigned incomplete_types;
750 /* Size (in elements) of increments by which we may expand the incomplete
751 types list. Actually, a single hunk of space of this size should
752 be enough for most typical programs. */
753 #define INCOMPLETE_TYPES_INCREMENT 64
755 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
756 This is used in a hack to help us get the DIEs describing types of
757 formal parameters to come *after* all of the DIEs describing the formal
758 parameters themselves. That's necessary in order to be compatible
759 with what the brain-damaged svr4 SDB debugger requires. */
761 static tree fake_containing_scope;
763 /* The number of the current function definition that we are generating
764 debugging information for. These numbers range from 1 up to the maximum
765 number of function definitions contained within the current compilation
766 unit. These numbers are used to create unique labels for various things
767 contained within various function definitions. */
769 static unsigned current_funcdef_number = 1;
771 /* A pointer to the ..._DECL node which we have most recently been working
772 on. We keep this around just in case something about it looks screwy
773 and we want to tell the user what the source coordinates for the actual
774 declaration are. */
776 static tree dwarf_last_decl;
778 /* A flag indicating that we are emitting the member declarations of a
779 class, so member functions and variables should not be entirely emitted.
780 This is a kludge to avoid passing a second argument to output_*_die. */
782 static int in_class;
784 /* Forward declarations for functions defined in this file. */
786 static void dwarfout_init PARAMS ((const char *));
787 static void dwarfout_finish PARAMS ((const char *));
788 static void dwarfout_define PARAMS ((unsigned int, const char *));
789 static void dwarfout_undef PARAMS ((unsigned int, const char *));
790 static void dwarfout_start_source_file PARAMS ((unsigned, const char *));
791 static void dwarfout_start_source_file_check PARAMS ((unsigned, const char *));
792 static void dwarfout_end_source_file PARAMS ((unsigned));
793 static void dwarfout_end_source_file_check PARAMS ((unsigned));
794 static void dwarfout_begin_block PARAMS ((unsigned, unsigned));
795 static void dwarfout_end_block PARAMS ((unsigned, unsigned));
796 static void dwarfout_end_epilogue PARAMS ((void));
797 static void dwarfout_source_line PARAMS ((unsigned int, const char *));
798 static void dwarfout_end_prologue PARAMS ((unsigned int));
799 static void dwarfout_end_function PARAMS ((unsigned int));
800 static void dwarfout_function_decl PARAMS ((tree));
801 static void dwarfout_global_decl PARAMS ((tree));
802 static void dwarfout_deferred_inline_function PARAMS ((tree));
803 static void dwarfout_file_scope_decl PARAMS ((tree , int));
804 static const char *dwarf_tag_name PARAMS ((unsigned));
805 static const char *dwarf_attr_name PARAMS ((unsigned));
806 static const char *dwarf_stack_op_name PARAMS ((unsigned));
807 static const char *dwarf_typemod_name PARAMS ((unsigned));
808 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
809 static const char *dwarf_fund_type_name PARAMS ((unsigned));
810 static tree decl_ultimate_origin PARAMS ((tree));
811 static tree block_ultimate_origin PARAMS ((tree));
812 static tree decl_class_context PARAMS ((tree));
813 #if 0
814 static void output_unsigned_leb128 PARAMS ((unsigned long));
815 static void output_signed_leb128 PARAMS ((long));
816 #endif
817 static int fundamental_type_code PARAMS ((tree));
818 static tree root_type_1 PARAMS ((tree, int));
819 static tree root_type PARAMS ((tree));
820 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
821 static void write_modifier_bytes PARAMS ((tree, int, int));
822 static inline int type_is_fundamental PARAMS ((tree));
823 static void equate_decl_number_to_die_number PARAMS ((tree));
824 static inline void equate_type_number_to_die_number PARAMS ((tree));
825 static void output_reg_number PARAMS ((rtx));
826 static void output_mem_loc_descriptor PARAMS ((rtx));
827 static void output_loc_descriptor PARAMS ((rtx));
828 static void output_bound_representation PARAMS ((tree, unsigned, int));
829 static void output_enumeral_list PARAMS ((tree));
830 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
831 static inline tree field_type PARAMS ((tree));
832 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
833 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
834 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
835 static inline void sibling_attribute PARAMS ((void));
836 static void location_attribute PARAMS ((rtx));
837 static void data_member_location_attribute PARAMS ((tree));
838 static void const_value_attribute PARAMS ((rtx));
839 static void location_or_const_value_attribute PARAMS ((tree));
840 static inline void name_attribute PARAMS ((const char *));
841 static inline void fund_type_attribute PARAMS ((unsigned));
842 static void mod_fund_type_attribute PARAMS ((tree, int, int));
843 static inline void user_def_type_attribute PARAMS ((tree));
844 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
845 #ifdef USE_ORDERING_ATTRIBUTE
846 static inline void ordering_attribute PARAMS ((unsigned));
847 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
848 static void subscript_data_attribute PARAMS ((tree));
849 static void byte_size_attribute PARAMS ((tree));
850 static inline void bit_offset_attribute PARAMS ((tree));
851 static inline void bit_size_attribute PARAMS ((tree));
852 static inline void element_list_attribute PARAMS ((tree));
853 static inline void stmt_list_attribute PARAMS ((const char *));
854 static inline void low_pc_attribute PARAMS ((const char *));
855 static inline void high_pc_attribute PARAMS ((const char *));
856 static inline void body_begin_attribute PARAMS ((const char *));
857 static inline void body_end_attribute PARAMS ((const char *));
858 static inline void language_attribute PARAMS ((unsigned));
859 static inline void member_attribute PARAMS ((tree));
860 #if 0
861 static inline void string_length_attribute PARAMS ((tree));
862 #endif
863 static inline void comp_dir_attribute PARAMS ((const char *));
864 static inline void sf_names_attribute PARAMS ((const char *));
865 static inline void src_info_attribute PARAMS ((const char *));
866 static inline void mac_info_attribute PARAMS ((const char *));
867 static inline void prototyped_attribute PARAMS ((tree));
868 static inline void producer_attribute PARAMS ((const char *));
869 static inline void inline_attribute PARAMS ((tree));
870 static inline void containing_type_attribute PARAMS ((tree));
871 static inline void abstract_origin_attribute PARAMS ((tree));
872 #ifdef DWARF_DECL_COORDINATES
873 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
874 #endif /* defined(DWARF_DECL_COORDINATES) */
875 static inline void pure_or_virtual_attribute PARAMS ((tree));
876 static void name_and_src_coords_attributes PARAMS ((tree));
877 static void type_attribute PARAMS ((tree, int, int));
878 static const char *type_tag PARAMS ((tree));
879 static inline void dienum_push PARAMS ((void));
880 static inline void dienum_pop PARAMS ((void));
881 static inline tree member_declared_type PARAMS ((tree));
882 static const char *function_start_label PARAMS ((tree));
883 static void output_array_type_die PARAMS ((void *));
884 static void output_set_type_die PARAMS ((void *));
885 #if 0
886 static void output_entry_point_die PARAMS ((void *));
887 #endif
888 static void output_inlined_enumeration_type_die PARAMS ((void *));
889 static void output_inlined_structure_type_die PARAMS ((void *));
890 static void output_inlined_union_type_die PARAMS ((void *));
891 static void output_enumeration_type_die PARAMS ((void *));
892 static void output_formal_parameter_die PARAMS ((void *));
893 static void output_global_subroutine_die PARAMS ((void *));
894 static void output_global_variable_die PARAMS ((void *));
895 static void output_label_die PARAMS ((void *));
896 static void output_lexical_block_die PARAMS ((void *));
897 static void output_inlined_subroutine_die PARAMS ((void *));
898 static void output_local_variable_die PARAMS ((void *));
899 static void output_member_die PARAMS ((void *));
900 #if 0
901 static void output_pointer_type_die PARAMS ((void *));
902 static void output_reference_type_die PARAMS ((void *));
903 #endif
904 static void output_ptr_to_mbr_type_die PARAMS ((void *));
905 static void output_compile_unit_die PARAMS ((void *));
906 static void output_string_type_die PARAMS ((void *));
907 static void output_inheritance_die PARAMS ((void *));
908 static void output_structure_type_die PARAMS ((void *));
909 static void output_local_subroutine_die PARAMS ((void *));
910 static void output_subroutine_type_die PARAMS ((void *));
911 static void output_typedef_die PARAMS ((void *));
912 static void output_union_type_die PARAMS ((void *));
913 static void output_unspecified_parameters_die PARAMS ((void *));
914 static void output_padded_null_die PARAMS ((void *));
915 static void output_die PARAMS ((void (*)(void *), void *));
916 static void end_sibling_chain PARAMS ((void));
917 static void output_formal_types PARAMS ((tree));
918 static void pend_type PARAMS ((tree));
919 static int type_ok_for_scope PARAMS ((tree, tree));
920 static void output_pending_types_for_scope PARAMS ((tree));
921 static void output_type PARAMS ((tree, tree));
922 static void output_tagged_type_instantiation PARAMS ((tree));
923 static void output_block PARAMS ((tree, int));
924 static void output_decls_for_scope PARAMS ((tree, int));
925 static void output_decl PARAMS ((tree, tree));
926 static void shuffle_filename_entry PARAMS ((filename_entry *));
927 static void generate_new_sfname_entry PARAMS ((void));
928 static unsigned lookup_filename PARAMS ((const char *));
929 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
930 static void generate_macinfo_entry PARAMS ((const char *, const char *));
931 static int is_pseudo_reg PARAMS ((rtx));
932 static tree type_main_variant PARAMS ((tree));
933 static int is_tagged_type PARAMS ((tree));
934 static int is_redundant_typedef PARAMS ((tree));
935 static void add_incomplete_type PARAMS ((tree));
936 static void retry_incomplete_types PARAMS ((void));
938 /* Definitions of defaults for assembler-dependent names of various
939 pseudo-ops and section names.
941 Theses may be overridden in your tm.h file (if necessary) for your
942 particular assembler. The default values provided here correspond to
943 what is expected by "standard" AT&T System V.4 assemblers. */
945 #ifndef FILE_ASM_OP
946 #define FILE_ASM_OP "\t.file\t"
947 #endif
948 #ifndef VERSION_ASM_OP
949 #define VERSION_ASM_OP "\t.version\t"
950 #endif
951 #ifndef SET_ASM_OP
952 #define SET_ASM_OP "\t.set\t"
953 #endif
955 /* Pseudo-ops for pushing the current section onto the section stack (and
956 simultaneously changing to a new section) and for poping back to the
957 section we were in immediately before this one. Note that most svr4
958 assemblers only maintain a one level stack... you can push all the
959 sections you want, but you can only pop out one level. (The sparc
960 svr4 assembler is an exception to this general rule.) That's
961 OK because we only use at most one level of the section stack herein. */
963 #ifndef PUSHSECTION_ASM_OP
964 #define PUSHSECTION_ASM_OP "\t.section\t"
965 #endif
966 #ifndef POPSECTION_ASM_OP
967 #define POPSECTION_ASM_OP "\t.previous"
968 #endif
970 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
971 to print the PUSHSECTION_ASM_OP and the section name. The default here
972 works for almost all svr4 assemblers, except for the sparc, where the
973 section name must be enclosed in double quotes. (See sparcv4.h.) */
975 #ifndef PUSHSECTION_FORMAT
976 #define PUSHSECTION_FORMAT "%s%s\n"
977 #endif
979 #ifndef DEBUG_SECTION
980 #define DEBUG_SECTION ".debug"
981 #endif
982 #ifndef LINE_SECTION
983 #define LINE_SECTION ".line"
984 #endif
985 #ifndef DEBUG_SFNAMES_SECTION
986 #define DEBUG_SFNAMES_SECTION ".debug_sfnames"
987 #endif
988 #ifndef DEBUG_SRCINFO_SECTION
989 #define DEBUG_SRCINFO_SECTION ".debug_srcinfo"
990 #endif
991 #ifndef DEBUG_MACINFO_SECTION
992 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
993 #endif
994 #ifndef DEBUG_PUBNAMES_SECTION
995 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
996 #endif
997 #ifndef DEBUG_ARANGES_SECTION
998 #define DEBUG_ARANGES_SECTION ".debug_aranges"
999 #endif
1000 #ifndef TEXT_SECTION_NAME
1001 #define TEXT_SECTION_NAME ".text"
1002 #endif
1003 #ifndef DATA_SECTION_NAME
1004 #define DATA_SECTION_NAME ".data"
1005 #endif
1006 #ifndef DATA1_SECTION_NAME
1007 #define DATA1_SECTION_NAME ".data1"
1008 #endif
1009 #ifndef RODATA_SECTION_NAME
1010 #define RODATA_SECTION_NAME ".rodata"
1011 #endif
1012 #ifndef RODATA1_SECTION_NAME
1013 #define RODATA1_SECTION_NAME ".rodata1"
1014 #endif
1015 #ifndef BSS_SECTION_NAME
1016 #define BSS_SECTION_NAME ".bss"
1017 #endif
1019 /* Definitions of defaults for formats and names of various special
1020 (artificial) labels which may be generated within this file (when
1021 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
1023 If necessary, these may be overridden from within your tm.h file,
1024 but typically, you should never need to override these.
1026 These labels have been hacked (temporarily) so that they all begin with
1027 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
1028 stock m88k/svr4 assembler, both of which need to see .L at the start of
1029 a label in order to prevent that label from going into the linker symbol
1030 table). When I get time, I'll have to fix this the right way so that we
1031 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
1032 but that will require a rather massive set of changes. For the moment,
1033 the following definitions out to produce the right results for all svr4
1034 and svr3 assemblers. -- rfg
1037 #ifndef TEXT_BEGIN_LABEL
1038 #define TEXT_BEGIN_LABEL "*.L_text_b"
1039 #endif
1040 #ifndef TEXT_END_LABEL
1041 #define TEXT_END_LABEL "*.L_text_e"
1042 #endif
1044 #ifndef DATA_BEGIN_LABEL
1045 #define DATA_BEGIN_LABEL "*.L_data_b"
1046 #endif
1047 #ifndef DATA_END_LABEL
1048 #define DATA_END_LABEL "*.L_data_e"
1049 #endif
1051 #ifndef DATA1_BEGIN_LABEL
1052 #define DATA1_BEGIN_LABEL "*.L_data1_b"
1053 #endif
1054 #ifndef DATA1_END_LABEL
1055 #define DATA1_END_LABEL "*.L_data1_e"
1056 #endif
1058 #ifndef RODATA_BEGIN_LABEL
1059 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
1060 #endif
1061 #ifndef RODATA_END_LABEL
1062 #define RODATA_END_LABEL "*.L_rodata_e"
1063 #endif
1065 #ifndef RODATA1_BEGIN_LABEL
1066 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
1067 #endif
1068 #ifndef RODATA1_END_LABEL
1069 #define RODATA1_END_LABEL "*.L_rodata1_e"
1070 #endif
1072 #ifndef BSS_BEGIN_LABEL
1073 #define BSS_BEGIN_LABEL "*.L_bss_b"
1074 #endif
1075 #ifndef BSS_END_LABEL
1076 #define BSS_END_LABEL "*.L_bss_e"
1077 #endif
1079 #ifndef LINE_BEGIN_LABEL
1080 #define LINE_BEGIN_LABEL "*.L_line_b"
1081 #endif
1082 #ifndef LINE_LAST_ENTRY_LABEL
1083 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
1084 #endif
1085 #ifndef LINE_END_LABEL
1086 #define LINE_END_LABEL "*.L_line_e"
1087 #endif
1089 #ifndef DEBUG_BEGIN_LABEL
1090 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
1091 #endif
1092 #ifndef SFNAMES_BEGIN_LABEL
1093 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
1094 #endif
1095 #ifndef SRCINFO_BEGIN_LABEL
1096 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
1097 #endif
1098 #ifndef MACINFO_BEGIN_LABEL
1099 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
1100 #endif
1102 #ifndef DEBUG_ARANGES_BEGIN_LABEL
1103 #define DEBUG_ARANGES_BEGIN_LABEL "*.L_debug_aranges_begin"
1104 #endif
1105 #ifndef DEBUG_ARANGES_END_LABEL
1106 #define DEBUG_ARANGES_END_LABEL "*.L_debug_aranges_end"
1107 #endif
1109 #ifndef DIE_BEGIN_LABEL_FMT
1110 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
1111 #endif
1112 #ifndef DIE_END_LABEL_FMT
1113 #define DIE_END_LABEL_FMT "*.L_D%u_e"
1114 #endif
1115 #ifndef PUB_DIE_LABEL_FMT
1116 #define PUB_DIE_LABEL_FMT "*.L_P%u"
1117 #endif
1118 #ifndef BLOCK_BEGIN_LABEL_FMT
1119 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
1120 #endif
1121 #ifndef BLOCK_END_LABEL_FMT
1122 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
1123 #endif
1124 #ifndef SS_BEGIN_LABEL_FMT
1125 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
1126 #endif
1127 #ifndef SS_END_LABEL_FMT
1128 #define SS_END_LABEL_FMT "*.L_s%u_e"
1129 #endif
1130 #ifndef EE_BEGIN_LABEL_FMT
1131 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
1132 #endif
1133 #ifndef EE_END_LABEL_FMT
1134 #define EE_END_LABEL_FMT "*.L_e%u_e"
1135 #endif
1136 #ifndef MT_BEGIN_LABEL_FMT
1137 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
1138 #endif
1139 #ifndef MT_END_LABEL_FMT
1140 #define MT_END_LABEL_FMT "*.L_t%u_e"
1141 #endif
1142 #ifndef LOC_BEGIN_LABEL_FMT
1143 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
1144 #endif
1145 #ifndef LOC_END_LABEL_FMT
1146 #define LOC_END_LABEL_FMT "*.L_l%u_e"
1147 #endif
1148 #ifndef BOUND_BEGIN_LABEL_FMT
1149 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
1150 #endif
1151 #ifndef BOUND_END_LABEL_FMT
1152 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
1153 #endif
1154 #ifndef DERIV_BEGIN_LABEL_FMT
1155 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
1156 #endif
1157 #ifndef DERIV_END_LABEL_FMT
1158 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
1159 #endif
1160 #ifndef SL_BEGIN_LABEL_FMT
1161 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
1162 #endif
1163 #ifndef SL_END_LABEL_FMT
1164 #define SL_END_LABEL_FMT "*.L_sl%u_e"
1165 #endif
1166 #ifndef BODY_BEGIN_LABEL_FMT
1167 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
1168 #endif
1169 #ifndef BODY_END_LABEL_FMT
1170 #define BODY_END_LABEL_FMT "*.L_b%u_e"
1171 #endif
1172 #ifndef FUNC_END_LABEL_FMT
1173 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
1174 #endif
1175 #ifndef TYPE_NAME_FMT
1176 #define TYPE_NAME_FMT "*.L_T%u"
1177 #endif
1178 #ifndef DECL_NAME_FMT
1179 #define DECL_NAME_FMT "*.L_E%u"
1180 #endif
1181 #ifndef LINE_CODE_LABEL_FMT
1182 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
1183 #endif
1184 #ifndef SFNAMES_ENTRY_LABEL_FMT
1185 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
1186 #endif
1187 #ifndef LINE_ENTRY_LABEL_FMT
1188 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
1189 #endif
1191 /* Definitions of defaults for various types of primitive assembly language
1192 output operations.
1194 If necessary, these may be overridden from within your tm.h file,
1195 but typically, you shouldn't need to override these. */
1197 #ifndef ASM_OUTPUT_PUSH_SECTION
1198 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
1199 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
1200 #endif
1202 #ifndef ASM_OUTPUT_POP_SECTION
1203 #define ASM_OUTPUT_POP_SECTION(FILE) \
1204 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
1205 #endif
1207 #ifndef ASM_OUTPUT_DWARF_DELTA2
1208 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
1209 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
1210 assemble_name (FILE, LABEL1); \
1211 fprintf (FILE, "-"); \
1212 assemble_name (FILE, LABEL2); \
1213 fprintf (FILE, "\n"); \
1214 } while (0)
1215 #endif
1217 #ifndef ASM_OUTPUT_DWARF_DELTA4
1218 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
1219 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1220 assemble_name (FILE, LABEL1); \
1221 fprintf (FILE, "-"); \
1222 assemble_name (FILE, LABEL2); \
1223 fprintf (FILE, "\n"); \
1224 } while (0)
1225 #endif
1227 #ifndef ASM_OUTPUT_DWARF_TAG
1228 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
1229 do { \
1230 fprintf ((FILE), "%s0x%x", \
1231 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
1232 if (flag_debug_asm) \
1233 fprintf ((FILE), "\t%s %s", \
1234 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
1235 fputc ('\n', (FILE)); \
1236 } while (0)
1237 #endif
1239 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
1240 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
1241 do { \
1242 fprintf ((FILE), "%s0x%x", \
1243 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
1244 if (flag_debug_asm) \
1245 fprintf ((FILE), "\t%s %s", \
1246 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
1247 fputc ('\n', (FILE)); \
1248 } while (0)
1249 #endif
1251 #ifndef ASM_OUTPUT_DWARF_STACK_OP
1252 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
1253 do { \
1254 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) OP); \
1255 if (flag_debug_asm) \
1256 fprintf ((FILE), "\t%s %s", \
1257 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
1258 fputc ('\n', (FILE)); \
1259 } while (0)
1260 #endif
1262 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
1263 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
1264 do { \
1265 fprintf ((FILE), "%s0x%x", \
1266 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
1267 if (flag_debug_asm) \
1268 fprintf ((FILE), "\t%s %s", \
1269 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
1270 fputc ('\n', (FILE)); \
1271 } while (0)
1272 #endif
1274 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
1275 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
1276 do { \
1277 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) FMT); \
1278 if (flag_debug_asm) \
1279 fprintf ((FILE), "\t%s %s", \
1280 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
1281 fputc ('\n', (FILE)); \
1282 } while (0)
1283 #endif
1285 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
1286 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
1287 do { \
1288 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) MOD); \
1289 if (flag_debug_asm) \
1290 fprintf ((FILE), "\t%s %s", \
1291 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
1292 fputc ('\n', (FILE)); \
1293 } while (0)
1294 #endif
1296 #ifndef ASM_OUTPUT_DWARF_ADDR
1297 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
1298 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1299 assemble_name (FILE, LABEL); \
1300 fprintf (FILE, "\n"); \
1301 } while (0)
1302 #endif
1304 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
1305 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
1306 do { \
1307 fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1308 output_addr_const ((FILE), (RTX)); \
1309 fputc ('\n', (FILE)); \
1310 } while (0)
1311 #endif
1313 #ifndef ASM_OUTPUT_DWARF_REF
1314 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
1315 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
1316 assemble_name (FILE, LABEL); \
1317 fprintf (FILE, "\n"); \
1318 } while (0)
1319 #endif
1321 #ifndef ASM_OUTPUT_DWARF_DATA1
1322 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
1323 fprintf ((FILE), "%s0x%x\n", ASM_BYTE_OP, VALUE)
1324 #endif
1326 #ifndef ASM_OUTPUT_DWARF_DATA2
1327 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
1328 fprintf ((FILE), "%s0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
1329 #endif
1331 #ifndef ASM_OUTPUT_DWARF_DATA4
1332 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
1333 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
1334 #endif
1336 #ifndef ASM_OUTPUT_DWARF_DATA8
1337 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
1338 do { \
1339 if (WORDS_BIG_ENDIAN) \
1341 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1342 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1344 else \
1346 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
1347 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
1349 } while (0)
1350 #endif
1352 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
1353 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
1354 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
1355 defined, we call it, then issue the line feed. If not, we supply a
1356 default defintion of calling ASM_OUTPUT_ASCII */
1358 #ifndef ASM_OUTPUT_DWARF_STRING
1359 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1360 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
1361 #else
1362 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1363 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
1364 #endif
1367 /* The debug hooks structure. */
1368 struct gcc_debug_hooks dwarf_debug_hooks =
1370 dwarfout_init,
1371 dwarfout_finish,
1372 dwarfout_define,
1373 dwarfout_undef,
1374 dwarfout_start_source_file_check,
1375 dwarfout_end_source_file_check,
1376 dwarfout_begin_block,
1377 dwarfout_end_block,
1378 debug_true_tree, /* ignore_block */
1379 dwarfout_source_line, /* source_line */
1380 dwarfout_source_line, /* begin_prologue */
1381 dwarfout_end_prologue,
1382 dwarfout_end_epilogue,
1383 debug_nothing_tree, /* begin_function */
1384 dwarfout_end_function,
1385 dwarfout_function_decl,
1386 dwarfout_global_decl,
1387 dwarfout_deferred_inline_function,
1388 debug_nothing_tree, /* outlining_inline_function */
1389 debug_nothing_rtx /* label */
1392 /************************ general utility functions **************************/
1394 static inline int
1395 is_pseudo_reg (rtl)
1396 rtx rtl;
1398 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1399 || ((GET_CODE (rtl) == SUBREG)
1400 && (REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)));
1403 static inline tree
1404 type_main_variant (type)
1405 tree type;
1407 type = TYPE_MAIN_VARIANT (type);
1409 /* There really should be only one main variant among any group of variants
1410 of a given type (and all of the MAIN_VARIANT values for all members of
1411 the group should point to that one type) but sometimes the C front-end
1412 messes this up for array types, so we work around that bug here. */
1414 if (TREE_CODE (type) == ARRAY_TYPE)
1416 while (type != TYPE_MAIN_VARIANT (type))
1417 type = TYPE_MAIN_VARIANT (type);
1420 return type;
1423 /* Return non-zero if the given type node represents a tagged type. */
1425 static inline int
1426 is_tagged_type (type)
1427 tree type;
1429 enum tree_code code = TREE_CODE (type);
1431 return (code == RECORD_TYPE || code == UNION_TYPE
1432 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1435 static const char *
1436 dwarf_tag_name (tag)
1437 unsigned tag;
1439 switch (tag)
1441 case TAG_padding: return "TAG_padding";
1442 case TAG_array_type: return "TAG_array_type";
1443 case TAG_class_type: return "TAG_class_type";
1444 case TAG_entry_point: return "TAG_entry_point";
1445 case TAG_enumeration_type: return "TAG_enumeration_type";
1446 case TAG_formal_parameter: return "TAG_formal_parameter";
1447 case TAG_global_subroutine: return "TAG_global_subroutine";
1448 case TAG_global_variable: return "TAG_global_variable";
1449 case TAG_label: return "TAG_label";
1450 case TAG_lexical_block: return "TAG_lexical_block";
1451 case TAG_local_variable: return "TAG_local_variable";
1452 case TAG_member: return "TAG_member";
1453 case TAG_pointer_type: return "TAG_pointer_type";
1454 case TAG_reference_type: return "TAG_reference_type";
1455 case TAG_compile_unit: return "TAG_compile_unit";
1456 case TAG_string_type: return "TAG_string_type";
1457 case TAG_structure_type: return "TAG_structure_type";
1458 case TAG_subroutine: return "TAG_subroutine";
1459 case TAG_subroutine_type: return "TAG_subroutine_type";
1460 case TAG_typedef: return "TAG_typedef";
1461 case TAG_union_type: return "TAG_union_type";
1462 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
1463 case TAG_variant: return "TAG_variant";
1464 case TAG_common_block: return "TAG_common_block";
1465 case TAG_common_inclusion: return "TAG_common_inclusion";
1466 case TAG_inheritance: return "TAG_inheritance";
1467 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
1468 case TAG_module: return "TAG_module";
1469 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
1470 case TAG_set_type: return "TAG_set_type";
1471 case TAG_subrange_type: return "TAG_subrange_type";
1472 case TAG_with_stmt: return "TAG_with_stmt";
1474 /* GNU extensions. */
1476 case TAG_format_label: return "TAG_format_label";
1477 case TAG_namelist: return "TAG_namelist";
1478 case TAG_function_template: return "TAG_function_template";
1479 case TAG_class_template: return "TAG_class_template";
1481 default: return "TAG_<unknown>";
1485 static const char *
1486 dwarf_attr_name (attr)
1487 unsigned attr;
1489 switch (attr)
1491 case AT_sibling: return "AT_sibling";
1492 case AT_location: return "AT_location";
1493 case AT_name: return "AT_name";
1494 case AT_fund_type: return "AT_fund_type";
1495 case AT_mod_fund_type: return "AT_mod_fund_type";
1496 case AT_user_def_type: return "AT_user_def_type";
1497 case AT_mod_u_d_type: return "AT_mod_u_d_type";
1498 case AT_ordering: return "AT_ordering";
1499 case AT_subscr_data: return "AT_subscr_data";
1500 case AT_byte_size: return "AT_byte_size";
1501 case AT_bit_offset: return "AT_bit_offset";
1502 case AT_bit_size: return "AT_bit_size";
1503 case AT_element_list: return "AT_element_list";
1504 case AT_stmt_list: return "AT_stmt_list";
1505 case AT_low_pc: return "AT_low_pc";
1506 case AT_high_pc: return "AT_high_pc";
1507 case AT_language: return "AT_language";
1508 case AT_member: return "AT_member";
1509 case AT_discr: return "AT_discr";
1510 case AT_discr_value: return "AT_discr_value";
1511 case AT_string_length: return "AT_string_length";
1512 case AT_common_reference: return "AT_common_reference";
1513 case AT_comp_dir: return "AT_comp_dir";
1514 case AT_const_value_string: return "AT_const_value_string";
1515 case AT_const_value_data2: return "AT_const_value_data2";
1516 case AT_const_value_data4: return "AT_const_value_data4";
1517 case AT_const_value_data8: return "AT_const_value_data8";
1518 case AT_const_value_block2: return "AT_const_value_block2";
1519 case AT_const_value_block4: return "AT_const_value_block4";
1520 case AT_containing_type: return "AT_containing_type";
1521 case AT_default_value_addr: return "AT_default_value_addr";
1522 case AT_default_value_data2: return "AT_default_value_data2";
1523 case AT_default_value_data4: return "AT_default_value_data4";
1524 case AT_default_value_data8: return "AT_default_value_data8";
1525 case AT_default_value_string: return "AT_default_value_string";
1526 case AT_friends: return "AT_friends";
1527 case AT_inline: return "AT_inline";
1528 case AT_is_optional: return "AT_is_optional";
1529 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1530 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1531 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1532 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1533 case AT_private: return "AT_private";
1534 case AT_producer: return "AT_producer";
1535 case AT_program: return "AT_program";
1536 case AT_protected: return "AT_protected";
1537 case AT_prototyped: return "AT_prototyped";
1538 case AT_public: return "AT_public";
1539 case AT_pure_virtual: return "AT_pure_virtual";
1540 case AT_return_addr: return "AT_return_addr";
1541 case AT_abstract_origin: return "AT_abstract_origin";
1542 case AT_start_scope: return "AT_start_scope";
1543 case AT_stride_size: return "AT_stride_size";
1544 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1545 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1546 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1547 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1548 case AT_virtual: return "AT_virtual";
1550 /* GNU extensions */
1552 case AT_sf_names: return "AT_sf_names";
1553 case AT_src_info: return "AT_src_info";
1554 case AT_mac_info: return "AT_mac_info";
1555 case AT_src_coords: return "AT_src_coords";
1556 case AT_body_begin: return "AT_body_begin";
1557 case AT_body_end: return "AT_body_end";
1559 default: return "AT_<unknown>";
1563 static const char *
1564 dwarf_stack_op_name (op)
1565 unsigned op;
1567 switch (op)
1569 case OP_REG: return "OP_REG";
1570 case OP_BASEREG: return "OP_BASEREG";
1571 case OP_ADDR: return "OP_ADDR";
1572 case OP_CONST: return "OP_CONST";
1573 case OP_DEREF2: return "OP_DEREF2";
1574 case OP_DEREF4: return "OP_DEREF4";
1575 case OP_ADD: return "OP_ADD";
1576 default: return "OP_<unknown>";
1580 static const char *
1581 dwarf_typemod_name (mod)
1582 unsigned mod;
1584 switch (mod)
1586 case MOD_pointer_to: return "MOD_pointer_to";
1587 case MOD_reference_to: return "MOD_reference_to";
1588 case MOD_const: return "MOD_const";
1589 case MOD_volatile: return "MOD_volatile";
1590 default: return "MOD_<unknown>";
1594 static const char *
1595 dwarf_fmt_byte_name (fmt)
1596 unsigned fmt;
1598 switch (fmt)
1600 case FMT_FT_C_C: return "FMT_FT_C_C";
1601 case FMT_FT_C_X: return "FMT_FT_C_X";
1602 case FMT_FT_X_C: return "FMT_FT_X_C";
1603 case FMT_FT_X_X: return "FMT_FT_X_X";
1604 case FMT_UT_C_C: return "FMT_UT_C_C";
1605 case FMT_UT_C_X: return "FMT_UT_C_X";
1606 case FMT_UT_X_C: return "FMT_UT_X_C";
1607 case FMT_UT_X_X: return "FMT_UT_X_X";
1608 case FMT_ET: return "FMT_ET";
1609 default: return "FMT_<unknown>";
1613 static const char *
1614 dwarf_fund_type_name (ft)
1615 unsigned ft;
1617 switch (ft)
1619 case FT_char: return "FT_char";
1620 case FT_signed_char: return "FT_signed_char";
1621 case FT_unsigned_char: return "FT_unsigned_char";
1622 case FT_short: return "FT_short";
1623 case FT_signed_short: return "FT_signed_short";
1624 case FT_unsigned_short: return "FT_unsigned_short";
1625 case FT_integer: return "FT_integer";
1626 case FT_signed_integer: return "FT_signed_integer";
1627 case FT_unsigned_integer: return "FT_unsigned_integer";
1628 case FT_long: return "FT_long";
1629 case FT_signed_long: return "FT_signed_long";
1630 case FT_unsigned_long: return "FT_unsigned_long";
1631 case FT_pointer: return "FT_pointer";
1632 case FT_float: return "FT_float";
1633 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1634 case FT_ext_prec_float: return "FT_ext_prec_float";
1635 case FT_complex: return "FT_complex";
1636 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1637 case FT_void: return "FT_void";
1638 case FT_boolean: return "FT_boolean";
1639 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1640 case FT_label: return "FT_label";
1642 /* GNU extensions. */
1644 case FT_long_long: return "FT_long_long";
1645 case FT_signed_long_long: return "FT_signed_long_long";
1646 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1648 case FT_int8: return "FT_int8";
1649 case FT_signed_int8: return "FT_signed_int8";
1650 case FT_unsigned_int8: return "FT_unsigned_int8";
1651 case FT_int16: return "FT_int16";
1652 case FT_signed_int16: return "FT_signed_int16";
1653 case FT_unsigned_int16: return "FT_unsigned_int16";
1654 case FT_int32: return "FT_int32";
1655 case FT_signed_int32: return "FT_signed_int32";
1656 case FT_unsigned_int32: return "FT_unsigned_int32";
1657 case FT_int64: return "FT_int64";
1658 case FT_signed_int64: return "FT_signed_int64";
1659 case FT_unsigned_int64: return "FT_unsigned_int64";
1660 case FT_int128: return "FT_int128";
1661 case FT_signed_int128: return "FT_signed_int128";
1662 case FT_unsigned_int128: return "FT_unsigned_int128";
1664 case FT_real32: return "FT_real32";
1665 case FT_real64: return "FT_real64";
1666 case FT_real96: return "FT_real96";
1667 case FT_real128: return "FT_real128";
1669 default: return "FT_<unknown>";
1673 /* Determine the "ultimate origin" of a decl. The decl may be an
1674 inlined instance of an inlined instance of a decl which is local
1675 to an inline function, so we have to trace all of the way back
1676 through the origin chain to find out what sort of node actually
1677 served as the original seed for the given block. */
1679 static tree
1680 decl_ultimate_origin (decl)
1681 tree decl;
1683 #ifdef ENABLE_CHECKING
1684 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1685 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1686 most distant ancestor, this should never happen. */
1687 abort ();
1688 #endif
1690 return DECL_ABSTRACT_ORIGIN (decl);
1693 /* Determine the "ultimate origin" of a block. The block may be an
1694 inlined instance of an inlined instance of a block which is local
1695 to an inline function, so we have to trace all of the way back
1696 through the origin chain to find out what sort of node actually
1697 served as the original seed for the given block. */
1699 static tree
1700 block_ultimate_origin (block)
1701 tree block;
1703 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1705 if (immediate_origin == NULL)
1706 return NULL;
1707 else
1709 tree ret_val;
1710 tree lookahead = immediate_origin;
1714 ret_val = lookahead;
1715 lookahead = (TREE_CODE (ret_val) == BLOCK)
1716 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1717 : NULL;
1719 while (lookahead != NULL && lookahead != ret_val);
1720 return ret_val;
1724 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1725 of a virtual function may refer to a base class, so we check the 'this'
1726 parameter. */
1728 static tree
1729 decl_class_context (decl)
1730 tree decl;
1732 tree context = NULL_TREE;
1733 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1734 context = DECL_CONTEXT (decl);
1735 else
1736 context = TYPE_MAIN_VARIANT
1737 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1739 if (context && !TYPE_P (context))
1740 context = NULL_TREE;
1742 return context;
1745 #if 0
1746 static void
1747 output_unsigned_leb128 (value)
1748 unsigned long value;
1750 unsigned long orig_value = value;
1754 unsigned byte = (value & 0x7f);
1756 value >>= 7;
1757 if (value != 0) /* more bytes to follow */
1758 byte |= 0x80;
1759 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1760 if (flag_debug_asm && value == 0)
1761 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1762 ASM_COMMENT_START, orig_value);
1763 fputc ('\n', asm_out_file);
1765 while (value != 0);
1768 static void
1769 output_signed_leb128 (value)
1770 long value;
1772 long orig_value = value;
1773 int negative = (value < 0);
1774 int more;
1778 unsigned byte = (value & 0x7f);
1780 value >>= 7;
1781 if (negative)
1782 value |= 0xfe000000; /* manually sign extend */
1783 if (((value == 0) && ((byte & 0x40) == 0))
1784 || ((value == -1) && ((byte & 0x40) == 1)))
1785 more = 0;
1786 else
1788 byte |= 0x80;
1789 more = 1;
1791 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1792 if (flag_debug_asm && more == 0)
1793 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1794 ASM_COMMENT_START, orig_value);
1795 fputc ('\n', asm_out_file);
1797 while (more);
1799 #endif
1801 /**************** utility functions for attribute functions ******************/
1803 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1804 type code for the given type.
1806 This routine must only be called for GCC type nodes that correspond to
1807 Dwarf fundamental types.
1809 The current Dwarf draft specification calls for Dwarf fundamental types
1810 to accurately reflect the fact that a given type was either a "plain"
1811 integral type or an explicitly "signed" integral type. Unfortunately,
1812 we can't always do this, because GCC may already have thrown away the
1813 information about the precise way in which the type was originally
1814 specified, as in:
1816 typedef signed int my_type;
1818 struct s { my_type f; };
1820 Since we may be stuck here without enought information to do exactly
1821 what is called for in the Dwarf draft specification, we do the best
1822 that we can under the circumstances and always use the "plain" integral
1823 fundamental type codes for int, short, and long types. That's probably
1824 good enough. The additional accuracy called for in the current DWARF
1825 draft specification is probably never even useful in practice. */
1827 static int
1828 fundamental_type_code (type)
1829 tree type;
1831 if (TREE_CODE (type) == ERROR_MARK)
1832 return 0;
1834 switch (TREE_CODE (type))
1836 case ERROR_MARK:
1837 return FT_void;
1839 case VOID_TYPE:
1840 return FT_void;
1842 case INTEGER_TYPE:
1843 /* Carefully distinguish all the standard types of C,
1844 without messing up if the language is not C.
1845 Note that we check only for the names that contain spaces;
1846 other names might occur by coincidence in other languages. */
1847 if (TYPE_NAME (type) != 0
1848 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1849 && DECL_NAME (TYPE_NAME (type)) != 0
1850 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1852 const char *const name =
1853 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1855 if (!strcmp (name, "unsigned char"))
1856 return FT_unsigned_char;
1857 if (!strcmp (name, "signed char"))
1858 return FT_signed_char;
1859 if (!strcmp (name, "unsigned int"))
1860 return FT_unsigned_integer;
1861 if (!strcmp (name, "short int"))
1862 return FT_short;
1863 if (!strcmp (name, "short unsigned int"))
1864 return FT_unsigned_short;
1865 if (!strcmp (name, "long int"))
1866 return FT_long;
1867 if (!strcmp (name, "long unsigned int"))
1868 return FT_unsigned_long;
1869 if (!strcmp (name, "long long int"))
1870 return FT_long_long; /* Not grok'ed by svr4 SDB */
1871 if (!strcmp (name, "long long unsigned int"))
1872 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1875 /* Most integer types will be sorted out above, however, for the
1876 sake of special `array index' integer types, the following code
1877 is also provided. */
1879 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1880 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1882 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1883 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1885 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1886 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1888 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1889 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1891 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1892 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1894 if (TYPE_MODE (type) == TImode)
1895 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1897 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1898 if (TYPE_PRECISION (type) == 1)
1899 return FT_boolean;
1901 abort ();
1903 case REAL_TYPE:
1904 /* Carefully distinguish all the standard types of C,
1905 without messing up if the language is not C. */
1906 if (TYPE_NAME (type) != 0
1907 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1908 && DECL_NAME (TYPE_NAME (type)) != 0
1909 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1911 const char *const name =
1912 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1914 /* Note that here we can run afowl of a serious bug in "classic"
1915 svr4 SDB debuggers. They don't seem to understand the
1916 FT_ext_prec_float type (even though they should). */
1918 if (!strcmp (name, "long double"))
1919 return FT_ext_prec_float;
1922 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1924 /* On the SH, when compiling with -m3e or -m4-single-only, both
1925 float and double are 32 bits. But since the debugger doesn't
1926 know about the subtarget, it always thinks double is 64 bits.
1927 So we have to tell the debugger that the type is float to
1928 make the output of the 'print' command etc. readable. */
1929 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1930 return FT_float;
1931 return FT_dbl_prec_float;
1933 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1934 return FT_float;
1936 /* Note that here we can run afowl of a serious bug in "classic"
1937 svr4 SDB debuggers. They don't seem to understand the
1938 FT_ext_prec_float type (even though they should). */
1940 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1941 return FT_ext_prec_float;
1942 abort ();
1944 case COMPLEX_TYPE:
1945 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1947 case CHAR_TYPE:
1948 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1950 case BOOLEAN_TYPE:
1951 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1953 default:
1954 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1956 return 0;
1959 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1960 the Dwarf "root" type for the given input type. The Dwarf "root" type
1961 of a given type is generally the same as the given type, except that if
1962 the given type is a pointer or reference type, then the root type of
1963 the given type is the root type of the "basis" type for the pointer or
1964 reference type. (This definition of the "root" type is recursive.)
1965 Also, the root type of a `const' qualified type or a `volatile'
1966 qualified type is the root type of the given type without the
1967 qualifiers. */
1969 static tree
1970 root_type_1 (type, count)
1971 tree type;
1972 int count;
1974 /* Give up after searching 1000 levels, in case this is a recursive
1975 pointer type. Such types are possible in Ada, but it is not possible
1976 to represent them in DWARF1 debug info. */
1977 if (count > 1000)
1978 return error_mark_node;
1980 switch (TREE_CODE (type))
1982 case ERROR_MARK:
1983 return error_mark_node;
1985 case POINTER_TYPE:
1986 case REFERENCE_TYPE:
1987 return root_type_1 (TREE_TYPE (type), count+1);
1989 default:
1990 return type;
1994 static tree
1995 root_type (type)
1996 tree type;
1998 type = root_type_1 (type, 0);
1999 if (type != error_mark_node)
2000 type = type_main_variant (type);
2001 return type;
2004 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
2005 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
2007 static void
2008 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
2009 tree type;
2010 int decl_const;
2011 int decl_volatile;
2012 int count;
2014 if (TREE_CODE (type) == ERROR_MARK)
2015 return;
2017 /* Give up after searching 1000 levels, in case this is a recursive
2018 pointer type. Such types are possible in Ada, but it is not possible
2019 to represent them in DWARF1 debug info. */
2020 if (count > 1000)
2021 return;
2023 if (TYPE_READONLY (type) || decl_const)
2024 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
2025 if (TYPE_VOLATILE (type) || decl_volatile)
2026 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
2027 switch (TREE_CODE (type))
2029 case POINTER_TYPE:
2030 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
2031 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
2032 return;
2034 case REFERENCE_TYPE:
2035 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
2036 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
2037 return;
2039 case ERROR_MARK:
2040 default:
2041 return;
2045 static void
2046 write_modifier_bytes (type, decl_const, decl_volatile)
2047 tree type;
2048 int decl_const;
2049 int decl_volatile;
2051 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
2054 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
2055 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
2057 static inline int
2058 type_is_fundamental (type)
2059 tree type;
2061 switch (TREE_CODE (type))
2063 case ERROR_MARK:
2064 case VOID_TYPE:
2065 case INTEGER_TYPE:
2066 case REAL_TYPE:
2067 case COMPLEX_TYPE:
2068 case BOOLEAN_TYPE:
2069 case CHAR_TYPE:
2070 return 1;
2072 case SET_TYPE:
2073 case ARRAY_TYPE:
2074 case RECORD_TYPE:
2075 case UNION_TYPE:
2076 case QUAL_UNION_TYPE:
2077 case ENUMERAL_TYPE:
2078 case FUNCTION_TYPE:
2079 case METHOD_TYPE:
2080 case POINTER_TYPE:
2081 case REFERENCE_TYPE:
2082 case FILE_TYPE:
2083 case OFFSET_TYPE:
2084 case LANG_TYPE:
2085 case VECTOR_TYPE:
2086 return 0;
2088 default:
2089 abort ();
2091 return 0;
2094 /* Given a pointer to some ..._DECL tree node, generate an assembly language
2095 equate directive which will associate a symbolic name with the current DIE.
2097 The name used is an artificial label generated from the DECL_UID number
2098 associated with the given decl node. The name it gets equated to is the
2099 symbolic label that we (previously) output at the start of the DIE that
2100 we are currently generating.
2102 Calling this function while generating some "decl related" form of DIE
2103 makes it possible to later refer to the DIE which represents the given
2104 decl simply by re-generating the symbolic name from the ..._DECL node's
2105 UID number. */
2107 static void
2108 equate_decl_number_to_die_number (decl)
2109 tree decl;
2111 /* In the case where we are generating a DIE for some ..._DECL node
2112 which represents either some inline function declaration or some
2113 entity declared within an inline function declaration/definition,
2114 setup a symbolic name for the current DIE so that we have a name
2115 for this DIE that we can easily refer to later on within
2116 AT_abstract_origin attributes. */
2118 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
2119 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2121 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
2122 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2123 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
2126 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
2127 equate directive which will associate a symbolic name with the current DIE.
2129 The name used is an artificial label generated from the TYPE_UID number
2130 associated with the given type node. The name it gets equated to is the
2131 symbolic label that we (previously) output at the start of the DIE that
2132 we are currently generating.
2134 Calling this function while generating some "type related" form of DIE
2135 makes it easy to later refer to the DIE which represents the given type
2136 simply by re-generating the alternative name from the ..._TYPE node's
2137 UID number. */
2139 static inline void
2140 equate_type_number_to_die_number (type)
2141 tree type;
2143 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
2144 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2146 /* We are generating a DIE to represent the main variant of this type
2147 (i.e the type without any const or volatile qualifiers) so in order
2148 to get the equate to come out right, we need to get the main variant
2149 itself here. */
2151 type = type_main_variant (type);
2153 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
2154 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2155 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
2158 static void
2159 output_reg_number (rtl)
2160 rtx rtl;
2162 unsigned regno = REGNO (rtl);
2164 if (regno >= DWARF_FRAME_REGISTERS)
2166 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
2167 regno);
2168 regno = 0;
2170 fprintf (asm_out_file, "%s0x%x",
2171 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
2172 if (flag_debug_asm)
2174 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
2175 PRINT_REG (rtl, 0, asm_out_file);
2177 fputc ('\n', asm_out_file);
2180 /* The following routine is a nice and simple transducer. It converts the
2181 RTL for a variable or parameter (resident in memory) into an equivalent
2182 Dwarf representation of a mechanism for getting the address of that same
2183 variable onto the top of a hypothetical "address evaluation" stack.
2185 When creating memory location descriptors, we are effectively trans-
2186 forming the RTL for a memory-resident object into its Dwarf postfix
2187 expression equivalent. This routine just recursively descends an
2188 RTL tree, turning it into Dwarf postfix code as it goes. */
2190 static void
2191 output_mem_loc_descriptor (rtl)
2192 rtx rtl;
2194 /* Note that for a dynamically sized array, the location we will
2195 generate a description of here will be the lowest numbered location
2196 which is actually within the array. That's *not* necessarily the
2197 same as the zeroth element of the array. */
2199 #ifdef ASM_SIMPLIFY_DWARF_ADDR
2200 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
2201 #endif
2203 switch (GET_CODE (rtl))
2205 case SUBREG:
2207 /* The case of a subreg may arise when we have a local (register)
2208 variable or a formal (register) parameter which doesn't quite
2209 fill up an entire register. For now, just assume that it is
2210 legitimate to make the Dwarf info refer to the whole register
2211 which contains the given subreg. */
2213 rtl = SUBREG_REG (rtl);
2214 /* Drop thru. */
2216 case REG:
2218 /* Whenever a register number forms a part of the description of
2219 the method for calculating the (dynamic) address of a memory
2220 resident object, DWARF rules require the register number to
2221 be referred to as a "base register". This distinction is not
2222 based in any way upon what category of register the hardware
2223 believes the given register belongs to. This is strictly
2224 DWARF terminology we're dealing with here.
2226 Note that in cases where the location of a memory-resident data
2227 object could be expressed as:
2229 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
2231 the actual DWARF location descriptor that we generate may just
2232 be OP_BASEREG (basereg). This may look deceptively like the
2233 object in question was allocated to a register (rather than
2234 in memory) so DWARF consumers need to be aware of the subtle
2235 distinction between OP_REG and OP_BASEREG. */
2237 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
2238 output_reg_number (rtl);
2239 break;
2241 case MEM:
2242 output_mem_loc_descriptor (XEXP (rtl, 0));
2243 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
2244 break;
2246 case CONST:
2247 case SYMBOL_REF:
2248 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
2249 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2250 break;
2252 case PLUS:
2253 output_mem_loc_descriptor (XEXP (rtl, 0));
2254 output_mem_loc_descriptor (XEXP (rtl, 1));
2255 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2256 break;
2258 case CONST_INT:
2259 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2260 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
2261 break;
2263 case MULT:
2264 /* If a pseudo-reg is optimized away, it is possible for it to
2265 be replaced with a MEM containing a multiply. Use a GNU extension
2266 to describe it. */
2267 output_mem_loc_descriptor (XEXP (rtl, 0));
2268 output_mem_loc_descriptor (XEXP (rtl, 1));
2269 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
2270 break;
2272 default:
2273 abort ();
2277 /* Output a proper Dwarf location descriptor for a variable or parameter
2278 which is either allocated in a register or in a memory location. For
2279 a register, we just generate an OP_REG and the register number. For a
2280 memory location we provide a Dwarf postfix expression describing how to
2281 generate the (dynamic) address of the object onto the address stack. */
2283 static void
2284 output_loc_descriptor (rtl)
2285 rtx rtl;
2287 switch (GET_CODE (rtl))
2289 case SUBREG:
2291 /* The case of a subreg may arise when we have a local (register)
2292 variable or a formal (register) parameter which doesn't quite
2293 fill up an entire register. For now, just assume that it is
2294 legitimate to make the Dwarf info refer to the whole register
2295 which contains the given subreg. */
2297 rtl = SUBREG_REG (rtl);
2298 /* Drop thru. */
2300 case REG:
2301 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
2302 output_reg_number (rtl);
2303 break;
2305 case MEM:
2306 output_mem_loc_descriptor (XEXP (rtl, 0));
2307 break;
2309 default:
2310 abort (); /* Should never happen */
2314 /* Given a tree node describing an array bound (either lower or upper)
2315 output a representation for that bound. */
2317 static void
2318 output_bound_representation (bound, dim_num, u_or_l)
2319 tree bound;
2320 unsigned dim_num; /* For multi-dimensional arrays. */
2321 char u_or_l; /* Designates upper or lower bound. */
2323 switch (TREE_CODE (bound))
2326 case ERROR_MARK:
2327 return;
2329 /* All fixed-bounds are represented by INTEGER_CST nodes. */
2331 case INTEGER_CST:
2332 if (host_integerp (bound, 0))
2333 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
2334 break;
2336 default:
2338 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
2339 SAVE_EXPR nodes, in which case we can do something, or as
2340 an expression, which we cannot represent. */
2342 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2343 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2345 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
2346 current_dienum, dim_num, u_or_l);
2348 sprintf (end_label, BOUND_END_LABEL_FMT,
2349 current_dienum, dim_num, u_or_l);
2351 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2352 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2354 /* If optimization is turned on, the SAVE_EXPRs that describe
2355 how to access the upper bound values are essentially bogus.
2356 They only describe (at best) how to get at these values at
2357 the points in the generated code right after they have just
2358 been computed. Worse yet, in the typical case, the upper
2359 bound values will not even *be* computed in the optimized
2360 code, so these SAVE_EXPRs are entirely bogus.
2362 In order to compensate for this fact, we check here to see
2363 if optimization is enabled, and if so, we effectively create
2364 an empty location description for the (unknown and unknowable)
2365 upper bound.
2367 This should not cause too much trouble for existing (stupid?)
2368 debuggers because they have to deal with empty upper bounds
2369 location descriptions anyway in order to be able to deal with
2370 incomplete array types.
2372 Of course an intelligent debugger (GDB?) should be able to
2373 comprehend that a missing upper bound specification in a
2374 array type used for a storage class `auto' local array variable
2375 indicates that the upper bound is both unknown (at compile-
2376 time) and unknowable (at run-time) due to optimization. */
2378 if (! optimize)
2380 while (TREE_CODE (bound) == NOP_EXPR
2381 || TREE_CODE (bound) == CONVERT_EXPR)
2382 bound = TREE_OPERAND (bound, 0);
2384 if (TREE_CODE (bound) == SAVE_EXPR)
2385 output_loc_descriptor
2386 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
2389 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2391 break;
2396 /* Recursive function to output a sequence of value/name pairs for
2397 enumeration constants in reversed order. This is called from
2398 enumeration_type_die. */
2400 static void
2401 output_enumeral_list (link)
2402 tree link;
2404 if (link)
2406 output_enumeral_list (TREE_CHAIN (link));
2408 if (host_integerp (TREE_VALUE (link), 0))
2409 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2410 tree_low_cst (TREE_VALUE (link), 0));
2412 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
2413 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
2417 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
2418 which is not less than the value itself. */
2420 static inline HOST_WIDE_INT
2421 ceiling (value, boundary)
2422 HOST_WIDE_INT value;
2423 unsigned int boundary;
2425 return (((value + boundary - 1) / boundary) * boundary);
2428 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
2429 pointer to the declared type for the relevant field variable, or return
2430 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
2432 static inline tree
2433 field_type (decl)
2434 tree decl;
2436 tree type;
2438 if (TREE_CODE (decl) == ERROR_MARK)
2439 return integer_type_node;
2441 type = DECL_BIT_FIELD_TYPE (decl);
2442 if (type == NULL)
2443 type = TREE_TYPE (decl);
2444 return type;
2447 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2448 node, return the alignment in bits for the type, or else return
2449 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
2451 static inline unsigned int
2452 simple_type_align_in_bits (type)
2453 tree type;
2455 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
2458 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2459 node, return the size in bits for the type if it is a constant, or
2460 else return the alignment for the type if the type's size is not
2461 constant, or else return BITS_PER_WORD if the type actually turns out
2462 to be an ERROR_MARK node. */
2464 static inline unsigned HOST_WIDE_INT
2465 simple_type_size_in_bits (type)
2466 tree type;
2468 tree type_size_tree;
2470 if (TREE_CODE (type) == ERROR_MARK)
2471 return BITS_PER_WORD;
2472 type_size_tree = TYPE_SIZE (type);
2474 if (type_size_tree == NULL_TREE)
2475 return 0;
2476 if (! host_integerp (type_size_tree, 1))
2477 return TYPE_ALIGN (type);
2478 return tree_low_cst (type_size_tree, 1);
2481 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
2482 return the byte offset of the lowest addressed byte of the "containing
2483 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
2484 mine what that offset is, either because the argument turns out to be a
2485 pointer to an ERROR_MARK node, or because the offset is actually variable.
2486 (We can't handle the latter case just yet.) */
2488 static HOST_WIDE_INT
2489 field_byte_offset (decl)
2490 tree decl;
2492 unsigned int type_align_in_bytes;
2493 unsigned int type_align_in_bits;
2494 unsigned HOST_WIDE_INT type_size_in_bits;
2495 HOST_WIDE_INT object_offset_in_align_units;
2496 HOST_WIDE_INT object_offset_in_bits;
2497 HOST_WIDE_INT object_offset_in_bytes;
2498 tree type;
2499 tree field_size_tree;
2500 HOST_WIDE_INT bitpos_int;
2501 HOST_WIDE_INT deepest_bitpos;
2502 unsigned HOST_WIDE_INT field_size_in_bits;
2504 if (TREE_CODE (decl) == ERROR_MARK)
2505 return 0;
2507 if (TREE_CODE (decl) != FIELD_DECL)
2508 abort ();
2510 type = field_type (decl);
2511 field_size_tree = DECL_SIZE (decl);
2513 /* The size could be unspecified if there was an error, or for
2514 a flexible array member. */
2515 if (! field_size_tree)
2516 field_size_tree = bitsize_zero_node;
2518 /* We cannot yet cope with fields whose positions or sizes are variable,
2519 so for now, when we see such things, we simply return 0. Someday,
2520 we may be able to handle such cases, but it will be damn difficult. */
2522 if (! host_integerp (bit_position (decl), 0)
2523 || ! host_integerp (field_size_tree, 1))
2524 return 0;
2526 bitpos_int = int_bit_position (decl);
2527 field_size_in_bits = tree_low_cst (field_size_tree, 1);
2529 type_size_in_bits = simple_type_size_in_bits (type);
2530 type_align_in_bits = simple_type_align_in_bits (type);
2531 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2533 /* Note that the GCC front-end doesn't make any attempt to keep track
2534 of the starting bit offset (relative to the start of the containing
2535 structure type) of the hypothetical "containing object" for a bit-
2536 field. Thus, when computing the byte offset value for the start of
2537 the "containing object" of a bit-field, we must deduce this infor-
2538 mation on our own.
2540 This can be rather tricky to do in some cases. For example, handling
2541 the following structure type definition when compiling for an i386/i486
2542 target (which only aligns long long's to 32-bit boundaries) can be very
2543 tricky:
2545 struct S {
2546 int field1;
2547 long long field2:31;
2550 Fortunately, there is a simple rule-of-thumb which can be used in such
2551 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2552 the structure shown above. It decides to do this based upon one simple
2553 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2554 taining object" for each bit-field at the first (i.e. lowest addressed)
2555 legitimate alignment boundary (based upon the required minimum alignment
2556 for the declared type of the field) which it can possibly use, subject
2557 to the condition that there is still enough available space remaining
2558 in the containing object (when allocated at the selected point) to
2559 fully accommodate all of the bits of the bit-field itself.
2561 This simple rule makes it obvious why GCC allocates 8 bytes for each
2562 object of the structure type shown above. When looking for a place to
2563 allocate the "containing object" for `field2', the compiler simply tries
2564 to allocate a 64-bit "containing object" at each successive 32-bit
2565 boundary (starting at zero) until it finds a place to allocate that 64-
2566 bit field such that at least 31 contiguous (and previously unallocated)
2567 bits remain within that selected 64 bit field. (As it turns out, for
2568 the example above, the compiler finds that it is OK to allocate the
2569 "containing object" 64-bit field at bit-offset zero within the
2570 structure type.)
2572 Here we attempt to work backwards from the limited set of facts we're
2573 given, and we try to deduce from those facts, where GCC must have
2574 believed that the containing object started (within the structure type).
2576 The value we deduce is then used (by the callers of this routine) to
2577 generate AT_location and AT_bit_offset attributes for fields (both
2578 bit-fields and, in the case of AT_location, regular fields as well). */
2580 /* Figure out the bit-distance from the start of the structure to the
2581 "deepest" bit of the bit-field. */
2582 deepest_bitpos = bitpos_int + field_size_in_bits;
2584 /* This is the tricky part. Use some fancy footwork to deduce where the
2585 lowest addressed bit of the containing object must be. */
2586 object_offset_in_bits
2587 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2589 /* Compute the offset of the containing object in "alignment units". */
2590 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2592 /* Compute the offset of the containing object in bytes. */
2593 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2595 /* The above code assumes that the field does not cross an alignment
2596 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2597 or if the structure is packed. If this happens, then we get an object
2598 which starts after the bitfield, which means that the bit offset is
2599 negative. Gdb fails when given negative bit offsets. We avoid this
2600 by recomputing using the first bit of the bitfield. This will give
2601 us an object which does not completely contain the bitfield, but it
2602 will be aligned, and it will contain the first bit of the bitfield.
2604 However, only do this for a BYTES_BIG_ENDIAN target. For a
2605 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2606 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2607 then we end up computing the object byte offset for the wrong word of the
2608 desired bitfield, which in turn causes the field offset to be negative
2609 in bit_offset_attribute. */
2610 if (BYTES_BIG_ENDIAN
2611 && object_offset_in_bits > bitpos_int)
2613 deepest_bitpos = bitpos_int + 1;
2614 object_offset_in_bits
2615 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2616 object_offset_in_align_units = (object_offset_in_bits
2617 / type_align_in_bits);
2618 object_offset_in_bytes = (object_offset_in_align_units
2619 * type_align_in_bytes);
2622 return object_offset_in_bytes;
2625 /****************************** attributes *********************************/
2627 /* The following routines are responsible for writing out the various types
2628 of Dwarf attributes (and any following data bytes associated with them).
2629 These routines are listed in order based on the numerical codes of their
2630 associated attributes. */
2632 /* Generate an AT_sibling attribute. */
2634 static inline void
2635 sibling_attribute ()
2637 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2639 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2640 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2641 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2644 /* Output the form of location attributes suitable for whole variables and
2645 whole parameters. Note that the location attributes for struct fields
2646 are generated by the routine `data_member_location_attribute' below. */
2648 static void
2649 location_attribute (rtl)
2650 rtx rtl;
2652 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2653 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2655 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2656 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2657 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2658 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2659 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2661 /* Handle a special case. If we are about to output a location descriptor
2662 for a variable or parameter which has been optimized out of existence,
2663 don't do that. Instead we output a zero-length location descriptor
2664 value as part of the location attribute.
2666 A variable which has been optimized out of existence will have a
2667 DECL_RTL value which denotes a pseudo-reg.
2669 Currently, in some rare cases, variables can have DECL_RTL values
2670 which look like (MEM (REG pseudo-reg#)). These cases are due to
2671 bugs elsewhere in the compiler. We treat such cases
2672 as if the variable(s) in question had been optimized out of existence.
2674 Note that in all cases where we wish to express the fact that a
2675 variable has been optimized out of existence, we do not simply
2676 suppress the generation of the entire location attribute because
2677 the absence of a location attribute in certain kinds of DIEs is
2678 used to indicate something else entirely... i.e. that the DIE
2679 represents an object declaration, but not a definition. So saith
2680 the PLSIG.
2683 if (! is_pseudo_reg (rtl)
2684 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2685 output_loc_descriptor (rtl);
2687 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2690 /* Output the specialized form of location attribute used for data members
2691 of struct and union types.
2693 In the special case of a FIELD_DECL node which represents a bit-field,
2694 the "offset" part of this special location descriptor must indicate the
2695 distance in bytes from the lowest-addressed byte of the containing
2696 struct or union type to the lowest-addressed byte of the "containing
2697 object" for the bit-field. (See the `field_byte_offset' function above.)
2699 For any given bit-field, the "containing object" is a hypothetical
2700 object (of some integral or enum type) within which the given bit-field
2701 lives. The type of this hypothetical "containing object" is always the
2702 same as the declared type of the individual bit-field itself (for GCC
2703 anyway... the DWARF spec doesn't actually mandate this).
2705 Note that it is the size (in bytes) of the hypothetical "containing
2706 object" which will be given in the AT_byte_size attribute for this
2707 bit-field. (See the `byte_size_attribute' function below.) It is
2708 also used when calculating the value of the AT_bit_offset attribute.
2709 (See the `bit_offset_attribute' function below.) */
2711 static void
2712 data_member_location_attribute (t)
2713 tree t;
2715 unsigned object_offset_in_bytes;
2716 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2717 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2719 if (TREE_CODE (t) == TREE_VEC)
2720 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2721 else
2722 object_offset_in_bytes = field_byte_offset (t);
2724 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2725 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2726 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2727 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2728 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2729 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2730 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2731 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2732 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2735 /* Output an AT_const_value attribute for a variable or a parameter which
2736 does not have a "location" either in memory or in a register. These
2737 things can arise in GNU C when a constant is passed as an actual
2738 parameter to an inlined function. They can also arise in C++ where
2739 declared constants do not necessarily get memory "homes". */
2741 static void
2742 const_value_attribute (rtl)
2743 rtx rtl;
2745 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2746 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2748 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2749 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2750 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2751 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2752 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2754 switch (GET_CODE (rtl))
2756 case CONST_INT:
2757 /* Note that a CONST_INT rtx could represent either an integer or
2758 a floating-point constant. A CONST_INT is used whenever the
2759 constant will fit into a single word. In all such cases, the
2760 original mode of the constant value is wiped out, and the
2761 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2762 precise mode information for these constants, we always just
2763 output them using 4 bytes. */
2765 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2766 break;
2768 case CONST_DOUBLE:
2769 /* Note that a CONST_DOUBLE rtx could represent either an integer
2770 or a floating-point constant. A CONST_DOUBLE is used whenever
2771 the constant requires more than one word in order to be adequately
2772 represented. In all such cases, the original mode of the constant
2773 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2774 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2776 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2777 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2778 (unsigned int) CONST_DOUBLE_LOW (rtl));
2779 break;
2781 case CONST_STRING:
2782 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2783 break;
2785 case SYMBOL_REF:
2786 case LABEL_REF:
2787 case CONST:
2788 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2789 break;
2791 case PLUS:
2792 /* In cases where an inlined instance of an inline function is passed
2793 the address of an `auto' variable (which is local to the caller)
2794 we can get a situation where the DECL_RTL of the artificial
2795 local variable (for the inlining) which acts as a stand-in for
2796 the corresponding formal parameter (of the inline function)
2797 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2798 This is not exactly a compile-time constant expression, but it
2799 isn't the address of the (artificial) local variable either.
2800 Rather, it represents the *value* which the artificial local
2801 variable always has during its lifetime. We currently have no
2802 way to represent such quasi-constant values in Dwarf, so for now
2803 we just punt and generate an AT_const_value attribute with form
2804 FORM_BLOCK4 and a length of zero. */
2805 break;
2807 default:
2808 abort (); /* No other kinds of rtx should be possible here. */
2811 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2814 /* Generate *either* an AT_location attribute or else an AT_const_value
2815 data attribute for a variable or a parameter. We generate the
2816 AT_const_value attribute only in those cases where the given
2817 variable or parameter does not have a true "location" either in
2818 memory or in a register. This can happen (for example) when a
2819 constant is passed as an actual argument in a call to an inline
2820 function. (It's possible that these things can crop up in other
2821 ways also.) Note that one type of constant value which can be
2822 passed into an inlined function is a constant pointer. This can
2823 happen for example if an actual argument in an inlined function
2824 call evaluates to a compile-time constant address. */
2826 static void
2827 location_or_const_value_attribute (decl)
2828 tree decl;
2830 rtx rtl;
2832 if (TREE_CODE (decl) == ERROR_MARK)
2833 return;
2835 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2837 /* Should never happen. */
2838 abort ();
2839 return;
2842 /* Here we have to decide where we are going to say the parameter "lives"
2843 (as far as the debugger is concerned). We only have a couple of choices.
2844 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2845 normally indicates where the parameter lives during most of the activa-
2846 tion of the function. If optimization is enabled however, this could
2847 be either NULL or else a pseudo-reg. Both of those cases indicate that
2848 the parameter doesn't really live anywhere (as far as the code generation
2849 parts of GCC are concerned) during most of the function's activation.
2850 That will happen (for example) if the parameter is never referenced
2851 within the function.
2853 We could just generate a location descriptor here for all non-NULL
2854 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2855 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2856 cases where DECL_RTL is NULL or is a pseudo-reg.
2858 Note however that we can only get away with using DECL_INCOMING_RTL as
2859 a backup substitute for DECL_RTL in certain limited cases. In cases
2860 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2861 we can be sure that the parameter was passed using the same type as it
2862 is declared to have within the function, and that its DECL_INCOMING_RTL
2863 points us to a place where a value of that type is passed. In cases
2864 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2865 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2866 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2867 points us to a value of some type which is *different* from the type
2868 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2869 to generate a location attribute in such cases, the debugger would
2870 end up (for example) trying to fetch a `float' from a place which
2871 actually contains the first part of a `double'. That would lead to
2872 really incorrect and confusing output at debug-time, and we don't
2873 want that now do we?
2875 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2876 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2877 couple of cute exceptions however. On little-endian machines we can
2878 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2879 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2880 an integral type which is smaller than TREE_TYPE(decl). These cases
2881 arise when (on a little-endian machine) a non-prototyped function has
2882 a parameter declared to be of type `short' or `char'. In such cases,
2883 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2884 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2885 passed `int' value. If the debugger then uses that address to fetch a
2886 `short' or a `char' (on a little-endian machine) the result will be the
2887 correct data, so we allow for such exceptional cases below.
2889 Note that our goal here is to describe the place where the given formal
2890 parameter lives during most of the function's activation (i.e. between
2891 the end of the prologue and the start of the epilogue). We'll do that
2892 as best as we can. Note however that if the given formal parameter is
2893 modified sometime during the execution of the function, then a stack
2894 backtrace (at debug-time) will show the function as having been called
2895 with the *new* value rather than the value which was originally passed
2896 in. This happens rarely enough that it is not a major problem, but it
2897 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2898 may generate two additional attributes for any given TAG_formal_parameter
2899 DIE which will describe the "passed type" and the "passed location" for
2900 the given formal parameter in addition to the attributes we now generate
2901 to indicate the "declared type" and the "active location" for each
2902 parameter. This additional set of attributes could be used by debuggers
2903 for stack backtraces.
2905 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2906 can be NULL also. This happens (for example) for inlined-instances of
2907 inline function formal parameters which are never referenced. This really
2908 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2909 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2910 these values for inlined instances of inline function parameters, so
2911 when we see such cases, we are just out-of-luck for the time
2912 being (until integrate.c gets fixed).
2915 /* Use DECL_RTL as the "location" unless we find something better. */
2916 rtl = DECL_RTL (decl);
2918 if (TREE_CODE (decl) == PARM_DECL)
2919 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2921 /* This decl represents a formal parameter which was optimized out. */
2922 tree declared_type = type_main_variant (TREE_TYPE (decl));
2923 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2925 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2926 *all* cases where (rtl == NULL_RTX) just below. */
2928 if (declared_type == passed_type)
2929 rtl = DECL_INCOMING_RTL (decl);
2930 else if (! BYTES_BIG_ENDIAN)
2931 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2932 /* NMS WTF? */
2933 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2934 rtl = DECL_INCOMING_RTL (decl);
2937 if (rtl == NULL_RTX)
2938 return;
2940 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2941 #ifdef LEAF_REG_REMAP
2942 if (current_function_uses_only_leaf_regs)
2943 leaf_renumber_regs_insn (rtl);
2944 #endif
2946 switch (GET_CODE (rtl))
2948 case ADDRESSOF:
2949 /* The address of a variable that was optimized away; don't emit
2950 anything. */
2951 break;
2953 case CONST_INT:
2954 case CONST_DOUBLE:
2955 case CONST_STRING:
2956 case SYMBOL_REF:
2957 case LABEL_REF:
2958 case CONST:
2959 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2960 const_value_attribute (rtl);
2961 break;
2963 case MEM:
2964 case REG:
2965 case SUBREG:
2966 location_attribute (rtl);
2967 break;
2969 case CONCAT:
2970 /* ??? CONCAT is used for complex variables, which may have the real
2971 part stored in one place and the imag part stored somewhere else.
2972 DWARF1 has no way to describe a variable that lives in two different
2973 places, so we just describe where the first part lives, and hope that
2974 the second part is stored after it. */
2975 location_attribute (XEXP (rtl, 0));
2976 break;
2978 default:
2979 abort (); /* Should never happen. */
2983 /* Generate an AT_name attribute given some string value to be included as
2984 the value of the attribute. */
2986 static inline void
2987 name_attribute (name_string)
2988 const char *name_string;
2990 if (name_string && *name_string)
2992 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2993 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2997 static inline void
2998 fund_type_attribute (ft_code)
2999 unsigned ft_code;
3001 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
3002 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
3005 static void
3006 mod_fund_type_attribute (type, decl_const, decl_volatile)
3007 tree type;
3008 int decl_const;
3009 int decl_volatile;
3011 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3012 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3014 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
3015 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
3016 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
3017 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3018 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3019 write_modifier_bytes (type, decl_const, decl_volatile);
3020 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3021 fundamental_type_code (root_type (type)));
3022 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3025 static inline void
3026 user_def_type_attribute (type)
3027 tree type;
3029 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
3031 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
3032 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
3033 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
3036 static void
3037 mod_u_d_type_attribute (type, decl_const, decl_volatile)
3038 tree type;
3039 int decl_const;
3040 int decl_volatile;
3042 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3043 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3044 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
3046 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
3047 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
3048 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
3049 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3050 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3051 write_modifier_bytes (type, decl_const, decl_volatile);
3052 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
3053 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
3054 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3057 #ifdef USE_ORDERING_ATTRIBUTE
3058 static inline void
3059 ordering_attribute (ordering)
3060 unsigned ordering;
3062 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
3063 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
3065 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3067 /* Note that the block of subscript information for an array type also
3068 includes information about the element type of type given array type. */
3070 static void
3071 subscript_data_attribute (type)
3072 tree type;
3074 unsigned dimension_number;
3075 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3076 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3078 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
3079 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
3080 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
3081 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3082 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3084 /* The GNU compilers represent multidimensional array types as sequences
3085 of one dimensional array types whose element types are themselves array
3086 types. Here we squish that down, so that each multidimensional array
3087 type gets only one array_type DIE in the Dwarf debugging info. The
3088 draft Dwarf specification say that we are allowed to do this kind
3089 of compression in C (because there is no difference between an
3090 array or arrays and a multidimensional array in C) but for other
3091 source languages (e.g. Ada) we probably shouldn't do this. */
3093 for (dimension_number = 0;
3094 TREE_CODE (type) == ARRAY_TYPE;
3095 type = TREE_TYPE (type), dimension_number++)
3097 tree domain = TYPE_DOMAIN (type);
3099 /* Arrays come in three flavors. Unspecified bounds, fixed
3100 bounds, and (in GNU C only) variable bounds. Handle all
3101 three forms here. */
3103 if (domain)
3105 /* We have an array type with specified bounds. */
3107 tree lower = TYPE_MIN_VALUE (domain);
3108 tree upper = TYPE_MAX_VALUE (domain);
3110 /* Handle only fundamental types as index types for now. */
3111 if (! type_is_fundamental (domain))
3112 abort ();
3114 /* Output the representation format byte for this dimension. */
3115 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
3116 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
3117 upper && TREE_CODE (upper) == INTEGER_CST));
3119 /* Output the index type for this dimension. */
3120 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3121 fundamental_type_code (domain));
3123 /* Output the representation for the lower bound. */
3124 output_bound_representation (lower, dimension_number, 'l');
3126 /* Output the representation for the upper bound. */
3127 if (upper)
3128 output_bound_representation (upper, dimension_number, 'u');
3129 else
3130 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3132 else
3134 /* We have an array type with an unspecified length. For C and
3135 C++ we can assume that this really means that (a) the index
3136 type is an integral type, and (b) the lower bound is zero.
3137 Note that Dwarf defines the representation of an unspecified
3138 (upper) bound as being a zero-length location description. */
3140 /* Output the array-bounds format byte. */
3142 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
3144 /* Output the (assumed) index type. */
3146 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
3148 /* Output the (assumed) lower bound (constant) value. */
3150 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3152 /* Output the (empty) location description for the upper bound. */
3154 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3158 /* Output the prefix byte that says that the element type is coming up. */
3160 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
3162 /* Output a representation of the type of the elements of this array type. */
3164 type_attribute (type, 0, 0);
3166 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3169 static void
3170 byte_size_attribute (tree_node)
3171 tree tree_node;
3173 unsigned size;
3175 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
3176 switch (TREE_CODE (tree_node))
3178 case ERROR_MARK:
3179 size = 0;
3180 break;
3182 case ENUMERAL_TYPE:
3183 case RECORD_TYPE:
3184 case UNION_TYPE:
3185 case QUAL_UNION_TYPE:
3186 case ARRAY_TYPE:
3187 size = int_size_in_bytes (tree_node);
3188 break;
3190 case FIELD_DECL:
3191 /* For a data member of a struct or union, the AT_byte_size is
3192 generally given as the number of bytes normally allocated for
3193 an object of the *declared* type of the member itself. This
3194 is true even for bit-fields. */
3195 size = simple_type_size_in_bits (field_type (tree_node))
3196 / BITS_PER_UNIT;
3197 break;
3199 default:
3200 abort ();
3203 /* Note that `size' might be -1 when we get to this point. If it
3204 is, that indicates that the byte size of the entity in question
3205 is variable. We have no good way of expressing this fact in Dwarf
3206 at the present time, so just let the -1 pass on through. */
3208 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
3211 /* For a FIELD_DECL node which represents a bit-field, output an attribute
3212 which specifies the distance in bits from the highest order bit of the
3213 "containing object" for the bit-field to the highest order bit of the
3214 bit-field itself.
3216 For any given bit-field, the "containing object" is a hypothetical
3217 object (of some integral or enum type) within which the given bit-field
3218 lives. The type of this hypothetical "containing object" is always the
3219 same as the declared type of the individual bit-field itself.
3221 The determination of the exact location of the "containing object" for
3222 a bit-field is rather complicated. It's handled by the `field_byte_offset'
3223 function (above).
3225 Note that it is the size (in bytes) of the hypothetical "containing
3226 object" which will be given in the AT_byte_size attribute for this
3227 bit-field. (See `byte_size_attribute' above.) */
3229 static inline void
3230 bit_offset_attribute (decl)
3231 tree decl;
3233 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
3234 tree type = DECL_BIT_FIELD_TYPE (decl);
3235 HOST_WIDE_INT bitpos_int;
3236 HOST_WIDE_INT highest_order_object_bit_offset;
3237 HOST_WIDE_INT highest_order_field_bit_offset;
3238 HOST_WIDE_INT bit_offset;
3240 /* Must be a bit field. */
3241 if (!type
3242 || TREE_CODE (decl) != FIELD_DECL)
3243 abort ();
3245 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
3246 if we encounter such things, just return without generating any
3247 attribute whatsoever. */
3249 if (! host_integerp (bit_position (decl), 0)
3250 || ! host_integerp (DECL_SIZE (decl), 1))
3251 return;
3253 bitpos_int = int_bit_position (decl);
3255 /* Note that the bit offset is always the distance (in bits) from the
3256 highest-order bit of the "containing object" to the highest-order
3257 bit of the bit-field itself. Since the "high-order end" of any
3258 object or field is different on big-endian and little-endian machines,
3259 the computation below must take account of these differences. */
3261 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
3262 highest_order_field_bit_offset = bitpos_int;
3264 if (! BYTES_BIG_ENDIAN)
3266 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
3267 highest_order_object_bit_offset += simple_type_size_in_bits (type);
3270 bit_offset =
3271 (! BYTES_BIG_ENDIAN
3272 ? highest_order_object_bit_offset - highest_order_field_bit_offset
3273 : highest_order_field_bit_offset - highest_order_object_bit_offset);
3275 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
3276 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
3279 /* For a FIELD_DECL node which represents a bit field, output an attribute
3280 which specifies the length in bits of the given field. */
3282 static inline void
3283 bit_size_attribute (decl)
3284 tree decl;
3286 /* Must be a field and a bit field. */
3287 if (TREE_CODE (decl) != FIELD_DECL
3288 || ! DECL_BIT_FIELD_TYPE (decl))
3289 abort ();
3291 if (host_integerp (DECL_SIZE (decl), 1))
3293 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
3294 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3295 tree_low_cst (DECL_SIZE (decl), 1));
3299 /* The following routine outputs the `element_list' attribute for enumeration
3300 type DIEs. The element_lits attribute includes the names and values of
3301 all of the enumeration constants associated with the given enumeration
3302 type. */
3304 static inline void
3305 element_list_attribute (element)
3306 tree element;
3308 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3309 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3311 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
3312 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
3313 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
3314 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3315 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3317 /* Here we output a list of value/name pairs for each enumeration constant
3318 defined for this enumeration type (as required), but we do it in REVERSE
3319 order. The order is the one required by the draft #5 Dwarf specification
3320 published by the UI/PLSIG. */
3322 output_enumeral_list (element); /* Recursively output the whole list. */
3324 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3327 /* Generate an AT_stmt_list attribute. These are normally present only in
3328 DIEs with a TAG_compile_unit tag. */
3330 static inline void
3331 stmt_list_attribute (label)
3332 const char *label;
3334 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
3335 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3336 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3339 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
3340 for a subroutine DIE. */
3342 static inline void
3343 low_pc_attribute (asm_low_label)
3344 const char *asm_low_label;
3346 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
3347 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
3350 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
3351 subroutine DIE. */
3353 static inline void
3354 high_pc_attribute (asm_high_label)
3355 const char *asm_high_label;
3357 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
3358 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
3361 /* Generate an AT_body_begin attribute for a subroutine DIE. */
3363 static inline void
3364 body_begin_attribute (asm_begin_label)
3365 const char *asm_begin_label;
3367 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
3368 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
3371 /* Generate an AT_body_end attribute for a subroutine DIE. */
3373 static inline void
3374 body_end_attribute (asm_end_label)
3375 const char *asm_end_label;
3377 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
3378 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
3381 /* Generate an AT_language attribute given a LANG value. These attributes
3382 are used only within TAG_compile_unit DIEs. */
3384 static inline void
3385 language_attribute (language_code)
3386 unsigned language_code;
3388 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
3389 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
3392 static inline void
3393 member_attribute (context)
3394 tree context;
3396 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3398 /* Generate this attribute only for members in C++. */
3400 if (context != NULL && is_tagged_type (context))
3402 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
3403 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
3404 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3408 #if 0
3409 static inline void
3410 string_length_attribute (upper_bound)
3411 tree upper_bound;
3413 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3414 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3416 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
3417 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
3418 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
3419 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3420 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3421 output_bound_representation (upper_bound, 0, 'u');
3422 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3424 #endif
3426 static inline void
3427 comp_dir_attribute (dirname)
3428 const char *dirname;
3430 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
3431 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
3434 static inline void
3435 sf_names_attribute (sf_names_start_label)
3436 const char *sf_names_start_label;
3438 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
3439 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3440 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
3443 static inline void
3444 src_info_attribute (src_info_start_label)
3445 const char *src_info_start_label;
3447 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
3448 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3449 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
3452 static inline void
3453 mac_info_attribute (mac_info_start_label)
3454 const char *mac_info_start_label;
3456 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
3457 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
3458 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
3461 static inline void
3462 prototyped_attribute (func_type)
3463 tree func_type;
3465 if ((strcmp (language_string, "GNU C") == 0)
3466 && (TYPE_ARG_TYPES (func_type) != NULL))
3468 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
3469 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3473 static inline void
3474 producer_attribute (producer)
3475 const char *producer;
3477 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
3478 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
3481 static inline void
3482 inline_attribute (decl)
3483 tree decl;
3485 if (DECL_INLINE (decl))
3487 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3488 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3492 static inline void
3493 containing_type_attribute (containing_type)
3494 tree containing_type;
3496 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3498 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3499 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3500 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3503 static inline void
3504 abstract_origin_attribute (origin)
3505 tree origin;
3507 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3509 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3510 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3512 case 'd':
3513 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3514 break;
3516 case 't':
3517 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3518 break;
3520 default:
3521 abort (); /* Should never happen. */
3524 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3527 #ifdef DWARF_DECL_COORDINATES
3528 static inline void
3529 src_coords_attribute (src_fileno, src_lineno)
3530 unsigned src_fileno;
3531 unsigned src_lineno;
3533 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3534 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3535 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3537 #endif /* defined(DWARF_DECL_COORDINATES) */
3539 static inline void
3540 pure_or_virtual_attribute (func_decl)
3541 tree func_decl;
3543 if (DECL_VIRTUAL_P (func_decl))
3545 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3546 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3547 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3548 else
3549 #endif
3550 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3551 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3555 /************************* end of attributes *****************************/
3557 /********************* utility routines for DIEs *************************/
3559 /* Output an AT_name attribute and an AT_src_coords attribute for the
3560 given decl, but only if it actually has a name. */
3562 static void
3563 name_and_src_coords_attributes (decl)
3564 tree decl;
3566 tree decl_name = DECL_NAME (decl);
3568 if (decl_name && IDENTIFIER_POINTER (decl_name))
3570 name_attribute (IDENTIFIER_POINTER (decl_name));
3571 #ifdef DWARF_DECL_COORDINATES
3573 register unsigned file_index;
3575 /* This is annoying, but we have to pop out of the .debug section
3576 for a moment while we call `lookup_filename' because calling it
3577 may cause a temporary switch into the .debug_sfnames section and
3578 most svr4 assemblers are not smart enough to be able to nest
3579 section switches to any depth greater than one. Note that we
3580 also can't skirt this issue by delaying all output to the
3581 .debug_sfnames section unit the end of compilation because that
3582 would cause us to have inter-section forward references and
3583 Fred Fish sez that m68k/svr4 assemblers botch those. */
3585 ASM_OUTPUT_POP_SECTION (asm_out_file);
3586 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3587 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3589 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3591 #endif /* defined(DWARF_DECL_COORDINATES) */
3595 /* Many forms of DIEs contain a "type description" part. The following
3596 routine writes out these "type descriptor" parts. */
3598 static void
3599 type_attribute (type, decl_const, decl_volatile)
3600 tree type;
3601 int decl_const;
3602 int decl_volatile;
3604 enum tree_code code = TREE_CODE (type);
3605 int root_type_modified;
3607 if (code == ERROR_MARK)
3608 return;
3610 /* Handle a special case. For functions whose return type is void,
3611 we generate *no* type attribute. (Note that no object may have
3612 type `void', so this only applies to function return types. */
3614 if (code == VOID_TYPE)
3615 return;
3617 /* If this is a subtype, find the underlying type. Eventually,
3618 this should write out the appropriate subtype info. */
3619 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3620 && TREE_TYPE (type) != 0)
3621 type = TREE_TYPE (type), code = TREE_CODE (type);
3623 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3624 || decl_const || decl_volatile
3625 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3627 if (type_is_fundamental (root_type (type)))
3629 if (root_type_modified)
3630 mod_fund_type_attribute (type, decl_const, decl_volatile);
3631 else
3632 fund_type_attribute (fundamental_type_code (type));
3634 else
3636 if (root_type_modified)
3637 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3638 else
3639 /* We have to get the type_main_variant here (and pass that to the
3640 `user_def_type_attribute' routine) because the ..._TYPE node we
3641 have might simply be a *copy* of some original type node (where
3642 the copy was created to help us keep track of typedef names)
3643 and that copy might have a different TYPE_UID from the original
3644 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3645 is labeling a given type DIE for future reference, it always and
3646 only creates labels for DIEs representing *main variants*, and it
3647 never even knows about non-main-variants.) */
3648 user_def_type_attribute (type_main_variant (type));
3652 /* Given a tree pointer to a struct, class, union, or enum type node, return
3653 a pointer to the (string) tag name for the given type, or zero if the
3654 type was declared without a tag. */
3656 static const char *
3657 type_tag (type)
3658 tree type;
3660 const char *name = 0;
3662 if (TYPE_NAME (type) != 0)
3664 tree t = 0;
3666 /* Find the IDENTIFIER_NODE for the type name. */
3667 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3668 t = TYPE_NAME (type);
3670 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3671 a TYPE_DECL node, regardless of whether or not a `typedef' was
3672 involved. */
3673 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3674 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3675 t = DECL_NAME (TYPE_NAME (type));
3677 /* Now get the name as a string, or invent one. */
3678 if (t != 0)
3679 name = IDENTIFIER_POINTER (t);
3682 return (name == 0 || *name == '\0') ? 0 : name;
3685 static inline void
3686 dienum_push ()
3688 /* Start by checking if the pending_sibling_stack needs to be expanded.
3689 If necessary, expand it. */
3691 if (pending_siblings == pending_siblings_allocated)
3693 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3694 pending_sibling_stack
3695 = (unsigned *) xrealloc (pending_sibling_stack,
3696 pending_siblings_allocated * sizeof(unsigned));
3699 pending_siblings++;
3700 NEXT_DIE_NUM = next_unused_dienum++;
3703 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3704 NEXT_DIE_NUM. */
3706 static inline void
3707 dienum_pop ()
3709 pending_siblings--;
3712 static inline tree
3713 member_declared_type (member)
3714 tree member;
3716 return (DECL_BIT_FIELD_TYPE (member))
3717 ? DECL_BIT_FIELD_TYPE (member)
3718 : TREE_TYPE (member);
3721 /* Get the function's label, as described by its RTL.
3722 This may be different from the DECL_NAME name used
3723 in the source file. */
3725 static const char *
3726 function_start_label (decl)
3727 tree decl;
3729 rtx x;
3730 const char *fnname;
3732 x = DECL_RTL (decl);
3733 if (GET_CODE (x) != MEM)
3734 abort ();
3735 x = XEXP (x, 0);
3736 if (GET_CODE (x) != SYMBOL_REF)
3737 abort ();
3738 fnname = XSTR (x, 0);
3739 return fnname;
3743 /******************************* DIEs ************************************/
3745 /* Output routines for individual types of DIEs. */
3747 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3749 static void
3750 output_array_type_die (arg)
3751 void *arg;
3753 tree type = arg;
3755 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3756 sibling_attribute ();
3757 equate_type_number_to_die_number (type);
3758 member_attribute (TYPE_CONTEXT (type));
3760 /* I believe that we can default the array ordering. SDB will probably
3761 do the right things even if AT_ordering is not present. It's not
3762 even an issue until we start to get into multidimensional arrays
3763 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3764 dimensional arrays, then we'll have to put the AT_ordering attribute
3765 back in. (But if and when we find out that we need to put these in,
3766 we will only do so for multidimensional arrays. After all, we don't
3767 want to waste space in the .debug section now do we?) */
3769 #ifdef USE_ORDERING_ATTRIBUTE
3770 ordering_attribute (ORD_row_major);
3771 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3773 subscript_data_attribute (type);
3776 static void
3777 output_set_type_die (arg)
3778 void *arg;
3780 tree type = arg;
3782 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3783 sibling_attribute ();
3784 equate_type_number_to_die_number (type);
3785 member_attribute (TYPE_CONTEXT (type));
3786 type_attribute (TREE_TYPE (type), 0, 0);
3789 #if 0
3790 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3792 static void
3793 output_entry_point_die (arg)
3794 void *arg;
3796 tree decl = arg;
3797 tree origin = decl_ultimate_origin (decl);
3799 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3800 sibling_attribute ();
3801 dienum_push ();
3802 if (origin != NULL)
3803 abstract_origin_attribute (origin);
3804 else
3806 name_and_src_coords_attributes (decl);
3807 member_attribute (DECL_CONTEXT (decl));
3808 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3810 if (DECL_ABSTRACT (decl))
3811 equate_decl_number_to_die_number (decl);
3812 else
3813 low_pc_attribute (function_start_label (decl));
3815 #endif
3817 /* Output a DIE to represent an inlined instance of an enumeration type. */
3819 static void
3820 output_inlined_enumeration_type_die (arg)
3821 void *arg;
3823 tree type = arg;
3825 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3826 sibling_attribute ();
3827 if (!TREE_ASM_WRITTEN (type))
3828 abort ();
3829 abstract_origin_attribute (type);
3832 /* Output a DIE to represent an inlined instance of a structure type. */
3834 static void
3835 output_inlined_structure_type_die (arg)
3836 void *arg;
3838 tree type = arg;
3840 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3841 sibling_attribute ();
3842 if (!TREE_ASM_WRITTEN (type))
3843 abort ();
3844 abstract_origin_attribute (type);
3847 /* Output a DIE to represent an inlined instance of a union type. */
3849 static void
3850 output_inlined_union_type_die (arg)
3851 void *arg;
3853 tree type = arg;
3855 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3856 sibling_attribute ();
3857 if (!TREE_ASM_WRITTEN (type))
3858 abort ();
3859 abstract_origin_attribute (type);
3862 /* Output a DIE to represent an enumeration type. Note that these DIEs
3863 include all of the information about the enumeration values also.
3864 This information is encoded into the element_list attribute. */
3866 static void
3867 output_enumeration_type_die (arg)
3868 void *arg;
3870 tree type = arg;
3872 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3873 sibling_attribute ();
3874 equate_type_number_to_die_number (type);
3875 name_attribute (type_tag (type));
3876 member_attribute (TYPE_CONTEXT (type));
3878 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3879 given enum type is incomplete, do not generate the AT_byte_size
3880 attribute or the AT_element_list attribute. */
3882 if (COMPLETE_TYPE_P (type))
3884 byte_size_attribute (type);
3885 element_list_attribute (TYPE_FIELDS (type));
3889 /* Output a DIE to represent either a real live formal parameter decl or
3890 to represent just the type of some formal parameter position in some
3891 function type.
3893 Note that this routine is a bit unusual because its argument may be
3894 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3895 represents an inlining of some PARM_DECL) or else some sort of a
3896 ..._TYPE node. If it's the former then this function is being called
3897 to output a DIE to represent a formal parameter object (or some inlining
3898 thereof). If it's the latter, then this function is only being called
3899 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3900 formal argument type of some subprogram type. */
3902 static void
3903 output_formal_parameter_die (arg)
3904 void *arg;
3906 tree node = arg;
3908 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3909 sibling_attribute ();
3911 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3913 case 'd': /* We were called with some kind of a ..._DECL node. */
3915 register tree origin = decl_ultimate_origin (node);
3917 if (origin != NULL)
3918 abstract_origin_attribute (origin);
3919 else
3921 name_and_src_coords_attributes (node);
3922 type_attribute (TREE_TYPE (node),
3923 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3925 if (DECL_ABSTRACT (node))
3926 equate_decl_number_to_die_number (node);
3927 else
3928 location_or_const_value_attribute (node);
3930 break;
3932 case 't': /* We were called with some kind of a ..._TYPE node. */
3933 type_attribute (node, 0, 0);
3934 break;
3936 default:
3937 abort (); /* Should never happen. */
3941 /* Output a DIE to represent a declared function (either file-scope
3942 or block-local) which has "external linkage" (according to ANSI-C). */
3944 static void
3945 output_global_subroutine_die (arg)
3946 void *arg;
3948 tree decl = arg;
3949 tree origin = decl_ultimate_origin (decl);
3951 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3952 sibling_attribute ();
3953 dienum_push ();
3954 if (origin != NULL)
3955 abstract_origin_attribute (origin);
3956 else
3958 tree type = TREE_TYPE (decl);
3960 name_and_src_coords_attributes (decl);
3961 inline_attribute (decl);
3962 prototyped_attribute (type);
3963 member_attribute (DECL_CONTEXT (decl));
3964 type_attribute (TREE_TYPE (type), 0, 0);
3965 pure_or_virtual_attribute (decl);
3967 if (DECL_ABSTRACT (decl))
3968 equate_decl_number_to_die_number (decl);
3969 else
3971 if (! DECL_EXTERNAL (decl) && ! in_class
3972 && decl == current_function_decl)
3974 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3976 low_pc_attribute (function_start_label (decl));
3977 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3978 high_pc_attribute (label);
3979 if (use_gnu_debug_info_extensions)
3981 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3982 body_begin_attribute (label);
3983 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3984 body_end_attribute (label);
3990 /* Output a DIE to represent a declared data object (either file-scope
3991 or block-local) which has "external linkage" (according to ANSI-C). */
3993 static void
3994 output_global_variable_die (arg)
3995 void *arg;
3997 tree decl = arg;
3998 tree origin = decl_ultimate_origin (decl);
4000 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
4001 sibling_attribute ();
4002 if (origin != NULL)
4003 abstract_origin_attribute (origin);
4004 else
4006 name_and_src_coords_attributes (decl);
4007 member_attribute (DECL_CONTEXT (decl));
4008 type_attribute (TREE_TYPE (decl),
4009 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4011 if (DECL_ABSTRACT (decl))
4012 equate_decl_number_to_die_number (decl);
4013 else
4015 if (! DECL_EXTERNAL (decl) && ! in_class
4016 && current_function_decl == decl_function_context (decl))
4017 location_or_const_value_attribute (decl);
4021 static void
4022 output_label_die (arg)
4023 void *arg;
4025 tree decl = arg;
4026 tree origin = decl_ultimate_origin (decl);
4028 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
4029 sibling_attribute ();
4030 if (origin != NULL)
4031 abstract_origin_attribute (origin);
4032 else
4033 name_and_src_coords_attributes (decl);
4034 if (DECL_ABSTRACT (decl))
4035 equate_decl_number_to_die_number (decl);
4036 else
4038 rtx insn = DECL_RTL (decl);
4040 /* Deleted labels are programmer specified labels which have been
4041 eliminated because of various optimisations. We still emit them
4042 here so that it is possible to put breakpoints on them. */
4043 if (GET_CODE (insn) == CODE_LABEL
4044 || ((GET_CODE (insn) == NOTE
4045 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
4047 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4049 /* When optimization is enabled (via -O) some parts of the compiler
4050 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
4051 represent source-level labels which were explicitly declared by
4052 the user. This really shouldn't be happening though, so catch
4053 it if it ever does happen. */
4055 if (INSN_DELETED_P (insn))
4056 abort (); /* Should never happen. */
4058 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
4059 low_pc_attribute (label);
4064 static void
4065 output_lexical_block_die (arg)
4066 void *arg;
4068 tree stmt = arg;
4070 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
4071 sibling_attribute ();
4072 dienum_push ();
4073 if (! BLOCK_ABSTRACT (stmt))
4075 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4076 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4078 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4079 low_pc_attribute (begin_label);
4080 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4081 high_pc_attribute (end_label);
4085 static void
4086 output_inlined_subroutine_die (arg)
4087 void *arg;
4089 tree stmt = arg;
4091 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
4092 sibling_attribute ();
4093 dienum_push ();
4094 abstract_origin_attribute (block_ultimate_origin (stmt));
4095 if (! BLOCK_ABSTRACT (stmt))
4097 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4098 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4100 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4101 low_pc_attribute (begin_label);
4102 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4103 high_pc_attribute (end_label);
4107 /* Output a DIE to represent a declared data object (either file-scope
4108 or block-local) which has "internal linkage" (according to ANSI-C). */
4110 static void
4111 output_local_variable_die (arg)
4112 void *arg;
4114 tree decl = arg;
4115 tree origin = decl_ultimate_origin (decl);
4117 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
4118 sibling_attribute ();
4119 if (origin != NULL)
4120 abstract_origin_attribute (origin);
4121 else
4123 name_and_src_coords_attributes (decl);
4124 member_attribute (DECL_CONTEXT (decl));
4125 type_attribute (TREE_TYPE (decl),
4126 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4128 if (DECL_ABSTRACT (decl))
4129 equate_decl_number_to_die_number (decl);
4130 else
4131 location_or_const_value_attribute (decl);
4134 static void
4135 output_member_die (arg)
4136 void *arg;
4138 tree decl = arg;
4140 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
4141 sibling_attribute ();
4142 name_and_src_coords_attributes (decl);
4143 member_attribute (DECL_CONTEXT (decl));
4144 type_attribute (member_declared_type (decl),
4145 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4146 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
4148 byte_size_attribute (decl);
4149 bit_size_attribute (decl);
4150 bit_offset_attribute (decl);
4152 data_member_location_attribute (decl);
4155 #if 0
4156 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
4157 modified types instead.
4159 We keep this code here just in case these types of DIEs may be
4160 needed to represent certain things in other languages (e.g. Pascal)
4161 someday. */
4163 static void
4164 output_pointer_type_die (arg)
4165 void *arg;
4167 tree type = arg;
4169 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
4170 sibling_attribute ();
4171 equate_type_number_to_die_number (type);
4172 member_attribute (TYPE_CONTEXT (type));
4173 type_attribute (TREE_TYPE (type), 0, 0);
4176 static void
4177 output_reference_type_die (arg)
4178 void *arg;
4180 tree type = arg;
4182 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
4183 sibling_attribute ();
4184 equate_type_number_to_die_number (type);
4185 member_attribute (TYPE_CONTEXT (type));
4186 type_attribute (TREE_TYPE (type), 0, 0);
4188 #endif
4190 static void
4191 output_ptr_to_mbr_type_die (arg)
4192 void *arg;
4194 tree type = arg;
4196 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
4197 sibling_attribute ();
4198 equate_type_number_to_die_number (type);
4199 member_attribute (TYPE_CONTEXT (type));
4200 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
4201 type_attribute (TREE_TYPE (type), 0, 0);
4204 static void
4205 output_compile_unit_die (arg)
4206 void *arg;
4208 const char *main_input_filename = arg;
4210 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
4211 sibling_attribute ();
4212 dienum_push ();
4213 name_attribute (main_input_filename);
4216 char producer[250];
4218 sprintf (producer, "%s %s", language_string, version_string);
4219 producer_attribute (producer);
4222 if (strcmp (language_string, "GNU C++") == 0)
4223 language_attribute (LANG_C_PLUS_PLUS);
4224 else if (strcmp (language_string, "GNU Ada") == 0)
4225 language_attribute (LANG_ADA83);
4226 else if (strcmp (language_string, "GNU F77") == 0)
4227 language_attribute (LANG_FORTRAN77);
4228 else if (strcmp (language_string, "GNU Pascal") == 0)
4229 language_attribute (LANG_PASCAL83);
4230 else if (strcmp (language_string, "GNU Java") == 0)
4231 language_attribute (LANG_JAVA);
4232 else if (flag_traditional)
4233 language_attribute (LANG_C);
4234 else
4235 language_attribute (LANG_C89);
4236 low_pc_attribute (TEXT_BEGIN_LABEL);
4237 high_pc_attribute (TEXT_END_LABEL);
4238 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4239 stmt_list_attribute (LINE_BEGIN_LABEL);
4240 last_filename = xstrdup (main_input_filename);
4243 const char *wd = getpwd ();
4244 if (wd)
4245 comp_dir_attribute (wd);
4248 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
4250 sf_names_attribute (SFNAMES_BEGIN_LABEL);
4251 src_info_attribute (SRCINFO_BEGIN_LABEL);
4252 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4253 mac_info_attribute (MACINFO_BEGIN_LABEL);
4257 static void
4258 output_string_type_die (arg)
4259 void *arg;
4261 tree type = arg;
4263 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
4264 sibling_attribute ();
4265 equate_type_number_to_die_number (type);
4266 member_attribute (TYPE_CONTEXT (type));
4267 /* this is a fixed length string */
4268 byte_size_attribute (type);
4271 static void
4272 output_inheritance_die (arg)
4273 void *arg;
4275 tree binfo = arg;
4277 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
4278 sibling_attribute ();
4279 type_attribute (BINFO_TYPE (binfo), 0, 0);
4280 data_member_location_attribute (binfo);
4281 if (TREE_VIA_VIRTUAL (binfo))
4283 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
4284 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4286 if (TREE_VIA_PUBLIC (binfo))
4288 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
4289 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4291 else if (TREE_VIA_PROTECTED (binfo))
4293 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
4294 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4298 static void
4299 output_structure_type_die (arg)
4300 void *arg;
4302 tree type = arg;
4304 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
4305 sibling_attribute ();
4306 equate_type_number_to_die_number (type);
4307 name_attribute (type_tag (type));
4308 member_attribute (TYPE_CONTEXT (type));
4310 /* If this type has been completed, then give it a byte_size attribute
4311 and prepare to give a list of members. Otherwise, don't do either of
4312 these things. In the latter case, we will not be generating a list
4313 of members (since we don't have any idea what they might be for an
4314 incomplete type). */
4316 if (COMPLETE_TYPE_P (type))
4318 dienum_push ();
4319 byte_size_attribute (type);
4323 /* Output a DIE to represent a declared function (either file-scope
4324 or block-local) which has "internal linkage" (according to ANSI-C). */
4326 static void
4327 output_local_subroutine_die (arg)
4328 void *arg;
4330 tree decl = arg;
4331 tree origin = decl_ultimate_origin (decl);
4333 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
4334 sibling_attribute ();
4335 dienum_push ();
4336 if (origin != NULL)
4337 abstract_origin_attribute (origin);
4338 else
4340 tree type = TREE_TYPE (decl);
4342 name_and_src_coords_attributes (decl);
4343 inline_attribute (decl);
4344 prototyped_attribute (type);
4345 member_attribute (DECL_CONTEXT (decl));
4346 type_attribute (TREE_TYPE (type), 0, 0);
4347 pure_or_virtual_attribute (decl);
4349 if (DECL_ABSTRACT (decl))
4350 equate_decl_number_to_die_number (decl);
4351 else
4353 /* Avoid getting screwed up in cases where a function was declared
4354 static but where no definition was ever given for it. */
4356 if (TREE_ASM_WRITTEN (decl))
4358 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4359 low_pc_attribute (function_start_label (decl));
4360 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4361 high_pc_attribute (label);
4362 if (use_gnu_debug_info_extensions)
4364 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
4365 body_begin_attribute (label);
4366 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
4367 body_end_attribute (label);
4373 static void
4374 output_subroutine_type_die (arg)
4375 void *arg;
4377 tree type = arg;
4378 tree return_type = TREE_TYPE (type);
4380 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
4381 sibling_attribute ();
4382 dienum_push ();
4383 equate_type_number_to_die_number (type);
4384 prototyped_attribute (type);
4385 member_attribute (TYPE_CONTEXT (type));
4386 type_attribute (return_type, 0, 0);
4389 static void
4390 output_typedef_die (arg)
4391 void *arg;
4393 tree decl = arg;
4394 tree origin = decl_ultimate_origin (decl);
4396 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
4397 sibling_attribute ();
4398 if (origin != NULL)
4399 abstract_origin_attribute (origin);
4400 else
4402 name_and_src_coords_attributes (decl);
4403 member_attribute (DECL_CONTEXT (decl));
4404 type_attribute (TREE_TYPE (decl),
4405 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4407 if (DECL_ABSTRACT (decl))
4408 equate_decl_number_to_die_number (decl);
4411 static void
4412 output_union_type_die (arg)
4413 void *arg;
4415 tree type = arg;
4417 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
4418 sibling_attribute ();
4419 equate_type_number_to_die_number (type);
4420 name_attribute (type_tag (type));
4421 member_attribute (TYPE_CONTEXT (type));
4423 /* If this type has been completed, then give it a byte_size attribute
4424 and prepare to give a list of members. Otherwise, don't do either of
4425 these things. In the latter case, we will not be generating a list
4426 of members (since we don't have any idea what they might be for an
4427 incomplete type). */
4429 if (COMPLETE_TYPE_P (type))
4431 dienum_push ();
4432 byte_size_attribute (type);
4436 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
4437 at the end of an (ANSI prototyped) formal parameters list. */
4439 static void
4440 output_unspecified_parameters_die (arg)
4441 void *arg;
4443 tree decl_or_type = arg;
4445 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
4446 sibling_attribute ();
4448 /* This kludge is here only for the sake of being compatible with what
4449 the USL CI5 C compiler does. The specification of Dwarf Version 1
4450 doesn't say that TAG_unspecified_parameters DIEs should contain any
4451 attributes other than the AT_sibling attribute, but they are certainly
4452 allowed to contain additional attributes, and the CI5 compiler
4453 generates AT_name, AT_fund_type, and AT_location attributes within
4454 TAG_unspecified_parameters DIEs which appear in the child lists for
4455 DIEs representing function definitions, so we do likewise here. */
4457 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
4459 name_attribute ("...");
4460 fund_type_attribute (FT_pointer);
4461 /* location_attribute (?); */
4465 static void
4466 output_padded_null_die (arg)
4467 void *arg ATTRIBUTE_UNUSED;
4469 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
4472 /*************************** end of DIEs *********************************/
4474 /* Generate some type of DIE. This routine generates the generic outer
4475 wrapper stuff which goes around all types of DIE's (regardless of their
4476 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
4477 DIE-length word, followed by the guts of the DIE itself. After the guts
4478 of the DIE, there must always be a terminator label for the DIE. */
4480 static void
4481 output_die (die_specific_output_function, param)
4482 void (*die_specific_output_function) PARAMS ((void *));
4483 void *param;
4485 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4486 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4488 current_dienum = NEXT_DIE_NUM;
4489 NEXT_DIE_NUM = next_unused_dienum;
4491 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4492 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4494 /* Write a label which will act as the name for the start of this DIE. */
4496 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4498 /* Write the DIE-length word. */
4500 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4502 /* Fill in the guts of the DIE. */
4504 next_unused_dienum++;
4505 die_specific_output_function (param);
4507 /* Write a label which will act as the name for the end of this DIE. */
4509 ASM_OUTPUT_LABEL (asm_out_file, end_label);
4512 static void
4513 end_sibling_chain ()
4515 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4517 current_dienum = NEXT_DIE_NUM;
4518 NEXT_DIE_NUM = next_unused_dienum;
4520 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4522 /* Write a label which will act as the name for the start of this DIE. */
4524 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4526 /* Write the DIE-length word. */
4528 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4530 dienum_pop ();
4533 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4534 TAG_unspecified_parameters DIE) to represent the types of the formal
4535 parameters as specified in some function type specification (except
4536 for those which appear as part of a function *definition*).
4538 Note that we must be careful here to output all of the parameter
4539 DIEs *before* we output any DIEs needed to represent the types of
4540 the formal parameters. This keeps svr4 SDB happy because it
4541 (incorrectly) thinks that the first non-parameter DIE it sees ends
4542 the formal parameter list. */
4544 static void
4545 output_formal_types (function_or_method_type)
4546 tree function_or_method_type;
4548 tree link;
4549 tree formal_type = NULL;
4550 tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4552 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4553 get bogus recursion when outputting tagged types local to a
4554 function declaration. */
4555 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4556 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4558 /* In the case where we are generating a formal types list for a C++
4559 non-static member function type, skip over the first thing on the
4560 TYPE_ARG_TYPES list because it only represents the type of the
4561 hidden `this pointer'. The debugger should be able to figure
4562 out (without being explicitly told) that this non-static member
4563 function type takes a `this pointer' and should be able to figure
4564 what the type of that hidden parameter is from the AT_member
4565 attribute of the parent TAG_subroutine_type DIE. */
4567 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4568 first_parm_type = TREE_CHAIN (first_parm_type);
4570 /* Make our first pass over the list of formal parameter types and output
4571 a TAG_formal_parameter DIE for each one. */
4573 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4575 formal_type = TREE_VALUE (link);
4576 if (formal_type == void_type_node)
4577 break;
4579 /* Output a (nameless) DIE to represent the formal parameter itself. */
4581 output_die (output_formal_parameter_die, formal_type);
4584 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4585 DIE to the end of the parameter list. */
4587 if (formal_type != void_type_node)
4588 output_die (output_unspecified_parameters_die, function_or_method_type);
4590 /* Make our second (and final) pass over the list of formal parameter types
4591 and output DIEs to represent those types (as necessary). */
4593 for (link = TYPE_ARG_TYPES (function_or_method_type);
4594 link;
4595 link = TREE_CHAIN (link))
4597 formal_type = TREE_VALUE (link);
4598 if (formal_type == void_type_node)
4599 break;
4601 output_type (formal_type, function_or_method_type);
4604 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4607 /* Remember a type in the pending_types_list. */
4609 static void
4610 pend_type (type)
4611 tree type;
4613 if (pending_types == pending_types_allocated)
4615 pending_types_allocated += PENDING_TYPES_INCREMENT;
4616 pending_types_list
4617 = (tree *) xrealloc (pending_types_list,
4618 sizeof (tree) * pending_types_allocated);
4620 pending_types_list[pending_types++] = type;
4622 /* Mark the pending type as having been output already (even though
4623 it hasn't been). This prevents the type from being added to the
4624 pending_types_list more than once. */
4626 TREE_ASM_WRITTEN (type) = 1;
4629 /* Return non-zero if it is legitimate to output DIEs to represent a
4630 given type while we are generating the list of child DIEs for some
4631 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4633 See the comments within the function for a description of when it is
4634 considered legitimate to output DIEs for various kinds of types.
4636 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4637 or it may point to a BLOCK node (for types local to a block), or to a
4638 FUNCTION_DECL node (for types local to the heading of some function
4639 definition), or to a FUNCTION_TYPE node (for types local to the
4640 prototyped parameter list of a function type specification), or to a
4641 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4642 (in the case of C++ nested types).
4644 The `scope' parameter should likewise be NULL or should point to a
4645 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4646 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4648 This function is used only for deciding when to "pend" and when to
4649 "un-pend" types to/from the pending_types_list.
4651 Note that we sometimes make use of this "type pending" feature in a
4652 rather twisted way to temporarily delay the production of DIEs for the
4653 types of formal parameters. (We do this just to make svr4 SDB happy.)
4654 It order to delay the production of DIEs representing types of formal
4655 parameters, callers of this function supply `fake_containing_scope' as
4656 the `scope' parameter to this function. Given that fake_containing_scope
4657 is a tagged type which is *not* the containing scope for *any* other type,
4658 the desired effect is achieved, i.e. output of DIEs representing types
4659 is temporarily suspended, and any type DIEs which would have otherwise
4660 been output are instead placed onto the pending_types_list. Later on,
4661 we force these (temporarily pended) types to be output simply by calling
4662 `output_pending_types_for_scope' with an actual argument equal to the
4663 true scope of the types we temporarily pended. */
4665 static inline int
4666 type_ok_for_scope (type, scope)
4667 tree type;
4668 tree scope;
4670 /* Tagged types (i.e. struct, union, and enum types) must always be
4671 output only in the scopes where they actually belong (or else the
4672 scoping of their own tag names and the scoping of their member
4673 names will be incorrect). Non-tagged-types on the other hand can
4674 generally be output anywhere, except that svr4 SDB really doesn't
4675 want to see them nested within struct or union types, so here we
4676 say it is always OK to immediately output any such a (non-tagged)
4677 type, so long as we are not within such a context. Note that the
4678 only kinds of non-tagged types which we will be dealing with here
4679 (for C and C++ anyway) will be array types and function types. */
4681 return is_tagged_type (type)
4682 ? (TYPE_CONTEXT (type) == scope
4683 /* Ignore namespaces for the moment. */
4684 || (scope == NULL_TREE
4685 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4686 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4687 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4688 : (scope == NULL_TREE || ! is_tagged_type (scope));
4691 /* Output any pending types (from the pending_types list) which we can output
4692 now (taking into account the scope that we are working on now).
4694 For each type output, remove the given type from the pending_types_list
4695 *before* we try to output it.
4697 Note that we have to process the list in beginning-to-end order,
4698 because the call made here to output_type may cause yet more types
4699 to be added to the end of the list, and we may have to output some
4700 of them too. */
4702 static void
4703 output_pending_types_for_scope (containing_scope)
4704 tree containing_scope;
4706 unsigned i;
4708 for (i = 0; i < pending_types; )
4710 tree type = pending_types_list[i];
4712 if (type_ok_for_scope (type, containing_scope))
4714 tree *mover;
4715 tree *limit;
4717 pending_types--;
4718 limit = &pending_types_list[pending_types];
4719 for (mover = &pending_types_list[i]; mover < limit; mover++)
4720 *mover = *(mover+1);
4722 /* Un-mark the type as having been output already (because it
4723 hasn't been, really). Then call output_type to generate a
4724 Dwarf representation of it. */
4726 TREE_ASM_WRITTEN (type) = 0;
4727 output_type (type, containing_scope);
4729 /* Don't increment the loop counter in this case because we
4730 have shifted all of the subsequent pending types down one
4731 element in the pending_types_list array. */
4733 else
4734 i++;
4738 /* Remember a type in the incomplete_types_list. */
4740 static void
4741 add_incomplete_type (type)
4742 tree type;
4744 if (incomplete_types == incomplete_types_allocated)
4746 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4747 incomplete_types_list
4748 = (tree *) xrealloc (incomplete_types_list,
4749 sizeof (tree) * incomplete_types_allocated);
4752 incomplete_types_list[incomplete_types++] = type;
4755 /* Walk through the list of incomplete types again, trying once more to
4756 emit full debugging info for them. */
4758 static void
4759 retry_incomplete_types ()
4761 tree type;
4763 finalizing = 1;
4764 while (incomplete_types)
4766 --incomplete_types;
4767 type = incomplete_types_list[incomplete_types];
4768 output_type (type, NULL_TREE);
4772 static void
4773 output_type (type, containing_scope)
4774 tree type;
4775 tree containing_scope;
4777 if (type == 0 || type == error_mark_node)
4778 return;
4780 /* We are going to output a DIE to represent the unqualified version of
4781 this type (i.e. without any const or volatile qualifiers) so get
4782 the main variant (i.e. the unqualified version) of this type now. */
4784 type = type_main_variant (type);
4786 if (TREE_ASM_WRITTEN (type))
4788 if (finalizing && AGGREGATE_TYPE_P (type))
4790 tree member;
4792 /* Some of our nested types might not have been defined when we
4793 were written out before; force them out now. */
4795 for (member = TYPE_FIELDS (type); member;
4796 member = TREE_CHAIN (member))
4797 if (TREE_CODE (member) == TYPE_DECL
4798 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4799 output_type (TREE_TYPE (member), containing_scope);
4801 return;
4804 /* If this is a nested type whose containing class hasn't been
4805 written out yet, writing it out will cover this one, too. */
4807 if (TYPE_CONTEXT (type)
4808 && TYPE_P (TYPE_CONTEXT (type))
4809 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4811 output_type (TYPE_CONTEXT (type), containing_scope);
4812 return;
4815 /* Don't generate any DIEs for this type now unless it is OK to do so
4816 (based upon what `type_ok_for_scope' tells us). */
4818 if (! type_ok_for_scope (type, containing_scope))
4820 pend_type (type);
4821 return;
4824 switch (TREE_CODE (type))
4826 case ERROR_MARK:
4827 break;
4829 case VECTOR_TYPE:
4830 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4831 break;
4833 case POINTER_TYPE:
4834 case REFERENCE_TYPE:
4835 /* Prevent infinite recursion in cases where this is a recursive
4836 type. Recursive types are possible in Ada. */
4837 TREE_ASM_WRITTEN (type) = 1;
4838 /* For these types, all that is required is that we output a DIE
4839 (or a set of DIEs) to represent the "basis" type. */
4840 output_type (TREE_TYPE (type), containing_scope);
4841 break;
4843 case OFFSET_TYPE:
4844 /* This code is used for C++ pointer-to-data-member types. */
4845 /* Output a description of the relevant class type. */
4846 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4847 /* Output a description of the type of the object pointed to. */
4848 output_type (TREE_TYPE (type), containing_scope);
4849 /* Now output a DIE to represent this pointer-to-data-member type
4850 itself. */
4851 output_die (output_ptr_to_mbr_type_die, type);
4852 break;
4854 case SET_TYPE:
4855 output_type (TYPE_DOMAIN (type), containing_scope);
4856 output_die (output_set_type_die, type);
4857 break;
4859 case FILE_TYPE:
4860 output_type (TREE_TYPE (type), containing_scope);
4861 abort (); /* No way to represent these in Dwarf yet! */
4862 break;
4864 case FUNCTION_TYPE:
4865 /* Force out return type (in case it wasn't forced out already). */
4866 output_type (TREE_TYPE (type), containing_scope);
4867 output_die (output_subroutine_type_die, type);
4868 output_formal_types (type);
4869 end_sibling_chain ();
4870 break;
4872 case METHOD_TYPE:
4873 /* Force out return type (in case it wasn't forced out already). */
4874 output_type (TREE_TYPE (type), containing_scope);
4875 output_die (output_subroutine_type_die, type);
4876 output_formal_types (type);
4877 end_sibling_chain ();
4878 break;
4880 case ARRAY_TYPE:
4881 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4883 output_type (TREE_TYPE (type), containing_scope);
4884 output_die (output_string_type_die, type);
4886 else
4888 tree element_type;
4890 element_type = TREE_TYPE (type);
4891 while (TREE_CODE (element_type) == ARRAY_TYPE)
4892 element_type = TREE_TYPE (element_type);
4894 output_type (element_type, containing_scope);
4895 output_die (output_array_type_die, type);
4897 break;
4899 case ENUMERAL_TYPE:
4900 case RECORD_TYPE:
4901 case UNION_TYPE:
4902 case QUAL_UNION_TYPE:
4904 /* For a non-file-scope tagged type, we can always go ahead and
4905 output a Dwarf description of this type right now, even if
4906 the type in question is still incomplete, because if this
4907 local type *was* ever completed anywhere within its scope,
4908 that complete definition would already have been attached to
4909 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4910 node by the time we reach this point. That's true because of the
4911 way the front-end does its processing of file-scope declarations (of
4912 functions and class types) within which other types might be
4913 nested. The C and C++ front-ends always gobble up such "local
4914 scope" things en-mass before they try to output *any* debugging
4915 information for any of the stuff contained inside them and thus,
4916 we get the benefit here of what is (in effect) a pre-resolution
4917 of forward references to tagged types in local scopes.
4919 Note however that for file-scope tagged types we cannot assume
4920 that such pre-resolution of forward references has taken place.
4921 A given file-scope tagged type may appear to be incomplete when
4922 we reach this point, but it may yet be given a full definition
4923 (at file-scope) later on during compilation. In order to avoid
4924 generating a premature (and possibly incorrect) set of Dwarf
4925 DIEs for such (as yet incomplete) file-scope tagged types, we
4926 generate nothing at all for as-yet incomplete file-scope tagged
4927 types here unless we are making our special "finalization" pass
4928 for file-scope things at the very end of compilation. At that
4929 time, we will certainly know as much about each file-scope tagged
4930 type as we are ever going to know, so at that point in time, we
4931 can safely generate correct Dwarf descriptions for these file-
4932 scope tagged types. */
4934 if (!COMPLETE_TYPE_P (type)
4935 && (TYPE_CONTEXT (type) == NULL
4936 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4937 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4938 && !finalizing)
4940 /* We don't need to do this for function-local types. */
4941 if (! decl_function_context (TYPE_STUB_DECL (type)))
4942 add_incomplete_type (type);
4943 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4946 /* Prevent infinite recursion in cases where the type of some
4947 member of this type is expressed in terms of this type itself. */
4949 TREE_ASM_WRITTEN (type) = 1;
4951 /* Output a DIE to represent the tagged type itself. */
4953 switch (TREE_CODE (type))
4955 case ENUMERAL_TYPE:
4956 output_die (output_enumeration_type_die, type);
4957 return; /* a special case -- nothing left to do so just return */
4959 case RECORD_TYPE:
4960 output_die (output_structure_type_die, type);
4961 break;
4963 case UNION_TYPE:
4964 case QUAL_UNION_TYPE:
4965 output_die (output_union_type_die, type);
4966 break;
4968 default:
4969 abort (); /* Should never happen. */
4972 /* If this is not an incomplete type, output descriptions of
4973 each of its members.
4975 Note that as we output the DIEs necessary to represent the
4976 members of this record or union type, we will also be trying
4977 to output DIEs to represent the *types* of those members.
4978 However the `output_type' function (above) will specifically
4979 avoid generating type DIEs for member types *within* the list
4980 of member DIEs for this (containing) type execpt for those
4981 types (of members) which are explicitly marked as also being
4982 members of this (containing) type themselves. The g++ front-
4983 end can force any given type to be treated as a member of some
4984 other (containing) type by setting the TYPE_CONTEXT of the
4985 given (member) type to point to the TREE node representing the
4986 appropriate (containing) type.
4989 if (COMPLETE_TYPE_P (type))
4991 /* First output info about the base classes. */
4992 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4994 register tree bases = TYPE_BINFO_BASETYPES (type);
4995 register int n_bases = TREE_VEC_LENGTH (bases);
4996 register int i;
4998 for (i = 0; i < n_bases; i++)
5000 tree binfo = TREE_VEC_ELT (bases, i);
5001 output_type (BINFO_TYPE (binfo), containing_scope);
5002 output_die (output_inheritance_die, binfo);
5006 ++in_class;
5009 tree normal_member;
5011 /* Now output info about the data members and type members. */
5013 for (normal_member = TYPE_FIELDS (type);
5014 normal_member;
5015 normal_member = TREE_CHAIN (normal_member))
5016 output_decl (normal_member, type);
5020 tree func_member;
5022 /* Now output info about the function members (if any). */
5024 for (func_member = TYPE_METHODS (type);
5025 func_member;
5026 func_member = TREE_CHAIN (func_member))
5028 /* Don't include clones in the member list. */
5029 if (DECL_ABSTRACT_ORIGIN (func_member))
5030 continue;
5032 output_decl (func_member, type);
5036 --in_class;
5038 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
5039 scopes (at least in C++) so we must now output any nested
5040 pending types which are local just to this type. */
5042 output_pending_types_for_scope (type);
5044 end_sibling_chain (); /* Terminate member chain. */
5047 break;
5049 case VOID_TYPE:
5050 case INTEGER_TYPE:
5051 case REAL_TYPE:
5052 case COMPLEX_TYPE:
5053 case BOOLEAN_TYPE:
5054 case CHAR_TYPE:
5055 break; /* No DIEs needed for fundamental types. */
5057 case LANG_TYPE: /* No Dwarf representation currently defined. */
5058 break;
5060 default:
5061 abort ();
5064 TREE_ASM_WRITTEN (type) = 1;
5067 static void
5068 output_tagged_type_instantiation (type)
5069 tree type;
5071 if (type == 0 || type == error_mark_node)
5072 return;
5074 /* We are going to output a DIE to represent the unqualified version of
5075 this type (i.e. without any const or volatile qualifiers) so make
5076 sure that we have the main variant (i.e. the unqualified version) of
5077 this type now. */
5079 if (type != type_main_variant (type))
5080 abort ();
5082 if (!TREE_ASM_WRITTEN (type))
5083 abort ();
5085 switch (TREE_CODE (type))
5087 case ERROR_MARK:
5088 break;
5090 case ENUMERAL_TYPE:
5091 output_die (output_inlined_enumeration_type_die, type);
5092 break;
5094 case RECORD_TYPE:
5095 output_die (output_inlined_structure_type_die, type);
5096 break;
5098 case UNION_TYPE:
5099 case QUAL_UNION_TYPE:
5100 output_die (output_inlined_union_type_die, type);
5101 break;
5103 default:
5104 abort (); /* Should never happen. */
5108 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
5109 the things which are local to the given block. */
5111 static void
5112 output_block (stmt, depth)
5113 tree stmt;
5114 int depth;
5116 int must_output_die = 0;
5117 tree origin;
5118 enum tree_code origin_code;
5120 /* Ignore blocks never really used to make RTL. */
5122 if (! stmt || ! TREE_USED (stmt)
5123 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
5124 return;
5126 /* Determine the "ultimate origin" of this block. This block may be an
5127 inlined instance of an inlined instance of inline function, so we
5128 have to trace all of the way back through the origin chain to find
5129 out what sort of node actually served as the original seed for the
5130 creation of the current block. */
5132 origin = block_ultimate_origin (stmt);
5133 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
5135 /* Determine if we need to output any Dwarf DIEs at all to represent this
5136 block. */
5138 if (origin_code == FUNCTION_DECL)
5139 /* The outer scopes for inlinings *must* always be represented. We
5140 generate TAG_inlined_subroutine DIEs for them. (See below.) */
5141 must_output_die = 1;
5142 else
5144 /* In the case where the current block represents an inlining of the
5145 "body block" of an inline function, we must *NOT* output any DIE
5146 for this block because we have already output a DIE to represent
5147 the whole inlined function scope and the "body block" of any
5148 function doesn't really represent a different scope according to
5149 ANSI C rules. So we check here to make sure that this block does
5150 not represent a "body block inlining" before trying to set the
5151 `must_output_die' flag. */
5153 if (! is_body_block (origin ? origin : stmt))
5155 /* Determine if this block directly contains any "significant"
5156 local declarations which we will need to output DIEs for. */
5158 if (debug_info_level > DINFO_LEVEL_TERSE)
5159 /* We are not in terse mode so *any* local declaration counts
5160 as being a "significant" one. */
5161 must_output_die = (BLOCK_VARS (stmt) != NULL);
5162 else
5164 tree decl;
5166 /* We are in terse mode, so only local (nested) function
5167 definitions count as "significant" local declarations. */
5169 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5170 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
5172 must_output_die = 1;
5173 break;
5179 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
5180 DIE for any block which contains no significant local declarations
5181 at all. Rather, in such cases we just call `output_decls_for_scope'
5182 so that any needed Dwarf info for any sub-blocks will get properly
5183 generated. Note that in terse mode, our definition of what constitutes
5184 a "significant" local declaration gets restricted to include only
5185 inlined function instances and local (nested) function definitions. */
5187 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
5188 /* We don't care about an abstract inlined subroutine. */;
5189 else if (must_output_die)
5191 output_die ((origin_code == FUNCTION_DECL)
5192 ? output_inlined_subroutine_die
5193 : output_lexical_block_die,
5194 stmt);
5195 output_decls_for_scope (stmt, depth);
5196 end_sibling_chain ();
5198 else
5199 output_decls_for_scope (stmt, depth);
5202 /* Output all of the decls declared within a given scope (also called
5203 a `binding contour') and (recursively) all of it's sub-blocks. */
5205 static void
5206 output_decls_for_scope (stmt, depth)
5207 tree stmt;
5208 int depth;
5210 /* Ignore blocks never really used to make RTL. */
5212 if (! stmt || ! TREE_USED (stmt))
5213 return;
5215 /* Output the DIEs to represent all of the data objects, functions,
5216 typedefs, and tagged types declared directly within this block
5217 but not within any nested sub-blocks. */
5220 tree decl;
5222 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5223 output_decl (decl, stmt);
5226 output_pending_types_for_scope (stmt);
5228 /* Output the DIEs to represent all sub-blocks (and the items declared
5229 therein) of this block. */
5232 tree subblocks;
5234 for (subblocks = BLOCK_SUBBLOCKS (stmt);
5235 subblocks;
5236 subblocks = BLOCK_CHAIN (subblocks))
5237 output_block (subblocks, depth + 1);
5241 /* Is this a typedef we can avoid emitting? */
5243 static inline int
5244 is_redundant_typedef (decl)
5245 tree decl;
5247 if (TYPE_DECL_IS_STUB (decl))
5248 return 1;
5249 if (DECL_ARTIFICIAL (decl)
5250 && DECL_CONTEXT (decl)
5251 && is_tagged_type (DECL_CONTEXT (decl))
5252 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
5253 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
5254 /* Also ignore the artificial member typedef for the class name. */
5255 return 1;
5256 return 0;
5259 /* Output Dwarf .debug information for a decl described by DECL. */
5261 static void
5262 output_decl (decl, containing_scope)
5263 tree decl;
5264 tree containing_scope;
5266 /* Make a note of the decl node we are going to be working on. We may
5267 need to give the user the source coordinates of where it appeared in
5268 case we notice (later on) that something about it looks screwy. */
5270 dwarf_last_decl = decl;
5272 if (TREE_CODE (decl) == ERROR_MARK)
5273 return;
5275 /* If a structure is declared within an initialization, e.g. as the
5276 operand of a sizeof, then it will not have a name. We don't want
5277 to output a DIE for it, as the tree nodes are in the temporary obstack */
5279 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5280 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
5281 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
5282 || (TYPE_FIELDS (TREE_TYPE (decl))
5283 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
5284 return;
5286 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5288 if (DECL_IGNORED_P (decl))
5289 return;
5291 switch (TREE_CODE (decl))
5293 case CONST_DECL:
5294 /* The individual enumerators of an enum type get output when we
5295 output the Dwarf representation of the relevant enum type itself. */
5296 break;
5298 case FUNCTION_DECL:
5299 /* If we are in terse mode, don't output any DIEs to represent
5300 mere function declarations. Also, if we are conforming
5301 to the DWARF version 1 specification, don't output DIEs for
5302 mere function declarations. */
5304 if (DECL_INITIAL (decl) == NULL_TREE)
5305 #if (DWARF_VERSION > 1)
5306 if (debug_info_level <= DINFO_LEVEL_TERSE)
5307 #endif
5308 break;
5310 /* Before we describe the FUNCTION_DECL itself, make sure that we
5311 have described its return type. */
5313 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
5316 /* And its containing type. */
5317 register tree origin = decl_class_context (decl);
5318 if (origin)
5319 output_type (origin, containing_scope);
5322 /* If we're emitting an out-of-line copy of an inline function,
5323 set up to refer to the abstract instance emitted from
5324 dwarfout_deferred_inline_function. */
5325 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
5326 && ! (containing_scope && TYPE_P (containing_scope)))
5327 set_decl_origin_self (decl);
5329 /* If the following DIE will represent a function definition for a
5330 function with "extern" linkage, output a special "pubnames" DIE
5331 label just ahead of the actual DIE. A reference to this label
5332 was already generated in the .debug_pubnames section sub-entry
5333 for this function definition. */
5335 if (TREE_PUBLIC (decl))
5337 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5339 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5340 ASM_OUTPUT_LABEL (asm_out_file, label);
5343 /* Now output a DIE to represent the function itself. */
5345 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
5346 ? output_global_subroutine_die
5347 : output_local_subroutine_die,
5348 decl);
5350 /* Now output descriptions of the arguments for this function.
5351 This gets (unnecessarily?) complex because of the fact that
5352 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
5353 cases where there was a trailing `...' at the end of the formal
5354 parameter list. In order to find out if there was a trailing
5355 ellipsis or not, we must instead look at the type associated
5356 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
5357 If the chain of type nodes hanging off of this FUNCTION_TYPE node
5358 ends with a void_type_node then there should *not* be an ellipsis
5359 at the end. */
5361 /* In the case where we are describing a mere function declaration, all
5362 we need to do here (and all we *can* do here) is to describe
5363 the *types* of its formal parameters. */
5365 if (decl != current_function_decl || in_class)
5366 output_formal_types (TREE_TYPE (decl));
5367 else
5369 /* Generate DIEs to represent all known formal parameters */
5371 tree arg_decls = DECL_ARGUMENTS (decl);
5372 tree parm;
5374 /* WARNING! Kludge zone ahead! Here we have a special
5375 hack for svr4 SDB compatibility. Instead of passing the
5376 current FUNCTION_DECL node as the second parameter (i.e.
5377 the `containing_scope' parameter) to `output_decl' (as
5378 we ought to) we instead pass a pointer to our own private
5379 fake_containing_scope node. That node is a RECORD_TYPE
5380 node which NO OTHER TYPE may ever actually be a member of.
5382 This pointer will ultimately get passed into `output_type'
5383 as its `containing_scope' parameter. `Output_type' will
5384 then perform its part in the hack... i.e. it will pend
5385 the type of the formal parameter onto the pending_types
5386 list. Later on, when we are done generating the whole
5387 sequence of formal parameter DIEs for this function
5388 definition, we will un-pend all previously pended types
5389 of formal parameters for this function definition.
5391 This whole kludge prevents any type DIEs from being
5392 mixed in with the formal parameter DIEs. That's good
5393 because svr4 SDB believes that the list of formal
5394 parameter DIEs for a function ends wherever the first
5395 non-formal-parameter DIE appears. Thus, we have to
5396 keep the formal parameter DIEs segregated. They must
5397 all appear (consecutively) at the start of the list of
5398 children for the DIE representing the function definition.
5399 Then (and only then) may we output any additional DIEs
5400 needed to represent the types of these formal parameters.
5404 When generating DIEs, generate the unspecified_parameters
5405 DIE instead if we come across the arg "__builtin_va_alist"
5408 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
5409 if (TREE_CODE (parm) == PARM_DECL)
5411 if (DECL_NAME(parm) &&
5412 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
5413 "__builtin_va_alist") )
5414 output_die (output_unspecified_parameters_die, decl);
5415 else
5416 output_decl (parm, fake_containing_scope);
5420 Now that we have finished generating all of the DIEs to
5421 represent the formal parameters themselves, force out
5422 any DIEs needed to represent their types. We do this
5423 simply by un-pending all previously pended types which
5424 can legitimately go into the chain of children DIEs for
5425 the current FUNCTION_DECL.
5428 output_pending_types_for_scope (decl);
5431 Decide whether we need an unspecified_parameters DIE at the end.
5432 There are 2 more cases to do this for:
5433 1) the ansi ... declaration - this is detectable when the end
5434 of the arg list is not a void_type_node
5435 2) an unprototyped function declaration (not a definition). This
5436 just means that we have no info about the parameters at all.
5440 tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
5442 if (fn_arg_types)
5444 /* this is the prototyped case, check for ... */
5445 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
5446 output_die (output_unspecified_parameters_die, decl);
5448 else
5450 /* this is unprototyped, check for undefined (just declaration) */
5451 if (!DECL_INITIAL (decl))
5452 output_die (output_unspecified_parameters_die, decl);
5456 /* Output Dwarf info for all of the stuff within the body of the
5457 function (if it has one - it may be just a declaration). */
5460 tree outer_scope = DECL_INITIAL (decl);
5462 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
5464 /* Note that here, `outer_scope' is a pointer to the outermost
5465 BLOCK node created to represent a function.
5466 This outermost BLOCK actually represents the outermost
5467 binding contour for the function, i.e. the contour in which
5468 the function's formal parameters and labels get declared.
5470 Curiously, it appears that the front end doesn't actually
5471 put the PARM_DECL nodes for the current function onto the
5472 BLOCK_VARS list for this outer scope. (They are strung
5473 off of the DECL_ARGUMENTS list for the function instead.)
5474 The BLOCK_VARS list for the `outer_scope' does provide us
5475 with a list of the LABEL_DECL nodes for the function however,
5476 and we output DWARF info for those here.
5478 Just within the `outer_scope' there will be a BLOCK node
5479 representing the function's outermost pair of curly braces,
5480 and any blocks used for the base and member initializers of
5481 a C++ constructor function. */
5483 output_decls_for_scope (outer_scope, 0);
5485 /* Finally, force out any pending types which are local to the
5486 outermost block of this function definition. These will
5487 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
5488 node itself. */
5490 output_pending_types_for_scope (decl);
5495 /* Generate a terminator for the list of stuff `owned' by this
5496 function. */
5498 end_sibling_chain ();
5500 break;
5502 case TYPE_DECL:
5503 /* If we are in terse mode, don't generate any DIEs to represent
5504 any actual typedefs. Note that even when we are in terse mode,
5505 we must still output DIEs to represent those tagged types which
5506 are used (directly or indirectly) in the specification of either
5507 a return type or a formal parameter type of some function. */
5509 if (debug_info_level <= DINFO_LEVEL_TERSE)
5510 if (! TYPE_DECL_IS_STUB (decl)
5511 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5512 return;
5514 /* In the special case of a TYPE_DECL node representing
5515 the declaration of some type tag, if the given TYPE_DECL is
5516 marked as having been instantiated from some other (original)
5517 TYPE_DECL node (e.g. one which was generated within the original
5518 definition of an inline function) we have to generate a special
5519 (abbreviated) TAG_structure_type, TAG_union_type, or
5520 TAG_enumeration-type DIE here. */
5522 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5524 output_tagged_type_instantiation (TREE_TYPE (decl));
5525 return;
5528 output_type (TREE_TYPE (decl), containing_scope);
5530 if (! is_redundant_typedef (decl))
5531 /* Output a DIE to represent the typedef itself. */
5532 output_die (output_typedef_die, decl);
5533 break;
5535 case LABEL_DECL:
5536 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5537 output_die (output_label_die, decl);
5538 break;
5540 case VAR_DECL:
5541 /* If we are conforming to the DWARF version 1 specification, don't
5542 generated any DIEs to represent mere external object declarations. */
5544 #if (DWARF_VERSION <= 1)
5545 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5546 break;
5547 #endif
5549 /* If we are in terse mode, don't generate any DIEs to represent
5550 any variable declarations or definitions. */
5552 if (debug_info_level <= DINFO_LEVEL_TERSE)
5553 break;
5555 /* Output any DIEs that are needed to specify the type of this data
5556 object. */
5558 output_type (TREE_TYPE (decl), containing_scope);
5561 /* And its containing type. */
5562 register tree origin = decl_class_context (decl);
5563 if (origin)
5564 output_type (origin, containing_scope);
5567 /* If the following DIE will represent a data object definition for a
5568 data object with "extern" linkage, output a special "pubnames" DIE
5569 label just ahead of the actual DIE. A reference to this label
5570 was already generated in the .debug_pubnames section sub-entry
5571 for this data object definition. */
5573 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5575 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5577 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5578 ASM_OUTPUT_LABEL (asm_out_file, label);
5581 /* Now output the DIE to represent the data object itself. This gets
5582 complicated because of the possibility that the VAR_DECL really
5583 represents an inlined instance of a formal parameter for an inline
5584 function. */
5587 void (*func) PARAMS ((void *));
5588 register tree origin = decl_ultimate_origin (decl);
5590 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5591 func = output_formal_parameter_die;
5592 else
5594 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5595 func = output_global_variable_die;
5596 else
5597 func = output_local_variable_die;
5599 output_die (func, decl);
5601 break;
5603 case FIELD_DECL:
5604 /* Ignore the nameless fields that are used to skip bits. */
5605 if (DECL_NAME (decl) != 0)
5607 output_type (member_declared_type (decl), containing_scope);
5608 output_die (output_member_die, decl);
5610 break;
5612 case PARM_DECL:
5613 /* Force out the type of this formal, if it was not forced out yet.
5614 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5615 It should be able to grok the presence of type DIEs within a list
5616 of TAG_formal_parameter DIEs, but it doesn't. */
5618 output_type (TREE_TYPE (decl), containing_scope);
5619 output_die (output_formal_parameter_die, decl);
5620 break;
5622 case NAMESPACE_DECL:
5623 /* Ignore for now. */
5624 break;
5626 default:
5627 abort ();
5631 /* Output debug information for a function. */
5632 static void
5633 dwarfout_function_decl (decl)
5634 tree decl;
5636 dwarfout_file_scope_decl (decl, 0);
5639 /* Debug information for a global DECL. Called from toplev.c after
5640 compilation proper has finished. */
5641 static void
5642 dwarfout_global_decl (decl)
5643 tree decl;
5645 /* Output DWARF information for file-scope tentative data object
5646 declarations, file-scope (extern) function declarations (which
5647 had no corresponding body) and file-scope tagged type
5648 declarations and definitions which have not yet been forced out. */
5650 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
5651 dwarfout_file_scope_decl (decl, 1);
5654 /* DECL is an inline function, whose body is present, but which is not
5655 being output at this point. (We're putting that off until we need
5656 to do it.) */
5657 static void
5658 dwarfout_deferred_inline_function (decl)
5659 tree decl;
5661 /* Generate the DWARF info for the "abstract" instance of a function
5662 which we may later generate inlined and/or out-of-line instances
5663 of. */
5664 if ((DECL_INLINE (decl) || DECL_ABSTRACT (decl))
5665 && ! DECL_ABSTRACT_ORIGIN (decl))
5667 /* The front-end may not have set CURRENT_FUNCTION_DECL, but the
5668 DWARF code expects it to be set in this case. Intuitively,
5669 DECL is the function we just finished defining, so setting
5670 CURRENT_FUNCTION_DECL is sensible. */
5671 tree saved_cfd = current_function_decl;
5672 int was_abstract = DECL_ABSTRACT (decl);
5673 current_function_decl = decl;
5675 /* Let the DWARF code do its work. */
5676 set_decl_abstract_flags (decl, 1);
5677 dwarfout_file_scope_decl (decl, 0);
5678 if (! was_abstract)
5679 set_decl_abstract_flags (decl, 0);
5681 /* Reset CURRENT_FUNCTION_DECL. */
5682 current_function_decl = saved_cfd;
5686 static void
5687 dwarfout_file_scope_decl (decl, set_finalizing)
5688 tree decl;
5689 int set_finalizing;
5691 if (TREE_CODE (decl) == ERROR_MARK)
5692 return;
5694 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5696 if (DECL_IGNORED_P (decl))
5697 return;
5699 switch (TREE_CODE (decl))
5701 case FUNCTION_DECL:
5703 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5704 a builtin function. Explicit programmer-supplied declarations of
5705 these same functions should NOT be ignored however. */
5707 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5708 return;
5710 /* What we would really like to do here is to filter out all mere
5711 file-scope declarations of file-scope functions which are never
5712 referenced later within this translation unit (and keep all of
5713 ones that *are* referenced later on) but we aren't clairvoyant,
5714 so we have no idea which functions will be referenced in the
5715 future (i.e. later on within the current translation unit).
5716 So here we just ignore all file-scope function declarations
5717 which are not also definitions. If and when the debugger needs
5718 to know something about these functions, it wil have to hunt
5719 around and find the DWARF information associated with the
5720 *definition* of the function.
5722 Note that we can't just check `DECL_EXTERNAL' to find out which
5723 FUNCTION_DECL nodes represent definitions and which ones represent
5724 mere declarations. We have to check `DECL_INITIAL' instead. That's
5725 because the C front-end supports some weird semantics for "extern
5726 inline" function definitions. These can get inlined within the
5727 current translation unit (an thus, we need to generate DWARF info
5728 for their abstract instances so that the DWARF info for the
5729 concrete inlined instances can have something to refer to) but
5730 the compiler never generates any out-of-lines instances of such
5731 things (despite the fact that they *are* definitions). The
5732 important point is that the C front-end marks these "extern inline"
5733 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5734 anyway.
5736 Note that the C++ front-end also plays some similar games for inline
5737 function definitions appearing within include files which also
5738 contain `#pragma interface' pragmas. */
5740 if (DECL_INITIAL (decl) == NULL_TREE)
5741 return;
5743 if (TREE_PUBLIC (decl)
5744 && ! DECL_EXTERNAL (decl)
5745 && ! DECL_ABSTRACT (decl))
5747 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5749 /* Output a .debug_pubnames entry for a public function
5750 defined in this compilation unit. */
5752 fputc ('\n', asm_out_file);
5753 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5754 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5755 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5756 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5757 IDENTIFIER_POINTER (DECL_NAME (decl)));
5758 ASM_OUTPUT_POP_SECTION (asm_out_file);
5761 break;
5763 case VAR_DECL:
5765 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5766 object declaration and if the declaration was never even
5767 referenced from within this entire compilation unit. We
5768 suppress these DIEs in order to save space in the .debug section
5769 (by eliminating entries which are probably useless). Note that
5770 we must not suppress block-local extern declarations (whether
5771 used or not) because that would screw-up the debugger's name
5772 lookup mechanism and cause it to miss things which really ought
5773 to be in scope at a given point. */
5775 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5776 return;
5778 if (TREE_PUBLIC (decl)
5779 && ! DECL_EXTERNAL (decl)
5780 && GET_CODE (DECL_RTL (decl)) == MEM
5781 && ! DECL_ABSTRACT (decl))
5783 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5785 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5787 /* Output a .debug_pubnames entry for a public variable
5788 defined in this compilation unit. */
5790 fputc ('\n', asm_out_file);
5791 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5792 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5793 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5794 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5795 IDENTIFIER_POINTER (DECL_NAME (decl)));
5796 ASM_OUTPUT_POP_SECTION (asm_out_file);
5799 if (DECL_INITIAL (decl) == NULL)
5801 /* Output a .debug_aranges entry for a public variable
5802 which is tentatively defined in this compilation unit. */
5804 fputc ('\n', asm_out_file);
5805 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
5806 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5807 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5808 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5809 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5810 ASM_OUTPUT_POP_SECTION (asm_out_file);
5814 /* If we are in terse mode, don't generate any DIEs to represent
5815 any variable declarations or definitions. */
5817 if (debug_info_level <= DINFO_LEVEL_TERSE)
5818 return;
5820 break;
5822 case TYPE_DECL:
5823 /* Don't bother trying to generate any DIEs to represent any of the
5824 normal built-in types for the language we are compiling, except
5825 in cases where the types in question are *not* DWARF fundamental
5826 types. We make an exception in the case of non-fundamental types
5827 for the sake of objective C (and perhaps C++) because the GNU
5828 front-ends for these languages may in fact create certain "built-in"
5829 types which are (for example) RECORD_TYPEs. In such cases, we
5830 really need to output these (non-fundamental) types because other
5831 DIEs may contain references to them. */
5833 /* Also ignore language dependent types here, because they are probably
5834 also built-in types. If we didn't ignore them, then we would get
5835 references to undefined labels because output_type doesn't support
5836 them. So, for now, we need to ignore them to avoid assembler
5837 errors. */
5839 /* ??? This code is different than the equivalent code in dwarf2out.c.
5840 The dwarf2out.c code is probably more correct. */
5842 if (DECL_SOURCE_LINE (decl) == 0
5843 && (type_is_fundamental (TREE_TYPE (decl))
5844 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5845 return;
5847 /* If we are in terse mode, don't generate any DIEs to represent
5848 any actual typedefs. Note that even when we are in terse mode,
5849 we must still output DIEs to represent those tagged types which
5850 are used (directly or indirectly) in the specification of either
5851 a return type or a formal parameter type of some function. */
5853 if (debug_info_level <= DINFO_LEVEL_TERSE)
5854 if (! TYPE_DECL_IS_STUB (decl)
5855 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5856 return;
5858 break;
5860 default:
5861 return;
5864 fputc ('\n', asm_out_file);
5865 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5866 finalizing = set_finalizing;
5867 output_decl (decl, NULL_TREE);
5869 /* NOTE: The call above to `output_decl' may have caused one or more
5870 file-scope named types (i.e. tagged types) to be placed onto the
5871 pending_types_list. We have to get those types off of that list
5872 at some point, and this is the perfect time to do it. If we didn't
5873 take them off now, they might still be on the list when cc1 finally
5874 exits. That might be OK if it weren't for the fact that when we put
5875 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5876 for these types, and that causes them never to be output unless
5877 `output_pending_types_for_scope' takes them off of the list and un-sets
5878 their TREE_ASM_WRITTEN flags. */
5880 output_pending_types_for_scope (NULL_TREE);
5882 /* The above call should have totally emptied the pending_types_list
5883 if this is not a nested function or class. If this is a nested type,
5884 then the remaining pending_types will be emitted when the containing type
5885 is handled. */
5887 if (! DECL_CONTEXT (decl))
5889 if (pending_types != 0)
5890 abort ();
5893 ASM_OUTPUT_POP_SECTION (asm_out_file);
5895 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5896 current_funcdef_number++;
5899 /* Output a marker (i.e. a label) for the beginning of the generated code
5900 for a lexical block. */
5902 static void
5903 dwarfout_begin_block (line, blocknum)
5904 unsigned int line ATTRIBUTE_UNUSED;
5905 unsigned int blocknum;
5907 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5909 function_section (current_function_decl);
5910 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5911 ASM_OUTPUT_LABEL (asm_out_file, label);
5914 /* Output a marker (i.e. a label) for the end of the generated code
5915 for a lexical block. */
5917 static void
5918 dwarfout_end_block (line, blocknum)
5919 unsigned int line ATTRIBUTE_UNUSED;
5920 unsigned int blocknum;
5922 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5924 function_section (current_function_decl);
5925 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5926 ASM_OUTPUT_LABEL (asm_out_file, label);
5929 /* Output a marker (i.e. a label) for the point in the generated code where
5930 the real body of the function begins (after parameters have been moved
5931 to their home locations). */
5933 static void
5934 dwarfout_end_prologue (line)
5935 unsigned int line ATTRIBUTE_UNUSED;
5937 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5939 if (! use_gnu_debug_info_extensions)
5940 return;
5942 function_section (current_function_decl);
5943 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5944 ASM_OUTPUT_LABEL (asm_out_file, label);
5947 /* Output a marker (i.e. a label) for the point in the generated code where
5948 the real body of the function ends (just before the epilogue code). */
5950 static void
5951 dwarfout_end_function (line)
5952 unsigned int line ATTRIBUTE_UNUSED;
5954 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5956 if (! use_gnu_debug_info_extensions)
5957 return;
5958 function_section (current_function_decl);
5959 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5960 ASM_OUTPUT_LABEL (asm_out_file, label);
5963 /* Output a marker (i.e. a label) for the absolute end of the generated code
5964 for a function definition. This gets called *after* the epilogue code
5965 has been generated. */
5967 static void
5968 dwarfout_end_epilogue ()
5970 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5972 /* Output a label to mark the endpoint of the code generated for this
5973 function. */
5975 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5976 ASM_OUTPUT_LABEL (asm_out_file, label);
5979 static void
5980 shuffle_filename_entry (new_zeroth)
5981 filename_entry *new_zeroth;
5983 filename_entry temp_entry;
5984 filename_entry *limit_p;
5985 filename_entry *move_p;
5987 if (new_zeroth == &filename_table[0])
5988 return;
5990 temp_entry = *new_zeroth;
5992 /* Shift entries up in the table to make room at [0]. */
5994 limit_p = &filename_table[0];
5995 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5996 *move_p = *(move_p-1);
5998 /* Install the found entry at [0]. */
6000 filename_table[0] = temp_entry;
6003 /* Create a new (string) entry for the .debug_sfnames section. */
6005 static void
6006 generate_new_sfname_entry ()
6008 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6010 fputc ('\n', asm_out_file);
6011 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6012 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
6013 ASM_OUTPUT_LABEL (asm_out_file, label);
6014 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
6015 filename_table[0].name
6016 ? filename_table[0].name
6017 : "");
6018 ASM_OUTPUT_POP_SECTION (asm_out_file);
6021 /* Lookup a filename (in the list of filenames that we know about here in
6022 dwarfout.c) and return its "index". The index of each (known) filename
6023 is just a unique number which is associated with only that one filename.
6024 We need such numbers for the sake of generating labels (in the
6025 .debug_sfnames section) and references to those unique labels (in the
6026 .debug_srcinfo and .debug_macinfo sections).
6028 If the filename given as an argument is not found in our current list,
6029 add it to the list and assign it the next available unique index number.
6031 Whatever we do (i.e. whether we find a pre-existing filename or add a new
6032 one), we shuffle the filename found (or added) up to the zeroth entry of
6033 our list of filenames (which is always searched linearly). We do this so
6034 as to optimize the most common case for these filename lookups within
6035 dwarfout.c. The most common case by far is the case where we call
6036 lookup_filename to lookup the very same filename that we did a lookup
6037 on the last time we called lookup_filename. We make sure that this
6038 common case is fast because such cases will constitute 99.9% of the
6039 lookups we ever do (in practice).
6041 If we add a new filename entry to our table, we go ahead and generate
6042 the corresponding entry in the .debug_sfnames section right away.
6043 Doing so allows us to avoid tickling an assembler bug (present in some
6044 m68k assemblers) which yields assembly-time errors in cases where the
6045 difference of two label addresses is taken and where the two labels
6046 are in a section *other* than the one where the difference is being
6047 calculated, and where at least one of the two symbol references is a
6048 forward reference. (This bug could be tickled by our .debug_srcinfo
6049 entries if we don't output their corresponding .debug_sfnames entries
6050 before them.) */
6052 static unsigned
6053 lookup_filename (file_name)
6054 const char *file_name;
6056 filename_entry *search_p;
6057 filename_entry *limit_p = &filename_table[ft_entries];
6059 for (search_p = filename_table; search_p < limit_p; search_p++)
6060 if (!strcmp (file_name, search_p->name))
6062 /* When we get here, we have found the filename that we were
6063 looking for in the filename_table. Now we want to make sure
6064 that it gets moved to the zero'th entry in the table (if it
6065 is not already there) so that subsequent attempts to find the
6066 same filename will find it as quickly as possible. */
6068 shuffle_filename_entry (search_p);
6069 return filename_table[0].number;
6072 /* We come here whenever we have a new filename which is not registered
6073 in the current table. Here we add it to the table. */
6075 /* Prepare to add a new table entry by making sure there is enough space
6076 in the table to do so. If not, expand the current table. */
6078 if (ft_entries == ft_entries_allocated)
6080 ft_entries_allocated += FT_ENTRIES_INCREMENT;
6081 filename_table
6082 = (filename_entry *)
6083 xrealloc (filename_table,
6084 ft_entries_allocated * sizeof (filename_entry));
6087 /* Initially, add the new entry at the end of the filename table. */
6089 filename_table[ft_entries].number = ft_entries;
6090 filename_table[ft_entries].name = xstrdup (file_name);
6092 /* Shuffle the new entry into filename_table[0]. */
6094 shuffle_filename_entry (&filename_table[ft_entries]);
6096 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6097 generate_new_sfname_entry ();
6099 ft_entries++;
6100 return filename_table[0].number;
6103 static void
6104 generate_srcinfo_entry (line_entry_num, files_entry_num)
6105 unsigned line_entry_num;
6106 unsigned files_entry_num;
6108 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6110 fputc ('\n', asm_out_file);
6111 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6112 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
6113 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
6114 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
6115 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
6116 ASM_OUTPUT_POP_SECTION (asm_out_file);
6119 static void
6120 dwarfout_source_line (line, filename)
6121 unsigned int line;
6122 const char *filename;
6124 if (debug_info_level >= DINFO_LEVEL_NORMAL
6125 /* We can't emit line number info for functions in separate sections,
6126 because the assembler can't subtract labels in different sections. */
6127 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
6129 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6130 static unsigned last_line_entry_num = 0;
6131 static unsigned prev_file_entry_num = (unsigned) -1;
6132 unsigned this_file_entry_num;
6134 function_section (current_function_decl);
6135 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
6136 ASM_OUTPUT_LABEL (asm_out_file, label);
6138 fputc ('\n', asm_out_file);
6140 if (use_gnu_debug_info_extensions)
6141 this_file_entry_num = lookup_filename (filename);
6142 else
6143 this_file_entry_num = (unsigned) -1;
6145 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6146 if (this_file_entry_num != prev_file_entry_num)
6148 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
6150 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
6151 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
6155 const char *tail = strrchr (filename, '/');
6157 if (tail != NULL)
6158 filename = tail;
6161 fprintf (asm_out_file, "%s%u\t%s %s:%u\n",
6162 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
6163 filename, line);
6164 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6165 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
6166 ASM_OUTPUT_POP_SECTION (asm_out_file);
6168 if (this_file_entry_num != prev_file_entry_num)
6169 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
6170 prev_file_entry_num = this_file_entry_num;
6174 /* Generate an entry in the .debug_macinfo section. */
6176 static void
6177 generate_macinfo_entry (type_and_offset, string)
6178 const char *type_and_offset;
6179 const char *string;
6181 if (! use_gnu_debug_info_extensions)
6182 return;
6184 fputc ('\n', asm_out_file);
6185 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6186 fprintf (asm_out_file, "%s%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
6187 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
6188 ASM_OUTPUT_POP_SECTION (asm_out_file);
6191 /* Wrapper for toplev.c callback to check debug info level. */
6192 static void
6193 dwarfout_start_source_file_check (line, filename)
6194 unsigned int line;
6195 const char *filename;
6197 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6198 dwarfout_start_source_file (line, filename);
6201 static void
6202 dwarfout_start_source_file (line, filename)
6203 unsigned int line ATTRIBUTE_UNUSED;
6204 const char *filename;
6206 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6207 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
6209 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
6210 sprintf (type_and_offset, "0x%08x+%s-%s",
6211 ((unsigned) MACINFO_start << 24),
6212 /* Hack: skip leading '*' . */
6213 (*label == '*') + label,
6214 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
6215 generate_macinfo_entry (type_and_offset, "");
6218 /* Wrapper for toplev.c callback to check debug info level. */
6219 static void
6220 dwarfout_end_source_file_check (lineno)
6221 unsigned lineno;
6223 if (debug_info_level == DINFO_LEVEL_VERBOSE)
6224 dwarfout_end_source_file (lineno);
6227 static void
6228 dwarfout_end_source_file (lineno)
6229 unsigned lineno;
6231 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6233 sprintf (type_and_offset, "0x%08x+%u",
6234 ((unsigned) MACINFO_resume << 24), lineno);
6235 generate_macinfo_entry (type_and_offset, "");
6238 /* Called from check_newline in c-parse.y. The `buffer' parameter
6239 contains the tail part of the directive line, i.e. the part which
6240 is past the initial whitespace, #, whitespace, directive-name,
6241 whitespace part. */
6243 static void
6244 dwarfout_define (lineno, buffer)
6245 unsigned lineno;
6246 const char *buffer;
6248 static int initialized = 0;
6249 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6251 if (!initialized)
6253 dwarfout_start_source_file (0, primary_filename);
6254 initialized = 1;
6256 sprintf (type_and_offset, "0x%08x+%u",
6257 ((unsigned) MACINFO_define << 24), lineno);
6258 generate_macinfo_entry (type_and_offset, buffer);
6261 /* Called from check_newline in c-parse.y. The `buffer' parameter
6262 contains the tail part of the directive line, i.e. the part which
6263 is past the initial whitespace, #, whitespace, directive-name,
6264 whitespace part. */
6266 static void
6267 dwarfout_undef (lineno, buffer)
6268 unsigned lineno;
6269 const char *buffer;
6271 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
6273 sprintf (type_and_offset, "0x%08x+%u",
6274 ((unsigned) MACINFO_undef << 24), lineno);
6275 generate_macinfo_entry (type_and_offset, buffer);
6278 /* Set up for Dwarf output at the start of compilation. */
6280 static void
6281 dwarfout_init (main_input_filename)
6282 const char *main_input_filename;
6284 /* Remember the name of the primary input file. */
6286 primary_filename = main_input_filename;
6288 /* Allocate the initial hunk of the pending_sibling_stack. */
6290 pending_sibling_stack
6291 = (unsigned *)
6292 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
6293 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
6294 pending_siblings = 1;
6296 /* Allocate the initial hunk of the filename_table. */
6298 filename_table
6299 = (filename_entry *)
6300 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
6301 ft_entries_allocated = FT_ENTRIES_INCREMENT;
6302 ft_entries = 0;
6304 /* Allocate the initial hunk of the pending_types_list. */
6306 pending_types_list
6307 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
6308 pending_types_allocated = PENDING_TYPES_INCREMENT;
6309 pending_types = 0;
6311 /* Create an artificial RECORD_TYPE node which we can use in our hack
6312 to get the DIEs representing types of formal parameters to come out
6313 only *after* the DIEs for the formal parameters themselves. */
6315 fake_containing_scope = make_node (RECORD_TYPE);
6317 /* Output a starting label for the .text section. */
6319 fputc ('\n', asm_out_file);
6320 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6321 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
6322 ASM_OUTPUT_POP_SECTION (asm_out_file);
6324 /* Output a starting label for the .data section. */
6326 fputc ('\n', asm_out_file);
6327 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6328 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
6329 ASM_OUTPUT_POP_SECTION (asm_out_file);
6331 #if 0 /* GNU C doesn't currently use .data1. */
6332 /* Output a starting label for the .data1 section. */
6334 fputc ('\n', asm_out_file);
6335 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6336 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
6337 ASM_OUTPUT_POP_SECTION (asm_out_file);
6338 #endif
6340 /* Output a starting label for the .rodata section. */
6342 fputc ('\n', asm_out_file);
6343 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6344 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
6345 ASM_OUTPUT_POP_SECTION (asm_out_file);
6347 #if 0 /* GNU C doesn't currently use .rodata1. */
6348 /* Output a starting label for the .rodata1 section. */
6350 fputc ('\n', asm_out_file);
6351 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6352 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
6353 ASM_OUTPUT_POP_SECTION (asm_out_file);
6354 #endif
6356 /* Output a starting label for the .bss section. */
6358 fputc ('\n', asm_out_file);
6359 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6360 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
6361 ASM_OUTPUT_POP_SECTION (asm_out_file);
6363 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6365 if (use_gnu_debug_info_extensions)
6367 /* Output a starting label and an initial (compilation directory)
6368 entry for the .debug_sfnames section. The starting label will be
6369 referenced by the initial entry in the .debug_srcinfo section. */
6371 fputc ('\n', asm_out_file);
6372 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6373 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
6375 const char *pwd = getpwd ();
6376 char *dirname;
6378 if (!pwd)
6379 fatal_io_error ("can't get current directory");
6381 dirname = concat (pwd, "/", NULL);
6382 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
6383 free (dirname);
6385 ASM_OUTPUT_POP_SECTION (asm_out_file);
6388 if (debug_info_level >= DINFO_LEVEL_VERBOSE
6389 && use_gnu_debug_info_extensions)
6391 /* Output a starting label for the .debug_macinfo section. This
6392 label will be referenced by the AT_mac_info attribute in the
6393 TAG_compile_unit DIE. */
6395 fputc ('\n', asm_out_file);
6396 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6397 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
6398 ASM_OUTPUT_POP_SECTION (asm_out_file);
6401 /* Generate the initial entry for the .line section. */
6403 fputc ('\n', asm_out_file);
6404 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6405 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
6406 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
6407 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6408 ASM_OUTPUT_POP_SECTION (asm_out_file);
6410 if (use_gnu_debug_info_extensions)
6412 /* Generate the initial entry for the .debug_srcinfo section. */
6414 fputc ('\n', asm_out_file);
6415 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6416 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
6417 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
6418 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
6419 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6420 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
6421 #ifdef DWARF_TIMESTAMPS
6422 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
6423 #else
6424 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6425 #endif
6426 ASM_OUTPUT_POP_SECTION (asm_out_file);
6429 /* Generate the initial entry for the .debug_pubnames section. */
6431 fputc ('\n', asm_out_file);
6432 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6433 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6434 ASM_OUTPUT_POP_SECTION (asm_out_file);
6436 /* Generate the initial entry for the .debug_aranges section. */
6438 fputc ('\n', asm_out_file);
6439 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6440 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6441 DEBUG_ARANGES_END_LABEL,
6442 DEBUG_ARANGES_BEGIN_LABEL);
6443 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_BEGIN_LABEL);
6444 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 1);
6445 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6446 ASM_OUTPUT_POP_SECTION (asm_out_file);
6449 /* Setup first DIE number == 1. */
6450 NEXT_DIE_NUM = next_unused_dienum++;
6452 /* Generate the initial DIE for the .debug section. Note that the
6453 (string) value given in the AT_name attribute of the TAG_compile_unit
6454 DIE will (typically) be a relative pathname and that this pathname
6455 should be taken as being relative to the directory from which the
6456 compiler was invoked when the given (base) source file was compiled. */
6458 fputc ('\n', asm_out_file);
6459 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6460 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
6461 output_die (output_compile_unit_die, (PTR) main_input_filename);
6462 ASM_OUTPUT_POP_SECTION (asm_out_file);
6464 fputc ('\n', asm_out_file);
6467 /* Output stuff that dwarf requires at the end of every file. */
6469 static void
6470 dwarfout_finish (main_input_filename)
6471 const char *main_input_filename ATTRIBUTE_UNUSED;
6473 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6475 fputc ('\n', asm_out_file);
6476 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6477 retry_incomplete_types ();
6478 fputc ('\n', asm_out_file);
6480 /* Mark the end of the chain of siblings which represent all file-scope
6481 declarations in this compilation unit. */
6483 /* The (null) DIE which represents the terminator for the (sibling linked)
6484 list of file-scope items is *special*. Normally, we would just call
6485 end_sibling_chain at this point in order to output a word with the
6486 value `4' and that word would act as the terminator for the list of
6487 DIEs describing file-scope items. Unfortunately, if we were to simply
6488 do that, the label that would follow this DIE in the .debug section
6489 (i.e. `..D2') would *not* be properly aligned (as it must be on some
6490 machines) to a 4 byte boundary.
6492 In order to force the label `..D2' to get aligned to a 4 byte boundary,
6493 the trick used is to insert extra (otherwise useless) padding bytes
6494 into the (null) DIE that we know must precede the ..D2 label in the
6495 .debug section. The amount of padding required can be anywhere between
6496 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
6497 with the padding) would normally contain the value 4, but now it will
6498 also have to include the padding bytes, so it will instead have some
6499 value in the range 4..7.
6501 Fortunately, the rules of Dwarf say that any DIE whose length word
6502 contains *any* value less than 8 should be treated as a null DIE, so
6503 this trick works out nicely. Clever, eh? Don't give me any credit
6504 (or blame). I didn't think of this scheme. I just conformed to it.
6507 output_die (output_padded_null_die, (void *) 0);
6508 dienum_pop ();
6510 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
6511 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
6512 ASM_OUTPUT_POP_SECTION (asm_out_file);
6514 /* Output a terminator label for the .text section. */
6516 fputc ('\n', asm_out_file);
6517 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6518 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
6519 ASM_OUTPUT_POP_SECTION (asm_out_file);
6521 /* Output a terminator label for the .data section. */
6523 fputc ('\n', asm_out_file);
6524 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6525 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
6526 ASM_OUTPUT_POP_SECTION (asm_out_file);
6528 #if 0 /* GNU C doesn't currently use .data1. */
6529 /* Output a terminator label for the .data1 section. */
6531 fputc ('\n', asm_out_file);
6532 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6533 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
6534 ASM_OUTPUT_POP_SECTION (asm_out_file);
6535 #endif
6537 /* Output a terminator label for the .rodata section. */
6539 fputc ('\n', asm_out_file);
6540 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6541 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
6542 ASM_OUTPUT_POP_SECTION (asm_out_file);
6544 #if 0 /* GNU C doesn't currently use .rodata1. */
6545 /* Output a terminator label for the .rodata1 section. */
6547 fputc ('\n', asm_out_file);
6548 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6549 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
6550 ASM_OUTPUT_POP_SECTION (asm_out_file);
6551 #endif
6553 /* Output a terminator label for the .bss section. */
6555 fputc ('\n', asm_out_file);
6556 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6557 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
6558 ASM_OUTPUT_POP_SECTION (asm_out_file);
6560 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6562 /* Output a terminating entry for the .line section. */
6564 fputc ('\n', asm_out_file);
6565 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6566 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
6567 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6568 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6569 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6570 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
6571 ASM_OUTPUT_POP_SECTION (asm_out_file);
6573 if (use_gnu_debug_info_extensions)
6575 /* Output a terminating entry for the .debug_srcinfo section. */
6577 fputc ('\n', asm_out_file);
6578 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6579 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6580 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6581 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6582 ASM_OUTPUT_POP_SECTION (asm_out_file);
6585 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6587 /* Output terminating entries for the .debug_macinfo section. */
6589 dwarfout_end_source_file (0);
6591 fputc ('\n', asm_out_file);
6592 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6593 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6594 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6595 ASM_OUTPUT_POP_SECTION (asm_out_file);
6598 /* Generate the terminating entry for the .debug_pubnames section. */
6600 fputc ('\n', asm_out_file);
6601 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6602 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6603 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6604 ASM_OUTPUT_POP_SECTION (asm_out_file);
6606 /* Generate the terminating entries for the .debug_aranges section.
6608 Note that we want to do this only *after* we have output the end
6609 labels (for the various program sections) which we are going to
6610 refer to here. This allows us to work around a bug in the m68k
6611 svr4 assembler. That assembler gives bogus assembly-time errors
6612 if (within any given section) you try to take the difference of
6613 two relocatable symbols, both of which are located within some
6614 other section, and if one (or both?) of the symbols involved is
6615 being forward-referenced. By generating the .debug_aranges
6616 entries at this late point in the assembly output, we skirt the
6617 issue simply by avoiding forward-references.
6620 fputc ('\n', asm_out_file);
6621 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6623 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6624 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6626 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6627 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6629 #if 0 /* GNU C doesn't currently use .data1. */
6630 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6631 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6632 DATA1_BEGIN_LABEL);
6633 #endif
6635 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6636 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6637 RODATA_BEGIN_LABEL);
6639 #if 0 /* GNU C doesn't currently use .rodata1. */
6640 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6641 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6642 RODATA1_BEGIN_LABEL);
6643 #endif
6645 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6646 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6648 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6649 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6651 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_END_LABEL);
6652 ASM_OUTPUT_POP_SECTION (asm_out_file);
6655 /* There should not be any pending types left at the end. We need
6656 this now because it may not have been checked on the last call to
6657 dwarfout_file_scope_decl. */
6658 if (pending_types != 0)
6659 abort ();
6662 #endif /* DWARF_DEBUGGING_INFO */