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