OSDN Git Service

* function.h (struct function) [funcdef_no]: Rename profile_label_no.
[pf3gnuchains/gcc-fork.git] / gcc / dwarfout.c
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.
5
6 This file is part of GCC.
7
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.
12
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.
17
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.  */
22
23 /*
24
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  ------------------------------------------------------------
29
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).
33
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.
38
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
41
42    http://www.eagercon.com/dwarf/dwarf2std.htm
43
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).
49
50  DWARF 1 generation for the GNU g++ compiler is implemented, but limited.
51  C++ users should definitely use DWARF 2 instead.
52
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.)
56
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).
66
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!)
71
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).
75
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.
81
82      ** IMPORTANT NOTE **    ** IMPORTANT NOTE **    ** IMPORTANT NOTE **
83
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.
95
96  ---------
97
98  (Footnote: Within this file, the term `Debugging Information Entry' will
99  be abbreviated as `DIE'.)
100
101
102  Release Notes  (aka known bugs)
103  -------------------------------
104
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.
113
114  -------------------------------
115
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).
123
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.
128
129  -------------------------------
130
131  It is believed at this time that old bugs relating to the AT_bit_offset
132  values for bit-fields have been fixed.
133
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.
138
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.)
142
143  --------------------------------
144
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.)
147
148  --------------------------------
149
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).
157
158  --------------------------------
159
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.
163
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".
177
178  Unfortunately, the GNU DWARF implementation is currently incapable of making
179  such distinctions.
180
181  --------------------------------
182
183
184  Known Interoperability Problems
185  -------------------------------
186
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.
193
194  --------------------------------
195
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.
205
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.)
209
210  --------------------------------
211
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.
218
219  --------------------------------
220
221
222  General GNU DWARF extensions
223  ----------------------------
224
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.)
231
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.
242
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).
248
249  For each LEC there is one entry in the .debug_srcinfo section.
250
251  Each normal entry in the .debug_srcinfo section consists of two 4-byte
252  words of data as follows:
253
254          (1)    The starting address (relative to the entire .line section)
255                  of the first .line entry in the relevant LEC.
256
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.)
262
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.
266
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.
275
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.
278
279
280          .line section     .debug_srcinfo section     .debug_sfnames section
281          ----------------------------------------------------------------
282
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                         * -----------------------------------
302          LE
303          LE
304          LE
305
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).
309
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.
317
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:
321
322          (1)    The starting address (relative to the entire .line section)
323                  of the .line section for this compilation unit.
324
325          (2)    The starting address (relative to the entire .debug_sfnames
326                  section) of the .debug_sfnames section for this compilation
327                  unit.
328
329          (3)    The starting address (in the execution virtual address space)
330                  of the .text section for this compilation unit.
331
332          (4)    The ending address plus one (in the execution virtual address
333                  space) of the .text section for this compilation unit.
334
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).
348
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.
357
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.
365
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:
369
370          (1)    The offset, measured from the start of the .line section to
371                  the beginning of the terminating entry for the .line section.
372
373          (2)    A word containing the value 0xffffffff.
374
375  --------------------------------
376
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.
380
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.
388
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.)
393
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:
397
398          (1)    A special "type" byte.
399
400          (2)    A 3-byte line-number/filename-offset field.
401
402          (3)    A NUL terminated string.
403
404  The interpretation of the second and third parts is dependent upon the
405  value of the leading (type) byte.
406
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:
410
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.
415
416  (Note that the MACINFO_... codes mentioned here are simply symbolic names
417  for constants which are defined in the GNU dwarf.h file.)
418
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.
428
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.
435
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.
441
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.
445
446  --------------------------------
447
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).
451
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.
467
468  --------------------------------
469
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.
475
476  --------------------------------
477
478
479  GNU DWARF Representation of GNU C Extensions to ANSI C
480  ------------------------------------------------------
481
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.
489
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.
496
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.
501
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.)
507
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.
511
512  --------------------------------
513
514
515  Future Directions
516  -----------------
517
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.)
527
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.
533
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.
536
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.
550
551  In particular, possible link-time transformations of DWARF code which could
552  provide significant benefits include (but are not limited to):
553
554          Commonization of duplicate DIEs obtained from multiple input
555          (object) files.
556
557          Cross-compilation type checking based upon DWARF type information
558          for objects and functions.
559
560          Other possible `compacting' transformations designed to save disk
561          space and to reduce linker & debugger I/O activity.
562
563 */
564
565 #include "config.h"
566
567 #ifdef DWARF_DEBUGGING_INFO
568 #include "system.h"
569 #include "dwarf.h"
570 #include "tree.h"
571 #include "flags.h"
572 #include "rtl.h"
573 #include "hard-reg-set.h"
574 #include "insn-config.h"
575 #include "reload.h"
576 #include "output.h"
577 #include "dwarf2asm.h"
578 #include "toplev.h"
579 #include "tm_p.h"
580 #include "debug.h"
581 #include "langhooks.h"
582
583 /* NOTE: In the comments in this file, many references are made to
584    so called "Debugging Information Entries".  For the sake of brevity,
585    this term is abbreviated to `DIE' throughout the remainder of this
586    file.  */
587
588 /* Note that the implementation of C++ support herein is (as yet) unfinished.
589    If you want to try to complete it, more power to you.  */
590
591 /* How to start an assembler comment.  */
592 #ifndef ASM_COMMENT_START
593 #define ASM_COMMENT_START ";#"
594 #endif
595
596 /* How to print out a register name.  */
597 #ifndef PRINT_REG
598 #define PRINT_REG(RTX, CODE, FILE) \
599   fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
600 #endif
601
602 /* Define a macro which returns non-zero for any tagged type which is
603    used (directly or indirectly) in the specification of either some
604    function's return type or some formal parameter of some function.
605    We use this macro when we are operating in "terse" mode to help us
606    know what tagged types have to be represented in Dwarf (even in
607    terse mode) and which ones don't.
608
609    A flag bit with this meaning really should be a part of the normal
610    GCC ..._TYPE nodes, but at the moment, there is no such bit defined
611    for these nodes.  For now, we have to just fake it.  It it safe for
612    us to simply return zero for all complete tagged types (which will
613    get forced out anyway if they were used in the specification of some
614    formal or return type) and non-zero for all incomplete tagged types.
615 */
616
617 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
618
619 /* Define a macro which returns non-zero for a TYPE_DECL which was
620    implicitly generated for a tagged type.
621
622    Note that unlike the gcc front end (which generates a NULL named
623    TYPE_DECL node for each complete tagged type, each array type, and
624    each function type node created) the g++ front end generates a
625    _named_ TYPE_DECL node for each tagged type node created.
626    These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
627    generate a DW_TAG_typedef DIE for them.  */
628 #define TYPE_DECL_IS_STUB(decl)                         \
629   (DECL_NAME (decl) == NULL                             \
630    || (DECL_ARTIFICIAL (decl)                           \
631        && is_tagged_type (TREE_TYPE (decl))             \
632        && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
633
634 /* Maximum size (in bytes) of an artificially generated label.  */
635
636 #define MAX_ARTIFICIAL_LABEL_BYTES      30
637 \f
638 /* Structure to keep track of source filenames.  */
639
640 struct filename_entry {
641   unsigned      number;
642   const char *  name;
643 };
644
645 typedef struct filename_entry filename_entry;
646
647 /* Pointer to an array of elements, each one having the structure above.  */
648
649 static filename_entry *filename_table;
650
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.  */
654
655 static unsigned ft_entries_allocated;
656
657 /* Number of entries in the filename_table which are actually in use.  */
658
659 static unsigned ft_entries;
660
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.    */
664
665 #define FT_ENTRIES_INCREMENT 64
666
667 /* Local pointer to the name of the main input file.  Initialized in
668    dwarfout_init.  */
669
670 static const char *primary_filename;
671
672 /* Counter to generate unique names for DIEs.  */
673
674 static unsigned next_unused_dienum = 1;
675
676 /* Number of the DIE which is currently being generated.  */
677
678 static unsigned current_dienum;
679
680 /* Number to use for the special "pubname" label on the next DIE which
681    represents a function or data object defined in this compilation
682    unit which has "extern" linkage.  */
683
684 static int next_pubname_number = 0;
685
686 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
687
688 /* Pointer to a dynamically allocated list of pre-reserved and still
689    pending sibling DIE numbers.  Note that this list will grow as needed.  */
690
691 static unsigned *pending_sibling_stack;
692
693 /* Counter to keep track of the number of pre-reserved and still pending
694    sibling DIE numbers.  */
695
696 static unsigned pending_siblings;
697
698 /* The currently allocated size of the above list (expressed in number of
699    list elements).  */
700
701 static unsigned pending_siblings_allocated;
702
703 /* Size (in elements) of increments by which we may expand the pending
704    sibling stack.  Actually, a single hunk of space of this size should
705    be enough for most typical programs.  */
706
707 #define PENDING_SIBLINGS_INCREMENT 64
708
709 /* Non-zero if we are performing our file-scope finalization pass and if
710    we should force out Dwarf descriptions of any and all file-scope
711    tagged types which are still incomplete types.  */
712
713 static int finalizing = 0;
714
715 /* A pointer to the base of a list of pending types which we haven't
716    generated DIEs for yet, but which we will have to come back to
717    later on.  */
718
719 static tree *pending_types_list;
720
721 /* Number of elements currently allocated for the pending_types_list.  */
722
723 static unsigned pending_types_allocated;
724
725 /* Number of elements of pending_types_list currently in use.  */
726
727 static unsigned pending_types;
728
729 /* Size (in elements) of increments by which we may expand the pending
730    types list.  Actually, a single hunk of space of this size should
731    be enough for most typical programs.  */
732
733 #define PENDING_TYPES_INCREMENT 64
734
735 /* A pointer to the base of a list of incomplete types which might be
736    completed at some later time.  */
737
738 static tree *incomplete_types_list;
739
740 /* Number of elements currently allocated for the incomplete_types_list.  */
741 static unsigned incomplete_types_allocated;
742
743 /* Number of elements of incomplete_types_list currently in use.  */
744 static unsigned incomplete_types;
745
746 /* Size (in elements) of increments by which we may expand the incomplete
747    types list.  Actually, a single hunk of space of this size should
748    be enough for most typical programs.  */
749 #define INCOMPLETE_TYPES_INCREMENT 64
750
751 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
752    This is used in a hack to help us get the DIEs describing types of
753    formal parameters to come *after* all of the DIEs describing the formal
754    parameters themselves.  That's necessary in order to be compatible
755    with what the brain-damaged svr4 SDB debugger requires.  */
756
757 static tree fake_containing_scope;
758
759 /* A pointer to the ..._DECL node which we have most recently been working
760    on.  We keep this around just in case something about it looks screwy
761    and we want to tell the user what the source coordinates for the actual
762    declaration are.  */
763
764 static tree dwarf_last_decl;
765
766 /* A flag indicating that we are emitting the member declarations of a
767    class, so member functions and variables should not be entirely emitted.
768    This is a kludge to avoid passing a second argument to output_*_die.  */
769
770 static int in_class;
771
772 /* Forward declarations for functions defined in this file.  */
773
774 static void dwarfout_init               PARAMS ((const char *));
775 static void dwarfout_finish             PARAMS ((const char *));
776 static void dwarfout_define             PARAMS ((unsigned int, const char *));
777 static void dwarfout_undef              PARAMS ((unsigned int, const char *));
778 static void dwarfout_start_source_file  PARAMS ((unsigned, const char *));
779 static void dwarfout_start_source_file_check PARAMS ((unsigned, const char *));
780 static void dwarfout_end_source_file    PARAMS ((unsigned));
781 static void dwarfout_end_source_file_check PARAMS ((unsigned));
782 static void dwarfout_begin_block        PARAMS ((unsigned, unsigned));
783 static void dwarfout_end_block          PARAMS ((unsigned, unsigned));
784 static void dwarfout_end_epilogue       PARAMS ((void));
785 static void dwarfout_source_line        PARAMS ((unsigned int, const char *));
786 static void dwarfout_end_prologue       PARAMS ((unsigned int));
787 static void dwarfout_end_function       PARAMS ((unsigned int));
788 static void dwarfout_function_decl      PARAMS ((tree));
789 static void dwarfout_global_decl        PARAMS ((tree));
790 static void dwarfout_deferred_inline_function   PARAMS ((tree));
791 static void dwarfout_file_scope_decl    PARAMS ((tree , int));
792 static const char *dwarf_tag_name       PARAMS ((unsigned));
793 static const char *dwarf_attr_name      PARAMS ((unsigned));
794 static const char *dwarf_stack_op_name  PARAMS ((unsigned));
795 static const char *dwarf_typemod_name   PARAMS ((unsigned));
796 static const char *dwarf_fmt_byte_name  PARAMS ((unsigned));
797 static const char *dwarf_fund_type_name PARAMS ((unsigned));
798 static tree decl_ultimate_origin        PARAMS ((tree));
799 static tree block_ultimate_origin       PARAMS ((tree));
800 static tree decl_class_context          PARAMS ((tree));
801 #if 0
802 static void output_unsigned_leb128      PARAMS ((unsigned long));
803 static void output_signed_leb128        PARAMS ((long));
804 #endif
805 static int fundamental_type_code        PARAMS ((tree));
806 static tree root_type_1                 PARAMS ((tree, int));
807 static tree root_type                   PARAMS ((tree));
808 static void write_modifier_bytes_1      PARAMS ((tree, int, int, int));
809 static void write_modifier_bytes        PARAMS ((tree, int, int));
810 static inline int type_is_fundamental   PARAMS ((tree));
811 static void equate_decl_number_to_die_number PARAMS ((tree));
812 static inline void equate_type_number_to_die_number PARAMS ((tree));
813 static void output_reg_number           PARAMS ((rtx));
814 static void output_mem_loc_descriptor   PARAMS ((rtx));
815 static void output_loc_descriptor       PARAMS ((rtx));
816 static void output_bound_representation PARAMS ((tree, unsigned, int));
817 static void output_enumeral_list        PARAMS ((tree));
818 static inline HOST_WIDE_INT ceiling     PARAMS ((HOST_WIDE_INT, unsigned int));
819 static inline tree field_type           PARAMS ((tree));
820 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
821 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits  PARAMS ((tree));
822 static HOST_WIDE_INT field_byte_offset  PARAMS ((tree));
823 static inline void sibling_attribute    PARAMS ((void));
824 static void location_attribute          PARAMS ((rtx));
825 static void data_member_location_attribute PARAMS ((tree));
826 static void const_value_attribute       PARAMS ((rtx));
827 static void location_or_const_value_attribute PARAMS ((tree));
828 static inline void name_attribute       PARAMS ((const char *));
829 static inline void fund_type_attribute  PARAMS ((unsigned));
830 static void mod_fund_type_attribute     PARAMS ((tree, int, int));
831 static inline void user_def_type_attribute PARAMS ((tree));
832 static void mod_u_d_type_attribute      PARAMS ((tree, int, int));
833 #ifdef USE_ORDERING_ATTRIBUTE
834 static inline void ordering_attribute   PARAMS ((unsigned));
835 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
836 static void subscript_data_attribute    PARAMS ((tree));
837 static void byte_size_attribute         PARAMS ((tree));
838 static inline void bit_offset_attribute PARAMS ((tree));
839 static inline void bit_size_attribute   PARAMS ((tree));
840 static inline void element_list_attribute PARAMS ((tree));
841 static inline void stmt_list_attribute  PARAMS ((const char *));
842 static inline void low_pc_attribute     PARAMS ((const char *));
843 static inline void high_pc_attribute    PARAMS ((const char *));
844 static inline void body_begin_attribute PARAMS ((const char *));
845 static inline void body_end_attribute   PARAMS ((const char *));
846 static inline void language_attribute   PARAMS ((unsigned));
847 static inline void member_attribute     PARAMS ((tree));
848 #if 0
849 static inline void string_length_attribute PARAMS ((tree));
850 #endif
851 static inline void comp_dir_attribute   PARAMS ((const char *));
852 static inline void sf_names_attribute   PARAMS ((const char *));
853 static inline void src_info_attribute   PARAMS ((const char *));
854 static inline void mac_info_attribute   PARAMS ((const char *));
855 static inline void prototyped_attribute PARAMS ((tree));
856 static inline void producer_attribute   PARAMS ((const char *));
857 static inline void inline_attribute     PARAMS ((tree));
858 static inline void containing_type_attribute PARAMS ((tree));
859 static inline void abstract_origin_attribute PARAMS ((tree));
860 #ifdef DWARF_DECL_COORDINATES
861 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
862 #endif /* defined(DWARF_DECL_COORDINATES) */
863 static inline void pure_or_virtual_attribute PARAMS ((tree));
864 static void name_and_src_coords_attributes PARAMS ((tree));
865 static void type_attribute              PARAMS ((tree, int, int));
866 static const char *type_tag             PARAMS ((tree));
867 static inline void dienum_push          PARAMS ((void));
868 static inline void dienum_pop           PARAMS ((void));
869 static inline tree member_declared_type PARAMS ((tree));
870 static const char *function_start_label PARAMS ((tree));
871 static void output_array_type_die       PARAMS ((void *));
872 static void output_set_type_die         PARAMS ((void *));
873 #if 0
874 static void output_entry_point_die      PARAMS ((void *));
875 #endif
876 static void output_inlined_enumeration_type_die PARAMS ((void *));
877 static void output_inlined_structure_type_die PARAMS ((void *));
878 static void output_inlined_union_type_die PARAMS ((void *));
879 static void output_enumeration_type_die PARAMS ((void *));
880 static void output_formal_parameter_die PARAMS ((void *));
881 static void output_global_subroutine_die PARAMS ((void *));
882 static void output_global_variable_die  PARAMS ((void *));
883 static void output_label_die            PARAMS ((void *));
884 static void output_lexical_block_die    PARAMS ((void *));
885 static void output_inlined_subroutine_die PARAMS ((void *));
886 static void output_local_variable_die   PARAMS ((void *));
887 static void output_member_die           PARAMS ((void *));
888 #if 0
889 static void output_pointer_type_die     PARAMS ((void *));
890 static void output_reference_type_die   PARAMS ((void *));
891 #endif
892 static void output_ptr_to_mbr_type_die  PARAMS ((void *));
893 static void output_compile_unit_die     PARAMS ((void *));
894 static void output_string_type_die      PARAMS ((void *));
895 static void output_inheritance_die      PARAMS ((void *));
896 static void output_structure_type_die   PARAMS ((void *));
897 static void output_local_subroutine_die PARAMS ((void *));
898 static void output_subroutine_type_die  PARAMS ((void *));
899 static void output_typedef_die          PARAMS ((void *));
900 static void output_union_type_die       PARAMS ((void *));
901 static void output_unspecified_parameters_die PARAMS ((void *));
902 static void output_padded_null_die      PARAMS ((void *));
903 static void output_die                  PARAMS ((void (*)(void *), void *));
904 static void end_sibling_chain           PARAMS ((void));
905 static void output_formal_types         PARAMS ((tree));
906 static void pend_type                   PARAMS ((tree));
907 static int type_ok_for_scope            PARAMS ((tree, tree));
908 static void output_pending_types_for_scope PARAMS ((tree));
909 static void output_type                 PARAMS ((tree, tree));
910 static void output_tagged_type_instantiation PARAMS ((tree));
911 static void output_block                PARAMS ((tree, int));
912 static void output_decls_for_scope      PARAMS ((tree, int));
913 static void output_decl                 PARAMS ((tree, tree));
914 static void shuffle_filename_entry      PARAMS ((filename_entry *));
915 static void generate_new_sfname_entry   PARAMS ((void));
916 static unsigned lookup_filename         PARAMS ((const char *));
917 static void generate_srcinfo_entry      PARAMS ((unsigned, unsigned));
918 static void generate_macinfo_entry      PARAMS ((unsigned int, rtx,
919                                                  const char *));
920 static int is_pseudo_reg                PARAMS ((rtx));
921 static tree type_main_variant           PARAMS ((tree));
922 static int is_tagged_type               PARAMS ((tree));
923 static int is_redundant_typedef         PARAMS ((tree));
924 static void add_incomplete_type         PARAMS ((tree));
925 static void retry_incomplete_types      PARAMS ((void));
926 \f
927 /* Definitions of defaults for assembler-dependent names of various
928    pseudo-ops and section names.
929
930    Theses may be overridden in your tm.h file (if necessary) for your
931    particular assembler.  The default values provided here correspond to
932    what is expected by "standard" AT&T System V.4 assemblers.  */
933
934 #ifndef FILE_ASM_OP
935 #define FILE_ASM_OP             "\t.file\t"
936 #endif
937 #ifndef VERSION_ASM_OP
938 #define VERSION_ASM_OP          "\t.version\t"
939 #endif
940 #ifndef SET_ASM_OP
941 #define SET_ASM_OP              "\t.set\t"
942 #endif
943
944 /* Pseudo-ops for pushing the current section onto the section stack (and
945    simultaneously changing to a new section) and for poping back to the
946    section we were in immediately before this one.  Note that most svr4
947    assemblers only maintain a one level stack... you can push all the
948    sections you want, but you can only pop out one level.  (The sparc
949    svr4 assembler is an exception to this general rule.)  That's
950    OK because we only use at most one level of the section stack herein.  */
951
952 #ifndef PUSHSECTION_ASM_OP
953 #define PUSHSECTION_ASM_OP      "\t.section\t"
954 #endif
955 #ifndef POPSECTION_ASM_OP
956 #define POPSECTION_ASM_OP       "\t.previous"
957 #endif
958
959 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
960    to print the PUSHSECTION_ASM_OP and the section name.  The default here
961    works for almost all svr4 assemblers, except for the sparc, where the
962    section name must be enclosed in double quotes.  (See sparcv4.h.)  */
963
964 #ifndef PUSHSECTION_FORMAT
965 #define PUSHSECTION_FORMAT      "%s%s\n"
966 #endif
967
968 #ifndef DEBUG_SECTION
969 #define DEBUG_SECTION           ".debug"
970 #endif
971 #ifndef LINE_SECTION
972 #define LINE_SECTION            ".line"
973 #endif
974 #ifndef DEBUG_SFNAMES_SECTION
975 #define DEBUG_SFNAMES_SECTION   ".debug_sfnames"
976 #endif
977 #ifndef DEBUG_SRCINFO_SECTION
978 #define DEBUG_SRCINFO_SECTION   ".debug_srcinfo"
979 #endif
980 #ifndef DEBUG_MACINFO_SECTION
981 #define DEBUG_MACINFO_SECTION   ".debug_macinfo"
982 #endif
983 #ifndef DEBUG_PUBNAMES_SECTION
984 #define DEBUG_PUBNAMES_SECTION  ".debug_pubnames"
985 #endif
986 #ifndef DEBUG_ARANGES_SECTION
987 #define DEBUG_ARANGES_SECTION   ".debug_aranges"
988 #endif
989 #ifndef TEXT_SECTION_NAME
990 #define TEXT_SECTION_NAME       ".text"
991 #endif
992 #ifndef DATA_SECTION_NAME
993 #define DATA_SECTION_NAME       ".data"
994 #endif
995 #ifndef DATA1_SECTION_NAME
996 #define DATA1_SECTION_NAME      ".data1"
997 #endif
998 #ifndef RODATA_SECTION_NAME
999 #define RODATA_SECTION_NAME     ".rodata"
1000 #endif
1001 #ifndef RODATA1_SECTION_NAME
1002 #define RODATA1_SECTION_NAME    ".rodata1"
1003 #endif
1004 #ifndef BSS_SECTION_NAME
1005 #define BSS_SECTION_NAME        ".bss"
1006 #endif
1007 \f
1008 /* Definitions of defaults for formats and names of various special
1009    (artificial) labels which may be generated within this file (when
1010    the -g options is used and DWARF_DEBUGGING_INFO is in effect.
1011
1012    If necessary, these may be overridden from within your tm.h file,
1013    but typically, you should never need to override these.
1014
1015    These labels have been hacked (temporarily) so that they all begin with
1016    a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
1017    stock m88k/svr4 assembler, both of which need to see .L at the start of
1018    a label in order to prevent that label from going into the linker symbol
1019    table).  When I get time, I'll have to fix this the right way so that we
1020    will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
1021    but that will require a rather massive set of changes.  For the moment,
1022    the following definitions out to produce the right results for all svr4
1023    and svr3 assemblers. -- rfg
1024 */
1025
1026 #ifndef TEXT_BEGIN_LABEL
1027 #define TEXT_BEGIN_LABEL        "*.L_text_b"
1028 #endif
1029 #ifndef TEXT_END_LABEL
1030 #define TEXT_END_LABEL          "*.L_text_e"
1031 #endif
1032
1033 #ifndef DATA_BEGIN_LABEL
1034 #define DATA_BEGIN_LABEL        "*.L_data_b"
1035 #endif
1036 #ifndef DATA_END_LABEL
1037 #define DATA_END_LABEL          "*.L_data_e"
1038 #endif
1039
1040 #ifndef DATA1_BEGIN_LABEL
1041 #define DATA1_BEGIN_LABEL       "*.L_data1_b"
1042 #endif
1043 #ifndef DATA1_END_LABEL
1044 #define DATA1_END_LABEL         "*.L_data1_e"
1045 #endif
1046
1047 #ifndef RODATA_BEGIN_LABEL
1048 #define RODATA_BEGIN_LABEL      "*.L_rodata_b"
1049 #endif
1050 #ifndef RODATA_END_LABEL
1051 #define RODATA_END_LABEL        "*.L_rodata_e"
1052 #endif
1053
1054 #ifndef RODATA1_BEGIN_LABEL
1055 #define RODATA1_BEGIN_LABEL     "*.L_rodata1_b"
1056 #endif
1057 #ifndef RODATA1_END_LABEL
1058 #define RODATA1_END_LABEL       "*.L_rodata1_e"
1059 #endif
1060
1061 #ifndef BSS_BEGIN_LABEL
1062 #define BSS_BEGIN_LABEL         "*.L_bss_b"
1063 #endif
1064 #ifndef BSS_END_LABEL
1065 #define BSS_END_LABEL           "*.L_bss_e"
1066 #endif
1067
1068 #ifndef LINE_BEGIN_LABEL
1069 #define LINE_BEGIN_LABEL        "*.L_line_b"
1070 #endif
1071 #ifndef LINE_LAST_ENTRY_LABEL
1072 #define LINE_LAST_ENTRY_LABEL   "*.L_line_last"
1073 #endif
1074 #ifndef LINE_END_LABEL
1075 #define LINE_END_LABEL          "*.L_line_e"
1076 #endif
1077
1078 #ifndef DEBUG_BEGIN_LABEL
1079 #define DEBUG_BEGIN_LABEL       "*.L_debug_b"
1080 #endif
1081 #ifndef SFNAMES_BEGIN_LABEL
1082 #define SFNAMES_BEGIN_LABEL     "*.L_sfnames_b"
1083 #endif
1084 #ifndef SRCINFO_BEGIN_LABEL
1085 #define SRCINFO_BEGIN_LABEL     "*.L_srcinfo_b"
1086 #endif
1087 #ifndef MACINFO_BEGIN_LABEL
1088 #define MACINFO_BEGIN_LABEL     "*.L_macinfo_b"
1089 #endif
1090
1091 #ifndef DEBUG_ARANGES_BEGIN_LABEL
1092 #define DEBUG_ARANGES_BEGIN_LABEL "*.L_debug_aranges_begin"
1093 #endif
1094 #ifndef DEBUG_ARANGES_END_LABEL
1095 #define DEBUG_ARANGES_END_LABEL "*.L_debug_aranges_end"
1096 #endif
1097
1098 #ifndef DIE_BEGIN_LABEL_FMT
1099 #define DIE_BEGIN_LABEL_FMT     "*.L_D%u"
1100 #endif
1101 #ifndef DIE_END_LABEL_FMT
1102 #define DIE_END_LABEL_FMT       "*.L_D%u_e"
1103 #endif
1104 #ifndef PUB_DIE_LABEL_FMT
1105 #define PUB_DIE_LABEL_FMT       "*.L_P%u"
1106 #endif
1107 #ifndef BLOCK_BEGIN_LABEL_FMT
1108 #define BLOCK_BEGIN_LABEL_FMT   "*.L_B%u"
1109 #endif
1110 #ifndef BLOCK_END_LABEL_FMT
1111 #define BLOCK_END_LABEL_FMT     "*.L_B%u_e"
1112 #endif
1113 #ifndef SS_BEGIN_LABEL_FMT
1114 #define SS_BEGIN_LABEL_FMT      "*.L_s%u"
1115 #endif
1116 #ifndef SS_END_LABEL_FMT
1117 #define SS_END_LABEL_FMT        "*.L_s%u_e"
1118 #endif
1119 #ifndef EE_BEGIN_LABEL_FMT
1120 #define EE_BEGIN_LABEL_FMT      "*.L_e%u"
1121 #endif
1122 #ifndef EE_END_LABEL_FMT
1123 #define EE_END_LABEL_FMT        "*.L_e%u_e"
1124 #endif
1125 #ifndef MT_BEGIN_LABEL_FMT
1126 #define MT_BEGIN_LABEL_FMT      "*.L_t%u"
1127 #endif
1128 #ifndef MT_END_LABEL_FMT
1129 #define MT_END_LABEL_FMT        "*.L_t%u_e"
1130 #endif
1131 #ifndef LOC_BEGIN_LABEL_FMT
1132 #define LOC_BEGIN_LABEL_FMT     "*.L_l%u"
1133 #endif
1134 #ifndef LOC_END_LABEL_FMT
1135 #define LOC_END_LABEL_FMT       "*.L_l%u_e"
1136 #endif
1137 #ifndef BOUND_BEGIN_LABEL_FMT
1138 #define BOUND_BEGIN_LABEL_FMT   "*.L_b%u_%u_%c"
1139 #endif
1140 #ifndef BOUND_END_LABEL_FMT
1141 #define BOUND_END_LABEL_FMT     "*.L_b%u_%u_%c_e"
1142 #endif
1143 #ifndef DERIV_BEGIN_LABEL_FMT
1144 #define DERIV_BEGIN_LABEL_FMT   "*.L_d%u"
1145 #endif
1146 #ifndef DERIV_END_LABEL_FMT
1147 #define DERIV_END_LABEL_FMT     "*.L_d%u_e"
1148 #endif
1149 #ifndef SL_BEGIN_LABEL_FMT
1150 #define SL_BEGIN_LABEL_FMT      "*.L_sl%u"
1151 #endif
1152 #ifndef SL_END_LABEL_FMT
1153 #define SL_END_LABEL_FMT        "*.L_sl%u_e"
1154 #endif
1155 #ifndef BODY_BEGIN_LABEL_FMT
1156 #define BODY_BEGIN_LABEL_FMT    "*.L_b%u"
1157 #endif
1158 #ifndef BODY_END_LABEL_FMT
1159 #define BODY_END_LABEL_FMT      "*.L_b%u_e"
1160 #endif
1161 #ifndef FUNC_END_LABEL_FMT
1162 #define FUNC_END_LABEL_FMT      "*.L_f%u_e"
1163 #endif
1164 #ifndef TYPE_NAME_FMT
1165 #define TYPE_NAME_FMT           "*.L_T%u"
1166 #endif
1167 #ifndef DECL_NAME_FMT
1168 #define DECL_NAME_FMT           "*.L_E%u"
1169 #endif
1170 #ifndef LINE_CODE_LABEL_FMT
1171 #define LINE_CODE_LABEL_FMT     "*.L_LC%u"
1172 #endif
1173 #ifndef SFNAMES_ENTRY_LABEL_FMT
1174 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
1175 #endif
1176 #ifndef LINE_ENTRY_LABEL_FMT
1177 #define LINE_ENTRY_LABEL_FMT    "*.L_LE%u"
1178 #endif
1179 \f
1180 /* Definitions of defaults for various types of primitive assembly language
1181    output operations.
1182
1183    If necessary, these may be overridden from within your tm.h file,
1184    but typically, you shouldn't need to override these.  */
1185
1186 #ifndef ASM_OUTPUT_PUSH_SECTION
1187 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
1188   fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
1189 #endif
1190
1191 #ifndef ASM_OUTPUT_POP_SECTION
1192 #define ASM_OUTPUT_POP_SECTION(FILE) \
1193   fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
1194 #endif
1195
1196 #ifndef ASM_OUTPUT_DWARF_DELTA2
1197 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2)                     \
1198   dw2_asm_output_delta (2, LABEL1, LABEL2, NULL)
1199 #endif
1200
1201 #ifndef ASM_OUTPUT_DWARF_DELTA4
1202 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2)                     \
1203   dw2_asm_output_delta (4, LABEL1, LABEL2, NULL)
1204 #endif
1205
1206 #ifndef ASM_OUTPUT_DWARF_TAG
1207 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG)                                  \
1208   dw2_asm_output_data (2, TAG, "%s", dwarf_tag_name (TAG));
1209 #endif
1210
1211 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
1212 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR)                           \
1213   dw2_asm_output_data (2, ATTR, "%s", dwarf_attr_name (ATTR))
1214 #endif
1215
1216 #ifndef ASM_OUTPUT_DWARF_STACK_OP
1217 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP)                              \
1218   dw2_asm_output_data (1, OP, "%s", dwarf_stack_op_name (OP))
1219 #endif
1220
1221 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
1222 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT)                             \
1223   dw2_asm_output_data (2, FT, "%s", dwarf_fund_type_name (FT))
1224 #endif
1225
1226 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
1227 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT)                             \
1228   dw2_asm_output_data (1, FMT, "%s", dwarf_fmt_byte_name (FMT));
1229 #endif
1230
1231 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
1232 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD)                        \
1233   dw2_asm_output_data (1, MOD, "%s", dwarf_typemod_name (MOD));
1234 #endif
1235 \f
1236 #ifndef ASM_OUTPUT_DWARF_ADDR
1237 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL)                               \
1238   dw2_asm_output_addr (4, LABEL, NULL)
1239 #endif
1240
1241 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
1242 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX)                           \
1243   dw2_asm_output_addr_rtx (4, RTX, NULL)
1244 #endif
1245
1246 #ifndef ASM_OUTPUT_DWARF_REF
1247 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL)                                \
1248   dw2_asm_output_addr (4, LABEL, NULL)
1249 #endif
1250
1251 #ifndef ASM_OUTPUT_DWARF_DATA1
1252 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
1253   dw2_asm_output_data (1, VALUE, NULL)
1254 #endif
1255
1256 #ifndef ASM_OUTPUT_DWARF_DATA2
1257 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
1258   dw2_asm_output_data (2, VALUE, NULL)
1259 #endif
1260
1261 #ifndef ASM_OUTPUT_DWARF_DATA4
1262 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
1263   dw2_asm_output_data (4, VALUE, NULL)
1264 #endif
1265
1266 #ifndef ASM_OUTPUT_DWARF_DATA8
1267 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE)               \
1268   dw2_asm_output_data (8, VALUE, NULL)
1269 #endif
1270
1271 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
1272    NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
1273    based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
1274    defined, we call it, then issue the line feed. If not, we supply a
1275    default definition of calling ASM_OUTPUT_ASCII */
1276
1277 #ifndef ASM_OUTPUT_DWARF_STRING
1278 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1279   ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
1280 #else
1281 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
1282   ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
1283 #endif
1284
1285 \f
1286 /* The debug hooks structure.  */
1287 const struct gcc_debug_hooks dwarf_debug_hooks =
1288 {
1289   dwarfout_init,
1290   dwarfout_finish,
1291   dwarfout_define,
1292   dwarfout_undef,
1293   dwarfout_start_source_file_check,
1294   dwarfout_end_source_file_check,
1295   dwarfout_begin_block,
1296   dwarfout_end_block,
1297   debug_true_tree,              /* ignore_block */
1298   dwarfout_source_line,         /* source_line */
1299   dwarfout_source_line,         /* begin_prologue */
1300   dwarfout_end_prologue,
1301   dwarfout_end_epilogue,
1302   debug_nothing_tree,           /* begin_function */
1303   dwarfout_end_function,
1304   dwarfout_function_decl,
1305   dwarfout_global_decl,
1306   dwarfout_deferred_inline_function,
1307   debug_nothing_tree,           /* outlining_inline_function */
1308   debug_nothing_rtx             /* label */
1309 };
1310 \f
1311 /************************ general utility functions **************************/
1312
1313 static inline int
1314 is_pseudo_reg (rtl)
1315      rtx rtl;
1316 {
1317   return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1318           || ((GET_CODE (rtl) == SUBREG)
1319               && (REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)));
1320 }
1321
1322 static inline tree
1323 type_main_variant (type)
1324      tree type;
1325 {
1326   type = TYPE_MAIN_VARIANT (type);
1327
1328   /* There really should be only one main variant among any group of variants
1329      of a given type (and all of the MAIN_VARIANT values for all members of
1330      the group should point to that one type) but sometimes the C front-end
1331      messes this up for array types, so we work around that bug here.  */
1332
1333   if (TREE_CODE (type) == ARRAY_TYPE)
1334     {
1335       while (type != TYPE_MAIN_VARIANT (type))
1336         type = TYPE_MAIN_VARIANT (type);
1337     }
1338
1339   return type;
1340 }
1341
1342 /* Return non-zero if the given type node represents a tagged type.  */
1343
1344 static inline int
1345 is_tagged_type (type)
1346      tree type;
1347 {
1348   enum tree_code code = TREE_CODE (type);
1349
1350   return (code == RECORD_TYPE || code == UNION_TYPE
1351           || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1352 }
1353
1354 static const char *
1355 dwarf_tag_name (tag)
1356      unsigned tag;
1357 {
1358   switch (tag)
1359     {
1360     case TAG_padding:                   return "TAG_padding";
1361     case TAG_array_type:                return "TAG_array_type";
1362     case TAG_class_type:                return "TAG_class_type";
1363     case TAG_entry_point:               return "TAG_entry_point";
1364     case TAG_enumeration_type:          return "TAG_enumeration_type";
1365     case TAG_formal_parameter:          return "TAG_formal_parameter";
1366     case TAG_global_subroutine:         return "TAG_global_subroutine";
1367     case TAG_global_variable:           return "TAG_global_variable";
1368     case TAG_label:                     return "TAG_label";
1369     case TAG_lexical_block:             return "TAG_lexical_block";
1370     case TAG_local_variable:            return "TAG_local_variable";
1371     case TAG_member:                    return "TAG_member";
1372     case TAG_pointer_type:              return "TAG_pointer_type";
1373     case TAG_reference_type:            return "TAG_reference_type";
1374     case TAG_compile_unit:              return "TAG_compile_unit";
1375     case TAG_string_type:               return "TAG_string_type";
1376     case TAG_structure_type:            return "TAG_structure_type";
1377     case TAG_subroutine:                return "TAG_subroutine";
1378     case TAG_subroutine_type:           return "TAG_subroutine_type";
1379     case TAG_typedef:                   return "TAG_typedef";
1380     case TAG_union_type:                return "TAG_union_type";
1381     case TAG_unspecified_parameters:    return "TAG_unspecified_parameters";
1382     case TAG_variant:                   return "TAG_variant";
1383     case TAG_common_block:              return "TAG_common_block";
1384     case TAG_common_inclusion:          return "TAG_common_inclusion";
1385     case TAG_inheritance:               return "TAG_inheritance";
1386     case TAG_inlined_subroutine:        return "TAG_inlined_subroutine";
1387     case TAG_module:                    return "TAG_module";
1388     case TAG_ptr_to_member_type:        return "TAG_ptr_to_member_type";
1389     case TAG_set_type:                  return "TAG_set_type";
1390     case TAG_subrange_type:             return "TAG_subrange_type";
1391     case TAG_with_stmt:                 return "TAG_with_stmt";
1392
1393     /* GNU extensions.  */
1394
1395     case TAG_format_label:              return "TAG_format_label";
1396     case TAG_namelist:                  return "TAG_namelist";
1397     case TAG_function_template:         return "TAG_function_template";
1398     case TAG_class_template:            return "TAG_class_template";
1399
1400     default:                            return "TAG_<unknown>";
1401     }
1402 }
1403
1404 static const char *
1405 dwarf_attr_name (attr)
1406      unsigned attr;
1407 {
1408   switch (attr)
1409     {
1410     case AT_sibling:                    return "AT_sibling";
1411     case AT_location:                   return "AT_location";
1412     case AT_name:                       return "AT_name";
1413     case AT_fund_type:                  return "AT_fund_type";
1414     case AT_mod_fund_type:              return "AT_mod_fund_type";
1415     case AT_user_def_type:              return "AT_user_def_type";
1416     case AT_mod_u_d_type:               return "AT_mod_u_d_type";
1417     case AT_ordering:                   return "AT_ordering";
1418     case AT_subscr_data:                return "AT_subscr_data";
1419     case AT_byte_size:                  return "AT_byte_size";
1420     case AT_bit_offset:                 return "AT_bit_offset";
1421     case AT_bit_size:                   return "AT_bit_size";
1422     case AT_element_list:               return "AT_element_list";
1423     case AT_stmt_list:                  return "AT_stmt_list";
1424     case AT_low_pc:                     return "AT_low_pc";
1425     case AT_high_pc:                    return "AT_high_pc";
1426     case AT_language:                   return "AT_language";
1427     case AT_member:                     return "AT_member";
1428     case AT_discr:                      return "AT_discr";
1429     case AT_discr_value:                return "AT_discr_value";
1430     case AT_string_length:              return "AT_string_length";
1431     case AT_common_reference:           return "AT_common_reference";
1432     case AT_comp_dir:                   return "AT_comp_dir";
1433     case AT_const_value_string:         return "AT_const_value_string";
1434     case AT_const_value_data2:          return "AT_const_value_data2";
1435     case AT_const_value_data4:          return "AT_const_value_data4";
1436     case AT_const_value_data8:          return "AT_const_value_data8";
1437     case AT_const_value_block2:         return "AT_const_value_block2";
1438     case AT_const_value_block4:         return "AT_const_value_block4";
1439     case AT_containing_type:            return "AT_containing_type";
1440     case AT_default_value_addr:         return "AT_default_value_addr";
1441     case AT_default_value_data2:        return "AT_default_value_data2";
1442     case AT_default_value_data4:        return "AT_default_value_data4";
1443     case AT_default_value_data8:        return "AT_default_value_data8";
1444     case AT_default_value_string:       return "AT_default_value_string";
1445     case AT_friends:                    return "AT_friends";
1446     case AT_inline:                     return "AT_inline";
1447     case AT_is_optional:                return "AT_is_optional";
1448     case AT_lower_bound_ref:            return "AT_lower_bound_ref";
1449     case AT_lower_bound_data2:          return "AT_lower_bound_data2";
1450     case AT_lower_bound_data4:          return "AT_lower_bound_data4";
1451     case AT_lower_bound_data8:          return "AT_lower_bound_data8";
1452     case AT_private:                    return "AT_private";
1453     case AT_producer:                   return "AT_producer";
1454     case AT_program:                    return "AT_program";
1455     case AT_protected:                  return "AT_protected";
1456     case AT_prototyped:                 return "AT_prototyped";
1457     case AT_public:                     return "AT_public";
1458     case AT_pure_virtual:               return "AT_pure_virtual";
1459     case AT_return_addr:                return "AT_return_addr";
1460     case AT_abstract_origin:            return "AT_abstract_origin";
1461     case AT_start_scope:                return "AT_start_scope";
1462     case AT_stride_size:                return "AT_stride_size";
1463     case AT_upper_bound_ref:            return "AT_upper_bound_ref";
1464     case AT_upper_bound_data2:          return "AT_upper_bound_data2";
1465     case AT_upper_bound_data4:          return "AT_upper_bound_data4";
1466     case AT_upper_bound_data8:          return "AT_upper_bound_data8";
1467     case AT_virtual:                    return "AT_virtual";
1468
1469     /* GNU extensions */
1470
1471     case AT_sf_names:                   return "AT_sf_names";
1472     case AT_src_info:                   return "AT_src_info";
1473     case AT_mac_info:                   return "AT_mac_info";
1474     case AT_src_coords:                 return "AT_src_coords";
1475     case AT_body_begin:                 return "AT_body_begin";
1476     case AT_body_end:                   return "AT_body_end";
1477
1478     default:                            return "AT_<unknown>";
1479     }
1480 }
1481
1482 static const char *
1483 dwarf_stack_op_name (op)
1484      unsigned op;
1485 {
1486   switch (op)
1487     {
1488     case OP_REG:                return "OP_REG";
1489     case OP_BASEREG:            return "OP_BASEREG";
1490     case OP_ADDR:               return "OP_ADDR";
1491     case OP_CONST:              return "OP_CONST";
1492     case OP_DEREF2:             return "OP_DEREF2";
1493     case OP_DEREF4:             return "OP_DEREF4";
1494     case OP_ADD:                return "OP_ADD";
1495     default:                    return "OP_<unknown>";
1496     }
1497 }
1498
1499 static const char *
1500 dwarf_typemod_name (mod)
1501      unsigned mod;
1502 {
1503   switch (mod)
1504     {
1505     case MOD_pointer_to:        return "MOD_pointer_to";
1506     case MOD_reference_to:      return "MOD_reference_to";
1507     case MOD_const:             return "MOD_const";
1508     case MOD_volatile:          return "MOD_volatile";
1509     default:                    return "MOD_<unknown>";
1510     }
1511 }
1512
1513 static const char *
1514 dwarf_fmt_byte_name (fmt)
1515      unsigned fmt;
1516 {
1517   switch (fmt)
1518     {
1519     case FMT_FT_C_C:    return "FMT_FT_C_C";
1520     case FMT_FT_C_X:    return "FMT_FT_C_X";
1521     case FMT_FT_X_C:    return "FMT_FT_X_C";
1522     case FMT_FT_X_X:    return "FMT_FT_X_X";
1523     case FMT_UT_C_C:    return "FMT_UT_C_C";
1524     case FMT_UT_C_X:    return "FMT_UT_C_X";
1525     case FMT_UT_X_C:    return "FMT_UT_X_C";
1526     case FMT_UT_X_X:    return "FMT_UT_X_X";
1527     case FMT_ET:        return "FMT_ET";
1528     default:            return "FMT_<unknown>";
1529     }
1530 }
1531
1532 static const char *
1533 dwarf_fund_type_name (ft)
1534      unsigned ft;
1535 {
1536   switch (ft)
1537     {
1538     case FT_char:               return "FT_char";
1539     case FT_signed_char:        return "FT_signed_char";
1540     case FT_unsigned_char:      return "FT_unsigned_char";
1541     case FT_short:              return "FT_short";
1542     case FT_signed_short:       return "FT_signed_short";
1543     case FT_unsigned_short:     return "FT_unsigned_short";
1544     case FT_integer:            return "FT_integer";
1545     case FT_signed_integer:     return "FT_signed_integer";
1546     case FT_unsigned_integer:   return "FT_unsigned_integer";
1547     case FT_long:               return "FT_long";
1548     case FT_signed_long:        return "FT_signed_long";
1549     case FT_unsigned_long:      return "FT_unsigned_long";
1550     case FT_pointer:            return "FT_pointer";
1551     case FT_float:              return "FT_float";
1552     case FT_dbl_prec_float:     return "FT_dbl_prec_float";
1553     case FT_ext_prec_float:     return "FT_ext_prec_float";
1554     case FT_complex:            return "FT_complex";
1555     case FT_dbl_prec_complex:   return "FT_dbl_prec_complex";
1556     case FT_void:               return "FT_void";
1557     case FT_boolean:            return "FT_boolean";
1558     case FT_ext_prec_complex:   return "FT_ext_prec_complex";
1559     case FT_label:              return "FT_label";
1560
1561     /* GNU extensions.  */
1562
1563     case FT_long_long:          return "FT_long_long";
1564     case FT_signed_long_long:   return "FT_signed_long_long";
1565     case FT_unsigned_long_long: return "FT_unsigned_long_long";
1566
1567     case FT_int8:               return "FT_int8";
1568     case FT_signed_int8:        return "FT_signed_int8";
1569     case FT_unsigned_int8:      return "FT_unsigned_int8";
1570     case FT_int16:              return "FT_int16";
1571     case FT_signed_int16:       return "FT_signed_int16";
1572     case FT_unsigned_int16:     return "FT_unsigned_int16";
1573     case FT_int32:              return "FT_int32";
1574     case FT_signed_int32:       return "FT_signed_int32";
1575     case FT_unsigned_int32:     return "FT_unsigned_int32";
1576     case FT_int64:              return "FT_int64";
1577     case FT_signed_int64:       return "FT_signed_int64";
1578     case FT_unsigned_int64:     return "FT_unsigned_int64";
1579     case FT_int128:             return "FT_int128";
1580     case FT_signed_int128:      return "FT_signed_int128";
1581     case FT_unsigned_int128:    return "FT_unsigned_int128";
1582
1583     case FT_real32:             return "FT_real32";
1584     case FT_real64:             return "FT_real64";
1585     case FT_real96:             return "FT_real96";
1586     case FT_real128:            return "FT_real128";
1587
1588     default:                    return "FT_<unknown>";
1589     }
1590 }
1591
1592 /* Determine the "ultimate origin" of a decl.  The decl may be an
1593    inlined instance of an inlined instance of a decl which is local
1594    to an inline function, so we have to trace all of the way back
1595    through the origin chain to find out what sort of node actually
1596    served as the original seed for the given block.  */
1597
1598 static tree
1599 decl_ultimate_origin (decl)
1600      tree decl;
1601 {
1602 #ifdef ENABLE_CHECKING
1603   if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1604     /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1605        most distant ancestor, this should never happen.  */
1606     abort ();
1607 #endif
1608
1609   return DECL_ABSTRACT_ORIGIN (decl);
1610 }
1611
1612 /* Determine the "ultimate origin" of a block.  The block may be an
1613    inlined instance of an inlined instance of a block which is local
1614    to an inline function, so we have to trace all of the way back
1615    through the origin chain to find out what sort of node actually
1616    served as the original seed for the given block.  */
1617
1618 static tree
1619 block_ultimate_origin (block)
1620      tree block;
1621 {
1622   tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1623
1624   if (immediate_origin == NULL)
1625     return NULL;
1626   else
1627     {
1628       tree ret_val;
1629       tree lookahead = immediate_origin;
1630
1631       do
1632         {
1633           ret_val = lookahead;
1634           lookahead = (TREE_CODE (ret_val) == BLOCK)
1635                        ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1636                        : NULL;
1637         }
1638       while (lookahead != NULL && lookahead != ret_val);
1639       return ret_val;
1640     }
1641 }
1642
1643 /* Get the class to which DECL belongs, if any.  In g++, the DECL_CONTEXT
1644    of a virtual function may refer to a base class, so we check the 'this'
1645    parameter.  */
1646
1647 static tree
1648 decl_class_context (decl)
1649      tree decl;
1650 {
1651   tree context = NULL_TREE;
1652   if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1653     context = DECL_CONTEXT (decl);
1654   else
1655     context = TYPE_MAIN_VARIANT
1656       (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1657
1658   if (context && !TYPE_P (context))
1659     context = NULL_TREE;
1660
1661   return context;
1662 }
1663
1664 #if 0
1665 static void
1666 output_unsigned_leb128 (value)
1667      unsigned long value;
1668 {
1669   unsigned long orig_value = value;
1670
1671   do
1672     {
1673       unsigned byte = (value & 0x7f);
1674
1675       value >>= 7;
1676       if (value != 0)   /* more bytes to follow */
1677         byte |= 0x80;
1678       dw2_asm_output_data (1, byte, "\t%s ULEB128 number - value = %lu",
1679                            orig_value);
1680     }
1681   while (value != 0);
1682 }
1683
1684 static void
1685 output_signed_leb128 (value)
1686      long value;
1687 {
1688   long orig_value = value;
1689   int negative = (value < 0);
1690   int more;
1691
1692   do
1693     {
1694       unsigned byte = (value & 0x7f);
1695
1696       value >>= 7;
1697       if (negative)
1698         value |= 0xfe000000;  /* manually sign extend */
1699       if (((value == 0) && ((byte & 0x40) == 0))
1700           || ((value == -1) && ((byte & 0x40) == 1)))
1701         more = 0;
1702       else
1703         {
1704           byte |= 0x80;
1705           more = 1;
1706         }
1707       dw2_asm_output_data (1, byte, "\t%s SLEB128 number - value = %ld",
1708                            orig_value);
1709     }
1710   while (more);
1711 }
1712 #endif
1713 \f
1714 /**************** utility functions for attribute functions ******************/
1715
1716 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1717    type code for the given type.
1718
1719    This routine must only be called for GCC type nodes that correspond to
1720    Dwarf fundamental types.
1721
1722    The current Dwarf draft specification calls for Dwarf fundamental types
1723    to accurately reflect the fact that a given type was either a "plain"
1724    integral type or an explicitly "signed" integral type.  Unfortunately,
1725    we can't always do this, because GCC may already have thrown away the
1726    information about the precise way in which the type was originally
1727    specified, as in:
1728
1729         typedef signed int my_type;
1730
1731         struct s { my_type f; };
1732
1733    Since we may be stuck here without enough information to do exactly
1734    what is called for in the Dwarf draft specification, we do the best
1735    that we can under the circumstances and always use the "plain" integral
1736    fundamental type codes for int, short, and long types.  That's probably
1737    good enough.  The additional accuracy called for in the current DWARF
1738    draft specification is probably never even useful in practice.  */
1739
1740 static int
1741 fundamental_type_code (type)
1742      tree type;
1743 {
1744   if (TREE_CODE (type) == ERROR_MARK)
1745     return 0;
1746
1747   switch (TREE_CODE (type))
1748     {
1749       case ERROR_MARK:
1750         return FT_void;
1751
1752       case VOID_TYPE:
1753         return FT_void;
1754
1755       case INTEGER_TYPE:
1756         /* Carefully distinguish all the standard types of C,
1757            without messing up if the language is not C.
1758            Note that we check only for the names that contain spaces;
1759            other names might occur by coincidence in other languages.  */
1760         if (TYPE_NAME (type) != 0
1761             && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1762             && DECL_NAME (TYPE_NAME (type)) != 0
1763             && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1764           {
1765             const char *const name =
1766               IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1767
1768             if (!strcmp (name, "unsigned char"))
1769               return FT_unsigned_char;
1770             if (!strcmp (name, "signed char"))
1771               return FT_signed_char;
1772             if (!strcmp (name, "unsigned int"))
1773               return FT_unsigned_integer;
1774             if (!strcmp (name, "short int"))
1775               return FT_short;
1776             if (!strcmp (name, "short unsigned int"))
1777               return FT_unsigned_short;
1778             if (!strcmp (name, "long int"))
1779               return FT_long;
1780             if (!strcmp (name, "long unsigned int"))
1781               return FT_unsigned_long;
1782             if (!strcmp (name, "long long int"))
1783               return FT_long_long;              /* Not grok'ed by svr4 SDB */
1784             if (!strcmp (name, "long long unsigned int"))
1785               return FT_unsigned_long_long;     /* Not grok'ed by svr4 SDB */
1786           }
1787
1788         /* Most integer types will be sorted out above, however, for the
1789            sake of special `array index' integer types, the following code
1790            is also provided.  */
1791
1792         if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1793           return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1794
1795         if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1796           return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1797
1798         if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1799           return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1800
1801         if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1802           return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1803
1804         if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1805           return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1806
1807         if (TYPE_MODE (type) == TImode)
1808           return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1809
1810         /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1811         if (TYPE_PRECISION (type) == 1)
1812           return FT_boolean;
1813
1814         abort ();
1815
1816       case REAL_TYPE:
1817         /* Carefully distinguish all the standard types of C,
1818            without messing up if the language is not C.  */
1819         if (TYPE_NAME (type) != 0
1820             && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1821             && DECL_NAME (TYPE_NAME (type)) != 0
1822             && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1823           {
1824             const char *const name =
1825               IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1826
1827             /* Note that here we can run afoul of a serious bug in "classic"
1828                svr4 SDB debuggers.  They don't seem to understand the
1829                FT_ext_prec_float type (even though they should).  */
1830
1831             if (!strcmp (name, "long double"))
1832               return FT_ext_prec_float;
1833           }
1834
1835         if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1836           {
1837             /* On the SH, when compiling with -m3e or -m4-single-only, both
1838                float and double are 32 bits.  But since the debugger doesn't
1839                know about the subtarget, it always thinks double is 64 bits.
1840                So we have to tell the debugger that the type is float to
1841                make the output of the 'print' command etc. readable.  */
1842             if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1843               return FT_float;
1844             return FT_dbl_prec_float;
1845           }
1846         if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1847           return FT_float;
1848
1849         /* Note that here we can run afoul of a serious bug in "classic"
1850            svr4 SDB debuggers.  They don't seem to understand the
1851            FT_ext_prec_float type (even though they should).  */
1852
1853         if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1854           return FT_ext_prec_float;
1855         abort ();
1856
1857       case COMPLEX_TYPE:
1858         return FT_complex;      /* GNU FORTRAN COMPLEX type.  */
1859
1860       case CHAR_TYPE:
1861         return FT_char;         /* GNU Pascal CHAR type.  Not used in C.  */
1862
1863       case BOOLEAN_TYPE:
1864         return FT_boolean;      /* GNU FORTRAN BOOLEAN type.  */
1865
1866       default:
1867         abort ();       /* No other TREE_CODEs are Dwarf fundamental types.  */
1868     }
1869   return 0;
1870 }
1871 \f
1872 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1873    the Dwarf "root" type for the given input type.  The Dwarf "root" type
1874    of a given type is generally the same as the given type, except that if
1875    the  given type is a pointer or reference type, then the root type of
1876    the given type is the root type of the "basis" type for the pointer or
1877    reference type.  (This definition of the "root" type is recursive.)
1878    Also, the root type of a `const' qualified type or a `volatile'
1879    qualified type is the root type of the given type without the
1880    qualifiers.  */
1881
1882 static tree
1883 root_type_1 (type, count)
1884      tree type;
1885      int count;
1886 {
1887   /* Give up after searching 1000 levels, in case this is a recursive
1888      pointer type.  Such types are possible in Ada, but it is not possible
1889      to represent them in DWARF1 debug info.  */
1890   if (count > 1000)
1891     return error_mark_node;
1892
1893   switch (TREE_CODE (type))
1894     {
1895       case ERROR_MARK:
1896         return error_mark_node;
1897
1898       case POINTER_TYPE:
1899       case REFERENCE_TYPE:
1900         return root_type_1 (TREE_TYPE (type), count+1);
1901
1902       default:
1903         return type;
1904     }
1905 }
1906
1907 static tree
1908 root_type (type)
1909      tree type;
1910 {
1911   type = root_type_1 (type, 0);
1912   if (type != error_mark_node)
1913     type = type_main_variant (type);
1914   return type;
1915 }
1916
1917 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1918    of zero or more Dwarf "type-modifier" bytes applicable to the type.  */
1919
1920 static void
1921 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1922      tree type;
1923      int decl_const;
1924      int decl_volatile;
1925      int count;
1926 {
1927   if (TREE_CODE (type) == ERROR_MARK)
1928     return;
1929
1930   /* Give up after searching 1000 levels, in case this is a recursive
1931      pointer type.  Such types are possible in Ada, but it is not possible
1932      to represent them in DWARF1 debug info.  */
1933   if (count > 1000)
1934     return;
1935
1936   if (TYPE_READONLY (type) || decl_const)
1937     ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1938   if (TYPE_VOLATILE (type) || decl_volatile)
1939     ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1940   switch (TREE_CODE (type))
1941     {
1942       case POINTER_TYPE:
1943         ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1944         write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1945         return;
1946
1947       case REFERENCE_TYPE:
1948         ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1949         write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1950         return;
1951
1952       case ERROR_MARK:
1953       default:
1954         return;
1955     }
1956 }
1957
1958 static void
1959 write_modifier_bytes (type, decl_const, decl_volatile)
1960      tree type;
1961      int decl_const;
1962      int decl_volatile;
1963 {
1964   write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1965 }
1966 \f
1967 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1968    given input type is a Dwarf "fundamental" type.  Otherwise return zero.  */
1969
1970 static inline int
1971 type_is_fundamental (type)
1972      tree type;
1973 {
1974   switch (TREE_CODE (type))
1975     {
1976       case ERROR_MARK:
1977       case VOID_TYPE:
1978       case INTEGER_TYPE:
1979       case REAL_TYPE:
1980       case COMPLEX_TYPE:
1981       case BOOLEAN_TYPE:
1982       case CHAR_TYPE:
1983         return 1;
1984
1985       case SET_TYPE:
1986       case ARRAY_TYPE:
1987       case RECORD_TYPE:
1988       case UNION_TYPE:
1989       case QUAL_UNION_TYPE:
1990       case ENUMERAL_TYPE:
1991       case FUNCTION_TYPE:
1992       case METHOD_TYPE:
1993       case POINTER_TYPE:
1994       case REFERENCE_TYPE:
1995       case FILE_TYPE:
1996       case OFFSET_TYPE:
1997       case LANG_TYPE:
1998       case VECTOR_TYPE:
1999         return 0;
2000
2001       default:
2002         abort ();
2003     }
2004   return 0;
2005 }
2006
2007 /* Given a pointer to some ..._DECL tree node, generate an assembly language
2008    equate directive which will associate a symbolic name with the current DIE.
2009
2010    The name used is an artificial label generated from the DECL_UID number
2011    associated with the given decl node.  The name it gets equated to is the
2012    symbolic label that we (previously) output at the start of the DIE that
2013    we are currently generating.
2014
2015    Calling this function while generating some "decl related" form of DIE
2016    makes it possible to later refer to the DIE which represents the given
2017    decl simply by re-generating the symbolic name from the ..._DECL node's
2018    UID number.  */
2019
2020 static void
2021 equate_decl_number_to_die_number (decl)
2022      tree decl;
2023 {
2024   /* In the case where we are generating a DIE for some ..._DECL node
2025      which represents either some inline function declaration or some
2026      entity declared within an inline function declaration/definition,
2027      setup a symbolic name for the current DIE so that we have a name
2028      for this DIE that we can easily refer to later on within
2029      AT_abstract_origin attributes.  */
2030
2031   char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
2032   char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2033
2034   sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
2035   sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2036   ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
2037 }
2038
2039 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
2040    equate directive which will associate a symbolic name with the current DIE.
2041
2042    The name used is an artificial label generated from the TYPE_UID number
2043    associated with the given type node.  The name it gets equated to is the
2044    symbolic label that we (previously) output at the start of the DIE that
2045    we are currently generating.
2046
2047    Calling this function while generating some "type related" form of DIE
2048    makes it easy to later refer to the DIE which represents the given type
2049    simply by re-generating the alternative name from the ..._TYPE node's
2050    UID number.  */
2051
2052 static inline void
2053 equate_type_number_to_die_number (type)
2054      tree type;
2055 {
2056   char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
2057   char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
2058
2059   /* We are generating a DIE to represent the main variant of this type
2060      (i.e the type without any const or volatile qualifiers) so in order
2061      to get the equate to come out right, we need to get the main variant
2062      itself here.  */
2063
2064   type = type_main_variant (type);
2065
2066   sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
2067   sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2068   ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
2069 }
2070
2071 static void
2072 output_reg_number (rtl)
2073      rtx rtl;
2074 {
2075   unsigned regno = REGNO (rtl);
2076
2077   if (regno >= DWARF_FRAME_REGISTERS)
2078     {
2079       warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
2080                          regno);
2081       regno = 0;
2082     }
2083   dw2_assemble_integer (4, GEN_INT (DBX_REGISTER_NUMBER (regno)));
2084   if (flag_debug_asm)
2085     {
2086       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
2087       PRINT_REG (rtl, 0, asm_out_file);
2088     }
2089   fputc ('\n', asm_out_file);
2090 }
2091
2092 /* The following routine is a nice and simple transducer.  It converts the
2093    RTL for a variable or parameter (resident in memory) into an equivalent
2094    Dwarf representation of a mechanism for getting the address of that same
2095    variable onto the top of a hypothetical "address evaluation" stack.
2096
2097    When creating memory location descriptors, we are effectively trans-
2098    forming the RTL for a memory-resident object into its Dwarf postfix
2099    expression equivalent.  This routine just recursively descends an
2100    RTL tree, turning it into Dwarf postfix code as it goes.  */
2101
2102 static void
2103 output_mem_loc_descriptor (rtl)
2104      rtx rtl;
2105 {
2106   /* Note that for a dynamically sized array, the location we will
2107      generate a description of here will be the lowest numbered location
2108      which is actually within the array.  That's *not* necessarily the
2109      same as the zeroth element of the array.  */
2110
2111 #ifdef ASM_SIMPLIFY_DWARF_ADDR
2112   rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
2113 #endif
2114
2115   switch (GET_CODE (rtl))
2116     {
2117       case SUBREG:
2118
2119         /* The case of a subreg may arise when we have a local (register)
2120            variable or a formal (register) parameter which doesn't quite
2121            fill up an entire register.  For now, just assume that it is
2122            legitimate to make the Dwarf info refer to the whole register
2123            which contains the given subreg.  */
2124
2125         rtl = SUBREG_REG (rtl);
2126         /* Drop thru.  */
2127
2128       case REG:
2129
2130         /* Whenever a register number forms a part of the description of
2131            the method for calculating the (dynamic) address of a memory
2132            resident object, DWARF rules require the register number to
2133            be referred to as a "base register".  This distinction is not
2134            based in any way upon what category of register the hardware
2135            believes the given register belongs to.  This is strictly
2136            DWARF terminology we're dealing with here.
2137
2138            Note that in cases where the location of a memory-resident data
2139            object could be expressed as:
2140
2141                     OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
2142
2143            the actual DWARF location descriptor that we generate may just
2144            be OP_BASEREG (basereg).  This may look deceptively like the
2145            object in question was allocated to a register (rather than
2146            in memory) so DWARF consumers need to be aware of the subtle
2147            distinction between OP_REG and OP_BASEREG.  */
2148
2149         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
2150         output_reg_number (rtl);
2151         break;
2152
2153       case MEM:
2154         output_mem_loc_descriptor (XEXP (rtl, 0));
2155         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
2156         break;
2157
2158       case CONST:
2159       case SYMBOL_REF:
2160         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
2161         ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2162         break;
2163
2164       case PLUS:
2165         output_mem_loc_descriptor (XEXP (rtl, 0));
2166         output_mem_loc_descriptor (XEXP (rtl, 1));
2167         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2168         break;
2169
2170       case CONST_INT:
2171         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2172         ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
2173         break;
2174
2175       case MULT:
2176         /* If a pseudo-reg is optimized away, it is possible for it to
2177            be replaced with a MEM containing a multiply.  Use a GNU extension
2178            to describe it.  */
2179         output_mem_loc_descriptor (XEXP (rtl, 0));
2180         output_mem_loc_descriptor (XEXP (rtl, 1));
2181         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
2182         break;
2183
2184       default:
2185         abort ();
2186     }
2187 }
2188
2189 /* Output a proper Dwarf location descriptor for a variable or parameter
2190    which is either allocated in a register or in a memory location.  For
2191    a register, we just generate an OP_REG and the register number.  For a
2192    memory location we provide a Dwarf postfix expression describing how to
2193    generate the (dynamic) address of the object onto the address stack.  */
2194
2195 static void
2196 output_loc_descriptor (rtl)
2197      rtx rtl;
2198 {
2199   switch (GET_CODE (rtl))
2200     {
2201     case SUBREG:
2202
2203         /* The case of a subreg may arise when we have a local (register)
2204            variable or a formal (register) parameter which doesn't quite
2205            fill up an entire register.  For now, just assume that it is
2206            legitimate to make the Dwarf info refer to the whole register
2207            which contains the given subreg.  */
2208
2209         rtl = SUBREG_REG (rtl);
2210         /* Drop thru.  */
2211
2212     case REG:
2213         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
2214         output_reg_number (rtl);
2215         break;
2216
2217     case MEM:
2218       output_mem_loc_descriptor (XEXP (rtl, 0));
2219       break;
2220
2221     default:
2222       abort ();         /* Should never happen */
2223     }
2224 }
2225
2226 /* Given a tree node describing an array bound (either lower or upper)
2227    output a representation for that bound.  */
2228
2229 static void
2230 output_bound_representation (bound, dim_num, u_or_l)
2231      tree bound;
2232      unsigned dim_num; /* For multi-dimensional arrays.  */
2233      char u_or_l;       /* Designates upper or lower bound.  */
2234 {
2235   switch (TREE_CODE (bound))
2236     {
2237
2238     case ERROR_MARK:
2239       return;
2240
2241       /* All fixed-bounds are represented by INTEGER_CST nodes.  */
2242
2243     case INTEGER_CST:
2244       if (host_integerp (bound, 0))
2245         ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
2246       break;
2247
2248     default:
2249
2250       /* Dynamic bounds may be represented by NOP_EXPR nodes containing
2251          SAVE_EXPR nodes, in which case we can do something, or as
2252          an expression, which we cannot represent.  */
2253       {
2254         char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2255         char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2256
2257         sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
2258                  current_dienum, dim_num, u_or_l);
2259
2260         sprintf (end_label, BOUND_END_LABEL_FMT,
2261                  current_dienum, dim_num, u_or_l);
2262
2263         ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2264         ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2265
2266         /* If optimization is turned on, the SAVE_EXPRs that describe
2267            how to access the upper bound values are essentially bogus.
2268            They only describe (at best) how to get at these values at
2269            the points in the generated code right after they have just
2270            been computed.  Worse yet, in the typical case, the upper
2271            bound values will not even *be* computed in the optimized
2272            code, so these SAVE_EXPRs are entirely bogus.
2273
2274            In order to compensate for this fact, we check here to see
2275            if optimization is enabled, and if so, we effectively create
2276            an empty location description for the (unknown and unknowable)
2277            upper bound.
2278
2279            This should not cause too much trouble for existing (stupid?)
2280            debuggers because they have to deal with empty upper bounds
2281            location descriptions anyway in order to be able to deal with
2282            incomplete array types.
2283
2284            Of course an intelligent debugger (GDB?) should be able to
2285            comprehend that a missing upper bound specification in a
2286            array type used for a storage class `auto' local array variable
2287            indicates that the upper bound is both unknown (at compile-
2288            time) and unknowable (at run-time) due to optimization.  */
2289
2290         if (! optimize)
2291           {
2292             while (TREE_CODE (bound) == NOP_EXPR
2293                    || TREE_CODE (bound) == CONVERT_EXPR)
2294               bound = TREE_OPERAND (bound, 0);
2295
2296             if (TREE_CODE (bound) == SAVE_EXPR)
2297               output_loc_descriptor
2298                 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
2299           }
2300
2301         ASM_OUTPUT_LABEL (asm_out_file, end_label);
2302       }
2303       break;
2304
2305     }
2306 }
2307
2308 /* Recursive function to output a sequence of value/name pairs for
2309    enumeration constants in reversed order.  This is called from
2310    enumeration_type_die.  */
2311
2312 static void
2313 output_enumeral_list (link)
2314      tree link;
2315 {
2316   if (link)
2317     {
2318       output_enumeral_list (TREE_CHAIN (link));
2319
2320       if (host_integerp (TREE_VALUE (link), 0))
2321         ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2322                                 tree_low_cst (TREE_VALUE (link), 0));
2323
2324       ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
2325                                IDENTIFIER_POINTER (TREE_PURPOSE (link)));
2326     }
2327 }
2328
2329 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
2330    which is not less than the value itself.  */
2331
2332 static inline HOST_WIDE_INT
2333 ceiling (value, boundary)
2334      HOST_WIDE_INT value;
2335      unsigned int boundary;
2336 {
2337   return (((value + boundary - 1) / boundary) * boundary);
2338 }
2339
2340 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
2341    pointer to the declared type for the relevant field variable, or return
2342    `integer_type_node' if the given node turns out to be an ERROR_MARK node.  */
2343
2344 static inline tree
2345 field_type (decl)
2346      tree decl;
2347 {
2348   tree type;
2349
2350   if (TREE_CODE (decl) == ERROR_MARK)
2351     return integer_type_node;
2352
2353   type = DECL_BIT_FIELD_TYPE (decl);
2354   if (type == NULL)
2355     type = TREE_TYPE (decl);
2356   return type;
2357 }
2358
2359 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2360    node, return the alignment in bits for the type, or else return
2361    BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node.  */
2362
2363 static inline unsigned int
2364 simple_type_align_in_bits (type)
2365      tree type;
2366 {
2367   return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
2368 }
2369
2370 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
2371    node, return the size in bits for the type if it is a constant, or
2372    else return the alignment for the type if the type's size is not
2373    constant, or else return BITS_PER_WORD if the type actually turns out
2374    to be an ERROR_MARK node.  */
2375
2376 static inline unsigned HOST_WIDE_INT
2377 simple_type_size_in_bits (type)
2378      tree type;
2379 {
2380   tree type_size_tree;
2381
2382   if (TREE_CODE (type) == ERROR_MARK)
2383     return BITS_PER_WORD;
2384   type_size_tree = TYPE_SIZE (type);
2385
2386   if (type_size_tree == NULL_TREE)
2387     return 0;
2388   if (! host_integerp (type_size_tree, 1))
2389     return TYPE_ALIGN (type);
2390   return tree_low_cst (type_size_tree, 1);
2391 }
2392
2393 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
2394    return the byte offset of the lowest addressed byte of the "containing
2395    object" for the given FIELD_DECL, or return 0 if we are unable to deter-
2396    mine what that offset is, either because the argument turns out to be a
2397    pointer to an ERROR_MARK node, or because the offset is actually variable.
2398    (We can't handle the latter case just yet.)  */
2399
2400 static HOST_WIDE_INT
2401 field_byte_offset (decl)
2402      tree decl;
2403 {
2404   unsigned int type_align_in_bytes;
2405   unsigned int type_align_in_bits;
2406   unsigned HOST_WIDE_INT type_size_in_bits;
2407   HOST_WIDE_INT object_offset_in_align_units;
2408   HOST_WIDE_INT object_offset_in_bits;
2409   HOST_WIDE_INT object_offset_in_bytes;
2410   tree type;
2411   tree field_size_tree;
2412   HOST_WIDE_INT bitpos_int;
2413   HOST_WIDE_INT deepest_bitpos;
2414   unsigned HOST_WIDE_INT field_size_in_bits;
2415
2416   if (TREE_CODE (decl) == ERROR_MARK)
2417     return 0;
2418
2419   if (TREE_CODE (decl) != FIELD_DECL)
2420     abort ();
2421
2422   type = field_type (decl);
2423   field_size_tree = DECL_SIZE (decl);
2424
2425   /* The size could be unspecified if there was an error, or for
2426      a flexible array member.  */
2427   if (! field_size_tree)
2428     field_size_tree = bitsize_zero_node;
2429
2430   /* We cannot yet cope with fields whose positions or sizes are variable,
2431      so for now, when we see such things, we simply return 0.  Someday,
2432      we may be able to handle such cases, but it will be damn difficult.  */
2433
2434   if (! host_integerp (bit_position (decl), 0)
2435       || ! host_integerp (field_size_tree, 1))
2436     return 0;
2437
2438   bitpos_int = int_bit_position (decl);
2439   field_size_in_bits = tree_low_cst (field_size_tree, 1);
2440
2441   type_size_in_bits = simple_type_size_in_bits (type);
2442   type_align_in_bits = simple_type_align_in_bits (type);
2443   type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2444
2445   /* Note that the GCC front-end doesn't make any attempt to keep track
2446      of the starting bit offset (relative to the start of the containing
2447      structure type) of the hypothetical "containing object" for a bit-
2448      field.  Thus, when computing the byte offset value for the start of
2449      the "containing object" of a bit-field, we must deduce this infor-
2450      mation on our own.
2451
2452      This can be rather tricky to do in some cases.  For example, handling
2453      the following structure type definition when compiling for an i386/i486
2454      target (which only aligns long long's to 32-bit boundaries) can be very
2455      tricky:
2456
2457                 struct S {
2458                         int             field1;
2459                         long long       field2:31;
2460                 };
2461
2462      Fortunately, there is a simple rule-of-thumb which can be used in such
2463      cases.  When compiling for an i386/i486, GCC will allocate 8 bytes for
2464      the structure shown above.  It decides to do this based upon one simple
2465      rule for bit-field allocation.  Quite simply, GCC allocates each "con-
2466      taining object" for each bit-field at the first (i.e. lowest addressed)
2467      legitimate alignment boundary (based upon the required minimum alignment
2468      for the declared type of the field) which it can possibly use, subject
2469      to the condition that there is still enough available space remaining
2470      in the containing object (when allocated at the selected point) to
2471      fully accommodate all of the bits of the bit-field itself.
2472
2473      This simple rule makes it obvious why GCC allocates 8 bytes for each
2474      object of the structure type shown above.  When looking for a place to
2475      allocate the "containing object" for `field2', the compiler simply tries
2476      to allocate a 64-bit "containing object" at each successive 32-bit
2477      boundary (starting at zero) until it finds a place to allocate that 64-
2478      bit field such that at least 31 contiguous (and previously unallocated)
2479      bits remain within that selected 64 bit field.  (As it turns out, for
2480      the example above, the compiler finds that it is OK to allocate the
2481      "containing object" 64-bit field at bit-offset zero within the
2482      structure type.)
2483
2484      Here we attempt to work backwards from the limited set of facts we're
2485      given, and we try to deduce from those facts, where GCC must have
2486      believed that the containing object started (within the structure type).
2487
2488      The value we deduce is then used (by the callers of this routine) to
2489      generate AT_location and AT_bit_offset attributes for fields (both
2490      bit-fields and, in the case of AT_location, regular fields as well).  */
2491
2492   /* Figure out the bit-distance from the start of the structure to the
2493      "deepest" bit of the bit-field.  */
2494   deepest_bitpos = bitpos_int + field_size_in_bits;
2495
2496   /* This is the tricky part.  Use some fancy footwork to deduce where the
2497      lowest addressed bit of the containing object must be.  */
2498   object_offset_in_bits
2499     = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2500
2501   /* Compute the offset of the containing object in "alignment units".  */
2502   object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2503
2504   /* Compute the offset of the containing object in bytes.  */
2505   object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2506
2507   /* The above code assumes that the field does not cross an alignment
2508      boundary.  This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2509      or if the structure is packed.  If this happens, then we get an object
2510      which starts after the bitfield, which means that the bit offset is
2511      negative.  Gdb fails when given negative bit offsets.  We avoid this
2512      by recomputing using the first bit of the bitfield.  This will give
2513      us an object which does not completely contain the bitfield, but it
2514      will be aligned, and it will contain the first bit of the bitfield.
2515
2516      However, only do this for a BYTES_BIG_ENDIAN target.  For a
2517      ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2518      first bit of the bitfield.  If we recompute using bitpos_int + 1 below,
2519      then we end up computing the object byte offset for the wrong word of the
2520      desired bitfield, which in turn causes the field offset to be negative
2521      in bit_offset_attribute.  */
2522   if (BYTES_BIG_ENDIAN
2523       && object_offset_in_bits > bitpos_int)
2524     {
2525       deepest_bitpos = bitpos_int + 1;
2526       object_offset_in_bits
2527         = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2528       object_offset_in_align_units = (object_offset_in_bits
2529                                       / type_align_in_bits);
2530       object_offset_in_bytes = (object_offset_in_align_units
2531                                 * type_align_in_bytes);
2532     }
2533
2534   return object_offset_in_bytes;
2535 }
2536
2537 /****************************** attributes *********************************/
2538
2539 /* The following routines are responsible for writing out the various types
2540    of Dwarf attributes (and any following data bytes associated with them).
2541    These routines are listed in order based on the numerical codes of their
2542    associated attributes.  */
2543
2544 /* Generate an AT_sibling attribute.  */
2545
2546 static inline void
2547 sibling_attribute ()
2548 {
2549   char label[MAX_ARTIFICIAL_LABEL_BYTES];
2550
2551   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2552   sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2553   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2554 }
2555
2556 /* Output the form of location attributes suitable for whole variables and
2557    whole parameters.  Note that the location attributes for struct fields
2558    are generated by the routine `data_member_location_attribute' below.  */
2559
2560 static void
2561 location_attribute (rtl)
2562      rtx rtl;
2563 {
2564   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2565   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2566
2567   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2568   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2569   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2570   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2571   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2572
2573   /* Handle a special case.  If we are about to output a location descriptor
2574      for a variable or parameter which has been optimized out of existence,
2575      don't do that.  Instead we output a zero-length location descriptor
2576      value as part of the location attribute.
2577
2578      A variable which has been optimized out of existence will have a
2579      DECL_RTL value which denotes a pseudo-reg.
2580
2581      Currently, in some rare cases, variables can have DECL_RTL values
2582      which look like (MEM (REG pseudo-reg#)).  These cases are due to
2583      bugs elsewhere in the compiler.  We treat such cases
2584      as if the variable(s) in question had been optimized out of existence.
2585
2586      Note that in all cases where we wish to express the fact that a
2587      variable has been optimized out of existence, we do not simply
2588      suppress the generation of the entire location attribute because
2589      the absence of a location attribute in certain kinds of DIEs is
2590      used to indicate something else entirely... i.e. that the DIE
2591      represents an object declaration, but not a definition.  So saith
2592      the PLSIG.
2593   */
2594
2595   if (! is_pseudo_reg (rtl)
2596       && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2597     output_loc_descriptor (rtl);
2598
2599   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2600 }
2601
2602 /* Output the specialized form of location attribute used for data members
2603    of struct and union types.
2604
2605    In the special case of a FIELD_DECL node which represents a bit-field,
2606    the "offset" part of this special location descriptor must indicate the
2607    distance in bytes from the lowest-addressed byte of the containing
2608    struct or union type to the lowest-addressed byte of the "containing
2609    object" for the bit-field.  (See the `field_byte_offset' function above.)
2610
2611    For any given bit-field, the "containing object" is a hypothetical
2612    object (of some integral or enum type) within which the given bit-field
2613    lives.  The type of this hypothetical "containing object" is always the
2614    same as the declared type of the individual bit-field itself (for GCC
2615    anyway... the DWARF spec doesn't actually mandate this).
2616
2617    Note that it is the size (in bytes) of the hypothetical "containing
2618    object" which will be given in the AT_byte_size attribute for this
2619    bit-field.  (See the `byte_size_attribute' function below.)  It is
2620    also used when calculating the value of the AT_bit_offset attribute.
2621    (See the `bit_offset_attribute' function below.)  */
2622
2623 static void
2624 data_member_location_attribute (t)
2625      tree t;
2626 {
2627   unsigned object_offset_in_bytes;
2628   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2629   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2630
2631   if (TREE_CODE (t) == TREE_VEC)
2632     object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2633   else
2634     object_offset_in_bytes = field_byte_offset (t);
2635
2636   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2637   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2638   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2639   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2640   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2641   ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2642   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2643   ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2644   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2645 }
2646
2647 /* Output an AT_const_value attribute for a variable or a parameter which
2648    does not have a "location" either in memory or in a register.  These
2649    things can arise in GNU C when a constant is passed as an actual
2650    parameter to an inlined function.  They can also arise in C++ where
2651    declared constants do not necessarily get memory "homes".  */
2652
2653 static void
2654 const_value_attribute (rtl)
2655      rtx rtl;
2656 {
2657   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2658   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2659
2660   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2661   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2662   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2663   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2664   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2665
2666   switch (GET_CODE (rtl))
2667     {
2668       case CONST_INT:
2669         /* Note that a CONST_INT rtx could represent either an integer or
2670            a floating-point constant.  A CONST_INT is used whenever the
2671            constant will fit into a single word.  In all such cases, the
2672            original mode of the constant value is wiped out, and the
2673            CONST_INT rtx is assigned VOIDmode.  Since we no longer have
2674            precise mode information for these constants, we always just
2675            output them using 4 bytes.  */
2676
2677         ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2678         break;
2679
2680       case CONST_DOUBLE:
2681         /* Note that a CONST_DOUBLE rtx could represent either an integer
2682            or a floating-point constant.  A CONST_DOUBLE is used whenever
2683            the constant requires more than one word in order to be adequately
2684            represented.  In all such cases, the original mode of the constant
2685            value is preserved as the mode of the CONST_DOUBLE rtx, but for
2686            simplicity we always just output CONST_DOUBLEs using 8 bytes.  */
2687
2688         ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2689                                 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2690                                 (unsigned int) CONST_DOUBLE_LOW (rtl));
2691         break;
2692
2693       case CONST_STRING:
2694         ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2695         break;
2696
2697       case SYMBOL_REF:
2698       case LABEL_REF:
2699       case CONST:
2700         ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2701         break;
2702
2703       case PLUS:
2704         /* In cases where an inlined instance of an inline function is passed
2705            the address of an `auto' variable (which is local to the caller)
2706            we can get a situation where the DECL_RTL of the artificial
2707            local variable (for the inlining) which acts as a stand-in for
2708            the corresponding formal parameter (of the inline function)
2709            will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2710            This is not exactly a compile-time constant expression, but it
2711            isn't the address of the (artificial) local variable either.
2712            Rather, it represents the *value* which the artificial local
2713            variable always has during its lifetime.  We currently have no
2714            way to represent such quasi-constant values in Dwarf, so for now
2715            we just punt and generate an AT_const_value attribute with form
2716            FORM_BLOCK4 and a length of zero.  */
2717         break;
2718
2719       default:
2720         abort ();  /* No other kinds of rtx should be possible here.  */
2721     }
2722
2723   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2724 }
2725
2726 /* Generate *either* an AT_location attribute or else an AT_const_value
2727    data attribute for a variable or a parameter.  We generate the
2728    AT_const_value attribute only in those cases where the given
2729    variable or parameter does not have a true "location" either in
2730    memory or in a register.  This can happen (for example) when a
2731    constant is passed as an actual argument in a call to an inline
2732    function.  (It's possible that these things can crop up in other
2733    ways also.)  Note that one type of constant value which can be
2734    passed into an inlined function is a constant pointer.  This can
2735    happen for example if an actual argument in an inlined function
2736    call evaluates to a compile-time constant address.  */
2737
2738 static void
2739 location_or_const_value_attribute (decl)
2740      tree decl;
2741 {
2742   rtx rtl;
2743
2744   if (TREE_CODE (decl) == ERROR_MARK)
2745     return;
2746
2747   if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2748     {
2749       /* Should never happen.  */
2750       abort ();
2751       return;
2752     }
2753
2754   /* Here we have to decide where we are going to say the parameter "lives"
2755      (as far as the debugger is concerned).  We only have a couple of choices.
2756      GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.  DECL_RTL
2757      normally indicates where the parameter lives during most of the activa-
2758      tion of the function.  If optimization is enabled however, this could
2759      be either NULL or else a pseudo-reg.  Both of those cases indicate that
2760      the parameter doesn't really live anywhere (as far as the code generation
2761      parts of GCC are concerned) during most of the function's activation.
2762      That will happen (for example) if the parameter is never referenced
2763      within the function.
2764
2765      We could just generate a location descriptor here for all non-NULL
2766      non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2767      be a little nicer than that if we also consider DECL_INCOMING_RTL in
2768      cases where DECL_RTL is NULL or is a pseudo-reg.
2769
2770      Note however that we can only get away with using DECL_INCOMING_RTL as
2771      a backup substitute for DECL_RTL in certain limited cases.  In cases
2772      where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2773      we can be sure that the parameter was passed using the same type as it
2774      is declared to have within the function, and that its DECL_INCOMING_RTL
2775      points us to a place where a value of that type is passed.  In cases
2776      where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2777      however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2778      substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2779      points us to a value of some type which is *different* from the type
2780      of the parameter itself.  Thus, if we tried to use DECL_INCOMING_RTL
2781      to generate a location attribute in such cases, the debugger would
2782      end up (for example) trying to fetch a `float' from a place which
2783      actually contains the first part of a `double'.  That would lead to
2784      really incorrect and confusing output at debug-time, and we don't
2785      want that now do we?
2786
2787      So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2788      in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl).  There are a
2789      couple of cute exceptions however.  On little-endian machines we can
2790      get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2791      not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2792      an integral type which is smaller than TREE_TYPE(decl).  These cases
2793      arise when (on a little-endian machine) a non-prototyped function has
2794      a parameter declared to be of type `short' or `char'.  In such cases,
2795      TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2796      `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2797      passed `int' value.  If the debugger then uses that address to fetch a
2798      `short' or a `char' (on a little-endian machine) the result will be the
2799      correct data, so we allow for such exceptional cases below.
2800
2801      Note that our goal here is to describe the place where the given formal
2802      parameter lives during most of the function's activation (i.e. between
2803      the end of the prologue and the start of the epilogue).  We'll do that
2804      as best as we can.  Note however that if the given formal parameter is
2805      modified sometime during the execution of the function, then a stack
2806      backtrace (at debug-time) will show the function as having been called
2807      with the *new* value rather than the value which was originally passed
2808      in.  This happens rarely enough that it is not a major problem, but it
2809      *is* a problem, and I'd like to fix it.  A future version of dwarfout.c
2810      may generate two additional attributes for any given TAG_formal_parameter
2811      DIE which will describe the "passed type" and the "passed location" for
2812      the given formal parameter in addition to the attributes we now generate
2813      to indicate the "declared type" and the "active location" for each
2814      parameter.  This additional set of attributes could be used by debuggers
2815      for stack backtraces.
2816
2817      Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2818      can be NULL also.  This happens (for example) for inlined-instances of
2819      inline function formal parameters which are never referenced.  This really
2820      shouldn't be happening.  All PARM_DECL nodes should get valid non-NULL
2821      DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2822      these values for inlined instances of inline function parameters, so
2823      when we see such cases, we are just out-of-luck for the time
2824      being (until integrate.c gets fixed).
2825   */
2826
2827   /* Use DECL_RTL as the "location" unless we find something better.  */
2828   rtl = DECL_RTL (decl);
2829
2830   if (TREE_CODE (decl) == PARM_DECL)
2831     if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2832       {
2833         /* This decl represents a formal parameter which was optimized out.  */
2834         tree declared_type = type_main_variant (TREE_TYPE (decl));
2835         tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2836
2837         /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2838            *all* cases where (rtl == NULL_RTX) just below.  */
2839
2840         if (declared_type == passed_type)
2841           rtl = DECL_INCOMING_RTL (decl);
2842         else if (! BYTES_BIG_ENDIAN)
2843           if (TREE_CODE (declared_type) == INTEGER_TYPE)
2844             /* NMS WTF? */
2845             if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2846               rtl = DECL_INCOMING_RTL (decl);
2847       }
2848
2849   if (rtl == NULL_RTX)
2850     return;
2851
2852   rtl = eliminate_regs (rtl, 0, NULL_RTX);
2853 #ifdef LEAF_REG_REMAP
2854   if (current_function_uses_only_leaf_regs)
2855     leaf_renumber_regs_insn (rtl);
2856 #endif
2857
2858   switch (GET_CODE (rtl))
2859     {
2860     case ADDRESSOF:
2861       /* The address of a variable that was optimized away; don't emit
2862          anything.  */
2863       break;
2864
2865     case CONST_INT:
2866     case CONST_DOUBLE:
2867     case CONST_STRING:
2868     case SYMBOL_REF:
2869     case LABEL_REF:
2870     case CONST:
2871     case PLUS:  /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2872       const_value_attribute (rtl);
2873       break;
2874
2875     case MEM:
2876     case REG:
2877     case SUBREG:
2878       location_attribute (rtl);
2879       break;
2880
2881     case CONCAT:
2882       /* ??? CONCAT is used for complex variables, which may have the real
2883          part stored in one place and the imag part stored somewhere else.
2884          DWARF1 has no way to describe a variable that lives in two different
2885          places, so we just describe where the first part lives, and hope that
2886          the second part is stored after it.  */
2887       location_attribute (XEXP (rtl, 0));
2888       break;
2889
2890     default:
2891       abort ();         /* Should never happen.  */
2892     }
2893 }
2894
2895 /* Generate an AT_name attribute given some string value to be included as
2896    the value of the attribute.  */
2897
2898 static inline void
2899 name_attribute (name_string)
2900      const char *name_string;
2901 {
2902   if (name_string && *name_string)
2903     {
2904       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2905       ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2906     }
2907 }
2908
2909 static inline void
2910 fund_type_attribute (ft_code)
2911      unsigned ft_code;
2912 {
2913   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2914   ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2915 }
2916
2917 static void
2918 mod_fund_type_attribute (type, decl_const, decl_volatile)
2919      tree type;
2920      int decl_const;
2921      int decl_volatile;
2922 {
2923   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2924   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2925
2926   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2927   sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2928   sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2929   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2930   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2931   write_modifier_bytes (type, decl_const, decl_volatile);
2932   ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2933                               fundamental_type_code (root_type (type)));
2934   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2935 }
2936
2937 static inline void
2938 user_def_type_attribute (type)
2939      tree type;
2940 {
2941   char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2942
2943   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2944   sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2945   ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2946 }
2947
2948 static void
2949 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2950      tree type;
2951      int decl_const;
2952      int decl_volatile;
2953 {
2954   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2955   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2956   char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2957
2958   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2959   sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2960   sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2961   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2962   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2963   write_modifier_bytes (type, decl_const, decl_volatile);
2964   sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2965   ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2966   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2967 }
2968
2969 #ifdef USE_ORDERING_ATTRIBUTE
2970 static inline void
2971 ordering_attribute (ordering)
2972      unsigned ordering;
2973 {
2974   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2975   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2976 }
2977 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2978
2979 /* Note that the block of subscript information for an array type also
2980    includes information about the element type of type given array type.  */
2981
2982 static void
2983 subscript_data_attribute (type)
2984      tree type;
2985 {
2986   unsigned dimension_number;
2987   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2988   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2989
2990   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2991   sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2992   sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2993   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2994   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2995
2996   /* The GNU compilers represent multidimensional array types as sequences
2997      of one dimensional array types whose element types are themselves array
2998      types.  Here we squish that down, so that each multidimensional array
2999      type gets only one array_type DIE in the Dwarf debugging info.  The
3000      draft Dwarf specification say that we are allowed to do this kind
3001      of compression in C (because there is no difference between an
3002      array or arrays and a multidimensional array in C) but for other
3003      source languages (e.g. Ada) we probably shouldn't do this.  */
3004
3005   for (dimension_number = 0;
3006         TREE_CODE (type) == ARRAY_TYPE;
3007         type = TREE_TYPE (type), dimension_number++)
3008     {
3009       tree domain = TYPE_DOMAIN (type);
3010
3011       /* Arrays come in three flavors.  Unspecified bounds, fixed
3012          bounds, and (in GNU C only) variable bounds.  Handle all
3013          three forms here.  */
3014
3015       if (domain)
3016         {
3017           /* We have an array type with specified bounds.  */
3018
3019           tree lower = TYPE_MIN_VALUE (domain);
3020           tree upper = TYPE_MAX_VALUE (domain);
3021
3022           /* Handle only fundamental types as index types for now.  */
3023           if (! type_is_fundamental (domain))
3024             abort ();
3025
3026           /* Output the representation format byte for this dimension.  */
3027           ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
3028                   FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
3029                             upper && TREE_CODE (upper) == INTEGER_CST));
3030
3031           /* Output the index type for this dimension.  */
3032           ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
3033                                       fundamental_type_code (domain));
3034
3035           /* Output the representation for the lower bound.  */
3036           output_bound_representation (lower, dimension_number, 'l');
3037
3038           /* Output the representation for the upper bound.  */
3039           if (upper)
3040             output_bound_representation (upper, dimension_number, 'u');
3041           else
3042             ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3043         }
3044       else
3045         {
3046           /* We have an array type with an unspecified length.  For C and
3047              C++ we can assume that this really means that (a) the index
3048              type is an integral type, and (b) the lower bound is zero.
3049              Note that Dwarf defines the representation of an unspecified
3050              (upper) bound as being a zero-length location description.  */
3051
3052           /* Output the array-bounds format byte.  */
3053
3054           ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
3055
3056           /* Output the (assumed) index type.  */
3057
3058           ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
3059
3060           /* Output the (assumed) lower bound (constant) value.  */
3061
3062           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3063
3064           /* Output the (empty) location description for the upper bound.  */
3065
3066           ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
3067         }
3068     }
3069
3070   /* Output the prefix byte that says that the element type is coming up.  */
3071
3072   ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
3073
3074   /* Output a representation of the type of the elements of this array type.  */
3075
3076   type_attribute (type, 0, 0);
3077
3078   ASM_OUTPUT_LABEL (asm_out_file, end_label);
3079 }
3080
3081 static void
3082 byte_size_attribute (tree_node)
3083      tree tree_node;
3084 {
3085   unsigned size;
3086
3087   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
3088   switch (TREE_CODE (tree_node))
3089     {
3090       case ERROR_MARK:
3091         size = 0;
3092         break;
3093
3094       case ENUMERAL_TYPE:
3095       case RECORD_TYPE:
3096       case UNION_TYPE:
3097       case QUAL_UNION_TYPE:
3098       case ARRAY_TYPE:
3099         size = int_size_in_bytes (tree_node);
3100         break;
3101
3102       case FIELD_DECL:
3103         /* For a data member of a struct or union, the AT_byte_size is
3104            generally given as the number of bytes normally allocated for
3105            an object of the *declared* type of the member itself.  This
3106            is true even for bit-fields.  */
3107         size = simple_type_size_in_bits (field_type (tree_node))
3108                / BITS_PER_UNIT;
3109         break;
3110
3111       default:
3112         abort ();
3113     }
3114
3115   /* Note that `size' might be -1 when we get to this point.  If it
3116      is, that indicates that the byte size of the entity in question
3117      is variable.  We have no good way of expressing this fact in Dwarf
3118      at the present time, so just let the -1 pass on through.  */
3119
3120   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
3121 }
3122
3123 /* For a FIELD_DECL node which represents a bit-field, output an attribute
3124    which specifies the distance in bits from the highest order bit of the
3125    "containing object" for the bit-field to the highest order bit of the
3126    bit-field itself.
3127
3128    For any given bit-field, the "containing object" is a hypothetical
3129    object (of some integral or enum type) within which the given bit-field
3130    lives.  The type of this hypothetical "containing object" is always the
3131    same as the declared type of the individual bit-field itself.
3132
3133    The determination of the exact location of the "containing object" for
3134    a bit-field is rather complicated.  It's handled by the `field_byte_offset'
3135    function (above).
3136
3137    Note that it is the size (in bytes) of the hypothetical "containing
3138    object" which will be given in the AT_byte_size attribute for this
3139    bit-field.  (See `byte_size_attribute' above.) */
3140
3141 static inline void
3142 bit_offset_attribute (decl)
3143      tree decl;
3144 {
3145   HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
3146   tree type = DECL_BIT_FIELD_TYPE (decl);
3147   HOST_WIDE_INT bitpos_int;
3148   HOST_WIDE_INT highest_order_object_bit_offset;
3149   HOST_WIDE_INT highest_order_field_bit_offset;
3150   HOST_WIDE_INT bit_offset;
3151
3152   /* Must be a bit field.  */
3153   if (!type
3154       || TREE_CODE (decl) != FIELD_DECL)
3155     abort ();
3156
3157   /* We can't yet handle bit-fields whose offsets or sizes are variable, so
3158      if we encounter such things, just return without generating any
3159      attribute whatsoever.  */
3160
3161   if (! host_integerp (bit_position (decl), 0)
3162       || ! host_integerp (DECL_SIZE (decl), 1))
3163     return;
3164
3165   bitpos_int = int_bit_position (decl);
3166
3167   /* Note that the bit offset is always the distance (in bits) from the
3168      highest-order bit of the "containing object" to the highest-order
3169      bit of the bit-field itself.  Since the "high-order end" of any
3170      object or field is different on big-endian and little-endian machines,
3171      the computation below must take account of these differences.  */
3172
3173   highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
3174   highest_order_field_bit_offset = bitpos_int;
3175
3176   if (! BYTES_BIG_ENDIAN)
3177     {
3178       highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
3179       highest_order_object_bit_offset += simple_type_size_in_bits (type);
3180     }
3181
3182   bit_offset =
3183     (! BYTES_BIG_ENDIAN
3184      ? highest_order_object_bit_offset - highest_order_field_bit_offset
3185      : highest_order_field_bit_offset - highest_order_object_bit_offset);
3186
3187   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
3188   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
3189 }
3190
3191 /* For a FIELD_DECL node which represents a bit field, output an attribute
3192    which specifies the length in bits of the given field.  */
3193
3194 static inline void
3195 bit_size_attribute (decl)
3196     tree decl;
3197 {
3198   /* Must be a field and a bit field.  */
3199   if (TREE_CODE (decl) != FIELD_DECL
3200       || ! DECL_BIT_FIELD_TYPE (decl))
3201     abort ();
3202
3203   if (host_integerp (DECL_SIZE (decl), 1))
3204     {
3205       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
3206       ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3207                               tree_low_cst (DECL_SIZE (decl), 1));
3208     }
3209 }
3210
3211 /* The following routine outputs the `element_list' attribute for enumeration
3212    type DIEs.  The element_lits attribute includes the names and values of
3213    all of the enumeration constants associated with the given enumeration
3214    type.  */
3215
3216 static inline void
3217 element_list_attribute (element)
3218      tree element;
3219 {
3220   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3221   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3222
3223   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
3224   sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
3225   sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
3226   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3227   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3228
3229   /* Here we output a list of value/name pairs for each enumeration constant
3230      defined for this enumeration type (as required), but we do it in REVERSE
3231      order.  The order is the one required by the draft #5 Dwarf specification
3232      published by the UI/PLSIG.  */
3233
3234   output_enumeral_list (element);   /* Recursively output the whole list.  */
3235
3236   ASM_OUTPUT_LABEL (asm_out_file, end_label);
3237 }
3238
3239 /* Generate an AT_stmt_list attribute.  These are normally present only in
3240    DIEs with a TAG_compile_unit tag.  */
3241
3242 static inline void
3243 stmt_list_attribute (label)
3244     const char *label;
3245 {
3246   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
3247   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
3248   ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3249 }
3250
3251 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
3252    for a subroutine DIE.  */
3253
3254 static inline void
3255 low_pc_attribute (asm_low_label)
3256      const char *asm_low_label;
3257 {
3258   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
3259   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
3260 }
3261
3262 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
3263    subroutine DIE.  */
3264
3265 static inline void
3266 high_pc_attribute (asm_high_label)
3267      const char *asm_high_label;
3268 {
3269   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
3270   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
3271 }
3272
3273 /* Generate an AT_body_begin attribute for a subroutine DIE.  */
3274
3275 static inline void
3276 body_begin_attribute (asm_begin_label)
3277      const char *asm_begin_label;
3278 {
3279   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
3280   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
3281 }
3282
3283 /* Generate an AT_body_end attribute for a subroutine DIE.  */
3284
3285 static inline void
3286 body_end_attribute (asm_end_label)
3287      const char *asm_end_label;
3288 {
3289   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
3290   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
3291 }
3292
3293 /* Generate an AT_language attribute given a LANG value.  These attributes
3294    are used only within TAG_compile_unit DIEs.  */
3295
3296 static inline void
3297 language_attribute (language_code)
3298      unsigned language_code;
3299 {
3300   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
3301   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
3302 }
3303
3304 static inline void
3305 member_attribute (context)
3306      tree context;
3307 {
3308   char label[MAX_ARTIFICIAL_LABEL_BYTES];
3309
3310   /* Generate this attribute only for members in C++.  */
3311
3312   if (context != NULL && is_tagged_type (context))
3313     {
3314       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
3315       sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
3316       ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3317     }
3318 }
3319
3320 #if 0
3321 static inline void
3322 string_length_attribute (upper_bound)
3323      tree upper_bound;
3324 {
3325   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3326   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3327
3328   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
3329   sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
3330   sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
3331   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
3332   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3333   output_bound_representation (upper_bound, 0, 'u');
3334   ASM_OUTPUT_LABEL (asm_out_file, end_label);
3335 }
3336 #endif
3337
3338 static inline void
3339 comp_dir_attribute (dirname)
3340      const char *dirname;
3341 {
3342   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
3343   ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
3344 }
3345
3346 static inline void
3347 sf_names_attribute (sf_names_start_label)
3348      const char *sf_names_start_label;
3349 {
3350   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
3351   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
3352   ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
3353 }
3354
3355 static inline void
3356 src_info_attribute (src_info_start_label)
3357      const char *src_info_start_label;
3358 {
3359   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
3360   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
3361   ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
3362 }
3363
3364 static inline void
3365 mac_info_attribute (mac_info_start_label)
3366      const char *mac_info_start_label;
3367 {
3368   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
3369   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
3370   ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
3371 }
3372
3373 static inline void
3374 prototyped_attribute (func_type)
3375      tree func_type;
3376 {
3377   if ((strcmp (lang_hooks.name, "GNU C") == 0)
3378       && (TYPE_ARG_TYPES (func_type) != NULL))
3379     {
3380       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
3381       ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3382     }
3383 }
3384
3385 static inline void
3386 producer_attribute (producer)
3387      const char *producer;
3388 {
3389   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
3390   ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
3391 }
3392
3393 static inline void
3394 inline_attribute (decl)
3395      tree decl;
3396 {
3397   if (DECL_INLINE (decl))
3398     {
3399       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3400       ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3401     }
3402 }
3403
3404 static inline void
3405 containing_type_attribute (containing_type)
3406      tree containing_type;
3407 {
3408   char label[MAX_ARTIFICIAL_LABEL_BYTES];
3409
3410   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3411   sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3412   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3413 }
3414
3415 static inline void
3416 abstract_origin_attribute (origin)
3417      tree origin;
3418 {
3419   char label[MAX_ARTIFICIAL_LABEL_BYTES];
3420
3421   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3422   switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3423     {
3424     case 'd':
3425       sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3426       break;
3427
3428     case 't':
3429       sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3430       break;
3431
3432     default:
3433       abort ();         /* Should never happen.  */
3434
3435     }
3436   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3437 }
3438
3439 #ifdef DWARF_DECL_COORDINATES
3440 static inline void
3441 src_coords_attribute (src_fileno, src_lineno)
3442      unsigned src_fileno;
3443      unsigned src_lineno;
3444 {
3445   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3446   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3447   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3448 }
3449 #endif /* defined(DWARF_DECL_COORDINATES) */
3450
3451 static inline void
3452 pure_or_virtual_attribute (func_decl)
3453      tree func_decl;
3454 {
3455   if (DECL_VIRTUAL_P (func_decl))
3456     {
3457 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific.  */
3458       if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3459         ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3460       else
3461 #endif
3462         ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3463       ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3464     }
3465 }
3466
3467 /************************* end of attributes *****************************/
3468
3469 /********************* utility routines for DIEs *************************/
3470
3471 /* Output an AT_name attribute and an AT_src_coords attribute for the
3472    given decl, but only if it actually has a name.  */
3473
3474 static void
3475 name_and_src_coords_attributes (decl)
3476     tree decl;
3477 {
3478   tree decl_name = DECL_NAME (decl);
3479
3480   if (decl_name && IDENTIFIER_POINTER (decl_name))
3481     {
3482       name_attribute (IDENTIFIER_POINTER (decl_name));
3483 #ifdef DWARF_DECL_COORDINATES
3484       {
3485         register unsigned file_index;
3486
3487         /* This is annoying, but we have to pop out of the .debug section
3488            for a moment while we call `lookup_filename' because calling it
3489            may cause a temporary switch into the .debug_sfnames section and
3490            most svr4 assemblers are not smart enough to be able to nest
3491            section switches to any depth greater than one.  Note that we
3492            also can't skirt this issue by delaying all output to the
3493            .debug_sfnames section unit the end of compilation because that
3494            would cause us to have inter-section forward references and
3495            Fred Fish sez that m68k/svr4 assemblers botch those.  */
3496
3497         ASM_OUTPUT_POP_SECTION (asm_out_file);
3498         file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3499         ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3500
3501         src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3502       }
3503 #endif /* defined(DWARF_DECL_COORDINATES) */
3504     }
3505 }
3506
3507 /* Many forms of DIEs contain a "type description" part.  The following
3508    routine writes out these "type descriptor" parts.  */
3509
3510 static void
3511 type_attribute (type, decl_const, decl_volatile)
3512      tree type;
3513      int decl_const;
3514      int decl_volatile;
3515 {
3516   enum tree_code code = TREE_CODE (type);
3517   int root_type_modified;
3518
3519   if (code == ERROR_MARK)
3520     return;
3521
3522   /* Handle a special case.  For functions whose return type is void,
3523      we generate *no* type attribute.  (Note that no object may have
3524      type `void', so this only applies to function return types.  */
3525
3526   if (code == VOID_TYPE)
3527     return;
3528
3529   /* If this is a subtype, find the underlying type.  Eventually,
3530      this should write out the appropriate subtype info.  */
3531   while ((code == INTEGER_TYPE || code == REAL_TYPE)
3532          && TREE_TYPE (type) != 0)
3533     type = TREE_TYPE (type), code = TREE_CODE (type);
3534
3535   root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3536                         || decl_const || decl_volatile
3537                         || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3538
3539   if (type_is_fundamental (root_type (type)))
3540     {
3541       if (root_type_modified)
3542         mod_fund_type_attribute (type, decl_const, decl_volatile);
3543       else
3544         fund_type_attribute (fundamental_type_code (type));
3545     }
3546   else
3547     {
3548       if (root_type_modified)
3549         mod_u_d_type_attribute (type, decl_const, decl_volatile);
3550       else
3551         /* We have to get the type_main_variant here (and pass that to the
3552            `user_def_type_attribute' routine) because the ..._TYPE node we
3553            have might simply be a *copy* of some original type node (where
3554            the copy was created to help us keep track of typedef names)
3555            and that copy might have a different TYPE_UID from the original
3556            ..._TYPE node.  (Note that when `equate_type_number_to_die_number'
3557            is labeling a given type DIE for future reference, it always and
3558            only creates labels for DIEs representing *main variants*, and it
3559            never even knows about non-main-variants.)  */
3560         user_def_type_attribute (type_main_variant (type));
3561     }
3562 }
3563
3564 /* Given a tree pointer to a struct, class, union, or enum type node, return
3565    a pointer to the (string) tag name for the given type, or zero if the
3566    type was declared without a tag.  */
3567
3568 static const char *
3569 type_tag (type)
3570      tree type;
3571 {
3572   const char *name = 0;
3573
3574   if (TYPE_NAME (type) != 0)
3575     {
3576       tree t = 0;
3577
3578       /* Find the IDENTIFIER_NODE for the type name.  */
3579       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3580         t = TYPE_NAME (type);
3581
3582       /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3583          a TYPE_DECL node, regardless of whether or not a `typedef' was
3584          involved.  */
3585       else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3586                && ! DECL_IGNORED_P (TYPE_NAME (type)))
3587           t = DECL_NAME (TYPE_NAME (type));
3588
3589       /* Now get the name as a string, or invent one.  */
3590       if (t != 0)
3591         name = IDENTIFIER_POINTER (t);
3592     }
3593
3594   return (name == 0 || *name == '\0') ? 0 : name;
3595 }
3596
3597 static inline void
3598 dienum_push ()
3599 {
3600   /* Start by checking if the pending_sibling_stack needs to be expanded.
3601      If necessary, expand it.  */
3602
3603   if (pending_siblings == pending_siblings_allocated)
3604     {
3605       pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3606       pending_sibling_stack
3607         = (unsigned *) xrealloc (pending_sibling_stack,
3608                                  pending_siblings_allocated * sizeof(unsigned));
3609     }
3610
3611   pending_siblings++;
3612   NEXT_DIE_NUM = next_unused_dienum++;
3613 }
3614
3615 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3616    NEXT_DIE_NUM.  */
3617
3618 static inline void
3619 dienum_pop ()
3620 {
3621   pending_siblings--;
3622 }
3623
3624 static inline tree
3625 member_declared_type (member)
3626      tree member;
3627 {
3628   return (DECL_BIT_FIELD_TYPE (member))
3629            ? DECL_BIT_FIELD_TYPE (member)
3630            : TREE_TYPE (member);
3631 }
3632
3633 /* Get the function's label, as described by its RTL.
3634    This may be different from the DECL_NAME name used
3635    in the source file.  */
3636
3637 static const char *
3638 function_start_label (decl)
3639     tree decl;
3640 {
3641   rtx x;
3642   const char *fnname;
3643
3644   x = DECL_RTL (decl);
3645   if (GET_CODE (x) != MEM)
3646     abort ();
3647   x = XEXP (x, 0);
3648   if (GET_CODE (x) != SYMBOL_REF)
3649                abort ();
3650   fnname = XSTR (x, 0);
3651   return fnname;
3652 }
3653
3654
3655 /******************************* DIEs ************************************/
3656
3657 /* Output routines for individual types of DIEs.  */
3658
3659 /* Note that every type of DIE (except a null DIE) gets a sibling.  */
3660
3661 static void
3662 output_array_type_die (arg)
3663      void *arg;
3664 {
3665   tree type = arg;
3666
3667   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3668   sibling_attribute ();
3669   equate_type_number_to_die_number (type);
3670   member_attribute (TYPE_CONTEXT (type));
3671
3672   /* I believe that we can default the array ordering.  SDB will probably
3673      do the right things even if AT_ordering is not present.  It's not
3674      even an issue until we start to get into multidimensional arrays
3675      anyway.  If SDB is ever caught doing the Wrong Thing for multi-
3676      dimensional arrays, then we'll have to put the AT_ordering attribute
3677      back in.  (But if and when we find out that we need to put these in,
3678      we will only do so for multidimensional arrays.  After all, we don't
3679      want to waste space in the .debug section now do we?)  */
3680
3681 #ifdef USE_ORDERING_ATTRIBUTE
3682   ordering_attribute (ORD_row_major);
3683 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3684
3685   subscript_data_attribute (type);
3686 }
3687
3688 static void
3689 output_set_type_die (arg)
3690      void *arg;
3691 {
3692   tree type = arg;
3693
3694   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3695   sibling_attribute ();
3696   equate_type_number_to_die_number (type);
3697   member_attribute (TYPE_CONTEXT (type));
3698   type_attribute (TREE_TYPE (type), 0, 0);
3699 }
3700
3701 #if 0
3702 /* Implement this when there is a GNU FORTRAN or GNU Ada front end.  */
3703
3704 static void
3705 output_entry_point_die (arg)
3706      void *arg;
3707 {
3708   tree decl = arg;
3709   tree origin = decl_ultimate_origin (decl);
3710
3711   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3712   sibling_attribute ();
3713   dienum_push ();
3714   if (origin != NULL)
3715     abstract_origin_attribute (origin);
3716   else
3717     {
3718       name_and_src_coords_attributes (decl);
3719       member_attribute (DECL_CONTEXT (decl));
3720       type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3721     }
3722   if (DECL_ABSTRACT (decl))
3723     equate_decl_number_to_die_number (decl);
3724   else
3725     low_pc_attribute (function_start_label (decl));
3726 }
3727 #endif
3728
3729 /* Output a DIE to represent an inlined instance of an enumeration type.  */
3730
3731 static void
3732 output_inlined_enumeration_type_die (arg)
3733      void *arg;
3734 {
3735   tree type = arg;
3736
3737   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3738   sibling_attribute ();
3739   if (!TREE_ASM_WRITTEN (type))
3740     abort ();
3741   abstract_origin_attribute (type);
3742 }
3743
3744 /* Output a DIE to represent an inlined instance of a structure type.  */
3745
3746 static void
3747 output_inlined_structure_type_die (arg)
3748      void *arg;
3749 {
3750   tree type = arg;
3751
3752   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3753   sibling_attribute ();
3754   if (!TREE_ASM_WRITTEN (type))
3755     abort ();
3756   abstract_origin_attribute (type);
3757 }
3758
3759 /* Output a DIE to represent an inlined instance of a union type.  */
3760
3761 static void
3762 output_inlined_union_type_die (arg)
3763      void *arg;
3764 {
3765   tree type = arg;
3766
3767   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3768   sibling_attribute ();
3769   if (!TREE_ASM_WRITTEN (type))
3770     abort ();
3771   abstract_origin_attribute (type);
3772 }
3773
3774 /* Output a DIE to represent an enumeration type.  Note that these DIEs
3775    include all of the information about the enumeration values also.
3776    This information is encoded into the element_list attribute.  */
3777
3778 static void
3779 output_enumeration_type_die (arg)
3780      void *arg;
3781 {
3782   tree type = arg;
3783
3784   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3785   sibling_attribute ();
3786   equate_type_number_to_die_number (type);
3787   name_attribute (type_tag (type));
3788   member_attribute (TYPE_CONTEXT (type));
3789
3790   /* Handle a GNU C/C++ extension, i.e. incomplete enum types.  If the
3791      given enum type is incomplete, do not generate the AT_byte_size
3792      attribute or the AT_element_list attribute.  */
3793
3794   if (COMPLETE_TYPE_P (type))
3795     {
3796       byte_size_attribute (type);
3797       element_list_attribute (TYPE_FIELDS (type));
3798     }
3799 }
3800
3801 /* Output a DIE to represent either a real live formal parameter decl or
3802    to represent just the type of some formal parameter position in some
3803    function type.
3804
3805    Note that this routine is a bit unusual because its argument may be
3806    a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3807    represents an inlining of some PARM_DECL) or else some sort of a
3808    ..._TYPE node.  If it's the former then this function is being called
3809    to output a DIE to represent a formal parameter object (or some inlining
3810    thereof).  If it's the latter, then this function is only being called
3811    to output a TAG_formal_parameter DIE to stand as a placeholder for some
3812    formal argument type of some subprogram type.  */
3813
3814 static void
3815 output_formal_parameter_die (arg)
3816      void *arg;
3817 {
3818   tree node = arg;
3819
3820   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3821   sibling_attribute ();
3822
3823   switch (TREE_CODE_CLASS (TREE_CODE (node)))
3824     {
3825     case 'd':   /* We were called with some kind of a ..._DECL node.  */
3826       {
3827         register tree origin = decl_ultimate_origin (node);
3828
3829         if (origin != NULL)
3830           abstract_origin_attribute (origin);
3831         else
3832           {
3833             name_and_src_coords_attributes (node);
3834             type_attribute (TREE_TYPE (node),
3835                             TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3836           }
3837         if (DECL_ABSTRACT (node))
3838           equate_decl_number_to_die_number (node);
3839         else
3840           location_or_const_value_attribute (node);
3841       }
3842       break;
3843
3844     case 't':   /* We were called with some kind of a ..._TYPE node.  */
3845       type_attribute (node, 0, 0);
3846       break;
3847
3848     default:
3849       abort (); /* Should never happen.  */
3850     }
3851 }
3852
3853 /* Output a DIE to represent a declared function (either file-scope
3854    or block-local) which has "external linkage" (according to ANSI-C).  */
3855
3856 static void
3857 output_global_subroutine_die (arg)
3858      void *arg;
3859 {
3860   tree decl = arg;
3861   tree origin = decl_ultimate_origin (decl);
3862
3863   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3864   sibling_attribute ();
3865   dienum_push ();
3866   if (origin != NULL)
3867     abstract_origin_attribute (origin);
3868   else
3869     {
3870       tree type = TREE_TYPE (decl);
3871
3872       name_and_src_coords_attributes (decl);
3873       inline_attribute (decl);
3874       prototyped_attribute (type);
3875       member_attribute (DECL_CONTEXT (decl));
3876       type_attribute (TREE_TYPE (type), 0, 0);
3877       pure_or_virtual_attribute (decl);
3878     }
3879   if (DECL_ABSTRACT (decl))
3880     equate_decl_number_to_die_number (decl);
3881   else
3882     {
3883       if (! DECL_EXTERNAL (decl) && ! in_class
3884           && decl == current_function_decl)
3885         {
3886           char label[MAX_ARTIFICIAL_LABEL_BYTES];
3887
3888           low_pc_attribute (function_start_label (decl));
3889           sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no);
3890           high_pc_attribute (label);
3891           if (use_gnu_debug_info_extensions)
3892             {
3893               sprintf (label, BODY_BEGIN_LABEL_FMT,
3894                        current_function_funcdef_no);
3895               body_begin_attribute (label);
3896               sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no);
3897               body_end_attribute (label);
3898             }
3899         }
3900     }
3901 }
3902
3903 /* Output a DIE to represent a declared data object (either file-scope
3904    or block-local) which has "external linkage" (according to ANSI-C).  */
3905
3906 static void
3907 output_global_variable_die (arg)
3908      void *arg;
3909 {
3910   tree decl = arg;
3911   tree origin = decl_ultimate_origin (decl);
3912
3913   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3914   sibling_attribute ();
3915   if (origin != NULL)
3916     abstract_origin_attribute (origin);
3917   else
3918     {
3919       name_and_src_coords_attributes (decl);
3920       member_attribute (DECL_CONTEXT (decl));
3921       type_attribute (TREE_TYPE (decl),
3922                       TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3923     }
3924   if (DECL_ABSTRACT (decl))
3925     equate_decl_number_to_die_number (decl);
3926   else
3927     {
3928       if (! DECL_EXTERNAL (decl) && ! in_class
3929           && current_function_decl == decl_function_context (decl))
3930         location_or_const_value_attribute (decl);
3931     }
3932 }
3933
3934 static void
3935 output_label_die (arg)
3936      void *arg;
3937 {
3938   tree decl = arg;
3939   tree origin = decl_ultimate_origin (decl);
3940
3941   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3942   sibling_attribute ();
3943   if (origin != NULL)
3944     abstract_origin_attribute (origin);
3945   else
3946     name_and_src_coords_attributes (decl);
3947   if (DECL_ABSTRACT (decl))
3948     equate_decl_number_to_die_number (decl);
3949   else
3950     {
3951       rtx insn = DECL_RTL (decl);
3952
3953       /* Deleted labels are programmer specified labels which have been
3954          eliminated because of various optimisations.  We still emit them
3955          here so that it is possible to put breakpoints on them.  */
3956       if (GET_CODE (insn) == CODE_LABEL
3957           || ((GET_CODE (insn) == NOTE
3958                && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
3959         {
3960           char label[MAX_ARTIFICIAL_LABEL_BYTES];
3961
3962           /* When optimization is enabled (via -O) some parts of the compiler
3963              (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3964              represent source-level labels which were explicitly declared by
3965              the user.  This really shouldn't be happening though, so catch
3966              it if it ever does happen.  */
3967
3968           if (INSN_DELETED_P (insn))
3969             abort ();   /* Should never happen.  */
3970
3971           ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
3972           low_pc_attribute (label);
3973         }
3974     }
3975 }
3976
3977 static void
3978 output_lexical_block_die (arg)
3979      void *arg;
3980 {
3981   tree stmt = arg;
3982
3983   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3984   sibling_attribute ();
3985   dienum_push ();
3986   if (! BLOCK_ABSTRACT (stmt))
3987     {
3988       char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3989       char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3990
3991       sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3992       low_pc_attribute (begin_label);
3993       sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3994       high_pc_attribute (end_label);
3995     }
3996 }
3997
3998 static void
3999 output_inlined_subroutine_die (arg)
4000      void *arg;
4001 {
4002   tree stmt = arg;
4003
4004   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
4005   sibling_attribute ();
4006   dienum_push ();
4007   abstract_origin_attribute (block_ultimate_origin (stmt));
4008   if (! BLOCK_ABSTRACT (stmt))
4009     {
4010       char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4011       char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4012
4013       sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
4014       low_pc_attribute (begin_label);
4015       sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
4016       high_pc_attribute (end_label);
4017     }
4018 }
4019
4020 /* Output a DIE to represent a declared data object (either file-scope
4021    or block-local) which has "internal linkage" (according to ANSI-C).  */
4022
4023 static void
4024 output_local_variable_die (arg)
4025      void *arg;
4026 {
4027   tree decl = arg;
4028   tree origin = decl_ultimate_origin (decl);
4029
4030   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
4031   sibling_attribute ();
4032   if (origin != NULL)
4033     abstract_origin_attribute (origin);
4034   else
4035     {
4036       name_and_src_coords_attributes (decl);
4037       member_attribute (DECL_CONTEXT (decl));
4038       type_attribute (TREE_TYPE (decl),
4039                       TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4040     }
4041   if (DECL_ABSTRACT (decl))
4042     equate_decl_number_to_die_number (decl);
4043   else
4044     location_or_const_value_attribute (decl);
4045 }
4046
4047 static void
4048 output_member_die (arg)
4049      void *arg;
4050 {
4051   tree decl = arg;
4052
4053   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
4054   sibling_attribute ();
4055   name_and_src_coords_attributes (decl);
4056   member_attribute (DECL_CONTEXT (decl));
4057   type_attribute (member_declared_type (decl),
4058                   TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4059   if (DECL_BIT_FIELD_TYPE (decl))       /* If this is a bit field...  */
4060     {
4061       byte_size_attribute (decl);
4062       bit_size_attribute (decl);
4063       bit_offset_attribute (decl);
4064     }
4065   data_member_location_attribute (decl);
4066 }
4067
4068 #if 0
4069 /* Don't generate either pointer_type DIEs or reference_type DIEs.  Use
4070    modified types instead.
4071
4072    We keep this code here just in case these types of DIEs may be
4073    needed to represent certain things in other languages (e.g. Pascal)
4074    someday.  */
4075
4076 static void
4077 output_pointer_type_die (arg)
4078      void *arg;
4079 {
4080   tree type = arg;
4081
4082   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
4083   sibling_attribute ();
4084   equate_type_number_to_die_number (type);
4085   member_attribute (TYPE_CONTEXT (type));
4086   type_attribute (TREE_TYPE (type), 0, 0);
4087 }
4088
4089 static void
4090 output_reference_type_die (arg)
4091      void *arg;
4092 {
4093   tree type = arg;
4094
4095   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
4096   sibling_attribute ();
4097   equate_type_number_to_die_number (type);
4098   member_attribute (TYPE_CONTEXT (type));
4099   type_attribute (TREE_TYPE (type), 0, 0);
4100 }
4101 #endif
4102
4103 static void
4104 output_ptr_to_mbr_type_die (arg)
4105      void *arg;
4106 {
4107   tree type = arg;
4108
4109   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
4110   sibling_attribute ();
4111   equate_type_number_to_die_number (type);
4112   member_attribute (TYPE_CONTEXT (type));
4113   containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
4114   type_attribute (TREE_TYPE (type), 0, 0);
4115 }
4116
4117 static void
4118 output_compile_unit_die (arg)
4119      void *arg;
4120 {
4121   const char *main_input_filename = arg;
4122   const char *language_string = lang_hooks.name;
4123
4124   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
4125   sibling_attribute ();
4126   dienum_push ();
4127   name_attribute (main_input_filename);
4128
4129   {
4130     char producer[250];
4131
4132     sprintf (producer, "%s %s", language_string, version_string);
4133     producer_attribute (producer);
4134   }
4135
4136   if (strcmp (language_string, "GNU C++") == 0)
4137     language_attribute (LANG_C_PLUS_PLUS);
4138   else if (strcmp (language_string, "GNU Ada") == 0)
4139     language_attribute (LANG_ADA83);
4140   else if (strcmp (language_string, "GNU F77") == 0)
4141     language_attribute (LANG_FORTRAN77);
4142   else if (strcmp (language_string, "GNU Pascal") == 0)
4143     language_attribute (LANG_PASCAL83);
4144   else if (strcmp (language_string, "GNU Java") == 0)
4145     language_attribute (LANG_JAVA);
4146   else
4147     language_attribute (LANG_C89);
4148   low_pc_attribute (TEXT_BEGIN_LABEL);
4149   high_pc_attribute (TEXT_END_LABEL);
4150   if (debug_info_level >= DINFO_LEVEL_NORMAL)
4151     stmt_list_attribute (LINE_BEGIN_LABEL);
4152
4153   {
4154     const char *wd = getpwd ();
4155     if (wd)
4156       comp_dir_attribute (wd);
4157   }
4158
4159   if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
4160     {
4161       sf_names_attribute (SFNAMES_BEGIN_LABEL);
4162       src_info_attribute (SRCINFO_BEGIN_LABEL);
4163       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4164         mac_info_attribute (MACINFO_BEGIN_LABEL);
4165     }
4166 }
4167
4168 static void
4169 output_string_type_die (arg)
4170      void *arg;
4171 {
4172   tree type = arg;
4173
4174   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
4175   sibling_attribute ();
4176   equate_type_number_to_die_number (type);
4177   member_attribute (TYPE_CONTEXT (type));
4178   /* this is a fixed length string */
4179   byte_size_attribute (type);
4180 }
4181
4182 static void
4183 output_inheritance_die (arg)
4184      void *arg;
4185 {
4186   tree binfo = arg;
4187
4188   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
4189   sibling_attribute ();
4190   type_attribute (BINFO_TYPE (binfo), 0, 0);
4191   data_member_location_attribute (binfo);
4192   if (TREE_VIA_VIRTUAL (binfo))
4193     {
4194       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
4195       ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4196     }
4197   if (TREE_VIA_PUBLIC (binfo))
4198     {
4199       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
4200       ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4201     }
4202   else if (TREE_VIA_PROTECTED (binfo))
4203     {
4204       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
4205       ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
4206     }
4207 }
4208
4209 static void
4210 output_structure_type_die (arg)
4211      void *arg;
4212 {
4213   tree type = arg;
4214
4215   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
4216   sibling_attribute ();
4217   equate_type_number_to_die_number (type);
4218   name_attribute (type_tag (type));
4219   member_attribute (TYPE_CONTEXT (type));
4220
4221   /* If this type has been completed, then give it a byte_size attribute
4222      and prepare to give a list of members.  Otherwise, don't do either of
4223      these things.  In the latter case, we will not be generating a list
4224      of members (since we don't have any idea what they might be for an
4225      incomplete type).  */
4226
4227   if (COMPLETE_TYPE_P (type))
4228     {
4229       dienum_push ();
4230       byte_size_attribute (type);
4231     }
4232 }
4233
4234 /* Output a DIE to represent a declared function (either file-scope
4235    or block-local) which has "internal linkage" (according to ANSI-C).  */
4236
4237 static void
4238 output_local_subroutine_die (arg)
4239      void *arg;
4240 {
4241   tree decl = arg;
4242   tree origin = decl_ultimate_origin (decl);
4243
4244   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
4245   sibling_attribute ();
4246   dienum_push ();
4247   if (origin != NULL)
4248     abstract_origin_attribute (origin);
4249   else
4250     {
4251       tree type = TREE_TYPE (decl);
4252
4253       name_and_src_coords_attributes (decl);
4254       inline_attribute (decl);
4255       prototyped_attribute (type);
4256       member_attribute (DECL_CONTEXT (decl));
4257       type_attribute (TREE_TYPE (type), 0, 0);
4258       pure_or_virtual_attribute (decl);
4259     }
4260   if (DECL_ABSTRACT (decl))
4261     equate_decl_number_to_die_number (decl);
4262   else
4263     {
4264       /* Avoid getting screwed up in cases where a function was declared
4265          static but where no definition was ever given for it.  */
4266
4267       if (TREE_ASM_WRITTEN (decl))
4268         {
4269           char label[MAX_ARTIFICIAL_LABEL_BYTES];
4270           low_pc_attribute (function_start_label (decl));
4271           sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no);
4272           high_pc_attribute (label);
4273           if (use_gnu_debug_info_extensions)
4274             {
4275               sprintf (label, BODY_BEGIN_LABEL_FMT,
4276                        current_function_funcdef_no);
4277               body_begin_attribute (label);
4278               sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no);
4279               body_end_attribute (label);
4280             }
4281         }
4282     }
4283 }
4284
4285 static void
4286 output_subroutine_type_die (arg)
4287      void *arg;
4288 {
4289   tree type = arg;
4290   tree return_type = TREE_TYPE (type);
4291
4292   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
4293   sibling_attribute ();
4294   dienum_push ();
4295   equate_type_number_to_die_number (type);
4296   prototyped_attribute (type);
4297   member_attribute (TYPE_CONTEXT (type));
4298   type_attribute (return_type, 0, 0);
4299 }
4300
4301 static void
4302 output_typedef_die (arg)
4303      void *arg;
4304 {
4305   tree decl = arg;
4306   tree origin = decl_ultimate_origin (decl);
4307
4308   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
4309   sibling_attribute ();
4310   if (origin != NULL)
4311     abstract_origin_attribute (origin);
4312   else
4313     {
4314       name_and_src_coords_attributes (decl);
4315       member_attribute (DECL_CONTEXT (decl));
4316       type_attribute (TREE_TYPE (decl),
4317                       TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
4318     }
4319   if (DECL_ABSTRACT (decl))
4320     equate_decl_number_to_die_number (decl);
4321 }
4322
4323 static void
4324 output_union_type_die (arg)
4325      void *arg;
4326 {
4327   tree type = arg;
4328
4329   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
4330   sibling_attribute ();
4331   equate_type_number_to_die_number (type);
4332   name_attribute (type_tag (type));
4333   member_attribute (TYPE_CONTEXT (type));
4334
4335   /* If this type has been completed, then give it a byte_size attribute
4336      and prepare to give a list of members.  Otherwise, don't do either of
4337      these things.  In the latter case, we will not be generating a list
4338      of members (since we don't have any idea what they might be for an
4339      incomplete type).  */
4340
4341   if (COMPLETE_TYPE_P (type))
4342     {
4343       dienum_push ();
4344       byte_size_attribute (type);
4345     }
4346 }
4347
4348 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
4349    at the end of an (ANSI prototyped) formal parameters list.  */
4350
4351 static void
4352 output_unspecified_parameters_die (arg)
4353      void *arg;
4354 {
4355   tree decl_or_type = arg;
4356
4357   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
4358   sibling_attribute ();
4359
4360   /* This kludge is here only for the sake of being compatible with what
4361      the USL CI5 C compiler does.  The specification of Dwarf Version 1
4362      doesn't say that TAG_unspecified_parameters DIEs should contain any
4363      attributes other than the AT_sibling attribute, but they are certainly
4364      allowed to contain additional attributes, and the CI5 compiler
4365      generates AT_name, AT_fund_type, and AT_location attributes within
4366      TAG_unspecified_parameters DIEs which appear in the child lists for
4367      DIEs representing function definitions, so we do likewise here.  */
4368
4369   if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
4370     {
4371       name_attribute ("...");
4372       fund_type_attribute (FT_pointer);
4373       /* location_attribute (?); */
4374     }
4375 }
4376
4377 static void
4378 output_padded_null_die (arg)
4379      void *arg ATTRIBUTE_UNUSED;
4380 {
4381   ASM_OUTPUT_ALIGN (asm_out_file, 2);   /* 2**2 == 4 */
4382 }
4383
4384 /*************************** end of DIEs *********************************/
4385
4386 /* Generate some type of DIE.  This routine generates the generic outer
4387    wrapper stuff which goes around all types of DIE's (regardless of their
4388    TAGs.  All forms of DIEs start with a DIE-specific label, followed by a
4389    DIE-length word, followed by the guts of the DIE itself.  After the guts
4390    of the DIE, there must always be a terminator label for the DIE.  */
4391
4392 static void
4393 output_die (die_specific_output_function, param)
4394      void (*die_specific_output_function) PARAMS ((void *));
4395      void *param;
4396 {
4397   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4398   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4399
4400   current_dienum = NEXT_DIE_NUM;
4401   NEXT_DIE_NUM = next_unused_dienum;
4402
4403   sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4404   sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4405
4406   /* Write a label which will act as the name for the start of this DIE.  */
4407
4408   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4409
4410   /* Write the DIE-length word.  */
4411
4412   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4413
4414   /* Fill in the guts of the DIE.  */
4415
4416   next_unused_dienum++;
4417   die_specific_output_function (param);
4418
4419   /* Write a label which will act as the name for the end of this DIE.  */
4420
4421   ASM_OUTPUT_LABEL (asm_out_file, end_label);
4422 }
4423
4424 static void
4425 end_sibling_chain ()
4426 {
4427   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4428
4429   current_dienum = NEXT_DIE_NUM;
4430   NEXT_DIE_NUM = next_unused_dienum;
4431
4432   sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4433
4434   /* Write a label which will act as the name for the start of this DIE.  */
4435
4436   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4437
4438   /* Write the DIE-length word.  */
4439
4440   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4441
4442   dienum_pop ();
4443 }
4444 \f
4445 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4446    TAG_unspecified_parameters DIE) to represent the types of the formal
4447    parameters as specified in some function type specification (except
4448    for those which appear as part of a function *definition*).
4449
4450    Note that we must be careful here to output all of the parameter
4451    DIEs *before* we output any DIEs needed to represent the types of
4452    the formal parameters.  This keeps svr4 SDB happy because it
4453    (incorrectly) thinks that the first non-parameter DIE it sees ends
4454    the formal parameter list.  */
4455
4456 static void
4457 output_formal_types (function_or_method_type)
4458      tree function_or_method_type;
4459 {
4460   tree link;
4461   tree formal_type = NULL;
4462   tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4463
4464   /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4465      get bogus recursion when outputting tagged types local to a
4466      function declaration.  */
4467   int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4468   TREE_ASM_WRITTEN (function_or_method_type) = 1;
4469
4470   /* In the case where we are generating a formal types list for a C++
4471      non-static member function type, skip over the first thing on the
4472      TYPE_ARG_TYPES list because it only represents the type of the
4473      hidden `this pointer'.  The debugger should be able to figure
4474      out (without being explicitly told) that this non-static member
4475      function type takes a `this pointer' and should be able to figure
4476      what the type of that hidden parameter is from the AT_member
4477      attribute of the parent TAG_subroutine_type DIE.  */
4478
4479   if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4480     first_parm_type = TREE_CHAIN (first_parm_type);
4481
4482   /* Make our first pass over the list of formal parameter types and output
4483      a TAG_formal_parameter DIE for each one.  */
4484
4485   for (link = first_parm_type; link; link = TREE_CHAIN (link))
4486     {
4487       formal_type = TREE_VALUE (link);
4488       if (formal_type == void_type_node)
4489         break;
4490
4491       /* Output a (nameless) DIE to represent the formal parameter itself.  */
4492
4493       output_die (output_formal_parameter_die, formal_type);
4494     }
4495
4496   /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4497      DIE to the end of the parameter list.  */
4498
4499   if (formal_type != void_type_node)
4500     output_die (output_unspecified_parameters_die, function_or_method_type);
4501
4502   /* Make our second (and final) pass over the list of formal parameter types
4503      and output DIEs to represent those types (as necessary).  */
4504
4505   for (link = TYPE_ARG_TYPES (function_or_method_type);
4506        link;
4507        link = TREE_CHAIN (link))
4508     {
4509       formal_type = TREE_VALUE (link);
4510       if (formal_type == void_type_node)
4511         break;
4512
4513       output_type (formal_type, function_or_method_type);
4514     }
4515
4516   TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4517 }
4518 \f
4519 /* Remember a type in the pending_types_list.  */
4520
4521 static void
4522 pend_type (type)
4523      tree type;
4524 {
4525   if (pending_types == pending_types_allocated)
4526     {
4527       pending_types_allocated += PENDING_TYPES_INCREMENT;
4528       pending_types_list
4529         = (tree *) xrealloc (pending_types_list,
4530                              sizeof (tree) * pending_types_allocated);
4531     }
4532   pending_types_list[pending_types++] = type;
4533
4534   /* Mark the pending type as having been output already (even though
4535      it hasn't been).  This prevents the type from being added to the
4536      pending_types_list more than once.  */
4537
4538   TREE_ASM_WRITTEN (type) = 1;
4539 }
4540
4541 /* Return non-zero if it is legitimate to output DIEs to represent a
4542    given type while we are generating the list of child DIEs for some
4543    DIE (e.g. a function or lexical block DIE) associated with a given scope.
4544
4545    See the comments within the function for a description of when it is
4546    considered legitimate to output DIEs for various kinds of types.
4547
4548    Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4549    or it may point to a BLOCK node (for types local to a block), or to a
4550    FUNCTION_DECL node (for types local to the heading of some function
4551    definition), or to a FUNCTION_TYPE node (for types local to the
4552    prototyped parameter list of a function type specification), or to a
4553    RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4554    (in the case of C++ nested types).
4555
4556    The `scope' parameter should likewise be NULL or should point to a
4557    BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4558    node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4559
4560    This function is used only for deciding when to "pend" and when to
4561    "un-pend" types to/from the pending_types_list.
4562
4563    Note that we sometimes make use of this "type pending" feature in a
4564    rather twisted way to temporarily delay the production of DIEs for the
4565    types of formal parameters.  (We do this just to make svr4 SDB happy.)
4566    It order to delay the production of DIEs representing types of formal
4567    parameters, callers of this function supply `fake_containing_scope' as
4568    the `scope' parameter to this function.  Given that fake_containing_scope
4569    is a tagged type which is *not* the containing scope for *any* other type,
4570    the desired effect is achieved, i.e. output of DIEs representing types
4571    is temporarily suspended, and any type DIEs which would have otherwise
4572    been output are instead placed onto the pending_types_list.  Later on,
4573    we force these (temporarily pended) types to be output simply by calling
4574    `output_pending_types_for_scope' with an actual argument equal to the
4575    true scope of the types we temporarily pended.  */
4576
4577 static inline int
4578 type_ok_for_scope (type, scope)
4579     tree type;
4580     tree scope;
4581 {
4582   /* Tagged types (i.e. struct, union, and enum types) must always be
4583      output only in the scopes where they actually belong (or else the
4584      scoping of their own tag names and the scoping of their member
4585      names will be incorrect).  Non-tagged-types on the other hand can
4586      generally be output anywhere, except that svr4 SDB really doesn't
4587      want to see them nested within struct or union types, so here we
4588      say it is always OK to immediately output any such a (non-tagged)
4589      type, so long as we are not within such a context.  Note that the
4590      only kinds of non-tagged types which we will be dealing with here
4591      (for C and C++ anyway) will be array types and function types.  */
4592
4593   return is_tagged_type (type)
4594          ? (TYPE_CONTEXT (type) == scope
4595             /* Ignore namespaces for the moment.  */
4596             || (scope == NULL_TREE
4597                 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4598             || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4599                 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4600          : (scope == NULL_TREE || ! is_tagged_type (scope));
4601 }
4602
4603 /* Output any pending types (from the pending_types list) which we can output
4604    now (taking into account the scope that we are working on now).
4605
4606    For each type output, remove the given type from the pending_types_list
4607    *before* we try to output it.
4608
4609    Note that we have to process the list in beginning-to-end order,
4610    because the call made here to output_type may cause yet more types
4611    to be added to the end of the list, and we may have to output some
4612    of them too.  */
4613
4614 static void
4615 output_pending_types_for_scope (containing_scope)
4616      tree containing_scope;
4617 {
4618   unsigned i;
4619
4620   for (i = 0; i < pending_types; )
4621     {
4622       tree type = pending_types_list[i];
4623
4624       if (type_ok_for_scope (type, containing_scope))
4625         {
4626           tree *mover;
4627           tree *limit;
4628
4629           pending_types--;
4630           limit = &pending_types_list[pending_types];
4631           for (mover = &pending_types_list[i]; mover < limit; mover++)
4632             *mover = *(mover+1);
4633
4634           /* Un-mark the type as having been output already (because it
4635              hasn't been, really).  Then call output_type to generate a
4636              Dwarf representation of it.  */
4637
4638           TREE_ASM_WRITTEN (type) = 0;
4639           output_type (type, containing_scope);
4640
4641           /* Don't increment the loop counter in this case because we
4642              have shifted all of the subsequent pending types down one
4643              element in the pending_types_list array.  */
4644         }
4645       else
4646         i++;
4647     }
4648 }
4649
4650 /* Remember a type in the incomplete_types_list.  */
4651
4652 static void
4653 add_incomplete_type (type)
4654      tree type;
4655 {
4656   if (incomplete_types == incomplete_types_allocated)
4657     {
4658       incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4659       incomplete_types_list
4660         = (tree *) xrealloc (incomplete_types_list,
4661                              sizeof (tree) * incomplete_types_allocated);
4662     }
4663
4664   incomplete_types_list[incomplete_types++] = type;
4665 }
4666
4667 /* Walk through the list of incomplete types again, trying once more to
4668    emit full debugging info for them.  */
4669
4670 static void
4671 retry_incomplete_types ()
4672 {
4673   tree type;
4674
4675   finalizing = 1;
4676   while (incomplete_types)
4677     {
4678       --incomplete_types;
4679       type = incomplete_types_list[incomplete_types];
4680       output_type (type, NULL_TREE);
4681     }
4682 }
4683
4684 static void
4685 output_type (type, containing_scope)
4686      tree type;
4687      tree containing_scope;
4688 {
4689   if (type == 0 || type == error_mark_node)
4690     return;
4691
4692   /* We are going to output a DIE to represent the unqualified version of
4693      this type (i.e. without any const or volatile qualifiers) so get
4694      the main variant (i.e. the unqualified version) of this type now.  */
4695
4696   type = type_main_variant (type);
4697
4698   if (TREE_ASM_WRITTEN (type))
4699     {
4700       if (finalizing && AGGREGATE_TYPE_P (type))
4701         {
4702           tree member;
4703
4704           /* Some of our nested types might not have been defined when we
4705              were written out before; force them out now.  */
4706
4707           for (member = TYPE_FIELDS (type); member;
4708                member = TREE_CHAIN (member))
4709             if (TREE_CODE (member) == TYPE_DECL
4710                 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4711               output_type (TREE_TYPE (member), containing_scope);
4712         }
4713       return;
4714     }
4715
4716   /* If this is a nested type whose containing class hasn't been
4717      written out yet, writing it out will cover this one, too.  */
4718
4719   if (TYPE_CONTEXT (type)
4720       && TYPE_P (TYPE_CONTEXT (type))
4721       && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4722     {
4723       output_type (TYPE_CONTEXT (type), containing_scope);
4724       return;
4725     }
4726
4727   /* Don't generate any DIEs for this type now unless it is OK to do so
4728      (based upon what `type_ok_for_scope' tells us).  */
4729
4730   if (! type_ok_for_scope (type, containing_scope))
4731     {
4732       pend_type (type);
4733       return;
4734     }
4735
4736   switch (TREE_CODE (type))
4737     {
4738       case ERROR_MARK:
4739         break;
4740
4741       case VECTOR_TYPE:
4742         output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4743         break;
4744
4745       case POINTER_TYPE:
4746       case REFERENCE_TYPE:
4747         /* Prevent infinite recursion in cases where this is a recursive
4748            type.  Recursive types are possible in Ada.  */
4749         TREE_ASM_WRITTEN (type) = 1;
4750         /* For these types, all that is required is that we output a DIE
4751            (or a set of DIEs) to represent the "basis" type.  */
4752         output_type (TREE_TYPE (type), containing_scope);
4753         break;
4754
4755       case OFFSET_TYPE:
4756         /* This code is used for C++ pointer-to-data-member types.  */
4757         /* Output a description of the relevant class type.  */
4758         output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4759         /* Output a description of the type of the object pointed to.  */
4760         output_type (TREE_TYPE (type), containing_scope);
4761         /* Now output a DIE to represent this pointer-to-data-member type
4762            itself.  */
4763         output_die (output_ptr_to_mbr_type_die, type);
4764         break;
4765
4766       case SET_TYPE:
4767         output_type (TYPE_DOMAIN (type), containing_scope);
4768         output_die (output_set_type_die, type);
4769         break;
4770
4771       case FILE_TYPE:
4772         output_type (TREE_TYPE (type), containing_scope);
4773         abort ();       /* No way to represent these in Dwarf yet!  */
4774         break;
4775
4776       case FUNCTION_TYPE:
4777         /* Force out return type (in case it wasn't forced out already).  */
4778         output_type (TREE_TYPE (type), containing_scope);
4779         output_die (output_subroutine_type_die, type);
4780         output_formal_types (type);
4781         end_sibling_chain ();
4782         break;
4783
4784       case METHOD_TYPE:
4785         /* Force out return type (in case it wasn't forced out already).  */
4786         output_type (TREE_TYPE (type), containing_scope);
4787         output_die (output_subroutine_type_die, type);
4788         output_formal_types (type);
4789         end_sibling_chain ();
4790         break;
4791
4792       case ARRAY_TYPE:
4793         if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4794           {
4795             output_type (TREE_TYPE (type), containing_scope);
4796             output_die (output_string_type_die, type);
4797           }
4798         else
4799           {
4800             tree element_type;
4801
4802             element_type = TREE_TYPE (type);
4803             while (TREE_CODE (element_type) == ARRAY_TYPE)
4804               element_type = TREE_TYPE (element_type);
4805
4806             output_type (element_type, containing_scope);
4807             output_die (output_array_type_die, type);
4808           }
4809         break;
4810
4811       case ENUMERAL_TYPE:
4812       case RECORD_TYPE:
4813       case UNION_TYPE:
4814       case QUAL_UNION_TYPE:
4815
4816         /* For a non-file-scope tagged type, we can always go ahead and
4817            output a Dwarf description of this type right now, even if
4818            the type in question is still incomplete, because if this
4819            local type *was* ever completed anywhere within its scope,
4820            that complete definition would already have been attached to
4821            this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4822            node by the time we reach this point.  That's true because of the
4823            way the front-end does its processing of file-scope declarations (of
4824            functions and class types) within which other types might be
4825            nested.  The C and C++ front-ends always gobble up such "local
4826            scope" things en-mass before they try to output *any* debugging
4827            information for any of the stuff contained inside them and thus,
4828            we get the benefit here of what is (in effect) a pre-resolution
4829            of forward references to tagged types in local scopes.
4830
4831            Note however that for file-scope tagged types we cannot assume
4832            that such pre-resolution of forward references has taken place.
4833            A given file-scope tagged type may appear to be incomplete when
4834            we reach this point, but it may yet be given a full definition
4835            (at file-scope) later on during compilation.  In order to avoid
4836            generating a premature (and possibly incorrect) set of Dwarf
4837            DIEs for such (as yet incomplete) file-scope tagged types, we
4838            generate nothing at all for as-yet incomplete file-scope tagged
4839            types here unless we are making our special "finalization" pass
4840            for file-scope things at the very end of compilation.  At that
4841            time, we will certainly know as much about each file-scope tagged
4842            type as we are ever going to know, so at that point in time, we
4843            can safely generate correct Dwarf descriptions for these file-
4844            scope tagged types.  */
4845
4846         if (!COMPLETE_TYPE_P (type)
4847             && (TYPE_CONTEXT (type) == NULL
4848                 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4849                 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4850             && !finalizing)
4851           {
4852             /* We don't need to do this for function-local types.  */
4853             if (! decl_function_context (TYPE_STUB_DECL (type)))
4854               add_incomplete_type (type);
4855             return;     /* EARLY EXIT!  Avoid setting TREE_ASM_WRITTEN.  */
4856           }
4857
4858         /* Prevent infinite recursion in cases where the type of some
4859            member of this type is expressed in terms of this type itself.  */
4860
4861         TREE_ASM_WRITTEN (type) = 1;
4862
4863         /* Output a DIE to represent the tagged type itself.  */
4864
4865         switch (TREE_CODE (type))
4866           {
4867           case ENUMERAL_TYPE:
4868             output_die (output_enumeration_type_die, type);
4869             return;  /* a special case -- nothing left to do so just return */
4870
4871           case RECORD_TYPE:
4872             output_die (output_structure_type_die, type);
4873             break;
4874
4875           case UNION_TYPE:
4876           case QUAL_UNION_TYPE:
4877             output_die (output_union_type_die, type);
4878             break;
4879
4880           default:
4881             abort ();   /* Should never happen.  */
4882           }
4883
4884         /* If this is not an incomplete type, output descriptions of
4885            each of its members.
4886
4887            Note that as we output the DIEs necessary to represent the
4888            members of this record or union type, we will also be trying
4889            to output DIEs to represent the *types* of those members.
4890            However the `output_type' function (above) will specifically
4891            avoid generating type DIEs for member types *within* the list
4892            of member DIEs for this (containing) type except for those
4893            types (of members) which are explicitly marked as also being
4894            members of this (containing) type themselves.  The g++ front-
4895            end can force any given type to be treated as a member of some
4896            other (containing) type by setting the TYPE_CONTEXT of the
4897            given (member) type to point to the TREE node representing the
4898            appropriate (containing) type.
4899         */
4900
4901         if (COMPLETE_TYPE_P (type))
4902           {
4903             /* First output info about the base classes.  */
4904             if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4905               {
4906                 register tree bases = TYPE_BINFO_BASETYPES (type);
4907                 register int n_bases = TREE_VEC_LENGTH (bases);
4908                 register int i;
4909
4910                 for (i = 0; i < n_bases; i++)
4911                   {
4912                     tree binfo = TREE_VEC_ELT (bases, i);
4913                     output_type (BINFO_TYPE (binfo), containing_scope);
4914                     output_die (output_inheritance_die, binfo);
4915                   }
4916               }
4917
4918             ++in_class;
4919
4920             {
4921               tree normal_member;
4922
4923               /* Now output info about the data members and type members.  */
4924
4925               for (normal_member = TYPE_FIELDS (type);
4926                    normal_member;
4927                    normal_member = TREE_CHAIN (normal_member))
4928                 output_decl (normal_member, type);
4929             }
4930
4931             {
4932               tree func_member;
4933
4934               /* Now output info about the function members (if any).  */
4935
4936               for (func_member = TYPE_METHODS (type);
4937                    func_member;
4938                    func_member = TREE_CHAIN (func_member))
4939                 {
4940                   /* Don't include clones in the member list.  */
4941                   if (DECL_ABSTRACT_ORIGIN (func_member))
4942                     continue;
4943
4944                   output_decl (func_member, type);
4945                 }
4946             }
4947
4948             --in_class;
4949
4950             /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4951                scopes (at least in C++) so we must now output any nested
4952                pending types which are local just to this type.  */
4953
4954             output_pending_types_for_scope (type);
4955
4956             end_sibling_chain ();       /* Terminate member chain.  */
4957           }
4958
4959         break;
4960
4961       case VOID_TYPE:
4962       case INTEGER_TYPE:
4963       case REAL_TYPE:
4964       case COMPLEX_TYPE:
4965       case BOOLEAN_TYPE:
4966       case CHAR_TYPE:
4967         break;          /* No DIEs needed for fundamental types.  */
4968
4969       case LANG_TYPE:   /* No Dwarf representation currently defined.  */
4970         break;
4971
4972       default:
4973         abort ();
4974     }
4975
4976   TREE_ASM_WRITTEN (type) = 1;
4977 }
4978
4979 static void
4980 output_tagged_type_instantiation (type)
4981      tree type;
4982 {
4983   if (type == 0 || type == error_mark_node)
4984     return;
4985
4986   /* We are going to output a DIE to represent the unqualified version of
4987      this type (i.e. without any const or volatile qualifiers) so make
4988      sure that we have the main variant (i.e. the unqualified version) of
4989      this type now.  */
4990
4991   if (type != type_main_variant (type))
4992     abort ();
4993
4994   if (!TREE_ASM_WRITTEN (type))
4995     abort ();
4996
4997   switch (TREE_CODE (type))
4998     {
4999       case ERROR_MARK:
5000         break;
5001
5002       case ENUMERAL_TYPE:
5003         output_die (output_inlined_enumeration_type_die, type);
5004         break;
5005
5006       case RECORD_TYPE:
5007         output_die (output_inlined_structure_type_die, type);
5008         break;
5009
5010       case UNION_TYPE:
5011       case QUAL_UNION_TYPE:
5012         output_die (output_inlined_union_type_die, type);
5013         break;
5014
5015       default:
5016         abort ();       /* Should never happen.  */
5017     }
5018 }
5019 \f
5020 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
5021    the things which are local to the given block.  */
5022
5023 static void
5024 output_block (stmt, depth)
5025     tree stmt;
5026     int depth;
5027 {
5028   int must_output_die = 0;
5029   tree origin;
5030   enum tree_code origin_code;
5031
5032   /* Ignore blocks never really used to make RTL.  */
5033
5034   if (! stmt || ! TREE_USED (stmt)
5035       || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
5036     return;
5037
5038   /* Determine the "ultimate origin" of this block.  This block may be an
5039      inlined instance of an inlined instance of inline function, so we
5040      have to trace all of the way back through the origin chain to find
5041      out what sort of node actually served as the original seed for the
5042      creation of the current block.  */
5043
5044   origin = block_ultimate_origin (stmt);
5045   origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
5046
5047   /* Determine if we need to output any Dwarf DIEs at all to represent this
5048      block.  */
5049
5050   if (origin_code == FUNCTION_DECL)
5051     /* The outer scopes for inlinings *must* always be represented.  We
5052        generate TAG_inlined_subroutine DIEs for them.  (See below.)  */
5053     must_output_die = 1;
5054   else
5055     {
5056       /* In the case where the current block represents an inlining of the
5057          "body block" of an inline function, we must *NOT* output any DIE
5058          for this block because we have already output a DIE to represent
5059          the whole inlined function scope and the "body block" of any
5060          function doesn't really represent a different scope according to
5061          ANSI C rules.  So we check here to make sure that this block does
5062          not represent a "body block inlining" before trying to set the
5063          `must_output_die' flag.  */
5064
5065       if (! is_body_block (origin ? origin : stmt))
5066         {
5067           /* Determine if this block directly contains any "significant"
5068              local declarations which we will need to output DIEs for.  */
5069
5070           if (debug_info_level > DINFO_LEVEL_TERSE)
5071             /* We are not in terse mode so *any* local declaration counts
5072                as being a "significant" one.  */
5073             must_output_die = (BLOCK_VARS (stmt) != NULL);
5074           else
5075             {
5076               tree decl;
5077
5078               /* We are in terse mode, so only local (nested) function
5079                  definitions count as "significant" local declarations.  */
5080
5081               for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5082                 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
5083                   {
5084                     must_output_die = 1;
5085                     break;
5086                   }
5087             }
5088         }
5089     }
5090
5091   /* It would be a waste of space to generate a Dwarf TAG_lexical_block
5092      DIE for any block which contains no significant local declarations
5093      at all.  Rather, in such cases we just call `output_decls_for_scope'
5094      so that any needed Dwarf info for any sub-blocks will get properly
5095      generated.  Note that in terse mode, our definition of what constitutes
5096      a "significant" local declaration gets restricted to include only
5097      inlined function instances and local (nested) function definitions.  */
5098
5099   if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
5100     /* We don't care about an abstract inlined subroutine.  */;
5101   else if (must_output_die)
5102     {
5103       output_die ((origin_code == FUNCTION_DECL)
5104                     ? output_inlined_subroutine_die
5105                     : output_lexical_block_die,
5106                   stmt);
5107       output_decls_for_scope (stmt, depth);
5108       end_sibling_chain ();
5109     }
5110   else
5111     output_decls_for_scope (stmt, depth);
5112 }
5113
5114 /* Output all of the decls declared within a given scope (also called
5115    a `binding contour') and (recursively) all of it's sub-blocks.  */
5116
5117 static void
5118 output_decls_for_scope (stmt, depth)
5119      tree stmt;
5120      int depth;
5121 {
5122   /* Ignore blocks never really used to make RTL.  */
5123
5124   if (! stmt || ! TREE_USED (stmt))
5125     return;
5126
5127   /* Output the DIEs to represent all of the data objects, functions,
5128      typedefs, and tagged types declared directly within this block
5129      but not within any nested sub-blocks.  */
5130
5131   {
5132     tree decl;
5133
5134     for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
5135       output_decl (decl, stmt);
5136   }
5137
5138   output_pending_types_for_scope (stmt);
5139
5140   /* Output the DIEs to represent all sub-blocks (and the items declared
5141      therein) of this block.     */
5142
5143   {
5144     tree subblocks;
5145
5146     for (subblocks = BLOCK_SUBBLOCKS (stmt);
5147          subblocks;
5148          subblocks = BLOCK_CHAIN (subblocks))
5149       output_block (subblocks, depth + 1);
5150   }
5151 }
5152
5153 /* Is this a typedef we can avoid emitting?  */
5154
5155 static inline int
5156 is_redundant_typedef (decl)
5157      tree decl;
5158 {
5159   if (TYPE_DECL_IS_STUB (decl))
5160     return 1;
5161   if (DECL_ARTIFICIAL (decl)
5162       && DECL_CONTEXT (decl)
5163       && is_tagged_type (DECL_CONTEXT (decl))
5164       && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
5165       && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
5166     /* Also ignore the artificial member typedef for the class name.  */
5167     return 1;
5168   return 0;
5169 }
5170
5171 /* Output Dwarf .debug information for a decl described by DECL.  */
5172
5173 static void
5174 output_decl (decl, containing_scope)
5175      tree decl;
5176      tree containing_scope;
5177 {
5178   /* Make a note of the decl node we are going to be working on.  We may
5179      need to give the user the source coordinates of where it appeared in
5180      case we notice (later on) that something about it looks screwy.  */
5181
5182   dwarf_last_decl = decl;
5183
5184   if (TREE_CODE (decl) == ERROR_MARK)
5185     return;
5186
5187   /* If a structure is declared within an initialization, e.g. as the
5188      operand of a sizeof, then it will not have a name.  We don't want
5189      to output a DIE for it, as the tree nodes are in the temporary obstack */
5190
5191   if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5192        || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
5193       && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
5194           || (TYPE_FIELDS (TREE_TYPE (decl))
5195               && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
5196     return;
5197
5198   /* If this ..._DECL node is marked to be ignored, then ignore it.  */
5199
5200   if (DECL_IGNORED_P (decl))
5201     return;
5202
5203   switch (TREE_CODE (decl))
5204     {
5205     case CONST_DECL:
5206       /* The individual enumerators of an enum type get output when we
5207          output the Dwarf representation of the relevant enum type itself.  */
5208       break;
5209
5210     case FUNCTION_DECL:
5211       /* If we are in terse mode, don't output any DIEs to represent
5212          mere function declarations.  Also, if we are conforming
5213          to the DWARF version 1 specification, don't output DIEs for
5214          mere function declarations.  */
5215
5216       if (DECL_INITIAL (decl) == NULL_TREE)
5217 #if (DWARF_VERSION > 1)
5218         if (debug_info_level <= DINFO_LEVEL_TERSE)
5219 #endif
5220           break;
5221
5222       /* Before we describe the FUNCTION_DECL itself, make sure that we
5223          have described its return type.  */
5224
5225       output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
5226
5227       {
5228         /* And its containing type.  */
5229         register tree origin = decl_class_context (decl);
5230         if (origin)
5231           output_type (origin, containing_scope);
5232       }
5233
5234       /* If we're emitting an out-of-line copy of an inline function,
5235          set up to refer to the abstract instance emitted from
5236          dwarfout_deferred_inline_function.  */
5237       if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
5238           && ! (containing_scope && TYPE_P (containing_scope)))
5239         set_decl_origin_self (decl);
5240
5241       /* If the following DIE will represent a function definition for a
5242          function with "extern" linkage, output a special "pubnames" DIE
5243          label just ahead of the actual DIE.  A reference to this label
5244          was already generated in the .debug_pubnames section sub-entry
5245          for this function definition.  */
5246
5247       if (TREE_PUBLIC (decl))
5248         {
5249           char label[MAX_ARTIFICIAL_LABEL_BYTES];
5250
5251           sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5252           ASM_OUTPUT_LABEL (asm_out_file, label);
5253         }
5254
5255       /* Now output a DIE to represent the function itself.  */
5256
5257       output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
5258                                 ? output_global_subroutine_die
5259                                 : output_local_subroutine_die,
5260                   decl);
5261
5262       /* Now output descriptions of the arguments for this function.
5263          This gets (unnecessarily?) complex because of the fact that
5264          the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
5265          cases where there was a trailing `...' at the end of the formal
5266          parameter list.  In order to find out if there was a trailing
5267          ellipsis or not, we must instead look at the type associated
5268          with the FUNCTION_DECL.  This will be a node of type FUNCTION_TYPE.
5269          If the chain of type nodes hanging off of this FUNCTION_TYPE node
5270          ends with a void_type_node then there should *not* be an ellipsis
5271          at the end.  */
5272
5273       /* In the case where we are describing a mere function declaration, all
5274          we need to do here (and all we *can* do here) is to describe
5275          the *types* of its formal parameters.  */
5276
5277       if (decl != current_function_decl || in_class)
5278         output_formal_types (TREE_TYPE (decl));
5279       else
5280         {
5281           /* Generate DIEs to represent all known formal parameters */
5282
5283           tree arg_decls = DECL_ARGUMENTS (decl);
5284           tree parm;
5285
5286           /* WARNING!  Kludge zone ahead!  Here we have a special
5287              hack for svr4 SDB compatibility.  Instead of passing the
5288              current FUNCTION_DECL node as the second parameter (i.e.
5289              the `containing_scope' parameter) to `output_decl' (as
5290              we ought to) we instead pass a pointer to our own private
5291              fake_containing_scope node.  That node is a RECORD_TYPE
5292              node which NO OTHER TYPE may ever actually be a member of.
5293
5294              This pointer will ultimately get passed into `output_type'
5295              as its `containing_scope' parameter.  `Output_type' will
5296              then perform its part in the hack... i.e. it will pend
5297              the type of the formal parameter onto the pending_types
5298              list.  Later on, when we are done generating the whole
5299              sequence of formal parameter DIEs for this function
5300              definition, we will un-pend all previously pended types
5301              of formal parameters for this function definition.
5302
5303              This whole kludge prevents any type DIEs from being
5304              mixed in with the formal parameter DIEs.  That's good
5305              because svr4 SDB believes that the list of formal
5306              parameter DIEs for a function ends wherever the first
5307              non-formal-parameter DIE appears.  Thus, we have to
5308              keep the formal parameter DIEs segregated.  They must
5309              all appear (consecutively) at the start of the list of
5310              children for the DIE representing the function definition.
5311              Then (and only then) may we output any additional DIEs
5312              needed to represent the types of these formal parameters.
5313           */
5314
5315           /*
5316              When generating DIEs, generate the unspecified_parameters
5317              DIE instead if we come across the arg "__builtin_va_alist"
5318           */
5319
5320           for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
5321             if (TREE_CODE (parm) == PARM_DECL)
5322               {
5323                 if (DECL_NAME(parm) &&
5324                     !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
5325                             "__builtin_va_alist") )
5326                   output_die (output_unspecified_parameters_die, decl);
5327                 else
5328                   output_decl (parm, fake_containing_scope);
5329               }
5330
5331           /*
5332              Now that we have finished generating all of the DIEs to
5333              represent the formal parameters themselves, force out
5334              any DIEs needed to represent their types.  We do this
5335              simply by un-pending all previously pended types which
5336              can legitimately go into the chain of children DIEs for
5337              the current FUNCTION_DECL.
5338           */
5339
5340           output_pending_types_for_scope (decl);
5341
5342           /*
5343             Decide whether we need an unspecified_parameters DIE at the end.
5344             There are 2 more cases to do this for:
5345             1) the ansi ... declaration - this is detectable when the end
5346                 of the arg list is not a void_type_node
5347             2) an unprototyped function declaration (not a definition).  This
5348                 just means that we have no info about the parameters at all.
5349           */
5350
5351           {
5352             tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
5353
5354             if (fn_arg_types)
5355               {
5356               /* this is the prototyped case, check for ...  */
5357               if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
5358                 output_die (output_unspecified_parameters_die, decl);
5359               }
5360             else
5361               {
5362                 /* this is unprototyped, check for undefined (just declaration) */
5363                 if (!DECL_INITIAL (decl))
5364                   output_die (output_unspecified_parameters_die, decl);
5365               }
5366           }
5367
5368           /* Output Dwarf info for all of the stuff within the body of the
5369              function (if it has one - it may be just a declaration).  */
5370
5371           {
5372             tree outer_scope = DECL_INITIAL (decl);
5373
5374             if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
5375               {
5376                 /* Note that here, `outer_scope' is a pointer to the outermost
5377                    BLOCK node created to represent a function.
5378                    This outermost BLOCK actually represents the outermost
5379                    binding contour for the function, i.e. the contour in which
5380                    the function's formal parameters and labels get declared.
5381
5382                    Curiously, it appears that the front end doesn't actually
5383                    put the PARM_DECL nodes for the current function onto the
5384                    BLOCK_VARS list for this outer scope.  (They are strung
5385                    off of the DECL_ARGUMENTS list for the function instead.)
5386                    The BLOCK_VARS list for the `outer_scope' does provide us
5387                    with a list of the LABEL_DECL nodes for the function however,
5388                    and we output DWARF info for those here.
5389
5390                    Just within the `outer_scope' there will be a BLOCK node
5391                    representing the function's outermost pair of curly braces,
5392                    and any blocks used for the base and member initializers of
5393                    a C++ constructor function.  */
5394
5395                 output_decls_for_scope (outer_scope, 0);
5396
5397                 /* Finally, force out any pending types which are local to the
5398                    outermost block of this function definition.  These will
5399                    all have a TYPE_CONTEXT which points to the FUNCTION_DECL
5400                    node itself.  */
5401
5402                 output_pending_types_for_scope (decl);
5403               }
5404           }
5405         }
5406
5407       /* Generate a terminator for the list of stuff `owned' by this
5408          function.  */
5409
5410       end_sibling_chain ();
5411
5412       break;
5413
5414     case TYPE_DECL:
5415       /* If we are in terse mode, don't generate any DIEs to represent
5416          any actual typedefs.  Note that even when we are in terse mode,
5417          we must still output DIEs to represent those tagged types which
5418          are used (directly or indirectly) in the specification of either
5419          a return type or a formal parameter type of some function.  */
5420
5421       if (debug_info_level <= DINFO_LEVEL_TERSE)
5422         if (! TYPE_DECL_IS_STUB (decl)
5423             || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5424           return;
5425
5426       /* In the special case of a TYPE_DECL node representing
5427          the declaration of some type tag, if the given TYPE_DECL is
5428          marked as having been instantiated from some other (original)
5429          TYPE_DECL node (e.g. one which was generated within the original
5430          definition of an inline function) we have to generate a special
5431          (abbreviated) TAG_structure_type, TAG_union_type, or
5432          TAG_enumeration-type DIE here.  */
5433
5434       if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5435         {
5436           output_tagged_type_instantiation (TREE_TYPE (decl));
5437           return;
5438         }
5439
5440       output_type (TREE_TYPE (decl), containing_scope);
5441
5442       if (! is_redundant_typedef (decl))
5443         /* Output a DIE to represent the typedef itself.  */
5444         output_die (output_typedef_die, decl);
5445       break;
5446
5447     case LABEL_DECL:
5448       if (debug_info_level >= DINFO_LEVEL_NORMAL)
5449         output_die (output_label_die, decl);
5450       break;
5451
5452     case VAR_DECL:
5453       /* If we are conforming to the DWARF version 1 specification, don't
5454          generated any DIEs to represent mere external object declarations.  */
5455
5456 #if (DWARF_VERSION <= 1)
5457       if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5458         break;
5459 #endif
5460
5461       /* If we are in terse mode, don't generate any DIEs to represent
5462          any variable declarations or definitions.  */
5463
5464       if (debug_info_level <= DINFO_LEVEL_TERSE)
5465         break;
5466
5467       /* Output any DIEs that are needed to specify the type of this data
5468          object.  */
5469
5470       output_type (TREE_TYPE (decl), containing_scope);
5471
5472       {
5473         /* And its containing type.  */
5474         register tree origin = decl_class_context (decl);
5475         if (origin)
5476           output_type (origin, containing_scope);
5477       }
5478
5479       /* If the following DIE will represent a data object definition for a
5480          data object with "extern" linkage, output a special "pubnames" DIE
5481          label just ahead of the actual DIE.  A reference to this label
5482          was already generated in the .debug_pubnames section sub-entry
5483          for this data object definition.  */
5484
5485       if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5486         {
5487           char label[MAX_ARTIFICIAL_LABEL_BYTES];
5488
5489           sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5490           ASM_OUTPUT_LABEL (asm_out_file, label);
5491         }
5492
5493       /* Now output the DIE to represent the data object itself.  This gets
5494          complicated because of the possibility that the VAR_DECL really
5495          represents an inlined instance of a formal parameter for an inline
5496          function.  */
5497
5498       {
5499         void (*func) PARAMS ((void *));
5500         register tree origin = decl_ultimate_origin (decl);
5501
5502         if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5503           func = output_formal_parameter_die;
5504         else
5505           {
5506             if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5507               func = output_global_variable_die;
5508             else
5509               func = output_local_variable_die;
5510           }
5511         output_die (func, decl);
5512       }
5513       break;
5514
5515     case FIELD_DECL:
5516       /* Ignore the nameless fields that are used to skip bits.  */
5517       if (DECL_NAME (decl) != 0)
5518         {
5519           output_type (member_declared_type (decl), containing_scope);
5520           output_die (output_member_die, decl);
5521         }
5522       break;
5523
5524     case PARM_DECL:
5525      /* Force out the type of this formal, if it was not forced out yet.
5526         Note that here we can run afoul of a bug in "classic" svr4 SDB.
5527         It should be able to grok the presence of type DIEs within a list
5528         of TAG_formal_parameter DIEs, but it doesn't.  */
5529
5530       output_type (TREE_TYPE (decl), containing_scope);
5531       output_die (output_formal_parameter_die, decl);
5532       break;
5533
5534     case NAMESPACE_DECL:
5535       /* Ignore for now.  */
5536       break;
5537
5538     default:
5539       abort ();
5540     }
5541 }
5542 \f
5543 /* Output debug information for a function.  */
5544 static void
5545 dwarfout_function_decl (decl)
5546      tree decl;
5547 {
5548   dwarfout_file_scope_decl (decl, 0);
5549 }
5550
5551 /* Debug information for a global DECL.  Called from toplev.c after
5552    compilation proper has finished.  */
5553 static void
5554 dwarfout_global_decl (decl)
5555      tree decl;
5556 {
5557   /* Output DWARF information for file-scope tentative data object
5558      declarations, file-scope (extern) function declarations (which
5559      had no corresponding body) and file-scope tagged type
5560      declarations and definitions which have not yet been forced out.  */
5561
5562   if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
5563     dwarfout_file_scope_decl (decl, 1);
5564 }
5565
5566 /* DECL is an inline function, whose body is present, but which is not
5567    being output at this point.  (We're putting that off until we need
5568    to do it.)  */
5569 static void
5570 dwarfout_deferred_inline_function (decl)
5571      tree decl;
5572 {
5573   /* Generate the DWARF info for the "abstract" instance of a function
5574      which we may later generate inlined and/or out-of-line instances
5575      of.  */
5576   if ((DECL_INLINE (decl) || DECL_ABSTRACT (decl))
5577       && ! DECL_ABSTRACT_ORIGIN (decl))
5578     {
5579       /* The front-end may not have set CURRENT_FUNCTION_DECL, but the
5580          DWARF code expects it to be set in this case.  Intuitively,
5581          DECL is the function we just finished defining, so setting
5582          CURRENT_FUNCTION_DECL is sensible.  */
5583       tree saved_cfd = current_function_decl;
5584       int was_abstract = DECL_ABSTRACT (decl);
5585       current_function_decl = decl;
5586
5587       /* Let the DWARF code do its work.  */
5588       set_decl_abstract_flags (decl, 1);
5589       dwarfout_file_scope_decl (decl, 0);
5590       if (! was_abstract)
5591         set_decl_abstract_flags (decl, 0);
5592
5593       /* Reset CURRENT_FUNCTION_DECL.  */
5594       current_function_decl = saved_cfd;
5595     }
5596 }
5597
5598 static void
5599 dwarfout_file_scope_decl (decl, set_finalizing)
5600      tree decl;
5601      int set_finalizing;
5602 {
5603   if (TREE_CODE (decl) == ERROR_MARK)
5604     return;
5605
5606   /* If this ..._DECL node is marked to be ignored, then ignore it.  */
5607
5608   if (DECL_IGNORED_P (decl))
5609     return;
5610
5611   switch (TREE_CODE (decl))
5612     {
5613     case FUNCTION_DECL:
5614
5615       /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5616          a builtin function.  Explicit programmer-supplied declarations of
5617          these same functions should NOT be ignored however.  */
5618
5619       if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5620         return;
5621
5622       /* What we would really like to do here is to filter out all mere
5623          file-scope declarations of file-scope functions which are never
5624          referenced later within this translation unit (and keep all of
5625          ones that *are* referenced later on) but we aren't clairvoyant,
5626          so we have no idea which functions will be referenced in the
5627          future (i.e. later on within the current translation unit).
5628          So here we just ignore all file-scope function declarations
5629          which are not also definitions.  If and when the debugger needs
5630          to know something about these functions, it will have to hunt
5631          around and find the DWARF information associated with the
5632          *definition* of the function.
5633
5634          Note that we can't just check `DECL_EXTERNAL' to find out which
5635          FUNCTION_DECL nodes represent definitions and which ones represent
5636          mere declarations.  We have to check `DECL_INITIAL' instead.  That's
5637          because the C front-end supports some weird semantics for "extern
5638          inline" function definitions.  These can get inlined within the
5639          current translation unit (an thus, we need to generate DWARF info
5640          for their abstract instances so that the DWARF info for the
5641          concrete inlined instances can have something to refer to) but
5642          the compiler never generates any out-of-lines instances of such
5643          things (despite the fact that they *are* definitions).  The
5644          important point is that the C front-end marks these "extern inline"
5645          functions as DECL_EXTERNAL, but we need to generate DWARF for them
5646          anyway.
5647
5648          Note that the C++ front-end also plays some similar games for inline
5649          function definitions appearing within include files which also
5650          contain `#pragma interface' pragmas.  */
5651
5652       if (DECL_INITIAL (decl) == NULL_TREE)
5653         return;
5654
5655       if (TREE_PUBLIC (decl)
5656           && ! DECL_EXTERNAL (decl)
5657           && ! DECL_ABSTRACT (decl))
5658         {
5659           char label[MAX_ARTIFICIAL_LABEL_BYTES];
5660
5661           /* Output a .debug_pubnames entry for a public function
5662              defined in this compilation unit.  */
5663
5664           fputc ('\n', asm_out_file);
5665           ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5666           sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5667           ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5668           ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5669                                    IDENTIFIER_POINTER (DECL_NAME (decl)));
5670           ASM_OUTPUT_POP_SECTION (asm_out_file);
5671         }
5672
5673       break;
5674
5675     case VAR_DECL:
5676
5677       /* Ignore this VAR_DECL if it refers to a file-scope extern data
5678          object declaration and if the declaration was never even
5679          referenced from within this entire compilation unit.  We
5680          suppress these DIEs in order to save space in the .debug section
5681          (by eliminating entries which are probably useless).  Note that
5682          we must not suppress block-local extern declarations (whether
5683          used or not) because that would screw-up the debugger's name
5684          lookup mechanism and cause it to miss things which really ought
5685          to be in scope at a given point.  */
5686
5687       if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5688         return;
5689
5690       if (TREE_PUBLIC (decl)
5691           && ! DECL_EXTERNAL (decl)
5692           && GET_CODE (DECL_RTL (decl)) == MEM
5693           && ! DECL_ABSTRACT (decl))
5694         {
5695           char label[MAX_ARTIFICIAL_LABEL_BYTES];
5696
5697           if (debug_info_level >= DINFO_LEVEL_NORMAL)
5698             {
5699               /* Output a .debug_pubnames entry for a public variable
5700                  defined in this compilation unit.  */
5701
5702               fputc ('\n', asm_out_file);
5703               ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
5704               sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5705               ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5706               ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5707                                        IDENTIFIER_POINTER (DECL_NAME (decl)));
5708               ASM_OUTPUT_POP_SECTION (asm_out_file);
5709             }
5710
5711           if (DECL_INITIAL (decl) == NULL)
5712             {
5713               /* Output a .debug_aranges entry for a public variable
5714                  which is tentatively defined in this compilation unit.  */
5715
5716               fputc ('\n', asm_out_file);
5717               ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
5718               ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5719                               IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5720               ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5721                         (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5722               ASM_OUTPUT_POP_SECTION (asm_out_file);
5723             }
5724         }
5725
5726       /* If we are in terse mode, don't generate any DIEs to represent
5727          any variable declarations or definitions.  */
5728
5729       if (debug_info_level <= DINFO_LEVEL_TERSE)
5730         return;
5731
5732       break;
5733
5734     case TYPE_DECL:
5735       /* Don't bother trying to generate any DIEs to represent any of the
5736          normal built-in types for the language we are compiling, except
5737          in cases where the types in question are *not* DWARF fundamental
5738          types.  We make an exception in the case of non-fundamental types
5739          for the sake of objective C (and perhaps C++) because the GNU
5740          front-ends for these languages may in fact create certain "built-in"
5741          types which are (for example) RECORD_TYPEs.  In such cases, we
5742          really need to output these (non-fundamental) types because other
5743          DIEs may contain references to them.  */
5744
5745       /* Also ignore language dependent types here, because they are probably
5746          also built-in types.  If we didn't ignore them, then we would get
5747          references to undefined labels because output_type doesn't support
5748          them.   So, for now, we need to ignore them to avoid assembler
5749          errors.  */
5750
5751       /* ??? This code is different than the equivalent code in dwarf2out.c.
5752          The dwarf2out.c code is probably more correct.  */
5753
5754       if (DECL_SOURCE_LINE (decl) == 0
5755           && (type_is_fundamental (TREE_TYPE (decl))
5756               || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5757         return;
5758
5759       /* If we are in terse mode, don't generate any DIEs to represent
5760          any actual typedefs.  Note that even when we are in terse mode,
5761          we must still output DIEs to represent those tagged types which
5762          are used (directly or indirectly) in the specification of either
5763          a return type or a formal parameter type of some function.  */
5764
5765       if (debug_info_level <= DINFO_LEVEL_TERSE)
5766         if (! TYPE_DECL_IS_STUB (decl)
5767             || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5768           return;
5769
5770       break;
5771
5772     default:
5773       return;
5774     }
5775
5776   fputc ('\n', asm_out_file);
5777   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5778   finalizing = set_finalizing;
5779   output_decl (decl, NULL_TREE);
5780
5781   /* NOTE:  The call above to `output_decl' may have caused one or more
5782      file-scope named types (i.e. tagged types) to be placed onto the
5783      pending_types_list.  We have to get those types off of that list
5784      at some point, and this is the perfect time to do it.  If we didn't
5785      take them off now, they might still be on the list when cc1 finally
5786      exits.  That might be OK if it weren't for the fact that when we put
5787      types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5788      for these types, and that causes them never to be output unless
5789      `output_pending_types_for_scope' takes them off of the list and un-sets
5790      their TREE_ASM_WRITTEN flags.  */
5791
5792   output_pending_types_for_scope (NULL_TREE);
5793
5794   /* The above call should have totally emptied the pending_types_list
5795      if this is not a nested function or class.  If this is a nested type,
5796      then the remaining pending_types will be emitted when the containing type
5797      is handled.  */
5798
5799   if (! DECL_CONTEXT (decl))
5800     {
5801       if (pending_types != 0)
5802         abort ();
5803     }
5804
5805   ASM_OUTPUT_POP_SECTION (asm_out_file);
5806 }
5807 \f
5808 /* Output a marker (i.e. a label) for the beginning of the generated code
5809    for a lexical block.  */
5810
5811 static void
5812 dwarfout_begin_block (line, blocknum)
5813      unsigned int line ATTRIBUTE_UNUSED;
5814      unsigned int blocknum;
5815 {
5816   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5817
5818   function_section (current_function_decl);
5819   sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5820   ASM_OUTPUT_LABEL (asm_out_file, label);
5821 }
5822
5823 /* Output a marker (i.e. a label) for the end of the generated code
5824    for a lexical block.  */
5825
5826 static void
5827 dwarfout_end_block (line, blocknum)
5828      unsigned int line ATTRIBUTE_UNUSED;
5829      unsigned int blocknum;
5830 {
5831   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5832
5833   function_section (current_function_decl);
5834   sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5835   ASM_OUTPUT_LABEL (asm_out_file, label);
5836 }
5837
5838 /* Output a marker (i.e. a label) for the point in the generated code where
5839    the real body of the function begins (after parameters have been moved
5840    to their home locations).  */
5841
5842 static void
5843 dwarfout_end_prologue (line)
5844      unsigned int line ATTRIBUTE_UNUSED;
5845 {
5846   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5847
5848   if (! use_gnu_debug_info_extensions)
5849     return;
5850
5851   function_section (current_function_decl);
5852   sprintf (label, BODY_BEGIN_LABEL_FMT, current_function_funcdef_no);
5853   ASM_OUTPUT_LABEL (asm_out_file, label);
5854 }
5855
5856 /* Output a marker (i.e. a label) for the point in the generated code where
5857    the real body of the function ends (just before the epilogue code).  */
5858
5859 static void
5860 dwarfout_end_function (line)
5861      unsigned int line ATTRIBUTE_UNUSED;
5862 {
5863   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5864
5865   if (! use_gnu_debug_info_extensions)
5866     return;
5867   function_section (current_function_decl);
5868   sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no);
5869   ASM_OUTPUT_LABEL (asm_out_file, label);
5870 }
5871
5872 /* Output a marker (i.e. a label) for the absolute end of the generated code
5873    for a function definition.  This gets called *after* the epilogue code
5874    has been generated.  */
5875
5876 static void
5877 dwarfout_end_epilogue ()
5878 {
5879   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5880
5881   /* Output a label to mark the endpoint of the code generated for this
5882      function.  */
5883
5884   sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no);
5885   ASM_OUTPUT_LABEL (asm_out_file, label);
5886 }
5887
5888 static void
5889 shuffle_filename_entry (new_zeroth)
5890      filename_entry *new_zeroth;
5891 {
5892   filename_entry temp_entry;
5893   filename_entry *limit_p;
5894   filename_entry *move_p;
5895
5896   if (new_zeroth == &filename_table[0])
5897     return;
5898
5899   temp_entry = *new_zeroth;
5900
5901   /* Shift entries up in the table to make room at [0].  */
5902
5903   limit_p = &filename_table[0];
5904   for (move_p = new_zeroth; move_p > limit_p; move_p--)
5905     *move_p = *(move_p-1);
5906
5907   /* Install the found entry at [0].  */
5908
5909   filename_table[0] = temp_entry;
5910 }
5911
5912 /* Create a new (string) entry for the .debug_sfnames section.  */
5913
5914 static void
5915 generate_new_sfname_entry ()
5916 {
5917   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5918
5919   fputc ('\n', asm_out_file);
5920   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
5921   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5922   ASM_OUTPUT_LABEL (asm_out_file, label);
5923   ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5924                                    filename_table[0].name
5925                                    ? filename_table[0].name
5926                                    : "");
5927   ASM_OUTPUT_POP_SECTION (asm_out_file);
5928 }
5929
5930 /* Lookup a filename (in the list of filenames that we know about here in
5931    dwarfout.c) and return its "index".  The index of each (known) filename
5932    is just a unique number which is associated with only that one filename.
5933    We need such numbers for the sake of generating labels (in the
5934    .debug_sfnames section) and references to those unique labels (in the
5935    .debug_srcinfo and .debug_macinfo sections).
5936
5937    If the filename given as an argument is not found in our current list,
5938    add it to the list and assign it the next available unique index number.
5939
5940    Whatever we do (i.e. whether we find a pre-existing filename or add a new
5941    one), we shuffle the filename found (or added) up to the zeroth entry of
5942    our list of filenames (which is always searched linearly).  We do this so
5943    as to optimize the most common case for these filename lookups within
5944    dwarfout.c.  The most common case by far is the case where we call
5945    lookup_filename to lookup the very same filename that we did a lookup
5946    on the last time we called lookup_filename.  We make sure that this
5947    common case is fast because such cases will constitute 99.9% of the
5948    lookups we ever do (in practice).
5949
5950    If we add a new filename entry to our table, we go ahead and generate
5951    the corresponding entry in the .debug_sfnames section right away.
5952    Doing so allows us to avoid tickling an assembler bug (present in some
5953    m68k assemblers) which yields assembly-time errors in cases where the
5954    difference of two label addresses is taken and where the two labels
5955    are in a section *other* than the one where the difference is being
5956    calculated, and where at least one of the two symbol references is a
5957    forward reference.  (This bug could be tickled by our .debug_srcinfo
5958    entries if we don't output their corresponding .debug_sfnames entries
5959    before them.) */
5960
5961 static unsigned
5962 lookup_filename (file_name)
5963      const char *file_name;
5964 {
5965   filename_entry *search_p;
5966   filename_entry *limit_p = &filename_table[ft_entries];
5967
5968   for (search_p = filename_table; search_p < limit_p; search_p++)
5969     if (!strcmp (file_name, search_p->name))
5970       {
5971         /* When we get here, we have found the filename that we were
5972            looking for in the filename_table.  Now we want to make sure
5973            that it gets moved to the zero'th entry in the table (if it
5974            is not already there) so that subsequent attempts to find the
5975            same filename will find it as quickly as possible.  */
5976
5977         shuffle_filename_entry (search_p);
5978         return filename_table[0].number;
5979       }
5980
5981   /* We come here whenever we have a new filename which is not registered
5982      in the current table.  Here we add it to the table.  */
5983
5984   /* Prepare to add a new table entry by making sure there is enough space
5985      in the table to do so.  If not, expand the current table.  */
5986
5987   if (ft_entries == ft_entries_allocated)
5988     {
5989       ft_entries_allocated += FT_ENTRIES_INCREMENT;
5990       filename_table
5991         = (filename_entry *)
5992           xrealloc (filename_table,
5993                     ft_entries_allocated * sizeof (filename_entry));
5994     }
5995
5996   /* Initially, add the new entry at the end of the filename table.  */
5997
5998   filename_table[ft_entries].number = ft_entries;
5999   filename_table[ft_entries].name = xstrdup (file_name);
6000
6001   /* Shuffle the new entry into filename_table[0].  */
6002
6003   shuffle_filename_entry (&filename_table[ft_entries]);
6004
6005   if (debug_info_level >= DINFO_LEVEL_NORMAL)
6006     generate_new_sfname_entry ();
6007
6008   ft_entries++;
6009   return filename_table[0].number;
6010 }
6011
6012 static void
6013 generate_srcinfo_entry (line_entry_num, files_entry_num)
6014      unsigned line_entry_num;
6015      unsigned files_entry_num;
6016 {
6017   char label[MAX_ARTIFICIAL_LABEL_BYTES];
6018
6019   fputc ('\n', asm_out_file);
6020   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6021   sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
6022   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
6023   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
6024   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
6025   ASM_OUTPUT_POP_SECTION (asm_out_file);
6026 }
6027
6028 static void
6029 dwarfout_source_line (line, filename)
6030      unsigned int line;
6031      const char *filename;
6032 {
6033   if (debug_info_level >= DINFO_LEVEL_NORMAL
6034       /* We can't emit line number info for functions in separate sections,
6035          because the assembler can't subtract labels in different sections.  */
6036       && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
6037     {
6038       char label[MAX_ARTIFICIAL_LABEL_BYTES];
6039       static unsigned last_line_entry_num = 0;
6040       static unsigned prev_file_entry_num = (unsigned) -1;
6041       unsigned this_file_entry_num;
6042
6043       function_section (current_function_decl);
6044       sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
6045       ASM_OUTPUT_LABEL (asm_out_file, label);
6046
6047       fputc ('\n', asm_out_file);
6048
6049       if (use_gnu_debug_info_extensions)
6050         this_file_entry_num = lookup_filename (filename);
6051       else
6052         this_file_entry_num = (unsigned) -1;
6053
6054       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6055       if (this_file_entry_num != prev_file_entry_num)
6056         {
6057           char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
6058
6059           sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
6060           ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
6061         }
6062
6063       {
6064         const char *tail = strrchr (filename, '/');
6065
6066         if (tail != NULL)
6067           filename = tail;
6068       }
6069
6070       dw2_asm_output_data (4, line, "%s:%u", filename, line);
6071       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6072       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
6073       ASM_OUTPUT_POP_SECTION (asm_out_file);
6074
6075       if (this_file_entry_num != prev_file_entry_num)
6076         generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
6077       prev_file_entry_num = this_file_entry_num;
6078     }
6079 }
6080
6081 /* Generate an entry in the .debug_macinfo section.  */
6082
6083 static void
6084 generate_macinfo_entry (type, offset, string)
6085      unsigned int type;
6086      rtx offset;
6087      const char *string;
6088 {
6089   if (! use_gnu_debug_info_extensions)
6090     return;
6091
6092   fputc ('\n', asm_out_file);
6093   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6094   assemble_integer (gen_rtx_PLUS (SImode, GEN_INT (type << 24), offset),
6095                     4, BITS_PER_UNIT, 1);
6096   ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
6097   ASM_OUTPUT_POP_SECTION (asm_out_file);
6098 }
6099
6100 /* Wrapper for toplev.c callback to check debug info level.  */
6101 static void
6102 dwarfout_start_source_file_check (line, filename)
6103      unsigned int line;
6104      const char *filename;
6105 {
6106   if (debug_info_level == DINFO_LEVEL_VERBOSE)
6107     dwarfout_start_source_file (line, filename);
6108 }
6109
6110 static void
6111 dwarfout_start_source_file (line, filename)
6112      unsigned int line ATTRIBUTE_UNUSED;
6113      const char *filename;
6114 {
6115   char label[MAX_ARTIFICIAL_LABEL_BYTES];
6116   const char *label1, *label2;
6117
6118   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
6119   label1 = (*label == '*') + label;
6120   label2 = (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL;
6121   generate_macinfo_entry (MACINFO_start,
6122                           gen_rtx_MINUS (Pmode,
6123                                          gen_rtx_SYMBOL_REF (Pmode, label1),
6124                                          gen_rtx_SYMBOL_REF (Pmode, label2)),
6125                           "");
6126 }
6127
6128 /* Wrapper for toplev.c callback to check debug info level.  */
6129 static void
6130 dwarfout_end_source_file_check (lineno)
6131      unsigned lineno;
6132 {
6133   if (debug_info_level == DINFO_LEVEL_VERBOSE)
6134     dwarfout_end_source_file (lineno);
6135 }
6136
6137 static void
6138 dwarfout_end_source_file (lineno)
6139      unsigned lineno;
6140 {
6141   generate_macinfo_entry (MACINFO_resume, GEN_INT (lineno), "");
6142 }
6143
6144 /* Called from check_newline in c-parse.y.  The `buffer' parameter
6145    contains the tail part of the directive line, i.e. the part which
6146    is past the initial whitespace, #, whitespace, directive-name,
6147    whitespace part.  */
6148
6149 static void
6150 dwarfout_define (lineno, buffer)
6151      unsigned lineno;
6152      const char *buffer;
6153 {
6154   static int initialized = 0;
6155
6156   if (!initialized)
6157     {
6158       dwarfout_start_source_file (0, primary_filename);
6159       initialized = 1;
6160     }
6161   generate_macinfo_entry (MACINFO_define, GEN_INT (lineno), buffer);
6162 }
6163
6164 /* Called from check_newline in c-parse.y.  The `buffer' parameter
6165    contains the tail part of the directive line, i.e. the part which
6166    is past the initial whitespace, #, whitespace, directive-name,
6167    whitespace part.  */
6168
6169 static void
6170 dwarfout_undef (lineno, buffer)
6171      unsigned lineno;
6172      const char *buffer;
6173 {
6174   generate_macinfo_entry (MACINFO_undef, GEN_INT (lineno), buffer);
6175 }
6176
6177 /* Set up for Dwarf output at the start of compilation.  */
6178
6179 static void
6180 dwarfout_init (main_input_filename)
6181      const char *main_input_filename;
6182 {
6183   /* Remember the name of the primary input file.  */
6184
6185   primary_filename = main_input_filename;
6186
6187   /* Allocate the initial hunk of the pending_sibling_stack.  */
6188
6189   pending_sibling_stack
6190     = (unsigned *)
6191         xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
6192   pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
6193   pending_siblings = 1;
6194
6195   /* Allocate the initial hunk of the filename_table.  */
6196
6197   filename_table
6198     = (filename_entry *)
6199         xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
6200   ft_entries_allocated = FT_ENTRIES_INCREMENT;
6201   ft_entries = 0;
6202
6203   /* Allocate the initial hunk of the pending_types_list.  */
6204
6205   pending_types_list
6206     = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
6207   pending_types_allocated = PENDING_TYPES_INCREMENT;
6208   pending_types = 0;
6209
6210   /* Create an artificial RECORD_TYPE node which we can use in our hack
6211      to get the DIEs representing types of formal parameters to come out
6212      only *after* the DIEs for the formal parameters themselves.  */
6213
6214   fake_containing_scope = make_node (RECORD_TYPE);
6215
6216   /* Output a starting label for the .text section.  */
6217
6218   fputc ('\n', asm_out_file);
6219   ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6220   ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
6221   ASM_OUTPUT_POP_SECTION (asm_out_file);
6222
6223   /* Output a starting label for the .data section.  */
6224
6225   fputc ('\n', asm_out_file);
6226   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6227   ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
6228   ASM_OUTPUT_POP_SECTION (asm_out_file);
6229
6230 #if 0 /* GNU C doesn't currently use .data1.  */
6231   /* Output a starting label for the .data1 section.  */
6232
6233   fputc ('\n', asm_out_file);
6234   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6235   ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
6236   ASM_OUTPUT_POP_SECTION (asm_out_file);
6237 #endif
6238
6239   /* Output a starting label for the .rodata section.  */
6240
6241   fputc ('\n', asm_out_file);
6242   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6243   ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
6244   ASM_OUTPUT_POP_SECTION (asm_out_file);
6245
6246 #if 0 /* GNU C doesn't currently use .rodata1.  */
6247   /* Output a starting label for the .rodata1 section.  */
6248
6249   fputc ('\n', asm_out_file);
6250   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6251   ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
6252   ASM_OUTPUT_POP_SECTION (asm_out_file);
6253 #endif
6254
6255   /* Output a starting label for the .bss section.  */
6256
6257   fputc ('\n', asm_out_file);
6258   ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6259   ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
6260   ASM_OUTPUT_POP_SECTION (asm_out_file);
6261
6262   if (debug_info_level >= DINFO_LEVEL_NORMAL)
6263     {
6264       if (use_gnu_debug_info_extensions)
6265         {
6266           /* Output a starting label and an initial (compilation directory)
6267              entry for the .debug_sfnames section.  The starting label will be
6268              referenced by the initial entry in the .debug_srcinfo section.  */
6269
6270           fputc ('\n', asm_out_file);
6271           ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
6272           ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
6273           {
6274             const char *pwd = getpwd ();
6275             char *dirname;
6276
6277             if (!pwd)
6278               fatal_io_error ("can't get current directory");
6279
6280             dirname = concat (pwd, "/", NULL);
6281             ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
6282             free (dirname);
6283           }
6284           ASM_OUTPUT_POP_SECTION (asm_out_file);
6285         }
6286
6287       if (debug_info_level >= DINFO_LEVEL_VERBOSE
6288           && use_gnu_debug_info_extensions)
6289         {
6290           /* Output a starting label for the .debug_macinfo section.  This
6291              label will be referenced by the AT_mac_info attribute in the
6292              TAG_compile_unit DIE.  */
6293
6294           fputc ('\n', asm_out_file);
6295           ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6296           ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
6297           ASM_OUTPUT_POP_SECTION (asm_out_file);
6298         }
6299
6300       /* Generate the initial entry for the .line section.  */
6301
6302       fputc ('\n', asm_out_file);
6303       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6304       ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
6305       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
6306       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6307       ASM_OUTPUT_POP_SECTION (asm_out_file);
6308
6309       if (use_gnu_debug_info_extensions)
6310         {
6311           /* Generate the initial entry for the .debug_srcinfo section.  */
6312
6313           fputc ('\n', asm_out_file);
6314           ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6315           ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
6316           ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
6317           ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
6318           ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6319           ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
6320 #ifdef DWARF_TIMESTAMPS
6321           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
6322 #else
6323           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6324 #endif
6325           ASM_OUTPUT_POP_SECTION (asm_out_file);
6326         }
6327
6328       /* Generate the initial entry for the .debug_pubnames section.  */
6329
6330       fputc ('\n', asm_out_file);
6331       ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6332       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6333       ASM_OUTPUT_POP_SECTION (asm_out_file);
6334
6335       /* Generate the initial entry for the .debug_aranges section.  */
6336
6337       fputc ('\n', asm_out_file);
6338       ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6339       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6340                                DEBUG_ARANGES_END_LABEL,
6341                                DEBUG_ARANGES_BEGIN_LABEL);
6342       ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_BEGIN_LABEL);
6343       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 1);
6344       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
6345       ASM_OUTPUT_POP_SECTION (asm_out_file);
6346     }
6347
6348   /* Setup first DIE number == 1.  */
6349   NEXT_DIE_NUM = next_unused_dienum++;
6350
6351   /* Generate the initial DIE for the .debug section.  Note that the
6352      (string) value given in the AT_name attribute of the TAG_compile_unit
6353      DIE will (typically) be a relative pathname and that this pathname
6354      should be taken as being relative to the directory from which the
6355      compiler was invoked when the given (base) source file was compiled.  */
6356
6357   fputc ('\n', asm_out_file);
6358   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6359   ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
6360   output_die (output_compile_unit_die, (PTR) main_input_filename);
6361   ASM_OUTPUT_POP_SECTION (asm_out_file);
6362
6363   fputc ('\n', asm_out_file);
6364 }
6365
6366 /* Output stuff that dwarf requires at the end of every file.  */
6367
6368 static void
6369 dwarfout_finish (main_input_filename)
6370      const char *main_input_filename ATTRIBUTE_UNUSED;
6371 {
6372   char label[MAX_ARTIFICIAL_LABEL_BYTES];
6373
6374   fputc ('\n', asm_out_file);
6375   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
6376   retry_incomplete_types ();
6377   fputc ('\n', asm_out_file);
6378
6379   /* Mark the end of the chain of siblings which represent all file-scope
6380      declarations in this compilation unit.  */
6381
6382   /* The (null) DIE which represents the terminator for the (sibling linked)
6383      list of file-scope items is *special*.  Normally, we would just call
6384      end_sibling_chain at this point in order to output a word with the
6385      value `4' and that word would act as the terminator for the list of
6386      DIEs describing file-scope items.  Unfortunately, if we were to simply
6387      do that, the label that would follow this DIE in the .debug section
6388      (i.e. `..D2') would *not* be properly aligned (as it must be on some
6389      machines) to a 4 byte boundary.
6390
6391      In order to force the label `..D2' to get aligned to a 4 byte boundary,
6392      the trick used is to insert extra (otherwise useless) padding bytes
6393      into the (null) DIE that we know must precede the ..D2 label in the
6394      .debug section.  The amount of padding required can be anywhere between
6395      0 and 3 bytes.  The length word at the start of this DIE (i.e. the one
6396      with the padding) would normally contain the value 4, but now it will
6397      also have to include the padding bytes, so it will instead have some
6398      value in the range 4..7.
6399
6400      Fortunately, the rules of Dwarf say that any DIE whose length word
6401      contains *any* value less than 8 should be treated as a null DIE, so
6402      this trick works out nicely.  Clever, eh?  Don't give me any credit
6403      (or blame).  I didn't think of this scheme.  I just conformed to it.
6404   */
6405
6406   output_die (output_padded_null_die, (void *) 0);
6407   dienum_pop ();
6408
6409   sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
6410   ASM_OUTPUT_LABEL (asm_out_file, label);       /* should be ..D2 */
6411   ASM_OUTPUT_POP_SECTION (asm_out_file);
6412
6413   /* Output a terminator label for the .text section.  */
6414
6415   fputc ('\n', asm_out_file);
6416   ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME);
6417   ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
6418   ASM_OUTPUT_POP_SECTION (asm_out_file);
6419
6420   /* Output a terminator label for the .data section.  */
6421
6422   fputc ('\n', asm_out_file);
6423   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME);
6424   ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
6425   ASM_OUTPUT_POP_SECTION (asm_out_file);
6426
6427 #if 0 /* GNU C doesn't currently use .data1.  */
6428   /* Output a terminator label for the .data1 section.  */
6429
6430   fputc ('\n', asm_out_file);
6431   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME);
6432   ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
6433   ASM_OUTPUT_POP_SECTION (asm_out_file);
6434 #endif
6435
6436   /* Output a terminator label for the .rodata section.  */
6437
6438   fputc ('\n', asm_out_file);
6439   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME);
6440   ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
6441   ASM_OUTPUT_POP_SECTION (asm_out_file);
6442
6443 #if 0 /* GNU C doesn't currently use .rodata1.  */
6444   /* Output a terminator label for the .rodata1 section.  */
6445
6446   fputc ('\n', asm_out_file);
6447   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME);
6448   ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
6449   ASM_OUTPUT_POP_SECTION (asm_out_file);
6450 #endif
6451
6452   /* Output a terminator label for the .bss section.  */
6453
6454   fputc ('\n', asm_out_file);
6455   ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME);
6456   ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
6457   ASM_OUTPUT_POP_SECTION (asm_out_file);
6458
6459   if (debug_info_level >= DINFO_LEVEL_NORMAL)
6460     {
6461       /* Output a terminating entry for the .line section.  */
6462
6463       fputc ('\n', asm_out_file);
6464       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6465       ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
6466       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6467       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6468       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6469       ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
6470       ASM_OUTPUT_POP_SECTION (asm_out_file);
6471
6472       if (use_gnu_debug_info_extensions)
6473         {
6474           /* Output a terminating entry for the .debug_srcinfo section.  */
6475
6476           fputc ('\n', asm_out_file);
6477           ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION);
6478           ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6479                                    LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6480           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6481           ASM_OUTPUT_POP_SECTION (asm_out_file);
6482         }
6483
6484       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6485         {
6486           /* Output terminating entries for the .debug_macinfo section.  */
6487
6488           dwarfout_end_source_file (0);
6489
6490           fputc ('\n', asm_out_file);
6491           ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
6492           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6493           ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6494           ASM_OUTPUT_POP_SECTION (asm_out_file);
6495         }
6496
6497       /* Generate the terminating entry for the .debug_pubnames section.  */
6498
6499       fputc ('\n', asm_out_file);
6500       ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
6501       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6502       ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6503       ASM_OUTPUT_POP_SECTION (asm_out_file);
6504
6505       /* Generate the terminating entries for the .debug_aranges section.
6506
6507          Note that we want to do this only *after* we have output the end
6508          labels (for the various program sections) which we are going to
6509          refer to here.  This allows us to work around a bug in the m68k
6510          svr4 assembler.  That assembler gives bogus assembly-time errors
6511          if (within any given section) you try to take the difference of
6512          two relocatable symbols, both of which are located within some
6513          other section, and if one (or both?) of the symbols involved is
6514          being forward-referenced.  By generating the .debug_aranges
6515          entries at this late point in the assembly output, we skirt the
6516          issue simply by avoiding forward-references.
6517       */
6518
6519       fputc ('\n', asm_out_file);
6520       ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
6521
6522       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6523       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6524
6525       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6526       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6527
6528 #if 0 /* GNU C doesn't currently use .data1.  */
6529       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6530       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6531                                              DATA1_BEGIN_LABEL);
6532 #endif
6533
6534       ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6535       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6536                                              RODATA_BEGIN_LABEL);
6537
6538 #if 0 /* GNU C doesn't currently use .rodata1.  */
6539       ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6540       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6541                                              RODATA1_BEGIN_LABEL);
6542 #endif
6543
6544       ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6545       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6546
6547       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6548       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6549
6550       ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_END_LABEL);
6551       ASM_OUTPUT_POP_SECTION (asm_out_file);
6552     }
6553
6554   /* There should not be any pending types left at the end.  We need
6555      this now because it may not have been checked on the last call to
6556      dwarfout_file_scope_decl.  */
6557   if (pending_types != 0)
6558     abort ();
6559 }
6560
6561 #endif /* DWARF_DEBUGGING_INFO */