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