]> gcc.gnu.org Git - gcc.git/blame - gcc/dwarfout.c
entered into RCS
[gcc.git] / gcc / dwarfout.c
CommitLineData
340ccaab
TW
1/* This file contains code written by Ron Guilmette (rfg@ncd.com) for
2 Network Computing Devices, August, September, October, November 1990.
3
4 Output Dwarf format symbol table information from the GNU C compiler.
5 Copyright (C) 1992 Free Software Foundation, Inc.
6
7This file is part of GNU CC.
8
9GNU CC is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2, or (at your option)
12any later version.
13
14GNU CC is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with GNU CC; see the file COPYING. If not, write to
21the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22
23#include "config.h"
24
25#ifdef DWARF_DEBUGGING_INFO
26#include <stdio.h>
27#include "dwarf.h"
28#include "tree.h"
29#include "flags.h"
30#include "rtl.h"
31#include "insn-config.h"
32#include "reload.h"
33#include "output.h"
9a631e8e 34#include "defaults.h"
340ccaab 35
648ebe7b
RS
36#ifndef DWARF_VERSION
37#define DWARF_VERSION 1
38#endif
39
340ccaab
TW
40/* #define NDEBUG 1 */
41#include <assert.h>
42
43#if defined(DWARF_TIMESTAMPS)
44#if defined(POSIX)
45#include <time.h>
46#else /* !defined(POSIX) */
47#include <sys/types.h>
48#if defined(__STDC__)
49extern time_t time (time_t *);
50#else /* !defined(__STDC__) */
51extern time_t time ();
52#endif /* !defined(__STDC__) */
53#endif /* !defined(POSIX) */
54#endif /* defined(DWARF_TIMESTAMPS) */
55
56#if defined(USG) || defined(POSIX)
57#include <string.h>
58#else
59#include <strings.h>
60#define strrchr rindex
340ccaab
TW
61#endif
62
9a631e8e 63extern char *getpwd ();
2e494f70 64
340ccaab
TW
65/* IMPORTANT NOTE: Please see the file README.DWARF for important details
66 regarding the GNU implementation of Dwarf. */
67
68/* NOTE: In the comments in this file, many references are made to
69 so called "Debugging Information Entries". For the sake of brevity,
70 this term is abbreviated to `DIE' throughout the remainder of this
71 file. */
72
73/* Note that the implementation of C++ support herein is (as yet) unfinished.
74 If you want to try to complete it, more power to you. */
75
76#if defined(__GNUC__) && (NDEBUG == 1)
77#define inline static inline
78#else
79#define inline static
80#endif
81
82/* How to start an assembler comment. */
83#ifndef ASM_COMMENT_START
84#define ASM_COMMENT_START ";#"
85#endif
86
87/* Define a macro which, when given a pointer to some BLOCK node, returns
88 a pointer to the FUNCTION_DECL node from which the given BLOCK node
89 was instantiated (as an inline expansion). This macro needs to be
90 defined properly in tree.h, however for the moment, we just fake it. */
91
92#define BLOCK_INLINE_FUNCTION(block) 0
93
94/* Define a macro which returns non-zero for any tagged type which is
95 used (directly or indirectly) in the specification of either some
96 function's return type or some formal parameter of some function.
97 We use this macro when we are operating in "terse" mode to help us
98 know what tagged types have to be represented in Dwarf (even in
99 terse mode) and which ones don't.
100
101 A flag bit with this meaning really should be a part of the normal
102 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
103 for these nodes. For now, we have to just fake it. It it safe for
104 us to simply return zero for all complete tagged types (which will
105 get forced out anyway if they were used in the specification of some
106 formal or return type) and non-zero for all incomplete tagged types.
107*/
108
109#define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
110
340ccaab
TW
111extern int flag_traditional;
112extern char *version_string;
113extern char *language_string;
114
115/* Maximum size (in bytes) of an artificially generated label. */
116
117#define MAX_ARTIFICIAL_LABEL_BYTES 30
118\f
119/* Make sure we know the sizes of the various types dwarf can describe.
120 These are only defaults. If the sizes are different for your target,
121 you should override these values by defining the appropriate symbols
122 in your tm.h file. */
123
124#ifndef CHAR_TYPE_SIZE
125#define CHAR_TYPE_SIZE BITS_PER_UNIT
126#endif
127
128#ifndef SHORT_TYPE_SIZE
129#define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
130#endif
131
132#ifndef INT_TYPE_SIZE
133#define INT_TYPE_SIZE BITS_PER_WORD
134#endif
135
136#ifndef LONG_TYPE_SIZE
137#define LONG_TYPE_SIZE BITS_PER_WORD
138#endif
139
140#ifndef LONG_LONG_TYPE_SIZE
141#define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
142#endif
143
144#ifndef WCHAR_TYPE_SIZE
145#define WCHAR_TYPE_SIZE INT_TYPE_SIZE
146#endif
147
148#ifndef WCHAR_UNSIGNED
149#define WCHAR_UNSIGNED 0
150#endif
151
152#ifndef FLOAT_TYPE_SIZE
153#define FLOAT_TYPE_SIZE BITS_PER_WORD
154#endif
155
156#ifndef DOUBLE_TYPE_SIZE
157#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
158#endif
159
160#ifndef LONG_DOUBLE_TYPE_SIZE
161#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
162#endif
163\f
164/* Structure to keep track of source filenames. */
165
166struct filename_entry {
167 unsigned number;
168 char * name;
169};
170
171typedef struct filename_entry filename_entry;
172
173/* Pointer to an array of elements, each one having the structure above. */
174
175static filename_entry *filename_table;
176
177/* Total number of entries in the table (i.e. array) pointed to by
178 `filename_table'. This is the *total* and includes both used and
179 unused slots. */
180
181static unsigned ft_entries_allocated;
182
183/* Number of entries in the filename_table which are actually in use. */
184
185static unsigned ft_entries;
186
187/* Size (in elements) of increments by which we may expand the filename
188 table. Actually, a single hunk of space of this size should be enough
189 for most typical programs. */
190
191#define FT_ENTRIES_INCREMENT 64
192
193/* Local pointer to the name of the main input file. Initialized in
194 dwarfout_init. */
195
196static char *primary_filename;
197
198/* Pointer to the most recent filename for which we produced some line info. */
199
200static char *last_filename;
201
202/* For Dwarf output, we must assign lexical-blocks id numbers
203 in the order in which their beginnings are encountered.
204 We output Dwarf debugging info that refers to the beginnings
205 and ends of the ranges of code for each lexical block with
206 assembler labels ..Bn and ..Bn.e, where n is the block number.
207 The labels themselves are generated in final.c, which assigns
208 numbers to the blocks in the same way. */
209
210static unsigned next_block_number = 2;
211
212/* Counter to generate unique names for DIEs. */
213
214static unsigned next_unused_dienum = 1;
215
216/* Number of the DIE which is currently being generated. */
217
218static unsigned current_dienum;
219
220/* Number to use for the special "pubname" label on the next DIE which
221 represents a function or data object defined in this compilation
222 unit which has "extern" linkage. */
223
224static next_pubname_number = 0;
225
226#define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
227
228/* Pointer to a dynamically allocated list of pre-reserved and still
229 pending sibling DIE numbers. Note that this list will grow as needed. */
230
231static unsigned *pending_sibling_stack;
232
233/* Counter to keep track of the number of pre-reserved and still pending
234 sibling DIE numbers. */
235
236static unsigned pending_siblings;
237
238/* The currently allocated size of the above list (expressed in number of
239 list elements). */
240
241static unsigned pending_siblings_allocated;
242
243/* Size (in elements) of increments by which we may expand the pending
244 sibling stack. Actually, a single hunk of space of this size should
245 be enough for most typical programs. */
246
247#define PENDING_SIBLINGS_INCREMENT 64
248
249/* Non-zero if we are performing our file-scope finalization pass and if
6dc42e49 250 we should force out Dwarf descriptions of any and all file-scope
340ccaab
TW
251 tagged types which are still incomplete types. */
252
253static int finalizing = 0;
254
255/* A pointer to the base of a list of pending types which we haven't
256 generated DIEs for yet, but which we will have to come back to
257 later on. */
258
259static tree *pending_types_list;
260
261/* Number of elements currently allocated for the pending_types_list. */
262
263static unsigned pending_types_allocated;
264
265/* Number of elements of pending_types_list currently in use. */
266
267static unsigned pending_types;
268
269/* Size (in elements) of increments by which we may expand the pending
270 types list. Actually, a single hunk of space of this size should
271 be enough for most typical programs. */
272
273#define PENDING_TYPES_INCREMENT 64
274
6dc42e49 275/* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
340ccaab
TW
276 This is used in a hack to help us get the DIEs describing types of
277 formal parameters to come *after* all of the DIEs describing the formal
278 parameters themselves. That's necessary in order to be compatible
6dc42e49 279 with what the brain-damaged svr4 SDB debugger requires. */
340ccaab
TW
280
281static tree fake_containing_scope;
282
283/* The number of the current function definition that we are generating
284 debugging information for. These numbers range from 1 up to the maximum
285 number of function definitions contained within the current compilation
286 unit. These numbers are used to create unique labels for various things
287 contained within various function definitions. */
288
289static unsigned current_funcdef_number = 1;
290
291/* Forward declarations for functions defined in this file. */
292
293static void output_type ();
294static void type_attribute ();
295static void output_decls_for_scope ();
296static void output_decl ();
297static unsigned lookup_filename ();
298\f
299/* Definitions of defaults for assembler-dependent names of various
300 pseudo-ops and section names.
301
302 Theses may be overridden in your tm.h file (if necessary) for your
303 particular assembler. The default values provided here correspond to
304 what is expected by "standard" AT&T System V.4 assemblers. */
305
306#ifndef FILE_ASM_OP
2e494f70 307#define FILE_ASM_OP ".file"
340ccaab
TW
308#endif
309#ifndef VERSION_ASM_OP
2e494f70 310#define VERSION_ASM_OP ".version"
340ccaab 311#endif
340ccaab 312#ifndef UNALIGNED_SHORT_ASM_OP
2e494f70 313#define UNALIGNED_SHORT_ASM_OP ".2byte"
340ccaab
TW
314#endif
315#ifndef UNALIGNED_INT_ASM_OP
2e494f70 316#define UNALIGNED_INT_ASM_OP ".4byte"
340ccaab 317#endif
9a631e8e
RS
318#ifndef ASM_BYTE_OP
319#define ASM_BYTE_OP ".byte"
320#endif
648ebe7b
RS
321#ifndef SET_ASM_OP
322#define SET_ASM_OP ".set"
340ccaab 323#endif
85595d1a
RS
324
325/* Pseudo-ops for pushing the current section onto the section stack (and
326 simultaneously changing to a new section) and for poping back to the
327 section we were in immediately before this one. Note that most svr4
328 assemblers only maintain a one level stack... you can push all the
329 sections you want, but you can only pop out one level. (The sparc
648ebe7b 330 svr4 assembler is an exception to this general rule.) That's
85595d1a
RS
331 OK because we only use at most one level of the section stack herein. */
332
333#ifndef PUSHSECTION_ASM_OP
9a631e8e 334#define PUSHSECTION_ASM_OP ".section"
85595d1a
RS
335#endif
336#ifndef POPSECTION_ASM_OP
9a631e8e 337#define POPSECTION_ASM_OP ".previous"
85595d1a
RS
338#endif
339
340/* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
341 to print the PUSHSECTION_ASM_OP and the section name. The default here
342 works for almost all svr4 assemblers, except for the sparc, where the
343 section name must be enclosed in double quotes. (See sparcv4.h.) */
344
345#ifndef PUSHSECTION_FORMAT
346#define PUSHSECTION_FORMAT "%s\t%s\n"
347#endif
348
349#ifndef DEBUG_SECTION
350#define DEBUG_SECTION ".debug"
351#endif
352#ifndef LINE_SECTION
353#define LINE_SECTION ".line"
354#endif
355#ifndef SFNAMES_SECTION
356#define SFNAMES_SECTION ".debug_sfnames"
357#endif
358#ifndef SRCINFO_SECTION
359#define SRCINFO_SECTION ".debug_srcinfo"
360#endif
361#ifndef MACINFO_SECTION
362#define MACINFO_SECTION ".debug_macinfo"
363#endif
364#ifndef PUBNAMES_SECTION
365#define PUBNAMES_SECTION ".debug_pubnames"
366#endif
367#ifndef ARANGES_SECTION
368#define ARANGES_SECTION ".debug_aranges"
369#endif
370#ifndef TEXT_SECTION
371#define TEXT_SECTION ".text"
372#endif
373#ifndef DATA_SECTION
374#define DATA_SECTION ".data"
375#endif
376#ifndef DATA1_SECTION
377#define DATA1_SECTION ".data1"
378#endif
379#ifndef RODATA_SECTION
380#define RODATA_SECTION ".rodata"
381#endif
382#ifndef RODATA1_SECTION
383#define RODATA1_SECTION ".rodata1"
384#endif
385#ifndef BSS_SECTION
386#define BSS_SECTION ".bss"
387#endif
340ccaab
TW
388\f
389/* Definitions of defaults for formats and names of various special
390 (artificial) labels which may be generated within this file (when
391 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
392
393 If necessary, these may be overridden from within your tm.h file,
9a631e8e
RS
394 but typically, you should never need to override these.
395
396 These labels have been hacked (temporarily) so that they all begin with
648ebe7b
RS
397 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
398 stock m88k/svr4 assembler, both of which need to see .L at the start of
399 a label in order to prevent that label from going into the linker symbol
400 table). When I get time, I'll have to fix this the right way so that we
401 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
402 but that will require a rather massive set of changes. For the moment,
403 the following definitions out to produce the right results for all svr4
404 and svr3 assemblers. -- rfg
9a631e8e 405*/
340ccaab
TW
406
407#ifndef TEXT_BEGIN_LABEL
9a631e8e 408#define TEXT_BEGIN_LABEL ".L_text_b"
340ccaab
TW
409#endif
410#ifndef TEXT_END_LABEL
9a631e8e 411#define TEXT_END_LABEL ".L_text_e"
340ccaab
TW
412#endif
413
414#ifndef DATA_BEGIN_LABEL
9a631e8e 415#define DATA_BEGIN_LABEL ".L_data_b"
340ccaab
TW
416#endif
417#ifndef DATA_END_LABEL
9a631e8e 418#define DATA_END_LABEL ".L_data_e"
340ccaab
TW
419#endif
420
421#ifndef DATA1_BEGIN_LABEL
9a631e8e 422#define DATA1_BEGIN_LABEL ".L_data1_b"
340ccaab
TW
423#endif
424#ifndef DATA1_END_LABEL
9a631e8e 425#define DATA1_END_LABEL ".L_data1_e"
340ccaab
TW
426#endif
427
428#ifndef RODATA_BEGIN_LABEL
9a631e8e 429#define RODATA_BEGIN_LABEL ".L_rodata_b"
340ccaab
TW
430#endif
431#ifndef RODATA_END_LABEL
9a631e8e 432#define RODATA_END_LABEL ".L_rodata_e"
340ccaab
TW
433#endif
434
435#ifndef RODATA1_BEGIN_LABEL
9a631e8e 436#define RODATA1_BEGIN_LABEL ".L_rodata1_b"
340ccaab
TW
437#endif
438#ifndef RODATA1_END_LABEL
9a631e8e 439#define RODATA1_END_LABEL ".L_rodata1_e"
340ccaab
TW
440#endif
441
442#ifndef BSS_BEGIN_LABEL
9a631e8e 443#define BSS_BEGIN_LABEL ".L_bss_b"
340ccaab
TW
444#endif
445#ifndef BSS_END_LABEL
9a631e8e 446#define BSS_END_LABEL ".L_bss_e"
340ccaab
TW
447#endif
448
449#ifndef LINE_BEGIN_LABEL
9a631e8e 450#define LINE_BEGIN_LABEL ".L_line_b"
340ccaab
TW
451#endif
452#ifndef LINE_LAST_ENTRY_LABEL
9a631e8e 453#define LINE_LAST_ENTRY_LABEL ".L_line_last"
340ccaab
TW
454#endif
455#ifndef LINE_END_LABEL
9a631e8e 456#define LINE_END_LABEL ".L_line_e"
340ccaab
TW
457#endif
458
459#ifndef DEBUG_BEGIN_LABEL
9a631e8e 460#define DEBUG_BEGIN_LABEL ".L_debug_b"
340ccaab
TW
461#endif
462#ifndef SFNAMES_BEGIN_LABEL
9a631e8e 463#define SFNAMES_BEGIN_LABEL ".L_sfnames_b"
340ccaab
TW
464#endif
465#ifndef SRCINFO_BEGIN_LABEL
9a631e8e 466#define SRCINFO_BEGIN_LABEL ".L_srcinfo_b"
340ccaab
TW
467#endif
468#ifndef MACINFO_BEGIN_LABEL
9a631e8e 469#define MACINFO_BEGIN_LABEL ".L_macinfo_b"
340ccaab
TW
470#endif
471
472#ifndef DIE_BEGIN_LABEL_FMT
9a631e8e 473#define DIE_BEGIN_LABEL_FMT ".L_D%u"
340ccaab
TW
474#endif
475#ifndef DIE_END_LABEL_FMT
9a631e8e 476#define DIE_END_LABEL_FMT ".L_D%u_e"
340ccaab
TW
477#endif
478#ifndef PUB_DIE_LABEL_FMT
9a631e8e 479#define PUB_DIE_LABEL_FMT ".L_P%u"
340ccaab
TW
480#endif
481#ifndef INSN_LABEL_FMT
9a631e8e 482#define INSN_LABEL_FMT ".L_I%u_%u"
340ccaab
TW
483#endif
484#ifndef BLOCK_BEGIN_LABEL_FMT
9a631e8e 485#define BLOCK_BEGIN_LABEL_FMT ".L_B%u"
340ccaab
TW
486#endif
487#ifndef BLOCK_END_LABEL_FMT
9a631e8e 488#define BLOCK_END_LABEL_FMT ".L_B%u_e"
340ccaab
TW
489#endif
490#ifndef SS_BEGIN_LABEL_FMT
9a631e8e 491#define SS_BEGIN_LABEL_FMT ".L_s%u"
340ccaab
TW
492#endif
493#ifndef SS_END_LABEL_FMT
9a631e8e 494#define SS_END_LABEL_FMT ".L_s%u_e"
340ccaab
TW
495#endif
496#ifndef EE_BEGIN_LABEL_FMT
9a631e8e 497#define EE_BEGIN_LABEL_FMT ".L_e%u"
340ccaab
TW
498#endif
499#ifndef EE_END_LABEL_FMT
9a631e8e 500#define EE_END_LABEL_FMT ".L_e%u_e"
340ccaab
TW
501#endif
502#ifndef MT_BEGIN_LABEL_FMT
9a631e8e 503#define MT_BEGIN_LABEL_FMT ".L_t%u"
340ccaab
TW
504#endif
505#ifndef MT_END_LABEL_FMT
9a631e8e 506#define MT_END_LABEL_FMT ".L_t%u_e"
340ccaab
TW
507#endif
508#ifndef LOC_BEGIN_LABEL_FMT
9a631e8e 509#define LOC_BEGIN_LABEL_FMT ".L_l%u"
340ccaab
TW
510#endif
511#ifndef LOC_END_LABEL_FMT
9a631e8e 512#define LOC_END_LABEL_FMT ".L_l%u_e"
340ccaab
TW
513#endif
514#ifndef BOUND_BEGIN_LABEL_FMT
9a631e8e 515#define BOUND_BEGIN_LABEL_FMT ".L_b%u_%u_%c"
340ccaab
TW
516#endif
517#ifndef BOUND_END_LABEL_FMT
9a631e8e 518#define BOUND_END_LABEL_FMT ".L_b%u_%u_%c_e"
340ccaab
TW
519#endif
520#ifndef DERIV_BEGIN_LABEL_FMT
9a631e8e 521#define DERIV_BEGIN_LABEL_FMT ".L_d%u"
340ccaab
TW
522#endif
523#ifndef DERIV_END_LABEL_FMT
9a631e8e 524#define DERIV_END_LABEL_FMT ".L_d%u_e"
340ccaab
TW
525#endif
526#ifndef SL_BEGIN_LABEL_FMT
9a631e8e 527#define SL_BEGIN_LABEL_FMT ".L_sl%u"
340ccaab
TW
528#endif
529#ifndef SL_END_LABEL_FMT
9a631e8e 530#define SL_END_LABEL_FMT ".L_sl%u_e"
340ccaab
TW
531#endif
532#ifndef FUNC_END_LABEL_FMT
9a631e8e 533#define FUNC_END_LABEL_FMT ".L_f%u_e"
340ccaab
TW
534#endif
535#ifndef TYPE_NAME_FMT
9a631e8e 536#define TYPE_NAME_FMT ".L_T%u"
340ccaab
TW
537#endif
538#ifndef LINE_CODE_LABEL_FMT
9a631e8e 539#define LINE_CODE_LABEL_FMT ".L_LC%u"
340ccaab
TW
540#endif
541#ifndef SFNAMES_ENTRY_LABEL_FMT
9a631e8e 542#define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
340ccaab
TW
543#endif
544#ifndef LINE_ENTRY_LABEL_FMT
9a631e8e 545#define LINE_ENTRY_LABEL_FMT ".L_LE%u"
340ccaab
TW
546#endif
547\f
548/* Definitions of defaults for various types of primitive assembly language
549 output operations.
550
551 If necessary, these may be overridden from within your tm.h file,
648ebe7b
RS
552 but typically, you shouldn't need to override these. One known
553 exception is ASM_OUTPUT_DEF which has to be different for stock
554 sparc/svr4 assemblers.
85595d1a
RS
555*/
556
557#ifndef ASM_OUTPUT_PUSH_SECTION
558#define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
559 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
560#endif
561
562#ifndef ASM_OUTPUT_POP_SECTION
563#define ASM_OUTPUT_POP_SECTION(FILE) \
9a631e8e 564 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
85595d1a 565#endif
340ccaab
TW
566
567#ifndef ASM_OUTPUT_SOURCE_FILENAME
568#define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \
2e494f70 569 fprintf ((FILE), "\t%s\t\"%s\"\n", FILE_ASM_OP, NAME)
340ccaab
TW
570#endif
571
572#ifndef ASM_OUTPUT_DEF
573#define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
648ebe7b 574 do { fprintf ((FILE), "\t%s\t", SET_ASM_OP); \
340ccaab
TW
575 assemble_name (FILE, LABEL1); \
576 fprintf (FILE, ","); \
577 assemble_name (FILE, LABEL2); \
578 fprintf (FILE, "\n"); \
579 } while (0)
580#endif
581
340ccaab
TW
582#ifndef ASM_OUTPUT_DWARF_DELTA2
583#define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
2e494f70 584 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
340ccaab
TW
585 assemble_name (FILE, LABEL1); \
586 fprintf (FILE, "-"); \
587 assemble_name (FILE, LABEL2); \
588 fprintf (FILE, "\n"); \
589 } while (0)
590#endif
591
592#ifndef ASM_OUTPUT_DWARF_DELTA4
593#define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
2e494f70 594 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
340ccaab
TW
595 assemble_name (FILE, LABEL1); \
596 fprintf (FILE, "-"); \
597 assemble_name (FILE, LABEL2); \
598 fprintf (FILE, "\n"); \
599 } while (0)
600#endif
601
602#ifndef ASM_OUTPUT_DWARF_TAG
603#define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
9a631e8e
RS
604 do { \
605 fprintf ((FILE), "\t%s\t0x%x", \
606 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
607 if (flag_verbose_asm) \
608 fprintf ((FILE), "\t%s %s", \
609 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
610 fputc ('\n', (FILE)); \
611 } while (0)
340ccaab
TW
612#endif
613
614#ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
9a631e8e
RS
615#define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
616 do { \
617 fprintf ((FILE), "\t%s\t0x%x", \
618 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
619 if (flag_verbose_asm) \
620 fprintf ((FILE), "\t%s %s", \
621 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
622 fputc ('\n', (FILE)); \
623 } while (0)
340ccaab
TW
624#endif
625
626#ifndef ASM_OUTPUT_DWARF_STACK_OP
627#define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
9a631e8e 628 do { \
648ebe7b 629 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
9a631e8e
RS
630 if (flag_verbose_asm) \
631 fprintf ((FILE), "\t%s %s", \
632 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
633 fputc ('\n', (FILE)); \
634 } while (0)
340ccaab
TW
635#endif
636
637#ifndef ASM_OUTPUT_DWARF_FUND_TYPE
638#define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
9a631e8e
RS
639 do { \
640 fprintf ((FILE), "\t%s\t0x%x", \
641 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
642 if (flag_verbose_asm) \
643 fprintf ((FILE), "\t%s %s", \
644 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
645 fputc ('\n', (FILE)); \
646 } while (0)
340ccaab
TW
647#endif
648
649#ifndef ASM_OUTPUT_DWARF_FMT_BYTE
650#define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
9a631e8e 651 do { \
648ebe7b 652 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
9a631e8e
RS
653 if (flag_verbose_asm) \
654 fprintf ((FILE), "\t%s %s", \
655 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
656 fputc ('\n', (FILE)); \
657 } while (0)
340ccaab
TW
658#endif
659
660#ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
661#define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
9a631e8e 662 do { \
648ebe7b 663 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
9a631e8e
RS
664 if (flag_verbose_asm) \
665 fprintf ((FILE), "\t%s %s", \
666 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
667 fputc ('\n', (FILE)); \
668 } while (0)
340ccaab
TW
669#endif
670\f
671#ifndef ASM_OUTPUT_DWARF_ADDR
672#define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
2e494f70 673 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
340ccaab
TW
674 assemble_name (FILE, LABEL); \
675 fprintf (FILE, "\n"); \
676 } while (0)
677#endif
678
679#ifndef ASM_OUTPUT_DWARF_ADDR_CONST
680#define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
648ebe7b
RS
681 do { \
682 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
683 output_addr_const ((FILE), (RTX)); \
684 fputc ('\n', (FILE)); \
685 } while (0)
340ccaab
TW
686#endif
687
688#ifndef ASM_OUTPUT_DWARF_REF
689#define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
2e494f70 690 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
340ccaab
TW
691 assemble_name (FILE, LABEL); \
692 fprintf (FILE, "\n"); \
693 } while (0)
694#endif
695
696#ifndef ASM_OUTPUT_DWARF_DATA1
697#define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
648ebe7b 698 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
340ccaab
TW
699#endif
700
701#ifndef ASM_OUTPUT_DWARF_DATA2
702#define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
2e494f70 703 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
340ccaab
TW
704#endif
705
706#ifndef ASM_OUTPUT_DWARF_DATA4
707#define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
2e494f70 708 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
340ccaab
TW
709#endif
710
711#ifndef ASM_OUTPUT_DWARF_DATA8
712#define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
713 do { \
714 if (WORDS_BIG_ENDIAN) \
715 { \
2e494f70
RS
716 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
717 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
340ccaab
TW
718 } \
719 else \
720 { \
2e494f70
RS
721 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
722 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
340ccaab
TW
723 } \
724 } while (0)
725#endif
726
727#ifndef ASM_OUTPUT_DWARF_STRING
728#define ASM_OUTPUT_DWARF_STRING(FILE,P) \
729 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
730#endif
731\f
732/************************ general utility functions **************************/
733
734inline char *
735xstrdup (s)
736 register char *s;
737{
738 register char *p = (char *) xmalloc (strlen (s) + 1);
739
740 strcpy (p, s);
741 return p;
742}
743
648ebe7b
RS
744inline int
745is_pseudo_reg (rtl)
746 register rtx rtl;
747{
748 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
749 || ((GET_CODE (rtl) == SUBREG)
750 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
751}
752
340ccaab 753static char *
9a631e8e 754dwarf_tag_name (tag)
340ccaab
TW
755 register unsigned tag;
756{
757 switch (tag)
758 {
9a631e8e
RS
759 case TAG_padding: return "TAG_padding";
760 case TAG_array_type: return "TAG_array_type";
761 case TAG_class_type: return "TAG_class_type";
762 case TAG_entry_point: return "TAG_entry_point";
763 case TAG_enumeration_type: return "TAG_enumeration_type";
764 case TAG_formal_parameter: return "TAG_formal_parameter";
765 case TAG_global_subroutine: return "TAG_global_subroutine";
766 case TAG_global_variable: return "TAG_global_variable";
767 case TAG_label: return "TAG_label";
768 case TAG_lexical_block: return "TAG_lexical_block";
769 case TAG_local_variable: return "TAG_local_variable";
770 case TAG_member: return "TAG_member";
771 case TAG_pointer_type: return "TAG_pointer_type";
772 case TAG_reference_type: return "TAG_reference_type";
773 case TAG_compile_unit: return "TAG_compile_unit";
774 case TAG_string_type: return "TAG_string_type";
775 case TAG_structure_type: return "TAG_structure_type";
776 case TAG_subroutine: return "TAG_subroutine";
777 case TAG_subroutine_type: return "TAG_subroutine_type";
778 case TAG_typedef: return "TAG_typedef";
779 case TAG_union_type: return "TAG_union_type";
340ccaab 780 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
9a631e8e
RS
781 case TAG_variant: return "TAG_variant";
782 case TAG_common_block: return "TAG_common_block";
783 case TAG_common_inclusion: return "TAG_common_inclusion";
784 case TAG_inheritance: return "TAG_inheritance";
785 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
786 case TAG_module: return "TAG_module";
787 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
788 case TAG_set_type: return "TAG_set_type";
789 case TAG_subrange_type: return "TAG_subrange_type";
790 case TAG_with_stmt: return "TAG_with_stmt";
791
792 /* GNU extensions. */
793
794 case TAG_format_label: return "TAG_format_label";
795 case TAG_namelist: return "TAG_namelist";
796 case TAG_function_template: return "TAG_function_template";
797 case TAG_class_template: return "TAG_class_template";
798
799 default: return "<unknown tag>";
340ccaab
TW
800 }
801}
802
803static char *
9a631e8e 804dwarf_attr_name (attr)
340ccaab
TW
805 register unsigned attr;
806{
807 switch (attr)
808 {
9a631e8e
RS
809 case AT_sibling: return "AT_sibling";
810 case AT_location: return "AT_location";
811 case AT_name: return "AT_name";
812 case AT_fund_type: return "AT_fund_type";
813 case AT_mod_fund_type: return "AT_mod_fund_type";
814 case AT_user_def_type: return "AT_user_def_type";
815 case AT_mod_u_d_type: return "AT_mod_u_d_type";
816 case AT_ordering: return "AT_ordering";
817 case AT_subscr_data: return "AT_subscr_data";
818 case AT_byte_size: return "AT_byte_size";
819 case AT_bit_offset: return "AT_bit_offset";
820 case AT_bit_size: return "AT_bit_size";
821 case AT_element_list: return "AT_element_list";
822 case AT_stmt_list: return "AT_stmt_list";
823 case AT_low_pc: return "AT_low_pc";
824 case AT_high_pc: return "AT_high_pc";
825 case AT_language: return "AT_language";
826 case AT_member: return "AT_member";
827 case AT_discr: return "AT_discr";
828 case AT_discr_value: return "AT_discr_value";
829 case AT_string_length: return "AT_string_length";
830 case AT_common_reference: return "AT_common_reference";
831 case AT_comp_dir: return "AT_comp_dir";
832 case AT_const_value_string: return "AT_const_value_string";
833 case AT_const_value_data2: return "AT_const_value_data2";
834 case AT_const_value_data4: return "AT_const_value_data4";
835 case AT_const_value_data8: return "AT_const_value_data8";
836 case AT_const_value_block2: return "AT_const_value_block2";
340ccaab 837 case AT_const_value_block4: return "AT_const_value_block4";
9a631e8e
RS
838 case AT_containing_type: return "AT_containing_type";
839 case AT_default_value_addr: return "AT_default_value_addr";
840 case AT_default_value_data2: return "AT_default_value_data2";
841 case AT_default_value_data4: return "AT_default_value_data4";
842 case AT_default_value_data8: return "AT_default_value_data8";
843 case AT_default_value_string: return "AT_default_value_string";
844 case AT_friends: return "AT_friends";
845 case AT_inline: return "AT_inline";
846 case AT_is_optional: return "AT_is_optional";
847 case AT_lower_bound_ref: return "AT_lower_bound_ref";
848 case AT_lower_bound_data2: return "AT_lower_bound_data2";
849 case AT_lower_bound_data4: return "AT_lower_bound_data4";
850 case AT_lower_bound_data8: return "AT_lower_bound_data8";
851 case AT_private: return "AT_private";
852 case AT_producer: return "AT_producer";
853 case AT_program: return "AT_program";
854 case AT_protected: return "AT_protected";
855 case AT_prototyped: return "AT_prototyped";
856 case AT_public: return "AT_public";
857 case AT_pure_virtual: return "AT_pure_virtual";
858 case AT_return_addr: return "AT_return_addr";
859 case AT_specification: return "AT_specification";
860 case AT_start_scope: return "AT_start_scope";
861 case AT_stride_size: return "AT_stride_size";
862 case AT_upper_bound_ref: return "AT_upper_bound_ref";
863 case AT_upper_bound_data2: return "AT_upper_bound_data2";
864 case AT_upper_bound_data4: return "AT_upper_bound_data4";
865 case AT_upper_bound_data8: return "AT_upper_bound_data8";
866 case AT_virtual: return "AT_virtual";
867
868 /* GNU extensions */
869
870 case AT_sf_names: return "AT_sf_names";
871 case AT_src_info: return "AT_src_info";
872 case AT_mac_info: return "AT_mac_info";
873 case AT_src_coords: return "AT_src_coords";
874
875 default: return "<unknown attribute>";
340ccaab
TW
876 }
877}
878
879static char *
9a631e8e 880dwarf_stack_op_name (op)
340ccaab
TW
881 register unsigned op;
882{
883 switch (op)
884 {
885 case OP_REG: return "OP_REG";
886 case OP_BASEREG: return "OP_BASEREG";
887 case OP_ADDR: return "OP_ADDR";
888 case OP_CONST: return "OP_CONST";
889 case OP_DEREF2: return "OP_DEREF2";
890 case OP_DEREF4: return "OP_DEREF4";
891 case OP_ADD: return "OP_ADD";
892 default: return "<unknown stack operator>";
893 }
894}
895
896static char *
9a631e8e 897dwarf_typemod_name (mod)
340ccaab
TW
898 register unsigned mod;
899{
900 switch (mod)
901 {
902 case MOD_pointer_to: return "MOD_pointer_to";
903 case MOD_reference_to: return "MOD_reference_to";
904 case MOD_const: return "MOD_const";
905 case MOD_volatile: return "MOD_volatile";
906 default: return "<unknown modifier>";
907 }
908}
909
910static char *
9a631e8e 911dwarf_fmt_byte_name (fmt)
340ccaab
TW
912 register unsigned fmt;
913{
914 switch (fmt)
915 {
916 case FMT_FT_C_C: return "FMT_FT_C_C";
917 case FMT_FT_C_X: return "FMT_FT_C_X";
918 case FMT_FT_X_C: return "FMT_FT_X_C";
919 case FMT_FT_X_X: return "FMT_FT_X_X";
920 case FMT_UT_C_C: return "FMT_UT_C_C";
921 case FMT_UT_C_X: return "FMT_UT_C_X";
922 case FMT_UT_X_C: return "FMT_UT_X_C";
923 case FMT_UT_X_X: return "FMT_UT_X_X";
924 case FMT_ET: return "FMT_ET";
925 default: return "<unknown array bound format byte>";
926 }
927}
928static char *
9a631e8e 929dwarf_fund_type_name (ft)
340ccaab
TW
930 register unsigned ft;
931{
932 switch (ft)
933 {
934 case FT_char: return "FT_char";
935 case FT_signed_char: return "FT_signed_char";
936 case FT_unsigned_char: return "FT_unsigned_char";
937 case FT_short: return "FT_short";
938 case FT_signed_short: return "FT_signed_short";
939 case FT_unsigned_short: return "FT_unsigned_short";
940 case FT_integer: return "FT_integer";
941 case FT_signed_integer: return "FT_signed_integer";
942 case FT_unsigned_integer: return "FT_unsigned_integer";
943 case FT_long: return "FT_long";
944 case FT_signed_long: return "FT_signed_long";
945 case FT_unsigned_long: return "FT_unsigned_long";
946 case FT_pointer: return "FT_pointer";
947 case FT_float: return "FT_float";
948 case FT_dbl_prec_float: return "FT_dbl_prec_float";
949 case FT_ext_prec_float: return "FT_ext_prec_float";
950 case FT_complex: return "FT_complex";
951 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
952 case FT_void: return "FT_void";
953 case FT_boolean: return "FT_boolean";
9a631e8e
RS
954 case FT_ext_prec_complex: return "FT_ext_prec_complex";
955 case FT_label: return "FT_label";
956
957 /* GNU extensions. */
958
340ccaab
TW
959 case FT_long_long: return "FT_long_long";
960 case FT_signed_long_long: return "FT_signed_long_long";
961 case FT_unsigned_long_long: return "FT_unsigned_long_long";
9a631e8e
RS
962
963 case FT_int8: return "FT_int8";
964 case FT_signed_int8: return "FT_signed_int8";
965 case FT_unsigned_int8: return "FT_unsigned_int8";
966 case FT_int16: return "FT_int16";
967 case FT_signed_int16: return "FT_signed_int16";
968 case FT_unsigned_int16: return "FT_unsigned_int16";
969 case FT_int32: return "FT_int32";
970 case FT_signed_int32: return "FT_signed_int32";
971 case FT_unsigned_int32: return "FT_unsigned_int32";
972 case FT_int64: return "FT_int64";
973 case FT_signed_int64: return "FT_signed_int64";
974 case FT_unsigned_int64: return "FT_signed_int64";
975
976 case FT_real32: return "FT_real32";
977 case FT_real64: return "FT_real64";
978 case FT_real96: return "FT_real96";
979 case FT_real128: return "FT_real128";
980
340ccaab
TW
981 default: return "<unknown fundamental type>";
982 }
983}
984\f
985/**************** utility functions for attribute functions ******************/
986
987/* Given a pointer to a tree node for some type, return a Dwarf fundamental
988 type code for the given type.
989
990 This routine must only be called for GCC type nodes that correspond to
991 Dwarf fundamental types.
992
993 The current Dwarf draft specification calls for Dwarf fundamental types
994 to accurately reflect the fact that a given type was either a "plain"
995 integral type or an explicitly "signed" integral type. Unfortuantely,
996 we can't always do this, because GCC may already have thrown away the
997 information about the precise way in which the type was originally
998 specified, as in:
999
1000 typedef signed int field_type;
1001
1002 struct s { field_type f; };
1003
1004 Since we may be stuck here without enought information to do exactly
1005 what is called for in the Dwarf draft specification, we do the best
1006 that we can under the circumstances and always use the "plain" integral
1007 fundamental type codes for int, short, and long types. That's probably
1008 good enough. The additional accuracy called for in the current DWARF
1009 draft specification is probably never even useful in practice. */
1010
1011static int
1012fundamental_type_code (type)
1013 register tree type;
1014{
1015 if (TREE_CODE (type) == ERROR_MARK)
1016 return 0;
1017
1018 switch (TREE_CODE (type))
1019 {
1020 case ERROR_MARK:
1021 return FT_void;
1022
1023 case VOID_TYPE:
1024 return FT_void;
1025
1026 case INTEGER_TYPE:
1027 /* Carefully distinguish all the standard types of C,
1028 without messing up if the language is not C.
1029 Note that we check only for the names that contain spaces;
1030 other names might occur by coincidence in other languages. */
1031 if (TYPE_NAME (type) != 0
1032 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1033 && DECL_NAME (TYPE_NAME (type)) != 0
1034 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1035 {
1036 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1037
1038 if (!strcmp (name, "unsigned char"))
1039 return FT_unsigned_char;
1040 if (!strcmp (name, "signed char"))
1041 return FT_signed_char;
1042 if (!strcmp (name, "unsigned int"))
1043 return FT_unsigned_integer;
1044 if (!strcmp (name, "short int"))
1045 return FT_short;
1046 if (!strcmp (name, "short unsigned int"))
1047 return FT_unsigned_short;
1048 if (!strcmp (name, "long int"))
1049 return FT_long;
1050 if (!strcmp (name, "long unsigned int"))
1051 return FT_unsigned_long;
1052 if (!strcmp (name, "long long int"))
1053 return FT_long_long; /* Not grok'ed by svr4 SDB */
1054 if (!strcmp (name, "long long unsigned int"))
1055 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1056 }
1057
1058 /* Most integer types will be sorted out above, however, for the
1059 sake of special `array index' integer types, the following code
1060 is also provided. */
1061
1062 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1063 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1064
1065 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1066 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1067
1068 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1069 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1070
1071 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1072 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1073
1074 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1075 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1076
1077 abort ();
1078
1079 case REAL_TYPE:
1080 /* Carefully distinguish all the standard types of C,
1081 without messing up if the language is not C. */
1082 if (TYPE_NAME (type) != 0
1083 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1084 && DECL_NAME (TYPE_NAME (type)) != 0
1085 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1086 {
1087 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1088
1089 /* Note that here we can run afowl of a serious bug in "classic"
1090 svr4 SDB debuggers. They don't seem to understand the
1091 FT_ext_prec_float type (even though they should). */
1092
1093 if (!strcmp (name, "long double"))
1094 return FT_ext_prec_float;
1095 }
1096
1097 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1098 return FT_dbl_prec_float;
1099 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1100 return FT_float;
1101
1102 /* Note that here we can run afowl of a serious bug in "classic"
1103 svr4 SDB debuggers. They don't seem to understand the
1104 FT_ext_prec_float type (even though they should). */
1105
1106 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1107 return FT_ext_prec_float;
1108 abort ();
1109
1110 case COMPLEX_TYPE:
1111 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1112
1113 case CHAR_TYPE:
1114 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1115
1116 case BOOLEAN_TYPE:
1117 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1118
1119 default:
1120 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1121 }
1122 return 0;
1123}
1124\f
1125/* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1126 the Dwarf "root" type for the given input type. The Dwarf "root" type
1127 of a given type is generally the same as the given type, except that if
1128 the given type is a pointer or reference type, then the root type of
1129 the given type is the root type of the "basis" type for the pointer or
1130 reference type. (This definition of the "root" type is recursive.)
1131 Also, the root type of a `const' qualified type or a `volatile'
1132 qualified type is the root type of the given type without the
1133 qualifiers. */
1134
1135static tree
1136root_type (type)
1137 register tree type;
1138{
1139 if (TREE_CODE (type) == ERROR_MARK)
1140 return error_mark_node;
1141
1142 switch (TREE_CODE (type))
1143 {
1144 case ERROR_MARK:
1145 return error_mark_node;
1146
1147 case POINTER_TYPE:
1148 case REFERENCE_TYPE:
1149 return TYPE_MAIN_VARIANT (root_type (TREE_TYPE (type)));
1150
1151 default:
1152 return TYPE_MAIN_VARIANT (type);
1153 }
1154}
1155
1156/* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1157 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1158
1159static void
1160write_modifier_bytes (type, decl_const, decl_volatile)
1161 register tree type;
1162 register int decl_const;
1163 register int decl_volatile;
1164{
1165 if (TREE_CODE (type) == ERROR_MARK)
1166 return;
1167
1168 if (TYPE_READONLY (type) || decl_const)
1169 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1170 if (TYPE_VOLATILE (type) || decl_volatile)
1171 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1172 switch (TREE_CODE (type))
1173 {
1174 case POINTER_TYPE:
1175 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1176 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1177 return;
1178
1179 case REFERENCE_TYPE:
1180 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1181 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1182 return;
1183
1184 case ERROR_MARK:
1185 default:
1186 return;
1187 }
1188}
1189\f
1190/* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1191 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1192
1193inline int
1194type_is_fundamental (type)
1195 register tree type;
1196{
1197 switch (TREE_CODE (type))
1198 {
1199 case ERROR_MARK:
1200 case VOID_TYPE:
1201 case INTEGER_TYPE:
1202 case REAL_TYPE:
1203 case COMPLEX_TYPE:
1204 case BOOLEAN_TYPE:
1205 case CHAR_TYPE:
1206 return 1;
1207
1208 case SET_TYPE:
1209 case ARRAY_TYPE:
1210 case RECORD_TYPE:
1211 case UNION_TYPE:
1212 case ENUMERAL_TYPE:
1213 case FUNCTION_TYPE:
1214 case METHOD_TYPE:
1215 case POINTER_TYPE:
1216 case REFERENCE_TYPE:
1217 case STRING_TYPE:
1218 case FILE_TYPE:
1219 case OFFSET_TYPE:
1220 case LANG_TYPE:
1221 return 0;
1222
1223 default:
1224 abort ();
1225 }
1226 return 0;
1227}
1228
1229/* Given a pointer to some ..._TYPE tree node, generate an assembly language
1230 equate directive which will associate an easily remembered symbolic name
1231 with the current DIE.
1232
1233 The name used is an artificial label generated from the TYPE_UID number
1234 associated with the given type node. The name it gets equated to is the
1235 symbolic label that we (previously) output at the start of the DIE that
1236 we are currently generating.
1237
1238 Calling this function while generating some "type related" form of DIE
1239 makes it easy to later refer to the DIE which represents the given type
1240 simply by re-generating the alternative name from the ..._TYPE node's
1241 UID number. */
1242
1243inline void
1244equate_type_number_to_die_number (type)
1245 register tree type;
1246{
1247 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1248 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1249
1250 /* We are generating a DIE to represent the main variant of this type
1251 (i.e the type without any const or volatile qualifiers) so in order
1252 to get the equate to come out right, we need to get the main variant
1253 itself here. */
1254
1255 type = TYPE_MAIN_VARIANT (type);
1256
1257 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1258 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1259 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1260}
1261
1262/* The following routine is a nice and simple transducer. It converts the
1263 RTL for a variable or parameter (resident in memory) into an equivalent
1264 Dwarf representation of a mechanism for getting the address of that same
1265 variable onto the top of a hypothetical "address evaluation" stack.
1266
1267 When creating memory location descriptors, we are effectively trans-
1268 forming the RTL for a memory-resident object into its Dwarf postfix
1269 expression equivalent. This routine just recursively descends an
1270 RTL tree, turning it into Dwarf postfix code as it goes. */
1271
1272static void
1273output_mem_loc_descriptor (rtl)
1274 register rtx rtl;
1275{
1276 /* Note that for a dynamically sized array, the location we will
1277 generate a description of here will be the lowest numbered location
1278 which is actually within the array. That's *not* necessarily the
1279 same as the zeroth element of the array. */
1280
1281 switch (GET_CODE (rtl))
1282 {
1283 case SUBREG:
1284
1285 /* The case of a subreg may arise when we have a local (register)
1286 variable or a formal (register) parameter which doesn't quite
1287 fill up an entire register. For now, just assume that it is
1288 legitimate to make the Dwarf info refer to the whole register
1289 which contains the given subreg. */
1290
1291 rtl = XEXP (rtl, 0);
1292 /* Drop thru. */
1293
1294 case REG:
1295
1296 /* Whenever a register number forms a part of the description of
1297 the method for calculating the (dynamic) address of a memory
1298 resident object, Dwarf rules require the register number to
1299 be referred to as a "base register". This distinction is not
1300 based in any way upon what category of register the hardware
1301 believes the given register belongs to. This is strictly
1302 Dwarf terminology we're dealing with here. */
1303
1304 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1305 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1306 DBX_REGISTER_NUMBER (REGNO (rtl)));
1307 break;
1308
1309 case MEM:
1310 output_mem_loc_descriptor (XEXP (rtl, 0));
1311 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1312 break;
1313
1314 case CONST:
1315 case SYMBOL_REF:
1316 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1317 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1318 break;
1319
1320 case PLUS:
1321 output_mem_loc_descriptor (XEXP (rtl, 0));
1322 output_mem_loc_descriptor (XEXP (rtl, 1));
1323 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1324 break;
1325
1326 case CONST_INT:
1327 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1328 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1329 break;
1330
1331 default:
1332 abort ();
1333 }
1334}
1335
1336/* Output a proper Dwarf location descriptor for a variable or parameter
1337 which is either allocated in a register or in a memory location. For
1338 a register, we just generate an OP_REG and the register number. For a
1339 memory location we provide a Dwarf postfix expression describing how to
1340 generate the (dynamic) address of the object onto the address stack. */
1341
1342static void
1343output_loc_descriptor (rtl)
1344 register rtx rtl;
1345{
1346 switch (GET_CODE (rtl))
1347 {
1348 case SUBREG:
1349
1350 /* The case of a subreg may arise when we have a local (register)
1351 variable or a formal (register) parameter which doesn't quite
1352 fill up an entire register. For now, just assume that it is
1353 legitimate to make the Dwarf info refer to the whole register
1354 which contains the given subreg. */
1355
1356 rtl = XEXP (rtl, 0);
1357 /* Drop thru. */
1358
1359 case REG:
1360 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1361 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1362 DBX_REGISTER_NUMBER (REGNO (rtl)));
1363 break;
1364
1365 case MEM:
1366 output_mem_loc_descriptor (XEXP (rtl, 0));
1367 break;
1368
1369 default:
1370 abort (); /* Should never happen */
1371 }
1372}
1373
1374/* Given a tree node describing an array bound (either lower or upper)
1375 output a representation for that bound. */
1376
1377static void
1378output_bound_representation (bound, dim_num, u_or_l)
1379 register tree bound;
1380 register unsigned dim_num; /* For multi-dimensional arrays. */
1381 register char u_or_l; /* Designates upper or lower bound. */
1382{
1383 switch (TREE_CODE (bound))
1384 {
1385
1386 case ERROR_MARK:
1387 return;
1388
1389 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1390
1391 case INTEGER_CST:
1392 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1393 (unsigned) TREE_INT_CST_LOW (bound));
1394 break;
1395
1396 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1397 SAVE_EXPR nodes. */
1398
1399 case NOP_EXPR:
1400 bound = TREE_OPERAND (bound, 0);
1401 /* ... fall thru... */
1402
1403 case SAVE_EXPR:
1404 {
1405 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1406 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1407
1408 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1409 current_dienum, dim_num, u_or_l);
1410
1411 sprintf (end_label, BOUND_END_LABEL_FMT,
1412 current_dienum, dim_num, u_or_l);
1413
1414 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1415 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1416
1417 /* If we are working on a bound for a dynamic dimension in C,
1418 the dynamic dimension in question had better have a static
1419 (zero) lower bound and a dynamic *upper* bound. */
1420
1421 if (u_or_l != 'u')
1422 abort ();
1423
1424 /* If optimization is turned on, the SAVE_EXPRs that describe
1425 how to access the upper bound values are essentially bogus.
1426 They only describe (at best) how to get at these values at
1427 the points in the generated code right after they have just
1428 been computed. Worse yet, in the typical case, the upper
1429 bound values will not even *be* computed in the optimized
1430 code, so these SAVE_EXPRs are entirely bogus.
1431
1432 In order to compensate for this fact, we check here to see
1433 if optimization is enabled, and if so, we effectively create
1434 an empty location description for the (unknown and unknowable)
1435 upper bound.
1436
1437 This should not cause too much trouble for existing (stupid?)
1438 debuggers because they have to deal with empty upper bounds
1439 location descriptions anyway in order to be able to deal with
1440 incomplete array types.
1441
1442 Of course an intelligent debugger (GDB?) should be able to
1443 comprehend that a missing upper bound specification in a
1444 array type used for a storage class `auto' local array variable
1445 indicates that the upper bound is both unknown (at compile-
1446 time) and unknowable (at run-time) due to optimization.
1447 */
1448
1449 if (! optimize)
1450 output_loc_descriptor
1451 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, 0));
1452
1453 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1454 }
1455 break;
1456
1457 default:
1458 abort ();
1459 }
1460}
1461
1462/* Recursive function to output a sequence of value/name pairs for
1463 enumeration constants in reversed order. This is called from
1464 enumeration_type_die. */
1465
1466static void
1467output_enumeral_list (link)
1468 register tree link;
1469{
1470 if (link)
1471 {
1472 output_enumeral_list (TREE_CHAIN (link));
1473 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1474 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1475 ASM_OUTPUT_DWARF_STRING (asm_out_file,
1476 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1477 }
1478}
1479
1480/****************************** attributes *********************************/
1481
1482/* The following routines are responsible for writing out the various types
1483 of Dwarf attributes (and any following data bytes associated with them).
1484 These routines are listed in order based on the numerical codes of their
1485 associated attributes. */
1486
1487/* Generate an AT_sibling attribute. */
1488
1489inline void
1490sibling_attribute ()
1491{
1492 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1493
1494 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
1495 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
1496 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
1497}
1498
1499/* Output the form of location attributes suitable for whole variables and
1500 whole parameters. Note that the location attributes for struct fields
1501 are generated by the routine `data_member_location_attribute' below. */
1502
1503static void
1504location_attribute (rtl)
1505 register rtx rtl;
1506{
1507 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1508 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1509
1510 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1511 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1512 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1513 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1514 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1515
1516 /* Handle a special case. If we are about to output a location descriptor
2e494f70 1517 for a variable or parameter which has been optimized out of existence,
340ccaab
TW
1518 don't do that. Instead we output a zero-length location descriptor
1519 value as part of the location attribute. Note that we cannot simply
1520 suppress the entire location attribute, because the absence of a
1521 location attribute in certain kinds of DIEs is used to indicate some-
1522 thing entirely different... i.e. that the DIE represents an object
1523 declaration, but not a definition. So sayeth the PLSIG. */
1524
648ebe7b 1525 if (! is_pseudo_reg (rtl))
340ccaab
TW
1526 output_loc_descriptor (eliminate_regs (rtl, 0, 0));
1527
1528 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1529}
1530
1531/* Output the specialized form of location attribute used for data members
9a631e8e
RS
1532 of struct types.
1533
1534 In the special case of a FIELD_DECL node which represents a bit-field,
1535 the "offset" part of this special location descriptor must indicate the
1536 distance in bytes from the lowest-addressed byte of the containing
1537 struct or union type to the lowest-addressed byte of the "containing
1538 object" for the bit-field.
1539
1540 For any given bit-field, the "containing object" is a hypothetical
1541 object (of some integral or enum type) within which the given bit-field
1542 lives. The type of this hypothetical "containing object" is always the
1543 same as the declared type of the individual bit-field itself.
1544
1545 Note that it is the size (in bytes) of the hypothetical "containing
1546 object" which will be given in the AT_byte_size attribute for this
1547 bit-field. (See the `byte_size_attribute' function below.)
1548*/
1549
340ccaab
TW
1550
1551static void
1552data_member_location_attribute (decl)
1553 register tree decl;
1554{
1555 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1556 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
648ebe7b
RS
1557 register unsigned type_align_in_bytes;
1558 register unsigned type_align_in_bits;
1559 register unsigned offset_in_align_units;
1560 register unsigned offset_in_bytes;
9a631e8e 1561 register tree type;
648ebe7b
RS
1562 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
1563 register unsigned bitpos_int;
340ccaab
TW
1564
1565 if (TREE_CODE (decl) == ERROR_MARK)
1566 return;
1567
1568 if (TREE_CODE (decl) != FIELD_DECL)
1569 abort ();
1570
9a631e8e
RS
1571 /* The bit position given by DECL_FIELD_BITPOS could be non-constant
1572 in the case where one or more variable sized members preceeded this
1573 member in the containing struct type. We could probably correctly
1574 handle this case someday, by it's too complicated to deal with at
1575 the moment (and probably too rare to worry about), so just punt on
1576 the whole AT_location attribute for now. Eventually, we'll have
1577 to analyze the expression given as the DECL_FIELD_BITPOS and turn
1578 it into a member-style AT_location descriptor, but that'll be
1579 tough to do. -- rfg */
1580
648ebe7b 1581 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
9a631e8e 1582 return;
648ebe7b 1583 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
9a631e8e 1584
340ccaab
TW
1585 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1586 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1587 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1588 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1589 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1590 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1591
9a631e8e
RS
1592 type = DECL_BIT_FIELD_TYPE (decl);
1593 if (type == NULL)
1594 type = TREE_TYPE (decl);
340ccaab 1595
648ebe7b
RS
1596 type_align_in_bits = TYPE_ALIGN (type);
1597 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
9a631e8e
RS
1598
1599 /* WARNING! Note that the GCC front-end doesn't make any attempt to
1600 keep track of the starting bit offset (relative to the start of
1601 the containing structure type) of the hypothetical "containing
1602 object" for a bit-field. (See the comments at the start of this
648ebe7b 1603 function.) Thus, when computing the byte offset value for a
9a631e8e 1604 bit-field, all we can do is to divide the starting bit offset of
648ebe7b
RS
1605 the bit-field by the alignment of the hypothetical "containing
1606 object" (which we can easily find) and then multiply by the number
1607 of bytes of that alignment.
1608
1609 This solution only yields an unambiguously correct result when
1610 the size of the bit-field is strictly larger than the size of the
1611 declared type minus the alignment of the declared type. When this
1612 condition is not satisfied, it means that there is at least an
1613 "alignment unit's" worth of other slop which co-resides within the
1614 hypothetical "containing object" with the bit field, and this other
1615 slop could be either to the left of the bit-field or to the right
1616 of the bit-field. (We have no way of knowing which.)
1617
1618 It also means that we cannot unambiguously tell exactly where the
1619 hypothetical "containing object" begins within the containing struct
1620 type. We only know the precise position of the bit-field which is
1621 contained therein, and that the hypothetical containing object must
1622 be aligned as required for its type. But when there is at least an
1623 alignment unit's worth of slop co-resident in the containing object
1624 with the actual bit-field, the actual start of the containing object
1625 is ambiguous and thus, we cannot unambiguously determine the "correct"
1626 byte offset to put into the AT_location attribute for the bit-field
1627 itself.
1628
1629 This whole thing is a non-issue for the majority of targets, because
1630 (for most GCC targets) the alignment of each supported integral type
1631 is the same as the size of that type, and thus (size - alignment) for
1632 the declared type of any bit-field yields zero, and the size (in bits)
1633 of any bit-field must be bigger than zero, so there is never any
1634 ambiguity about the starting positions of the containing objects of
1635 bit-fields for most GCC targets.
1636
1637 An exception arises however for some machines (e.g. i386) which have
1638 BIGGEST_ALIGNMENT set to something less than the size of type `long
1639 long' (i.e. 64) and when we are confronted with something like:
1640
1641 struct S {
1642 int field1;
1643 long long field2:31;
1644 };
1645
1646 Here it is ambiguous (going by DWARF rules anyway) whether the con-
1647 taining `long long' object for `field2' should be said to occupy the
1648 first and second (32-bit) words of the containing struct type, or
1649 whether it should be said to occupy the second and third words of
1650 the struct type.
1651
1652 Currently, GCC allocates 8 bytes (for an i386 target) for each object
1653 of the above type. This is probably a bug however, and GCC should
1654 probably be allocating 12 bytes for each such structure (for the i386
1655 target).
1656
1657 Assuming this bug gets fixed, one would have a strong case for saying
1658 that the containing `long long' object for `field2' occupies the second
1659 and third words of the above structure type, and that `field2' itself
1660 occupies the first 31 bits of that containing object. However consider:
1661
1662 struct S {
1663 int field1;
1664 long long field2:31;
1665 long long field3:2;
1666 long long field4:31;
1667 };
1668
1669 Even if the current "member allocation" bug in GCC is fixed, this ex-
1670 ample would still illustrate a case in which the starting point of the
1671 containing `long long' object for `field4' would be ambiguous, even
1672 though we know the exact starting bit offset (within the structure) of
1673 the `field4' bit-field itself.
1674
1675 We essentially just ignore this whole issue here and always act as if
1676 most of the slop which co-resides in a containing object along with a
1677 bit-field appears in that containing object *AFTER* the bit field.
1678 Thus, for the above example, we say that the containing object for
1679 `field4' occupies the third and fourth words of the structure type,
1680 even though objects of the type only occupy three words. As long
1681 as the debugger understands that the compiler uses this disambiguation
1682 rule, the debugger should easily be able to do the Right Thing in all
1683 cases.
9a631e8e
RS
1684 */
1685
648ebe7b
RS
1686 offset_in_align_units = bitpos_int / type_align_in_bits;
1687 offset_in_bytes = offset_in_align_units * type_align_in_bytes;
9a631e8e 1688
648ebe7b 1689 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, offset_in_bytes);
340ccaab
TW
1690 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1691 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1692}
1693
1694/* Output an AT_const_value attribute for a variable or a parameter which
1695 does not have a "location" either in memory or in a register. These
1696 things can arise in GNU C when a constant is passed as an actual
1697 parameter to an inlined function. They can also arise in C++ where
1698 declared constants do not necessarily get memory "homes". */
1699
1700static void
1701const_value_attribute (rtl)
1702 register rtx rtl;
1703{
1704 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1705 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1706
1707 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
1708 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1709 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1710 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
1711 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1712
1713 switch (GET_CODE (rtl))
1714 {
1715 case CONST_INT:
1716 /* Note that a CONST_INT rtx could represent either an integer or
1717 a floating-point constant. A CONST_INT is used whenever the
1718 constant will fit into a single word. In all such cases, the
1719 original mode of the constant value is wiped out, and the
1720 CONST_INT rtx is assigned VOIDmode. Since we no longer have
1721 precise mode information for these constants, we always just
1722 output them using 4 bytes. */
1723
1724 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
1725 break;
1726
1727 case CONST_DOUBLE:
1728 /* Note that a CONST_DOUBLE rtx could represent either an integer
1729 or a floating-point constant. A CONST_DOUBLE is used whenever
1730 the constant requires more than one word in order to be adequately
1731 represented. In all such cases, the original mode of the constant
1732 value is preserved as the mode of the CONST_DOUBLE rtx, but for
1733 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
1734
1735 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
1736 (unsigned) CONST_DOUBLE_HIGH (rtl),
1737 (unsigned) CONST_DOUBLE_LOW (rtl));
1738 break;
1739
1740 case CONST_STRING:
1741 ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
1742 break;
1743
1744 case SYMBOL_REF:
1745 case LABEL_REF:
1746 case CONST:
1747 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1748 break;
1749
1750 case PLUS:
1751 /* In cases where an inlined instance of an inline function is passed
1752 the address of an `auto' variable (which is local to the caller)
1753 we can get a situation where the DECL_RTL of the artificial
1754 local variable (for the inlining) which acts as a stand-in for
1755 the corresponding formal parameter (of the inline function)
1756 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
1757 This is not exactly a compile-time constant expression, but it
1758 isn't the address of the (artificial) local variable either.
1759 Rather, it represents the *value* which the artificial local
1760 variable always has during its lifetime. We currently have no
1761 way to represent such quasi-constant values in Dwarf, so for now
1762 we just punt and generate an AT_const_value attribute with form
1763 FORM_BLOCK4 and a length of zero. */
1764 break;
1765 }
1766
1767 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1768}
1769
1770/* Generate *either* an AT_location attribute or else an AT_const_value
1771 data attribute for a variable or a parameter. We generate the
1772 AT_const_value attribute only in those cases where the given
1773 variable or parameter does not have a true "location" either in
1774 memory or in a register. This can happen (for example) when a
1775 constant is passed as an actual argument in a call to an inline
1776 function. (It's possible that these things can crop up in other
1777 ways also.) Note that one type of constant value which can be
1778 passed into an inlined function is a constant pointer. This can
1779 happen for example if an actual argument in an inlined function
1780 call evaluates to a compile-time constant address. */
1781
1782static void
1783location_or_const_value_attribute (decl)
1784 register tree decl;
1785{
1786 register rtx rtl;
1787
1788 if (TREE_CODE (decl) == ERROR_MARK)
1789 return;
1790
1791 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
1792 abort ();
1793
9a631e8e 1794 /* Existing Dwarf debuggers need and expect the location descriptors for
648ebe7b
RS
1795 formal parameters to reflect either the place where the parameters get
1796 passed (if they are passed on the stack and in memory) or else the
1797 (preserved) registers which the paramaters get copied to during the
1798 function prologue.
1799
1800 At least this is the way things are for most common CISC machines
1801 (e.g. x86 and m68k) where parameters are passed in the stack, and for
1802 most common RISC machines (e.g. i860 and m88k) where parameters are
1803 passed in registers.
1804
1805 The rules for Sparc are a little weird for some reason. The DWARF
1806 generated by the USL C compiler for the Sparc/svr4 reference port says
1807 that the parameters are passed in the stack. I haven't figured out
1808 how to duplicate that behavior here (for the Sparc) yet, or even if
1809 I really need to.
1810
1811 Note that none of this is clearly spelled out in the current Dwarf
9a631e8e
RS
1812 version 1 specification, but it's obvious if you look at the output of
1813 the CI5 compiler, or if you try to use the svr4 SDB debugger. Hopefully,
1814 a later version of the Dwarf specification will clarify this. For now,
1815 we just need to generate the right thing. Note that Dwarf version 2
1816 will provide us with a means to describe *all* of the locations in which
1817 a given variable or parameter resides (and the PC ranges over which it
648ebe7b
RS
1818 occupies each one), but for now we can only describe one "location"
1819 for each formal parameter passed, and so we just try to mimic existing
1820 practice as much as possible.
1821 */
9a631e8e 1822
648ebe7b
RS
1823 if (TREE_CODE (decl) != PARM_DECL)
1824 /* If this decl is not a formal parameter, just use DECL_RTL. */
1825 rtl = DECL_RTL (decl);
1826 else
1827 {
1828 if (GET_CODE (DECL_INCOMING_RTL (decl)) == MEM)
1829 /* Parameter was passed in memory, so say that's where it lives. */
1830 rtl = DECL_INCOMING_RTL (decl);
1831 else
1832 {
1833 /* Parameter was passed in a register, so say it lives in the
1834 register it will be copied to during the prologue. */
1835 rtl = DECL_RTL (decl);
1836
1837 /* Note that in cases where the formal parameter is never used
1838 and where this compilation is done with -O, the copying of
1839 of an incoming register parameter to another register (in
1840 the prologue) can be totally optimized away. (In such cases
1841 the DECL_RTL will indicate a pseudo-register.) We could just
1842 use the DECL_RTL (as we normally do for register parameters)
1843 in these cases, but if we did that, we would end up generating
1844 a null location descriptor. (See `location_attribute' above.)
1845 That would be acceptable (according to the DWARF spec) but it
1846 is probably more useful to say that the formal resides where
1847 it was passed instead of saying that it resides nowhere. */
1848 if (is_pseudo_reg (rtl))
1849 rtl = DECL_INCOMING_RTL (decl);
1850 }
1851 }
340ccaab
TW
1852
1853 if (rtl == NULL)
1854 return;
1855
1856 switch (GET_CODE (rtl))
1857 {
1858 case CONST_INT:
1859 case CONST_DOUBLE:
1860 case CONST_STRING:
1861 case SYMBOL_REF:
1862 case LABEL_REF:
1863 case CONST:
1864 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
1865 const_value_attribute (rtl);
1866 break;
1867
1868 case MEM:
1869 case REG:
1870 case SUBREG:
1871 location_attribute (rtl);
1872 break;
1873
1874 default:
1875 abort (); /* Should never happen. */
1876 }
1877}
1878
1879/* Generate an AT_name attribute given some string value to be included as
9a631e8e 1880 the value of the attribute. */
340ccaab
TW
1881
1882inline void
1883name_attribute (name_string)
1884 register char *name_string;
1885{
75791cee
TW
1886 if (name_string && *name_string)
1887 {
1888 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
1889 ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
1890 }
340ccaab
TW
1891}
1892
1893inline void
1894fund_type_attribute (ft_code)
1895 register unsigned ft_code;
1896{
1897 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
1898 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
1899}
1900
1901static void
1902mod_fund_type_attribute (type, decl_const, decl_volatile)
1903 register tree type;
1904 register int decl_const;
1905 register int decl_volatile;
1906{
1907 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1908 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1909
1910 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
1911 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
1912 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
1913 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1914 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1915 write_modifier_bytes (type, decl_const, decl_volatile);
1916 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
1917 fundamental_type_code (root_type (type)));
1918 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1919}
1920
1921inline void
1922user_def_type_attribute (type)
1923 register tree type;
1924{
1925 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
1926
1927 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
1928 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
1929 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
1930}
1931
1932static void
1933mod_u_d_type_attribute (type, decl_const, decl_volatile)
1934 register tree type;
1935 register int decl_const;
1936 register int decl_volatile;
1937{
1938 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1939 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1940 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
1941
1942 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
1943 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
1944 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
1945 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1946 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1947 write_modifier_bytes (type, decl_const, decl_volatile);
1948 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
1949 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
1950 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1951}
1952
1953inline void
1954ordering_attribute (ordering)
1955 register unsigned ordering;
1956{
1957 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
1958 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
1959}
1960
1961/* Note that the block of subscript information for an array type also
1962 includes information about the element type of type given array type. */
1963
1964static void
1965subscript_data_attribute (type)
1966 register tree type;
1967{
1968 register unsigned dimension_number;
1969 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1970 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1971
1972 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
1973 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
1974 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
1975 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1976 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1977
1978 /* The GNU compilers represent multidimensional array types as sequences
1979 of one dimensional array types whose element types are themselves array
1980 types. Here we squish that down, so that each multidimensional array
1981 type gets only one array_type DIE in the Dwarf debugging info. The
1982 draft Dwarf specification say that we are allowed to do this kind
1983 of compression in C (because there is no difference between an
1984 array or arrays and a multidimensional array in C) but for other
1985 source languages (e.g. Ada) we probably shouldn't do this. */
1986
1987 for (dimension_number = 0;
1988 TREE_CODE (type) == ARRAY_TYPE;
1989 type = TREE_TYPE (type), dimension_number++)
1990 {
1991 register tree domain = TYPE_DOMAIN (type);
1992
1993 /* Arrays come in three flavors. Unspecified bounds, fixed
1994 bounds, and (in GNU C only) variable bounds. Handle all
1995 three forms here. */
1996
1997 if (domain)
1998 {
1999 /* We have an array type with specified bounds. */
2000
2001 register tree lower = TYPE_MIN_VALUE (domain);
2002 register tree upper = TYPE_MAX_VALUE (domain);
2003
2004 /* Handle only fundamental types as index types for now. */
2005
2006 if (! type_is_fundamental (domain))
2007 abort ();
2008
2009 /* Output the representation format byte for this dimension. */
2010
2011 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2012 FMT_CODE (1,
2013 TREE_CODE (lower) == INTEGER_CST,
2014 TREE_CODE (upper) == INTEGER_CST));
2015
2016 /* Output the index type for this dimension. */
2017
2018 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2019 fundamental_type_code (domain));
2020
2021 /* Output the representation for the lower bound. */
2022
2023 output_bound_representation (lower, dimension_number, 'l');
2024
2025 /* Output the representation for the upper bound. */
2026
2027 output_bound_representation (upper, dimension_number, 'u');
2028 }
2029 else
2030 {
2031 /* We have an array type with an unspecified length. For C and
2032 C++ we can assume that this really means that (a) the index
2033 type is an integral type, and (b) the lower bound is zero.
2034 Note that Dwarf defines the representation of an unspecified
2035 (upper) bound as being a zero-length location description. */
2036
2037 /* Output the array-bounds format byte. */
2038
2039 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2040
2041 /* Output the (assumed) index type. */
2042
2043 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2044
2045 /* Output the (assumed) lower bound (constant) value. */
2046
2047 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2048
2049 /* Output the (empty) location description for the upper bound. */
2050
2051 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2052 }
2053 }
2054
2055 /* Output the prefix byte that says that the element type is comming up. */
2056
2057 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2058
2059 /* Output a representation of the type of the elements of this array type. */
2060
2061 type_attribute (type, 0, 0);
2062
2063 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2064}
2065
2066static void
2067byte_size_attribute (tree_node)
2068 register tree tree_node;
2069{
2070 register unsigned size;
2071
2072 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2073 switch (TREE_CODE (tree_node))
2074 {
2075 case ERROR_MARK:
2076 size = 0;
2077 break;
2078
2079 case ENUMERAL_TYPE:
2080 case RECORD_TYPE:
2081 case UNION_TYPE:
2082 size = int_size_in_bytes (tree_node);
2083 break;
2084
2085 case FIELD_DECL:
9a631e8e
RS
2086 /* For a data member of a struct or union, the AT_byte_size is
2087 always given as the number of bytes normally allocated for
2088 an object of the *declared* type of the member itself. This
2089 is true even for bit-fields. */
2090 size = int_size_in_bytes (DECL_BIT_FIELD_TYPE (tree_node)
2091 ? DECL_BIT_FIELD_TYPE (tree_node)
2092 : TREE_TYPE (tree_node));
340ccaab
TW
2093 break;
2094
2095 default:
2096 abort ();
2097 }
9a631e8e
RS
2098
2099 /* Note that `size' might be -1 when we get to this point. If it
2100 is, that indicates that the byte size of the entity in question
2101 is variable. We have no good way of expressing this fact in Dwarf
2102 at the present time, so just let the -1 pass on through. */
2103
340ccaab
TW
2104 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2105}
2106
9a631e8e
RS
2107/* For a FIELD_DECL node which represents a bit-field, output an attribute
2108 which specifies the distance in bits from the highest order bit of the
2109 "containing object" for the bit-field to the highest order bit of the
2110 bit-field itself.
2111
2112 For any given bit-field, the "containing object" is a hypothetical
2113 object (of some integral or enum type) within which the given bit-field
2114 lives. The type of this hypothetical "containing object" is always the
2115 same as the declared type of the individual bit-field itself.
2116
2117 Note that it is the size (in bytes) of the hypothetical "containing
2118 object" which will be given in the AT_byte_size attribute for this
2119 bit-field. (See `byte_size_attribute' above.)
2120*/
340ccaab
TW
2121
2122inline void
2123bit_offset_attribute (decl)
2124 register tree decl;
2125{
9a631e8e 2126 register tree type = DECL_BIT_FIELD_TYPE (decl);
9a631e8e
RS
2127 register unsigned dwarf_bit_offset;
2128 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
648ebe7b 2129 register unsigned bitpos_int;
9a631e8e 2130
340ccaab 2131 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
9a631e8e
RS
2132 assert (type); /* Must be a bit field. */
2133
2134 /* The bit position given by DECL_FIELD_BITPOS could be non-constant
2135 in the case where one or more variable sized members preceeded this
2136 member in the containing struct type. We could probably correctly
2137 handle this case someday, by it's too complicated to deal with at
2138 the moment, so just punt on the whole AT_bit_offset attribute for
2139 now. Eventually, we'll have to analyze the (variable) expression
2140 given as the DECL_FIELD_BITPOS and see if we can factor out just
2141 the (constant) bit offset part of that expression. -- rfg */
2142
648ebe7b 2143 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
9a631e8e 2144 return;
648ebe7b 2145 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
9a631e8e 2146
648ebe7b
RS
2147 /* For a detailed description of how the AT_bit_offset attribute value
2148 is calculated, see the comments in `data_member_location_attribute'
2149 above. */
9a631e8e
RS
2150
2151#if (BYTES_BIG_ENDIAN == 1)
648ebe7b 2152 dwarf_bit_offset = bitpos_int % TYPE_ALIGN (type);
9a631e8e
RS
2153#else
2154 {
648ebe7b
RS
2155 register unsigned high_order_bitpos
2156 = bitpos_int + (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2157 register tree type_size_tree = TYPE_SIZE (type);
2158 register unsigned type_size_in_bits;
2159
2160 if (TREE_CODE (type_size_tree) != INTEGER_CST)
2161 abort ();
2162 type_size_in_bits = (unsigned) TREE_INT_CST_LOW (type_size_tree);
9a631e8e 2163
648ebe7b
RS
2164 dwarf_bit_offset = type_size_in_bits
2165 - (high_order_bitpos % TYPE_ALIGN (type));
9a631e8e
RS
2166 }
2167#endif
340ccaab
TW
2168
2169 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
9a631e8e 2170 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, dwarf_bit_offset);
340ccaab
TW
2171}
2172
2173/* For a FIELD_DECL node which represents a bit field, output an attribute
2174 which specifies the length in bits of the given field. */
2175
2176inline void
2177bit_size_attribute (decl)
2178 register tree decl;
2179{
2180 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2181 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
2182
2183 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2184 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2185 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2186}
2187
2188/* The following routine outputs the `element_list' attribute for enumeration
2189 type DIEs. The element_lits attribute includes the names and values of
2190 all of the enumeration constants associated with the given enumeration
2191 type. */
2192
2193inline void
2194element_list_attribute (element)
2195 register tree element;
2196{
2197 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2198 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2199
2200 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2201 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2202 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2203 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2204 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2205
2206 /* Here we output a list of value/name pairs for each enumeration constant
2207 defined for this enumeration type (as required), but we do it in REVERSE
2208 order. The order is the one required by the draft #5 Dwarf specification
2209 published by the UI/PLSIG. */
2210
2211 output_enumeral_list (element); /* Recursively output the whole list. */
2212
2213 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2214}
2215
2216/* Generate an AT_stmt_list attribute. These are normally present only in
2217 DIEs with a TAG_compile_unit tag. */
2218
2219inline void
2220stmt_list_attribute (label)
2221 register char *label;
2222{
2223 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2224 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2225 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2226}
2227
2228/* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2229 for a subroutine DIE. */
2230
2231inline void
2232low_pc_attribute (asm_low_label)
2233 register char *asm_low_label;
2234{
2235 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2236 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2237}
2238
2239/* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2240 subroutine DIE. */
2241
2242inline void
2243high_pc_attribute (asm_high_label)
2244 register char *asm_high_label;
2245{
2246 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2247 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2248}
2249
2250/* Generate an AT_language attribute given a LANG value. These attributes
2251 are used only within TAG_compile_unit DIEs. */
2252
2253inline void
2254language_attribute (language_code)
2255 register unsigned language_code;
2256{
2257 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2258 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2259}
2260
2261inline void
2262member_attribute (context)
2263 register tree context;
2264{
2265 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2266
2267 /* Generate this attribute only for members in C++. */
2268
2269 if (context != NULL
2270 && (TREE_CODE (context) == RECORD_TYPE
2271 || TREE_CODE (context) == UNION_TYPE))
2272 {
2273 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2274 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2275 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2276 }
2277}
2278
2279inline void
2280string_length_attribute (upper_bound)
2281 register tree upper_bound;
2282{
2283 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2284 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2285
2286 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2287 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2288 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2289 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2290 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2291 output_bound_representation (upper_bound, 0, 'u');
2292 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2293}
2294
2295inline void
2296comp_dir_attribute (dirname)
2297 register char *dirname;
2298{
2299 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2300 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2301}
2302
2303inline void
2304sf_names_attribute (sf_names_start_label)
2305 register char *sf_names_start_label;
2306{
2307 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2308 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2309 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2310}
2311
2312inline void
2313src_info_attribute (src_info_start_label)
2314 register char *src_info_start_label;
2315{
2316 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2317 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2318 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2319}
2320
2321inline void
2322mac_info_attribute (mac_info_start_label)
2323 register char *mac_info_start_label;
2324{
2325 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2326 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2327 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2328}
2329
2330inline void
2331prototyped_attribute (func_type)
2332 register tree func_type;
2333{
2334 if ((strcmp (language_string, "GNU C") == 0)
2335 && (TYPE_ARG_TYPES (func_type) != NULL))
2336 {
2337 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2338 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2339 }
2340}
2341
2342inline void
2343producer_attribute (producer)
2344 register char *producer;
2345{
2346 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2347 ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2348}
2349
2350inline void
2351inline_attribute (decl)
2352 register tree decl;
2353{
2354 if (TREE_INLINE (decl))
2355 {
2356 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2357 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2358 }
2359}
2360
2361inline void
2362containing_type_attribute (containing_type)
2363 register tree containing_type;
2364{
2365 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2366
2367 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2368 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2369 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2370}
2371
9a631e8e
RS
2372inline void
2373src_coords_attribute (src_fileno, src_lineno)
2374 register unsigned src_fileno;
2375 register unsigned src_lineno;
2376{
9a631e8e
RS
2377 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
2378 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
2379 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
9a631e8e
RS
2380}
2381
340ccaab
TW
2382/************************* end of attributes *****************************/
2383
2384/********************* utility routines for DIEs *************************/
2385
9a631e8e
RS
2386/* Output an AT_name attribute and an AT_src_coords attribute for the
2387 given decl, but only if it actually has a name. */
2388
2389inline void
2390name_and_src_coords_attributes (decl)
2391 register tree decl;
2392{
2393 register tree decl_name = DECL_NAME (decl);
2394
2395 if (decl_name && IDENTIFIER_POINTER (decl_name))
2396 {
2397 name_attribute (IDENTIFIER_POINTER (decl_name));
75791cee
TW
2398#ifdef DWARF_DECL_COORDINATES
2399 {
2400 register unsigned file_index;
2401
2402 /* This is annoying, but we have to pop out of the .debug section
2403 for a moment while we call `lookup_filename' because calling it
2404 may cause a temporary switch into the .debug_sfnames section and
2405 most svr4 assemblers are not smart enough be be able to nest
2406 section switches to any depth greater than one. Note that we
2407 also can't skirt this issue by delaying all output to the
2408 .debug_sfnames section unit the end of compilation because that
2409 would cause us to have inter-section forward references and
2410 Fred Fish sez that m68k/svr4 assemblers botch those. */
2411
2412 ASM_OUTPUT_POP_SECTION (asm_out_file);
2413 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
2414 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
2415
2416 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
2417 }
2418#endif
9a631e8e
RS
2419 }
2420}
2421
340ccaab
TW
2422/* Many forms of DIEs contain a "type description" part. The following
2423 routine writes out these "type descriptor" parts. */
2424
2425static void
2426type_attribute (type, decl_const, decl_volatile)
2427 register tree type;
2428 register int decl_const;
2429 register int decl_volatile;
2430{
2431 register enum tree_code code = TREE_CODE (type);
2432 register int root_type_modified;
2433
2434 if (TREE_CODE (type) == ERROR_MARK)
2435 return;
2436
2437 /* Handle a special case. For functions whose return type is void,
2438 we generate *no* type attribute. (Note that no object may have
2439 type `void', so this only applies to function return types. */
2440
2441 if (TREE_CODE (type) == VOID_TYPE)
2442 return;
2443
2444 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
2445 || decl_const || decl_volatile
2446 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
2447
2448 if (type_is_fundamental (root_type (type)))
2449 if (root_type_modified)
2450 mod_fund_type_attribute (type, decl_const, decl_volatile);
2451 else
2452 fund_type_attribute (fundamental_type_code (type));
2453 else
2454 if (root_type_modified)
2455 mod_u_d_type_attribute (type, decl_const, decl_volatile);
2456 else
2457 user_def_type_attribute (type);
2458}
2459
2460/* Given a tree pointer to a struct, class, union, or enum type node, return
2461 a pointer to the (string) tag name for the given type, or zero if the
2462 type was declared without a tag. */
2463
2464static char *
2465type_tag (type)
2466 register tree type;
2467{
2468 register char *name = 0;
2469
2470 if (TYPE_NAME (type) != 0)
2471 {
2472 register tree t = 0;
2473
2474 /* Find the IDENTIFIER_NODE for the type name. */
2475 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2476 t = TYPE_NAME (type);
2477#if 0
2478 /* The g++ front end makes the TYPE_NAME of *each* tagged type point
2479 to a TYPE_DECL node, regardless of whether or not a `typedef' was
2480 involved. This is distinctly different from what the gcc front-end
2481 does. It always makes the TYPE_NAME for each tagged type be either
2482 NULL (signifying an anonymous tagged type) or else a pointer to an
2483 IDENTIFIER_NODE. Obviously, we would like to generate correct Dwarf
6dc42e49 2484 for both C and C++, but given this inconsistency in the TREE
340ccaab
TW
2485 representation of tagged types for C and C++ in the GNU front-ends,
2486 we cannot support both languages correctly unless we introduce some
2487 front-end specific code here, and rms objects to that, so we can
2488 only generate correct Dwarf for one of these two languages. C is
2489 more important, so for now we'll do the right thing for C and let
2490 g++ go fish. */
2491
2492 else
2493 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2494 t = DECL_NAME (TYPE_NAME (type));
2495#endif
2496 /* Now get the name as a string, or invent one. */
2497 if (t != 0)
2498 name = IDENTIFIER_POINTER (t);
2499 }
2500
2501 return (name == 0 || *name == '\0') ? 0 : name;
2502}
2503
2504inline void
2505dienum_push ()
2506{
2507 /* Start by checking if the pending_sibling_stack needs to be expanded.
2508 If necessary, expand it. */
2509
2510 if (pending_siblings == pending_siblings_allocated)
2511 {
2512 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
2513 pending_sibling_stack
2514 = (unsigned *) xrealloc (pending_sibling_stack,
2515 pending_siblings_allocated * sizeof(unsigned));
2516 }
2517
2518 pending_siblings++;
2519 NEXT_DIE_NUM = next_unused_dienum++;
2520}
2521
2522/* Pop the sibling stack so that the most recently pushed DIEnum becomes the
2523 NEXT_DIE_NUM. */
2524
2525inline void
2526dienum_pop ()
2527{
2528 pending_siblings--;
2529}
2530
2531inline tree
2532member_declared_type (member)
2533 register tree member;
2534{
2535 return (DECL_BIT_FIELD_TYPE (member))
2536 ? DECL_BIT_FIELD_TYPE (member)
2537 : TREE_TYPE (member);
2538}
2539
2540/******************************* DIEs ************************************/
2541
2542/* Output routines for individual types of DIEs. */
2543
2544/* Note that every type of DIE (except a null DIE) gets a sibling. */
2545
2546static void
2547output_array_type_die (arg)
2548 register void *arg;
2549{
2550 register tree type = arg;
2551
2552 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
2553 sibling_attribute ();
2554 equate_type_number_to_die_number (type);
2555 member_attribute (TYPE_CONTEXT (type));
2556
2557 /* I believe that we can default the array ordering. SDB will probably
2558 do the right things even if AT_ordering is not present. It's not
2559 even an issue until we start to get into multidimensional arrays
9a631e8e
RS
2560 anyway. If SDB is ever caught doing the Wrong Thing for multi-
2561 dimensional arrays, then we'll have to put the AT_ordering attribute
2562 back in. (But if and when we find out that we need to put these in,
2563 we will only do so for multidimensional arrays. After all, we don't
2564 want to waste space in the .debug section now do we?) */
340ccaab
TW
2565
2566#if 0
2567 ordering_attribute (ORD_row_major);
2568#endif
2569
2570 subscript_data_attribute (type);
2571}
2572
2573static void
2574output_set_type_die (arg)
2575 register void *arg;
2576{
2577 register tree type = arg;
2578
2579 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
2580 sibling_attribute ();
2581 equate_type_number_to_die_number (type);
2582 member_attribute (TYPE_CONTEXT (type));
2583 type_attribute (TREE_TYPE (type), 0, 0);
2584}
2585
2586#if 0
2587/* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
2588static void
2589output_entry_point_die (arg)
2590 register void *arg;
2591{
2592 register tree decl = arg;
2593 register tree type = TREE_TYPE (decl);
2594 register tree return_type = TREE_TYPE (type);
2595
2596 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
2597 sibling_attribute ();
2598 dienum_push ();
9a631e8e 2599 name_and_src_coords_attributes (decl);
340ccaab
TW
2600 member_attribute (DECL_CONTEXT (decl));
2601 type_attribute (return_type, 0, 0);
2602}
2603#endif
2604
2605/* Output a DIE to represent an enumeration type. Note that these DIEs
2606 include all of the information about the enumeration values also.
2607 This information is encoded into the element_list attribute. */
2608
2609static void
2610output_enumeration_type_die (arg)
2611 register void *arg;
2612{
2613 register tree type = arg;
2614
2615 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
2616 sibling_attribute ();
2617 equate_type_number_to_die_number (type);
2618 name_attribute (type_tag (type));
2619 member_attribute (TYPE_CONTEXT (type));
2620
2621 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
2622 given enum type is incomplete, do not generate the AT_byte_size
2623 attribute or the AT_element_list attribute. */
2624
2625 if (TYPE_SIZE (type))
2626 {
2627 byte_size_attribute (type);
2628 element_list_attribute (TYPE_FIELDS (type));
2629 }
2630}
2631
2632/* Output a DIE to represent either a real live formal parameter decl or
2633 to represent just the type of some formal parameter position in some
2634 function type.
2635
2636 Note that this routine is a bit unusual because its argument may be
2637 either a PARM_DECL node or else some sort of a ..._TYPE node. If it's
2638 the formar then this function is being called to output a real live
2639 formal parameter declaration. If it's the latter, then this function
2640 is only being called to output a TAG_formal_parameter DIE to stand as
2641 a placeholder for some formal argument type of some subprogram type. */
2642
2643static void
2644output_formal_parameter_die (arg)
2645 register void *arg;
2646{
2647 register tree decl = arg;
2648 register tree type;
2649
2650 if (TREE_CODE (decl) == PARM_DECL)
2651 type = TREE_TYPE (decl);
2652 else
2653 {
2654 type = decl; /* we were called with a type, not a decl */
2655 decl = NULL;
2656 }
2657
2658 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
2659 sibling_attribute ();
2660 if (decl)
2661 {
9a631e8e 2662 name_and_src_coords_attributes (decl);
340ccaab
TW
2663 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2664 location_or_const_value_attribute (decl);
2665 }
2666 else
2667 type_attribute (type, 0, 0);
2668}
2669
2670/* Output a DIE to represent a declared function (either file-scope
2671 or block-local) which has "external linkage" (according to ANSI-C). */
2672
2673static void
2674output_global_subroutine_die (arg)
2675 register void *arg;
2676{
2677 register tree decl = arg;
2678 register tree type = TREE_TYPE (decl);
2679 register tree return_type = TREE_TYPE (type);
2680
2681 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
2682 sibling_attribute ();
2683 dienum_push ();
9a631e8e 2684 name_and_src_coords_attributes (decl);
340ccaab
TW
2685 inline_attribute (decl);
2686 prototyped_attribute (type);
2687 member_attribute (DECL_CONTEXT (decl));
2688 type_attribute (return_type, 0, 0);
2689 if (!TREE_EXTERNAL (decl))
2690 {
2691 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2692
9a631e8e 2693 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
340ccaab
TW
2694 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
2695 high_pc_attribute (func_end_label);
2696 }
2697}
2698
2699/* Output a DIE to represent a declared data object (either file-scope
2700 or block-local) which has "external linkage" (according to ANSI-C). */
2701
2702static void
2703output_global_variable_die (arg)
2704 register void *arg;
2705{
2706 register tree decl = arg;
2707 register tree type = TREE_TYPE (decl);
2708
2709 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
2710 sibling_attribute ();
9a631e8e 2711 name_and_src_coords_attributes (decl);
340ccaab
TW
2712 member_attribute (DECL_CONTEXT (decl));
2713 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2714 if (!TREE_EXTERNAL (decl))
2715 location_or_const_value_attribute (decl);
2716}
2717
2718#if 0
2719/* TAG_inline_subroutine has been retired by the UI/PLSIG. We're
2720 now supposed to use either TAG_subroutine or TAG_global_subroutine
2721 (depending on whether or not the function in question has internal
2722 or external linkage) and we're supposed to just put in an AT_inline
2723 attribute. */
2724static void
2725output_inline_subroutine_die (arg)
2726 register void *arg;
2727{
2728 register tree decl = arg;
2729 register tree type = TREE_TYPE (decl);
2730 register tree return_type = TREE_TYPE (type);
2731
2732 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inline_subroutine);
2733 sibling_attribute ();
2734 dienum_push ();
9a631e8e 2735 name_and_src_coords_attributes (decl);
340ccaab
TW
2736 prototyped_attribute (type);
2737 member_attribute (DECL_CONTEXT (decl));
2738 type_attribute (return_type, 0, 0);
2739
2740 /* Note: For each inline function which gets an out-of-line body
2741 generated for it, we want to generate AT_low_pc and AT_high_pc
2742 attributes here for the function's out-of-line body.
2743
2744 Unfortunately, the decision as to whether or not to generate an
2745 out-of-line body for any given inline function may not be made
2746 until we reach the end of the containing scope for the given
2747 inline function (because only then will it be known if the
2748 function was ever even called).
2749
2750 For this reason, the output of DIEs representing file-scope inline
2751 functions gets delayed until a special post-pass which happens only
2752 after we have reached the end of the compilation unit. Because of
2753 this mechanism, we can always be sure (by the time we reach here)
2754 that TREE_ASM_WRITTEN(decl) will correctly indicate whether or not
2755 there was an out-of-line body generated for this inline function.
2756 */
2757
2758 if (!TREE_EXTERNAL (decl))
2759 {
2760 if (TREE_ASM_WRITTEN (decl))
2761 {
2762 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2763
9a631e8e 2764 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
340ccaab
TW
2765 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
2766 high_pc_attribute (func_end_label);
2767 }
2768 }
2769}
2770#endif
2771
2772static void
2773output_label_die (arg)
2774 register void *arg;
2775{
2776 register tree decl = arg;
2777 register rtx insn = DECL_RTL (decl);
2778
2779 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
2780 sibling_attribute ();
9a631e8e 2781 name_and_src_coords_attributes (decl);
340ccaab
TW
2782
2783 /* When optimization is enabled (with -O) the code in jump.c and in flow.c
2784 may cause insns representing one of more of the user's own labels to
2785 be deleted. This happens whenever it is determined that a given label
2786 is unreachable.
2787
2788 In such cases, we here generate an abbreviated form of a label DIE.
2789 This abbreviated version does *not* have a low_pc attribute. This
2790 should signify to the debugger that the label has been optimized away.
2791
2792 Note that a CODE_LABEL can get deleted either by begin converted into
2793 a NOTE_INSN_DELETED note, or by simply having its INSN_DELETED_P flag
2794 set to true. We handle both cases here.
2795 */
2796
2797 if (GET_CODE (insn) == CODE_LABEL && ! INSN_DELETED_P (insn))
2798 {
2799 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2800
2801 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
2802 (unsigned) INSN_UID (insn));
2803 low_pc_attribute (label);
2804 }
2805}
2806
2807static void
2808output_lexical_block_die (arg)
2809 register void *arg;
2810{
2811 register tree stmt = arg;
2812 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2813 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2814
2815 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
2816 sibling_attribute ();
2817 dienum_push ();
2818 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
2819 low_pc_attribute (begin_label);
2820 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
2821 high_pc_attribute (end_label);
2822}
2823
2824static void
2825output_inlined_subroutine_die (arg)
2826 register void *arg;
2827{
2828 register tree stmt = arg;
2829 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2830 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2831
2832 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
2833 sibling_attribute ();
2834 dienum_push ();
2835 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
2836 low_pc_attribute (begin_label);
2837 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
2838 high_pc_attribute (end_label);
2839}
2840
2841/* Output a DIE to represent a declared data object (either file-scope
2842 or block-local) which has "internal linkage" (according to ANSI-C). */
2843
2844static void
2845output_local_variable_die (arg)
2846 register void *arg;
2847{
2848 register tree decl = arg;
2849 register tree type = TREE_TYPE (decl);
2850
2851 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
2852 sibling_attribute ();
9a631e8e 2853 name_and_src_coords_attributes (decl);
340ccaab
TW
2854 member_attribute (DECL_CONTEXT (decl));
2855 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2856 location_or_const_value_attribute (decl);
2857}
2858
2859static void
2860output_member_die (arg)
2861 register void *arg;
2862{
2863 register tree decl = arg;
2864
2865 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
2866 sibling_attribute ();
9a631e8e 2867 name_and_src_coords_attributes (decl);
340ccaab
TW
2868 member_attribute (DECL_CONTEXT (decl));
2869 type_attribute (member_declared_type (decl),
2870 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2871 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
2872 {
2873 byte_size_attribute (decl);
2874 bit_size_attribute (decl);
2875 bit_offset_attribute (decl);
2876 }
2877 data_member_location_attribute (decl);
2878}
2879
2880#if 0
2881/* Don't generate either pointer_type DIEs or reference_type DIEs. According
2882 to the 4-4-90 Dwarf draft spec (just after requirement #47):
2883
2884 These two type entries are not currently generated by any compiler.
2885 Since the only way to name a pointer (or reference) type is C or C++
2886 is via a "typedef", an entry with the "typedef" tag is generated
2887 instead.
2888
2889 We keep this code here just in case these types of DIEs may be needed
2890 to represent certain things in other languages (e.g. Pascal) someday.
2891*/
2892
2893static void
2894output_pointer_type_die (arg)
2895 register void *arg;
2896{
2897 register tree type = arg;
2898
2899 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
2900 sibling_attribute ();
2901 equate_type_number_to_die_number (type);
2902 member_attribute (TYPE_CONTEXT (type));
2903 type_attribute (TREE_TYPE (type), 0, 0);
2904}
2905
2906static void
2907output_reference_type_die (arg)
2908 register void *arg;
2909{
2910 register tree type = arg;
2911
2912 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
2913 sibling_attribute ();
2914 equate_type_number_to_die_number (type);
2915 member_attribute (TYPE_CONTEXT (type));
2916 type_attribute (TREE_TYPE (type), 0, 0);
2917}
2918#endif
2919
2920output_ptr_to_mbr_type_die (arg)
2921 register void *arg;
2922{
2923 register tree type = arg;
2924
2925 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
2926 sibling_attribute ();
2927 equate_type_number_to_die_number (type);
2928 member_attribute (TYPE_CONTEXT (type));
2929 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
2930 type_attribute (TREE_TYPE (type), 0, 0);
2931}
2932
2933static void
2934output_compile_unit_die (arg)
2935 register void *arg;
2936{
2937 register char *main_input_filename = arg;
2938
2939 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
2940 sibling_attribute ();
2941 dienum_push ();
2942 name_attribute (main_input_filename);
2943
2944 {
2945 char producer[250];
2946
2947 sprintf (producer, "%s %s", language_string, version_string);
2948 producer_attribute (producer);
2949 }
2950
2951 if (strcmp (language_string, "GNU C++") == 0)
2952 language_attribute (LANG_C_PLUS_PLUS);
2953 else if (flag_traditional)
2954 language_attribute (LANG_C);
2955 else
2956 language_attribute (LANG_C89);
2957 low_pc_attribute (TEXT_BEGIN_LABEL);
2958 high_pc_attribute (TEXT_END_LABEL);
2959 if (debug_info_level >= DINFO_LEVEL_NORMAL)
2960 stmt_list_attribute (LINE_BEGIN_LABEL);
2961 last_filename = xstrdup (main_input_filename);
2962
2963 {
2e494f70
RS
2964 char *wd = getpwd ();
2965 if (wd)
2966 comp_dir_attribute (wd);
340ccaab
TW
2967 }
2968
2969 if (debug_info_level >= DINFO_LEVEL_NORMAL)
2970 {
2971 sf_names_attribute (SFNAMES_BEGIN_LABEL);
2972 src_info_attribute (SRCINFO_BEGIN_LABEL);
2973 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
2974 mac_info_attribute (MACINFO_BEGIN_LABEL);
2975 }
2976}
2977
2978static void
2979output_string_type_die (arg)
2980 register void *arg;
2981{
2982 register tree type = arg;
2983
2984 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
2985 sibling_attribute ();
2986 member_attribute (TYPE_CONTEXT (type));
2987
2988 /* Fudge the string length attribute for now. */
2989
2990 string_length_attribute (
2991 TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
2992}
2993
2994static void
2995output_structure_type_die (arg)
2996 register void *arg;
2997{
2998 register tree type = arg;
2999
3000 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3001 sibling_attribute ();
3002 equate_type_number_to_die_number (type);
3003 name_attribute (type_tag (type));
3004 member_attribute (TYPE_CONTEXT (type));
3005
3006 /* If this type has been completed, then give it a byte_size attribute
3007 and prepare to give a list of members. Otherwise, don't do either of
3008 these things. In the latter case, we will not be generating a list
3009 of members (since we don't have any idea what they might be for an
3010 incomplete type). */
3011
3012 if (TYPE_SIZE (type))
3013 {
3014 dienum_push ();
3015 byte_size_attribute (type);
3016 }
3017}
3018
3019/* Output a DIE to represent a declared function (either file-scope
3020 or block-local) which has "internal linkage" (according to ANSI-C). */
3021
3022static void
3023output_local_subroutine_die (arg)
3024 register void *arg;
3025{
3026 register tree decl = arg;
3027 register tree type = TREE_TYPE (decl);
3028 register tree return_type = TREE_TYPE (type);
3029 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3030
3031 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3032 sibling_attribute ();
3033 dienum_push ();
9a631e8e 3034 name_and_src_coords_attributes (decl);
340ccaab
TW
3035 inline_attribute (decl);
3036 prototyped_attribute (type);
3037 member_attribute (DECL_CONTEXT (decl));
3038 type_attribute (return_type, 0, 0);
3039
3040 /* Avoid getting screwed up in cases where a function was declared static
3041 but where no definition was ever given for it. */
3042
3043 if (TREE_ASM_WRITTEN (decl))
3044 {
9a631e8e 3045 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
340ccaab
TW
3046 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
3047 high_pc_attribute (func_end_label);
3048 }
3049}
3050
3051static void
3052output_subroutine_type_die (arg)
3053 register void *arg;
3054{
3055 register tree type = arg;
3056 register tree return_type = TREE_TYPE (type);
3057
3058 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3059 sibling_attribute ();
3060 dienum_push ();
3061 equate_type_number_to_die_number (type);
3062 prototyped_attribute (type);
3063 member_attribute (TYPE_CONTEXT (type));
3064 type_attribute (return_type, 0, 0);
3065}
3066
3067static void
3068output_typedef_die (arg)
3069 register void *arg;
3070{
3071 register tree decl = arg;
3072 register tree type = TREE_TYPE (decl);
3073
3074 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3075 sibling_attribute ();
9a631e8e 3076 name_and_src_coords_attributes (decl);
340ccaab
TW
3077 member_attribute (DECL_CONTEXT (decl));
3078 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3079}
3080
3081static void
3082output_union_type_die (arg)
3083 register void *arg;
3084{
3085 register tree type = arg;
3086
3087 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3088 sibling_attribute ();
3089 equate_type_number_to_die_number (type);
3090 name_attribute (type_tag (type));
3091 member_attribute (TYPE_CONTEXT (type));
3092
3093 /* If this type has been completed, then give it a byte_size attribute
3094 and prepare to give a list of members. Otherwise, don't do either of
3095 these things. In the latter case, we will not be generating a list
3096 of members (since we don't have any idea what they might be for an
3097 incomplete type). */
3098
3099 if (TYPE_SIZE (type))
3100 {
3101 dienum_push ();
3102 byte_size_attribute (type);
3103 }
3104}
3105
3106/* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3107 at the end of an (ANSI prototyped) formal parameters list. */
3108
3109static void
3110output_unspecified_parameters_die (arg)
3111 register void *arg;
3112{
3113 register tree decl_or_type = arg;
3114
3115 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3116 sibling_attribute ();
3117
3118 /* This kludge is here only for the sake of being compatible with what
3119 the USL CI5 C compiler does. The specification of Dwarf Version 1
3120 doesn't say that TAG_unspecified_parameters DIEs should contain any
3121 attributes other than the AT_sibling attribute, but they are certainly
3122 allowed to contain additional attributes, and the CI5 compiler
3123 generates AT_name, AT_fund_type, and AT_location attributes within
3124 TAG_unspecified_parameters DIEs which appear in the child lists for
3125 DIEs representing function definitions, so we do likewise here. */
3126
3127 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3128 {
3129 name_attribute ("...");
3130 fund_type_attribute (FT_pointer);
3131 /* location_attribute (?); */
3132 }
3133}
3134
3135static void
3136output_padded_null_die (arg)
3137 register void *arg;
3138{
3139 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3140}
3141
3142/*************************** end of DIEs *********************************/
3143
3144/* Generate some type of DIE. This routine generates the generic outer
3145 wrapper stuff which goes around all types of DIE's (regardless of their
3146 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3147 DIE-length word, followed by the guts of the DIE itself. After the guts
3148 of the DIE, there must always be a terminator label for the DIE. */
3149
3150static void
3151output_die (die_specific_output_function, param)
3152 register void (*die_specific_output_function)();
3153 register void *param;
3154{
3155 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3156 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3157
3158 current_dienum = NEXT_DIE_NUM;
3159 NEXT_DIE_NUM = next_unused_dienum;
3160
3161 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3162 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3163
3164 /* Write a label which will act as the name for the start of this DIE. */
3165
3166 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3167
3168 /* Write the DIE-length word. */
3169
3170 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3171
3172 /* Fill in the guts of the DIE. */
3173
3174 next_unused_dienum++;
3175 die_specific_output_function (param);
3176
3177 /* Write a label which will act as the name for the end of this DIE. */
3178
3179 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3180}
3181
3182static void
3183end_sibling_chain ()
3184{
3185 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3186
3187 current_dienum = NEXT_DIE_NUM;
3188 NEXT_DIE_NUM = next_unused_dienum;
3189
3190 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3191
3192 /* Write a label which will act as the name for the start of this DIE. */
3193
3194 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3195
3196 /* Write the DIE-length word. */
3197
3198 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3199
3200 dienum_pop ();
3201}
3202\f
3203/* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
3204 TAG_unspecified_parameters DIE) to represent the types of the formal
3205 parameters as specified in some function type specification (except
3206 for those which appear as part of a function *definition*).
3207
3208 Note that we must be careful here to output all of the parameter DIEs
3209 *before* we output any DIEs needed to represent the types of the formal
3210 parameters. This keeps svr4 SDB happy because it (incorrectly) thinks
3211 that the first non-parameter DIE it sees ends the formal parameter list.
3212*/
3213
3214static void
3215output_formal_types (function_or_method_type)
3216 register tree function_or_method_type;
3217{
3218 register tree link;
3219 register tree formal_type;
3220 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
3221
3222 /* In the case where we are generating a formal types list for a C++
3223 non-static member function type, skip over the first thing on the
3224 TYPE_ARG_TYPES list because it only represents the type of the
3225 hidden `this pointer'. The debugger should be able to figure
3226 out (without being explicitly told) that this non-static member
3227 function type takes a `this pointer' and should be able to figure
3228 what the type of that hidden parameter is from the AT_member
3229 attribute of the parent TAG_subroutine_type DIE. */
3230
3231 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
3232 first_parm_type = TREE_CHAIN (first_parm_type);
3233
3234 /* Make our first pass over the list of formal parameter types and output
3235 a TAG_formal_parameter DIE for each one. */
3236
3237 for (link = first_parm_type; link; link = TREE_CHAIN (link))
3238 {
3239 formal_type = TREE_VALUE (link);
3240 if (formal_type == void_type_node)
3241 break;
3242
3243 /* Output a (nameless) DIE to represent the formal parameter itself. */
3244
3245 output_die (output_formal_parameter_die, formal_type);
3246 }
3247
3248 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
3249 DIE to the end of the parameter list. */
3250
3251 if (formal_type != void_type_node)
3252 output_die (output_unspecified_parameters_die, function_or_method_type);
3253
3254 /* Make our second (and final) pass over the list of formal parameter types
3255 and output DIEs to represent those types (as necessary). */
3256
3257 for (link = TYPE_ARG_TYPES (function_or_method_type);
3258 link;
3259 link = TREE_CHAIN (link))
3260 {
3261 formal_type = TREE_VALUE (link);
3262 if (formal_type == void_type_node)
3263 break;
3264
3265 output_type (formal_type, function_or_method_type);
3266 }
3267}
3268\f
3269/* Remember a type in the pending_types_list. */
3270
3271static void
3272pend_type (type)
3273 register tree type;
3274{
3275 if (pending_types == pending_types_allocated)
3276 {
3277 pending_types_allocated += PENDING_TYPES_INCREMENT;
3278 pending_types_list
3279 = (tree *) xrealloc (pending_types_list,
3280 sizeof (tree) * pending_types_allocated);
3281 }
3282 pending_types_list[pending_types++] = type;
3283
3284 /* Mark the pending type as having been output already (even though
3285 it hasn't been). This prevents the type from being added to the
3286 pending_types_list more than once. */
3287
3288 TREE_ASM_WRITTEN (type) = 1;
3289}
3290
3291/* Return non-zero if it is legitimate to output DIEs to represent a
3292 given type while we are generating the list of child DIEs for some
3293 DIE associated with a given scope.
3294
3295 This function returns non-zero if *either* of the following two conditions
3296 is satisfied:
3297
3298 o the type actually belongs to the given scope (as evidenced
3299 by its TYPE_CONTEXT value), or
3300
3301 o the type is anonymous, and the `scope' in question is *not*
3302 a RECORD_TYPE or UNION_TYPE.
3303
3304 In theory, we should be able to generate DIEs for anonymous types
3305 *anywhere* (since the scope of an anonymous type is irrelevant)
3306 however svr4 SDB doesn't want to see other type DIEs within the
3307 lists of child DIEs for a TAG_structure_type or TAG_union_type DIE.
3308
3309 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
3310 or it may point to a BLOCK node (for types local to a block), or to a
3311 FUNCTION_DECL node (for types local to the heading of some function
3312 definition), or to a FUNCTION_TYPE node (for types local to the
3313 prototyped parameter list of a function type specification), or to a
3314 RECORD_TYPE or UNION_TYPE node (in the case of C++ nested types).
3315
3316 The `scope' parameter should likewise be NULL or should point to a
3317 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
3318 node, or a UNION_TYPE node.
3319
3320 This function is used only for deciding when to "pend" and when to
3321 "un-pend" types to/from the pending_types_list.
3322
3323 Note that we sometimes make use of this "type pending" feature in a
3324 rather twisted way to temporarily delay the production of DIEs for the
3325 types of formal parameters. (We do this just to make svr4 SDB happy.)
3326 It order to delay the production of DIEs representing types of formal
3327 parameters, callers of this function supply `fake_containing_scope' as
3328 the `scope' parameter to this function. Given that fake_containing_scope
3329 is *not* the containing scope for *any* other type, the desired effect
3330 is achieved, i.e. output of DIEs representing types is temporarily
3331 suspended, and any type DIEs which would have been output otherwise
3332 are instead placed onto the pending_types_list. Later on, we can force
3333 these (temporarily pended) types to be output simply by calling
3334 `output_pending_types_for_scope' with an actual argument equal to the
3335 true scope of the types we temporarily pended.
3336*/
3337
3338static int
3339type_ok_for_scope (type, scope)
3340 register tree type;
3341 register tree scope;
3342{
3343 return (TYPE_CONTEXT (type) == scope
3344 || (TYPE_NAME (type) == NULL
3345 && TREE_CODE (scope) != RECORD_TYPE
3346 && TREE_CODE (scope) != UNION_TYPE));
3347}
3348
3349/* Output any pending types (from the pending_types list) which we can output
3350 now (given the limitations of the scope that we are working on now).
3351
3352 For each type output, remove the given type from the pending_types_list
3353 *before* we try to output it.
3354
3355 Note that we have to process the list in beginning-to-end order,
3356 because the call made here to output_type may cause yet more types
3357 to be added to the end of the list, and we may have to output some
3358 of them too.
3359*/
3360
3361static void
3362output_pending_types_for_scope (containing_scope)
3363 register tree containing_scope;
3364{
3365 register unsigned i;
3366
3367 for (i = 0; i < pending_types; )
3368 {
3369 register tree type = pending_types_list[i];
3370
3371 if (type_ok_for_scope (type, containing_scope))
3372 {
3373 register tree *mover;
3374 register tree *limit;
3375
3376 pending_types--;
3377 limit = &pending_types_list[pending_types];
3378 for (mover = &pending_types_list[i]; mover < limit; mover++)
3379 *mover = *(mover+1);
3380
3381 /* Un-mark the type as having been output already (because it
3382 hasn't been, really). Then call output_type to generate a
3383 Dwarf representation of it. */
3384
3385 TREE_ASM_WRITTEN (type) = 0;
3386 output_type (type, containing_scope);
3387
3388 /* Don't increment the loop counter in this case because we
3389 have shifted all of the subsequent pending types down one
3390 element in the pending_types_list array. */
3391 }
3392 else
3393 i++;
3394 }
3395}
3396
3397static void
3398output_type (type, containing_scope)
3399 register tree type;
3400 register tree containing_scope;
3401{
3402 if (type == 0 || type == error_mark_node)
3403 return;
3404
3405 /* We are going to output a DIE to represent the unqualified version of
3406 of this type (i.e. without any const or volatile qualifiers) so get
3407 the main variant (i.e. the unqualified version) of this type now. */
3408
3409 type = TYPE_MAIN_VARIANT (type);
3410
3411 if (TREE_ASM_WRITTEN (type))
3412 return;
3413
3414 /* Don't generate any DIEs for this type now unless it is OK to do so
3415 (based upon what `type_ok_for_scope' tells us). */
3416
3417 if (! type_ok_for_scope (type, containing_scope))
3418 {
3419 pend_type (type);
3420 return;
3421 }
3422
3423 switch (TREE_CODE (type))
3424 {
3425 case ERROR_MARK:
3426 break;
3427
3428 case POINTER_TYPE:
3429 case REFERENCE_TYPE:
3430 /* For these types, all that is required is that we output a DIE
3431 (or a set of DIEs) to represent that "basis" type. */
3432 output_type (TREE_TYPE (type), containing_scope);
3433 break;
3434
3435 case OFFSET_TYPE:
3436 /* This code is used for C++ pointer-to-data-member types. */
3437 /* Output a description of the relevant class type. */
3438 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
3439 /* Output a description of the type of the object pointed to. */
3440 output_type (TREE_TYPE (type), containing_scope);
3441 /* Now output a DIE to represent this pointer-to-data-member type
3442 itself. */
3443 output_die (output_ptr_to_mbr_type_die, type);
3444 break;
3445
3446 case SET_TYPE:
3447 output_type (TREE_TYPE (type), containing_scope);
3448 output_die (output_set_type_die, type);
3449 break;
3450
3451 case FILE_TYPE:
3452 output_type (TREE_TYPE (type), containing_scope);
6dc42e49 3453 abort (); /* No way to represent these in Dwarf yet! */
340ccaab
TW
3454 break;
3455
3456 case STRING_TYPE:
3457 output_type (TREE_TYPE (type), containing_scope);
3458 output_die (output_string_type_die, type);
3459 break;
3460
3461 case FUNCTION_TYPE:
3462 /* Force out return type (in case it wasn't forced out already). */
3463 output_type (TREE_TYPE (type), containing_scope);
3464 output_die (output_subroutine_type_die, type);
3465 output_formal_types (type);
3466 end_sibling_chain ();
3467 break;
3468
3469 case METHOD_TYPE:
3470 /* Force out return type (in case it wasn't forced out already). */
3471 output_type (TREE_TYPE (type), containing_scope);
3472 output_die (output_subroutine_type_die, type);
3473 output_formal_types (type);
3474 end_sibling_chain ();
3475 break;
3476
3477 case ARRAY_TYPE:
3478 {
3479 register tree element_type;
3480
3481 element_type = TREE_TYPE (type);
3482 while (TREE_CODE (element_type) == ARRAY_TYPE)
3483 element_type = TREE_TYPE (element_type);
3484
3485 output_type (element_type, containing_scope);
3486 output_die (output_array_type_die, type);
3487 }
3488 break;
3489
3490 case ENUMERAL_TYPE:
3491 case RECORD_TYPE:
3492 case UNION_TYPE:
3493
3494 /* For a non-file-scope tagged type, we can always go ahead and
3495 output a Dwarf description of this type right now, even if
3496 the type in question is still incomplete, because if this
3497 local type *was* ever completed anywhere within its scope,
3498 that complete definition would already have been attached to
3499 this RECORD_TYPE, UNION_TYPE or ENUMERAL_TYPE node by the
3500 time we reach this point. That's true because of the way the
3501 front-end does its processing of file-scope declarations (of
3502 functions and class types) within which other types might be
3503 nested. The C and C++ front-ends always gobble up such "local
3504 scope" things en-mass before they try to output *any* debugging
3505 information for any of the stuff contained inside them and thus,
3506 we get the benefit here of what is (in effect) a pre-resolution
3507 of forward references to tagged types in local scopes.
3508
3509 Note however that for file-scope tagged types we cannot assume
3510 that such pre-resolution of forward references has taken place.
3511 A given file-scope tagged type may appear to be incomplete when
3512 we reach this point, but it may yet be given a full definition
3513 (at file-scope) later on during compilation. In order to avoid
3514 generating a premature (and possibly incorrect) set of Dwarf
3515 DIEs for such (as yet incomplete) file-scope tagged types, we
3516 generate nothing at all for as-yet incomplete file-scope tagged
3517 types here unless we are making our special "finalization" pass
3518 for file-scope things at the very end of compilation. At that
3519 time, we will certainly know as much about each file-scope tagged
3520 type as we are ever going to know, so at that point in time, we
3521 can safely generate correct Dwarf descriptions for these file-
3522 scope tagged types.
3523 */
3524
3525 if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing)
3526 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
3527
3528 /* Prevent infinite recursion in cases where the type of some
3529 member of this type is expressed in terms of this type itself. */
3530
3531 TREE_ASM_WRITTEN (type) = 1;
3532
3533 /* Output a DIE to represent the tagged type itself. */
3534
3535 switch (TREE_CODE (type))
3536 {
3537 case ENUMERAL_TYPE:
3538 output_die (output_enumeration_type_die, type);
3539 return; /* a special case -- nothing left to do so just return */
3540
3541 case RECORD_TYPE:
3542 output_die (output_structure_type_die, type);
3543 break;
3544
3545 case UNION_TYPE:
3546 output_die (output_union_type_die, type);
3547 break;
3548 }
3549
3550 /* If this is not an incomplete type, output descriptions of
3551 each of its members.
3552
3553 Note that as we output the DIEs necessary to represent the
3554 members of this record or union type, we will also be trying
3555 to output DIEs to represent the *types* of those members.
3556 However the `output_type' function (above) will specifically
3557 avoid generating type DIEs for member types *within* the list
3558 of member DIEs for this (containing) type execpt for those
3559 types (of members) which are explicitly marked as also being
3560 members of this (containing) type themselves. The g++ front-
3561 end can force any given type to be treated as a member of some
3562 other (containing) type by setting the TYPE_CONTEXT of the
3563 given (member) type to point to the TREE node representing the
3564 appropriate (containing) type.
3565 */
3566
3567 if (TYPE_SIZE (type))
3568 {
9a631e8e
RS
3569 {
3570 register tree normal_member;
340ccaab 3571
9a631e8e 3572 /* First output info about the data members and type members. */
340ccaab 3573
9a631e8e
RS
3574 for (normal_member = TYPE_FIELDS (type);
3575 normal_member;
3576 normal_member = TREE_CHAIN (normal_member))
3577 output_decl (normal_member, type);
3578 }
340ccaab 3579
9a631e8e
RS
3580 {
3581 register tree vec_base;
3582
3583 /* Now output info about the function members (if any). */
3584
3585 vec_base = TYPE_METHODS (type);
3586 if (vec_base)
3587 {
3588 register tree first_func_member = TREE_VEC_ELT (vec_base, 0);
3589 register tree func_member;
3590
3591 /* This isn't documented, but the first element of the
3592 vector of member functions can be NULL in cases where
3593 the class type in question didn't have either a
3594 constructor or a destructor declared for it. We have
3595 to make allowances for that here. */
3596
3597 if (first_func_member == NULL)
3598 first_func_member = TREE_VEC_ELT (vec_base, 1);
3599
3600 for (func_member = first_func_member;
3601 func_member;
3602 func_member = TREE_CHAIN (func_member))
3603 output_decl (func_member, type);
3604 }
3605 }
340ccaab
TW
3606
3607 end_sibling_chain (); /* Terminate member chain. */
3608 }
3609
3610 break;
3611
3612 case VOID_TYPE:
3613 case INTEGER_TYPE:
3614 case REAL_TYPE:
3615 case COMPLEX_TYPE:
3616 case BOOLEAN_TYPE:
3617 case CHAR_TYPE:
3618 break; /* No DIEs needed for fundamental types. */
3619
3620 case LANG_TYPE: /* No Dwarf representation currently defined. */
3621 break;
3622
3623 default:
3624 abort ();
3625 }
3626
3627 TREE_ASM_WRITTEN (type) = 1;
3628}
3629\f
3630/* Output a TAG_lexical_block DIE followed by DIEs to represent all of
3631 the things which are local to the given block. */
3632
3633static void
3634output_block (stmt)
3635 register tree stmt;
3636{
3637 register int have_significant_locals = 0;
3638
3639 /* Ignore blocks never really used to make RTL. */
3640
3641 if (! stmt || ! TREE_USED (stmt))
3642 return;
3643
3644 /* Determine if this block contains any "significant" local declarations
3645 which we need to output DIEs for. */
3646
3647 if (BLOCK_INLINE_FUNCTION (stmt))
3648 /* The outer scopes for inlinings *must* always be represented. */
3649 have_significant_locals = 1;
3650 else
3651 if (debug_info_level > DINFO_LEVEL_TERSE)
3652 have_significant_locals = (BLOCK_VARS (stmt) != NULL);
3653 else
3654 {
3655 register tree decl;
3656
3657 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
3658 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
3659 {
3660 have_significant_locals = 1;
3661 break;
3662 }
3663 }
3664
3665 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
3666 DIE for any block which contains no significant local declarations
3667 at all. Rather, in such cases we just call `output_decls_for_scope'
3668 so that any needed Dwarf info for any sub-blocks will get properly
3669 generated. Note that in terse mode, our definition of what constitutes
3670 a "significant" local declaration gets restricted to include only
3671 inlined function instances and local (nested) function definitions. */
3672
3673 if (have_significant_locals)
3674 {
3675 output_die (BLOCK_INLINE_FUNCTION (stmt)
3676 ? output_inlined_subroutine_die
3677 : output_lexical_block_die,
3678 stmt);
3679 output_decls_for_scope (stmt);
3680 end_sibling_chain ();
3681 }
3682 else
3683 output_decls_for_scope (stmt);
3684}
3685
3686/* Output all of the decls declared within a given scope (also called
3687 a `binding contour') and (recursively) all of it's sub-blocks. */
3688
3689static void
3690output_decls_for_scope (stmt)
3691 register tree stmt;
3692{
3693 /* Ignore blocks never really used to make RTL. */
3694
3695 if (! stmt || ! TREE_USED (stmt))
3696 return;
3697
3698 next_block_number++;
3699
3700 /* Output the DIEs to represent all of the data objects, functions,
3701 typedefs, and tagged types declared directly within this block
3702 but not within any nested sub-blocks. */
3703
3704 {
3705 register tree decl;
3706
3707 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
3708 output_decl (decl, stmt);
3709 }
3710
3711 output_pending_types_for_scope (stmt);
3712
3713 /* Output the DIEs to represent all sub-blocks (and the items declared
3714 therein) of this block. */
3715
3716 {
3717 register tree subblocks;
3718
3719 for (subblocks = BLOCK_SUBBLOCKS (stmt);
3720 subblocks;
3721 subblocks = BLOCK_CHAIN (subblocks))
3722 output_block (subblocks);
3723 }
3724}
3725
3726/* Output Dwarf .debug information for a decl described by DECL. */
3727
3728static void
3729output_decl (decl, containing_scope)
3730 register tree decl;
3731 register tree containing_scope;
3732{
8ac9cb56
RS
3733 if (TREE_CODE (decl) == ERROR_MARK)
3734 return;
3735
3736 /* If this ..._DECL node is marked to be ignored, then ignore it.
3737 But don't ignore a function definition, since that would screw
3738 up our count of blocks, and that it turn will completely screw up the
3739 the labels we will reference in subsequent AT_low_pc and AT_high_pc
3740 attributes (for subsequent blocks). */
3741
3742 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
3743 return;
3744
340ccaab
TW
3745 switch (TREE_CODE (decl))
3746 {
340ccaab
TW
3747 case CONST_DECL:
3748 /* The individual enumerators of an enum type get output when we
3749 output the Dwarf representation of the relevant enum type itself. */
3750 break;
3751
3752 case FUNCTION_DECL:
3753 /* If we are in terse mode, don't output any DIEs to represent
648ebe7b
RS
3754 mere external function declarations. Also, if we are conforming
3755 to the DWARF version 1 specification, don't output DIEs for
340ccaab
TW
3756 mere external function declarations. */
3757
648ebe7b
RS
3758 if (TREE_EXTERNAL (decl))
3759#if (DWARF_VERSION > 1)
3760 if (debug_info_level <= DINFO_LEVEL_TERSE)
3761#endif
3762 break;
340ccaab
TW
3763
3764 /* Before we describe the FUNCTION_DECL itself, make sure that we
3765 have described its return type. */
3766
3767 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
3768
3769 /* If the following DIE will represent a function definition for a
3770 function with "extern" linkage, output a special "pubnames" DIE
3771 label just ahead of the actual DIE. A reference to this label
3772 was already generated in the .debug_pubnames section sub-entry
3773 for this function definition. */
3774
3775 if (TREE_PUBLIC (decl))
3776 {
3777 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3778
3779 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
3780 ASM_OUTPUT_LABEL (asm_out_file, label);
3781 }
3782
3783 /* Now output a DIE to represent the function itself. */
3784
3785 output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl)
3786 ? output_global_subroutine_die
3787 : output_local_subroutine_die,
3788 decl);
3789
3790 /* Now output descriptions of the arguments for this function.
3791 This gets (unnecessarily?) complex because of the fact that
3792 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
3793 cases where there was a trailing `...' at the end of the formal
3794 parameter list. In order to find out if there was a trailing
3795 ellipsis or not, we must instead look at the type associated
3796 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
3797 If the chain of type nodes hanging off of this FUNCTION_TYPE node
3798 ends with a void_type_node then there should *not* be an ellipsis
3799 at the end. */
3800
3801 /* In the case where we are describing an external function, all
3802 we need to do here (and all we *can* do here) is to describe
3803 the *types* of its formal parameters. */
3804
3805 if (TREE_EXTERNAL (decl))
3806 output_formal_types (TREE_TYPE (decl));
3807 else
3808 {
3809 register tree arg_decls = DECL_ARGUMENTS (decl);
3810
3811 /* In the case where the FUNCTION_DECL represents a C++ non-static
3812 member function, skip over the first thing on the DECL_ARGUMENTS
3813 chain. It only represents the hidden `this pointer' parameter
3814 and the debugger should know implicitly that non-static member
3815 functions have such a thing, and should be able to figure out
3816 exactly what the type of each `this pointer' is (from the
3817 AT_member attribute of the parent TAG_subroutine DIE) without
3818 being explicitly told. */
3819
3820 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
3821 arg_decls = TREE_CHAIN (arg_decls);
3822
3823 {
3824 register tree last_arg;
3825
3826 last_arg = (arg_decls && TREE_CODE (arg_decls) != ERROR_MARK)
3827 ? tree_last (arg_decls)
3828 : NULL;
3829
3830 /* Generate DIEs to represent all known formal parameters, but
3831 don't do it if this looks like a varargs function. A given
3832 function is considered to be a varargs function if (and only
3833 if) its last named argument is named `__builtin_va_alist'. */
3834
3835 if (! last_arg
3836 || ! DECL_NAME (last_arg)
3837 || strcmp (IDENTIFIER_POINTER (DECL_NAME (last_arg)),
3838 "__builtin_va_alist"))
3839 {
3840 register tree parm;
3841
3842 /* WARNING! Kludge zone ahead! Here we have a special
2e494f70 3843 hack for svr4 SDB compatibility. Instead of passing the
340ccaab
TW
3844 current FUNCTION_DECL node as the second parameter (i.e.
3845 the `containing_scope' parameter) to `output_decl' (as
3846 we ought to) we instead pass a pointer to our own private
3847 fake_containing_scope node. That node is a RECORD_TYPE
3848 node which NO OTHER TYPE may ever actually be a member of.
3849
3850 This pointer will ultimately get passed into `output_type'
3851 as its `containing_scope' parameter. `Output_type' will
3852 then perform its part in the hack... i.e. it will pend
3853 the type of the formal parameter onto the pending_types
3854 list. Later on, when we are done generating the whole
3855 sequence of formal parameter DIEs for this function
3856 definition, we will un-pend all previously pended types
3857 of formal parameters for this function definition.
3858
3859 This whole kludge prevents any type DIEs from being
3860 mixed in with the formal parameter DIEs. That's good
3861 because svr4 SDB believes that the list of formal
3862 parameter DIEs for a function ends wherever the first
3863 non-formal-parameter DIE appears. Thus, we have to
3864 keep the formal parameter DIEs segregated. They must
3865 all appear (consecutively) at the start of the list of
3866 children for the DIE representing the function definition.
3867 Then (and only then) may we output any additional DIEs
3868 needed to represent the types of these formal parameters.
3869 */
3870
3871 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
3872 if (TREE_CODE (parm) == PARM_DECL)
3873 output_decl (parm, fake_containing_scope);
3874
3875 /* Now that we have finished generating all of the DIEs to
3876 represent the formal parameters themselves, force out
3877 any DIEs needed to represent their types. We do this
3878 simply by un-pending all previously pended types which
3879 can legitimately go into the chain of children DIEs for
3880 the current FUNCTION_DECL. */
3881
3882 output_pending_types_for_scope (decl);
3883 }
3884 }
3885
3886 /* Now try to decide if we should put an ellipsis at the end. */
3887
3888 {
3889 register int has_ellipsis = TRUE; /* default assumption */
3890 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
3891
3892 if (fn_arg_types)
3893 {
3894 /* This function declaration/definition was prototyped. */
3895
3896 /* If the list of formal argument types ends with a
3897 void_type_node, then the formals list did *not* end
3898 with an ellipsis. */
3899
3900 if (TREE_VALUE (tree_last (fn_arg_types)) == void_type_node)
3901 has_ellipsis = FALSE;
3902 }
3903 else
3904 {
3905 /* This function declaration/definition was not prototyped. */
3906
3907 /* Note that all non-prototyped function *declarations* are
3908 assumed to represent varargs functions (until proven
3909 otherwise). */
3910
3911 if (DECL_INITIAL (decl)) /* if this is a func definition */
3912 {
3913 if (!arg_decls)
3914 has_ellipsis = FALSE; /* no args == (void) */
3915 else
3916 {
3917 /* For a non-prototyped function definition which
3918 declares one or more formal parameters, if the name
3919 of the first formal parameter is *not*
3920 __builtin_va_alist then we must assume that this
3921 is *not* a varargs function. */
3922
3923 if (DECL_NAME (arg_decls)
3924 && strcmp (IDENTIFIER_POINTER (DECL_NAME (arg_decls)),
3925 "__builtin_va_alist"))
3926 has_ellipsis = FALSE;
3927 }
3928 }
3929 }
3930
3931 if (has_ellipsis)
3932 output_die (output_unspecified_parameters_die, decl);
3933 }
3934 }
3935
3936 /* Output Dwarf info for all of the stuff within the body of the
3937 function (if it has one - it may be just a declaration). */
3938
3939 {
3940 register tree outer_scope = DECL_INITIAL (decl);
3941
3942 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
3943 {
3944 /* Note that here, `outer_scope' is a pointer to the outermost
3945 BLOCK node created to represent the body of a function.
3946 This outermost BLOCK actually represents the outermost
3947 binding contour for the function, i.e. the contour in which
3948 the function's formal parameters get declared. Just within
3949 this contour, there will be another (nested) BLOCK which
3950 represents the function's outermost block. We don't want
3951 to generate a lexical_block DIE to represent the outermost
3952 block of a function body, because that is not really an
3953 independent scope according to ANSI C rules. Rather, it is
3954 the same scope in which the parameters were declared and
3955 for Dwarf, we do not generate a TAG_lexical_block DIE for
3956 that scope. We must however see to it that the LABEL_DECLs
3957 associated with `outer_scope' get DIEs generated for them. */
3958
3959 {
3960 register tree label;
3961
3962 for (label = BLOCK_VARS (outer_scope);
3963 label;
3964 label = TREE_CHAIN (label))
3965 output_decl (label, outer_scope);
3966 }
3967
3968 output_decls_for_scope (BLOCK_SUBBLOCKS (outer_scope));
3969
3970 /* Finally, force out any pending types which are local to the
3971 outermost block of this function definition. These will
3972 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
3973 node itself. */
3974
3975 output_pending_types_for_scope (decl);
3976 }
3977 }
3978
3979 /* Generate a terminator for the list of stuff `owned' by this
3980 function. */
3981
3982 end_sibling_chain ();
3983
3984 break;
3985
3986 case TYPE_DECL:
3987 /* If we are in terse mode, don't generate any DIEs to represent
3988 any actual typedefs. Note that even when we are in terse mode,
3989 we must still output DIEs to represent those tagged types which
3990 are used (directly or indirectly) in the specification of either
3991 a return type or a formal parameter type of some function. */
3992
3993 if (debug_info_level <= DINFO_LEVEL_TERSE)
3994 if (DECL_NAME (decl) != NULL
3995 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
3996 return;
3997
3998 output_type (TREE_TYPE (decl), containing_scope);
3999
4000 /* Note that unlike the gcc front end (which generates a NULL named
4001 TYPE_DECL node for each complete tagged type, each array type,
4002 and each function type node created) the g++ front end generates
4003 a *named* TYPE_DECL node for each tagged type node created.
4004 Unfortunately, these g++ TYPE_DECL nodes cause us to output many
4005 superfluous and unnecessary TAG_typedef DIEs here. When g++ is
4006 fixed to stop generating these superfluous named TYPE_DECL nodes,
4007 the superfluous TAG_typedef DIEs will likewise cease. */
4008
4009 if (DECL_NAME (decl))
4010 /* Output a DIE to represent the typedef itself. */
4011 output_die (output_typedef_die, decl);
4012 break;
4013
4014 case LABEL_DECL:
4015 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4016 output_die (output_label_die, decl);
4017 break;
4018
4019 case VAR_DECL:
648ebe7b
RS
4020 /* If we are conforming to the DWARF version 1 specification, don't
4021 generated any DIEs to represent mere external object declarations. */
4022
4023#if (DWARF_VERSION <= 1)
4024 if (TREE_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4025 break;
4026#endif
4027
340ccaab
TW
4028 /* If we are in terse mode, don't generate any DIEs to represent
4029 any variable declarations or definitions. */
4030
4031 if (debug_info_level <= DINFO_LEVEL_TERSE)
4032 break;
4033
4034 /* Output any DIEs that are needed to specify the type of this data
4035 object. */
4036
4037 output_type (TREE_TYPE (decl), containing_scope);
4038
4039 /* If the following DIE will represent a data object definition for a
4040 data object with "extern" linkage, output a special "pubnames" DIE
4041 label just ahead of the actual DIE. A reference to this label
4042 was already generated in the .debug_pubnames section sub-entry
4043 for this data object definition. */
4044
4045 if (TREE_PUBLIC (decl))
4046 {
4047 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4048
4049 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4050 ASM_OUTPUT_LABEL (asm_out_file, label);
4051 }
4052
4053 /* Now output the DIE to represent the data object itself. */
4054
4055 output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl)
4056 ? output_global_variable_die : output_local_variable_die,
4057 decl);
4058 break;
4059
4060 case FIELD_DECL:
4061 /* Ignore the nameless fields that are used to skip bits. */
4062 if (DECL_NAME (decl) != 0)
4063 {
4064 output_type (member_declared_type (decl), containing_scope);
4065 output_die (output_member_die, decl);
4066 }
4067 break;
4068
4069 case PARM_DECL:
4070 /* Force out the type of this formal, if it was not forced out yet.
4071 Note that here we can run afowl of a bug in "classic" svr4 SDB.
4072 It should be able to grok the presence of type DIEs within a list
4073 of TAG_formal_parameter DIEs, but it doesn't. */
4074
4075 output_type (TREE_TYPE (decl), containing_scope);
4076 output_die (output_formal_parameter_die, decl);
4077 break;
4078
4079 default:
4080 abort ();
4081 }
4082}
4083\f
4084void
4085dwarfout_file_scope_decl (decl, set_finalizing)
4086 register tree decl;
4087 register int set_finalizing;
4088{
8ac9cb56
RS
4089 if (TREE_CODE (decl) == ERROR_MARK)
4090 return;
4091
4092 /* If this ..._DECL node is marked to be ignored, then ignore it. We
4093 gotta hope that the node in question doesn't represent a function
4094 definition. If it does, then totally ignoring it is bound to screw
4095 up our count of blocks, and that it turn will completely screw up the
4096 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4097 attributes (for subsequent blocks). (It's too bad that BLOCK nodes
4098 don't carry their own sequence numbers with them!) */
4099
4100 if (DECL_IGNORED_P (decl))
4101 {
4102 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4103 abort ();
4104 return;
4105 }
4106
340ccaab
TW
4107 switch (TREE_CODE (decl))
4108 {
4109 case FUNCTION_DECL:
4110
8ac9cb56
RS
4111 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
4112 a builtin function. Explicit programmer-supplied declarations of
4113 these same functions should NOT be ignored however. */
340ccaab
TW
4114
4115 if (TREE_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
4116 return;
4117
4118 /* Ignore this FUNCTION_DECL if it refers to a file-scope extern
4119 function declaration and if the declaration was never even
4120 referenced from within this entire compilation unit. We
4121 suppress these DIEs in order to save space in the .debug section
4122 (by eliminating entries which are probably useless). Note that
4123 we must not suppress block-local extern declarations (whether
4124 used or not) because that would screw-up the debugger's name
4125 lookup mechanism and cause it to miss things which really ought
4126 to be in scope at a given point. */
4127
4128 if (TREE_EXTERNAL (decl) && !TREE_USED (decl))
4129 return;
4130
4131 if (TREE_PUBLIC (decl) && ! TREE_EXTERNAL (decl))
4132 {
4133 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4134
4135 /* Output a .debug_pubnames entry for a public function
4136 defined in this compilation unit. */
4137
4138 fputc ('\n', asm_out_file);
85595d1a 4139 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab
TW
4140 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4141 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4142 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4143 IDENTIFIER_POINTER (DECL_NAME (decl)));
85595d1a 4144 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4145 }
4146
4147 break;
4148
4149 case VAR_DECL:
4150
4151 /* Ignore this VAR_DECL if it refers to a file-scope extern data
4152 object declaration and if the declaration was never even
4153 referenced from within this entire compilation unit. We
4154 suppress these DIEs in order to save space in the .debug section
4155 (by eliminating entries which are probably useless). Note that
4156 we must not suppress block-local extern declarations (whether
4157 used or not) because that would screw-up the debugger's name
4158 lookup mechanism and cause it to miss things which really ought
4159 to be in scope at a given point. */
4160
4161 if (TREE_EXTERNAL (decl) && !TREE_USED (decl))
4162 return;
4163
6dc42e49
RS
4164 if (TREE_PUBLIC (decl)
4165 && ! TREE_EXTERNAL (decl)
4166 && GET_CODE (DECL_RTL (decl)) == MEM)
340ccaab
TW
4167 {
4168 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4169
4170 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4171 {
4172 /* Output a .debug_pubnames entry for a public variable
4173 defined in this compilation unit. */
4174
4175 fputc ('\n', asm_out_file);
85595d1a 4176 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab
TW
4177 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4178 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4179 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4180 IDENTIFIER_POINTER (DECL_NAME (decl)));
85595d1a 4181 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4182 }
4183
4184 if (DECL_INITIAL (decl) == NULL)
4185 {
4186 /* Output a .debug_aranges entry for a public variable
6dc42e49 4187 which is tentatively defined in this compilation unit. */
340ccaab
TW
4188
4189 fputc ('\n', asm_out_file);
85595d1a 4190 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
340ccaab 4191 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
9a631e8e 4192 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
340ccaab
TW
4193 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
4194 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
85595d1a 4195 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4196 }
4197 }
4198
4199 /* If we are in terse mode, don't generate any DIEs to represent
4200 any variable declarations or definitions. */
4201
4202 if (debug_info_level <= DINFO_LEVEL_TERSE)
4203 return;
4204
4205 break;
4206
4207 case TYPE_DECL:
4208 /* Don't generate any DIEs to represent the standard built-in types. */
4209
4210 if (DECL_SOURCE_LINE (decl) == 0)
4211 return;
4212
4213 /* If we are in terse mode, don't generate any DIEs to represent
4214 any actual typedefs. Note that even when we are in terse mode,
4215 we must still output DIEs to represent those tagged types which
4216 are used (directly or indirectly) in the specification of either
4217 a return type or a formal parameter type of some function. */
4218
4219 if (debug_info_level <= DINFO_LEVEL_TERSE)
4220 if (DECL_NAME (decl) != NULL
4221 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
4222 return;
4223
4224 break;
4225
4226 default:
4227 return;
4228 }
4229
4230 fputc ('\n', asm_out_file);
85595d1a 4231 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
340ccaab
TW
4232 finalizing = set_finalizing;
4233 output_decl (decl, NULL);
4234
4235 /* NOTE: The call above to `output_decl' may have caused one or more
4236 file-scope named types (i.e. tagged types) to be placed onto the
4237 pending_types_list. We have to get those types off of that list
4238 at some point, and this is the perfect time to do it. If we didn't
4239 take them off now, they might still be on the list when cc1 finally
4240 exits. That might be OK if it weren't for the fact that when we put
4241 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
4242 for these types, and that causes them never to be output unless
4243 `output_pending_types_for_scope' takes them off of the list and un-sets
4244 their TREE_ASM_WRITTEN flags. */
4245
4246 output_pending_types_for_scope (NULL);
4247
4248 /* The above call should have totally emptied the pending_types_list. */
4249
4250 assert (pending_types == 0);
4251
85595d1a 4252 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4253
4254 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4255 current_funcdef_number++;
4256}
4257\f
4258/* Output a marker (i.e. a label) for the beginning of the generated code
4259 for a lexical block. */
4260
4261void
4262dwarfout_begin_block (blocknum)
4263 register unsigned blocknum;
4264{
4265 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4266
4267 text_section ();
4268 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
4269 ASM_OUTPUT_LABEL (asm_out_file, label);
4270}
4271
4272/* Output a marker (i.e. a label) for the end of the generated code
4273 for a lexical block. */
4274
4275void
4276dwarfout_end_block (blocknum)
4277 register unsigned blocknum;
4278{
4279 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4280
4281 text_section ();
4282 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
4283 ASM_OUTPUT_LABEL (asm_out_file, label);
4284}
4285
4286/* Output a marker (i.e. a label) at a point in the assembly code which
4287 corresponds to a given source level label. */
4288
4289void
4290dwarfout_label (insn)
4291 register rtx insn;
4292{
4293 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4294 {
4295 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4296
4297 text_section ();
4298 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
4299 (unsigned) INSN_UID (insn));
4300 ASM_OUTPUT_LABEL (asm_out_file, label);
4301 }
4302}
4303
4304/* Output a marker (i.e. a label) for the absolute end of the generated code
4305 for a function definition. This gets called *after* the epilogue code
4306 has been generated. */
4307
4308void
4309dwarfout_end_epilogue ()
4310{
4311 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4312
4313 /* Output a label to mark the endpoint of the code generated for this
4314 function. */
4315
4316 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4317 ASM_OUTPUT_LABEL (asm_out_file, label);
4318}
4319
4320static void
4321shuffle_filename_entry (new_zeroth)
4322 register filename_entry *new_zeroth;
4323{
4324 filename_entry temp_entry;
4325 register filename_entry *limit_p;
4326 register filename_entry *move_p;
4327
4328 if (new_zeroth == &filename_table[0])
4329 return;
4330
4331 temp_entry = *new_zeroth;
4332
4333 /* Shift entries up in the table to make room at [0]. */
4334
4335 limit_p = &filename_table[0];
4336 for (move_p = new_zeroth; move_p > limit_p; move_p--)
4337 *move_p = *(move_p-1);
4338
4339 /* Install the found entry at [0]. */
4340
4341 filename_table[0] = temp_entry;
4342}
4343
4344/* Create a new (string) entry for the .debug_sfnames section. */
4345
4346static void
4347generate_new_sfname_entry ()
4348{
4349 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4350
4351 fputc ('\n', asm_out_file);
85595d1a 4352 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
340ccaab
TW
4353 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
4354 ASM_OUTPUT_LABEL (asm_out_file, label);
4355 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4356 filename_table[0].name
4357 ? filename_table[0].name
4358 : "");
85595d1a 4359 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4360}
4361
4362/* Lookup a filename (in the list of filenames that we know about here in
4363 dwarfout.c) and return its "index". The index of each (known) filename
4364 is just a unique number which is associated with only that one filename.
4365 We need such numbers for the sake of generating labels (in the
4366 .debug_sfnames section) and references to those unique labels (in the
4367 .debug_srcinfo and .debug_macinfo sections).
4368
4369 If the filename given as an argument is not found in our current list,
4370 add it to the list and assign it the next available unique index number.
4371
4372 Whatever we do (i.e. whether we find a pre-existing filename or add a new
4373 one), we shuffle the filename found (or added) up to the zeroth entry of
4374 our list of filenames (which is always searched linearly). We do this so
4375 as to optimize the most common case for these filename lookups within
4376 dwarfout.c. The most common case by far is the case where we call
4377 lookup_filename to lookup the very same filename that we did a lookup
4378 on the last time we called lookup_filename. We make sure that this
4379 common case is fast because such cases will constitute 99.9% of the
4380 lookups we ever do (in practice).
4381
4382 If we add a new filename entry to our table, we go ahead and generate
4383 the corresponding entry in the .debug_sfnames section right away.
4384 Doing so allows us to avoid tickling an assembler bug (present in some
4385 m68k assemblers) which yields assembly-time errors in cases where the
4386 difference of two label addresses is taken and where the two labels
4387 are in a section *other* than the one where the difference is being
4388 calculated, and where at least one of the two symbol references is a
4389 forward reference. (This bug could be tickled by our .debug_srcinfo
4390 entries if we don't output their corresponding .debug_sfnames entries
4391 before them.)
4392*/
4393
4394static unsigned
4395lookup_filename (file_name)
4396 char *file_name;
4397{
4398 register filename_entry *search_p;
4399 register filename_entry *limit_p = &filename_table[ft_entries];
4400
4401 for (search_p = filename_table; search_p < limit_p; search_p++)
4402 if (!strcmp (file_name, search_p->name))
4403 {
4404 /* When we get here, we have found the filename that we were
4405 looking for in the filename_table. Now we want to make sure
4406 that it gets moved to the zero'th entry in the table (if it
4407 is not already there) so that subsequent attempts to find the
4408 same filename will find it as quickly as possible. */
4409
4410 shuffle_filename_entry (search_p);
4411 return filename_table[0].number;
4412 }
4413
4414 /* We come here whenever we have a new filename which is not registered
4415 in the current table. Here we add it to the table. */
4416
4417 /* Prepare to add a new table entry by making sure there is enough space
4418 in the table to do so. If not, expand the current table. */
4419
4420 if (ft_entries == ft_entries_allocated)
4421 {
4422 ft_entries_allocated += FT_ENTRIES_INCREMENT;
4423 filename_table
4424 = (filename_entry *)
4425 xrealloc (filename_table,
4426 ft_entries_allocated * sizeof (filename_entry));
4427 }
4428
4429 /* Initially, add the new entry at the end of the filename table. */
4430
4431 filename_table[ft_entries].number = ft_entries;
4432 filename_table[ft_entries].name = xstrdup (file_name);
4433
4434 /* Shuffle the new entry into filename_table[0]. */
4435
4436 shuffle_filename_entry (&filename_table[ft_entries]);
4437
4438 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4439 generate_new_sfname_entry ();
4440
4441 ft_entries++;
4442 return filename_table[0].number;
4443}
4444
4445static void
4446generate_srcinfo_entry (line_entry_num, files_entry_num)
4447 unsigned line_entry_num;
4448 unsigned files_entry_num;
4449{
4450 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4451
4452 fputc ('\n', asm_out_file);
85595d1a 4453 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
340ccaab
TW
4454 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
4455 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
4456 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
4457 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
85595d1a 4458 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4459}
4460
4461void
4462dwarfout_line (filename, line)
4463 register char *filename;
4464 register unsigned line;
4465{
4466 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4467 {
4468 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4469 static unsigned last_line_entry_num = 0;
4470 static unsigned prev_file_entry_num = (unsigned) -1;
4471 register unsigned this_file_entry_num = lookup_filename (filename);
4472
4473 text_section ();
4474 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
4475 ASM_OUTPUT_LABEL (asm_out_file, label);
4476
4477 fputc ('\n', asm_out_file);
85595d1a 4478 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
340ccaab
TW
4479
4480 if (this_file_entry_num != prev_file_entry_num)
4481 {
4482 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
4483
4484 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
4485 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
4486 }
4487
4488 {
4489 register char *tail = strrchr (filename, '/');
4490
4491 if (tail != NULL)
4492 filename = tail;
4493 }
4494
2e494f70 4495 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
340ccaab
TW
4496 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
4497 filename, line);
4498 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
4499 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
85595d1a 4500 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4501
4502 if (this_file_entry_num != prev_file_entry_num)
4503 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
4504 prev_file_entry_num = this_file_entry_num;
4505 }
4506}
4507
4508/* Generate an entry in the .debug_macinfo section. */
4509
4510static void
4511generate_macinfo_entry (type_and_offset, string)
4512 register char *type_and_offset;
4513 register char *string;
4514{
4515 fputc ('\n', asm_out_file);
85595d1a 4516 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
2e494f70 4517 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
340ccaab 4518 ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
85595d1a 4519 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4520}
4521
4522void
4523dwarfout_start_new_source_file (filename)
4524 register char *filename;
4525{
4526 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4527 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
4528
4529 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
4530 sprintf (type_and_offset, "0x%08x+%s-%s",
4531 ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL);
4532 generate_macinfo_entry (type_and_offset, "");
4533}
4534
4535void
4536dwarfout_resume_previous_source_file (lineno)
4537 register unsigned lineno;
4538{
4539 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4540
4541 sprintf (type_and_offset, "0x%08x+%u",
4542 ((unsigned) MACINFO_resume << 24), lineno);
4543 generate_macinfo_entry (type_and_offset, "");
4544}
4545
4546/* Called from check_newline in c-parse.y. The `buffer' parameter
4547 contains the tail part of the directive line, i.e. the part which
4548 is past the initial whitespace, #, whitespace, directive-name,
4549 whitespace part. */
4550
4551void
4552dwarfout_define (lineno, buffer)
4553 register unsigned lineno;
4554 register char *buffer;
4555{
4556 static int initialized = 0;
4557 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4558
4559 if (!initialized)
4560 {
4561 dwarfout_start_new_source_file (primary_filename);
4562 initialized = 1;
4563 }
4564 sprintf (type_and_offset, "0x%08x+%u",
4565 ((unsigned) MACINFO_define << 24), lineno);
4566 generate_macinfo_entry (type_and_offset, buffer);
4567}
4568
4569/* Called from check_newline in c-parse.y. The `buffer' parameter
4570 contains the tail part of the directive line, i.e. the part which
4571 is past the initial whitespace, #, whitespace, directive-name,
4572 whitespace part. */
4573
4574void
4575dwarfout_undef (lineno, buffer)
4576 register unsigned lineno;
4577 register char *buffer;
4578{
4579 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4580
4581 sprintf (type_and_offset, "0x%08x+%u",
4582 ((unsigned) MACINFO_undef << 24), lineno);
4583 generate_macinfo_entry (type_and_offset, buffer);
4584}
4585
4586/* Set up for Dwarf output at the start of compilation. */
4587
4588void
4589dwarfout_init (asm_out_file, main_input_filename)
4590 register FILE *asm_out_file;
4591 register char *main_input_filename;
4592{
4593 /* Remember the name of the primary input file. */
4594
4595 primary_filename = main_input_filename;
4596
4597 /* Allocate the initial hunk of the pending_sibling_stack. */
4598
4599 pending_sibling_stack
4600 = (unsigned *)
4601 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
4602 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
4603 pending_siblings = 1;
4604
4605 /* Allocate the initial hunk of the filename_table. */
4606
4607 filename_table
4608 = (filename_entry *)
4609 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
4610 ft_entries_allocated = FT_ENTRIES_INCREMENT;
4611 ft_entries = 0;
4612
4613 /* Allocate the initial hunk of the pending_types_list. */
4614
4615 pending_types_list
4616 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
4617 pending_types_allocated = PENDING_TYPES_INCREMENT;
4618 pending_types = 0;
4619
4620 /* Create an artificial RECORD_TYPE node which we can use in our hack
4621 to get the DIEs representing types of formal parameters to come out
4622 only *after* the DIEs for the formal parameters themselves. */
4623
4624 fake_containing_scope = make_node (RECORD_TYPE);
4625
4626 /* Output a starting label for the .text section. */
4627
4628 fputc ('\n', asm_out_file);
85595d1a 4629 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
340ccaab 4630 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
85595d1a 4631 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4632
4633 /* Output a starting label for the .data section. */
4634
4635 fputc ('\n', asm_out_file);
85595d1a 4636 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
340ccaab 4637 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
85595d1a 4638 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4639
4640 /* Output a starting label for the .data1 section. */
4641
4642 fputc ('\n', asm_out_file);
85595d1a 4643 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
340ccaab 4644 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
85595d1a 4645 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4646
4647 /* Output a starting label for the .rodata section. */
4648
4649 fputc ('\n', asm_out_file);
85595d1a 4650 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
340ccaab 4651 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
85595d1a 4652 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4653
4654 /* Output a starting label for the .rodata1 section. */
4655
4656 fputc ('\n', asm_out_file);
85595d1a 4657 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
340ccaab 4658 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
85595d1a 4659 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4660
4661 /* Output a starting label for the .bss section. */
4662
4663 fputc ('\n', asm_out_file);
85595d1a 4664 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
340ccaab 4665 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
85595d1a 4666 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4667
4668 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4669 {
4670 /* Output a starting label and an initial (compilation directory)
4671 entry for the .debug_sfnames section. The starting label will be
4672 referenced by the initial entry in the .debug_srcinfo section. */
4673
4674 fputc ('\n', asm_out_file);
85595d1a 4675 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
340ccaab
TW
4676 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
4677 {
2e494f70
RS
4678 register char *pwd = getpwd ();
4679 register unsigned len = strlen (pwd);
4680 register char *dirname = (char *) xmalloc (len + 2);
340ccaab 4681
2e494f70
RS
4682 strcpy (dirname, pwd);
4683 strcpy (dirname + len, "/");
340ccaab
TW
4684 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
4685 free (dirname);
4686 }
85595d1a 4687 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4688
4689 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4690 {
4691 /* Output a starting label for the .debug_macinfo section. This
4692 label will be referenced by the AT_mac_info attribute in the
4693 TAG_compile_unit DIE. */
4694
4695 fputc ('\n', asm_out_file);
85595d1a 4696 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
340ccaab 4697 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
85595d1a 4698 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4699 }
4700
4701 /* Generate the initial entry for the .line section. */
4702
4703 fputc ('\n', asm_out_file);
85595d1a 4704 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
340ccaab
TW
4705 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
4706 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
4707 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
85595d1a 4708 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4709
4710 /* Generate the initial entry for the .debug_srcinfo section. */
4711
4712 fputc ('\n', asm_out_file);
85595d1a 4713 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
340ccaab
TW
4714 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
4715 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
4716 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
4717 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
4718 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
4719#ifdef DWARF_TIMESTAMPS
4720 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
4721#else
4722 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
4723#endif
85595d1a 4724 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4725
4726 /* Generate the initial entry for the .debug_pubnames section. */
4727
4728 fputc ('\n', asm_out_file);
85595d1a 4729 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab 4730 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
85595d1a 4731 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4732
4733 /* Generate the initial entry for the .debug_aranges section. */
4734
4735 fputc ('\n', asm_out_file);
85595d1a 4736 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
340ccaab 4737 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
85595d1a 4738 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4739 }
4740
4741 /* Setup first DIE number == 1. */
4742 NEXT_DIE_NUM = next_unused_dienum++;
4743
4744 /* Generate the initial DIE for the .debug section. Note that the
4745 (string) value given in the AT_name attribute of the TAG_compile_unit
4746 DIE will (typically) be a relative pathname and that this pathname
4747 should be taken as being relative to the directory from which the
4748 compiler was invoked when the given (base) source file was compiled. */
4749
4750 fputc ('\n', asm_out_file);
85595d1a 4751 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
340ccaab
TW
4752 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
4753 output_die (output_compile_unit_die, main_input_filename);
85595d1a 4754 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4755
4756 fputc ('\n', asm_out_file);
4757}
4758
4759/* Output stuff that dwarf requires at the end of every file. */
4760
4761void
4762dwarfout_finish ()
4763{
4764 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4765
4766 fputc ('\n', asm_out_file);
85595d1a 4767 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
340ccaab
TW
4768
4769 /* Mark the end of the chain of siblings which represent all file-scope
4770 declarations in this compilation unit. */
4771
4772 /* The (null) DIE which represents the terminator for the (sibling linked)
4773 list of file-scope items is *special*. Normally, we would just call
4774 end_sibling_chain at this point in order to output a word with the
4775 value `4' and that word would act as the terminator for the list of
4776 DIEs describing file-scope items. Unfortunately, if we were to simply
4777 do that, the label that would follow this DIE in the .debug section
4778 (i.e. `..D2') would *not* be properly aligned (as it must be on some
4779 machines) to a 4 byte boundary.
4780
4781 In order to force the label `..D2' to get aligned to a 4 byte boundary,
4782 the trick used is to insert extra (otherwise useless) padding bytes
6dc42e49 4783 into the (null) DIE that we know must precede the ..D2 label in the
340ccaab
TW
4784 .debug section. The amount of padding required can be anywhere between
4785 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
4786 with the padding) would normally contain the value 4, but now it will
4787 also have to include the padding bytes, so it will instead have some
4788 value in the range 4..7.
4789
4790 Fortunately, the rules of Dwarf say that any DIE whose length word
4791 contains *any* value less than 8 should be treated as a null DIE, so
4792 this trick works out nicely. Clever, eh? Don't give me any credit
4793 (or blame). I didn't think of this scheme. I just conformed to it.
4794 */
4795
4796 output_die (output_padded_null_die, (void *)0);
4797 dienum_pop ();
4798
4799 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
4800 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
85595d1a 4801 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4802
4803 /* Output a terminator label for the .text section. */
4804
4805 fputc ('\n', asm_out_file);
85595d1a 4806 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
340ccaab 4807 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
85595d1a 4808 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4809
4810 /* Output a terminator label for the .data section. */
4811
4812 fputc ('\n', asm_out_file);
85595d1a 4813 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
340ccaab 4814 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
85595d1a 4815 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4816
4817 /* Output a terminator label for the .data1 section. */
4818
4819 fputc ('\n', asm_out_file);
85595d1a 4820 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
340ccaab 4821 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
85595d1a 4822 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4823
4824 /* Output a terminator label for the .rodata section. */
4825
4826 fputc ('\n', asm_out_file);
85595d1a 4827 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
340ccaab 4828 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
85595d1a 4829 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4830
4831 /* Output a terminator label for the .rodata1 section. */
4832
4833 fputc ('\n', asm_out_file);
85595d1a 4834 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
340ccaab 4835 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
85595d1a 4836 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4837
4838 /* Output a terminator label for the .bss section. */
4839
4840 fputc ('\n', asm_out_file);
85595d1a 4841 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
340ccaab 4842 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
85595d1a 4843 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4844
4845 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4846 {
4847 /* Output a terminating entry for the .line section. */
4848
4849 fputc ('\n', asm_out_file);
85595d1a 4850 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
340ccaab
TW
4851 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
4852 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4853 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
4854 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
4855 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
85595d1a 4856 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4857
4858 /* Output a terminating entry for the .debug_srcinfo section. */
4859
4860 fputc ('\n', asm_out_file);
85595d1a 4861 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
340ccaab
TW
4862 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
4863 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
4864 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
85595d1a 4865 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4866
4867 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4868 {
4869 /* Output terminating entries for the .debug_macinfo section. */
4870
4871 dwarfout_resume_previous_source_file (0);
4872
4873 fputc ('\n', asm_out_file);
85595d1a 4874 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
340ccaab
TW
4875 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4876 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
85595d1a 4877 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4878 }
4879
4880 /* Generate the terminating entry for the .debug_pubnames section. */
4881
4882 fputc ('\n', asm_out_file);
85595d1a 4883 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab
TW
4884 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4885 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
85595d1a 4886 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4887
4888 /* Generate the terminating entries for the .debug_aranges section.
4889
4890 Note that we want to do this only *after* we have output the end
4891 labels (for the various program sections) which we are going to
4892 refer to here. This allows us to work around a bug in the m68k
4893 svr4 assembler. That assembler gives bogus assembly-time errors
4894 if (within any given section) you try to take the difference of
4895 two relocatable symbols, both of which are located within some
4896 other section, and if one (or both?) of the symbols involved is
4897 being forward-referenced. By generating the .debug_aranges
4898 entries at this late point in the assembly output, we skirt the
4899 issue simply by avoiding forward-references.
4900 */
4901
4902 fputc ('\n', asm_out_file);
85595d1a 4903 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
340ccaab
TW
4904
4905 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
4906 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
4907
4908 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
4909 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
4910
4911 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
4912 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
4913 DATA1_BEGIN_LABEL);
4914
4915 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
4916 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
4917 RODATA_BEGIN_LABEL);
4918
4919 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
4920 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
4921 RODATA1_BEGIN_LABEL);
4922
4923 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
4924 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
4925
4926 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4927 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4928
85595d1a 4929 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4930 }
4931}
4932
4933#endif /* DWARF_DEBUGGING_INFO */
This page took 0.538587 seconds and 5 git commands to generate.