]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/dwarf2out.c
m32r.md, [...]: Add some comments regarding use of dead_or_set_p.
[thirdparty/gcc.git] / gcc / dwarf2out.c
CommitLineData
a3f97cbb 1/* Output Dwarf2 format symbol table information from the GNU C compiler.
fa1610e9 2 Copyright (C) 1992, 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
e9a25f70
JL
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
469ac993 5 Extensively modified by Jason Merrill (jason@cygnus.com).
a3f97cbb
JW
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
3f76745e
JM
23/* The first part of this file deals with the DWARF 2 frame unwind
24 information, which is also used by the GCC efficient exception handling
25 mechanism. The second part, controlled only by an #ifdef
26 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
27 information. */
28
0021b564
JM
29#include "config.h"
30#include "defaults.h"
a3f97cbb 31#include <stdio.h>
a3f97cbb
JW
32#include "tree.h"
33#include "flags.h"
34#include "rtl.h"
35#include "hard-reg-set.h"
36#include "regs.h"
37#include "insn-config.h"
38#include "reload.h"
39#include "output.h"
71dfc51f 40#include "expr.h"
3f76745e 41#include "except.h"
a7cc7f29 42#include "dwarf2.h"
a3f97cbb 43
c85f7c16
JL
44/* We cannot use <assert.h> in GCC source, since that would include
45 GCC's assert.h, which may not be compatible with the host compiler. */
46#undef assert
47#ifdef NDEBUG
48# define assert(e)
49#else
50# define assert(e) do { if (! (e)) abort (); } while (0)
51#endif
52
0021b564
JM
53/* Decide whether we want to emit frame unwind information for the current
54 translation unit. */
55
56int
57dwarf2out_do_frame ()
58{
59 return (write_symbols == DWARF2_DEBUG
60#ifdef DWARF2_UNWIND_INFO
61 || (flag_exceptions && ! exceptions_via_longjmp)
62#endif
63 );
64}
65
66#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
67
71dfc51f
RK
68#ifndef __GNUC__
69#define inline
a3f97cbb
JW
70#endif
71
eaf95893
RK
72/* How to start an assembler comment. */
73#ifndef ASM_COMMENT_START
74#define ASM_COMMENT_START ";#"
75#endif
76
a3f97cbb
JW
77typedef struct dw_cfi_struct *dw_cfi_ref;
78typedef struct dw_fde_struct *dw_fde_ref;
79typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
a3f97cbb
JW
80
81/* Call frames are described using a sequence of Call Frame
82 Information instructions. The register number, offset
83 and address fields are provided as possible operands;
84 their use is selected by the opcode field. */
71dfc51f 85
a3f97cbb 86typedef union dw_cfi_oprnd_struct
71dfc51f
RK
87{
88 unsigned long dw_cfi_reg_num;
89 long int dw_cfi_offset;
90 char *dw_cfi_addr;
91}
a3f97cbb
JW
92dw_cfi_oprnd;
93
94typedef struct dw_cfi_struct
71dfc51f
RK
95{
96 dw_cfi_ref dw_cfi_next;
97 enum dwarf_call_frame_info dw_cfi_opc;
98 dw_cfi_oprnd dw_cfi_oprnd1;
99 dw_cfi_oprnd dw_cfi_oprnd2;
100}
a3f97cbb
JW
101dw_cfi_node;
102
103/* All call frame descriptions (FDE's) in the GCC generated DWARF
4b674448 104 refer to a single Common Information Entry (CIE), defined at
a3f97cbb
JW
105 the beginning of the .debug_frame section. This used of a single
106 CIE obviates the need to keep track of multiple CIE's
107 in the DWARF generation routines below. */
71dfc51f 108
a3f97cbb 109typedef struct dw_fde_struct
71dfc51f 110{
71dfc51f
RK
111 char *dw_fde_begin;
112 char *dw_fde_current_label;
113 char *dw_fde_end;
114 dw_cfi_ref dw_fde_cfi;
115}
a3f97cbb
JW
116dw_fde_node;
117
a3f97cbb
JW
118/* Maximum size (in bytes) of an artificially generated label. */
119#define MAX_ARTIFICIAL_LABEL_BYTES 30
120
121/* Make sure we know the sizes of the various types dwarf can describe. These
122 are only defaults. If the sizes are different for your target, you should
123 override these values by defining the appropriate symbols in your tm.h
124 file. */
71dfc51f 125
a3f97cbb
JW
126#ifndef CHAR_TYPE_SIZE
127#define CHAR_TYPE_SIZE BITS_PER_UNIT
128#endif
a3f97cbb 129#ifndef PTR_SIZE
a9d38797 130#define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
a3f97cbb
JW
131#endif
132
7e23cb16
JM
133/* The size in bytes of a DWARF field indicating an offset or length
134 relative to a debug info section, specified to be 4 bytes in the DWARF-2
135 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
71dfc51f 136
7e23cb16
JM
137#ifndef DWARF_OFFSET_SIZE
138#define DWARF_OFFSET_SIZE 4
139#endif
140
9a666dda
JM
141#define DWARF_VERSION 2
142
7e23cb16
JM
143/* Round SIZE up to the nearest BOUNDARY. */
144#define DWARF_ROUND(SIZE,BOUNDARY) \
145 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
a3f97cbb 146
a3f97cbb 147/* Offsets recorded in opcodes are a multiple of this alignment factor. */
469ac993
JM
148#ifdef STACK_GROWS_DOWNWARD
149#define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
150#else
151#define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
152#endif
a3f97cbb 153
3f76745e
JM
154/* A pointer to the base of a table that contains frame description
155 information for each routine. */
156static dw_fde_ref fde_table;
a3f97cbb 157
3f76745e
JM
158/* Number of elements currently allocated for fde_table. */
159static unsigned fde_table_allocated;
a94dbf2c 160
3f76745e
JM
161/* Number of elements in fde_table currently in use. */
162static unsigned fde_table_in_use;
a3f97cbb 163
3f76745e
JM
164/* Size (in elements) of increments by which we may expand the
165 fde_table. */
166#define FDE_TABLE_INCREMENT 256
a3f97cbb 167
a94dbf2c
JM
168/* A list of call frame insns for the CIE. */
169static dw_cfi_ref cie_cfi_head;
170
a3f97cbb
JW
171/* The number of the current function definition for which debugging
172 information is being generated. These numbers range from 1 up to the
173 maximum number of function definitions contained within the current
174 compilation unit. These numbers are used to create unique label id's
175 unique to each function definition. */
4f988ea2 176static unsigned current_funcdef_number = 0;
a3f97cbb
JW
177
178/* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
179 attribute that accelerates the lookup of the FDE associated
180 with the subprogram. This variable holds the table index of the FDE
181 associated with the current function (body) definition. */
182static unsigned current_funcdef_fde;
183
a3f97cbb 184/* Forward declarations for functions defined in this file. */
71dfc51f
RK
185
186static char *stripattributes PROTO((char *));
3f76745e
JM
187static char *dwarf_cfi_name PROTO((unsigned));
188static dw_cfi_ref new_cfi PROTO((void));
189static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref));
71dfc51f
RK
190static unsigned long size_of_uleb128 PROTO((unsigned long));
191static unsigned long size_of_sleb128 PROTO((long));
71dfc51f
RK
192static void output_uleb128 PROTO((unsigned long));
193static void output_sleb128 PROTO((long));
71dfc51f
RK
194static void add_fde_cfi PROTO((char *, dw_cfi_ref));
195static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *,
196 long *));
197static void lookup_cfa PROTO((unsigned long *, long *));
198static void reg_save PROTO((char *, unsigned, unsigned,
199 long));
200static void initial_return_save PROTO((rtx));
71dfc51f 201static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref));
3f76745e 202static void output_call_frame_info PROTO((int));
71dfc51f 203static unsigned reg_number PROTO((rtx));
a3f97cbb
JW
204
205/* Definitions of defaults for assembler-dependent names of various
206 pseudo-ops and section names.
207 Theses may be overridden in the tm.h file (if necessary) for a particular
208 assembler. */
71dfc51f 209
0021b564 210#ifdef OBJECT_FORMAT_ELF
a3f97cbb
JW
211#ifndef UNALIGNED_SHORT_ASM_OP
212#define UNALIGNED_SHORT_ASM_OP ".2byte"
213#endif
214#ifndef UNALIGNED_INT_ASM_OP
215#define UNALIGNED_INT_ASM_OP ".4byte"
216#endif
7e23cb16
JM
217#ifndef UNALIGNED_DOUBLE_INT_ASM_OP
218#define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
219#endif
0021b564
JM
220#endif /* OBJECT_FORMAT_ELF */
221
a3f97cbb
JW
222#ifndef ASM_BYTE_OP
223#define ASM_BYTE_OP ".byte"
224#endif
225
7e23cb16
JM
226/* Data and reference forms for relocatable data. */
227#define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
228#define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
229
a3f97cbb
JW
230/* Pseudo-op for defining a new section. */
231#ifndef SECTION_ASM_OP
232#define SECTION_ASM_OP ".section"
233#endif
234
235/* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
236 print the SECTION_ASM_OP and the section name. The default here works for
237 almost all svr4 assemblers, except for the sparc, where the section name
238 must be enclosed in double quotes. (See sparcv4.h). */
239#ifndef SECTION_FORMAT
c53aa195
JM
240#ifdef PUSHSECTION_FORMAT
241#define SECTION_FORMAT PUSHSECTION_FORMAT
242#else
243#define SECTION_FORMAT "\t%s\t%s\n"
244#endif
a3f97cbb
JW
245#endif
246
a3f97cbb
JW
247#ifndef FRAME_SECTION
248#define FRAME_SECTION ".debug_frame"
249#endif
a3f97cbb 250
5c90448c
JM
251#ifndef FUNC_BEGIN_LABEL
252#define FUNC_BEGIN_LABEL "LFB"
a3f97cbb 253#endif
5c90448c
JM
254#ifndef FUNC_END_LABEL
255#define FUNC_END_LABEL "LFE"
a3f97cbb 256#endif
a6ab3aad
JM
257#define CIE_AFTER_SIZE_LABEL "LSCIE"
258#define CIE_END_LABEL "LECIE"
2ed2af28 259#define CIE_LENGTH_LABEL "LLCIE"
a6ab3aad
JM
260#define FDE_AFTER_SIZE_LABEL "LSFDE"
261#define FDE_END_LABEL "LEFDE"
2ed2af28 262#define FDE_LENGTH_LABEL "LLFDE"
a3f97cbb 263
a3f97cbb
JW
264/* Definitions of defaults for various types of primitive assembly language
265 output operations. These may be overridden from within the tm.h file,
956d6950 266 but typically, that is unnecessary. */
71dfc51f 267
a3f97cbb
JW
268#ifndef ASM_OUTPUT_SECTION
269#define ASM_OUTPUT_SECTION(FILE, SECTION) \
270 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
271#endif
272
0021b564
JM
273#ifndef ASM_OUTPUT_DWARF_DATA1
274#define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
275 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
276#endif
277
bb727b5a
JM
278#ifndef ASM_OUTPUT_DWARF_DELTA1
279#define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
280 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
281 assemble_name (FILE, LABEL1); \
282 fprintf (FILE, "-"); \
283 assemble_name (FILE, LABEL2); \
284 } while (0)
285#endif
286
0021b564
JM
287#ifdef UNALIGNED_INT_ASM_OP
288
289#ifndef UNALIGNED_OFFSET_ASM_OP
290#define UNALIGNED_OFFSET_ASM_OP \
291 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
292#endif
293
294#ifndef UNALIGNED_WORD_ASM_OP
295#define UNALIGNED_WORD_ASM_OP \
296 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
297#endif
298
a3f97cbb
JW
299#ifndef ASM_OUTPUT_DWARF_DELTA2
300#define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
301 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
302 assemble_name (FILE, LABEL1); \
303 fprintf (FILE, "-"); \
304 assemble_name (FILE, LABEL2); \
305 } while (0)
306#endif
307
308#ifndef ASM_OUTPUT_DWARF_DELTA4
309#define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
310 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
311 assemble_name (FILE, LABEL1); \
312 fprintf (FILE, "-"); \
313 assemble_name (FILE, LABEL2); \
314 } while (0)
315#endif
316
7e23cb16
JM
317#ifndef ASM_OUTPUT_DWARF_DELTA
318#define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
319 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
320 assemble_name (FILE, LABEL1); \
321 fprintf (FILE, "-"); \
322 assemble_name (FILE, LABEL2); \
323 } while (0)
324#endif
325
326#ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
327#define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
328 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
329 assemble_name (FILE, LABEL1); \
330 fprintf (FILE, "-"); \
331 assemble_name (FILE, LABEL2); \
332 } while (0)
333#endif
334
a3f97cbb
JW
335#ifndef ASM_OUTPUT_DWARF_ADDR
336#define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
7e23cb16 337 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
a3f97cbb
JW
338 assemble_name (FILE, LABEL); \
339 } while (0)
340#endif
341
342#ifndef ASM_OUTPUT_DWARF_ADDR_CONST
343#define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
7e23cb16
JM
344 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
345#endif
346
7bb9fb0e
JM
347#ifndef ASM_OUTPUT_DWARF_OFFSET4
348#define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
349 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
350 assemble_name (FILE, LABEL); \
351 } while (0)
352#endif
353
7e23cb16
JM
354#ifndef ASM_OUTPUT_DWARF_OFFSET
355#define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
356 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
357 assemble_name (FILE, LABEL); \
358 } while (0)
a3f97cbb
JW
359#endif
360
a3f97cbb
JW
361#ifndef ASM_OUTPUT_DWARF_DATA2
362#define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
363 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
364#endif
365
366#ifndef ASM_OUTPUT_DWARF_DATA4
367#define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
368 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
369#endif
370
7e23cb16
JM
371#ifndef ASM_OUTPUT_DWARF_DATA
372#define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
373 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
374 (unsigned long) VALUE)
375#endif
376
377#ifndef ASM_OUTPUT_DWARF_ADDR_DATA
378#define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
379 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
380 (unsigned long) VALUE)
381#endif
382
a3f97cbb
JW
383#ifndef ASM_OUTPUT_DWARF_DATA8
384#define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
385 do { \
386 if (WORDS_BIG_ENDIAN) \
387 { \
388 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
389 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
390 } \
391 else \
392 { \
393 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
394 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
395 } \
396 } while (0)
397#endif
398
0021b564
JM
399#else /* UNALIGNED_INT_ASM_OP */
400
401/* We don't have unaligned support, let's hope the normal output works for
402 .debug_frame. */
403
404#define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
38a448ca 405 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1)
0021b564 406
7bb9fb0e 407#define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
38a448ca 408 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
7bb9fb0e 409
0021b564 410#define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
38a448ca 411 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
0021b564
JM
412
413#define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
38a448ca
RH
414 assemble_integer (gen_rtx_MINUS (HImode, \
415 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
416 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
0021b564
JM
417 2, 1)
418
419#define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
38a448ca
RH
420 assemble_integer (gen_rtx_MINUS (SImode, \
421 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
422 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
0021b564
JM
423 4, 1)
424
425#define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
38a448ca
RH
426 assemble_integer (gen_rtx_MINUS (Pmode, \
427 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
428 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
0021b564
JM
429 PTR_SIZE, 1)
430
431#define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
432 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
433
434#define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
435 assemble_integer (GEN_INT (VALUE), 4, 1)
436
437#endif /* UNALIGNED_INT_ASM_OP */
438
2ed2af28
PDM
439#ifdef SET_ASM_OP
440#ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
7bb9fb0e
JM
441#define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
442 do { \
443 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
444 assemble_name (FILE, SY); \
445 fputc (',', FILE); \
446 assemble_name (FILE, HI); \
447 fputc ('-', FILE); \
448 assemble_name (FILE, LO); \
449 } while (0)
2ed2af28
PDM
450#endif
451#endif /* SET_ASM_OP */
452
a6ab3aad 453/* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
2ed2af28 454 newline is produced. When flag_debug_asm is asserted, we add commentary
a6ab3aad
JM
455 at the end of the line, so we must avoid output of a newline here. */
456#ifndef ASM_OUTPUT_DWARF_STRING
457#define ASM_OUTPUT_DWARF_STRING(FILE,P) \
458 do { \
459 register int slen = strlen(P); \
460 register char *p = (P); \
461 register int i; \
462 fprintf (FILE, "\t.ascii \""); \
463 for (i = 0; i < slen; i++) \
464 { \
465 register int c = p[i]; \
466 if (c == '\"' || c == '\\') \
467 putc ('\\', FILE); \
468 if (c >= ' ' && c < 0177) \
469 putc (c, FILE); \
470 else \
471 { \
472 fprintf (FILE, "\\%o", c); \
473 } \
474 } \
475 fprintf (FILE, "\\0\""); \
476 } \
477 while (0)
478#endif
479
c8cc5c4a 480/* The DWARF 2 CFA column which tracks the return address. Normally this
a94dbf2c
JM
481 is the column for PC, or the first column after all of the hard
482 registers. */
c8cc5c4a 483#ifndef DWARF_FRAME_RETURN_COLUMN
a94dbf2c
JM
484#ifdef PC_REGNUM
485#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
486#else
466446b0 487#define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
a94dbf2c 488#endif
c8cc5c4a
JM
489#endif
490
491/* The mapping from gcc register number to DWARF 2 CFA column number. By
469ac993 492 default, we just provide columns for all registers. */
c8cc5c4a 493#ifndef DWARF_FRAME_REGNUM
469ac993 494#define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
c8cc5c4a 495#endif
3f76745e 496
0021b564
JM
497/* Hook used by __throw. */
498
499rtx
500expand_builtin_dwarf_fp_regnum ()
501{
502 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
503}
504
a6ab3aad
JM
505/* The offset from the incoming value of %sp to the top of the stack frame
506 for the current function. */
507#ifndef INCOMING_FRAME_SP_OFFSET
508#define INCOMING_FRAME_SP_OFFSET 0
509#endif
510
71dfc51f 511/* Return a pointer to a copy of the section string name S with all
a3f97cbb 512 attributes stripped off. */
71dfc51f
RK
513
514static inline char *
a3f97cbb 515stripattributes (s)
71dfc51f 516 char *s;
a3f97cbb 517{
71dfc51f
RK
518 char *stripped = xstrdup (s);
519 char *p = stripped;
520
a3f97cbb
JW
521 while (*p && *p != ',')
522 p++;
71dfc51f 523
a3f97cbb
JW
524 *p = '\0';
525 return stripped;
526}
527
3f76745e 528/* Return the register number described by a given RTL node. */
71dfc51f 529
3f76745e
JM
530static unsigned
531reg_number (rtl)
532 register rtx rtl;
a3f97cbb 533{
3f76745e 534 register unsigned regno = REGNO (rtl);
a3f97cbb 535
3f76745e 536 if (regno >= FIRST_PSEUDO_REGISTER)
a3f97cbb 537 {
3f76745e
JM
538 warning ("internal regno botch: regno = %d\n", regno);
539 regno = 0;
540 }
a3f97cbb 541
3f76745e
JM
542 regno = DBX_REGISTER_NUMBER (regno);
543 return regno;
544}
a3f97cbb 545
2f3ca9e7
JM
546struct reg_size_range
547{
548 int beg;
549 int end;
550 int size;
551};
552
553/* Given a register number in REG_TREE, return an rtx for its size in bytes.
554 We do this in kind of a roundabout way, by building up a list of
555 register size ranges and seeing where our register falls in one of those
556 ranges. We need to do it this way because REG_TREE is not a constant,
557 and the target macros were not designed to make this task easy. */
558
559rtx
560expand_builtin_dwarf_reg_size (reg_tree, target)
561 tree reg_tree;
562 rtx target;
563{
31c8581d 564 enum machine_mode mode;
d1485032 565 int size;
2f3ca9e7
JM
566 struct reg_size_range ranges[5];
567 tree t, t2;
568
d1485032
JM
569 int i = 0;
570 int n_ranges = 0;
571 int last_size = -1;
2f3ca9e7 572
d1485032 573 for (; i < FIRST_PSEUDO_REGISTER; ++i)
2f3ca9e7 574 {
d1485032
JM
575 /* The return address is out of order on the MIPS, and we don't use
576 copy_reg for it anyway, so we don't care here how large it is. */
577 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
578 continue;
579
31c8581d
JW
580 mode = reg_raw_mode[i];
581 /* CCmode is arbitrarily given a size of 4 bytes. It is more useful
582 to use the same size as word_mode, since that reduces the number
583 of ranges we need. It should not matter, since the result should
584 never be used for a condition code register anyways. */
585 if (mode == CCmode)
586 mode = word_mode;
587 size = GET_MODE_SIZE (mode);
588
d1485032 589 if (size != last_size)
2f3ca9e7 590 {
2f3ca9e7 591 ranges[n_ranges].beg = i;
d1485032 592 ranges[n_ranges].size = last_size = GET_MODE_SIZE (reg_raw_mode[i]);
2f3ca9e7 593 ++n_ranges;
3a88cbd1
JL
594 if (n_ranges >= 5)
595 abort ();
2f3ca9e7 596 }
d1485032 597 ranges[n_ranges-1].end = i;
2f3ca9e7 598 }
2f3ca9e7
JM
599
600 /* The usual case: fp regs surrounded by general regs. */
601 if (n_ranges == 3 && ranges[0].size == ranges[2].size)
602 {
3a88cbd1
JL
603 if ((DWARF_FRAME_REGNUM (ranges[1].end)
604 - DWARF_FRAME_REGNUM (ranges[1].beg))
605 != ranges[1].end - ranges[1].beg)
606 abort ();
2f3ca9e7
JM
607 t = fold (build (GE_EXPR, integer_type_node, reg_tree,
608 build_int_2 (DWARF_FRAME_REGNUM (ranges[1].beg), 0)));
609 t2 = fold (build (LE_EXPR, integer_type_node, reg_tree,
610 build_int_2 (DWARF_FRAME_REGNUM (ranges[1].end), 0)));
611 t = fold (build (TRUTH_ANDIF_EXPR, integer_type_node, t, t2));
612 t = fold (build (COND_EXPR, integer_type_node, t,
613 build_int_2 (ranges[1].size, 0),
614 build_int_2 (ranges[0].size, 0)));
615 }
616 else
617 {
618 --n_ranges;
619 t = build_int_2 (ranges[n_ranges].size, 0);
620 size = DWARF_FRAME_REGNUM (ranges[n_ranges].beg);
621 for (; n_ranges--; )
622 {
3a88cbd1
JL
623 if ((DWARF_FRAME_REGNUM (ranges[n_ranges].end)
624 - DWARF_FRAME_REGNUM (ranges[n_ranges].beg))
625 != ranges[n_ranges].end - ranges[n_ranges].beg)
626 abort ();
627 if (DWARF_FRAME_REGNUM (ranges[n_ranges].beg) >= size)
628 abort ();
2f3ca9e7
JM
629 size = DWARF_FRAME_REGNUM (ranges[n_ranges].beg);
630 t2 = fold (build (LE_EXPR, integer_type_node, reg_tree,
631 build_int_2 (DWARF_FRAME_REGNUM
632 (ranges[n_ranges].end), 0)));
633 t = fold (build (COND_EXPR, integer_type_node, t2,
634 build_int_2 (ranges[n_ranges].size, 0), t));
635 }
636 }
637 return expand_expr (t, target, Pmode, 0);
638}
639
3f76745e 640/* Convert a DWARF call frame info. operation to its string name */
a3f97cbb 641
3f76745e
JM
642static char *
643dwarf_cfi_name (cfi_opc)
644 register unsigned cfi_opc;
645{
646 switch (cfi_opc)
647 {
648 case DW_CFA_advance_loc:
649 return "DW_CFA_advance_loc";
650 case DW_CFA_offset:
651 return "DW_CFA_offset";
652 case DW_CFA_restore:
653 return "DW_CFA_restore";
654 case DW_CFA_nop:
655 return "DW_CFA_nop";
656 case DW_CFA_set_loc:
657 return "DW_CFA_set_loc";
658 case DW_CFA_advance_loc1:
659 return "DW_CFA_advance_loc1";
660 case DW_CFA_advance_loc2:
661 return "DW_CFA_advance_loc2";
662 case DW_CFA_advance_loc4:
663 return "DW_CFA_advance_loc4";
664 case DW_CFA_offset_extended:
665 return "DW_CFA_offset_extended";
666 case DW_CFA_restore_extended:
667 return "DW_CFA_restore_extended";
668 case DW_CFA_undefined:
669 return "DW_CFA_undefined";
670 case DW_CFA_same_value:
671 return "DW_CFA_same_value";
672 case DW_CFA_register:
673 return "DW_CFA_register";
674 case DW_CFA_remember_state:
675 return "DW_CFA_remember_state";
676 case DW_CFA_restore_state:
677 return "DW_CFA_restore_state";
678 case DW_CFA_def_cfa:
679 return "DW_CFA_def_cfa";
680 case DW_CFA_def_cfa_register:
681 return "DW_CFA_def_cfa_register";
682 case DW_CFA_def_cfa_offset:
683 return "DW_CFA_def_cfa_offset";
c53aa195 684
3f76745e
JM
685 /* SGI/MIPS specific */
686 case DW_CFA_MIPS_advance_loc8:
687 return "DW_CFA_MIPS_advance_loc8";
c53aa195
JM
688
689 /* GNU extensions */
690 case DW_CFA_GNU_window_save:
691 return "DW_CFA_GNU_window_save";
0021b564
JM
692 case DW_CFA_GNU_args_size:
693 return "DW_CFA_GNU_args_size";
c53aa195 694
3f76745e
JM
695 default:
696 return "DW_CFA_<unknown>";
697 }
698}
a3f97cbb 699
3f76745e 700/* Return a pointer to a newly allocated Call Frame Instruction. */
71dfc51f 701
3f76745e
JM
702static inline dw_cfi_ref
703new_cfi ()
704{
705 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
71dfc51f 706
3f76745e
JM
707 cfi->dw_cfi_next = NULL;
708 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
709 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
a3f97cbb 710
3f76745e
JM
711 return cfi;
712}
a3f97cbb 713
3f76745e 714/* Add a Call Frame Instruction to list of instructions. */
a3f97cbb 715
3f76745e
JM
716static inline void
717add_cfi (list_head, cfi)
718 register dw_cfi_ref *list_head;
719 register dw_cfi_ref cfi;
720{
721 register dw_cfi_ref *p;
a3f97cbb 722
3f76745e
JM
723 /* Find the end of the chain. */
724 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
725 ;
726
727 *p = cfi;
a3f97cbb
JW
728}
729
3f76745e 730/* Generate a new label for the CFI info to refer to. */
71dfc51f 731
c53aa195 732char *
3f76745e 733dwarf2out_cfi_label ()
a3f97cbb 734{
3f76745e
JM
735 static char label[20];
736 static unsigned long label_num = 0;
737
738 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
739 ASM_OUTPUT_LABEL (asm_out_file, label);
740
741 return label;
a3f97cbb
JW
742}
743
3f76745e
JM
744/* Add CFI to the current fde at the PC value indicated by LABEL if specified,
745 or to the CIE if LABEL is NULL. */
71dfc51f 746
3f76745e
JM
747static void
748add_fde_cfi (label, cfi)
749 register char *label;
750 register dw_cfi_ref cfi;
a3f97cbb 751{
3f76745e
JM
752 if (label)
753 {
754 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
a3f97cbb 755
3f76745e
JM
756 if (*label == 0)
757 label = dwarf2out_cfi_label ();
71dfc51f 758
3f76745e
JM
759 if (fde->dw_fde_current_label == NULL
760 || strcmp (label, fde->dw_fde_current_label) != 0)
761 {
762 register dw_cfi_ref xcfi;
a3f97cbb 763
3f76745e 764 fde->dw_fde_current_label = label = xstrdup (label);
71dfc51f 765
3f76745e
JM
766 /* Set the location counter to the new label. */
767 xcfi = new_cfi ();
768 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
769 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
770 add_cfi (&fde->dw_fde_cfi, xcfi);
771 }
71dfc51f 772
3f76745e
JM
773 add_cfi (&fde->dw_fde_cfi, cfi);
774 }
775
776 else
777 add_cfi (&cie_cfi_head, cfi);
a3f97cbb
JW
778}
779
3f76745e 780/* Subroutine of lookup_cfa. */
71dfc51f 781
3f76745e
JM
782static inline void
783lookup_cfa_1 (cfi, regp, offsetp)
784 register dw_cfi_ref cfi;
785 register unsigned long *regp;
786 register long *offsetp;
a3f97cbb 787{
3f76745e
JM
788 switch (cfi->dw_cfi_opc)
789 {
790 case DW_CFA_def_cfa_offset:
791 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
792 break;
793 case DW_CFA_def_cfa_register:
794 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
795 break;
796 case DW_CFA_def_cfa:
797 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
798 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
799 break;
e9a25f70
JL
800 default:
801 break;
3f76745e 802 }
a3f97cbb
JW
803}
804
3f76745e 805/* Find the previous value for the CFA. */
71dfc51f 806
3f76745e
JM
807static void
808lookup_cfa (regp, offsetp)
809 register unsigned long *regp;
810 register long *offsetp;
a3f97cbb 811{
3f76745e
JM
812 register dw_cfi_ref cfi;
813
814 *regp = (unsigned long) -1;
815 *offsetp = 0;
816
817 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
818 lookup_cfa_1 (cfi, regp, offsetp);
819
820 if (fde_table_in_use)
a3f97cbb 821 {
3f76745e
JM
822 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
823 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
824 lookup_cfa_1 (cfi, regp, offsetp);
a3f97cbb
JW
825 }
826}
827
3f76745e 828/* The current rule for calculating the DWARF2 canonical frame address. */
a6ab3aad 829static unsigned long cfa_reg;
3f76745e 830static long cfa_offset;
71dfc51f 831
3f76745e
JM
832/* The register used for saving registers to the stack, and its offset
833 from the CFA. */
834static unsigned cfa_store_reg;
835static long cfa_store_offset;
836
0021b564
JM
837/* The running total of the size of arguments pushed onto the stack. */
838static long args_size;
839
3f76745e
JM
840/* Entry point to update the canonical frame address (CFA).
841 LABEL is passed to add_fde_cfi. The value of CFA is now to be
842 calculated from REG+OFFSET. */
843
844void
845dwarf2out_def_cfa (label, reg, offset)
846 register char *label;
847 register unsigned reg;
848 register long offset;
a3f97cbb 849{
3f76745e
JM
850 register dw_cfi_ref cfi;
851 unsigned long old_reg;
852 long old_offset;
853
5bef9b1f
JM
854 cfa_reg = reg;
855 cfa_offset = offset;
856 if (cfa_store_reg == reg)
857 cfa_store_offset = offset;
858
3f76745e
JM
859 reg = DWARF_FRAME_REGNUM (reg);
860 lookup_cfa (&old_reg, &old_offset);
861
862 if (reg == old_reg && offset == old_offset)
863 return;
864
865 cfi = new_cfi ();
866
867 if (reg == old_reg)
a3f97cbb 868 {
3f76745e
JM
869 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
870 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
871 }
a3f97cbb 872
3f76745e
JM
873#ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
874 else if (offset == old_offset && old_reg != (unsigned long) -1)
875 {
876 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
877 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
878 }
879#endif
a3f97cbb 880
3f76745e
JM
881 else
882 {
883 cfi->dw_cfi_opc = DW_CFA_def_cfa;
884 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
885 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
a3f97cbb 886 }
3f76745e
JM
887
888 add_fde_cfi (label, cfi);
a3f97cbb
JW
889}
890
3f76745e
JM
891/* Add the CFI for saving a register. REG is the CFA column number.
892 LABEL is passed to add_fde_cfi.
893 If SREG is -1, the register is saved at OFFSET from the CFA;
894 otherwise it is saved in SREG. */
71dfc51f 895
3f76745e
JM
896static void
897reg_save (label, reg, sreg, offset)
898 register char * label;
899 register unsigned reg;
900 register unsigned sreg;
901 register long offset;
a3f97cbb 902{
3f76745e
JM
903 register dw_cfi_ref cfi = new_cfi ();
904
905 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
906
907 if (sreg == -1)
a3f97cbb 908 {
3f76745e
JM
909 if (reg & ~0x3f)
910 /* The register number won't fit in 6 bits, so we have to use
911 the long form. */
912 cfi->dw_cfi_opc = DW_CFA_offset_extended;
913 else
914 cfi->dw_cfi_opc = DW_CFA_offset;
915
916 offset /= DWARF_CIE_DATA_ALIGNMENT;
3a88cbd1
JL
917 if (offset < 0)
918 abort ();
3f76745e
JM
919 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
920 }
921 else
922 {
923 cfi->dw_cfi_opc = DW_CFA_register;
924 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
925 }
926
927 add_fde_cfi (label, cfi);
928}
929
c53aa195
JM
930/* Add the CFI for saving a register window. LABEL is passed to reg_save.
931 This CFI tells the unwinder that it needs to restore the window registers
932 from the previous frame's window save area.
933
934 ??? Perhaps we should note in the CIE where windows are saved (instead of
935 assuming 0(cfa)) and what registers are in the window. */
936
937void
938dwarf2out_window_save (label)
939 register char * label;
940{
941 register dw_cfi_ref cfi = new_cfi ();
942 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
943 add_fde_cfi (label, cfi);
944}
945
0021b564
JM
946/* Add a CFI to update the running total of the size of arguments
947 pushed onto the stack. */
948
949void
950dwarf2out_args_size (label, size)
951 char *label;
952 long size;
953{
954 register dw_cfi_ref cfi = new_cfi ();
955 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
956 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
957 add_fde_cfi (label, cfi);
958}
959
c53aa195
JM
960/* Entry point for saving a register to the stack. REG is the GCC register
961 number. LABEL and OFFSET are passed to reg_save. */
3f76745e
JM
962
963void
964dwarf2out_reg_save (label, reg, offset)
965 register char * label;
966 register unsigned reg;
967 register long offset;
968{
969 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
970}
971
c53aa195
JM
972/* Entry point for saving the return address in the stack.
973 LABEL and OFFSET are passed to reg_save. */
974
975void
976dwarf2out_return_save (label, offset)
977 register char * label;
978 register long offset;
979{
980 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
981}
982
983/* Entry point for saving the return address in a register.
984 LABEL and SREG are passed to reg_save. */
985
986void
987dwarf2out_return_reg (label, sreg)
988 register char * label;
989 register unsigned sreg;
990{
991 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
992}
993
3f76745e
JM
994/* Record the initial position of the return address. RTL is
995 INCOMING_RETURN_ADDR_RTX. */
996
997static void
998initial_return_save (rtl)
999 register rtx rtl;
1000{
1001 unsigned reg = -1;
1002 long offset = 0;
1003
1004 switch (GET_CODE (rtl))
1005 {
1006 case REG:
1007 /* RA is in a register. */
1008 reg = reg_number (rtl);
1009 break;
1010 case MEM:
1011 /* RA is on the stack. */
1012 rtl = XEXP (rtl, 0);
1013 switch (GET_CODE (rtl))
1014 {
1015 case REG:
3a88cbd1
JL
1016 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1017 abort ();
3f76745e
JM
1018 offset = 0;
1019 break;
1020 case PLUS:
3a88cbd1
JL
1021 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1022 abort ();
3f76745e
JM
1023 offset = INTVAL (XEXP (rtl, 1));
1024 break;
1025 case MINUS:
3a88cbd1
JL
1026 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1027 abort ();
3f76745e
JM
1028 offset = -INTVAL (XEXP (rtl, 1));
1029 break;
1030 default:
1031 abort ();
1032 }
1033 break;
c53aa195
JM
1034 case PLUS:
1035 /* The return address is at some offset from any value we can
1036 actually load. For instance, on the SPARC it is in %i7+8. Just
1037 ignore the offset for now; it doesn't matter for unwinding frames. */
3a88cbd1
JL
1038 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1039 abort ();
c53aa195
JM
1040 initial_return_save (XEXP (rtl, 0));
1041 return;
a3f97cbb 1042 default:
3f76745e 1043 abort ();
a3f97cbb 1044 }
3f76745e 1045
a6ab3aad 1046 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
a3f97cbb
JW
1047}
1048
0021b564
JM
1049/* Check INSN to see if it looks like a push or a stack adjustment, and
1050 make a note of it if it does. EH uses this information to find out how
1051 much extra space it needs to pop off the stack. */
1052
1053static void
1054dwarf2out_stack_adjust (insn)
1055 rtx insn;
1056{
0021b564
JM
1057 long offset;
1058 char *label;
1059
6020d360 1060 if (GET_CODE (insn) == BARRIER)
0021b564 1061 {
6020d360
JM
1062 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1063 the compiler will have already emitted a stack adjustment, but
1064 doesn't bother for calls to noreturn functions. */
1065#ifdef STACK_GROWS_DOWNWARD
1066 offset = -args_size;
1067#else
1068 offset = args_size;
1069#endif
0021b564 1070 }
6020d360 1071 else if (GET_CODE (PATTERN (insn)) == SET)
0021b564 1072 {
6020d360
JM
1073 rtx src, dest;
1074 enum rtx_code code;
1075
1076 insn = PATTERN (insn);
1077 src = SET_SRC (insn);
1078 dest = SET_DEST (insn);
0021b564 1079
6020d360
JM
1080 if (dest == stack_pointer_rtx)
1081 {
1082 /* (set (reg sp) (plus (reg sp) (const_int))) */
1083 code = GET_CODE (src);
1084 if (! (code == PLUS || code == MINUS)
1085 || XEXP (src, 0) != stack_pointer_rtx
1086 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1087 return;
1088
1089 offset = INTVAL (XEXP (src, 1));
1090 }
1091 else if (GET_CODE (dest) == MEM)
1092 {
1093 /* (set (mem (pre_dec (reg sp))) (foo)) */
1094 src = XEXP (dest, 0);
1095 code = GET_CODE (src);
1096
1097 if (! (code == PRE_DEC || code == PRE_INC)
1098 || XEXP (src, 0) != stack_pointer_rtx)
1099 return;
1100
1101 offset = GET_MODE_SIZE (GET_MODE (dest));
1102 }
1103 else
0021b564
JM
1104 return;
1105
6020d360
JM
1106 if (code == PLUS || code == PRE_INC)
1107 offset = -offset;
0021b564
JM
1108 }
1109 else
1110 return;
1111
6020d360
JM
1112 if (offset == 0)
1113 return;
1114
0021b564
JM
1115 if (cfa_reg == STACK_POINTER_REGNUM)
1116 cfa_offset += offset;
1117
1118#ifndef STACK_GROWS_DOWNWARD
1119 offset = -offset;
1120#endif
1121 args_size += offset;
1122 if (args_size < 0)
1123 args_size = 0;
1124
1125 label = dwarf2out_cfi_label ();
1126 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1127 dwarf2out_args_size (label, args_size);
1128}
1129
3f76745e
JM
1130/* Record call frame debugging information for INSN, which either
1131 sets SP or FP (adjusting how we calculate the frame address) or saves a
1132 register to the stack. If INSN is NULL_RTX, initialize our state. */
71dfc51f 1133
3f76745e
JM
1134void
1135dwarf2out_frame_debug (insn)
1136 rtx insn;
a3f97cbb 1137{
3f76745e
JM
1138 char *label;
1139 rtx src, dest;
1140 long offset;
1141
1142 /* A temporary register used in adjusting SP or setting up the store_reg. */
1143 static unsigned cfa_temp_reg;
1144 static long cfa_temp_value;
1145
1146 if (insn == NULL_RTX)
a3f97cbb 1147 {
3f76745e 1148 /* Set up state for generating call frame debug info. */
a6ab3aad 1149 lookup_cfa (&cfa_reg, &cfa_offset);
3a88cbd1
JL
1150 if (cfa_reg != DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1151 abort ();
3f76745e 1152 cfa_reg = STACK_POINTER_REGNUM;
a6ab3aad
JM
1153 cfa_store_reg = cfa_reg;
1154 cfa_store_offset = cfa_offset;
3f76745e
JM
1155 cfa_temp_reg = -1;
1156 cfa_temp_value = 0;
1157 return;
1158 }
1159
0021b564
JM
1160 if (! RTX_FRAME_RELATED_P (insn))
1161 {
6020d360 1162 dwarf2out_stack_adjust (insn);
0021b564
JM
1163 return;
1164 }
1165
3f76745e
JM
1166 label = dwarf2out_cfi_label ();
1167
1168 insn = PATTERN (insn);
267c09ab
JM
1169 /* Assume that in a PARALLEL prologue insn, only the first elt is
1170 significant. Currently this is true. */
1171 if (GET_CODE (insn) == PARALLEL)
1172 insn = XVECEXP (insn, 0, 0);
3a88cbd1
JL
1173 if (GET_CODE (insn) != SET)
1174 abort ();
3f76745e
JM
1175
1176 src = SET_SRC (insn);
1177 dest = SET_DEST (insn);
1178
1179 switch (GET_CODE (dest))
1180 {
1181 case REG:
1182 /* Update the CFA rule wrt SP or FP. Make sure src is
1183 relative to the current CFA register. */
1184 switch (GET_CODE (src))
1185 {
1186 /* Setting FP from SP. */
1187 case REG:
3a88cbd1
JL
1188 if (cfa_reg != REGNO (src))
1189 abort ();
1190 if (REGNO (dest) != STACK_POINTER_REGNUM
1191 && !(frame_pointer_needed
1192 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM))
1193 abort ();
3f76745e
JM
1194 cfa_reg = REGNO (dest);
1195 break;
1196
1197 case PLUS:
1198 case MINUS:
1199 if (dest == stack_pointer_rtx)
1200 {
1201 /* Adjusting SP. */
1202 switch (GET_CODE (XEXP (src, 1)))
1203 {
1204 case CONST_INT:
1205 offset = INTVAL (XEXP (src, 1));
1206 break;
1207 case REG:
3a88cbd1
JL
1208 if (REGNO (XEXP (src, 1)) != cfa_temp_reg)
1209 abort ();
3f76745e
JM
1210 offset = cfa_temp_value;
1211 break;
1212 default:
1213 abort ();
1214 }
1215
0021b564
JM
1216 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1217 {
1218 /* Restoring SP from FP in the epilogue. */
3a88cbd1
JL
1219 if (cfa_reg != HARD_FRAME_POINTER_REGNUM)
1220 abort ();
0021b564
JM
1221 cfa_reg = STACK_POINTER_REGNUM;
1222 }
3a88cbd1
JL
1223 else if (XEXP (src, 0) != stack_pointer_rtx)
1224 abort ();
0021b564 1225
3f76745e
JM
1226 if (GET_CODE (src) == PLUS)
1227 offset = -offset;
1228 if (cfa_reg == STACK_POINTER_REGNUM)
1229 cfa_offset += offset;
1230 if (cfa_store_reg == STACK_POINTER_REGNUM)
1231 cfa_store_offset += offset;
3f76745e 1232 }
63d96a95
GK
1233 else if (dest == hard_frame_pointer_rtx)
1234 {
1235 /* Either setting the FP from an offset of the SP,
1236 or adjusting the FP */
1237 if (! frame_pointer_needed
1238 || REGNO (dest) != HARD_FRAME_POINTER_REGNUM)
1239 abort ();
1240
1241 if (XEXP (src, 0) == stack_pointer_rtx
1242 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1243 {
1244 if (cfa_reg != STACK_POINTER_REGNUM)
1245 abort ();
1246 offset = INTVAL (XEXP (src, 1));
1247 if (GET_CODE (src) == PLUS)
1248 offset = -offset;
1249 cfa_offset += offset;
1250 cfa_reg = HARD_FRAME_POINTER_REGNUM;
1251 }
1252 else if (XEXP (src, 0) == hard_frame_pointer_rtx
1253 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1254 {
1255 if (cfa_reg != HARD_FRAME_POINTER_REGNUM)
1256 abort ();
1257 offset = INTVAL (XEXP (src, 1));
1258 if (GET_CODE (src) == PLUS)
1259 offset = -offset;
1260 cfa_offset += offset;
1261 }
1262
1263 else
1264 abort();
1265 }
3f76745e
JM
1266 else
1267 {
3a88cbd1 1268 if (GET_CODE (src) != PLUS
31d52528 1269 || XEXP (src, 1) != stack_pointer_rtx)
3a88cbd1
JL
1270 abort ();
1271 if (GET_CODE (XEXP (src, 0)) != REG
1272 || REGNO (XEXP (src, 0)) != cfa_temp_reg)
1273 abort ();
218c2cdb
JW
1274 if (cfa_reg != STACK_POINTER_REGNUM)
1275 abort ();
3f76745e 1276 cfa_store_reg = REGNO (dest);
218c2cdb 1277 cfa_store_offset = cfa_offset - cfa_temp_value;
3f76745e
JM
1278 }
1279 break;
1280
1281 case CONST_INT:
1282 cfa_temp_reg = REGNO (dest);
1283 cfa_temp_value = INTVAL (src);
1284 break;
1285
ef76d03b 1286 case IOR:
3a88cbd1
JL
1287 if (GET_CODE (XEXP (src, 0)) != REG
1288 || REGNO (XEXP (src, 0)) != cfa_temp_reg
1289 || REGNO (dest) != cfa_temp_reg
1290 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1291 abort ();
ef76d03b
JW
1292 cfa_temp_value |= INTVAL (XEXP (src, 1));
1293 break;
1294
3f76745e
JM
1295 default:
1296 abort ();
1297 }
1298 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1299 break;
1300
1301 case MEM:
1302 /* Saving a register to the stack. Make sure dest is relative to the
1303 CFA register. */
3a88cbd1
JL
1304 if (GET_CODE (src) != REG)
1305 abort ();
3f76745e
JM
1306 switch (GET_CODE (XEXP (dest, 0)))
1307 {
1308 /* With a push. */
1309 case PRE_INC:
1310 case PRE_DEC:
1311 offset = GET_MODE_SIZE (GET_MODE (dest));
0021b564 1312 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
3f76745e
JM
1313 offset = -offset;
1314
3a88cbd1
JL
1315 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1316 || cfa_store_reg != STACK_POINTER_REGNUM)
1317 abort ();
3f76745e
JM
1318 cfa_store_offset += offset;
1319 if (cfa_reg == STACK_POINTER_REGNUM)
1320 cfa_offset = cfa_store_offset;
1321
1322 offset = -cfa_store_offset;
1323 break;
1324
1325 /* With an offset. */
1326 case PLUS:
1327 case MINUS:
1328 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1329 if (GET_CODE (src) == MINUS)
1330 offset = -offset;
1331
3a88cbd1
JL
1332 if (cfa_store_reg != REGNO (XEXP (XEXP (dest, 0), 0)))
1333 abort ();
3f76745e
JM
1334 offset -= cfa_store_offset;
1335 break;
1336
1337 default:
1338 abort ();
1339 }
1340 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1341 dwarf2out_reg_save (label, REGNO (src), offset);
1342 break;
1343
1344 default:
1345 abort ();
1346 }
1347}
1348
1349/* Return the size of an unsigned LEB128 quantity. */
1350
1351static inline unsigned long
1352size_of_uleb128 (value)
1353 register unsigned long value;
1354{
1355 register unsigned long size = 0;
1356 register unsigned byte;
1357
1358 do
1359 {
1360 byte = (value & 0x7f);
1361 value >>= 7;
1362 size += 1;
1363 }
1364 while (value != 0);
1365
1366 return size;
1367}
1368
1369/* Return the size of a signed LEB128 quantity. */
1370
1371static inline unsigned long
1372size_of_sleb128 (value)
1373 register long value;
1374{
1375 register unsigned long size = 0;
1376 register unsigned byte;
1377
1378 do
1379 {
1380 byte = (value & 0x7f);
1381 value >>= 7;
1382 size += 1;
1383 }
1384 while (!(((value == 0) && ((byte & 0x40) == 0))
1385 || ((value == -1) && ((byte & 0x40) != 0))));
1386
1387 return size;
1388}
1389
3f76745e
JM
1390/* Output an unsigned LEB128 quantity. */
1391
1392static void
1393output_uleb128 (value)
1394 register unsigned long value;
1395{
1396 unsigned long save_value = value;
1397
1398 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1399 do
1400 {
1401 register unsigned byte = (value & 0x7f);
1402 value >>= 7;
1403 if (value != 0)
1404 /* More bytes to follow. */
1405 byte |= 0x80;
1406
1407 fprintf (asm_out_file, "0x%x", byte);
1408 if (value != 0)
1409 fprintf (asm_out_file, ",");
1410 }
1411 while (value != 0);
1412
c5cec899 1413 if (flag_debug_asm)
3f76745e
JM
1414 fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value);
1415}
1416
1417/* Output an signed LEB128 quantity. */
1418
1419static void
1420output_sleb128 (value)
1421 register long value;
1422{
1423 register int more;
1424 register unsigned byte;
1425 long save_value = value;
1426
1427 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1428 do
1429 {
1430 byte = (value & 0x7f);
1431 /* arithmetic shift */
1432 value >>= 7;
1433 more = !((((value == 0) && ((byte & 0x40) == 0))
1434 || ((value == -1) && ((byte & 0x40) != 0))));
1435 if (more)
1436 byte |= 0x80;
1437
1438 fprintf (asm_out_file, "0x%x", byte);
1439 if (more)
1440 fprintf (asm_out_file, ",");
1441 }
1442
1443 while (more);
c5cec899 1444 if (flag_debug_asm)
3f76745e
JM
1445 fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value);
1446}
1447
1448/* Output a Call Frame Information opcode and its operand(s). */
1449
1450static void
1451output_cfi (cfi, fde)
1452 register dw_cfi_ref cfi;
1453 register dw_fde_ref fde;
1454{
1455 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1456 {
1457 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1458 cfi->dw_cfi_opc
1459 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
c5cec899 1460 if (flag_debug_asm)
3f76745e
JM
1461 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%x",
1462 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1463 fputc ('\n', asm_out_file);
1464 }
1465
1466 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1467 {
1468 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1469 cfi->dw_cfi_opc
1470 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
c5cec899 1471 if (flag_debug_asm)
3f76745e
JM
1472 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%x",
1473 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1474
1475 fputc ('\n', asm_out_file);
1476 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1477 fputc ('\n', asm_out_file);
1478 }
1479 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1480 {
1481 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1482 cfi->dw_cfi_opc
1483 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
c5cec899 1484 if (flag_debug_asm)
3f76745e
JM
1485 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%x",
1486 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1487
1488 fputc ('\n', asm_out_file);
1489 }
1490 else
1491 {
1492 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
c5cec899 1493 if (flag_debug_asm)
3f76745e
JM
1494 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1495 dwarf_cfi_name (cfi->dw_cfi_opc));
1496
1497 fputc ('\n', asm_out_file);
1498 switch (cfi->dw_cfi_opc)
1499 {
1500 case DW_CFA_set_loc:
1501 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1502 fputc ('\n', asm_out_file);
1503 break;
1504 case DW_CFA_advance_loc1:
bb727b5a
JM
1505 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1506 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1507 fde->dw_fde_current_label);
1508 fputc ('\n', asm_out_file);
1509 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3f76745e
JM
1510 break;
1511 case DW_CFA_advance_loc2:
1512 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1513 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1514 fde->dw_fde_current_label);
1515 fputc ('\n', asm_out_file);
1516 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1517 break;
1518 case DW_CFA_advance_loc4:
1519 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1520 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1521 fde->dw_fde_current_label);
1522 fputc ('\n', asm_out_file);
1523 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1524 break;
1525#ifdef MIPS_DEBUGGING_INFO
1526 case DW_CFA_MIPS_advance_loc8:
1527 /* TODO: not currently implemented. */
1528 abort ();
1529 break;
1530#endif
1531 case DW_CFA_offset_extended:
1532 case DW_CFA_def_cfa:
1533 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1534 fputc ('\n', asm_out_file);
1535 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1536 fputc ('\n', asm_out_file);
1537 break;
1538 case DW_CFA_restore_extended:
1539 case DW_CFA_undefined:
1540 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1541 fputc ('\n', asm_out_file);
1542 break;
1543 case DW_CFA_same_value:
1544 case DW_CFA_def_cfa_register:
1545 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1546 fputc ('\n', asm_out_file);
1547 break;
1548 case DW_CFA_register:
1549 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1550 fputc ('\n', asm_out_file);
1551 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1552 fputc ('\n', asm_out_file);
1553 break;
1554 case DW_CFA_def_cfa_offset:
1555 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1556 fputc ('\n', asm_out_file);
1557 break;
c53aa195
JM
1558 case DW_CFA_GNU_window_save:
1559 break;
0021b564
JM
1560 case DW_CFA_GNU_args_size:
1561 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1562 fputc ('\n', asm_out_file);
1563 break;
3f76745e
JM
1564 default:
1565 break;
1566 }
1567 }
1568}
1569
0021b564
JM
1570#if !defined (EH_FRAME_SECTION)
1571#if defined (EH_FRAME_SECTION_ASM_OP)
1572#define EH_FRAME_SECTION() eh_frame_section();
1573#else
1574#if defined (ASM_OUTPUT_SECTION_NAME)
1575#define EH_FRAME_SECTION() \
1576 do { \
1577 named_section (NULL_TREE, ".eh_frame", 0); \
1578 } while (0)
1579#endif
1580#endif
1581#endif
1582
3f76745e
JM
1583/* Output the call frame information used to used to record information
1584 that relates to calculating the frame pointer, and records the
1585 location of saved registers. */
1586
1587static void
1588output_call_frame_info (for_eh)
1589 int for_eh;
1590{
1591 register unsigned long i, j;
1592 register dw_fde_ref fde;
1593 register unsigned long fde_size;
1594 register dw_cfi_ref cfi;
1595 unsigned long fde_pad;
a6ab3aad 1596 char l1[20], l2[20];
2ed2af28
PDM
1597#ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1598 char ld[20];
1599#endif
a6ab3aad
JM
1600
1601 /* Do we want to include a pointer to the exception table? */
1602 int eh_ptr = for_eh && exception_table_p ();
3f76745e 1603
3f76745e 1604 fputc ('\n', asm_out_file);
e9e30253 1605
aa0c1401
JL
1606 /* We're going to be generating comments, so turn on app. */
1607 if (flag_debug_asm)
1608 app_enable ();
956d6950 1609
3f76745e
JM
1610 if (for_eh)
1611 {
1612#ifdef EH_FRAME_SECTION
0021b564 1613 EH_FRAME_SECTION ();
3f76745e 1614#else
496651db 1615 tree label = get_file_function_name ('F');
0021b564 1616
3f76745e 1617 data_section ();
f4744807 1618 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
0021b564
JM
1619 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1620 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3f76745e
JM
1621#endif
1622 assemble_label ("__FRAME_BEGIN__");
1623 }
1624 else
1625 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1626
1627 /* Output the CIE. */
a6ab3aad
JM
1628 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1629 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2ed2af28
PDM
1630#ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1631 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1632 if (for_eh)
7bb9fb0e 1633 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2ed2af28
PDM
1634 else
1635 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1636#else
267c09ab
JM
1637 if (for_eh)
1638 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1639 else
1640 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2ed2af28 1641#endif
c5cec899 1642 if (flag_debug_asm)
3f76745e
JM
1643 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1644 ASM_COMMENT_START);
1645
1646 fputc ('\n', asm_out_file);
a6ab3aad
JM
1647 ASM_OUTPUT_LABEL (asm_out_file, l1);
1648
d84e64d4
JM
1649 if (for_eh)
1650 /* Now that the CIE pointer is PC-relative for EH,
1651 use 0 to identify the CIE. */
1652 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1653 else
1654 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1655
c5cec899 1656 if (flag_debug_asm)
3f76745e
JM
1657 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1658
1659 fputc ('\n', asm_out_file);
d84e64d4 1660 if (! for_eh && DWARF_OFFSET_SIZE == 8)
3f76745e
JM
1661 {
1662 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1663 fputc ('\n', asm_out_file);
1664 }
1665
1666 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
c5cec899 1667 if (flag_debug_asm)
3f76745e
JM
1668 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1669
1670 fputc ('\n', asm_out_file);
a6ab3aad
JM
1671 if (eh_ptr)
1672 {
d84e64d4
JM
1673 /* The CIE contains a pointer to the exception region info for the
1674 frame. Make the augmentation string three bytes (including the
1675 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1676 can't handle unaligned relocs. */
c5cec899 1677 if (flag_debug_asm)
8d4e65a6
JL
1678 {
1679 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1680 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1681 }
1682 else
1683 {
c2c85462 1684 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
8d4e65a6 1685 }
d84e64d4
JM
1686 fputc ('\n', asm_out_file);
1687
1688 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1689 if (flag_debug_asm)
1690 fprintf (asm_out_file, "\t%s pointer to exception region info",
1691 ASM_COMMENT_START);
a6ab3aad
JM
1692 }
1693 else
1694 {
1695 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
c5cec899 1696 if (flag_debug_asm)
a6ab3aad
JM
1697 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1698 ASM_COMMENT_START);
1699 }
3f76745e
JM
1700
1701 fputc ('\n', asm_out_file);
1702 output_uleb128 (1);
c5cec899 1703 if (flag_debug_asm)
3f76745e
JM
1704 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1705
1706 fputc ('\n', asm_out_file);
1707 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
c5cec899 1708 if (flag_debug_asm)
3f76745e
JM
1709 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1710
1711 fputc ('\n', asm_out_file);
1712 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
c5cec899 1713 if (flag_debug_asm)
3f76745e
JM
1714 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1715
1716 fputc ('\n', asm_out_file);
1717
1718 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1719 output_cfi (cfi, NULL);
1720
1721 /* Pad the CIE out to an address sized boundary. */
a6ab3aad
JM
1722 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1723 ASM_OUTPUT_LABEL (asm_out_file, l2);
2ed2af28
PDM
1724#ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1725 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
7bb9fb0e
JM
1726 if (flag_debug_asm)
1727 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1728 fputc ('\n', asm_out_file);
2ed2af28 1729#endif
3f76745e
JM
1730
1731 /* Loop through all of the FDE's. */
1732 for (i = 0; i < fde_table_in_use; ++i)
1733 {
1734 fde = &fde_table[i];
3f76745e 1735
a6ab3aad
JM
1736 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1737 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
2ed2af28
PDM
1738#ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1739 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1740 if (for_eh)
7bb9fb0e 1741 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2ed2af28
PDM
1742 else
1743 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1744#else
267c09ab
JM
1745 if (for_eh)
1746 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1747 else
1748 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2ed2af28 1749#endif
c5cec899 1750 if (flag_debug_asm)
3f76745e 1751 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
3f76745e 1752 fputc ('\n', asm_out_file);
a6ab3aad
JM
1753 ASM_OUTPUT_LABEL (asm_out_file, l1);
1754
3f76745e 1755 if (for_eh)
ede19932 1756 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l1, "__FRAME_BEGIN__");
3f76745e
JM
1757 else
1758 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
c5cec899 1759 if (flag_debug_asm)
3f76745e
JM
1760 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1761
1762 fputc ('\n', asm_out_file);
1763 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
c5cec899 1764 if (flag_debug_asm)
3f76745e
JM
1765 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1766
1767 fputc ('\n', asm_out_file);
1768 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1769 fde->dw_fde_end, fde->dw_fde_begin);
c5cec899 1770 if (flag_debug_asm)
3f76745e
JM
1771 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1772
1773 fputc ('\n', asm_out_file);
1774
1775 /* Loop through the Call Frame Instructions associated with
1776 this FDE. */
1777 fde->dw_fde_current_label = fde->dw_fde_begin;
1778 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1779 output_cfi (cfi, fde);
1780
a6ab3aad
JM
1781 /* Pad the FDE out to an address sized boundary. */
1782 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1783 ASM_OUTPUT_LABEL (asm_out_file, l2);
2ed2af28
PDM
1784#ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1785 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
7bb9fb0e
JM
1786 if (flag_debug_asm)
1787 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1788 fputc ('\n', asm_out_file);
2ed2af28 1789#endif
3f76745e
JM
1790 }
1791#ifndef EH_FRAME_SECTION
1792 if (for_eh)
1793 {
1794 /* Emit terminating zero for table. */
267c09ab 1795 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3f76745e
JM
1796 fputc ('\n', asm_out_file);
1797 }
1798#endif
a6ab3aad
JM
1799#ifdef MIPS_DEBUGGING_INFO
1800 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1801 get a value of 0. Putting .align 0 after the label fixes it. */
1802 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1803#endif
aa0c1401
JL
1804
1805 /* Turn off app to make assembly quicker. */
1806 if (flag_debug_asm)
1807 app_disable ();
a6ab3aad
JM
1808}
1809
3f76745e
JM
1810/* Output a marker (i.e. a label) for the beginning of a function, before
1811 the prologue. */
1812
1813void
1814dwarf2out_begin_prologue ()
1815{
1816 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1817 register dw_fde_ref fde;
1818
4f988ea2
JM
1819 ++current_funcdef_number;
1820
3f76745e
JM
1821 function_section (current_function_decl);
1822 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1823 current_funcdef_number);
1824 ASM_OUTPUT_LABEL (asm_out_file, label);
1825
1826 /* Expand the fde table if necessary. */
1827 if (fde_table_in_use == fde_table_allocated)
1828 {
1829 fde_table_allocated += FDE_TABLE_INCREMENT;
1830 fde_table
1831 = (dw_fde_ref) xrealloc (fde_table,
1832 fde_table_allocated * sizeof (dw_fde_node));
a3f97cbb 1833 }
3f76745e
JM
1834
1835 /* Record the FDE associated with this function. */
1836 current_funcdef_fde = fde_table_in_use;
1837
1838 /* Add the new FDE at the end of the fde_table. */
1839 fde = &fde_table[fde_table_in_use++];
1840 fde->dw_fde_begin = xstrdup (label);
1841 fde->dw_fde_current_label = NULL;
1842 fde->dw_fde_end = NULL;
1843 fde->dw_fde_cfi = NULL;
0021b564
JM
1844
1845 args_size = 0;
3f76745e
JM
1846}
1847
1848/* Output a marker (i.e. a label) for the absolute end of the generated code
1849 for a function definition. This gets called *after* the epilogue code has
1850 been generated. */
1851
1852void
1853dwarf2out_end_epilogue ()
1854{
1855 dw_fde_ref fde;
1856 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1857
1858 /* Output a label to mark the endpoint of the code generated for this
1859 function. */
1860 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1861 ASM_OUTPUT_LABEL (asm_out_file, label);
1862 fde = &fde_table[fde_table_in_use - 1];
1863 fde->dw_fde_end = xstrdup (label);
3f76745e
JM
1864}
1865
1866void
1867dwarf2out_frame_init ()
1868{
1869 /* Allocate the initial hunk of the fde_table. */
1870 fde_table
1871 = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1872 bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1873 fde_table_allocated = FDE_TABLE_INCREMENT;
1874 fde_table_in_use = 0;
1875
1876 /* Generate the CFA instructions common to all FDE's. Do it now for the
1877 sake of lookup_cfa. */
1878
a6ab3aad 1879#ifdef DWARF2_UNWIND_INFO
69145bcc
JC
1880 if (DWARF2_UNWIND_INFO)
1881 {
1882 /* On entry, the Canonical Frame Address is at SP. */
1883 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1884 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1885 }
3f76745e
JM
1886#endif
1887}
1888
1889void
1890dwarf2out_frame_finish ()
1891{
3f76745e 1892 /* Output call frame information. */
a6ab3aad 1893#ifdef MIPS_DEBUGGING_INFO
3f76745e
JM
1894 if (write_symbols == DWARF2_DEBUG)
1895 output_call_frame_info (0);
1896 if (flag_exceptions && ! exceptions_via_longjmp)
1897 output_call_frame_info (1);
a6ab3aad
JM
1898#else
1899 if (write_symbols == DWARF2_DEBUG
1900 || (flag_exceptions && ! exceptions_via_longjmp))
1901 output_call_frame_info (1);
1902#endif
3f76745e
JM
1903}
1904
1905#endif /* .debug_frame support */
1906
1907/* And now, the support for symbolic debugging information. */
1908#ifdef DWARF2_DEBUGGING_INFO
1909
1910extern char *getpwd ();
1911
1912/* NOTE: In the comments in this file, many references are made to
1913 "Debugging Information Entries". This term is abbreviated as `DIE'
1914 throughout the remainder of this file. */
1915
1916/* An internal representation of the DWARF output is built, and then
1917 walked to generate the DWARF debugging info. The walk of the internal
1918 representation is done after the entire program has been compiled.
1919 The types below are used to describe the internal representation. */
1920
1921/* Each DIE may have a series of attribute/value pairs. Values
1922 can take on several forms. The forms that are used in this
1923 implementation are listed below. */
1924
1925typedef enum
1926{
1927 dw_val_class_addr,
1928 dw_val_class_loc,
1929 dw_val_class_const,
1930 dw_val_class_unsigned_const,
1931 dw_val_class_long_long,
1932 dw_val_class_float,
1933 dw_val_class_flag,
1934 dw_val_class_die_ref,
1935 dw_val_class_fde_ref,
1936 dw_val_class_lbl_id,
1937 dw_val_class_section_offset,
1938 dw_val_class_str
a3f97cbb 1939}
3f76745e 1940dw_val_class;
a3f97cbb 1941
3f76745e
JM
1942/* Various DIE's use offsets relative to the beginning of the
1943 .debug_info section to refer to each other. */
71dfc51f 1944
3f76745e
JM
1945typedef long int dw_offset;
1946
1947/* Define typedefs here to avoid circular dependencies. */
1948
1949typedef struct die_struct *dw_die_ref;
1950typedef struct dw_attr_struct *dw_attr_ref;
1951typedef struct dw_val_struct *dw_val_ref;
1952typedef struct dw_line_info_struct *dw_line_info_ref;
1953typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1954typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1955typedef struct pubname_struct *pubname_ref;
1956typedef dw_die_ref *arange_ref;
1957
1958/* Describe a double word constant value. */
1959
1960typedef struct dw_long_long_struct
a3f97cbb 1961{
3f76745e
JM
1962 unsigned long hi;
1963 unsigned long low;
1964}
1965dw_long_long_const;
1966
1967/* Describe a floating point constant value. */
1968
1969typedef struct dw_fp_struct
1970{
1971 long *array;
1972 unsigned length;
1973}
1974dw_float_const;
1975
1976/* Each entry in the line_info_table maintains the file and
956d6950 1977 line number associated with the label generated for that
3f76745e
JM
1978 entry. The label gives the PC value associated with
1979 the line number entry. */
1980
1981typedef struct dw_line_info_struct
1982{
1983 unsigned long dw_file_num;
1984 unsigned long dw_line_num;
1985}
1986dw_line_info_entry;
1987
1988/* Line information for functions in separate sections; each one gets its
1989 own sequence. */
1990typedef struct dw_separate_line_info_struct
1991{
1992 unsigned long dw_file_num;
1993 unsigned long dw_line_num;
1994 unsigned long function;
1995}
1996dw_separate_line_info_entry;
1997
956d6950 1998/* The dw_val_node describes an attribute's value, as it is
3f76745e
JM
1999 represented internally. */
2000
2001typedef struct dw_val_struct
2002{
2003 dw_val_class val_class;
2004 union
a3f97cbb 2005 {
3f76745e
JM
2006 char *val_addr;
2007 dw_loc_descr_ref val_loc;
2008 long int val_int;
2009 long unsigned val_unsigned;
2010 dw_long_long_const val_long_long;
2011 dw_float_const val_float;
2012 dw_die_ref val_die_ref;
2013 unsigned val_fde_index;
2014 char *val_str;
2015 char *val_lbl_id;
2016 char *val_section;
2017 unsigned char val_flag;
a3f97cbb 2018 }
3f76745e
JM
2019 v;
2020}
2021dw_val_node;
2022
2023/* Locations in memory are described using a sequence of stack machine
2024 operations. */
2025
2026typedef struct dw_loc_descr_struct
2027{
2028 dw_loc_descr_ref dw_loc_next;
2029 enum dwarf_location_atom dw_loc_opc;
2030 dw_val_node dw_loc_oprnd1;
2031 dw_val_node dw_loc_oprnd2;
2032}
2033dw_loc_descr_node;
2034
2035/* Each DIE attribute has a field specifying the attribute kind,
2036 a link to the next attribute in the chain, and an attribute value.
2037 Attributes are typically linked below the DIE they modify. */
2038
2039typedef struct dw_attr_struct
2040{
2041 enum dwarf_attribute dw_attr;
2042 dw_attr_ref dw_attr_next;
2043 dw_val_node dw_attr_val;
2044}
2045dw_attr_node;
2046
2047/* The Debugging Information Entry (DIE) structure */
2048
2049typedef struct die_struct
2050{
2051 enum dwarf_tag die_tag;
2052 dw_attr_ref die_attr;
2053 dw_attr_ref die_attr_last;
2054 dw_die_ref die_parent;
2055 dw_die_ref die_child;
2056 dw_die_ref die_child_last;
2057 dw_die_ref die_sib;
2058 dw_offset die_offset;
2059 unsigned long die_abbrev;
a3f97cbb 2060}
3f76745e
JM
2061die_node;
2062
2063/* The pubname structure */
2064
2065typedef struct pubname_struct
2066{
2067 dw_die_ref die;
2068 char * name;
2069}
2070pubname_entry;
2071
ef76d03b
JW
2072/* The limbo die list structure. */
2073typedef struct limbo_die_struct
2074{
2075 dw_die_ref die;
2076 struct limbo_die_struct *next;
2077}
2078limbo_die_node;
2079
3f76745e
JM
2080/* How to start an assembler comment. */
2081#ifndef ASM_COMMENT_START
2082#define ASM_COMMENT_START ";#"
2083#endif
2084
2085/* Define a macro which returns non-zero for a TYPE_DECL which was
2086 implicitly generated for a tagged type.
2087
2088 Note that unlike the gcc front end (which generates a NULL named
2089 TYPE_DECL node for each complete tagged type, each array type, and
2090 each function type node created) the g++ front end generates a
2091 _named_ TYPE_DECL node for each tagged type node created.
2092 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2093 generate a DW_TAG_typedef DIE for them. */
2094
2095#define TYPE_DECL_IS_STUB(decl) \
2096 (DECL_NAME (decl) == NULL_TREE \
2097 || (DECL_ARTIFICIAL (decl) \
2098 && is_tagged_type (TREE_TYPE (decl)) \
ef76d03b
JW
2099 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2100 /* This is necessary for stub decls that \
2101 appear in nested inline functions. */ \
2102 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2103 && (decl_ultimate_origin (decl) \
2104 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3f76745e
JM
2105
2106/* Information concerning the compilation unit's programming
2107 language, and compiler version. */
2108
2109extern int flag_traditional;
2110extern char *version_string;
2111extern char *language_string;
2112
2113/* Fixed size portion of the DWARF compilation unit header. */
2114#define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2115
2116/* Fixed size portion of debugging line information prolog. */
2117#define DWARF_LINE_PROLOG_HEADER_SIZE 5
2118
2119/* Fixed size portion of public names info. */
2120#define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2121
2122/* Fixed size portion of the address range info. */
2123#define DWARF_ARANGES_HEADER_SIZE \
2124 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2125
2126/* Define the architecture-dependent minimum instruction length (in bytes).
2127 In this implementation of DWARF, this field is used for information
2128 purposes only. Since GCC generates assembly language, we have
2129 no a priori knowledge of how many instruction bytes are generated
2130 for each source line, and therefore can use only the DW_LNE_set_address
2131 and DW_LNS_fixed_advance_pc line information commands. */
2132
2133#ifndef DWARF_LINE_MIN_INSTR_LENGTH
2134#define DWARF_LINE_MIN_INSTR_LENGTH 4
2135#endif
2136
2137/* Minimum line offset in a special line info. opcode.
2138 This value was chosen to give a reasonable range of values. */
2139#define DWARF_LINE_BASE -10
2140
2141/* First special line opcde - leave room for the standard opcodes. */
2142#define DWARF_LINE_OPCODE_BASE 10
2143
2144/* Range of line offsets in a special line info. opcode. */
2145#define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2146
2147/* Flag that indicates the initial value of the is_stmt_start flag.
2148 In the present implementation, we do not mark any lines as
2149 the beginning of a source statement, because that information
2150 is not made available by the GCC front-end. */
2151#define DWARF_LINE_DEFAULT_IS_STMT_START 1
2152
2153/* This location is used by calc_die_sizes() to keep track
2154 the offset of each DIE within the .debug_info section. */
2155static unsigned long next_die_offset;
2156
2157/* Record the root of the DIE's built for the current compilation unit. */
2158static dw_die_ref comp_unit_die;
2159
ef76d03b
JW
2160/* A list of DIEs with a NULL parent waiting to be relocated. */
2161static limbo_die_node *limbo_die_list = 0;
3f76745e
JM
2162
2163/* Pointer to an array of filenames referenced by this compilation unit. */
2164static char **file_table;
2165
2166/* Total number of entries in the table (i.e. array) pointed to by
2167 `file_table'. This is the *total* and includes both used and unused
2168 slots. */
2169static unsigned file_table_allocated;
a3f97cbb 2170
3f76745e
JM
2171/* Number of entries in the file_table which are actually in use. */
2172static unsigned file_table_in_use;
71dfc51f 2173
3f76745e
JM
2174/* Size (in elements) of increments by which we may expand the filename
2175 table. */
2176#define FILE_TABLE_INCREMENT 64
71dfc51f 2177
3f76745e
JM
2178/* Local pointer to the name of the main input file. Initialized in
2179 dwarf2out_init. */
2180static char *primary_filename;
a3f97cbb 2181
3f76745e
JM
2182/* For Dwarf output, we must assign lexical-blocks id numbers in the order in
2183 which their beginnings are encountered. We output Dwarf debugging info
2184 that refers to the beginnings and ends of the ranges of code for each
2185 lexical block. The labels themselves are generated in final.c, which
2186 assigns numbers to the blocks in the same way. */
2187static unsigned next_block_number = 2;
a3f97cbb 2188
3f76745e
JM
2189/* A pointer to the base of a table of references to DIE's that describe
2190 declarations. The table is indexed by DECL_UID() which is a unique
956d6950 2191 number identifying each decl. */
3f76745e 2192static dw_die_ref *decl_die_table;
71dfc51f 2193
3f76745e
JM
2194/* Number of elements currently allocated for the decl_die_table. */
2195static unsigned decl_die_table_allocated;
a3f97cbb 2196
3f76745e
JM
2197/* Number of elements in decl_die_table currently in use. */
2198static unsigned decl_die_table_in_use;
71dfc51f 2199
3f76745e
JM
2200/* Size (in elements) of increments by which we may expand the
2201 decl_die_table. */
2202#define DECL_DIE_TABLE_INCREMENT 256
a3f97cbb 2203
3f76745e
JM
2204/* A pointer to the base of a table of references to declaration
2205 scopes. This table is a display which tracks the nesting
2206 of declaration scopes at the current scope and containing
2207 scopes. This table is used to find the proper place to
2208 define type declaration DIE's. */
2209static tree *decl_scope_table;
a3f97cbb 2210
3f76745e
JM
2211/* Number of elements currently allocated for the decl_scope_table. */
2212static unsigned decl_scope_table_allocated;
71dfc51f 2213
956d6950 2214/* Current level of nesting of declaration scopes. */
3f76745e 2215static unsigned decl_scope_depth;
bdb669cb 2216
3f76745e
JM
2217/* Size (in elements) of increments by which we may expand the
2218 decl_scope_table. */
2219#define DECL_SCOPE_TABLE_INCREMENT 64
bdb669cb 2220
3f76745e
JM
2221/* A pointer to the base of a list of references to DIE's that
2222 are uniquely identified by their tag, presence/absence of
2223 children DIE's, and list of attribute/value pairs. */
2224static dw_die_ref *abbrev_die_table;
71dfc51f 2225
3f76745e
JM
2226/* Number of elements currently allocated for abbrev_die_table. */
2227static unsigned abbrev_die_table_allocated;
bdb669cb 2228
3f76745e
JM
2229/* Number of elements in type_die_table currently in use. */
2230static unsigned abbrev_die_table_in_use;
bdb669cb 2231
3f76745e
JM
2232/* Size (in elements) of increments by which we may expand the
2233 abbrev_die_table. */
2234#define ABBREV_DIE_TABLE_INCREMENT 256
71dfc51f 2235
3f76745e
JM
2236/* A pointer to the base of a table that contains line information
2237 for each source code line in .text in the compilation unit. */
2238static dw_line_info_ref line_info_table;
a3f97cbb 2239
3f76745e
JM
2240/* Number of elements currently allocated for line_info_table. */
2241static unsigned line_info_table_allocated;
71dfc51f 2242
3f76745e
JM
2243/* Number of elements in separate_line_info_table currently in use. */
2244static unsigned separate_line_info_table_in_use;
71dfc51f 2245
3f76745e
JM
2246/* A pointer to the base of a table that contains line information
2247 for each source code line outside of .text in the compilation unit. */
2248static dw_separate_line_info_ref separate_line_info_table;
a3f97cbb 2249
3f76745e
JM
2250/* Number of elements currently allocated for separate_line_info_table. */
2251static unsigned separate_line_info_table_allocated;
71dfc51f 2252
3f76745e
JM
2253/* Number of elements in line_info_table currently in use. */
2254static unsigned line_info_table_in_use;
71dfc51f 2255
3f76745e
JM
2256/* Size (in elements) of increments by which we may expand the
2257 line_info_table. */
2258#define LINE_INFO_TABLE_INCREMENT 1024
a3f97cbb 2259
3f76745e
JM
2260/* A pointer to the base of a table that contains a list of publicly
2261 accessible names. */
2262static pubname_ref pubname_table;
71dfc51f 2263
3f76745e
JM
2264/* Number of elements currently allocated for pubname_table. */
2265static unsigned pubname_table_allocated;
2266
2267/* Number of elements in pubname_table currently in use. */
2268static unsigned pubname_table_in_use;
2269
2270/* Size (in elements) of increments by which we may expand the
2271 pubname_table. */
2272#define PUBNAME_TABLE_INCREMENT 64
2273
2274/* A pointer to the base of a table that contains a list of publicly
2275 accessible names. */
2276static arange_ref arange_table;
71dfc51f 2277
3f76745e
JM
2278/* Number of elements currently allocated for arange_table. */
2279static unsigned arange_table_allocated;
a3f97cbb 2280
3f76745e
JM
2281/* Number of elements in arange_table currently in use. */
2282static unsigned arange_table_in_use;
71dfc51f 2283
3f76745e
JM
2284/* Size (in elements) of increments by which we may expand the
2285 arange_table. */
2286#define ARANGE_TABLE_INCREMENT 64
71dfc51f 2287
3f76745e
JM
2288/* A pointer to the base of a list of pending types which we haven't
2289 generated DIEs for yet, but which we will have to come back to
2290 later on. */
469ac993 2291
3f76745e 2292static tree *pending_types_list;
71dfc51f 2293
3f76745e
JM
2294/* Number of elements currently allocated for the pending_types_list. */
2295static unsigned pending_types_allocated;
71dfc51f 2296
3f76745e
JM
2297/* Number of elements of pending_types_list currently in use. */
2298static unsigned pending_types;
a3f97cbb 2299
3f76745e
JM
2300/* Size (in elements) of increments by which we may expand the pending
2301 types list. Actually, a single hunk of space of this size should
2302 be enough for most typical programs. */
2303#define PENDING_TYPES_INCREMENT 64
71dfc51f 2304
3f76745e
JM
2305/* Record whether the function being analyzed contains inlined functions. */
2306static int current_function_has_inlines;
2307static int comp_unit_has_inlines;
71dfc51f 2308
3f76745e
JM
2309/* A pointer to the ..._DECL node which we have most recently been working
2310 on. We keep this around just in case something about it looks screwy and
2311 we want to tell the user what the source coordinates for the actual
2312 declaration are. */
2313static tree dwarf_last_decl;
a3f97cbb 2314
3f76745e 2315/* Forward declarations for functions defined in this file. */
71dfc51f 2316
3f76745e
JM
2317static void addr_const_to_string PROTO((char *, rtx));
2318static char *addr_to_string PROTO((rtx));
2319static int is_pseudo_reg PROTO((rtx));
2320static tree type_main_variant PROTO((tree));
2321static int is_tagged_type PROTO((tree));
2322static char *dwarf_tag_name PROTO((unsigned));
2323static char *dwarf_attr_name PROTO((unsigned));
2324static char *dwarf_form_name PROTO((unsigned));
2325static char *dwarf_stack_op_name PROTO((unsigned));
2326static char *dwarf_type_encoding_name PROTO((unsigned));
2327static tree decl_ultimate_origin PROTO((tree));
2328static tree block_ultimate_origin PROTO((tree));
2329static tree decl_class_context PROTO((tree));
2330static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref));
2331static void add_AT_flag PROTO((dw_die_ref,
2332 enum dwarf_attribute,
2333 unsigned));
2334static void add_AT_int PROTO((dw_die_ref,
2335 enum dwarf_attribute, long));
2336static void add_AT_unsigned PROTO((dw_die_ref,
2337 enum dwarf_attribute,
2338 unsigned long));
2339static void add_AT_long_long PROTO((dw_die_ref,
2340 enum dwarf_attribute,
2341 unsigned long, unsigned long));
2342static void add_AT_float PROTO((dw_die_ref,
2343 enum dwarf_attribute,
2344 unsigned, long *));
2345static void add_AT_string PROTO((dw_die_ref,
2346 enum dwarf_attribute, char *));
2347static void add_AT_die_ref PROTO((dw_die_ref,
2348 enum dwarf_attribute,
2349 dw_die_ref));
2350static void add_AT_fde_ref PROTO((dw_die_ref,
2351 enum dwarf_attribute,
2352 unsigned));
2353static void add_AT_loc PROTO((dw_die_ref,
2354 enum dwarf_attribute,
2355 dw_loc_descr_ref));
2356static void add_AT_addr PROTO((dw_die_ref,
2357 enum dwarf_attribute, char *));
2358static void add_AT_lbl_id PROTO((dw_die_ref,
2359 enum dwarf_attribute, char *));
956d6950 2360static void add_AT_section_offset PROTO((dw_die_ref,
3f76745e
JM
2361 enum dwarf_attribute, char *));
2362static int is_extern_subr_die PROTO((dw_die_ref));
2363static dw_attr_ref get_AT PROTO((dw_die_ref,
2364 enum dwarf_attribute));
2365static char *get_AT_low_pc PROTO((dw_die_ref));
2366static char *get_AT_hi_pc PROTO((dw_die_ref));
2367static char *get_AT_string PROTO((dw_die_ref,
2368 enum dwarf_attribute));
2369static int get_AT_flag PROTO((dw_die_ref,
2370 enum dwarf_attribute));
2371static unsigned get_AT_unsigned PROTO((dw_die_ref,
2372 enum dwarf_attribute));
2373static int is_c_family PROTO((void));
2374static int is_fortran PROTO((void));
2375static void remove_AT PROTO((dw_die_ref,
2376 enum dwarf_attribute));
2377static void remove_children PROTO((dw_die_ref));
2378static void add_child_die PROTO((dw_die_ref, dw_die_ref));
2379static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref));
2380static dw_die_ref lookup_type_die PROTO((tree));
2381static void equate_type_number_to_die PROTO((tree, dw_die_ref));
2382static dw_die_ref lookup_decl_die PROTO((tree));
2383static void equate_decl_number_to_die PROTO((tree, dw_die_ref));
2384static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom,
2385 unsigned long, unsigned long));
2386static void add_loc_descr PROTO((dw_loc_descr_ref *,
2387 dw_loc_descr_ref));
2388static void print_spaces PROTO((FILE *));
2389static void print_die PROTO((dw_die_ref, FILE *));
2390static void print_dwarf_line_table PROTO((FILE *));
956d6950 2391static void add_sibling_attributes PROTO((dw_die_ref));
3f76745e
JM
2392static void build_abbrev_table PROTO((dw_die_ref));
2393static unsigned long size_of_string PROTO((char *));
2394static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
2395static unsigned long size_of_locs PROTO((dw_loc_descr_ref));
2396static int constant_size PROTO((long unsigned));
2397static unsigned long size_of_die PROTO((dw_die_ref));
2398static void calc_die_sizes PROTO((dw_die_ref));
2399static unsigned long size_of_prolog PROTO((void));
2400static unsigned long size_of_line_info PROTO((void));
2401static unsigned long size_of_pubnames PROTO((void));
2402static unsigned long size_of_aranges PROTO((void));
2403static enum dwarf_form value_format PROTO((dw_val_ref));
2404static void output_value_format PROTO((dw_val_ref));
2405static void output_abbrev_section PROTO((void));
2406static void output_loc_operands PROTO((dw_loc_descr_ref));
2407static unsigned long sibling_offset PROTO((dw_die_ref));
2408static void output_die PROTO((dw_die_ref));
2409static void output_compilation_unit_header PROTO((void));
2410static char *dwarf2_name PROTO((tree, int));
2411static void add_pubname PROTO((tree, dw_die_ref));
2412static void output_pubnames PROTO((void));
2413static void add_arrange PROTO((tree, dw_die_ref));
2414static void output_arranges PROTO((void));
2415static void output_line_info PROTO((void));
2416static int is_body_block PROTO((tree));
2417static dw_die_ref base_type_die PROTO((tree));
2418static tree root_type PROTO((tree));
2419static int is_base_type PROTO((tree));
2420static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref));
2421static int type_is_enum PROTO((tree));
4401bf24 2422static dw_loc_descr_ref reg_loc_descriptor PROTO((rtx));
3f76745e
JM
2423static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
2424static int is_based_loc PROTO((rtx));
2425static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx));
4401bf24 2426static dw_loc_descr_ref concat_loc_descriptor PROTO((rtx, rtx));
3f76745e
JM
2427static dw_loc_descr_ref loc_descriptor PROTO((rtx));
2428static unsigned ceiling PROTO((unsigned, unsigned));
2429static tree field_type PROTO((tree));
2430static unsigned simple_type_align_in_bits PROTO((tree));
2431static unsigned simple_type_size_in_bits PROTO((tree));
2432static unsigned field_byte_offset PROTO((tree));
ef76d03b
JW
2433static void add_AT_location_description PROTO((dw_die_ref,
2434 enum dwarf_attribute, rtx));
3f76745e
JM
2435static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
2436static void add_const_value_attribute PROTO((dw_die_ref, rtx));
2437static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
2438static void add_name_attribute PROTO((dw_die_ref, char *));
2439static void add_bound_info PROTO((dw_die_ref,
2440 enum dwarf_attribute, tree));
2441static void add_subscript_info PROTO((dw_die_ref, tree));
2442static void add_byte_size_attribute PROTO((dw_die_ref, tree));
2443static void add_bit_offset_attribute PROTO((dw_die_ref, tree));
2444static void add_bit_size_attribute PROTO((dw_die_ref, tree));
2445static void add_prototyped_attribute PROTO((dw_die_ref, tree));
2446static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
2447static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
2448static void add_src_coords_attributes PROTO((dw_die_ref, tree));
2449static void ad_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
2450static void push_decl_scope PROTO((tree));
2451static dw_die_ref scope_die_for PROTO((tree, dw_die_ref));
2452static void pop_decl_scope PROTO((void));
2453static void add_type_attribute PROTO((dw_die_ref, tree, int, int,
2454 dw_die_ref));
2455static char *type_tag PROTO((tree));
2456static tree member_declared_type PROTO((tree));
2457static char *decl_start_label PROTO((tree));
2458static void gen_arrqay_type_die PROTO((tree, dw_die_ref));
2459static void gen_set_type_die PROTO((tree, dw_die_ref));
2460static void gen_entry_point_die PROTO((tree, dw_die_ref));
2461static void pend_type PROTO((tree));
2462static void output_pending_types_for_scope PROTO((dw_die_ref));
2463static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
2464static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
2465static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
2466static void gen_enumeration_type_die PROTO((tree, dw_die_ref));
2467static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
2468static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
2469static void gen_formal_types_die PROTO((tree, dw_die_ref));
2470static void gen_subprogram_die PROTO((tree, dw_die_ref));
2471static void gen_variable_die PROTO((tree, dw_die_ref));
2472static void gen_label_die PROTO((tree, dw_die_ref));
2473static void gen_lexical_block_die PROTO((tree, dw_die_ref, int));
2474static void gen_inlined_subprogram_die PROTO((tree, dw_die_ref, int));
2475static void gen_field_die PROTO((tree, dw_die_ref));
2476static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref));
2477static void gen_compile_unit_die PROTO((char *));
2478static void gen_string_type_die PROTO((tree, dw_die_ref));
2479static void gen_inheritance_die PROTO((tree, dw_die_ref));
2480static void gen_member_die PROTO((tree, dw_die_ref));
2481static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
2482static void gen_subroutine_type_die PROTO((tree, dw_die_ref));
2483static void gen_typedef_die PROTO((tree, dw_die_ref));
2484static void gen_type_die PROTO((tree, dw_die_ref));
2485static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
2486static void gen_block_die PROTO((tree, dw_die_ref, int));
2487static void decls_for_scope PROTO((tree, dw_die_ref, int));
2488static int is_redundant_typedef PROTO((tree));
2489static void gen_decl_die PROTO((tree, dw_die_ref));
2490static unsigned lookup_filename PROTO((char *));
71dfc51f 2491
3f76745e 2492/* Section names used to hold DWARF debugging information. */
c53aa195
JM
2493#ifndef DEBUG_INFO_SECTION
2494#define DEBUG_INFO_SECTION ".debug_info"
3f76745e
JM
2495#endif
2496#ifndef ABBREV_SECTION
2497#define ABBREV_SECTION ".debug_abbrev"
2498#endif
2499#ifndef ARANGES_SECTION
2500#define ARANGES_SECTION ".debug_aranges"
2501#endif
2502#ifndef DW_MACINFO_SECTION
2503#define DW_MACINFO_SECTION ".debug_macinfo"
2504#endif
c53aa195
JM
2505#ifndef DEBUG_LINE_SECTION
2506#define DEBUG_LINE_SECTION ".debug_line"
3f76745e
JM
2507#endif
2508#ifndef LOC_SECTION
2509#define LOC_SECTION ".debug_loc"
2510#endif
2511#ifndef PUBNAMES_SECTION
2512#define PUBNAMES_SECTION ".debug_pubnames"
2513#endif
2514#ifndef STR_SECTION
2515#define STR_SECTION ".debug_str"
2516#endif
a3f97cbb 2517
956d6950 2518/* Standard ELF section names for compiled code and data. */
3f76745e
JM
2519#ifndef TEXT_SECTION
2520#define TEXT_SECTION ".text"
2521#endif
2522#ifndef DATA_SECTION
2523#define DATA_SECTION ".data"
2524#endif
2525#ifndef BSS_SECTION
2526#define BSS_SECTION ".bss"
2527#endif
71dfc51f 2528
a3f97cbb 2529
3f76745e
JM
2530/* Definitions of defaults for formats and names of various special
2531 (artificial) labels which may be generated within this file (when the -g
2532 options is used and DWARF_DEBUGGING_INFO is in effect.
2533 If necessary, these may be overridden from within the tm.h file, but
2534 typically, overriding these defaults is unnecessary. */
a3f97cbb 2535
257ebd1f 2536static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
71dfc51f 2537
3f76745e
JM
2538#ifndef TEXT_END_LABEL
2539#define TEXT_END_LABEL "Letext"
2540#endif
2541#ifndef DATA_END_LABEL
2542#define DATA_END_LABEL "Ledata"
2543#endif
2544#ifndef BSS_END_LABEL
2545#define BSS_END_LABEL "Lebss"
2546#endif
2547#ifndef INSN_LABEL_FMT
2548#define INSN_LABEL_FMT "LI%u_"
2549#endif
2550#ifndef BLOCK_BEGIN_LABEL
2551#define BLOCK_BEGIN_LABEL "LBB"
2552#endif
2553#ifndef BLOCK_END_LABEL
2554#define BLOCK_END_LABEL "LBE"
2555#endif
2556#ifndef BODY_BEGIN_LABEL
2557#define BODY_BEGIN_LABEL "Lbb"
2558#endif
2559#ifndef BODY_END_LABEL
2560#define BODY_END_LABEL "Lbe"
2561#endif
2562#ifndef LINE_CODE_LABEL
2563#define LINE_CODE_LABEL "LM"
2564#endif
2565#ifndef SEPARATE_LINE_CODE_LABEL
2566#define SEPARATE_LINE_CODE_LABEL "LSM"
2567#endif
71dfc51f 2568
3f76745e
JM
2569/* Convert a reference to the assembler name of a C-level name. This
2570 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2571 a string rather than writing to a file. */
2572#ifndef ASM_NAME_TO_STRING
2573#define ASM_NAME_TO_STRING(STR, NAME) \
2574 do { \
2575 if ((NAME)[0] == '*') \
2576 strcpy (STR, NAME+1); \
2577 else \
2578 strcpy (STR, NAME); \
2579 } \
2580 while (0)
2581#endif
2582\f
2583/* Convert an integer constant expression into assembler syntax. Addition
2584 and subtraction are the only arithmetic that may appear in these
2585 expressions. This is an adaptation of output_addr_const in final.c.
2586 Here, the target of the conversion is a string buffer. We can't use
2587 output_addr_const directly, because it writes to a file. */
71dfc51f 2588
3f76745e
JM
2589static void
2590addr_const_to_string (str, x)
2591 char *str;
2592 rtx x;
a3f97cbb 2593{
3f76745e
JM
2594 char buf1[256];
2595 char buf2[256];
71dfc51f 2596
3f76745e
JM
2597restart:
2598 str[0] = '\0';
2599 switch (GET_CODE (x))
2600 {
2601 case PC:
2602 if (flag_pic)
2603 strcat (str, ",");
2604 else
2605 abort ();
2606 break;
71dfc51f 2607
3f76745e
JM
2608 case SYMBOL_REF:
2609 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
2610 strcat (str, buf1);
2611 break;
a3f97cbb 2612
3f76745e
JM
2613 case LABEL_REF:
2614 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2615 ASM_NAME_TO_STRING (buf2, buf1);
2616 strcat (str, buf2);
2617 break;
71dfc51f 2618
3f76745e
JM
2619 case CODE_LABEL:
2620 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
2621 ASM_NAME_TO_STRING (buf2, buf1);
2622 strcat (str, buf2);
2623 break;
71dfc51f 2624
3f76745e
JM
2625 case CONST_INT:
2626 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2627 strcat (str, buf1);
2628 break;
a3f97cbb 2629
3f76745e
JM
2630 case CONST:
2631 /* This used to output parentheses around the expression, but that does
2632 not work on the 386 (either ATT or BSD assembler). */
2633 addr_const_to_string (buf1, XEXP (x, 0));
2634 strcat (str, buf1);
2635 break;
71dfc51f 2636
3f76745e
JM
2637 case CONST_DOUBLE:
2638 if (GET_MODE (x) == VOIDmode)
2639 {
2640 /* We can use %d if the number is one word and positive. */
2641 if (CONST_DOUBLE_HIGH (x))
2642 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
2643 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2644 else if (CONST_DOUBLE_LOW (x) < 0)
2645 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
2646 else
2647 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
2648 CONST_DOUBLE_LOW (x));
2649 strcat (str, buf1);
2650 }
2651 else
2652 /* We can't handle floating point constants; PRINT_OPERAND must
2653 handle them. */
2654 output_operand_lossage ("floating constant misused");
2655 break;
71dfc51f 2656
3f76745e
JM
2657 case PLUS:
2658 /* Some assemblers need integer constants to appear last (eg masm). */
2659 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
a3f97cbb 2660 {
3f76745e
JM
2661 addr_const_to_string (buf1, XEXP (x, 1));
2662 strcat (str, buf1);
2663 if (INTVAL (XEXP (x, 0)) >= 0)
2664 strcat (str, "+");
2665
2666 addr_const_to_string (buf1, XEXP (x, 0));
2667 strcat (str, buf1);
a3f97cbb 2668 }
3f76745e
JM
2669 else
2670 {
2671 addr_const_to_string (buf1, XEXP (x, 0));
2672 strcat (str, buf1);
2673 if (INTVAL (XEXP (x, 1)) >= 0)
2674 strcat (str, "+");
71dfc51f 2675
3f76745e
JM
2676 addr_const_to_string (buf1, XEXP (x, 1));
2677 strcat (str, buf1);
2678 }
2679 break;
a3f97cbb 2680
3f76745e
JM
2681 case MINUS:
2682 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2683 can't handle that. */
2684 x = simplify_subtraction (x);
2685 if (GET_CODE (x) != MINUS)
2686 goto restart;
71dfc51f 2687
3f76745e
JM
2688 addr_const_to_string (buf1, XEXP (x, 0));
2689 strcat (str, buf1);
2690 strcat (str, "-");
2691 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2692 && INTVAL (XEXP (x, 1)) < 0)
a3f97cbb 2693 {
3f76745e
JM
2694 strcat (str, ASM_OPEN_PAREN);
2695 addr_const_to_string (buf1, XEXP (x, 1));
2696 strcat (str, buf1);
2697 strcat (str, ASM_CLOSE_PAREN);
2698 }
2699 else
2700 {
2701 addr_const_to_string (buf1, XEXP (x, 1));
2702 strcat (str, buf1);
a3f97cbb 2703 }
3f76745e 2704 break;
71dfc51f 2705
3f76745e
JM
2706 case ZERO_EXTEND:
2707 case SIGN_EXTEND:
2708 addr_const_to_string (buf1, XEXP (x, 0));
2709 strcat (str, buf1);
2710 break;
71dfc51f 2711
3f76745e
JM
2712 default:
2713 output_operand_lossage ("invalid expression as operand");
2714 }
d291dd49
JM
2715}
2716
3f76745e
JM
2717/* Convert an address constant to a string, and return a pointer to
2718 a copy of the result, located on the heap. */
71dfc51f 2719
3f76745e
JM
2720static char *
2721addr_to_string (x)
2722 rtx x;
d291dd49 2723{
3f76745e
JM
2724 char buf[1024];
2725 addr_const_to_string (buf, x);
2726 return xstrdup (buf);
d291dd49
JM
2727}
2728
956d6950 2729/* Test if rtl node points to a pseudo register. */
71dfc51f 2730
3f76745e
JM
2731static inline int
2732is_pseudo_reg (rtl)
2733 register rtx rtl;
d291dd49 2734{
3f76745e
JM
2735 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2736 || ((GET_CODE (rtl) == SUBREG)
2737 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
d291dd49
JM
2738}
2739
3f76745e
JM
2740/* Return a reference to a type, with its const and volatile qualifiers
2741 removed. */
71dfc51f 2742
3f76745e
JM
2743static inline tree
2744type_main_variant (type)
2745 register tree type;
d291dd49 2746{
3f76745e 2747 type = TYPE_MAIN_VARIANT (type);
71dfc51f 2748
3f76745e
JM
2749 /* There really should be only one main variant among any group of variants
2750 of a given type (and all of the MAIN_VARIANT values for all members of
2751 the group should point to that one type) but sometimes the C front-end
2752 messes this up for array types, so we work around that bug here. */
71dfc51f 2753
3f76745e
JM
2754 if (TREE_CODE (type) == ARRAY_TYPE)
2755 while (type != TYPE_MAIN_VARIANT (type))
2756 type = TYPE_MAIN_VARIANT (type);
2757
2758 return type;
a3f97cbb
JW
2759}
2760
3f76745e 2761/* Return non-zero if the given type node represents a tagged type. */
71dfc51f
RK
2762
2763static inline int
3f76745e
JM
2764is_tagged_type (type)
2765 register tree type;
bdb669cb 2766{
3f76745e 2767 register enum tree_code code = TREE_CODE (type);
71dfc51f 2768
3f76745e
JM
2769 return (code == RECORD_TYPE || code == UNION_TYPE
2770 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
bdb669cb
JM
2771}
2772
3f76745e 2773/* Convert a DIE tag into its string name. */
71dfc51f 2774
3f76745e
JM
2775static char *
2776dwarf_tag_name (tag)
2777 register unsigned tag;
bdb669cb 2778{
3f76745e
JM
2779 switch (tag)
2780 {
2781 case DW_TAG_padding:
2782 return "DW_TAG_padding";
2783 case DW_TAG_array_type:
2784 return "DW_TAG_array_type";
2785 case DW_TAG_class_type:
2786 return "DW_TAG_class_type";
2787 case DW_TAG_entry_point:
2788 return "DW_TAG_entry_point";
2789 case DW_TAG_enumeration_type:
2790 return "DW_TAG_enumeration_type";
2791 case DW_TAG_formal_parameter:
2792 return "DW_TAG_formal_parameter";
2793 case DW_TAG_imported_declaration:
2794 return "DW_TAG_imported_declaration";
2795 case DW_TAG_label:
2796 return "DW_TAG_label";
2797 case DW_TAG_lexical_block:
2798 return "DW_TAG_lexical_block";
2799 case DW_TAG_member:
2800 return "DW_TAG_member";
2801 case DW_TAG_pointer_type:
2802 return "DW_TAG_pointer_type";
2803 case DW_TAG_reference_type:
2804 return "DW_TAG_reference_type";
2805 case DW_TAG_compile_unit:
2806 return "DW_TAG_compile_unit";
2807 case DW_TAG_string_type:
2808 return "DW_TAG_string_type";
2809 case DW_TAG_structure_type:
2810 return "DW_TAG_structure_type";
2811 case DW_TAG_subroutine_type:
2812 return "DW_TAG_subroutine_type";
2813 case DW_TAG_typedef:
2814 return "DW_TAG_typedef";
2815 case DW_TAG_union_type:
2816 return "DW_TAG_union_type";
2817 case DW_TAG_unspecified_parameters:
2818 return "DW_TAG_unspecified_parameters";
2819 case DW_TAG_variant:
2820 return "DW_TAG_variant";
2821 case DW_TAG_common_block:
2822 return "DW_TAG_common_block";
2823 case DW_TAG_common_inclusion:
2824 return "DW_TAG_common_inclusion";
2825 case DW_TAG_inheritance:
2826 return "DW_TAG_inheritance";
2827 case DW_TAG_inlined_subroutine:
2828 return "DW_TAG_inlined_subroutine";
2829 case DW_TAG_module:
2830 return "DW_TAG_module";
2831 case DW_TAG_ptr_to_member_type:
2832 return "DW_TAG_ptr_to_member_type";
2833 case DW_TAG_set_type:
2834 return "DW_TAG_set_type";
2835 case DW_TAG_subrange_type:
2836 return "DW_TAG_subrange_type";
2837 case DW_TAG_with_stmt:
2838 return "DW_TAG_with_stmt";
2839 case DW_TAG_access_declaration:
2840 return "DW_TAG_access_declaration";
2841 case DW_TAG_base_type:
2842 return "DW_TAG_base_type";
2843 case DW_TAG_catch_block:
2844 return "DW_TAG_catch_block";
2845 case DW_TAG_const_type:
2846 return "DW_TAG_const_type";
2847 case DW_TAG_constant:
2848 return "DW_TAG_constant";
2849 case DW_TAG_enumerator:
2850 return "DW_TAG_enumerator";
2851 case DW_TAG_file_type:
2852 return "DW_TAG_file_type";
2853 case DW_TAG_friend:
2854 return "DW_TAG_friend";
2855 case DW_TAG_namelist:
2856 return "DW_TAG_namelist";
2857 case DW_TAG_namelist_item:
2858 return "DW_TAG_namelist_item";
2859 case DW_TAG_packed_type:
2860 return "DW_TAG_packed_type";
2861 case DW_TAG_subprogram:
2862 return "DW_TAG_subprogram";
2863 case DW_TAG_template_type_param:
2864 return "DW_TAG_template_type_param";
2865 case DW_TAG_template_value_param:
2866 return "DW_TAG_template_value_param";
2867 case DW_TAG_thrown_type:
2868 return "DW_TAG_thrown_type";
2869 case DW_TAG_try_block:
2870 return "DW_TAG_try_block";
2871 case DW_TAG_variant_part:
2872 return "DW_TAG_variant_part";
2873 case DW_TAG_variable:
2874 return "DW_TAG_variable";
2875 case DW_TAG_volatile_type:
2876 return "DW_TAG_volatile_type";
2877 case DW_TAG_MIPS_loop:
2878 return "DW_TAG_MIPS_loop";
2879 case DW_TAG_format_label:
2880 return "DW_TAG_format_label";
2881 case DW_TAG_function_template:
2882 return "DW_TAG_function_template";
2883 case DW_TAG_class_template:
2884 return "DW_TAG_class_template";
2885 default:
2886 return "DW_TAG_<unknown>";
2887 }
bdb669cb 2888}
a3f97cbb 2889
3f76745e 2890/* Convert a DWARF attribute code into its string name. */
71dfc51f 2891
3f76745e
JM
2892static char *
2893dwarf_attr_name (attr)
2894 register unsigned attr;
4b674448 2895{
3f76745e 2896 switch (attr)
4b674448 2897 {
3f76745e
JM
2898 case DW_AT_sibling:
2899 return "DW_AT_sibling";
2900 case DW_AT_location:
2901 return "DW_AT_location";
2902 case DW_AT_name:
2903 return "DW_AT_name";
2904 case DW_AT_ordering:
2905 return "DW_AT_ordering";
2906 case DW_AT_subscr_data:
2907 return "DW_AT_subscr_data";
2908 case DW_AT_byte_size:
2909 return "DW_AT_byte_size";
2910 case DW_AT_bit_offset:
2911 return "DW_AT_bit_offset";
2912 case DW_AT_bit_size:
2913 return "DW_AT_bit_size";
2914 case DW_AT_element_list:
2915 return "DW_AT_element_list";
2916 case DW_AT_stmt_list:
2917 return "DW_AT_stmt_list";
2918 case DW_AT_low_pc:
2919 return "DW_AT_low_pc";
2920 case DW_AT_high_pc:
2921 return "DW_AT_high_pc";
2922 case DW_AT_language:
2923 return "DW_AT_language";
2924 case DW_AT_member:
2925 return "DW_AT_member";
2926 case DW_AT_discr:
2927 return "DW_AT_discr";
2928 case DW_AT_discr_value:
2929 return "DW_AT_discr_value";
2930 case DW_AT_visibility:
2931 return "DW_AT_visibility";
2932 case DW_AT_import:
2933 return "DW_AT_import";
2934 case DW_AT_string_length:
2935 return "DW_AT_string_length";
2936 case DW_AT_common_reference:
2937 return "DW_AT_common_reference";
2938 case DW_AT_comp_dir:
2939 return "DW_AT_comp_dir";
2940 case DW_AT_const_value:
2941 return "DW_AT_const_value";
2942 case DW_AT_containing_type:
2943 return "DW_AT_containing_type";
2944 case DW_AT_default_value:
2945 return "DW_AT_default_value";
2946 case DW_AT_inline:
2947 return "DW_AT_inline";
2948 case DW_AT_is_optional:
2949 return "DW_AT_is_optional";
2950 case DW_AT_lower_bound:
2951 return "DW_AT_lower_bound";
2952 case DW_AT_producer:
2953 return "DW_AT_producer";
2954 case DW_AT_prototyped:
2955 return "DW_AT_prototyped";
2956 case DW_AT_return_addr:
2957 return "DW_AT_return_addr";
2958 case DW_AT_start_scope:
2959 return "DW_AT_start_scope";
2960 case DW_AT_stride_size:
2961 return "DW_AT_stride_size";
2962 case DW_AT_upper_bound:
2963 return "DW_AT_upper_bound";
2964 case DW_AT_abstract_origin:
2965 return "DW_AT_abstract_origin";
2966 case DW_AT_accessibility:
2967 return "DW_AT_accessibility";
2968 case DW_AT_address_class:
2969 return "DW_AT_address_class";
2970 case DW_AT_artificial:
2971 return "DW_AT_artificial";
2972 case DW_AT_base_types:
2973 return "DW_AT_base_types";
2974 case DW_AT_calling_convention:
2975 return "DW_AT_calling_convention";
2976 case DW_AT_count:
2977 return "DW_AT_count";
2978 case DW_AT_data_member_location:
2979 return "DW_AT_data_member_location";
2980 case DW_AT_decl_column:
2981 return "DW_AT_decl_column";
2982 case DW_AT_decl_file:
2983 return "DW_AT_decl_file";
2984 case DW_AT_decl_line:
2985 return "DW_AT_decl_line";
2986 case DW_AT_declaration:
2987 return "DW_AT_declaration";
2988 case DW_AT_discr_list:
2989 return "DW_AT_discr_list";
2990 case DW_AT_encoding:
2991 return "DW_AT_encoding";
2992 case DW_AT_external:
2993 return "DW_AT_external";
2994 case DW_AT_frame_base:
2995 return "DW_AT_frame_base";
2996 case DW_AT_friend:
2997 return "DW_AT_friend";
2998 case DW_AT_identifier_case:
2999 return "DW_AT_identifier_case";
3000 case DW_AT_macro_info:
3001 return "DW_AT_macro_info";
3002 case DW_AT_namelist_items:
3003 return "DW_AT_namelist_items";
3004 case DW_AT_priority:
3005 return "DW_AT_priority";
3006 case DW_AT_segment:
3007 return "DW_AT_segment";
3008 case DW_AT_specification:
3009 return "DW_AT_specification";
3010 case DW_AT_static_link:
3011 return "DW_AT_static_link";
3012 case DW_AT_type:
3013 return "DW_AT_type";
3014 case DW_AT_use_location:
3015 return "DW_AT_use_location";
3016 case DW_AT_variable_parameter:
3017 return "DW_AT_variable_parameter";
3018 case DW_AT_virtuality:
3019 return "DW_AT_virtuality";
3020 case DW_AT_vtable_elem_location:
3021 return "DW_AT_vtable_elem_location";
71dfc51f 3022
3f76745e
JM
3023 case DW_AT_MIPS_fde:
3024 return "DW_AT_MIPS_fde";
3025 case DW_AT_MIPS_loop_begin:
3026 return "DW_AT_MIPS_loop_begin";
3027 case DW_AT_MIPS_tail_loop_begin:
3028 return "DW_AT_MIPS_tail_loop_begin";
3029 case DW_AT_MIPS_epilog_begin:
3030 return "DW_AT_MIPS_epilog_begin";
3031 case DW_AT_MIPS_loop_unroll_factor:
3032 return "DW_AT_MIPS_loop_unroll_factor";
3033 case DW_AT_MIPS_software_pipeline_depth:
3034 return "DW_AT_MIPS_software_pipeline_depth";
3035 case DW_AT_MIPS_linkage_name:
3036 return "DW_AT_MIPS_linkage_name";
3037 case DW_AT_MIPS_stride:
3038 return "DW_AT_MIPS_stride";
3039 case DW_AT_MIPS_abstract_name:
3040 return "DW_AT_MIPS_abstract_name";
3041 case DW_AT_MIPS_clone_origin:
3042 return "DW_AT_MIPS_clone_origin";
3043 case DW_AT_MIPS_has_inlines:
3044 return "DW_AT_MIPS_has_inlines";
71dfc51f 3045
3f76745e
JM
3046 case DW_AT_sf_names:
3047 return "DW_AT_sf_names";
3048 case DW_AT_src_info:
3049 return "DW_AT_src_info";
3050 case DW_AT_mac_info:
3051 return "DW_AT_mac_info";
3052 case DW_AT_src_coords:
3053 return "DW_AT_src_coords";
3054 case DW_AT_body_begin:
3055 return "DW_AT_body_begin";
3056 case DW_AT_body_end:
3057 return "DW_AT_body_end";
3058 default:
3059 return "DW_AT_<unknown>";
4b674448
JM
3060 }
3061}
3062
3f76745e 3063/* Convert a DWARF value form code into its string name. */
71dfc51f 3064
3f76745e
JM
3065static char *
3066dwarf_form_name (form)
3067 register unsigned form;
4b674448 3068{
3f76745e 3069 switch (form)
4b674448 3070 {
3f76745e
JM
3071 case DW_FORM_addr:
3072 return "DW_FORM_addr";
3073 case DW_FORM_block2:
3074 return "DW_FORM_block2";
3075 case DW_FORM_block4:
3076 return "DW_FORM_block4";
3077 case DW_FORM_data2:
3078 return "DW_FORM_data2";
3079 case DW_FORM_data4:
3080 return "DW_FORM_data4";
3081 case DW_FORM_data8:
3082 return "DW_FORM_data8";
3083 case DW_FORM_string:
3084 return "DW_FORM_string";
3085 case DW_FORM_block:
3086 return "DW_FORM_block";
3087 case DW_FORM_block1:
3088 return "DW_FORM_block1";
3089 case DW_FORM_data1:
3090 return "DW_FORM_data1";
3091 case DW_FORM_flag:
3092 return "DW_FORM_flag";
3093 case DW_FORM_sdata:
3094 return "DW_FORM_sdata";
3095 case DW_FORM_strp:
3096 return "DW_FORM_strp";
3097 case DW_FORM_udata:
3098 return "DW_FORM_udata";
3099 case DW_FORM_ref_addr:
3100 return "DW_FORM_ref_addr";
3101 case DW_FORM_ref1:
3102 return "DW_FORM_ref1";
3103 case DW_FORM_ref2:
3104 return "DW_FORM_ref2";
3105 case DW_FORM_ref4:
3106 return "DW_FORM_ref4";
3107 case DW_FORM_ref8:
3108 return "DW_FORM_ref8";
3109 case DW_FORM_ref_udata:
3110 return "DW_FORM_ref_udata";
3111 case DW_FORM_indirect:
3112 return "DW_FORM_indirect";
3113 default:
3114 return "DW_FORM_<unknown>";
4b674448
JM
3115 }
3116}
3117
3f76745e 3118/* Convert a DWARF stack opcode into its string name. */
71dfc51f 3119
3f76745e
JM
3120static char *
3121dwarf_stack_op_name (op)
3122 register unsigned op;
a3f97cbb 3123{
3f76745e 3124 switch (op)
a3f97cbb 3125 {
3f76745e
JM
3126 case DW_OP_addr:
3127 return "DW_OP_addr";
3128 case DW_OP_deref:
3129 return "DW_OP_deref";
3130 case DW_OP_const1u:
3131 return "DW_OP_const1u";
3132 case DW_OP_const1s:
3133 return "DW_OP_const1s";
3134 case DW_OP_const2u:
3135 return "DW_OP_const2u";
3136 case DW_OP_const2s:
3137 return "DW_OP_const2s";
3138 case DW_OP_const4u:
3139 return "DW_OP_const4u";
3140 case DW_OP_const4s:
3141 return "DW_OP_const4s";
3142 case DW_OP_const8u:
3143 return "DW_OP_const8u";
3144 case DW_OP_const8s:
3145 return "DW_OP_const8s";
3146 case DW_OP_constu:
3147 return "DW_OP_constu";
3148 case DW_OP_consts:
3149 return "DW_OP_consts";
3150 case DW_OP_dup:
3151 return "DW_OP_dup";
3152 case DW_OP_drop:
3153 return "DW_OP_drop";
3154 case DW_OP_over:
3155 return "DW_OP_over";
3156 case DW_OP_pick:
3157 return "DW_OP_pick";
3158 case DW_OP_swap:
3159 return "DW_OP_swap";
3160 case DW_OP_rot:
3161 return "DW_OP_rot";
3162 case DW_OP_xderef:
3163 return "DW_OP_xderef";
3164 case DW_OP_abs:
3165 return "DW_OP_abs";
3166 case DW_OP_and:
3167 return "DW_OP_and";
3168 case DW_OP_div:
3169 return "DW_OP_div";
3170 case DW_OP_minus:
3171 return "DW_OP_minus";
3172 case DW_OP_mod:
3173 return "DW_OP_mod";
3174 case DW_OP_mul:
3175 return "DW_OP_mul";
3176 case DW_OP_neg:
3177 return "DW_OP_neg";
3178 case DW_OP_not:
3179 return "DW_OP_not";
3180 case DW_OP_or:
3181 return "DW_OP_or";
3182 case DW_OP_plus:
3183 return "DW_OP_plus";
3184 case DW_OP_plus_uconst:
3185 return "DW_OP_plus_uconst";
3186 case DW_OP_shl:
3187 return "DW_OP_shl";
3188 case DW_OP_shr:
3189 return "DW_OP_shr";
3190 case DW_OP_shra:
3191 return "DW_OP_shra";
3192 case DW_OP_xor:
3193 return "DW_OP_xor";
3194 case DW_OP_bra:
3195 return "DW_OP_bra";
3196 case DW_OP_eq:
3197 return "DW_OP_eq";
3198 case DW_OP_ge:
3199 return "DW_OP_ge";
3200 case DW_OP_gt:
3201 return "DW_OP_gt";
3202 case DW_OP_le:
3203 return "DW_OP_le";
3204 case DW_OP_lt:
3205 return "DW_OP_lt";
3206 case DW_OP_ne:
3207 return "DW_OP_ne";
3208 case DW_OP_skip:
3209 return "DW_OP_skip";
3210 case DW_OP_lit0:
3211 return "DW_OP_lit0";
3212 case DW_OP_lit1:
3213 return "DW_OP_lit1";
3214 case DW_OP_lit2:
3215 return "DW_OP_lit2";
3216 case DW_OP_lit3:
3217 return "DW_OP_lit3";
3218 case DW_OP_lit4:
3219 return "DW_OP_lit4";
3220 case DW_OP_lit5:
3221 return "DW_OP_lit5";
3222 case DW_OP_lit6:
3223 return "DW_OP_lit6";
3224 case DW_OP_lit7:
3225 return "DW_OP_lit7";
3226 case DW_OP_lit8:
3227 return "DW_OP_lit8";
3228 case DW_OP_lit9:
3229 return "DW_OP_lit9";
3230 case DW_OP_lit10:
3231 return "DW_OP_lit10";
3232 case DW_OP_lit11:
3233 return "DW_OP_lit11";
3234 case DW_OP_lit12:
3235 return "DW_OP_lit12";
3236 case DW_OP_lit13:
3237 return "DW_OP_lit13";
3238 case DW_OP_lit14:
3239 return "DW_OP_lit14";
3240 case DW_OP_lit15:
3241 return "DW_OP_lit15";
3242 case DW_OP_lit16:
3243 return "DW_OP_lit16";
3244 case DW_OP_lit17:
3245 return "DW_OP_lit17";
3246 case DW_OP_lit18:
3247 return "DW_OP_lit18";
3248 case DW_OP_lit19:
3249 return "DW_OP_lit19";
3250 case DW_OP_lit20:
3251 return "DW_OP_lit20";
3252 case DW_OP_lit21:
3253 return "DW_OP_lit21";
3254 case DW_OP_lit22:
3255 return "DW_OP_lit22";
3256 case DW_OP_lit23:
3257 return "DW_OP_lit23";
3258 case DW_OP_lit24:
3259 return "DW_OP_lit24";
3260 case DW_OP_lit25:
3261 return "DW_OP_lit25";
3262 case DW_OP_lit26:
3263 return "DW_OP_lit26";
3264 case DW_OP_lit27:
3265 return "DW_OP_lit27";
3266 case DW_OP_lit28:
3267 return "DW_OP_lit28";
3268 case DW_OP_lit29:
3269 return "DW_OP_lit29";
3270 case DW_OP_lit30:
3271 return "DW_OP_lit30";
3272 case DW_OP_lit31:
3273 return "DW_OP_lit31";
3274 case DW_OP_reg0:
3275 return "DW_OP_reg0";
3276 case DW_OP_reg1:
3277 return "DW_OP_reg1";
3278 case DW_OP_reg2:
3279 return "DW_OP_reg2";
3280 case DW_OP_reg3:
3281 return "DW_OP_reg3";
3282 case DW_OP_reg4:
3283 return "DW_OP_reg4";
3284 case DW_OP_reg5:
3285 return "DW_OP_reg5";
3286 case DW_OP_reg6:
3287 return "DW_OP_reg6";
3288 case DW_OP_reg7:
3289 return "DW_OP_reg7";
3290 case DW_OP_reg8:
3291 return "DW_OP_reg8";
3292 case DW_OP_reg9:
3293 return "DW_OP_reg9";
3294 case DW_OP_reg10:
3295 return "DW_OP_reg10";
3296 case DW_OP_reg11:
3297 return "DW_OP_reg11";
3298 case DW_OP_reg12:
3299 return "DW_OP_reg12";
3300 case DW_OP_reg13:
3301 return "DW_OP_reg13";
3302 case DW_OP_reg14:
3303 return "DW_OP_reg14";
3304 case DW_OP_reg15:
3305 return "DW_OP_reg15";
3306 case DW_OP_reg16:
3307 return "DW_OP_reg16";
3308 case DW_OP_reg17:
3309 return "DW_OP_reg17";
3310 case DW_OP_reg18:
3311 return "DW_OP_reg18";
3312 case DW_OP_reg19:
3313 return "DW_OP_reg19";
3314 case DW_OP_reg20:
3315 return "DW_OP_reg20";
3316 case DW_OP_reg21:
3317 return "DW_OP_reg21";
3318 case DW_OP_reg22:
3319 return "DW_OP_reg22";
3320 case DW_OP_reg23:
3321 return "DW_OP_reg23";
3322 case DW_OP_reg24:
3323 return "DW_OP_reg24";
3324 case DW_OP_reg25:
3325 return "DW_OP_reg25";
3326 case DW_OP_reg26:
3327 return "DW_OP_reg26";
3328 case DW_OP_reg27:
3329 return "DW_OP_reg27";
3330 case DW_OP_reg28:
3331 return "DW_OP_reg28";
3332 case DW_OP_reg29:
3333 return "DW_OP_reg29";
3334 case DW_OP_reg30:
3335 return "DW_OP_reg30";
3336 case DW_OP_reg31:
3337 return "DW_OP_reg31";
3338 case DW_OP_breg0:
3339 return "DW_OP_breg0";
3340 case DW_OP_breg1:
3341 return "DW_OP_breg1";
3342 case DW_OP_breg2:
3343 return "DW_OP_breg2";
3344 case DW_OP_breg3:
3345 return "DW_OP_breg3";
3346 case DW_OP_breg4:
3347 return "DW_OP_breg4";
3348 case DW_OP_breg5:
3349 return "DW_OP_breg5";
3350 case DW_OP_breg6:
3351 return "DW_OP_breg6";
3352 case DW_OP_breg7:
3353 return "DW_OP_breg7";
3354 case DW_OP_breg8:
3355 return "DW_OP_breg8";
3356 case DW_OP_breg9:
3357 return "DW_OP_breg9";
3358 case DW_OP_breg10:
3359 return "DW_OP_breg10";
3360 case DW_OP_breg11:
3361 return "DW_OP_breg11";
3362 case DW_OP_breg12:
3363 return "DW_OP_breg12";
3364 case DW_OP_breg13:
3365 return "DW_OP_breg13";
3366 case DW_OP_breg14:
3367 return "DW_OP_breg14";
3368 case DW_OP_breg15:
3369 return "DW_OP_breg15";
3370 case DW_OP_breg16:
3371 return "DW_OP_breg16";
3372 case DW_OP_breg17:
3373 return "DW_OP_breg17";
3374 case DW_OP_breg18:
3375 return "DW_OP_breg18";
3376 case DW_OP_breg19:
3377 return "DW_OP_breg19";
3378 case DW_OP_breg20:
3379 return "DW_OP_breg20";
3380 case DW_OP_breg21:
3381 return "DW_OP_breg21";
3382 case DW_OP_breg22:
3383 return "DW_OP_breg22";
3384 case DW_OP_breg23:
3385 return "DW_OP_breg23";
3386 case DW_OP_breg24:
3387 return "DW_OP_breg24";
3388 case DW_OP_breg25:
3389 return "DW_OP_breg25";
3390 case DW_OP_breg26:
3391 return "DW_OP_breg26";
3392 case DW_OP_breg27:
3393 return "DW_OP_breg27";
3394 case DW_OP_breg28:
3395 return "DW_OP_breg28";
3396 case DW_OP_breg29:
3397 return "DW_OP_breg29";
3398 case DW_OP_breg30:
3399 return "DW_OP_breg30";
3400 case DW_OP_breg31:
3401 return "DW_OP_breg31";
3402 case DW_OP_regx:
3403 return "DW_OP_regx";
3404 case DW_OP_fbreg:
3405 return "DW_OP_fbreg";
3406 case DW_OP_bregx:
3407 return "DW_OP_bregx";
3408 case DW_OP_piece:
3409 return "DW_OP_piece";
3410 case DW_OP_deref_size:
3411 return "DW_OP_deref_size";
3412 case DW_OP_xderef_size:
3413 return "DW_OP_xderef_size";
3414 case DW_OP_nop:
3415 return "DW_OP_nop";
3416 default:
3417 return "OP_<unknown>";
a3f97cbb
JW
3418 }
3419}
3420
3f76745e 3421/* Convert a DWARF type code into its string name. */
71dfc51f 3422
3f76745e
JM
3423static char *
3424dwarf_type_encoding_name (enc)
3425 register unsigned enc;
a3f97cbb 3426{
3f76745e 3427 switch (enc)
a3f97cbb 3428 {
3f76745e
JM
3429 case DW_ATE_address:
3430 return "DW_ATE_address";
3431 case DW_ATE_boolean:
3432 return "DW_ATE_boolean";
3433 case DW_ATE_complex_float:
3434 return "DW_ATE_complex_float";
3435 case DW_ATE_float:
3436 return "DW_ATE_float";
3437 case DW_ATE_signed:
3438 return "DW_ATE_signed";
3439 case DW_ATE_signed_char:
3440 return "DW_ATE_signed_char";
3441 case DW_ATE_unsigned:
3442 return "DW_ATE_unsigned";
3443 case DW_ATE_unsigned_char:
3444 return "DW_ATE_unsigned_char";
3445 default:
3446 return "DW_ATE_<unknown>";
3447 }
a3f97cbb 3448}
3f76745e
JM
3449\f
3450/* Determine the "ultimate origin" of a decl. The decl may be an inlined
3451 instance of an inlined instance of a decl which is local to an inline
3452 function, so we have to trace all of the way back through the origin chain
3453 to find out what sort of node actually served as the original seed for the
3454 given block. */
a3f97cbb 3455
3f76745e
JM
3456static tree
3457decl_ultimate_origin (decl)
3458 register tree decl;
a3f97cbb 3459{
3f76745e 3460 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
71dfc51f 3461
3f76745e
JM
3462 if (immediate_origin == NULL_TREE)
3463 return NULL_TREE;
3464 else
3465 {
3466 register tree ret_val;
3467 register tree lookahead = immediate_origin;
71dfc51f 3468
3f76745e
JM
3469 do
3470 {
3471 ret_val = lookahead;
3472 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
3473 }
3474 while (lookahead != NULL && lookahead != ret_val);
3475
3476 return ret_val;
3477 }
a3f97cbb
JW
3478}
3479
3f76745e
JM
3480/* Determine the "ultimate origin" of a block. The block may be an inlined
3481 instance of an inlined instance of a block which is local to an inline
3482 function, so we have to trace all of the way back through the origin chain
3483 to find out what sort of node actually served as the original seed for the
3484 given block. */
71dfc51f 3485
3f76745e
JM
3486static tree
3487block_ultimate_origin (block)
3488 register tree block;
a3f97cbb 3489{
3f76745e 3490 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
71dfc51f 3491
3f76745e
JM
3492 if (immediate_origin == NULL_TREE)
3493 return NULL_TREE;
3494 else
3495 {
3496 register tree ret_val;
3497 register tree lookahead = immediate_origin;
71dfc51f 3498
3f76745e
JM
3499 do
3500 {
3501 ret_val = lookahead;
3502 lookahead = (TREE_CODE (ret_val) == BLOCK)
3503 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3504 : NULL;
3505 }
3506 while (lookahead != NULL && lookahead != ret_val);
3507
3508 return ret_val;
3509 }
a3f97cbb
JW
3510}
3511
3f76745e
JM
3512/* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3513 of a virtual function may refer to a base class, so we check the 'this'
3514 parameter. */
71dfc51f 3515
3f76745e
JM
3516static tree
3517decl_class_context (decl)
3518 tree decl;
a3f97cbb 3519{
3f76745e 3520 tree context = NULL_TREE;
71dfc51f 3521
3f76745e
JM
3522 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3523 context = DECL_CONTEXT (decl);
3524 else
3525 context = TYPE_MAIN_VARIANT
3526 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
71dfc51f 3527
3f76745e
JM
3528 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3529 context = NULL_TREE;
3530
3531 return context;
a3f97cbb
JW
3532}
3533\f
3f76745e 3534/* Add an attribute/value pair to a DIE */
71dfc51f
RK
3535
3536static inline void
3f76745e
JM
3537add_dwarf_attr (die, attr)
3538 register dw_die_ref die;
3539 register dw_attr_ref attr;
a3f97cbb 3540{
3f76745e 3541 if (die != NULL && attr != NULL)
a3f97cbb 3542 {
3f76745e 3543 if (die->die_attr == NULL)
a3f97cbb 3544 {
3f76745e
JM
3545 die->die_attr = attr;
3546 die->die_attr_last = attr;
3547 }
3548 else
3549 {
3550 die->die_attr_last->dw_attr_next = attr;
3551 die->die_attr_last = attr;
a3f97cbb 3552 }
a3f97cbb
JW
3553 }
3554}
3555
3f76745e 3556/* Add a flag value attribute to a DIE. */
71dfc51f 3557
3f76745e
JM
3558static inline void
3559add_AT_flag (die, attr_kind, flag)
3560 register dw_die_ref die;
3561 register enum dwarf_attribute attr_kind;
3562 register unsigned flag;
a3f97cbb 3563{
3f76745e 3564 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 3565
3f76745e
JM
3566 attr->dw_attr_next = NULL;
3567 attr->dw_attr = attr_kind;
3568 attr->dw_attr_val.val_class = dw_val_class_flag;
3569 attr->dw_attr_val.v.val_flag = flag;
3570 add_dwarf_attr (die, attr);
a3f97cbb
JW
3571}
3572
3f76745e 3573/* Add a signed integer attribute value to a DIE. */
71dfc51f 3574
3f76745e
JM
3575static inline void
3576add_AT_int (die, attr_kind, int_val)
3577 register dw_die_ref die;
3578 register enum dwarf_attribute attr_kind;
3579 register long int int_val;
a3f97cbb 3580{
3f76745e
JM
3581 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3582
3583 attr->dw_attr_next = NULL;
3584 attr->dw_attr = attr_kind;
3585 attr->dw_attr_val.val_class = dw_val_class_const;
3586 attr->dw_attr_val.v.val_int = int_val;
3587 add_dwarf_attr (die, attr);
a3f97cbb
JW
3588}
3589
3f76745e 3590/* Add an unsigned integer attribute value to a DIE. */
71dfc51f 3591
3f76745e
JM
3592static inline void
3593add_AT_unsigned (die, attr_kind, unsigned_val)
3594 register dw_die_ref die;
3595 register enum dwarf_attribute attr_kind;
3596 register unsigned long unsigned_val;
a3f97cbb 3597{
3f76745e
JM
3598 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3599
3600 attr->dw_attr_next = NULL;
3601 attr->dw_attr = attr_kind;
3602 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3603 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3604 add_dwarf_attr (die, attr);
a3f97cbb 3605}
71dfc51f 3606
3f76745e
JM
3607/* Add an unsigned double integer attribute value to a DIE. */
3608
3609static inline void
3610add_AT_long_long (die, attr_kind, val_hi, val_low)
a3f97cbb 3611 register dw_die_ref die;
3f76745e
JM
3612 register enum dwarf_attribute attr_kind;
3613 register unsigned long val_hi;
3614 register unsigned long val_low;
a3f97cbb 3615{
3f76745e 3616 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 3617
3f76745e
JM
3618 attr->dw_attr_next = NULL;
3619 attr->dw_attr = attr_kind;
3620 attr->dw_attr_val.val_class = dw_val_class_long_long;
3621 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3622 attr->dw_attr_val.v.val_long_long.low = val_low;
3623 add_dwarf_attr (die, attr);
3624}
71dfc51f 3625
3f76745e 3626/* Add a floating point attribute value to a DIE and return it. */
71dfc51f 3627
3f76745e
JM
3628static inline void
3629add_AT_float (die, attr_kind, length, array)
3630 register dw_die_ref die;
3631 register enum dwarf_attribute attr_kind;
3632 register unsigned length;
3633 register long *array;
3634{
3635 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3636
3637 attr->dw_attr_next = NULL;
3638 attr->dw_attr = attr_kind;
3639 attr->dw_attr_val.val_class = dw_val_class_float;
3640 attr->dw_attr_val.v.val_float.length = length;
3641 attr->dw_attr_val.v.val_float.array = array;
3642 add_dwarf_attr (die, attr);
a3f97cbb
JW
3643}
3644
3f76745e 3645/* Add a string attribute value to a DIE. */
71dfc51f 3646
3f76745e
JM
3647static inline void
3648add_AT_string (die, attr_kind, str)
a3f97cbb 3649 register dw_die_ref die;
3f76745e
JM
3650 register enum dwarf_attribute attr_kind;
3651 register char *str;
a3f97cbb 3652{
3f76745e 3653 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 3654
3f76745e
JM
3655 attr->dw_attr_next = NULL;
3656 attr->dw_attr = attr_kind;
3657 attr->dw_attr_val.val_class = dw_val_class_str;
3658 attr->dw_attr_val.v.val_str = xstrdup (str);
3659 add_dwarf_attr (die, attr);
3660}
71dfc51f 3661
3f76745e 3662/* Add a DIE reference attribute value to a DIE. */
71dfc51f 3663
3f76745e
JM
3664static inline void
3665add_AT_die_ref (die, attr_kind, targ_die)
3666 register dw_die_ref die;
3667 register enum dwarf_attribute attr_kind;
3668 register dw_die_ref targ_die;
3669{
3670 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 3671
3f76745e
JM
3672 attr->dw_attr_next = NULL;
3673 attr->dw_attr = attr_kind;
3674 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3675 attr->dw_attr_val.v.val_die_ref = targ_die;
3676 add_dwarf_attr (die, attr);
3677}
b1ccbc24 3678
3f76745e 3679/* Add an FDE reference attribute value to a DIE. */
b1ccbc24 3680
3f76745e
JM
3681static inline void
3682add_AT_fde_ref (die, attr_kind, targ_fde)
3683 register dw_die_ref die;
3684 register enum dwarf_attribute attr_kind;
3685 register unsigned targ_fde;
3686{
3687 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
b1ccbc24 3688
3f76745e
JM
3689 attr->dw_attr_next = NULL;
3690 attr->dw_attr = attr_kind;
3691 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3692 attr->dw_attr_val.v.val_fde_index = targ_fde;
3693 add_dwarf_attr (die, attr);
a3f97cbb 3694}
71dfc51f 3695
3f76745e 3696/* Add a location description attribute value to a DIE. */
71dfc51f 3697
3f76745e
JM
3698static inline void
3699add_AT_loc (die, attr_kind, loc)
3700 register dw_die_ref die;
3701 register enum dwarf_attribute attr_kind;
3702 register dw_loc_descr_ref loc;
3703{
3704 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 3705
3f76745e
JM
3706 attr->dw_attr_next = NULL;
3707 attr->dw_attr = attr_kind;
3708 attr->dw_attr_val.val_class = dw_val_class_loc;
3709 attr->dw_attr_val.v.val_loc = loc;
3710 add_dwarf_attr (die, attr);
a3f97cbb
JW
3711}
3712
3f76745e 3713/* Add an address constant attribute value to a DIE. */
71dfc51f 3714
3f76745e
JM
3715static inline void
3716add_AT_addr (die, attr_kind, addr)
3717 register dw_die_ref die;
3718 register enum dwarf_attribute attr_kind;
3719 char *addr;
a3f97cbb 3720{
3f76745e 3721 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 3722
3f76745e
JM
3723 attr->dw_attr_next = NULL;
3724 attr->dw_attr = attr_kind;
3725 attr->dw_attr_val.val_class = dw_val_class_addr;
3726 attr->dw_attr_val.v.val_addr = addr;
3727 add_dwarf_attr (die, attr);
a3f97cbb
JW
3728}
3729
3f76745e 3730/* Add a label identifier attribute value to a DIE. */
71dfc51f 3731
3f76745e
JM
3732static inline void
3733add_AT_lbl_id (die, attr_kind, lbl_id)
3734 register dw_die_ref die;
3735 register enum dwarf_attribute attr_kind;
3736 register char *lbl_id;
a3f97cbb 3737{
3f76745e 3738 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 3739
3f76745e
JM
3740 attr->dw_attr_next = NULL;
3741 attr->dw_attr = attr_kind;
3742 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3743 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3744 add_dwarf_attr (die, attr);
3745}
71dfc51f 3746
3f76745e
JM
3747/* Add a section offset attribute value to a DIE. */
3748
3749static inline void
3750add_AT_section_offset (die, attr_kind, section)
3751 register dw_die_ref die;
3752 register enum dwarf_attribute attr_kind;
3753 register char *section;
3754{
3755 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 3756
3f76745e
JM
3757 attr->dw_attr_next = NULL;
3758 attr->dw_attr = attr_kind;
3759 attr->dw_attr_val.val_class = dw_val_class_section_offset;
3760 attr->dw_attr_val.v.val_section = section;
3761 add_dwarf_attr (die, attr);
3762
a3f97cbb
JW
3763}
3764
3f76745e 3765/* Test if die refers to an external subroutine. */
71dfc51f 3766
3f76745e
JM
3767static inline int
3768is_extern_subr_die (die)
3769 register dw_die_ref die;
a3f97cbb 3770{
3f76745e
JM
3771 register dw_attr_ref a;
3772 register int is_subr = FALSE;
3773 register int is_extern = FALSE;
71dfc51f 3774
3f76745e 3775 if (die != NULL && die->die_tag == DW_TAG_subprogram)
a3f97cbb 3776 {
3f76745e
JM
3777 is_subr = TRUE;
3778 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3779 {
3780 if (a->dw_attr == DW_AT_external
3781 && a->dw_attr_val.val_class == dw_val_class_flag
3782 && a->dw_attr_val.v.val_flag != 0)
3783 {
3784 is_extern = TRUE;
3785 break;
3786 }
3787 }
a3f97cbb 3788 }
71dfc51f 3789
3f76745e 3790 return is_subr && is_extern;
a3f97cbb
JW
3791}
3792
3f76745e 3793/* Get the attribute of type attr_kind. */
71dfc51f 3794
3f76745e
JM
3795static inline dw_attr_ref
3796get_AT (die, attr_kind)
3797 register dw_die_ref die;
3798 register enum dwarf_attribute attr_kind;
f37230f0 3799{
3f76745e
JM
3800 register dw_attr_ref a;
3801 register dw_die_ref spec = NULL;
3802
3803 if (die != NULL)
3804 {
3805 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3806 {
3807 if (a->dw_attr == attr_kind)
3808 return a;
71dfc51f 3809
3f76745e
JM
3810 if (a->dw_attr == DW_AT_specification
3811 || a->dw_attr == DW_AT_abstract_origin)
3812 spec = a->dw_attr_val.v.val_die_ref;
3813 }
71dfc51f 3814
3f76745e
JM
3815 if (spec)
3816 return get_AT (spec, attr_kind);
3817 }
3818
3819 return NULL;
f37230f0
JM
3820}
3821
3f76745e
JM
3822/* Return the "low pc" attribute value, typically associated with
3823 a subprogram DIE. Return null if the "low pc" attribute is
3824 either not prsent, or if it cannot be represented as an
3825 assembler label identifier. */
71dfc51f 3826
3f76745e
JM
3827static inline char *
3828get_AT_low_pc (die)
3829 register dw_die_ref die;
7e23cb16 3830{
3f76745e 3831 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7e23cb16 3832
3f76745e
JM
3833 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3834 return a->dw_attr_val.v.val_lbl_id;
7e23cb16 3835
3f76745e 3836 return NULL;
7e23cb16
JM
3837}
3838
3f76745e
JM
3839/* Return the "high pc" attribute value, typically associated with
3840 a subprogram DIE. Return null if the "high pc" attribute is
3841 either not prsent, or if it cannot be represented as an
3842 assembler label identifier. */
71dfc51f 3843
3f76745e
JM
3844static inline char *
3845get_AT_hi_pc (die)
a3f97cbb
JW
3846 register dw_die_ref die;
3847{
3f76745e 3848 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
71dfc51f 3849
3f76745e
JM
3850 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3851 return a->dw_attr_val.v.val_lbl_id;
f37230f0 3852
3f76745e
JM
3853 return NULL;
3854}
3855
3856/* Return the value of the string attribute designated by ATTR_KIND, or
3857 NULL if it is not present. */
71dfc51f 3858
3f76745e
JM
3859static inline char *
3860get_AT_string (die, attr_kind)
3861 register dw_die_ref die;
3862 register enum dwarf_attribute attr_kind;
3863{
3864 register dw_attr_ref a = get_AT (die, attr_kind);
3865
3866 if (a && a->dw_attr_val.val_class == dw_val_class_str)
3867 return a->dw_attr_val.v.val_str;
3868
3869 return NULL;
a3f97cbb
JW
3870}
3871
3f76745e
JM
3872/* Return the value of the flag attribute designated by ATTR_KIND, or -1
3873 if it is not present. */
71dfc51f 3874
3f76745e
JM
3875static inline int
3876get_AT_flag (die, attr_kind)
3877 register dw_die_ref die;
3878 register enum dwarf_attribute attr_kind;
a3f97cbb 3879{
3f76745e 3880 register dw_attr_ref a = get_AT (die, attr_kind);
71dfc51f 3881
3f76745e
JM
3882 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
3883 return a->dw_attr_val.v.val_flag;
71dfc51f 3884
3f76745e 3885 return -1;
a3f97cbb
JW
3886}
3887
3f76745e
JM
3888/* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3889 if it is not present. */
71dfc51f 3890
3f76745e
JM
3891static inline unsigned
3892get_AT_unsigned (die, attr_kind)
3893 register dw_die_ref die;
3894 register enum dwarf_attribute attr_kind;
a3f97cbb 3895{
3f76745e 3896 register dw_attr_ref a = get_AT (die, attr_kind);
71dfc51f 3897
3f76745e
JM
3898 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
3899 return a->dw_attr_val.v.val_unsigned;
71dfc51f 3900
3f76745e
JM
3901 return 0;
3902}
71dfc51f 3903
3f76745e
JM
3904static inline int
3905is_c_family ()
3906{
3907 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
71dfc51f 3908
3f76745e
JM
3909 return (lang == DW_LANG_C || lang == DW_LANG_C89
3910 || lang == DW_LANG_C_plus_plus);
3911}
71dfc51f 3912
3f76745e
JM
3913static inline int
3914is_fortran ()
3915{
3916 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
71dfc51f 3917
3f76745e
JM
3918 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3919}
71dfc51f 3920
3f76745e 3921/* Remove the specified attribute if present. */
71dfc51f 3922
3f76745e
JM
3923static inline void
3924remove_AT (die, attr_kind)
3925 register dw_die_ref die;
3926 register enum dwarf_attribute attr_kind;
3927{
3928 register dw_attr_ref a;
3929 register dw_attr_ref removed = NULL;;
a3f97cbb 3930
3f76745e
JM
3931 if (die != NULL)
3932 {
3933 if (die->die_attr->dw_attr == attr_kind)
3934 {
3935 removed = die->die_attr;
3936 if (die->die_attr_last == die->die_attr)
3937 die->die_attr_last = NULL;
71dfc51f 3938
3f76745e
JM
3939 die->die_attr = die->die_attr->dw_attr_next;
3940 }
71dfc51f 3941
3f76745e
JM
3942 else
3943 for (a = die->die_attr; a->dw_attr_next != NULL;
3944 a = a->dw_attr_next)
3945 if (a->dw_attr_next->dw_attr == attr_kind)
3946 {
3947 removed = a->dw_attr_next;
3948 if (die->die_attr_last == a->dw_attr_next)
3949 die->die_attr_last = a;
71dfc51f 3950
3f76745e
JM
3951 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
3952 break;
3953 }
71dfc51f 3954
3f76745e
JM
3955 if (removed != 0)
3956 free (removed);
3957 }
3958}
71dfc51f 3959
3f76745e 3960/* Discard the children of this DIE. */
71dfc51f 3961
3f76745e
JM
3962static inline void
3963remove_children (die)
3964 register dw_die_ref die;
3965{
3966 register dw_die_ref child_die = die->die_child;
3967
3968 die->die_child = NULL;
3969 die->die_child_last = NULL;
3970
3971 while (child_die != NULL)
a3f97cbb 3972 {
3f76745e
JM
3973 register dw_die_ref tmp_die = child_die;
3974 register dw_attr_ref a;
71dfc51f 3975
3f76745e
JM
3976 child_die = child_die->die_sib;
3977
3978 for (a = tmp_die->die_attr; a != NULL; )
a3f97cbb 3979 {
3f76745e 3980 register dw_attr_ref tmp_a = a;
71dfc51f 3981
3f76745e
JM
3982 a = a->dw_attr_next;
3983 free (tmp_a);
a3f97cbb 3984 }
71dfc51f 3985
3f76745e
JM
3986 free (tmp_die);
3987 }
3988}
71dfc51f 3989
3f76745e 3990/* Add a child DIE below its parent. */
71dfc51f 3991
3f76745e
JM
3992static inline void
3993add_child_die (die, child_die)
3994 register dw_die_ref die;
3995 register dw_die_ref child_die;
3996{
3997 if (die != NULL && child_die != NULL)
e90b62db 3998 {
3a88cbd1
JL
3999 if (die == child_die)
4000 abort ();
3f76745e
JM
4001 child_die->die_parent = die;
4002 child_die->die_sib = NULL;
4003
4004 if (die->die_child == NULL)
e90b62db 4005 {
3f76745e
JM
4006 die->die_child = child_die;
4007 die->die_child_last = child_die;
e90b62db
JM
4008 }
4009 else
e90b62db 4010 {
3f76745e
JM
4011 die->die_child_last->die_sib = child_die;
4012 die->die_child_last = child_die;
e90b62db 4013 }
3f76745e
JM
4014 }
4015}
4016
4017/* Return a pointer to a newly created DIE node. */
4018
4019static inline dw_die_ref
4020new_die (tag_value, parent_die)
4021 register enum dwarf_tag tag_value;
4022 register dw_die_ref parent_die;
4023{
4024 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4025
4026 die->die_tag = tag_value;
4027 die->die_abbrev = 0;
4028 die->die_offset = 0;
4029 die->die_child = NULL;
4030 die->die_parent = NULL;
4031 die->die_sib = NULL;
4032 die->die_child_last = NULL;
4033 die->die_attr = NULL;
4034 die->die_attr_last = NULL;
4035
4036 if (parent_die != NULL)
4037 add_child_die (parent_die, die);
4038 else
ef76d03b
JW
4039 {
4040 limbo_die_node *limbo_node;
4041
4042 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4043 limbo_node->die = die;
4044 limbo_node->next = limbo_die_list;
4045 limbo_die_list = limbo_node;
4046 }
71dfc51f 4047
3f76745e
JM
4048 return die;
4049}
71dfc51f 4050
3f76745e 4051/* Return the DIE associated with the given type specifier. */
71dfc51f 4052
3f76745e
JM
4053static inline dw_die_ref
4054lookup_type_die (type)
4055 register tree type;
4056{
4057 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4058}
e90b62db 4059
3f76745e 4060/* Equate a DIE to a given type specifier. */
71dfc51f 4061
3f76745e
JM
4062static void
4063equate_type_number_to_die (type, type_die)
4064 register tree type;
4065 register dw_die_ref type_die;
4066{
4067 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4068}
71dfc51f 4069
3f76745e 4070/* Return the DIE associated with a given declaration. */
71dfc51f 4071
3f76745e
JM
4072static inline dw_die_ref
4073lookup_decl_die (decl)
4074 register tree decl;
4075{
4076 register unsigned decl_id = DECL_UID (decl);
4077
4078 return (decl_id < decl_die_table_in_use
4079 ? decl_die_table[decl_id] : NULL);
a3f97cbb
JW
4080}
4081
3f76745e 4082/* Equate a DIE to a particular declaration. */
71dfc51f 4083
3f76745e
JM
4084static void
4085equate_decl_number_to_die (decl, decl_die)
4086 register tree decl;
4087 register dw_die_ref decl_die;
a3f97cbb 4088{
3f76745e 4089 register unsigned decl_id = DECL_UID (decl);
d291dd49 4090 register unsigned i;
3f76745e 4091 register unsigned num_allocated;
d291dd49 4092
3f76745e 4093 if (decl_id >= decl_die_table_allocated)
a3f97cbb 4094 {
3f76745e
JM
4095 num_allocated
4096 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4097 / DECL_DIE_TABLE_INCREMENT)
4098 * DECL_DIE_TABLE_INCREMENT;
4099
4100 decl_die_table
4101 = (dw_die_ref *) xrealloc (decl_die_table,
4102 sizeof (dw_die_ref) * num_allocated);
4103
4104 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4105 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4106 decl_die_table_allocated = num_allocated;
a3f97cbb 4107 }
71dfc51f 4108
3f76745e
JM
4109 if (decl_id >= decl_die_table_in_use)
4110 decl_die_table_in_use = (decl_id + 1);
4111
4112 decl_die_table[decl_id] = decl_die;
a3f97cbb
JW
4113}
4114
3f76745e
JM
4115/* Return a pointer to a newly allocated location description. Location
4116 descriptions are simple expression terms that can be strung
4117 together to form more complicated location (address) descriptions. */
71dfc51f 4118
3f76745e
JM
4119static inline dw_loc_descr_ref
4120new_loc_descr (op, oprnd1, oprnd2)
4121 register enum dwarf_location_atom op;
4122 register unsigned long oprnd1;
4123 register unsigned long oprnd2;
a3f97cbb 4124{
3f76745e
JM
4125 register dw_loc_descr_ref descr
4126 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
71dfc51f 4127
3f76745e
JM
4128 descr->dw_loc_next = NULL;
4129 descr->dw_loc_opc = op;
4130 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4131 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4132 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4133 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
71dfc51f 4134
3f76745e 4135 return descr;
a3f97cbb 4136}
71dfc51f 4137
3f76745e
JM
4138/* Add a location description term to a location description expression. */
4139
4140static inline void
4141add_loc_descr (list_head, descr)
4142 register dw_loc_descr_ref *list_head;
4143 register dw_loc_descr_ref descr;
a3f97cbb 4144{
3f76745e 4145 register dw_loc_descr_ref *d;
71dfc51f 4146
3f76745e
JM
4147 /* Find the end of the chain. */
4148 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4149 ;
71dfc51f 4150
3f76745e
JM
4151 *d = descr;
4152}
4153\f
4154/* Keep track of the number of spaces used to indent the
4155 output of the debugging routines that print the structure of
4156 the DIE internal representation. */
4157static int print_indent;
71dfc51f 4158
3f76745e
JM
4159/* Indent the line the number of spaces given by print_indent. */
4160
4161static inline void
4162print_spaces (outfile)
4163 FILE *outfile;
4164{
4165 fprintf (outfile, "%*s", print_indent, "");
a3f97cbb
JW
4166}
4167
956d6950 4168/* Print the information associated with a given DIE, and its children.
3f76745e 4169 This routine is a debugging aid only. */
71dfc51f 4170
a3f97cbb 4171static void
3f76745e
JM
4172print_die (die, outfile)
4173 dw_die_ref die;
4174 FILE *outfile;
a3f97cbb 4175{
3f76745e
JM
4176 register dw_attr_ref a;
4177 register dw_die_ref c;
71dfc51f 4178
3f76745e
JM
4179 print_spaces (outfile);
4180 fprintf (outfile, "DIE %4u: %s\n",
4181 die->die_offset, dwarf_tag_name (die->die_tag));
4182 print_spaces (outfile);
4183 fprintf (outfile, " abbrev id: %u", die->die_abbrev);
4184 fprintf (outfile, " offset: %u\n", die->die_offset);
4185
4186 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
a3f97cbb 4187 {
3f76745e
JM
4188 print_spaces (outfile);
4189 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4190
4191 switch (a->dw_attr_val.val_class)
4192 {
4193 case dw_val_class_addr:
4194 fprintf (outfile, "address");
4195 break;
4196 case dw_val_class_loc:
4197 fprintf (outfile, "location descriptor");
4198 break;
4199 case dw_val_class_const:
4200 fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
4201 break;
4202 case dw_val_class_unsigned_const:
4203 fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
4204 break;
4205 case dw_val_class_long_long:
4206 fprintf (outfile, "constant (%u,%u)",
4207 a->dw_attr_val.v.val_long_long.hi,
4208 a->dw_attr_val.v.val_long_long.low);
4209 break;
4210 case dw_val_class_float:
4211 fprintf (outfile, "floating-point constant");
4212 break;
4213 case dw_val_class_flag:
4214 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
4215 break;
4216 case dw_val_class_die_ref:
4217 if (a->dw_attr_val.v.val_die_ref != NULL)
4218 fprintf (outfile, "die -> %u",
4219 a->dw_attr_val.v.val_die_ref->die_offset);
4220 else
4221 fprintf (outfile, "die -> <null>");
4222 break;
4223 case dw_val_class_lbl_id:
4224 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
4225 break;
4226 case dw_val_class_section_offset:
4227 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
4228 break;
4229 case dw_val_class_str:
4230 if (a->dw_attr_val.v.val_str != NULL)
4231 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
4232 else
4233 fprintf (outfile, "<null>");
4234 break;
e9a25f70
JL
4235 default:
4236 break;
3f76745e
JM
4237 }
4238
4239 fprintf (outfile, "\n");
4240 }
4241
4242 if (die->die_child != NULL)
4243 {
4244 print_indent += 4;
4245 for (c = die->die_child; c != NULL; c = c->die_sib)
4246 print_die (c, outfile);
71dfc51f 4247
3f76745e 4248 print_indent -= 4;
a3f97cbb 4249 }
a3f97cbb
JW
4250}
4251
3f76745e
JM
4252/* Print the contents of the source code line number correspondence table.
4253 This routine is a debugging aid only. */
71dfc51f 4254
3f76745e
JM
4255static void
4256print_dwarf_line_table (outfile)
4257 FILE *outfile;
a3f97cbb 4258{
3f76745e
JM
4259 register unsigned i;
4260 register dw_line_info_ref line_info;
4261
4262 fprintf (outfile, "\n\nDWARF source line information\n");
4263 for (i = 1; i < line_info_table_in_use; ++i)
a3f97cbb 4264 {
3f76745e
JM
4265 line_info = &line_info_table[i];
4266 fprintf (outfile, "%5d: ", i);
4267 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4268 fprintf (outfile, "%6d", line_info->dw_line_num);
4269 fprintf (outfile, "\n");
a3f97cbb 4270 }
3f76745e
JM
4271
4272 fprintf (outfile, "\n\n");
f37230f0
JM
4273}
4274
3f76745e
JM
4275/* Print the information collected for a given DIE. */
4276
4277void
4278debug_dwarf_die (die)
4279 dw_die_ref die;
4280{
4281 print_die (die, stderr);
4282}
4283
4284/* Print all DWARF information collected for the compilation unit.
4285 This routine is a debugging aid only. */
4286
4287void
4288debug_dwarf ()
4289{
4290 print_indent = 0;
4291 print_die (comp_unit_die, stderr);
4292 print_dwarf_line_table (stderr);
4293}
4294\f
4295/* Traverse the DIE, and add a sibling attribute if it may have the
4296 effect of speeding up access to siblings. To save some space,
4297 avoid generating sibling attributes for DIE's without children. */
71dfc51f 4298
f37230f0 4299static void
3f76745e
JM
4300add_sibling_attributes(die)
4301 register dw_die_ref die;
f37230f0 4302{
3f76745e
JM
4303 register dw_die_ref c;
4304 register dw_attr_ref attr;
4305 if (die != comp_unit_die && die->die_child != NULL)
4306 {
4307 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4308 attr->dw_attr_next = NULL;
4309 attr->dw_attr = DW_AT_sibling;
4310 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4311 attr->dw_attr_val.v.val_die_ref = die->die_sib;
71dfc51f 4312
3f76745e
JM
4313 /* Add the sibling link to the front of the attribute list. */
4314 attr->dw_attr_next = die->die_attr;
4315 if (die->die_attr == NULL)
4316 die->die_attr_last = attr;
71dfc51f 4317
3f76745e
JM
4318 die->die_attr = attr;
4319 }
4320
4321 for (c = die->die_child; c != NULL; c = c->die_sib)
4322 add_sibling_attributes (c);
a3f97cbb
JW
4323}
4324
3f76745e
JM
4325/* The format of each DIE (and its attribute value pairs)
4326 is encoded in an abbreviation table. This routine builds the
4327 abbreviation table and assigns a unique abbreviation id for
4328 each abbreviation entry. The children of each die are visited
4329 recursively. */
71dfc51f 4330
a3f97cbb 4331static void
3f76745e
JM
4332build_abbrev_table (die)
4333 register dw_die_ref die;
a3f97cbb 4334{
3f76745e
JM
4335 register unsigned long abbrev_id;
4336 register unsigned long n_alloc;
4337 register dw_die_ref c;
4338 register dw_attr_ref d_attr, a_attr;
a3f97cbb
JW
4339 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4340 {
4341 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
71dfc51f 4342
3f76745e
JM
4343 if (abbrev->die_tag == die->die_tag)
4344 {
4345 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4346 {
4347 a_attr = abbrev->die_attr;
4348 d_attr = die->die_attr;
71dfc51f 4349
3f76745e
JM
4350 while (a_attr != NULL && d_attr != NULL)
4351 {
4352 if ((a_attr->dw_attr != d_attr->dw_attr)
4353 || (value_format (&a_attr->dw_attr_val)
4354 != value_format (&d_attr->dw_attr_val)))
4355 break;
71dfc51f 4356
3f76745e
JM
4357 a_attr = a_attr->dw_attr_next;
4358 d_attr = d_attr->dw_attr_next;
4359 }
71dfc51f 4360
3f76745e
JM
4361 if (a_attr == NULL && d_attr == NULL)
4362 break;
4363 }
4364 }
4365 }
71dfc51f 4366
3f76745e
JM
4367 if (abbrev_id >= abbrev_die_table_in_use)
4368 {
4369 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
a3f97cbb 4370 {
3f76745e
JM
4371 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4372 abbrev_die_table
c760091a 4373 = (dw_die_ref *) xrealloc (abbrev_die_table,
966f5dff 4374 sizeof (dw_die_ref) * n_alloc);
71dfc51f 4375
3f76745e
JM
4376 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4377 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4378 abbrev_die_table_allocated = n_alloc;
a3f97cbb 4379 }
71dfc51f 4380
3f76745e
JM
4381 ++abbrev_die_table_in_use;
4382 abbrev_die_table[abbrev_id] = die;
a3f97cbb 4383 }
3f76745e
JM
4384
4385 die->die_abbrev = abbrev_id;
4386 for (c = die->die_child; c != NULL; c = c->die_sib)
4387 build_abbrev_table (c);
a3f97cbb 4388}
3f76745e
JM
4389\f
4390/* Return the size of a string, including the null byte. */
a3f97cbb 4391
3f76745e
JM
4392static unsigned long
4393size_of_string (str)
4394 register char *str;
4395{
4396 register unsigned long size = 0;
4397 register unsigned long slen = strlen (str);
4398 register unsigned long i;
4399 register unsigned c;
71dfc51f 4400
3f76745e
JM
4401 for (i = 0; i < slen; ++i)
4402 {
4403 c = str[i];
4404 if (c == '\\')
4405 ++i;
4406
4407 size += 1;
4408 }
4409
4410 /* Null terminator. */
4411 size += 1;
4412 return size;
4413}
4414
4415/* Return the size of a location descriptor. */
4416
4417static unsigned long
4418size_of_loc_descr (loc)
a3f97cbb
JW
4419 register dw_loc_descr_ref loc;
4420{
3f76745e 4421 register unsigned long size = 1;
71dfc51f 4422
a3f97cbb
JW
4423 switch (loc->dw_loc_opc)
4424 {
4425 case DW_OP_addr:
3f76745e 4426 size += PTR_SIZE;
a3f97cbb
JW
4427 break;
4428 case DW_OP_const1u:
4429 case DW_OP_const1s:
3f76745e 4430 size += 1;
a3f97cbb
JW
4431 break;
4432 case DW_OP_const2u:
4433 case DW_OP_const2s:
3f76745e 4434 size += 2;
a3f97cbb
JW
4435 break;
4436 case DW_OP_const4u:
4437 case DW_OP_const4s:
3f76745e 4438 size += 4;
a3f97cbb
JW
4439 break;
4440 case DW_OP_const8u:
4441 case DW_OP_const8s:
3f76745e 4442 size += 8;
a3f97cbb
JW
4443 break;
4444 case DW_OP_constu:
3f76745e 4445 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
a3f97cbb
JW
4446 break;
4447 case DW_OP_consts:
3f76745e 4448 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
a3f97cbb
JW
4449 break;
4450 case DW_OP_pick:
3f76745e 4451 size += 1;
a3f97cbb
JW
4452 break;
4453 case DW_OP_plus_uconst:
3f76745e 4454 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
a3f97cbb
JW
4455 break;
4456 case DW_OP_skip:
4457 case DW_OP_bra:
3f76745e 4458 size += 2;
a3f97cbb
JW
4459 break;
4460 case DW_OP_breg0:
4461 case DW_OP_breg1:
4462 case DW_OP_breg2:
4463 case DW_OP_breg3:
4464 case DW_OP_breg4:
4465 case DW_OP_breg5:
4466 case DW_OP_breg6:
4467 case DW_OP_breg7:
4468 case DW_OP_breg8:
4469 case DW_OP_breg9:
4470 case DW_OP_breg10:
4471 case DW_OP_breg11:
4472 case DW_OP_breg12:
4473 case DW_OP_breg13:
4474 case DW_OP_breg14:
4475 case DW_OP_breg15:
4476 case DW_OP_breg16:
4477 case DW_OP_breg17:
4478 case DW_OP_breg18:
4479 case DW_OP_breg19:
4480 case DW_OP_breg20:
4481 case DW_OP_breg21:
4482 case DW_OP_breg22:
4483 case DW_OP_breg23:
4484 case DW_OP_breg24:
4485 case DW_OP_breg25:
4486 case DW_OP_breg26:
4487 case DW_OP_breg27:
4488 case DW_OP_breg28:
4489 case DW_OP_breg29:
4490 case DW_OP_breg30:
4491 case DW_OP_breg31:
3f76745e 4492 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
a3f97cbb
JW
4493 break;
4494 case DW_OP_regx:
3f76745e 4495 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
a3f97cbb
JW
4496 break;
4497 case DW_OP_fbreg:
3f76745e 4498 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
a3f97cbb
JW
4499 break;
4500 case DW_OP_bregx:
3f76745e
JM
4501 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4502 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
a3f97cbb
JW
4503 break;
4504 case DW_OP_piece:
3f76745e 4505 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
a3f97cbb
JW
4506 break;
4507 case DW_OP_deref_size:
4508 case DW_OP_xderef_size:
3f76745e 4509 size += 1;
a3f97cbb
JW
4510 break;
4511 default:
4512 break;
4513 }
3f76745e
JM
4514
4515 return size;
a3f97cbb
JW
4516}
4517
3f76745e 4518/* Return the size of a series of location descriptors. */
71dfc51f 4519
a3f97cbb 4520static unsigned long
3f76745e
JM
4521size_of_locs (loc)
4522 register dw_loc_descr_ref loc;
a3f97cbb 4523{
3f76745e 4524 register unsigned long size = 0;
71dfc51f 4525
3f76745e
JM
4526 for (; loc != NULL; loc = loc->dw_loc_next)
4527 size += size_of_loc_descr (loc);
4528
4529 return size;
4530}
4531
4532/* Return the power-of-two number of bytes necessary to represent VALUE. */
4533
4534static int
4535constant_size (value)
4536 long unsigned value;
4537{
4538 int log;
4539
4540 if (value == 0)
4541 log = 0;
a3f97cbb 4542 else
3f76745e 4543 log = floor_log2 (value);
71dfc51f 4544
3f76745e
JM
4545 log = log / 8;
4546 log = 1 << (floor_log2 (log) + 1);
4547
4548 return log;
a3f97cbb
JW
4549}
4550
3f76745e
JM
4551/* Return the size of a DIE, as it is represented in the
4552 .debug_info section. */
71dfc51f 4553
3f76745e
JM
4554static unsigned long
4555size_of_die (die)
a3f97cbb
JW
4556 register dw_die_ref die;
4557{
3f76745e 4558 register unsigned long size = 0;
a3f97cbb 4559 register dw_attr_ref a;
71dfc51f 4560
3f76745e 4561 size += size_of_uleb128 (die->die_abbrev);
a3f97cbb
JW
4562 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4563 {
4564 switch (a->dw_attr_val.val_class)
4565 {
4566 case dw_val_class_addr:
3f76745e 4567 size += PTR_SIZE;
a3f97cbb
JW
4568 break;
4569 case dw_val_class_loc:
3f76745e
JM
4570 {
4571 register unsigned long lsize
4572 = size_of_locs (a->dw_attr_val.v.val_loc);
71dfc51f 4573
3f76745e
JM
4574 /* Block length. */
4575 size += constant_size (lsize);
4576 size += lsize;
4577 }
a3f97cbb
JW
4578 break;
4579 case dw_val_class_const:
3f76745e 4580 size += 4;
a3f97cbb
JW
4581 break;
4582 case dw_val_class_unsigned_const:
3f76745e 4583 size += constant_size (a->dw_attr_val.v.val_unsigned);
a3f97cbb 4584 break;
469ac993 4585 case dw_val_class_long_long:
3f76745e 4586 size += 1 + 8; /* block */
469ac993
JM
4587 break;
4588 case dw_val_class_float:
3f76745e 4589 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
a3f97cbb
JW
4590 break;
4591 case dw_val_class_flag:
3f76745e 4592 size += 1;
a3f97cbb
JW
4593 break;
4594 case dw_val_class_die_ref:
3f76745e 4595 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
4596 break;
4597 case dw_val_class_fde_ref:
3f76745e 4598 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
4599 break;
4600 case dw_val_class_lbl_id:
3f76745e
JM
4601 size += PTR_SIZE;
4602 break;
4603 case dw_val_class_section_offset:
4604 size += DWARF_OFFSET_SIZE;
4605 break;
4606 case dw_val_class_str:
4607 size += size_of_string (a->dw_attr_val.v.val_str);
4608 break;
4609 default:
4610 abort ();
4611 }
a3f97cbb 4612 }
3f76745e
JM
4613
4614 return size;
a3f97cbb
JW
4615}
4616
956d6950 4617/* Size the debugging information associated with a given DIE.
3f76745e
JM
4618 Visits the DIE's children recursively. Updates the global
4619 variable next_die_offset, on each time through. Uses the
956d6950 4620 current value of next_die_offset to update the die_offset
3f76745e 4621 field in each DIE. */
71dfc51f 4622
a3f97cbb 4623static void
3f76745e
JM
4624calc_die_sizes (die)
4625 dw_die_ref die;
a3f97cbb 4626{
3f76745e
JM
4627 register dw_die_ref c;
4628 die->die_offset = next_die_offset;
4629 next_die_offset += size_of_die (die);
71dfc51f 4630
3f76745e
JM
4631 for (c = die->die_child; c != NULL; c = c->die_sib)
4632 calc_die_sizes (c);
71dfc51f 4633
3f76745e
JM
4634 if (die->die_child != NULL)
4635 /* Count the null byte used to terminate sibling lists. */
4636 next_die_offset += 1;
a3f97cbb
JW
4637}
4638
3f76745e
JM
4639/* Return the size of the line information prolog generated for the
4640 compilation unit. */
469ac993 4641
3f76745e
JM
4642static unsigned long
4643size_of_line_prolog ()
a94dbf2c 4644{
3f76745e
JM
4645 register unsigned long size;
4646 register unsigned long ft_index;
a94dbf2c 4647
3f76745e 4648 size = DWARF_LINE_PROLOG_HEADER_SIZE;
469ac993 4649
3f76745e
JM
4650 /* Count the size of the table giving number of args for each
4651 standard opcode. */
4652 size += DWARF_LINE_OPCODE_BASE - 1;
71dfc51f 4653
3f76745e
JM
4654 /* Include directory table is empty (at present). Count only the
4655 the null byte used to terminate the table. */
4656 size += 1;
71dfc51f 4657
3f76745e
JM
4658 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4659 {
4660 /* File name entry. */
4661 size += size_of_string (file_table[ft_index]);
a94dbf2c 4662
3f76745e
JM
4663 /* Include directory index. */
4664 size += size_of_uleb128 (0);
a94dbf2c 4665
3f76745e
JM
4666 /* Modification time. */
4667 size += size_of_uleb128 (0);
71dfc51f 4668
3f76745e
JM
4669 /* File length in bytes. */
4670 size += size_of_uleb128 (0);
a94dbf2c 4671 }
71dfc51f 4672
3f76745e
JM
4673 /* Count the file table terminator. */
4674 size += 1;
4675 return size;
a94dbf2c
JM
4676}
4677
3f76745e
JM
4678/* Return the size of the line information generated for this
4679 compilation unit. */
71dfc51f 4680
3f76745e
JM
4681static unsigned long
4682size_of_line_info ()
a94dbf2c 4683{
3f76745e
JM
4684 register unsigned long size;
4685 register unsigned long lt_index;
4686 register unsigned long current_line;
4687 register long line_offset;
4688 register long line_delta;
4689 register unsigned long current_file;
4690 register unsigned long function;
f19a6894
JW
4691 unsigned long size_of_set_address;
4692
4693 /* Size of a DW_LNE_set_address instruction. */
4694 size_of_set_address = 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
a94dbf2c 4695
3f76745e
JM
4696 /* Version number. */
4697 size = 2;
71dfc51f 4698
3f76745e
JM
4699 /* Prolog length specifier. */
4700 size += DWARF_OFFSET_SIZE;
71dfc51f 4701
3f76745e
JM
4702 /* Prolog. */
4703 size += size_of_line_prolog ();
a94dbf2c 4704
3f76745e 4705 /* Set address register instruction. */
f19a6894 4706 size += size_of_set_address;
71dfc51f 4707
3f76745e
JM
4708 current_file = 1;
4709 current_line = 1;
4710 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
a94dbf2c 4711 {
3f76745e
JM
4712 register dw_line_info_ref line_info;
4713
4714 /* Advance pc instruction. */
f19a6894
JW
4715 /* ??? See the DW_LNS_advance_pc comment in output_line_info. */
4716 if (0)
4717 size += 1 + 2;
4718 else
4719 size += size_of_set_address;
4720
3f76745e
JM
4721 line_info = &line_info_table[lt_index];
4722 if (line_info->dw_file_num != current_file)
4723 {
4724 /* Set file number instruction. */
4725 size += 1;
4726 current_file = line_info->dw_file_num;
4727 size += size_of_uleb128 (current_file);
4728 }
4729
4730 if (line_info->dw_line_num != current_line)
4731 {
4732 line_offset = line_info->dw_line_num - current_line;
4733 line_delta = line_offset - DWARF_LINE_BASE;
4734 current_line = line_info->dw_line_num;
4735 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4736 /* 1-byte special line number instruction. */
4737 size += 1;
4738 else
4739 {
4740 /* Advance line instruction. */
4741 size += 1;
4742 size += size_of_sleb128 (line_offset);
4743 /* Generate line entry instruction. */
4744 size += 1;
4745 }
4746 }
a94dbf2c 4747 }
a94dbf2c 4748
3f76745e 4749 /* Advance pc instruction. */
f19a6894
JW
4750 if (0)
4751 size += 1 + 2;
4752 else
4753 size += size_of_set_address;
a94dbf2c 4754
3f76745e
JM
4755 /* End of line number info. marker. */
4756 size += 1 + size_of_uleb128 (1) + 1;
a94dbf2c 4757
3f76745e
JM
4758 function = 0;
4759 current_file = 1;
4760 current_line = 1;
4761 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4762 {
4763 register dw_separate_line_info_ref line_info
4764 = &separate_line_info_table[lt_index];
4765 if (function != line_info->function)
4766 {
4767 function = line_info->function;
4768 /* Set address register instruction. */
f19a6894 4769 size += size_of_set_address;
3f76745e
JM
4770 }
4771 else
f19a6894
JW
4772 {
4773 /* Advance pc instruction. */
4774 if (0)
4775 size += 1 + 2;
4776 else
4777 size += size_of_set_address;
4778 }
3f76745e
JM
4779
4780 if (line_info->dw_file_num != current_file)
4781 {
4782 /* Set file number instruction. */
4783 size += 1;
4784 current_file = line_info->dw_file_num;
4785 size += size_of_uleb128 (current_file);
4786 }
4787
4788 if (line_info->dw_line_num != current_line)
4789 {
4790 line_offset = line_info->dw_line_num - current_line;
4791 line_delta = line_offset - DWARF_LINE_BASE;
4792 current_line = line_info->dw_line_num;
4793 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4794 /* 1-byte special line number instruction. */
4795 size += 1;
4796 else
4797 {
4798 /* Advance line instruction. */
4799 size += 1;
4800 size += size_of_sleb128 (line_offset);
a94dbf2c 4801
3f76745e
JM
4802 /* Generate line entry instruction. */
4803 size += 1;
4804 }
4805 }
a94dbf2c 4806
3f76745e 4807 ++lt_index;
a94dbf2c 4808
3f76745e
JM
4809 /* If we're done with a function, end its sequence. */
4810 if (lt_index == separate_line_info_table_in_use
4811 || separate_line_info_table[lt_index].function != function)
4812 {
4813 current_file = 1;
4814 current_line = 1;
71dfc51f 4815
3f76745e 4816 /* Advance pc instruction. */
f19a6894
JW
4817 if (0)
4818 size += 1 + 2;
4819 else
4820 size += size_of_set_address;
71dfc51f 4821
3f76745e
JM
4822 /* End of line number info. marker. */
4823 size += 1 + size_of_uleb128 (1) + 1;
4824 }
a94dbf2c
JM
4825 }
4826
3f76745e 4827 return size;
a94dbf2c
JM
4828}
4829
3f76745e
JM
4830/* Return the size of the .debug_pubnames table generated for the
4831 compilation unit. */
a94dbf2c 4832
3f76745e
JM
4833static unsigned long
4834size_of_pubnames ()
a94dbf2c 4835{
3f76745e
JM
4836 register unsigned long size;
4837 register unsigned i;
469ac993 4838
3f76745e
JM
4839 size = DWARF_PUBNAMES_HEADER_SIZE;
4840 for (i = 0; i < pubname_table_in_use; ++i)
a94dbf2c 4841 {
3f76745e
JM
4842 register pubname_ref p = &pubname_table[i];
4843 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
a94dbf2c
JM
4844 }
4845
3f76745e
JM
4846 size += DWARF_OFFSET_SIZE;
4847 return size;
a94dbf2c
JM
4848}
4849
956d6950 4850/* Return the size of the information in the .debug_aranges section. */
469ac993 4851
3f76745e
JM
4852static unsigned long
4853size_of_aranges ()
469ac993 4854{
3f76745e 4855 register unsigned long size;
469ac993 4856
3f76745e 4857 size = DWARF_ARANGES_HEADER_SIZE;
469ac993 4858
3f76745e
JM
4859 /* Count the address/length pair for this compilation unit. */
4860 size += 2 * PTR_SIZE;
4861 size += 2 * PTR_SIZE * arange_table_in_use;
469ac993 4862
3f76745e
JM
4863 /* Count the two zero words used to terminated the address range table. */
4864 size += 2 * PTR_SIZE;
4865 return size;
4866}
4867\f
4868/* Select the encoding of an attribute value. */
4869
4870static enum dwarf_form
4871value_format (v)
4872 dw_val_ref v;
4873{
4874 switch (v->val_class)
469ac993 4875 {
3f76745e
JM
4876 case dw_val_class_addr:
4877 return DW_FORM_addr;
4878 case dw_val_class_loc:
4879 switch (constant_size (size_of_locs (v->v.val_loc)))
469ac993 4880 {
3f76745e
JM
4881 case 1:
4882 return DW_FORM_block1;
4883 case 2:
4884 return DW_FORM_block2;
469ac993
JM
4885 default:
4886 abort ();
4887 }
3f76745e
JM
4888 case dw_val_class_const:
4889 return DW_FORM_data4;
4890 case dw_val_class_unsigned_const:
4891 switch (constant_size (v->v.val_unsigned))
4892 {
4893 case 1:
4894 return DW_FORM_data1;
4895 case 2:
4896 return DW_FORM_data2;
4897 case 4:
4898 return DW_FORM_data4;
4899 case 8:
4900 return DW_FORM_data8;
4901 default:
4902 abort ();
4903 }
4904 case dw_val_class_long_long:
4905 return DW_FORM_block1;
4906 case dw_val_class_float:
4907 return DW_FORM_block1;
4908 case dw_val_class_flag:
4909 return DW_FORM_flag;
4910 case dw_val_class_die_ref:
4911 return DW_FORM_ref;
4912 case dw_val_class_fde_ref:
4913 return DW_FORM_data;
4914 case dw_val_class_lbl_id:
4915 return DW_FORM_addr;
4916 case dw_val_class_section_offset:
4917 return DW_FORM_data;
4918 case dw_val_class_str:
4919 return DW_FORM_string;
469ac993
JM
4920 default:
4921 abort ();
4922 }
a94dbf2c
JM
4923}
4924
3f76745e 4925/* Output the encoding of an attribute value. */
469ac993 4926
3f76745e
JM
4927static void
4928output_value_format (v)
4929 dw_val_ref v;
a94dbf2c 4930{
3f76745e 4931 enum dwarf_form form = value_format (v);
71dfc51f 4932
3f76745e 4933 output_uleb128 (form);
c5cec899 4934 if (flag_debug_asm)
3f76745e 4935 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
141719a8 4936
3f76745e
JM
4937 fputc ('\n', asm_out_file);
4938}
469ac993 4939
3f76745e
JM
4940/* Output the .debug_abbrev section which defines the DIE abbreviation
4941 table. */
469ac993 4942
3f76745e
JM
4943static void
4944output_abbrev_section ()
4945{
4946 unsigned long abbrev_id;
71dfc51f 4947
3f76745e
JM
4948 dw_attr_ref a_attr;
4949 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4950 {
4951 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
71dfc51f 4952
3f76745e 4953 output_uleb128 (abbrev_id);
c5cec899 4954 if (flag_debug_asm)
3f76745e 4955 fprintf (asm_out_file, " (abbrev code)");
469ac993 4956
3f76745e
JM
4957 fputc ('\n', asm_out_file);
4958 output_uleb128 (abbrev->die_tag);
c5cec899 4959 if (flag_debug_asm)
3f76745e
JM
4960 fprintf (asm_out_file, " (TAG: %s)",
4961 dwarf_tag_name (abbrev->die_tag));
71dfc51f 4962
3f76745e
JM
4963 fputc ('\n', asm_out_file);
4964 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4965 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
469ac993 4966
c5cec899 4967 if (flag_debug_asm)
3f76745e
JM
4968 fprintf (asm_out_file, "\t%s %s",
4969 ASM_COMMENT_START,
4970 (abbrev->die_child != NULL
4971 ? "DW_children_yes" : "DW_children_no"));
4972
4973 fputc ('\n', asm_out_file);
4974
4975 for (a_attr = abbrev->die_attr; a_attr != NULL;
4976 a_attr = a_attr->dw_attr_next)
4977 {
4978 output_uleb128 (a_attr->dw_attr);
c5cec899 4979 if (flag_debug_asm)
3f76745e
JM
4980 fprintf (asm_out_file, " (%s)",
4981 dwarf_attr_name (a_attr->dw_attr));
4982
4983 fputc ('\n', asm_out_file);
4984 output_value_format (&a_attr->dw_attr_val);
469ac993 4985 }
469ac993 4986
3f76745e 4987 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
469ac993 4988 }
a94dbf2c
JM
4989}
4990
3f76745e 4991/* Output location description stack opcode's operands (if any). */
71dfc51f 4992
3f76745e
JM
4993static void
4994output_loc_operands (loc)
4995 register dw_loc_descr_ref loc;
a3f97cbb 4996{
3f76745e
JM
4997 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4998 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
71dfc51f 4999
3f76745e 5000 switch (loc->dw_loc_opc)
a3f97cbb 5001 {
3f76745e
JM
5002 case DW_OP_addr:
5003 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
5004 fputc ('\n', asm_out_file);
a3f97cbb 5005 break;
3f76745e
JM
5006 case DW_OP_const1u:
5007 case DW_OP_const1s:
5008 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
5009 fputc ('\n', asm_out_file);
a3f97cbb 5010 break;
3f76745e
JM
5011 case DW_OP_const2u:
5012 case DW_OP_const2s:
5013 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
5014 fputc ('\n', asm_out_file);
a3f97cbb 5015 break;
3f76745e
JM
5016 case DW_OP_const4u:
5017 case DW_OP_const4s:
5018 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
5019 fputc ('\n', asm_out_file);
a3f97cbb 5020 break;
3f76745e
JM
5021 case DW_OP_const8u:
5022 case DW_OP_const8s:
5023 abort ();
5024 fputc ('\n', asm_out_file);
a3f97cbb 5025 break;
3f76745e
JM
5026 case DW_OP_constu:
5027 output_uleb128 (val1->v.val_unsigned);
5028 fputc ('\n', asm_out_file);
a3f97cbb 5029 break;
3f76745e
JM
5030 case DW_OP_consts:
5031 output_sleb128 (val1->v.val_int);
5032 fputc ('\n', asm_out_file);
a3f97cbb 5033 break;
3f76745e
JM
5034 case DW_OP_pick:
5035 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
5036 fputc ('\n', asm_out_file);
a3f97cbb 5037 break;
3f76745e
JM
5038 case DW_OP_plus_uconst:
5039 output_uleb128 (val1->v.val_unsigned);
5040 fputc ('\n', asm_out_file);
a3f97cbb 5041 break;
3f76745e
JM
5042 case DW_OP_skip:
5043 case DW_OP_bra:
5044 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
5045 fputc ('\n', asm_out_file);
a3f97cbb 5046 break;
3f76745e
JM
5047 case DW_OP_breg0:
5048 case DW_OP_breg1:
5049 case DW_OP_breg2:
5050 case DW_OP_breg3:
5051 case DW_OP_breg4:
5052 case DW_OP_breg5:
5053 case DW_OP_breg6:
5054 case DW_OP_breg7:
5055 case DW_OP_breg8:
5056 case DW_OP_breg9:
5057 case DW_OP_breg10:
5058 case DW_OP_breg11:
5059 case DW_OP_breg12:
5060 case DW_OP_breg13:
5061 case DW_OP_breg14:
5062 case DW_OP_breg15:
5063 case DW_OP_breg16:
5064 case DW_OP_breg17:
5065 case DW_OP_breg18:
5066 case DW_OP_breg19:
5067 case DW_OP_breg20:
5068 case DW_OP_breg21:
5069 case DW_OP_breg22:
5070 case DW_OP_breg23:
5071 case DW_OP_breg24:
5072 case DW_OP_breg25:
5073 case DW_OP_breg26:
5074 case DW_OP_breg27:
5075 case DW_OP_breg28:
5076 case DW_OP_breg29:
5077 case DW_OP_breg30:
5078 case DW_OP_breg31:
5079 output_sleb128 (val1->v.val_int);
5080 fputc ('\n', asm_out_file);
5081 break;
5082 case DW_OP_regx:
5083 output_uleb128 (val1->v.val_unsigned);
5084 fputc ('\n', asm_out_file);
5085 break;
5086 case DW_OP_fbreg:
5087 output_sleb128 (val1->v.val_int);
5088 fputc ('\n', asm_out_file);
5089 break;
5090 case DW_OP_bregx:
5091 output_uleb128 (val1->v.val_unsigned);
5092 fputc ('\n', asm_out_file);
5093 output_sleb128 (val2->v.val_int);
5094 fputc ('\n', asm_out_file);
5095 break;
5096 case DW_OP_piece:
5097 output_uleb128 (val1->v.val_unsigned);
5098 fputc ('\n', asm_out_file);
5099 break;
5100 case DW_OP_deref_size:
5101 case DW_OP_xderef_size:
5102 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
5103 fputc ('\n', asm_out_file);
a3f97cbb
JW
5104 break;
5105 default:
5106 break;
5107 }
a3f97cbb
JW
5108}
5109
3f76745e 5110/* Compute the offset of a sibling. */
71dfc51f 5111
3f76745e
JM
5112static unsigned long
5113sibling_offset (die)
5114 dw_die_ref die;
a3f97cbb 5115{
3f76745e 5116 unsigned long offset;
71dfc51f 5117
3f76745e
JM
5118 if (die->die_child_last == NULL)
5119 offset = die->die_offset + size_of_die (die);
5120 else
5121 offset = sibling_offset (die->die_child_last) + 1;
71dfc51f 5122
3f76745e 5123 return offset;
a3f97cbb
JW
5124}
5125
3f76745e
JM
5126/* Output the DIE and its attributes. Called recursively to generate
5127 the definitions of each child DIE. */
71dfc51f 5128
a3f97cbb 5129static void
3f76745e
JM
5130output_die (die)
5131 register dw_die_ref die;
a3f97cbb 5132{
3f76745e
JM
5133 register dw_attr_ref a;
5134 register dw_die_ref c;
5135 register unsigned long ref_offset;
5136 register unsigned long size;
5137 register dw_loc_descr_ref loc;
5138 register int i;
a94dbf2c 5139
3f76745e 5140 output_uleb128 (die->die_abbrev);
c5cec899 5141 if (flag_debug_asm)
3f76745e
JM
5142 fprintf (asm_out_file, " (DIE (0x%x) %s)",
5143 die->die_offset, dwarf_tag_name (die->die_tag));
a94dbf2c 5144
3f76745e 5145 fputc ('\n', asm_out_file);
a94dbf2c 5146
3f76745e 5147 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
a3f97cbb 5148 {
3f76745e
JM
5149 switch (a->dw_attr_val.val_class)
5150 {
5151 case dw_val_class_addr:
5152 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5153 a->dw_attr_val.v.val_addr);
5154 break;
a3f97cbb 5155
3f76745e
JM
5156 case dw_val_class_loc:
5157 size = size_of_locs (a->dw_attr_val.v.val_loc);
71dfc51f 5158
3f76745e
JM
5159 /* Output the block length for this list of location operations. */
5160 switch (constant_size (size))
5161 {
5162 case 1:
5163 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5164 break;
5165 case 2:
5166 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5167 break;
5168 default:
5169 abort ();
5170 }
71dfc51f 5171
c5cec899 5172 if (flag_debug_asm)
3f76745e
JM
5173 fprintf (asm_out_file, "\t%s %s",
5174 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
71dfc51f 5175
3f76745e
JM
5176 fputc ('\n', asm_out_file);
5177 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
5178 loc = loc->dw_loc_next)
5179 {
5180 /* Output the opcode. */
5181 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
c5cec899 5182 if (flag_debug_asm)
3f76745e
JM
5183 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
5184 dwarf_stack_op_name (loc->dw_loc_opc));
71dfc51f 5185
3f76745e 5186 fputc ('\n', asm_out_file);
71dfc51f 5187
3f76745e
JM
5188 /* Output the operand(s) (if any). */
5189 output_loc_operands (loc);
5190 }
a3f97cbb 5191 break;
3f76745e
JM
5192
5193 case dw_val_class_const:
5194 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
a3f97cbb 5195 break;
3f76745e
JM
5196
5197 case dw_val_class_unsigned_const:
5198 switch (constant_size (a->dw_attr_val.v.val_unsigned))
5199 {
5200 case 1:
5201 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5202 a->dw_attr_val.v.val_unsigned);
5203 break;
5204 case 2:
5205 ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
5206 a->dw_attr_val.v.val_unsigned);
5207 break;
5208 case 4:
5209 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5210 a->dw_attr_val.v.val_unsigned);
5211 break;
5212 case 8:
5213 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5214 a->dw_attr_val.v.val_long_long.hi,
5215 a->dw_attr_val.v.val_long_long.low);
5216 break;
5217 default:
5218 abort ();
5219 }
a3f97cbb 5220 break;
3f76745e
JM
5221
5222 case dw_val_class_long_long:
5223 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
c5cec899 5224 if (flag_debug_asm)
3f76745e
JM
5225 fprintf (asm_out_file, "\t%s %s",
5226 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5227
5228 fputc ('\n', asm_out_file);
5229 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5230 a->dw_attr_val.v.val_long_long.hi,
5231 a->dw_attr_val.v.val_long_long.low);
5232
c5cec899 5233 if (flag_debug_asm)
3f76745e
JM
5234 fprintf (asm_out_file,
5235 "\t%s long long constant", ASM_COMMENT_START);
5236
5237 fputc ('\n', asm_out_file);
a3f97cbb 5238 break;
3f76745e
JM
5239
5240 case dw_val_class_float:
5241 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5242 a->dw_attr_val.v.val_float.length * 4);
c5cec899 5243 if (flag_debug_asm)
3f76745e
JM
5244 fprintf (asm_out_file, "\t%s %s",
5245 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5246
5247 fputc ('\n', asm_out_file);
5248 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5249 {
5250 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5251 a->dw_attr_val.v.val_float.array[i]);
c5cec899 5252 if (flag_debug_asm)
3f76745e
JM
5253 fprintf (asm_out_file, "\t%s fp constant word %d",
5254 ASM_COMMENT_START, i);
5255
5256 fputc ('\n', asm_out_file);
5257 }
a3f97cbb 5258 break;
3f76745e
JM
5259
5260 case dw_val_class_flag:
5261 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
a3f97cbb 5262 break;
3f76745e
JM
5263
5264 case dw_val_class_die_ref:
5265 if (a->dw_attr_val.v.val_die_ref != NULL)
5266 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
5267 else if (a->dw_attr == DW_AT_sibling)
5268 ref_offset = sibling_offset(die);
5269 else
5270 abort ();
5271
5272 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
a3f97cbb 5273 break;
3f76745e
JM
5274
5275 case dw_val_class_fde_ref:
a6ab3aad
JM
5276 {
5277 char l1[20];
5278 ASM_GENERATE_INTERNAL_LABEL
5279 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5280 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5281 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5282 }
a3f97cbb 5283 break;
a3f97cbb 5284
3f76745e
JM
5285 case dw_val_class_lbl_id:
5286 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
5287 break;
71dfc51f 5288
3f76745e
JM
5289 case dw_val_class_section_offset:
5290 ASM_OUTPUT_DWARF_OFFSET (asm_out_file,
5291 stripattributes
5292 (a->dw_attr_val.v.val_section));
5293 break;
a3f97cbb 5294
3f76745e 5295 case dw_val_class_str:
8d4e65a6
JL
5296 if (flag_debug_asm)
5297 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
5298 else
5299 ASM_OUTPUT_ASCII (asm_out_file,
5300 a->dw_attr_val.v.val_str,
c2c85462 5301 strlen (a->dw_attr_val.v.val_str) + 1);
3f76745e 5302 break;
b2932ae5 5303
3f76745e
JM
5304 default:
5305 abort ();
5306 }
a94dbf2c 5307
3f76745e
JM
5308 if (a->dw_attr_val.val_class != dw_val_class_loc
5309 && a->dw_attr_val.val_class != dw_val_class_long_long
5310 && a->dw_attr_val.val_class != dw_val_class_float)
5311 {
c5cec899 5312 if (flag_debug_asm)
3f76745e
JM
5313 fprintf (asm_out_file, "\t%s %s",
5314 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
b2932ae5 5315
3f76745e
JM
5316 fputc ('\n', asm_out_file);
5317 }
5318 }
71dfc51f 5319
3f76745e
JM
5320 for (c = die->die_child; c != NULL; c = c->die_sib)
5321 output_die (c);
71dfc51f 5322
3f76745e 5323 if (die->die_child != NULL)
7e23cb16 5324 {
3f76745e
JM
5325 /* Add null byte to terminate sibling list. */
5326 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
c5cec899 5327 if (flag_debug_asm)
3f76745e
JM
5328 fprintf (asm_out_file, "\t%s end of children of DIE 0x%x",
5329 ASM_COMMENT_START, die->die_offset);
5330
7e23cb16
JM
5331 fputc ('\n', asm_out_file);
5332 }
3f76745e 5333}
71dfc51f 5334
3f76745e
JM
5335/* Output the compilation unit that appears at the beginning of the
5336 .debug_info section, and precedes the DIE descriptions. */
71dfc51f 5337
3f76745e
JM
5338static void
5339output_compilation_unit_header ()
5340{
5341 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
c5cec899 5342 if (flag_debug_asm)
3f76745e
JM
5343 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5344 ASM_COMMENT_START);
71dfc51f 5345
a3f97cbb 5346 fputc ('\n', asm_out_file);
3f76745e 5347 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
c5cec899 5348 if (flag_debug_asm)
3f76745e 5349 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
71dfc51f 5350
a3f97cbb 5351 fputc ('\n', asm_out_file);
3f76745e 5352 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
c5cec899 5353 if (flag_debug_asm)
3f76745e
JM
5354 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5355 ASM_COMMENT_START);
71dfc51f 5356
a3f97cbb 5357 fputc ('\n', asm_out_file);
3f76745e 5358 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
c5cec899 5359 if (flag_debug_asm)
3f76745e 5360 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
71dfc51f 5361
a3f97cbb 5362 fputc ('\n', asm_out_file);
a3f97cbb
JW
5363}
5364
a1d7ffe3
JM
5365/* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5366 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5367 argument list, and maybe the scope. */
5368
71dfc51f 5369static char *
a1d7ffe3
JM
5370dwarf2_name (decl, scope)
5371 tree decl;
5372 int scope;
5373{
5374 return (*decl_printable_name) (decl, scope ? 1 : 0);
5375}
5376
d291dd49 5377/* Add a new entry to .debug_pubnames if appropriate. */
71dfc51f 5378
d291dd49
JM
5379static void
5380add_pubname (decl, die)
5381 tree decl;
5382 dw_die_ref die;
5383{
5384 pubname_ref p;
5385
5386 if (! TREE_PUBLIC (decl))
5387 return;
5388
5389 if (pubname_table_in_use == pubname_table_allocated)
5390 {
5391 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5392 pubname_table = (pubname_ref) xrealloc
5393 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5394 }
71dfc51f 5395
d291dd49
JM
5396 p = &pubname_table[pubname_table_in_use++];
5397 p->die = die;
a1d7ffe3
JM
5398
5399 p->name = xstrdup (dwarf2_name (decl, 1));
d291dd49
JM
5400}
5401
a3f97cbb
JW
5402/* Output the public names table used to speed up access to externally
5403 visible names. For now, only generate entries for externally
5404 visible procedures. */
71dfc51f 5405
a3f97cbb
JW
5406static void
5407output_pubnames ()
5408{
d291dd49 5409 register unsigned i;
71dfc51f
RK
5410 register unsigned long pubnames_length = size_of_pubnames ();
5411
5412 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5413
c5cec899 5414 if (flag_debug_asm)
71dfc51f
RK
5415 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5416 ASM_COMMENT_START);
5417
a3f97cbb
JW
5418 fputc ('\n', asm_out_file);
5419 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
71dfc51f 5420
c5cec899 5421 if (flag_debug_asm)
71dfc51f
RK
5422 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5423
a3f97cbb 5424 fputc ('\n', asm_out_file);
c53aa195 5425 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION));
c5cec899 5426 if (flag_debug_asm)
71dfc51f
RK
5427 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5428 ASM_COMMENT_START);
5429
a3f97cbb 5430 fputc ('\n', asm_out_file);
7e23cb16 5431 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
c5cec899 5432 if (flag_debug_asm)
71dfc51f
RK
5433 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5434
a3f97cbb 5435 fputc ('\n', asm_out_file);
d291dd49 5436 for (i = 0; i < pubname_table_in_use; ++i)
a3f97cbb 5437 {
d291dd49 5438 register pubname_ref pub = &pubname_table[i];
71dfc51f 5439
7e23cb16 5440 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
c5cec899 5441 if (flag_debug_asm)
71dfc51f
RK
5442 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5443
d291dd49
JM
5444 fputc ('\n', asm_out_file);
5445
c5cec899 5446 if (flag_debug_asm)
8d4e65a6
JL
5447 {
5448 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5449 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5450 }
5451 else
5452 {
c2c85462 5453 ASM_OUTPUT_ASCII (asm_out_file, pub->name, strlen (pub->name) + 1);
8d4e65a6 5454 }
71dfc51f 5455
d291dd49 5456 fputc ('\n', asm_out_file);
a3f97cbb 5457 }
71dfc51f 5458
7e23cb16 5459 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
a3f97cbb
JW
5460 fputc ('\n', asm_out_file);
5461}
5462
d291dd49 5463/* Add a new entry to .debug_aranges if appropriate. */
71dfc51f 5464
d291dd49
JM
5465static void
5466add_arange (decl, die)
5467 tree decl;
5468 dw_die_ref die;
5469{
5470 if (! DECL_SECTION_NAME (decl))
5471 return;
5472
5473 if (arange_table_in_use == arange_table_allocated)
5474 {
5475 arange_table_allocated += ARANGE_TABLE_INCREMENT;
71dfc51f
RK
5476 arange_table
5477 = (arange_ref) xrealloc (arange_table,
5478 arange_table_allocated * sizeof (dw_die_ref));
d291dd49 5479 }
71dfc51f 5480
d291dd49
JM
5481 arange_table[arange_table_in_use++] = die;
5482}
5483
a3f97cbb
JW
5484/* Output the information that goes into the .debug_aranges table.
5485 Namely, define the beginning and ending address range of the
5486 text section generated for this compilation unit. */
71dfc51f 5487
a3f97cbb
JW
5488static void
5489output_aranges ()
5490{
d291dd49 5491 register unsigned i;
71dfc51f
RK
5492 register unsigned long aranges_length = size_of_aranges ();
5493
5494 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
c5cec899 5495 if (flag_debug_asm)
71dfc51f
RK
5496 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5497 ASM_COMMENT_START);
5498
a3f97cbb
JW
5499 fputc ('\n', asm_out_file);
5500 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
c5cec899 5501 if (flag_debug_asm)
71dfc51f
RK
5502 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5503
a3f97cbb 5504 fputc ('\n', asm_out_file);
c53aa195 5505 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION));
c5cec899 5506 if (flag_debug_asm)
71dfc51f
RK
5507 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5508 ASM_COMMENT_START);
5509
a3f97cbb
JW
5510 fputc ('\n', asm_out_file);
5511 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
c5cec899 5512 if (flag_debug_asm)
71dfc51f
RK
5513 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5514
a3f97cbb
JW
5515 fputc ('\n', asm_out_file);
5516 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
c5cec899 5517 if (flag_debug_asm)
71dfc51f
RK
5518 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5519 ASM_COMMENT_START);
5520
a3f97cbb
JW
5521 fputc ('\n', asm_out_file);
5522 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
7e23cb16
JM
5523 if (PTR_SIZE == 8)
5524 fprintf (asm_out_file, ",0,0");
71dfc51f 5525
c5cec899 5526 if (flag_debug_asm)
71dfc51f
RK
5527 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5528 ASM_COMMENT_START, 2 * PTR_SIZE);
5529
a3f97cbb 5530 fputc ('\n', asm_out_file);
bdb669cb 5531 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
c5cec899 5532 if (flag_debug_asm)
71dfc51f
RK
5533 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5534
a3f97cbb 5535 fputc ('\n', asm_out_file);
5c90448c 5536 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION);
c5cec899 5537 if (flag_debug_asm)
71dfc51f
RK
5538 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5539
a3f97cbb 5540 fputc ('\n', asm_out_file);
d291dd49
JM
5541 for (i = 0; i < arange_table_in_use; ++i)
5542 {
5543 dw_die_ref a = arange_table[i];
71dfc51f 5544
d291dd49
JM
5545 if (a->die_tag == DW_TAG_subprogram)
5546 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
5547 else
a1d7ffe3
JM
5548 {
5549 char *name = get_AT_string (a, DW_AT_MIPS_linkage_name);
5550 if (! name)
5551 name = get_AT_string (a, DW_AT_name);
71dfc51f 5552
a1d7ffe3
JM
5553 ASM_OUTPUT_DWARF_ADDR (asm_out_file, name);
5554 }
71dfc51f 5555
c5cec899 5556 if (flag_debug_asm)
71dfc51f
RK
5557 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5558
d291dd49
JM
5559 fputc ('\n', asm_out_file);
5560 if (a->die_tag == DW_TAG_subprogram)
7e23cb16
JM
5561 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
5562 get_AT_low_pc (a));
d291dd49 5563 else
7e23cb16
JM
5564 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5565 get_AT_unsigned (a, DW_AT_byte_size));
71dfc51f 5566
c5cec899 5567 if (flag_debug_asm)
71dfc51f
RK
5568 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5569
d291dd49
JM
5570 fputc ('\n', asm_out_file);
5571 }
71dfc51f 5572
a3f97cbb 5573 /* Output the terminator words. */
7e23cb16 5574 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
a3f97cbb 5575 fputc ('\n', asm_out_file);
7e23cb16 5576 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
a3f97cbb
JW
5577 fputc ('\n', asm_out_file);
5578}
5579
5580/* Output the source line number correspondence information. This
f19a6894
JW
5581 information goes into the .debug_line section.
5582
5583 If the format of this data changes, then the function size_of_line_info
5584 must also be adjusted the same way. */
71dfc51f 5585
a3f97cbb
JW
5586static void
5587output_line_info ()
5588{
a3f97cbb
JW
5589 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5590 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5591 register unsigned opc;
5592 register unsigned n_op_args;
a3f97cbb
JW
5593 register unsigned long ft_index;
5594 register unsigned long lt_index;
5595 register unsigned long current_line;
5596 register long line_offset;
5597 register long line_delta;
5598 register unsigned long current_file;
e90b62db 5599 register unsigned long function;
71dfc51f 5600
7e23cb16 5601 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
c5cec899 5602 if (flag_debug_asm)
71dfc51f
RK
5603 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5604 ASM_COMMENT_START);
5605
a3f97cbb
JW
5606 fputc ('\n', asm_out_file);
5607 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
c5cec899 5608 if (flag_debug_asm)
71dfc51f
RK
5609 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5610
a3f97cbb 5611 fputc ('\n', asm_out_file);
7e23cb16 5612 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
c5cec899 5613 if (flag_debug_asm)
71dfc51f
RK
5614 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5615
a3f97cbb
JW
5616 fputc ('\n', asm_out_file);
5617 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
c5cec899 5618 if (flag_debug_asm)
71dfc51f
RK
5619 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5620 ASM_COMMENT_START);
5621
a3f97cbb
JW
5622 fputc ('\n', asm_out_file);
5623 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
c5cec899 5624 if (flag_debug_asm)
71dfc51f
RK
5625 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5626 ASM_COMMENT_START);
5627
a3f97cbb
JW
5628 fputc ('\n', asm_out_file);
5629 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
c5cec899 5630 if (flag_debug_asm)
71dfc51f
RK
5631 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5632 ASM_COMMENT_START);
5633
a3f97cbb
JW
5634 fputc ('\n', asm_out_file);
5635 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
c5cec899 5636 if (flag_debug_asm)
71dfc51f
RK
5637 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5638 ASM_COMMENT_START);
5639
a3f97cbb
JW
5640 fputc ('\n', asm_out_file);
5641 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
c5cec899 5642 if (flag_debug_asm)
71dfc51f
RK
5643 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5644
a3f97cbb
JW
5645 fputc ('\n', asm_out_file);
5646 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5647 {
5648 switch (opc)
5649 {
5650 case DW_LNS_advance_pc:
5651 case DW_LNS_advance_line:
5652 case DW_LNS_set_file:
5653 case DW_LNS_set_column:
5654 case DW_LNS_fixed_advance_pc:
5655 n_op_args = 1;
5656 break;
5657 default:
5658 n_op_args = 0;
5659 break;
5660 }
5661 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
c5cec899 5662 if (flag_debug_asm)
71dfc51f
RK
5663 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5664 ASM_COMMENT_START, opc, n_op_args);
a3f97cbb
JW
5665 fputc ('\n', asm_out_file);
5666 }
71dfc51f 5667
c5cec899 5668 if (flag_debug_asm)
71dfc51f
RK
5669 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5670
a3f97cbb
JW
5671 /* Include directory table is empty, at present */
5672 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5673 fputc ('\n', asm_out_file);
c5cec899 5674 if (flag_debug_asm)
71dfc51f
RK
5675 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5676
a3f97cbb
JW
5677 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5678 {
c5cec899 5679 if (flag_debug_asm)
8d4e65a6
JL
5680 {
5681 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5682 fprintf (asm_out_file, "%s File Entry: 0x%x",
5683 ASM_COMMENT_START, ft_index);
5684 }
5685 else
5686 {
5687 ASM_OUTPUT_ASCII (asm_out_file,
5688 file_table[ft_index],
c2c85462 5689 strlen (file_table[ft_index]) + 1);
8d4e65a6 5690 }
71dfc51f 5691
a3f97cbb 5692 fputc ('\n', asm_out_file);
71dfc51f 5693
a3f97cbb
JW
5694 /* Include directory index */
5695 output_uleb128 (0);
5696 fputc ('\n', asm_out_file);
71dfc51f 5697
a3f97cbb
JW
5698 /* Modification time */
5699 output_uleb128 (0);
5700 fputc ('\n', asm_out_file);
71dfc51f 5701
a3f97cbb
JW
5702 /* File length in bytes */
5703 output_uleb128 (0);
5704 fputc ('\n', asm_out_file);
5705 }
71dfc51f 5706
a3f97cbb
JW
5707 /* Terminate the file name table */
5708 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5709 fputc ('\n', asm_out_file);
5710
5711 /* Set the address register to the first location in the text section */
5712 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
c5cec899 5713 if (flag_debug_asm)
71dfc51f
RK
5714 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5715
a3f97cbb
JW
5716 fputc ('\n', asm_out_file);
5717 output_uleb128 (1 + PTR_SIZE);
5718 fputc ('\n', asm_out_file);
5719 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5720 fputc ('\n', asm_out_file);
bdb669cb 5721 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
a3f97cbb
JW
5722 fputc ('\n', asm_out_file);
5723
5724 /* Generate the line number to PC correspondence table, encoded as
5725 a series of state machine operations. */
5726 current_file = 1;
5727 current_line = 1;
bdb669cb 5728 strcpy (prev_line_label, TEXT_SECTION);
a3f97cbb
JW
5729 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5730 {
e90b62db 5731 register dw_line_info_ref line_info;
71dfc51f 5732
f19a6894
JW
5733 /* Emit debug info for the address of the current line, choosing
5734 the encoding that uses the least amount of space. */
5735 /* ??? Unfortunately, we have little choice here currently, and must
5736 always use the most general form. Gcc does not know the address
5737 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5738 dwarf2 aware assemblers at this time, so we can't use any special
5739 pseudo ops that would allow the assembler to optimally encode this for
5740 us. Many ports do have length attributes which will give an upper
5741 bound on the address range. We could perhaps use length attributes
5742 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5c90448c 5743 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
f19a6894
JW
5744 if (0)
5745 {
5746 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5747 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
c5cec899 5748 if (flag_debug_asm)
f19a6894
JW
5749 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5750 ASM_COMMENT_START);
5751
5752 fputc ('\n', asm_out_file);
5753 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5754 fputc ('\n', asm_out_file);
5755 }
5756 else
5757 {
5758 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5759 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
c5cec899 5760 if (flag_debug_asm)
f19a6894
JW
5761 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5762 ASM_COMMENT_START);
5763 fputc ('\n', asm_out_file);
5764 output_uleb128 (1 + PTR_SIZE);
5765 fputc ('\n', asm_out_file);
5766 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5767 fputc ('\n', asm_out_file);
5768 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5769 fputc ('\n', asm_out_file);
5770 }
5771 strcpy (prev_line_label, line_label);
5772
5773 /* Emit debug info for the source file of the current line, if
5774 different from the previous line. */
a3f97cbb
JW
5775 line_info = &line_info_table[lt_index];
5776 if (line_info->dw_file_num != current_file)
5777 {
5778 current_file = line_info->dw_file_num;
5779 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
c5cec899 5780 if (flag_debug_asm)
71dfc51f
RK
5781 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5782
a3f97cbb
JW
5783 fputc ('\n', asm_out_file);
5784 output_uleb128 (current_file);
c5cec899 5785 if (flag_debug_asm)
b2932ae5 5786 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
71dfc51f 5787
a3f97cbb
JW
5788 fputc ('\n', asm_out_file);
5789 }
71dfc51f 5790
f19a6894
JW
5791 /* Emit debug info for the current line number, choosing the encoding
5792 that uses the least amount of space. */
a94dbf2c
JM
5793 line_offset = line_info->dw_line_num - current_line;
5794 line_delta = line_offset - DWARF_LINE_BASE;
5795 current_line = line_info->dw_line_num;
5796 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
a3f97cbb 5797 {
f19a6894
JW
5798 /* This can handle deltas from -10 to 234, using the current
5799 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5800 takes 1 byte. */
a94dbf2c
JM
5801 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5802 DWARF_LINE_OPCODE_BASE + line_delta);
c5cec899 5803 if (flag_debug_asm)
a94dbf2c
JM
5804 fprintf (asm_out_file,
5805 "\t%s line %d", ASM_COMMENT_START, current_line);
71dfc51f 5806
a94dbf2c
JM
5807 fputc ('\n', asm_out_file);
5808 }
5809 else
5810 {
f19a6894
JW
5811 /* This can handle any delta. This takes at least 4 bytes, depending
5812 on the value being encoded. */
a94dbf2c 5813 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
c5cec899 5814 if (flag_debug_asm)
71dfc51f
RK
5815 fprintf (asm_out_file, "\t%s advance to line %d",
5816 ASM_COMMENT_START, current_line);
5817
a94dbf2c
JM
5818 fputc ('\n', asm_out_file);
5819 output_sleb128 (line_offset);
5820 fputc ('\n', asm_out_file);
5821 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5822 fputc ('\n', asm_out_file);
a3f97cbb 5823 }
a3f97cbb
JW
5824 }
5825
f19a6894
JW
5826 /* Emit debug info for the address of the end of the function. */
5827 if (0)
5828 {
5829 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
c5cec899 5830 if (flag_debug_asm)
f19a6894
JW
5831 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5832 ASM_COMMENT_START);
71dfc51f 5833
f19a6894
JW
5834 fputc ('\n', asm_out_file);
5835 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5836 fputc ('\n', asm_out_file);
5837 }
5838 else
5839 {
5840 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
c5cec899 5841 if (flag_debug_asm)
f19a6894
JW
5842 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5843 fputc ('\n', asm_out_file);
5844 output_uleb128 (1 + PTR_SIZE);
5845 fputc ('\n', asm_out_file);
5846 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5847 fputc ('\n', asm_out_file);
5848 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5849 fputc ('\n', asm_out_file);
5850 }
bdb669cb 5851
a3f97cbb
JW
5852 /* Output the marker for the end of the line number info. */
5853 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
c5cec899 5854 if (flag_debug_asm)
71dfc51f
RK
5855 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5856
a3f97cbb
JW
5857 fputc ('\n', asm_out_file);
5858 output_uleb128 (1);
5859 fputc ('\n', asm_out_file);
5860 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5861 fputc ('\n', asm_out_file);
e90b62db
JM
5862
5863 function = 0;
5864 current_file = 1;
5865 current_line = 1;
5866 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5867 {
5868 register dw_separate_line_info_ref line_info
5869 = &separate_line_info_table[lt_index];
71dfc51f 5870
f19a6894
JW
5871 /* Emit debug info for the address of the current line. If this is
5872 a new function, or the first line of a function, then we need
5873 to handle it differently. */
5c90448c
JM
5874 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5875 lt_index);
e90b62db
JM
5876 if (function != line_info->function)
5877 {
5878 function = line_info->function;
71dfc51f 5879
e90b62db
JM
5880 /* Set the address register to the first line in the function */
5881 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
c5cec899 5882 if (flag_debug_asm)
e90b62db
JM
5883 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5884 ASM_COMMENT_START);
71dfc51f 5885
e90b62db
JM
5886 fputc ('\n', asm_out_file);
5887 output_uleb128 (1 + PTR_SIZE);
5888 fputc ('\n', asm_out_file);
5889 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5890 fputc ('\n', asm_out_file);
5891 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5892 fputc ('\n', asm_out_file);
5893 }
5894 else
5895 {
f19a6894
JW
5896 /* ??? See the DW_LNS_advance_pc comment above. */
5897 if (0)
5898 {
5899 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
c5cec899 5900 if (flag_debug_asm)
f19a6894
JW
5901 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5902 ASM_COMMENT_START);
71dfc51f 5903
f19a6894
JW
5904 fputc ('\n', asm_out_file);
5905 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5906 prev_line_label);
5907 fputc ('\n', asm_out_file);
5908 }
5909 else
5910 {
5911 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
c5cec899 5912 if (flag_debug_asm)
f19a6894
JW
5913 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5914 ASM_COMMENT_START);
5915 fputc ('\n', asm_out_file);
5916 output_uleb128 (1 + PTR_SIZE);
5917 fputc ('\n', asm_out_file);
5918 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5919 fputc ('\n', asm_out_file);
5920 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5921 fputc ('\n', asm_out_file);
5922 }
e90b62db 5923 }
f19a6894 5924 strcpy (prev_line_label, line_label);
71dfc51f 5925
f19a6894
JW
5926 /* Emit debug info for the source file of the current line, if
5927 different from the previous line. */
e90b62db
JM
5928 if (line_info->dw_file_num != current_file)
5929 {
5930 current_file = line_info->dw_file_num;
5931 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
c5cec899 5932 if (flag_debug_asm)
71dfc51f
RK
5933 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5934
e90b62db
JM
5935 fputc ('\n', asm_out_file);
5936 output_uleb128 (current_file);
c5cec899 5937 if (flag_debug_asm)
b2932ae5 5938 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
71dfc51f 5939
e90b62db
JM
5940 fputc ('\n', asm_out_file);
5941 }
71dfc51f 5942
f19a6894
JW
5943 /* Emit debug info for the current line number, choosing the encoding
5944 that uses the least amount of space. */
e90b62db
JM
5945 if (line_info->dw_line_num != current_line)
5946 {
5947 line_offset = line_info->dw_line_num - current_line;
5948 line_delta = line_offset - DWARF_LINE_BASE;
5949 current_line = line_info->dw_line_num;
5950 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5951 {
5952 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5953 DWARF_LINE_OPCODE_BASE + line_delta);
c5cec899 5954 if (flag_debug_asm)
71dfc51f
RK
5955 fprintf (asm_out_file,
5956 "\t%s line %d", ASM_COMMENT_START, current_line);
5957
e90b62db
JM
5958 fputc ('\n', asm_out_file);
5959 }
5960 else
5961 {
5962 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
c5cec899 5963 if (flag_debug_asm)
71dfc51f
RK
5964 fprintf (asm_out_file, "\t%s advance to line %d",
5965 ASM_COMMENT_START, current_line);
5966
e90b62db
JM
5967 fputc ('\n', asm_out_file);
5968 output_sleb128 (line_offset);
5969 fputc ('\n', asm_out_file);
5970 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5971 fputc ('\n', asm_out_file);
5972 }
5973 }
71dfc51f 5974
e90b62db 5975 ++lt_index;
e90b62db
JM
5976
5977 /* If we're done with a function, end its sequence. */
5978 if (lt_index == separate_line_info_table_in_use
5979 || separate_line_info_table[lt_index].function != function)
5980 {
5981 current_file = 1;
5982 current_line = 1;
71dfc51f 5983
f19a6894 5984 /* Emit debug info for the address of the end of the function. */
5c90448c 5985 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
f19a6894
JW
5986 if (0)
5987 {
5988 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
c5cec899 5989 if (flag_debug_asm)
f19a6894
JW
5990 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5991 ASM_COMMENT_START);
5992
5993 fputc ('\n', asm_out_file);
5994 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5995 prev_line_label);
5996 fputc ('\n', asm_out_file);
5997 }
5998 else
5999 {
6000 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
c5cec899 6001 if (flag_debug_asm)
f19a6894
JW
6002 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6003 ASM_COMMENT_START);
6004 fputc ('\n', asm_out_file);
6005 output_uleb128 (1 + PTR_SIZE);
6006 fputc ('\n', asm_out_file);
6007 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6008 fputc ('\n', asm_out_file);
6009 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6010 fputc ('\n', asm_out_file);
6011 }
e90b62db
JM
6012
6013 /* Output the marker for the end of this sequence. */
6014 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
c5cec899 6015 if (flag_debug_asm)
e90b62db
JM
6016 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
6017 ASM_COMMENT_START);
71dfc51f 6018
e90b62db
JM
6019 fputc ('\n', asm_out_file);
6020 output_uleb128 (1);
6021 fputc ('\n', asm_out_file);
6022 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6023 fputc ('\n', asm_out_file);
6024 }
6025 }
a3f97cbb
JW
6026}
6027\f
71dfc51f
RK
6028/* Given a pointer to a BLOCK node return non-zero if (and only if) the node
6029 in question represents the outermost pair of curly braces (i.e. the "body
6030 block") of a function or method.
6031
6032 For any BLOCK node representing a "body block" of a function or method, the
6033 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
6034 represents the outermost (function) scope for the function or method (i.e.
6035 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
6036 *that* node in turn will point to the relevant FUNCTION_DECL node. */
6037
6038static inline int
a3f97cbb
JW
6039is_body_block (stmt)
6040 register tree stmt;
6041{
6042 if (TREE_CODE (stmt) == BLOCK)
6043 {
6044 register tree parent = BLOCK_SUPERCONTEXT (stmt);
6045
6046 if (TREE_CODE (parent) == BLOCK)
6047 {
6048 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
6049
6050 if (TREE_CODE (grandparent) == FUNCTION_DECL)
6051 return 1;
6052 }
6053 }
71dfc51f 6054
a3f97cbb
JW
6055 return 0;
6056}
6057
a3f97cbb
JW
6058/* Given a pointer to a tree node for some base type, return a pointer to
6059 a DIE that describes the given type.
6060
6061 This routine must only be called for GCC type nodes that correspond to
6062 Dwarf base (fundamental) types. */
71dfc51f 6063
a3f97cbb
JW
6064static dw_die_ref
6065base_type_die (type)
6066 register tree type;
6067{
a9d38797
JM
6068 register dw_die_ref base_type_result;
6069 register char *type_name;
6070 register enum dwarf_type encoding;
71dfc51f 6071 register tree name = TYPE_NAME (type);
a3f97cbb 6072
a9d38797
JM
6073 if (TREE_CODE (type) == ERROR_MARK
6074 || TREE_CODE (type) == VOID_TYPE)
a3f97cbb
JW
6075 return 0;
6076
71dfc51f
RK
6077 if (TREE_CODE (name) == TYPE_DECL)
6078 name = DECL_NAME (name);
6079 type_name = IDENTIFIER_POINTER (name);
a9d38797 6080
a3f97cbb
JW
6081 switch (TREE_CODE (type))
6082 {
a3f97cbb 6083 case INTEGER_TYPE:
a9d38797 6084 /* Carefully distinguish the C character types, without messing
a3f97cbb
JW
6085 up if the language is not C. Note that we check only for the names
6086 that contain spaces; other names might occur by coincidence in other
6087 languages. */
a9d38797
JM
6088 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6089 && (type == char_type_node
6090 || ! strcmp (type_name, "signed char")
6091 || ! strcmp (type_name, "unsigned char"))))
a3f97cbb 6092 {
a9d38797
JM
6093 if (TREE_UNSIGNED (type))
6094 encoding = DW_ATE_unsigned;
6095 else
6096 encoding = DW_ATE_signed;
6097 break;
a3f97cbb 6098 }
a9d38797 6099 /* else fall through */
a3f97cbb 6100
a9d38797
JM
6101 case CHAR_TYPE:
6102 /* GNU Pascal/Ada CHAR type. Not used in C. */
6103 if (TREE_UNSIGNED (type))
6104 encoding = DW_ATE_unsigned_char;
6105 else
6106 encoding = DW_ATE_signed_char;
a3f97cbb
JW
6107 break;
6108
6109 case REAL_TYPE:
a9d38797 6110 encoding = DW_ATE_float;
a3f97cbb
JW
6111 break;
6112
6113 case COMPLEX_TYPE:
a9d38797 6114 encoding = DW_ATE_complex_float;
a3f97cbb
JW
6115 break;
6116
6117 case BOOLEAN_TYPE:
a9d38797
JM
6118 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6119 encoding = DW_ATE_boolean;
a3f97cbb
JW
6120 break;
6121
6122 default:
a9d38797 6123 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
a3f97cbb
JW
6124 }
6125
a9d38797
JM
6126 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6127 add_AT_string (base_type_result, DW_AT_name, type_name);
6128 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6129 TYPE_PRECISION (type) / BITS_PER_UNIT);
6130 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
a3f97cbb
JW
6131
6132 return base_type_result;
6133}
6134
6135/* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6136 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6137 a given type is generally the same as the given type, except that if the
6138 given type is a pointer or reference type, then the root type of the given
6139 type is the root type of the "basis" type for the pointer or reference
6140 type. (This definition of the "root" type is recursive.) Also, the root
6141 type of a `const' qualified type or a `volatile' qualified type is the
6142 root type of the given type without the qualifiers. */
71dfc51f 6143
a3f97cbb
JW
6144static tree
6145root_type (type)
6146 register tree type;
6147{
6148 if (TREE_CODE (type) == ERROR_MARK)
6149 return error_mark_node;
6150
6151 switch (TREE_CODE (type))
6152 {
6153 case ERROR_MARK:
6154 return error_mark_node;
6155
6156 case POINTER_TYPE:
6157 case REFERENCE_TYPE:
6158 return type_main_variant (root_type (TREE_TYPE (type)));
6159
6160 default:
6161 return type_main_variant (type);
6162 }
6163}
6164
6165/* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6166 given input type is a Dwarf "fundamental" type. Otherwise return null. */
71dfc51f
RK
6167
6168static inline int
a3f97cbb
JW
6169is_base_type (type)
6170 register tree type;
6171{
6172 switch (TREE_CODE (type))
6173 {
6174 case ERROR_MARK:
6175 case VOID_TYPE:
6176 case INTEGER_TYPE:
6177 case REAL_TYPE:
6178 case COMPLEX_TYPE:
6179 case BOOLEAN_TYPE:
6180 case CHAR_TYPE:
6181 return 1;
6182
6183 case SET_TYPE:
6184 case ARRAY_TYPE:
6185 case RECORD_TYPE:
6186 case UNION_TYPE:
6187 case QUAL_UNION_TYPE:
6188 case ENUMERAL_TYPE:
6189 case FUNCTION_TYPE:
6190 case METHOD_TYPE:
6191 case POINTER_TYPE:
6192 case REFERENCE_TYPE:
6193 case FILE_TYPE:
6194 case OFFSET_TYPE:
6195 case LANG_TYPE:
6196 return 0;
6197
6198 default:
6199 abort ();
6200 }
71dfc51f 6201
a3f97cbb
JW
6202 return 0;
6203}
6204
6205/* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6206 entry that chains various modifiers in front of the given type. */
71dfc51f 6207
a3f97cbb
JW
6208static dw_die_ref
6209modified_type_die (type, is_const_type, is_volatile_type, context_die)
6210 register tree type;
6211 register int is_const_type;
6212 register int is_volatile_type;
6213 register dw_die_ref context_die;
6214{
6215 register enum tree_code code = TREE_CODE (type);
6216 register dw_die_ref mod_type_die = NULL;
6217 register dw_die_ref sub_die = NULL;
dfcf9891 6218 register tree item_type = NULL;
a3f97cbb
JW
6219
6220 if (code != ERROR_MARK)
6221 {
a94dbf2c 6222 type = build_type_variant (type, is_const_type, is_volatile_type);
bdb669cb
JM
6223
6224 mod_type_die = lookup_type_die (type);
6225 if (mod_type_die)
6226 return mod_type_die;
6227
a94dbf2c
JM
6228 /* Handle C typedef types. */
6229 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6230 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6231 {
6232 tree dtype = TREE_TYPE (TYPE_NAME (type));
6233 if (type == dtype)
6234 {
6235 /* For a named type, use the typedef. */
6236 gen_type_die (type, context_die);
6237 mod_type_die = lookup_type_die (type);
6238 }
71dfc51f 6239
a94dbf2c
JM
6240 else if (is_const_type < TYPE_READONLY (dtype)
6241 || is_volatile_type < TYPE_VOLATILE (dtype))
6242 /* cv-unqualified version of named type. Just use the unnamed
6243 type to which it refers. */
71dfc51f
RK
6244 mod_type_die
6245 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6246 is_const_type, is_volatile_type,
6247 context_die);
6248 /* Else cv-qualified version of named type; fall through. */
a94dbf2c
JM
6249 }
6250
6251 if (mod_type_die)
6252 /* OK */;
6253 else if (is_const_type)
a3f97cbb 6254 {
ab72d377 6255 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
a9d38797 6256 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
a3f97cbb
JW
6257 }
6258 else if (is_volatile_type)
6259 {
ab72d377 6260 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
a9d38797 6261 sub_die = modified_type_die (type, 0, 0, context_die);
a3f97cbb
JW
6262 }
6263 else if (code == POINTER_TYPE)
6264 {
ab72d377 6265 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
a3f97cbb 6266 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
61b32c02 6267#if 0
a3f97cbb 6268 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
61b32c02 6269#endif
a3f97cbb 6270 item_type = TREE_TYPE (type);
a3f97cbb
JW
6271 }
6272 else if (code == REFERENCE_TYPE)
6273 {
ab72d377 6274 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
a3f97cbb 6275 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
61b32c02 6276#if 0
a3f97cbb 6277 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
61b32c02 6278#endif
a3f97cbb 6279 item_type = TREE_TYPE (type);
a3f97cbb
JW
6280 }
6281 else if (is_base_type (type))
71dfc51f 6282 mod_type_die = base_type_die (type);
a3f97cbb
JW
6283 else
6284 {
4b674448
JM
6285 gen_type_die (type, context_die);
6286
a3f97cbb
JW
6287 /* We have to get the type_main_variant here (and pass that to the
6288 `lookup_type_die' routine) because the ..._TYPE node we have
6289 might simply be a *copy* of some original type node (where the
6290 copy was created to help us keep track of typedef names) and
6291 that copy might have a different TYPE_UID from the original
a94dbf2c 6292 ..._TYPE node. */
a3f97cbb 6293 mod_type_die = lookup_type_die (type_main_variant (type));
3a88cbd1
JL
6294 if (mod_type_die == NULL)
6295 abort ();
a3f97cbb
JW
6296 }
6297 }
71dfc51f 6298
dfcf9891
JW
6299 equate_type_number_to_die (type, mod_type_die);
6300 if (item_type)
71dfc51f
RK
6301 /* We must do this after the equate_type_number_to_die call, in case
6302 this is a recursive type. This ensures that the modified_type_die
6303 recursion will terminate even if the type is recursive. Recursive
6304 types are possible in Ada. */
6305 sub_die = modified_type_die (item_type,
6306 TYPE_READONLY (item_type),
6307 TYPE_VOLATILE (item_type),
6308 context_die);
6309
a3f97cbb 6310 if (sub_die != NULL)
71dfc51f
RK
6311 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6312
a3f97cbb
JW
6313 return mod_type_die;
6314}
6315
a3f97cbb
JW
6316/* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6317 an enumerated type. */
71dfc51f
RK
6318
6319static inline int
a3f97cbb
JW
6320type_is_enum (type)
6321 register tree type;
6322{
6323 return TREE_CODE (type) == ENUMERAL_TYPE;
6324}
6325
a3f97cbb 6326/* Return a location descriptor that designates a machine register. */
71dfc51f 6327
a3f97cbb
JW
6328static dw_loc_descr_ref
6329reg_loc_descriptor (rtl)
6330 register rtx rtl;
6331{
6332 register dw_loc_descr_ref loc_result = NULL;
6333 register unsigned reg = reg_number (rtl);
71dfc51f 6334
a3f97cbb 6335 if (reg >= 0 && reg <= 31)
71dfc51f 6336 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
a3f97cbb 6337 else
71dfc51f
RK
6338 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6339
a3f97cbb
JW
6340 return loc_result;
6341}
6342
6343/* Return a location descriptor that designates a base+offset location. */
71dfc51f 6344
a3f97cbb
JW
6345static dw_loc_descr_ref
6346based_loc_descr (reg, offset)
6347 unsigned reg;
6348 long int offset;
6349{
6350 register dw_loc_descr_ref loc_result;
810429b7
JM
6351 /* For the "frame base", we use the frame pointer or stack pointer
6352 registers, since the RTL for local variables is relative to one of
6353 them. */
6354 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
b1ccbc24 6355 ? HARD_FRAME_POINTER_REGNUM
810429b7 6356 : STACK_POINTER_REGNUM);
71dfc51f 6357
a3f97cbb 6358 if (reg == fp_reg)
71dfc51f 6359 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
a3f97cbb 6360 else if (reg >= 0 && reg <= 31)
71dfc51f 6361 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
a3f97cbb 6362 else
71dfc51f
RK
6363 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6364
a3f97cbb
JW
6365 return loc_result;
6366}
6367
6368/* Return true if this RTL expression describes a base+offset calculation. */
71dfc51f
RK
6369
6370static inline int
a3f97cbb
JW
6371is_based_loc (rtl)
6372 register rtx rtl;
6373{
71dfc51f
RK
6374 return (GET_CODE (rtl) == PLUS
6375 && ((GET_CODE (XEXP (rtl, 0)) == REG
6376 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
a3f97cbb
JW
6377}
6378
6379/* The following routine converts the RTL for a variable or parameter
6380 (resident in memory) into an equivalent Dwarf representation of a
6381 mechanism for getting the address of that same variable onto the top of a
6382 hypothetical "address evaluation" stack.
71dfc51f 6383
a3f97cbb
JW
6384 When creating memory location descriptors, we are effectively transforming
6385 the RTL for a memory-resident object into its Dwarf postfix expression
6386 equivalent. This routine recursively descends an RTL tree, turning
6387 it into Dwarf postfix code as it goes. */
71dfc51f 6388
a3f97cbb
JW
6389static dw_loc_descr_ref
6390mem_loc_descriptor (rtl)
6391 register rtx rtl;
6392{
6393 dw_loc_descr_ref mem_loc_result = NULL;
6394 /* Note that for a dynamically sized array, the location we will generate a
6395 description of here will be the lowest numbered location which is
6396 actually within the array. That's *not* necessarily the same as the
6397 zeroth element of the array. */
71dfc51f 6398
a3f97cbb
JW
6399 switch (GET_CODE (rtl))
6400 {
6401 case SUBREG:
6402 /* The case of a subreg may arise when we have a local (register)
6403 variable or a formal (register) parameter which doesn't quite fill
6404 up an entire register. For now, just assume that it is
6405 legitimate to make the Dwarf info refer to the whole register which
6406 contains the given subreg. */
6407 rtl = XEXP (rtl, 0);
71dfc51f
RK
6408
6409 /* ... fall through ... */
a3f97cbb
JW
6410
6411 case REG:
6412 /* Whenever a register number forms a part of the description of the
6413 method for calculating the (dynamic) address of a memory resident
6414 object, DWARF rules require the register number be referred to as
6415 a "base register". This distinction is not based in any way upon
6416 what category of register the hardware believes the given register
6417 belongs to. This is strictly DWARF terminology we're dealing with
6418 here. Note that in cases where the location of a memory-resident
6419 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6420 OP_CONST (0)) the actual DWARF location descriptor that we generate
6421 may just be OP_BASEREG (basereg). This may look deceptively like
6422 the object in question was allocated to a register (rather than in
6423 memory) so DWARF consumers need to be aware of the subtle
6424 distinction between OP_REG and OP_BASEREG. */
6425 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6426 break;
6427
6428 case MEM:
6429 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
6430 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6431 break;
6432
6433 case CONST:
6434 case SYMBOL_REF:
6435 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6436 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6437 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
6438 break;
6439
6440 case PLUS:
6441 if (is_based_loc (rtl))
71dfc51f
RK
6442 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6443 INTVAL (XEXP (rtl, 1)));
a3f97cbb
JW
6444 else
6445 {
6446 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
6447 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
6448 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6449 }
6450 break;
6451
dd2478ae
JW
6452 case MULT:
6453 /* If a pseudo-reg is optimized away, it is possible for it to
6454 be replaced with a MEM containing a multiply. */
6455 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
6456 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
6457 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6458 break;
6459
a3f97cbb
JW
6460 case CONST_INT:
6461 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6462 break;
6463
6464 default:
6465 abort ();
6466 }
71dfc51f 6467
a3f97cbb
JW
6468 return mem_loc_result;
6469}
6470
956d6950 6471/* Return a descriptor that describes the concatenation of two locations.
4401bf24
JL
6472 This is typically a complex variable. */
6473
6474static dw_loc_descr_ref
6475concat_loc_descriptor (x0, x1)
6476 register rtx x0, x1;
6477{
6478 dw_loc_descr_ref cc_loc_result = NULL;
6479
6480 if (!is_pseudo_reg (x0)
6481 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6482 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6483 add_loc_descr (&cc_loc_result,
6484 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6485
6486 if (!is_pseudo_reg (x1)
6487 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6488 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6489 add_loc_descr (&cc_loc_result,
6490 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6491
6492 return cc_loc_result;
6493}
6494
a3f97cbb
JW
6495/* Output a proper Dwarf location descriptor for a variable or parameter
6496 which is either allocated in a register or in a memory location. For a
6497 register, we just generate an OP_REG and the register number. For a
6498 memory location we provide a Dwarf postfix expression describing how to
6499 generate the (dynamic) address of the object onto the address stack. */
71dfc51f 6500
a3f97cbb
JW
6501static dw_loc_descr_ref
6502loc_descriptor (rtl)
6503 register rtx rtl;
6504{
6505 dw_loc_descr_ref loc_result = NULL;
6506 switch (GET_CODE (rtl))
6507 {
6508 case SUBREG:
a3f97cbb
JW
6509 /* The case of a subreg may arise when we have a local (register)
6510 variable or a formal (register) parameter which doesn't quite fill
71dfc51f 6511 up an entire register. For now, just assume that it is
a3f97cbb
JW
6512 legitimate to make the Dwarf info refer to the whole register which
6513 contains the given subreg. */
a3f97cbb 6514 rtl = XEXP (rtl, 0);
71dfc51f
RK
6515
6516 /* ... fall through ... */
a3f97cbb
JW
6517
6518 case REG:
5c90448c 6519 loc_result = reg_loc_descriptor (rtl);
a3f97cbb
JW
6520 break;
6521
6522 case MEM:
6523 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
6524 break;
6525
4401bf24
JL
6526 case CONCAT:
6527 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6528 break;
6529
a3f97cbb 6530 default:
71dfc51f 6531 abort ();
a3f97cbb 6532 }
71dfc51f 6533
a3f97cbb
JW
6534 return loc_result;
6535}
6536
6537/* Given an unsigned value, round it up to the lowest multiple of `boundary'
6538 which is not less than the value itself. */
71dfc51f
RK
6539
6540static inline unsigned
a3f97cbb
JW
6541ceiling (value, boundary)
6542 register unsigned value;
6543 register unsigned boundary;
6544{
6545 return (((value + boundary - 1) / boundary) * boundary);
6546}
6547
6548/* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6549 pointer to the declared type for the relevant field variable, or return
6550 `integer_type_node' if the given node turns out to be an
6551 ERROR_MARK node. */
71dfc51f
RK
6552
6553static inline tree
a3f97cbb
JW
6554field_type (decl)
6555 register tree decl;
6556{
6557 register tree type;
6558
6559 if (TREE_CODE (decl) == ERROR_MARK)
6560 return integer_type_node;
6561
6562 type = DECL_BIT_FIELD_TYPE (decl);
71dfc51f 6563 if (type == NULL_TREE)
a3f97cbb
JW
6564 type = TREE_TYPE (decl);
6565
6566 return type;
6567}
6568
6569/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6570 node, return the alignment in bits for the type, or else return
6571 BITS_PER_WORD if the node actually turns out to be an
6572 ERROR_MARK node. */
71dfc51f
RK
6573
6574static inline unsigned
a3f97cbb
JW
6575simple_type_align_in_bits (type)
6576 register tree type;
6577{
6578 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6579}
6580
6581/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6582 node, return the size in bits for the type if it is a constant, or else
6583 return the alignment for the type if the type's size is not constant, or
6584 else return BITS_PER_WORD if the type actually turns out to be an
6585 ERROR_MARK node. */
71dfc51f
RK
6586
6587static inline unsigned
a3f97cbb
JW
6588simple_type_size_in_bits (type)
6589 register tree type;
6590{
6591 if (TREE_CODE (type) == ERROR_MARK)
6592 return BITS_PER_WORD;
6593 else
6594 {
6595 register tree type_size_tree = TYPE_SIZE (type);
6596
6597 if (TREE_CODE (type_size_tree) != INTEGER_CST)
6598 return TYPE_ALIGN (type);
6599
6600 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
6601 }
6602}
6603
6604/* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6605 return the byte offset of the lowest addressed byte of the "containing
6606 object" for the given FIELD_DECL, or return 0 if we are unable to
6607 determine what that offset is, either because the argument turns out to
6608 be a pointer to an ERROR_MARK node, or because the offset is actually
6609 variable. (We can't handle the latter case just yet). */
71dfc51f 6610
a3f97cbb
JW
6611static unsigned
6612field_byte_offset (decl)
6613 register tree decl;
6614{
6615 register unsigned type_align_in_bytes;
6616 register unsigned type_align_in_bits;
6617 register unsigned type_size_in_bits;
6618 register unsigned object_offset_in_align_units;
6619 register unsigned object_offset_in_bits;
6620 register unsigned object_offset_in_bytes;
6621 register tree type;
6622 register tree bitpos_tree;
6623 register tree field_size_tree;
6624 register unsigned bitpos_int;
6625 register unsigned deepest_bitpos;
6626 register unsigned field_size_in_bits;
6627
6628 if (TREE_CODE (decl) == ERROR_MARK)
6629 return 0;
6630
6631 if (TREE_CODE (decl) != FIELD_DECL)
6632 abort ();
6633
6634 type = field_type (decl);
6635
6636 bitpos_tree = DECL_FIELD_BITPOS (decl);
6637 field_size_tree = DECL_SIZE (decl);
6638
6639 /* We cannot yet cope with fields whose positions or sizes are variable, so
6640 for now, when we see such things, we simply return 0. Someday, we may
6641 be able to handle such cases, but it will be damn difficult. */
6642 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6643 return 0;
6644 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6645
6646 if (TREE_CODE (field_size_tree) != INTEGER_CST)
6647 return 0;
a3f97cbb 6648
71dfc51f 6649 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
a3f97cbb 6650 type_size_in_bits = simple_type_size_in_bits (type);
a3f97cbb
JW
6651 type_align_in_bits = simple_type_align_in_bits (type);
6652 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6653
6654 /* Note that the GCC front-end doesn't make any attempt to keep track of
6655 the starting bit offset (relative to the start of the containing
6656 structure type) of the hypothetical "containing object" for a bit-
6657 field. Thus, when computing the byte offset value for the start of the
6658 "containing object" of a bit-field, we must deduce this information on
6659 our own. This can be rather tricky to do in some cases. For example,
6660 handling the following structure type definition when compiling for an
6661 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6662 can be very tricky:
6663
6664 struct S { int field1; long long field2:31; };
6665
6666 Fortunately, there is a simple rule-of-thumb which can be
6667 used in such cases. When compiling for an i386/i486, GCC will allocate
6668 8 bytes for the structure shown above. It decides to do this based upon
6669 one simple rule for bit-field allocation. Quite simply, GCC allocates
6670 each "containing object" for each bit-field at the first (i.e. lowest
6671 addressed) legitimate alignment boundary (based upon the required
6672 minimum alignment for the declared type of the field) which it can
6673 possibly use, subject to the condition that there is still enough
6674 available space remaining in the containing object (when allocated at
6675 the selected point) to fully accommodate all of the bits of the
6676 bit-field itself. This simple rule makes it obvious why GCC allocates
6677 8 bytes for each object of the structure type shown above. When looking
6678 for a place to allocate the "containing object" for `field2', the
6679 compiler simply tries to allocate a 64-bit "containing object" at each
6680 successive 32-bit boundary (starting at zero) until it finds a place to
6681 allocate that 64- bit field such that at least 31 contiguous (and
6682 previously unallocated) bits remain within that selected 64 bit field.
6683 (As it turns out, for the example above, the compiler finds that it is
6684 OK to allocate the "containing object" 64-bit field at bit-offset zero
6685 within the structure type.) Here we attempt to work backwards from the
6686 limited set of facts we're given, and we try to deduce from those facts,
6687 where GCC must have believed that the containing object started (within
6688 the structure type). The value we deduce is then used (by the callers of
6689 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6690 for fields (both bit-fields and, in the case of DW_AT_location, regular
6691 fields as well). */
6692
6693 /* Figure out the bit-distance from the start of the structure to the
6694 "deepest" bit of the bit-field. */
6695 deepest_bitpos = bitpos_int + field_size_in_bits;
6696
6697 /* This is the tricky part. Use some fancy footwork to deduce where the
6698 lowest addressed bit of the containing object must be. */
6699 object_offset_in_bits
6700 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6701
6702 /* Compute the offset of the containing object in "alignment units". */
6703 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6704
6705 /* Compute the offset of the containing object in bytes. */
6706 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6707
6708 return object_offset_in_bytes;
6709}
a3f97cbb 6710\f
71dfc51f
RK
6711/* The following routines define various Dwarf attributes and any data
6712 associated with them. */
a3f97cbb 6713
ef76d03b 6714/* Add a location description attribute value to a DIE.
a3f97cbb 6715
ef76d03b 6716 This emits location attributes suitable for whole variables and
a3f97cbb
JW
6717 whole parameters. Note that the location attributes for struct fields are
6718 generated by the routine `data_member_location_attribute' below. */
71dfc51f 6719
a3f97cbb 6720static void
ef76d03b 6721add_AT_location_description (die, attr_kind, rtl)
a3f97cbb 6722 dw_die_ref die;
ef76d03b 6723 enum dwarf_attribute attr_kind;
a3f97cbb
JW
6724 register rtx rtl;
6725{
a3f97cbb
JW
6726 /* Handle a special case. If we are about to output a location descriptor
6727 for a variable or parameter which has been optimized out of existence,
6a7a9f01 6728 don't do that. A variable which has been optimized out
a3f97cbb
JW
6729 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6730 Currently, in some rare cases, variables can have DECL_RTL values which
6731 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6732 elsewhere in the compiler. We treat such cases as if the variable(s) in
6a7a9f01 6733 question had been optimized out of existence. */
a3f97cbb 6734
6a7a9f01
JM
6735 if (is_pseudo_reg (rtl)
6736 || (GET_CODE (rtl) == MEM
4401bf24
JL
6737 && is_pseudo_reg (XEXP (rtl, 0)))
6738 || (GET_CODE (rtl) == CONCAT
6739 && is_pseudo_reg (XEXP (rtl, 0))
6740 && is_pseudo_reg (XEXP (rtl, 1))))
6a7a9f01 6741 return;
a3f97cbb 6742
6a7a9f01 6743 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
a3f97cbb
JW
6744}
6745
6746/* Attach the specialized form of location attribute used for data
6747 members of struct and union types. In the special case of a
6748 FIELD_DECL node which represents a bit-field, the "offset" part
6749 of this special location descriptor must indicate the distance
6750 in bytes from the lowest-addressed byte of the containing struct
6751 or union type to the lowest-addressed byte of the "containing
6752 object" for the bit-field. (See the `field_byte_offset' function
6753 above).. For any given bit-field, the "containing object" is a
6754 hypothetical object (of some integral or enum type) within which
6755 the given bit-field lives. The type of this hypothetical
6756 "containing object" is always the same as the declared type of
6757 the individual bit-field itself (for GCC anyway... the DWARF
6758 spec doesn't actually mandate this). Note that it is the size
6759 (in bytes) of the hypothetical "containing object" which will
6760 be given in the DW_AT_byte_size attribute for this bit-field.
6761 (See the `byte_size_attribute' function below.) It is also used
6762 when calculating the value of the DW_AT_bit_offset attribute.
6763 (See the `bit_offset_attribute' function below). */
71dfc51f 6764
a3f97cbb
JW
6765static void
6766add_data_member_location_attribute (die, decl)
6767 register dw_die_ref die;
6768 register tree decl;
6769{
61b32c02 6770 register unsigned long offset;
a3f97cbb
JW
6771 register dw_loc_descr_ref loc_descr;
6772 register enum dwarf_location_atom op;
6773
61b32c02
JM
6774 if (TREE_CODE (decl) == TREE_VEC)
6775 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6776 else
6777 offset = field_byte_offset (decl);
6778
a3f97cbb
JW
6779 /* The DWARF2 standard says that we should assume that the structure address
6780 is already on the stack, so we can specify a structure field address
6781 by using DW_OP_plus_uconst. */
71dfc51f 6782
a3f97cbb
JW
6783#ifdef MIPS_DEBUGGING_INFO
6784 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6785 correctly. It works only if we leave the offset on the stack. */
6786 op = DW_OP_constu;
6787#else
6788 op = DW_OP_plus_uconst;
6789#endif
71dfc51f 6790
a3f97cbb
JW
6791 loc_descr = new_loc_descr (op, offset, 0);
6792 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6793}
6794
6795/* Attach an DW_AT_const_value attribute for a variable or a parameter which
6796 does not have a "location" either in memory or in a register. These
6797 things can arise in GNU C when a constant is passed as an actual parameter
6798 to an inlined function. They can also arise in C++ where declared
6799 constants do not necessarily get memory "homes". */
71dfc51f 6800
a3f97cbb
JW
6801static void
6802add_const_value_attribute (die, rtl)
6803 register dw_die_ref die;
6804 register rtx rtl;
6805{
6806 switch (GET_CODE (rtl))
6807 {
6808 case CONST_INT:
6809 /* Note that a CONST_INT rtx could represent either an integer or a
6810 floating-point constant. A CONST_INT is used whenever the constant
6811 will fit into a single word. In all such cases, the original mode
6812 of the constant value is wiped out, and the CONST_INT rtx is
6813 assigned VOIDmode. */
6814 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6815 break;
6816
6817 case CONST_DOUBLE:
6818 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6819 floating-point constant. A CONST_DOUBLE is used whenever the
6820 constant requires more than one word in order to be adequately
469ac993
JM
6821 represented. We output CONST_DOUBLEs as blocks. */
6822 {
6823 register enum machine_mode mode = GET_MODE (rtl);
6824
6825 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6826 {
71dfc51f
RK
6827 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6828 long array[4];
6829 REAL_VALUE_TYPE rv;
469ac993 6830
71dfc51f 6831 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
469ac993
JM
6832 switch (mode)
6833 {
6834 case SFmode:
71dfc51f 6835 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
469ac993
JM
6836 break;
6837
6838 case DFmode:
71dfc51f 6839 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
469ac993
JM
6840 break;
6841
6842 case XFmode:
6843 case TFmode:
71dfc51f 6844 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
469ac993
JM
6845 break;
6846
6847 default:
6848 abort ();
6849 }
6850
469ac993
JM
6851 add_AT_float (die, DW_AT_const_value, length, array);
6852 }
6853 else
6854 add_AT_long_long (die, DW_AT_const_value,
6855 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6856 }
a3f97cbb
JW
6857 break;
6858
6859 case CONST_STRING:
6860 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6861 break;
6862
6863 case SYMBOL_REF:
6864 case LABEL_REF:
6865 case CONST:
6866 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
6867 break;
6868
6869 case PLUS:
6870 /* In cases where an inlined instance of an inline function is passed
6871 the address of an `auto' variable (which is local to the caller) we
6872 can get a situation where the DECL_RTL of the artificial local
6873 variable (for the inlining) which acts as a stand-in for the
6874 corresponding formal parameter (of the inline function) will look
6875 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6876 exactly a compile-time constant expression, but it isn't the address
6877 of the (artificial) local variable either. Rather, it represents the
6878 *value* which the artificial local variable always has during its
6879 lifetime. We currently have no way to represent such quasi-constant
6a7a9f01 6880 values in Dwarf, so for now we just punt and generate nothing. */
a3f97cbb
JW
6881 break;
6882
6883 default:
6884 /* No other kinds of rtx should be possible here. */
6885 abort ();
6886 }
6887
6888}
6889
6890/* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6891 data attribute for a variable or a parameter. We generate the
6892 DW_AT_const_value attribute only in those cases where the given variable
6893 or parameter does not have a true "location" either in memory or in a
6894 register. This can happen (for example) when a constant is passed as an
6895 actual argument in a call to an inline function. (It's possible that
6896 these things can crop up in other ways also.) Note that one type of
6897 constant value which can be passed into an inlined function is a constant
6898 pointer. This can happen for example if an actual argument in an inlined
6899 function call evaluates to a compile-time constant address. */
71dfc51f 6900
a3f97cbb
JW
6901static void
6902add_location_or_const_value_attribute (die, decl)
6903 register dw_die_ref die;
6904 register tree decl;
6905{
6906 register rtx rtl;
6907 register tree declared_type;
6908 register tree passed_type;
6909
6910 if (TREE_CODE (decl) == ERROR_MARK)
71dfc51f
RK
6911 return;
6912
6913 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6914 abort ();
6915
a3f97cbb
JW
6916 /* Here we have to decide where we are going to say the parameter "lives"
6917 (as far as the debugger is concerned). We only have a couple of
6918 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
71dfc51f 6919
a3f97cbb 6920 DECL_RTL normally indicates where the parameter lives during most of the
71dfc51f 6921 activation of the function. If optimization is enabled however, this
a3f97cbb
JW
6922 could be either NULL or else a pseudo-reg. Both of those cases indicate
6923 that the parameter doesn't really live anywhere (as far as the code
6924 generation parts of GCC are concerned) during most of the function's
6925 activation. That will happen (for example) if the parameter is never
71dfc51f
RK
6926 referenced within the function.
6927
6928 We could just generate a location descriptor here for all non-NULL
6929 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6930 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6931 where DECL_RTL is NULL or is a pseudo-reg.
6932
6933 Note however that we can only get away with using DECL_INCOMING_RTL as
6934 a backup substitute for DECL_RTL in certain limited cases. In cases
6935 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6936 we can be sure that the parameter was passed using the same type as it is
6937 declared to have within the function, and that its DECL_INCOMING_RTL
6938 points us to a place where a value of that type is passed.
6939
6940 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6941 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6942 because in these cases DECL_INCOMING_RTL points us to a value of some
6943 type which is *different* from the type of the parameter itself. Thus,
6944 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6945 such cases, the debugger would end up (for example) trying to fetch a
6946 `float' from a place which actually contains the first part of a
6947 `double'. That would lead to really incorrect and confusing
6948 output at debug-time.
6949
6950 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6951 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6952 are a couple of exceptions however. On little-endian machines we can
6953 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6954 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6955 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6956 when (on a little-endian machine) a non-prototyped function has a
6957 parameter declared to be of type `short' or `char'. In such cases,
6958 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6959 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6960 passed `int' value. If the debugger then uses that address to fetch
6961 a `short' or a `char' (on a little-endian machine) the result will be
6962 the correct data, so we allow for such exceptional cases below.
6963
6964 Note that our goal here is to describe the place where the given formal
6965 parameter lives during most of the function's activation (i.e. between
6966 the end of the prologue and the start of the epilogue). We'll do that
6967 as best as we can. Note however that if the given formal parameter is
6968 modified sometime during the execution of the function, then a stack
6969 backtrace (at debug-time) will show the function as having been
6970 called with the *new* value rather than the value which was
6971 originally passed in. This happens rarely enough that it is not
6972 a major problem, but it *is* a problem, and I'd like to fix it.
6973
6974 A future version of dwarf2out.c may generate two additional
6975 attributes for any given DW_TAG_formal_parameter DIE which will
6976 describe the "passed type" and the "passed location" for the
6977 given formal parameter in addition to the attributes we now
6978 generate to indicate the "declared type" and the "active
6979 location" for each parameter. This additional set of attributes
6980 could be used by debuggers for stack backtraces. Separately, note
6981 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6982 NULL also. This happens (for example) for inlined-instances of
6983 inline function formal parameters which are never referenced.
6984 This really shouldn't be happening. All PARM_DECL nodes should
6985 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6986 doesn't currently generate these values for inlined instances of
6987 inline function parameters, so when we see such cases, we are
956d6950 6988 just out-of-luck for the time being (until integrate.c
a3f97cbb
JW
6989 gets fixed). */
6990
6991 /* Use DECL_RTL as the "location" unless we find something better. */
6992 rtl = DECL_RTL (decl);
6993
6994 if (TREE_CODE (decl) == PARM_DECL)
6995 {
6996 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6997 {
6998 declared_type = type_main_variant (TREE_TYPE (decl));
6999 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
a3f97cbb 7000
71dfc51f 7001 /* This decl represents a formal parameter which was optimized out.
a3f97cbb
JW
7002 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7003 all* cases where (rtl == NULL_RTX) just below. */
7004 if (declared_type == passed_type)
71dfc51f
RK
7005 rtl = DECL_INCOMING_RTL (decl);
7006 else if (! BYTES_BIG_ENDIAN
7007 && TREE_CODE (declared_type) == INTEGER_TYPE
7008 && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
7009 rtl = DECL_INCOMING_RTL (decl);
a3f97cbb
JW
7010 }
7011 }
71dfc51f 7012
61b32c02
JM
7013 if (rtl == NULL_RTX)
7014 return;
7015
1914f5da 7016 rtl = eliminate_regs (rtl, 0, NULL_RTX);
6a7a9f01
JM
7017#ifdef LEAF_REG_REMAP
7018 if (leaf_function)
5f52dcfe 7019 leaf_renumber_regs_insn (rtl);
6a7a9f01
JM
7020#endif
7021
a3f97cbb
JW
7022 switch (GET_CODE (rtl))
7023 {
e9a25f70
JL
7024 case ADDRESSOF:
7025 /* The address of a variable that was optimized away; don't emit
7026 anything. */
7027 break;
7028
a3f97cbb
JW
7029 case CONST_INT:
7030 case CONST_DOUBLE:
7031 case CONST_STRING:
7032 case SYMBOL_REF:
7033 case LABEL_REF:
7034 case CONST:
7035 case PLUS:
7036 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7037 add_const_value_attribute (die, rtl);
7038 break;
7039
7040 case MEM:
7041 case REG:
7042 case SUBREG:
4401bf24 7043 case CONCAT:
ef76d03b 7044 add_AT_location_description (die, DW_AT_location, rtl);
a3f97cbb
JW
7045 break;
7046
7047 default:
71dfc51f 7048 abort ();
a3f97cbb
JW
7049 }
7050}
7051
7052/* Generate an DW_AT_name attribute given some string value to be included as
7053 the value of the attribute. */
71dfc51f
RK
7054
7055static inline void
a3f97cbb
JW
7056add_name_attribute (die, name_string)
7057 register dw_die_ref die;
7058 register char *name_string;
7059{
71dfc51f
RK
7060 if (name_string != NULL && *name_string != 0)
7061 add_AT_string (die, DW_AT_name, name_string);
a3f97cbb
JW
7062}
7063
7064/* Given a tree node describing an array bound (either lower or upper) output
466446b0 7065 a representation for that bound. */
71dfc51f 7066
a3f97cbb
JW
7067static void
7068add_bound_info (subrange_die, bound_attr, bound)
7069 register dw_die_ref subrange_die;
7070 register enum dwarf_attribute bound_attr;
7071 register tree bound;
7072{
a3f97cbb 7073 register unsigned bound_value = 0;
ef76d03b
JW
7074
7075 /* If this is an Ada unconstrained array type, then don't emit any debug
7076 info because the array bounds are unknown. They are parameterized when
7077 the type is instantiated. */
7078 if (contains_placeholder_p (bound))
7079 return;
7080
a3f97cbb
JW
7081 switch (TREE_CODE (bound))
7082 {
7083 case ERROR_MARK:
7084 return;
7085
7086 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7087 case INTEGER_CST:
7088 bound_value = TREE_INT_CST_LOW (bound);
141719a8
JM
7089 if (bound_attr == DW_AT_lower_bound
7090 && ((is_c_family () && bound_value == 0)
7091 || (is_fortran () && bound_value == 1)))
7092 /* use the default */;
7093 else
7094 add_AT_unsigned (subrange_die, bound_attr, bound_value);
a3f97cbb
JW
7095 break;
7096
b1ccbc24 7097 case CONVERT_EXPR:
a3f97cbb 7098 case NOP_EXPR:
b1ccbc24
RK
7099 case NON_LVALUE_EXPR:
7100 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7101 break;
7102
a3f97cbb
JW
7103 case SAVE_EXPR:
7104 /* If optimization is turned on, the SAVE_EXPRs that describe how to
466446b0
JM
7105 access the upper bound values may be bogus. If they refer to a
7106 register, they may only describe how to get at these values at the
7107 points in the generated code right after they have just been
7108 computed. Worse yet, in the typical case, the upper bound values
7109 will not even *be* computed in the optimized code (though the
7110 number of elements will), so these SAVE_EXPRs are entirely
7111 bogus. In order to compensate for this fact, we check here to see
7112 if optimization is enabled, and if so, we don't add an attribute
7113 for the (unknown and unknowable) upper bound. This should not
7114 cause too much trouble for existing (stupid?) debuggers because
7115 they have to deal with empty upper bounds location descriptions
7116 anyway in order to be able to deal with incomplete array types.
7117 Of course an intelligent debugger (GDB?) should be able to
7118 comprehend that a missing upper bound specification in a array
7119 type used for a storage class `auto' local array variable
7120 indicates that the upper bound is both unknown (at compile- time)
7121 and unknowable (at run-time) due to optimization.
7122
7123 We assume that a MEM rtx is safe because gcc wouldn't put the
7124 value there unless it was going to be used repeatedly in the
7125 function, i.e. for cleanups. */
7126 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
a3f97cbb 7127 {
466446b0
JM
7128 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7129 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7130 add_AT_flag (decl_die, DW_AT_artificial, 1);
7131 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
ef76d03b
JW
7132 add_AT_location_description (decl_die, DW_AT_location,
7133 SAVE_EXPR_RTL (bound));
466446b0 7134 add_AT_die_ref (subrange_die, bound_attr, decl_die);
a3f97cbb 7135 }
71dfc51f
RK
7136
7137 /* Else leave out the attribute. */
a3f97cbb 7138 break;
3f76745e 7139
ef76d03b
JW
7140 case MAX_EXPR:
7141 case VAR_DECL:
c85f7c16 7142 case COMPONENT_REF:
ef76d03b
JW
7143 /* ??? These types of bounds can be created by the Ada front end,
7144 and it isn't clear how to emit debug info for them. */
7145 break;
7146
3f76745e
JM
7147 default:
7148 abort ();
a3f97cbb
JW
7149 }
7150}
7151
7152/* Note that the block of subscript information for an array type also
7153 includes information about the element type of type given array type. */
71dfc51f 7154
a3f97cbb
JW
7155static void
7156add_subscript_info (type_die, type)
7157 register dw_die_ref type_die;
7158 register tree type;
7159{
7160 register unsigned dimension_number;
7161 register tree lower, upper;
7162 register dw_die_ref subrange_die;
7163
7164 /* The GNU compilers represent multidimensional array types as sequences of
7165 one dimensional array types whose element types are themselves array
7166 types. Here we squish that down, so that each multidimensional array
7167 type gets only one array_type DIE in the Dwarf debugging info. The draft
7168 Dwarf specification say that we are allowed to do this kind of
7169 compression in C (because there is no difference between an array or
7170 arrays and a multidimensional array in C) but for other source languages
7171 (e.g. Ada) we probably shouldn't do this. */
71dfc51f 7172
a3f97cbb
JW
7173 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7174 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7175 We work around this by disabling this feature. See also
7176 gen_array_type_die. */
7177#ifndef MIPS_DEBUGGING_INFO
7178 for (dimension_number = 0;
7179 TREE_CODE (type) == ARRAY_TYPE;
7180 type = TREE_TYPE (type), dimension_number++)
7181 {
7182#endif
7183 register tree domain = TYPE_DOMAIN (type);
7184
7185 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7186 and (in GNU C only) variable bounds. Handle all three forms
7187 here. */
7188 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7189 if (domain)
7190 {
7191 /* We have an array type with specified bounds. */
7192 lower = TYPE_MIN_VALUE (domain);
7193 upper = TYPE_MAX_VALUE (domain);
7194
a9d38797
JM
7195 /* define the index type. */
7196 if (TREE_TYPE (domain))
ef76d03b
JW
7197 {
7198 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7199 TREE_TYPE field. We can't emit debug info for this
7200 because it is an unnamed integral type. */
7201 if (TREE_CODE (domain) == INTEGER_TYPE
7202 && TYPE_NAME (domain) == NULL_TREE
7203 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7204 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7205 ;
7206 else
7207 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7208 type_die);
7209 }
a9d38797 7210
e1ee5cdc
RH
7211 /* ??? If upper is NULL, the array has unspecified length,
7212 but it does have a lower bound. This happens with Fortran
7213 dimension arr(N:*)
7214 Since the debugger is definitely going to need to know N
7215 to produce useful results, go ahead and output the lower
7216 bound solo, and hope the debugger can cope. */
7217
141719a8 7218 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
e1ee5cdc
RH
7219 if (upper)
7220 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
a3f97cbb
JW
7221 }
7222 else
71dfc51f 7223 /* We have an array type with an unspecified length. The DWARF-2
a9d38797
JM
7224 spec does not say how to handle this; let's just leave out the
7225 bounds. */
71dfc51f
RK
7226 ;
7227
a3f97cbb
JW
7228#ifndef MIPS_DEBUGGING_INFO
7229 }
7230#endif
7231}
7232
7233static void
7234add_byte_size_attribute (die, tree_node)
7235 dw_die_ref die;
7236 register tree tree_node;
7237{
7238 register unsigned size;
7239
7240 switch (TREE_CODE (tree_node))
7241 {
7242 case ERROR_MARK:
7243 size = 0;
7244 break;
7245 case ENUMERAL_TYPE:
7246 case RECORD_TYPE:
7247 case UNION_TYPE:
7248 case QUAL_UNION_TYPE:
7249 size = int_size_in_bytes (tree_node);
7250 break;
7251 case FIELD_DECL:
7252 /* For a data member of a struct or union, the DW_AT_byte_size is
7253 generally given as the number of bytes normally allocated for an
7254 object of the *declared* type of the member itself. This is true
7255 even for bit-fields. */
7256 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7257 break;
7258 default:
7259 abort ();
7260 }
7261
7262 /* Note that `size' might be -1 when we get to this point. If it is, that
7263 indicates that the byte size of the entity in question is variable. We
7264 have no good way of expressing this fact in Dwarf at the present time,
7265 so just let the -1 pass on through. */
7266
7267 add_AT_unsigned (die, DW_AT_byte_size, size);
7268}
7269
7270/* For a FIELD_DECL node which represents a bit-field, output an attribute
7271 which specifies the distance in bits from the highest order bit of the
7272 "containing object" for the bit-field to the highest order bit of the
7273 bit-field itself.
7274
b2932ae5
JM
7275 For any given bit-field, the "containing object" is a hypothetical
7276 object (of some integral or enum type) within which the given bit-field
7277 lives. The type of this hypothetical "containing object" is always the
7278 same as the declared type of the individual bit-field itself. The
7279 determination of the exact location of the "containing object" for a
7280 bit-field is rather complicated. It's handled by the
7281 `field_byte_offset' function (above).
a3f97cbb
JW
7282
7283 Note that it is the size (in bytes) of the hypothetical "containing object"
7284 which will be given in the DW_AT_byte_size attribute for this bit-field.
7285 (See `byte_size_attribute' above). */
71dfc51f
RK
7286
7287static inline void
a3f97cbb
JW
7288add_bit_offset_attribute (die, decl)
7289 register dw_die_ref die;
7290 register tree decl;
7291{
7292 register unsigned object_offset_in_bytes = field_byte_offset (decl);
7293 register tree type = DECL_BIT_FIELD_TYPE (decl);
7294 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
7295 register unsigned bitpos_int;
7296 register unsigned highest_order_object_bit_offset;
7297 register unsigned highest_order_field_bit_offset;
7298 register unsigned bit_offset;
7299
3a88cbd1
JL
7300 /* Must be a field and a bit field. */
7301 if (!type
7302 || TREE_CODE (decl) != FIELD_DECL)
7303 abort ();
a3f97cbb
JW
7304
7305 /* We can't yet handle bit-fields whose offsets are variable, so if we
7306 encounter such things, just return without generating any attribute
7307 whatsoever. */
7308 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
71dfc51f
RK
7309 return;
7310
a3f97cbb
JW
7311 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
7312
7313 /* Note that the bit offset is always the distance (in bits) from the
7314 highest-order bit of the "containing object" to the highest-order bit of
7315 the bit-field itself. Since the "high-order end" of any object or field
7316 is different on big-endian and little-endian machines, the computation
7317 below must take account of these differences. */
7318 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7319 highest_order_field_bit_offset = bitpos_int;
7320
71dfc51f 7321 if (! BYTES_BIG_ENDIAN)
a3f97cbb
JW
7322 {
7323 highest_order_field_bit_offset
7324 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
7325
7326 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7327 }
71dfc51f
RK
7328
7329 bit_offset
7330 = (! BYTES_BIG_ENDIAN
7331 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7332 : highest_order_field_bit_offset - highest_order_object_bit_offset);
a3f97cbb
JW
7333
7334 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7335}
7336
7337/* For a FIELD_DECL node which represents a bit field, output an attribute
7338 which specifies the length in bits of the given field. */
71dfc51f
RK
7339
7340static inline void
a3f97cbb
JW
7341add_bit_size_attribute (die, decl)
7342 register dw_die_ref die;
7343 register tree decl;
7344{
3a88cbd1
JL
7345 /* Must be a field and a bit field. */
7346 if (TREE_CODE (decl) != FIELD_DECL
7347 || ! DECL_BIT_FIELD_TYPE (decl))
7348 abort ();
a3f97cbb
JW
7349 add_AT_unsigned (die, DW_AT_bit_size,
7350 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
7351}
7352
88dad228 7353/* If the compiled language is ANSI C, then add a 'prototyped'
a3f97cbb 7354 attribute, if arg types are given for the parameters of a function. */
71dfc51f
RK
7355
7356static inline void
a3f97cbb
JW
7357add_prototyped_attribute (die, func_type)
7358 register dw_die_ref die;
7359 register tree func_type;
7360{
88dad228
JM
7361 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7362 && TYPE_ARG_TYPES (func_type) != NULL)
7363 add_AT_flag (die, DW_AT_prototyped, 1);
a3f97cbb
JW
7364}
7365
7366
7367/* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7368 by looking in either the type declaration or object declaration
7369 equate table. */
71dfc51f
RK
7370
7371static inline void
a3f97cbb
JW
7372add_abstract_origin_attribute (die, origin)
7373 register dw_die_ref die;
7374 register tree origin;
7375{
7376 dw_die_ref origin_die = NULL;
7377 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
71dfc51f 7378 origin_die = lookup_decl_die (origin);
a3f97cbb 7379 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
71dfc51f
RK
7380 origin_die = lookup_type_die (origin);
7381
a3f97cbb
JW
7382 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7383}
7384
bdb669cb
JM
7385/* We do not currently support the pure_virtual attribute. */
7386
71dfc51f 7387static inline void
a3f97cbb
JW
7388add_pure_or_virtual_attribute (die, func_decl)
7389 register dw_die_ref die;
7390 register tree func_decl;
7391{
a94dbf2c 7392 if (DECL_VINDEX (func_decl))
a3f97cbb 7393 {
bdb669cb 7394 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
71dfc51f
RK
7395 add_AT_loc (die, DW_AT_vtable_elem_location,
7396 new_loc_descr (DW_OP_constu,
7397 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
7398 0));
7399
a94dbf2c
JM
7400 /* GNU extension: Record what type this method came from originally. */
7401 if (debug_info_level > DINFO_LEVEL_TERSE)
7402 add_AT_die_ref (die, DW_AT_containing_type,
7403 lookup_type_die (DECL_CONTEXT (func_decl)));
a3f97cbb
JW
7404 }
7405}
7406\f
b2932ae5 7407/* Add source coordinate attributes for the given decl. */
71dfc51f 7408
b2932ae5
JM
7409static void
7410add_src_coords_attributes (die, decl)
7411 register dw_die_ref die;
7412 register tree decl;
7413{
7414 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
71dfc51f 7415
b2932ae5
JM
7416 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7417 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7418}
7419
a3f97cbb
JW
7420/* Add an DW_AT_name attribute and source coordinate attribute for the
7421 given decl, but only if it actually has a name. */
71dfc51f 7422
a3f97cbb
JW
7423static void
7424add_name_and_src_coords_attributes (die, decl)
7425 register dw_die_ref die;
7426 register tree decl;
7427{
61b32c02 7428 register tree decl_name;
71dfc51f 7429
a1d7ffe3 7430 decl_name = DECL_NAME (decl);
71dfc51f 7431 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
a3f97cbb 7432 {
a1d7ffe3 7433 add_name_attribute (die, dwarf2_name (decl, 0));
b2932ae5 7434 add_src_coords_attributes (die, decl);
a1d7ffe3
JM
7435 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7436 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7437 add_AT_string (die, DW_AT_MIPS_linkage_name,
7438 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
a3f97cbb
JW
7439 }
7440}
7441
7442/* Push a new declaration scope. */
71dfc51f 7443
a3f97cbb
JW
7444static void
7445push_decl_scope (scope)
7446 tree scope;
7447{
7448 /* Make room in the decl_scope_table, if necessary. */
7449 if (decl_scope_table_allocated == decl_scope_depth)
7450 {
7451 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
71dfc51f
RK
7452 decl_scope_table
7453 = (tree *) xrealloc (decl_scope_table,
7454 decl_scope_table_allocated * sizeof (tree));
a3f97cbb 7455 }
71dfc51f 7456
a3f97cbb
JW
7457 decl_scope_table[decl_scope_depth++] = scope;
7458}
7459
7460/* Return the DIE for the scope the immediately contains this declaration. */
71dfc51f 7461
a3f97cbb 7462static dw_die_ref
ab72d377
JM
7463scope_die_for (t, context_die)
7464 register tree t;
a3f97cbb
JW
7465 register dw_die_ref context_die;
7466{
7467 register dw_die_ref scope_die = NULL;
7468 register tree containing_scope;
7469 register unsigned long i;
7470
7471 /* Walk back up the declaration tree looking for a place to define
7472 this type. */
ab72d377
JM
7473 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
7474 containing_scope = TYPE_CONTEXT (t);
a94dbf2c 7475 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
ab72d377
JM
7476 containing_scope = decl_class_context (t);
7477 else
7478 containing_scope = DECL_CONTEXT (t);
7479
ef76d03b
JW
7480 /* Function-local tags and functions get stuck in limbo until they are
7481 fixed up by decls_for_scope. */
7482 if (context_die == NULL && containing_scope != NULL_TREE
7483 && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
7484 return NULL;
7485
71dfc51f
RK
7486 if (containing_scope == NULL_TREE)
7487 scope_die = comp_unit_die;
a3f97cbb
JW
7488 else
7489 {
ab72d377
JM
7490 for (i = decl_scope_depth, scope_die = context_die;
7491 i > 0 && decl_scope_table[i - 1] != containing_scope;
7d4440be 7492 scope_die = scope_die->die_parent, --i)
71dfc51f
RK
7493 ;
7494
ab72d377 7495 if (i == 0)
a3f97cbb 7496 {
3a88cbd1
JL
7497 if (scope_die != comp_unit_die
7498 || TREE_CODE_CLASS (TREE_CODE (containing_scope)) != 't')
7499 abort ();
7500 if (debug_info_level > DINFO_LEVEL_TERSE
7501 && !TREE_ASM_WRITTEN (containing_scope))
7502 abort ();
a3f97cbb
JW
7503 }
7504 }
71dfc51f 7505
a3f97cbb
JW
7506 return scope_die;
7507}
7508
7509/* Pop a declaration scope. */
71dfc51f 7510static inline void
a3f97cbb
JW
7511pop_decl_scope ()
7512{
3a88cbd1
JL
7513 if (decl_scope_depth <= 0)
7514 abort ();
a3f97cbb
JW
7515 --decl_scope_depth;
7516}
7517
7518/* Many forms of DIEs require a "type description" attribute. This
7519 routine locates the proper "type descriptor" die for the type given
7520 by 'type', and adds an DW_AT_type attribute below the given die. */
71dfc51f 7521
a3f97cbb
JW
7522static void
7523add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7524 register dw_die_ref object_die;
7525 register tree type;
7526 register int decl_const;
7527 register int decl_volatile;
7528 register dw_die_ref context_die;
7529{
7530 register enum tree_code code = TREE_CODE (type);
a3f97cbb
JW
7531 register dw_die_ref type_die = NULL;
7532
ef76d03b
JW
7533 /* ??? If this type is an unnamed subrange type of an integral or
7534 floating-point type, use the inner type. This is because we have no
7535 support for unnamed types in base_type_die. This can happen if this is
7536 an Ada subrange type. Correct solution is emit a subrange type die. */
b1ccbc24
RK
7537 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7538 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7539 type = TREE_TYPE (type), code = TREE_CODE (type);
7540
a3f97cbb 7541 if (code == ERROR_MARK)
b1ccbc24 7542 return;
a3f97cbb
JW
7543
7544 /* Handle a special case. For functions whose return type is void, we
7545 generate *no* type attribute. (Note that no object may have type
7546 `void', so this only applies to function return types). */
7547 if (code == VOID_TYPE)
b1ccbc24 7548 return;
a3f97cbb 7549
a3f97cbb
JW
7550 type_die = modified_type_die (type,
7551 decl_const || TYPE_READONLY (type),
7552 decl_volatile || TYPE_VOLATILE (type),
ab72d377 7553 context_die);
a3f97cbb 7554 if (type_die != NULL)
71dfc51f 7555 add_AT_die_ref (object_die, DW_AT_type, type_die);
a3f97cbb
JW
7556}
7557
7558/* Given a tree pointer to a struct, class, union, or enum type node, return
7559 a pointer to the (string) tag name for the given type, or zero if the type
7560 was declared without a tag. */
71dfc51f 7561
a3f97cbb
JW
7562static char *
7563type_tag (type)
7564 register tree type;
7565{
7566 register char *name = 0;
7567
7568 if (TYPE_NAME (type) != 0)
7569 {
7570 register tree t = 0;
7571
7572 /* Find the IDENTIFIER_NODE for the type name. */
7573 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7574 t = TYPE_NAME (type);
bdb669cb 7575
a3f97cbb
JW
7576 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7577 a TYPE_DECL node, regardless of whether or not a `typedef' was
bdb669cb 7578 involved. */
a94dbf2c
JM
7579 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7580 && ! DECL_IGNORED_P (TYPE_NAME (type)))
a3f97cbb 7581 t = DECL_NAME (TYPE_NAME (type));
bdb669cb 7582
a3f97cbb
JW
7583 /* Now get the name as a string, or invent one. */
7584 if (t != 0)
a94dbf2c 7585 name = IDENTIFIER_POINTER (t);
a3f97cbb 7586 }
71dfc51f 7587
a3f97cbb
JW
7588 return (name == 0 || *name == '\0') ? 0 : name;
7589}
7590
7591/* Return the type associated with a data member, make a special check
7592 for bit field types. */
71dfc51f
RK
7593
7594static inline tree
a3f97cbb
JW
7595member_declared_type (member)
7596 register tree member;
7597{
71dfc51f
RK
7598 return (DECL_BIT_FIELD_TYPE (member)
7599 ? DECL_BIT_FIELD_TYPE (member)
7600 : TREE_TYPE (member));
a3f97cbb
JW
7601}
7602
d291dd49 7603/* Get the decl's label, as described by its RTL. This may be different
a3f97cbb 7604 from the DECL_NAME name used in the source file. */
71dfc51f 7605
a3f97cbb 7606static char *
d291dd49 7607decl_start_label (decl)
a3f97cbb
JW
7608 register tree decl;
7609{
7610 rtx x;
7611 char *fnname;
7612 x = DECL_RTL (decl);
7613 if (GET_CODE (x) != MEM)
71dfc51f
RK
7614 abort ();
7615
a3f97cbb
JW
7616 x = XEXP (x, 0);
7617 if (GET_CODE (x) != SYMBOL_REF)
71dfc51f
RK
7618 abort ();
7619
a3f97cbb
JW
7620 fnname = XSTR (x, 0);
7621 return fnname;
7622}
7623\f
956d6950 7624/* These routines generate the internal representation of the DIE's for
a3f97cbb 7625 the compilation unit. Debugging information is collected by walking
88dad228 7626 the declaration trees passed in from dwarf2out_decl(). */
a3f97cbb
JW
7627
7628static void
7629gen_array_type_die (type, context_die)
7630 register tree type;
7631 register dw_die_ref context_die;
7632{
ab72d377 7633 register dw_die_ref scope_die = scope_die_for (type, context_die);
a9d38797 7634 register dw_die_ref array_die;
a3f97cbb 7635 register tree element_type;
bdb669cb 7636
a9d38797
JM
7637 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7638 the inner array type comes before the outer array type. Thus we must
7639 call gen_type_die before we call new_die. See below also. */
7640#ifdef MIPS_DEBUGGING_INFO
7641 gen_type_die (TREE_TYPE (type), context_die);
7642#endif
7643
7644 array_die = new_die (DW_TAG_array_type, scope_die);
7645
a3f97cbb
JW
7646#if 0
7647 /* We default the array ordering. SDB will probably do
7648 the right things even if DW_AT_ordering is not present. It's not even
7649 an issue until we start to get into multidimensional arrays anyway. If
7650 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7651 then we'll have to put the DW_AT_ordering attribute back in. (But if
7652 and when we find out that we need to put these in, we will only do so
7653 for multidimensional arrays. */
7654 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7655#endif
7656
a9d38797 7657#ifdef MIPS_DEBUGGING_INFO
4edb7b60
JM
7658 /* The SGI compilers handle arrays of unknown bound by setting
7659 AT_declaration and not emitting any subrange DIEs. */
a9d38797
JM
7660 if (! TYPE_DOMAIN (type))
7661 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7662 else
7663#endif
7664 add_subscript_info (array_die, type);
a3f97cbb
JW
7665
7666 equate_type_number_to_die (type, array_die);
7667
7668 /* Add representation of the type of the elements of this array type. */
7669 element_type = TREE_TYPE (type);
71dfc51f 7670
a3f97cbb
JW
7671 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7672 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7673 We work around this by disabling this feature. See also
7674 add_subscript_info. */
7675#ifndef MIPS_DEBUGGING_INFO
71dfc51f
RK
7676 while (TREE_CODE (element_type) == ARRAY_TYPE)
7677 element_type = TREE_TYPE (element_type);
7678
a3f97cbb 7679 gen_type_die (element_type, context_die);
a9d38797 7680#endif
a3f97cbb
JW
7681
7682 add_type_attribute (array_die, element_type, 0, 0, context_die);
7683}
7684
7685static void
7686gen_set_type_die (type, context_die)
7687 register tree type;
7688 register dw_die_ref context_die;
7689{
71dfc51f
RK
7690 register dw_die_ref type_die
7691 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7692
a3f97cbb 7693 equate_type_number_to_die (type, type_die);
a3f97cbb
JW
7694 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7695}
7696
7697static void
7698gen_entry_point_die (decl, context_die)
7699 register tree decl;
7700 register dw_die_ref context_die;
7701{
7702 register tree origin = decl_ultimate_origin (decl);
7703 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7704 if (origin != NULL)
71dfc51f 7705 add_abstract_origin_attribute (decl_die, origin);
a3f97cbb
JW
7706 else
7707 {
7708 add_name_and_src_coords_attributes (decl_die, decl);
a3f97cbb
JW
7709 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7710 0, 0, context_die);
7711 }
71dfc51f 7712
a3f97cbb 7713 if (DECL_ABSTRACT (decl))
71dfc51f 7714 equate_decl_number_to_die (decl, decl_die);
a3f97cbb 7715 else
71dfc51f 7716 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
a3f97cbb
JW
7717}
7718
a94dbf2c
JM
7719/* Remember a type in the pending_types_list. */
7720
7721static void
7722pend_type (type)
7723 register tree type;
7724{
7725 if (pending_types == pending_types_allocated)
7726 {
7727 pending_types_allocated += PENDING_TYPES_INCREMENT;
7728 pending_types_list
7729 = (tree *) xrealloc (pending_types_list,
7730 sizeof (tree) * pending_types_allocated);
7731 }
71dfc51f 7732
a94dbf2c
JM
7733 pending_types_list[pending_types++] = type;
7734}
7735
7736/* Output any pending types (from the pending_types list) which we can output
7737 now (taking into account the scope that we are working on now).
7738
7739 For each type output, remove the given type from the pending_types_list
7740 *before* we try to output it. */
7741
7742static void
7743output_pending_types_for_scope (context_die)
7744 register dw_die_ref context_die;
7745{
7746 register tree type;
7747
7748 while (pending_types)
7749 {
7750 --pending_types;
7751 type = pending_types_list[pending_types];
7752 gen_type_die (type, context_die);
3a88cbd1
JL
7753 if (!TREE_ASM_WRITTEN (type))
7754 abort ();
a94dbf2c
JM
7755 }
7756}
7757
a3f97cbb 7758/* Generate a DIE to represent an inlined instance of an enumeration type. */
71dfc51f 7759
a3f97cbb
JW
7760static void
7761gen_inlined_enumeration_type_die (type, context_die)
7762 register tree type;
7763 register dw_die_ref context_die;
7764{
71dfc51f
RK
7765 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7766 scope_die_for (type, context_die));
7767
3a88cbd1
JL
7768 if (!TREE_ASM_WRITTEN (type))
7769 abort ();
a3f97cbb
JW
7770 add_abstract_origin_attribute (type_die, type);
7771}
7772
7773/* Generate a DIE to represent an inlined instance of a structure type. */
71dfc51f 7774
a3f97cbb
JW
7775static void
7776gen_inlined_structure_type_die (type, context_die)
7777 register tree type;
7778 register dw_die_ref context_die;
7779{
71dfc51f
RK
7780 register dw_die_ref type_die = new_die (DW_TAG_structure_type,
7781 scope_die_for (type, context_die));
7782
3a88cbd1
JL
7783 if (!TREE_ASM_WRITTEN (type))
7784 abort ();
a3f97cbb
JW
7785 add_abstract_origin_attribute (type_die, type);
7786}
7787
7788/* Generate a DIE to represent an inlined instance of a union type. */
71dfc51f 7789
a3f97cbb
JW
7790static void
7791gen_inlined_union_type_die (type, context_die)
7792 register tree type;
7793 register dw_die_ref context_die;
7794{
71dfc51f
RK
7795 register dw_die_ref type_die = new_die (DW_TAG_union_type,
7796 scope_die_for (type, context_die));
7797
3a88cbd1
JL
7798 if (!TREE_ASM_WRITTEN (type))
7799 abort ();
a3f97cbb
JW
7800 add_abstract_origin_attribute (type_die, type);
7801}
7802
7803/* Generate a DIE to represent an enumeration type. Note that these DIEs
7804 include all of the information about the enumeration values also. Each
273dbe67
JM
7805 enumerated type name/value is listed as a child of the enumerated type
7806 DIE. */
71dfc51f 7807
a3f97cbb 7808static void
273dbe67 7809gen_enumeration_type_die (type, context_die)
a3f97cbb 7810 register tree type;
a3f97cbb
JW
7811 register dw_die_ref context_die;
7812{
273dbe67
JM
7813 register dw_die_ref type_die = lookup_type_die (type);
7814
a3f97cbb
JW
7815 if (type_die == NULL)
7816 {
7817 type_die = new_die (DW_TAG_enumeration_type,
ab72d377 7818 scope_die_for (type, context_die));
a3f97cbb
JW
7819 equate_type_number_to_die (type, type_die);
7820 add_name_attribute (type_die, type_tag (type));
a3f97cbb 7821 }
273dbe67
JM
7822 else if (! TYPE_SIZE (type))
7823 return;
7824 else
7825 remove_AT (type_die, DW_AT_declaration);
7826
7827 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7828 given enum type is incomplete, do not generate the DW_AT_byte_size
7829 attribute or the DW_AT_element_list attribute. */
7830 if (TYPE_SIZE (type))
a3f97cbb 7831 {
273dbe67 7832 register tree link;
71dfc51f 7833
a082c85a 7834 TREE_ASM_WRITTEN (type) = 1;
273dbe67 7835 add_byte_size_attribute (type_die, type);
e9a25f70 7836 if (TYPE_STUB_DECL (type) != NULL_TREE)
b2932ae5 7837 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
71dfc51f 7838
ef76d03b
JW
7839 /* If the first reference to this type was as the return type of an
7840 inline function, then it may not have a parent. Fix this now. */
7841 if (type_die->die_parent == NULL)
7842 add_child_die (scope_die_for (type, context_die), type_die);
7843
273dbe67
JM
7844 for (link = TYPE_FIELDS (type);
7845 link != NULL; link = TREE_CHAIN (link))
a3f97cbb 7846 {
273dbe67 7847 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
71dfc51f 7848
273dbe67
JM
7849 add_name_attribute (enum_die,
7850 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7851 add_AT_unsigned (enum_die, DW_AT_const_value,
a3f97cbb 7852 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
a3f97cbb
JW
7853 }
7854 }
273dbe67
JM
7855 else
7856 add_AT_flag (type_die, DW_AT_declaration, 1);
a3f97cbb
JW
7857}
7858
7859
7860/* Generate a DIE to represent either a real live formal parameter decl or to
7861 represent just the type of some formal parameter position in some function
7862 type.
71dfc51f 7863
a3f97cbb
JW
7864 Note that this routine is a bit unusual because its argument may be a
7865 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7866 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7867 node. If it's the former then this function is being called to output a
7868 DIE to represent a formal parameter object (or some inlining thereof). If
7869 it's the latter, then this function is only being called to output a
7870 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7871 argument type of some subprogram type. */
71dfc51f 7872
a94dbf2c 7873static dw_die_ref
a3f97cbb
JW
7874gen_formal_parameter_die (node, context_die)
7875 register tree node;
7876 register dw_die_ref context_die;
7877{
71dfc51f
RK
7878 register dw_die_ref parm_die
7879 = new_die (DW_TAG_formal_parameter, context_die);
a3f97cbb 7880 register tree origin;
71dfc51f 7881
a3f97cbb
JW
7882 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7883 {
a3f97cbb
JW
7884 case 'd':
7885 origin = decl_ultimate_origin (node);
7886 if (origin != NULL)
a94dbf2c 7887 add_abstract_origin_attribute (parm_die, origin);
a3f97cbb
JW
7888 else
7889 {
7890 add_name_and_src_coords_attributes (parm_die, node);
7891 add_type_attribute (parm_die, TREE_TYPE (node),
7892 TREE_READONLY (node),
7893 TREE_THIS_VOLATILE (node),
7894 context_die);
bdb669cb
JM
7895 if (DECL_ARTIFICIAL (node))
7896 add_AT_flag (parm_die, DW_AT_artificial, 1);
a3f97cbb 7897 }
71dfc51f 7898
141719a8
JM
7899 equate_decl_number_to_die (node, parm_die);
7900 if (! DECL_ABSTRACT (node))
a94dbf2c 7901 add_location_or_const_value_attribute (parm_die, node);
71dfc51f 7902
a3f97cbb
JW
7903 break;
7904
a3f97cbb 7905 case 't':
71dfc51f 7906 /* We were called with some kind of a ..._TYPE node. */
a3f97cbb
JW
7907 add_type_attribute (parm_die, node, 0, 0, context_die);
7908 break;
7909
a3f97cbb
JW
7910 default:
7911 abort ();
7912 }
71dfc51f 7913
a94dbf2c 7914 return parm_die;
a3f97cbb
JW
7915}
7916
7917/* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7918 at the end of an (ANSI prototyped) formal parameters list. */
71dfc51f 7919
a3f97cbb
JW
7920static void
7921gen_unspecified_parameters_die (decl_or_type, context_die)
7922 register tree decl_or_type;
7923 register dw_die_ref context_die;
7924{
7925 register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
7926 context_die);
a3f97cbb
JW
7927}
7928
7929/* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7930 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7931 parameters as specified in some function type specification (except for
7932 those which appear as part of a function *definition*).
71dfc51f
RK
7933
7934 Note we must be careful here to output all of the parameter DIEs before*
a3f97cbb
JW
7935 we output any DIEs needed to represent the types of the formal parameters.
7936 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7937 non-parameter DIE it sees ends the formal parameter list. */
71dfc51f 7938
a3f97cbb
JW
7939static void
7940gen_formal_types_die (function_or_method_type, context_die)
7941 register tree function_or_method_type;
7942 register dw_die_ref context_die;
7943{
7944 register tree link;
7945 register tree formal_type = NULL;
7946 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
7947
bdb669cb 7948#if 0
a3f97cbb
JW
7949 /* In the case where we are generating a formal types list for a C++
7950 non-static member function type, skip over the first thing on the
7951 TYPE_ARG_TYPES list because it only represents the type of the hidden
7952 `this pointer'. The debugger should be able to figure out (without
7953 being explicitly told) that this non-static member function type takes a
7954 `this pointer' and should be able to figure what the type of that hidden
7955 parameter is from the DW_AT_member attribute of the parent
7956 DW_TAG_subroutine_type DIE. */
7957 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
7958 first_parm_type = TREE_CHAIN (first_parm_type);
bdb669cb 7959#endif
a3f97cbb
JW
7960
7961 /* Make our first pass over the list of formal parameter types and output a
7962 DW_TAG_formal_parameter DIE for each one. */
7963 for (link = first_parm_type; link; link = TREE_CHAIN (link))
7964 {
a94dbf2c
JM
7965 register dw_die_ref parm_die;
7966
a3f97cbb
JW
7967 formal_type = TREE_VALUE (link);
7968 if (formal_type == void_type_node)
7969 break;
7970
7971 /* Output a (nameless) DIE to represent the formal parameter itself. */
a94dbf2c
JM
7972 parm_die = gen_formal_parameter_die (formal_type, context_die);
7973 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
7974 && link == first_parm_type)
7975 add_AT_flag (parm_die, DW_AT_artificial, 1);
a3f97cbb
JW
7976 }
7977
7978 /* If this function type has an ellipsis, add a
7979 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
7980 if (formal_type != void_type_node)
7981 gen_unspecified_parameters_die (function_or_method_type, context_die);
7982
7983 /* Make our second (and final) pass over the list of formal parameter types
7984 and output DIEs to represent those types (as necessary). */
7985 for (link = TYPE_ARG_TYPES (function_or_method_type);
7986 link;
7987 link = TREE_CHAIN (link))
7988 {
7989 formal_type = TREE_VALUE (link);
7990 if (formal_type == void_type_node)
7991 break;
7992
b50c02f9 7993 gen_type_die (formal_type, context_die);
a3f97cbb
JW
7994 }
7995}
7996
7997/* Generate a DIE to represent a declared function (either file-scope or
7998 block-local). */
71dfc51f 7999
a3f97cbb
JW
8000static void
8001gen_subprogram_die (decl, context_die)
8002 register tree decl;
8003 register dw_die_ref context_die;
8004{
8005 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8006 register tree origin = decl_ultimate_origin (decl);
4b674448 8007 register dw_die_ref subr_die;
a3f97cbb 8008 register dw_loc_descr_ref fp_loc = NULL;
b1ccbc24 8009 register rtx fp_reg;
a3f97cbb
JW
8010 register tree fn_arg_types;
8011 register tree outer_scope;
a94dbf2c 8012 register dw_die_ref old_die = lookup_decl_die (decl);
9c6cd30e
JM
8013 register int declaration
8014 = (current_function_decl != decl
8015 || (context_die
8016 && (context_die->die_tag == DW_TAG_structure_type
8017 || context_die->die_tag == DW_TAG_union_type)));
a3f97cbb 8018
a3f97cbb
JW
8019 if (origin != NULL)
8020 {
4b674448 8021 subr_die = new_die (DW_TAG_subprogram, context_die);
a3f97cbb
JW
8022 add_abstract_origin_attribute (subr_die, origin);
8023 }
4401bf24
JL
8024 else if (old_die && DECL_ABSTRACT (decl)
8025 && get_AT_unsigned (old_die, DW_AT_inline))
8026 {
8027 /* This must be a redefinition of an extern inline function.
8028 We can just reuse the old die here. */
8029 subr_die = old_die;
8030
8031 /* Clear out the inlined attribute and parm types. */
8032 remove_AT (subr_die, DW_AT_inline);
8033 remove_children (subr_die);
8034 }
bdb669cb
JM
8035 else if (old_die)
8036 {
4b674448
JM
8037 register unsigned file_index
8038 = lookup_filename (DECL_SOURCE_FILE (decl));
a94dbf2c 8039
3a88cbd1
JL
8040 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8041 abort ();
4b674448
JM
8042
8043 /* If the definition comes from the same place as the declaration,
a94dbf2c
JM
8044 maybe use the old DIE. We always want the DIE for this function
8045 that has the *_pc attributes to be under comp_unit_die so the
8046 debugger can find it. For inlines, that is the concrete instance,
8047 so we can use the old DIE here. For non-inline methods, we want a
8048 specification DIE at toplevel, so we need a new DIE. For local
8049 class methods, this does not apply. */
8050 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8051 || context_die == NULL)
8052 && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
4b674448
JM
8053 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8054 == DECL_SOURCE_LINE (decl)))
bdb669cb 8055 {
4b674448
JM
8056 subr_die = old_die;
8057
8058 /* Clear out the declaration attribute and the parm types. */
8059 remove_AT (subr_die, DW_AT_declaration);
8060 remove_children (subr_die);
8061 }
8062 else
8063 {
8064 subr_die = new_die (DW_TAG_subprogram, context_die);
8065 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
bdb669cb
JM
8066 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8067 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8068 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8069 != DECL_SOURCE_LINE (decl))
8070 add_AT_unsigned
8071 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8072 }
8073 }
a3f97cbb
JW
8074 else
8075 {
4edb7b60
JM
8076 register dw_die_ref scope_die;
8077
8078 if (DECL_CONTEXT (decl))
8079 scope_die = scope_die_for (decl, context_die);
8080 else
8081 /* Don't put block extern declarations under comp_unit_die. */
8082 scope_die = context_die;
8083
8084 subr_die = new_die (DW_TAG_subprogram, scope_die);
8085
273dbe67
JM
8086 if (TREE_PUBLIC (decl))
8087 add_AT_flag (subr_die, DW_AT_external, 1);
71dfc51f 8088
a3f97cbb 8089 add_name_and_src_coords_attributes (subr_die, decl);
4927276d
JM
8090 if (debug_info_level > DINFO_LEVEL_TERSE)
8091 {
8092 register tree type = TREE_TYPE (decl);
71dfc51f 8093
4927276d
JM
8094 add_prototyped_attribute (subr_die, type);
8095 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8096 }
71dfc51f 8097
a3f97cbb 8098 add_pure_or_virtual_attribute (subr_die, decl);
273dbe67
JM
8099 if (DECL_ARTIFICIAL (decl))
8100 add_AT_flag (subr_die, DW_AT_artificial, 1);
a94dbf2c
JM
8101 if (TREE_PROTECTED (decl))
8102 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8103 else if (TREE_PRIVATE (decl))
8104 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
a3f97cbb 8105 }
4edb7b60 8106
a94dbf2c
JM
8107 if (declaration)
8108 {
8109 add_AT_flag (subr_die, DW_AT_declaration, 1);
8110
8111 /* The first time we see a member function, it is in the context of
8112 the class to which it belongs. We make sure of this by emitting
8113 the class first. The next time is the definition, which is
8114 handled above. The two may come from the same source text. */
f6c74b02 8115 if (DECL_CONTEXT (decl))
a94dbf2c
JM
8116 equate_decl_number_to_die (decl, subr_die);
8117 }
8118 else if (DECL_ABSTRACT (decl))
a3f97cbb 8119 {
4401bf24
JL
8120 /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions,
8121 but not for extern inline functions. We can't get this completely
8122 correct because information about whether the function was declared
8123 inline is not saved anywhere. */
61b32c02
JM
8124 if (DECL_DEFER_OUTPUT (decl))
8125 {
8126 if (DECL_INLINE (decl))
8127 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8128 else
8129 add_AT_unsigned (subr_die, DW_AT_inline,
8130 DW_INL_declared_not_inlined);
8131 }
8132 else if (DECL_INLINE (decl))
8133 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8134 else
8135 abort ();
8136
a3f97cbb
JW
8137 equate_decl_number_to_die (decl, subr_die);
8138 }
8139 else if (!DECL_EXTERNAL (decl))
8140 {
71dfc51f 8141 if (origin == NULL_TREE)
ba7b35df 8142 equate_decl_number_to_die (decl, subr_die);
71dfc51f 8143
5c90448c
JM
8144 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8145 current_funcdef_number);
7d4440be 8146 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
5c90448c
JM
8147 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8148 current_funcdef_number);
a3f97cbb
JW
8149 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8150
d291dd49
JM
8151 add_pubname (decl, subr_die);
8152 add_arange (decl, subr_die);
8153
a3f97cbb 8154#ifdef MIPS_DEBUGGING_INFO
a3f97cbb
JW
8155 /* Add a reference to the FDE for this routine. */
8156 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8157#endif
8158
810429b7
JM
8159 /* Define the "frame base" location for this routine. We use the
8160 frame pointer or stack pointer registers, since the RTL for local
8161 variables is relative to one of them. */
b1ccbc24
RK
8162 fp_reg
8163 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8164 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
a3f97cbb 8165
ef76d03b
JW
8166#if 0
8167 /* ??? This fails for nested inline functions, because context_display
8168 is not part of the state saved/restored for inline functions. */
88dad228 8169 if (current_function_needs_context)
ef76d03b
JW
8170 add_AT_location_description (subr_die, DW_AT_static_link,
8171 lookup_static_chain (decl));
8172#endif
a3f97cbb
JW
8173 }
8174
8175 /* Now output descriptions of the arguments for this function. This gets
8176 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8177 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8178 `...' at the end of the formal parameter list. In order to find out if
8179 there was a trailing ellipsis or not, we must instead look at the type
8180 associated with the FUNCTION_DECL. This will be a node of type
8181 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8182 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8183 an ellipsis at the end. */
ab72d377 8184 push_decl_scope (decl);
71dfc51f 8185
a3f97cbb
JW
8186 /* In the case where we are describing a mere function declaration, all we
8187 need to do here (and all we *can* do here) is to describe the *types* of
8188 its formal parameters. */
4927276d 8189 if (debug_info_level <= DINFO_LEVEL_TERSE)
71dfc51f 8190 ;
4edb7b60
JM
8191 else if (declaration)
8192 gen_formal_types_die (TREE_TYPE (decl), subr_die);
a3f97cbb
JW
8193 else
8194 {
8195 /* Generate DIEs to represent all known formal parameters */
8196 register tree arg_decls = DECL_ARGUMENTS (decl);
8197 register tree parm;
8198
8199 /* When generating DIEs, generate the unspecified_parameters DIE
8200 instead if we come across the arg "__builtin_va_alist" */
8201 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
71dfc51f
RK
8202 if (TREE_CODE (parm) == PARM_DECL)
8203 {
db3cf6fb
MS
8204 if (DECL_NAME (parm)
8205 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8206 "__builtin_va_alist"))
71dfc51f
RK
8207 gen_unspecified_parameters_die (parm, subr_die);
8208 else
8209 gen_decl_die (parm, subr_die);
8210 }
a3f97cbb
JW
8211
8212 /* Decide whether we need a unspecified_parameters DIE at the end.
8213 There are 2 more cases to do this for: 1) the ansi ... declaration -
8214 this is detectable when the end of the arg list is not a
8215 void_type_node 2) an unprototyped function declaration (not a
8216 definition). This just means that we have no info about the
8217 parameters at all. */
8218 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
71dfc51f 8219 if (fn_arg_types != NULL)
a3f97cbb
JW
8220 {
8221 /* this is the prototyped case, check for ... */
8222 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
71dfc51f 8223 gen_unspecified_parameters_die (decl, subr_die);
a3f97cbb 8224 }
71dfc51f
RK
8225 else if (DECL_INITIAL (decl) == NULL_TREE)
8226 gen_unspecified_parameters_die (decl, subr_die);
a3f97cbb
JW
8227 }
8228
8229 /* Output Dwarf info for all of the stuff within the body of the function
8230 (if it has one - it may be just a declaration). */
8231 outer_scope = DECL_INITIAL (decl);
8232
d7248bff
JM
8233 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8234 node created to represent a function. This outermost BLOCK actually
8235 represents the outermost binding contour for the function, i.e. the
8236 contour in which the function's formal parameters and labels get
8237 declared. Curiously, it appears that the front end doesn't actually
8238 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8239 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8240 list for the function instead.) The BLOCK_VARS list for the
8241 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8242 the function however, and we output DWARF info for those in
8243 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8244 node representing the function's outermost pair of curly braces, and
8245 any blocks used for the base and member initializers of a C++
8246 constructor function. */
4edb7b60 8247 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
7e23cb16
JM
8248 {
8249 current_function_has_inlines = 0;
8250 decls_for_scope (outer_scope, subr_die, 0);
71dfc51f 8251
ce61cc73 8252#if 0 && defined (MIPS_DEBUGGING_INFO)
7e23cb16
JM
8253 if (current_function_has_inlines)
8254 {
8255 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8256 if (! comp_unit_has_inlines)
8257 {
8258 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8259 comp_unit_has_inlines = 1;
8260 }
8261 }
8262#endif
8263 }
71dfc51f 8264
ab72d377 8265 pop_decl_scope ();
a3f97cbb
JW
8266}
8267
8268/* Generate a DIE to represent a declared data object. */
71dfc51f 8269
a3f97cbb
JW
8270static void
8271gen_variable_die (decl, context_die)
8272 register tree decl;
8273 register dw_die_ref context_die;
8274{
8275 register tree origin = decl_ultimate_origin (decl);
8276 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
71dfc51f 8277
bdb669cb 8278 dw_die_ref old_die = lookup_decl_die (decl);
4edb7b60
JM
8279 int declaration
8280 = (DECL_EXTERNAL (decl)
a94dbf2c
JM
8281 || current_function_decl != decl_function_context (decl)
8282 || context_die->die_tag == DW_TAG_structure_type
8283 || context_die->die_tag == DW_TAG_union_type);
4edb7b60 8284
a3f97cbb 8285 if (origin != NULL)
71dfc51f 8286 add_abstract_origin_attribute (var_die, origin);
f76b8156
JW
8287 /* Loop unrolling can create multiple blocks that refer to the same
8288 static variable, so we must test for the DW_AT_declaration flag. */
8289 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8290 copy decls and set the DECL_ABSTRACT flag on them instead of
8291 sharing them. */
8292 else if (old_die && TREE_STATIC (decl)
8293 && get_AT_flag (old_die, DW_AT_declaration) == 1)
bdb669cb 8294 {
f76b8156 8295 /* ??? This is an instantiation of a C++ class level static. */
bdb669cb
JM
8296 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8297 if (DECL_NAME (decl))
8298 {
8299 register unsigned file_index
8300 = lookup_filename (DECL_SOURCE_FILE (decl));
71dfc51f 8301
bdb669cb
JM
8302 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8303 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
71dfc51f 8304
bdb669cb
JM
8305 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8306 != DECL_SOURCE_LINE (decl))
71dfc51f
RK
8307
8308 add_AT_unsigned (var_die, DW_AT_decl_line,
8309 DECL_SOURCE_LINE (decl));
bdb669cb
JM
8310 }
8311 }
a3f97cbb
JW
8312 else
8313 {
8314 add_name_and_src_coords_attributes (var_die, decl);
a3f97cbb
JW
8315 add_type_attribute (var_die, TREE_TYPE (decl),
8316 TREE_READONLY (decl),
8317 TREE_THIS_VOLATILE (decl), context_die);
71dfc51f 8318
273dbe67
JM
8319 if (TREE_PUBLIC (decl))
8320 add_AT_flag (var_die, DW_AT_external, 1);
71dfc51f 8321
273dbe67
JM
8322 if (DECL_ARTIFICIAL (decl))
8323 add_AT_flag (var_die, DW_AT_artificial, 1);
71dfc51f 8324
a94dbf2c
JM
8325 if (TREE_PROTECTED (decl))
8326 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
71dfc51f 8327
a94dbf2c
JM
8328 else if (TREE_PRIVATE (decl))
8329 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
a3f97cbb 8330 }
4edb7b60
JM
8331
8332 if (declaration)
8333 add_AT_flag (var_die, DW_AT_declaration, 1);
8334
8335 if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
8336 equate_decl_number_to_die (decl, var_die);
8337
8338 if (! declaration && ! DECL_ABSTRACT (decl))
a3f97cbb 8339 {
141719a8 8340 equate_decl_number_to_die (decl, var_die);
a3f97cbb 8341 add_location_or_const_value_attribute (var_die, decl);
d291dd49 8342 add_pubname (decl, var_die);
a3f97cbb
JW
8343 }
8344}
8345
8346/* Generate a DIE to represent a label identifier. */
71dfc51f 8347
a3f97cbb
JW
8348static void
8349gen_label_die (decl, context_die)
8350 register tree decl;
8351 register dw_die_ref context_die;
8352{
8353 register tree origin = decl_ultimate_origin (decl);
8354 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8355 register rtx insn;
8356 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5c90448c 8357 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
71dfc51f 8358
a3f97cbb 8359 if (origin != NULL)
71dfc51f 8360 add_abstract_origin_attribute (lbl_die, origin);
a3f97cbb 8361 else
71dfc51f
RK
8362 add_name_and_src_coords_attributes (lbl_die, decl);
8363
a3f97cbb 8364 if (DECL_ABSTRACT (decl))
71dfc51f 8365 equate_decl_number_to_die (decl, lbl_die);
a3f97cbb
JW
8366 else
8367 {
8368 insn = DECL_RTL (decl);
8369 if (GET_CODE (insn) == CODE_LABEL)
8370 {
8371 /* When optimization is enabled (via -O) some parts of the compiler
8372 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8373 represent source-level labels which were explicitly declared by
8374 the user. This really shouldn't be happening though, so catch
8375 it if it ever does happen. */
8376 if (INSN_DELETED_P (insn))
71dfc51f
RK
8377 abort ();
8378
5c90448c
JM
8379 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8380 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8381 (unsigned) INSN_UID (insn));
a3f97cbb
JW
8382 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8383 }
8384 }
8385}
8386
8387/* Generate a DIE for a lexical block. */
71dfc51f 8388
a3f97cbb 8389static void
d7248bff 8390gen_lexical_block_die (stmt, context_die, depth)
a3f97cbb
JW
8391 register tree stmt;
8392 register dw_die_ref context_die;
d7248bff 8393 int depth;
a3f97cbb
JW
8394{
8395 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8396 char label[MAX_ARTIFICIAL_LABEL_BYTES];
71dfc51f
RK
8397
8398 if (! BLOCK_ABSTRACT (stmt))
a3f97cbb 8399 {
5c90448c
JM
8400 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8401 next_block_number);
a3f97cbb 8402 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
5c90448c 8403 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
a3f97cbb
JW
8404 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8405 }
71dfc51f 8406
7d4440be 8407 push_decl_scope (stmt);
d7248bff 8408 decls_for_scope (stmt, stmt_die, depth);
7d4440be 8409 pop_decl_scope ();
a3f97cbb
JW
8410}
8411
8412/* Generate a DIE for an inlined subprogram. */
71dfc51f 8413
a3f97cbb 8414static void
d7248bff 8415gen_inlined_subroutine_die (stmt, context_die, depth)
a3f97cbb
JW
8416 register tree stmt;
8417 register dw_die_ref context_die;
d7248bff 8418 int depth;
a3f97cbb 8419{
71dfc51f 8420 if (! BLOCK_ABSTRACT (stmt))
a3f97cbb 8421 {
71dfc51f
RK
8422 register dw_die_ref subr_die
8423 = new_die (DW_TAG_inlined_subroutine, context_die);
ab72d377 8424 register tree decl = block_ultimate_origin (stmt);
d7248bff 8425 char label[MAX_ARTIFICIAL_LABEL_BYTES];
71dfc51f 8426
ab72d377 8427 add_abstract_origin_attribute (subr_die, decl);
5c90448c
JM
8428 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8429 next_block_number);
a3f97cbb 8430 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
5c90448c 8431 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
a3f97cbb 8432 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
ab72d377 8433 push_decl_scope (decl);
d7248bff 8434 decls_for_scope (stmt, subr_die, depth);
ab72d377 8435 pop_decl_scope ();
7e23cb16 8436 current_function_has_inlines = 1;
a3f97cbb 8437 }
a3f97cbb
JW
8438}
8439
8440/* Generate a DIE for a field in a record, or structure. */
71dfc51f 8441
a3f97cbb
JW
8442static void
8443gen_field_die (decl, context_die)
8444 register tree decl;
8445 register dw_die_ref context_die;
8446{
8447 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
71dfc51f 8448
a3f97cbb 8449 add_name_and_src_coords_attributes (decl_die, decl);
a3f97cbb
JW
8450 add_type_attribute (decl_die, member_declared_type (decl),
8451 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8452 context_die);
71dfc51f 8453
a3f97cbb
JW
8454 /* If this is a bit field... */
8455 if (DECL_BIT_FIELD_TYPE (decl))
8456 {
8457 add_byte_size_attribute (decl_die, decl);
8458 add_bit_size_attribute (decl_die, decl);
8459 add_bit_offset_attribute (decl_die, decl);
8460 }
71dfc51f 8461
a94dbf2c
JM
8462 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8463 add_data_member_location_attribute (decl_die, decl);
71dfc51f 8464
273dbe67
JM
8465 if (DECL_ARTIFICIAL (decl))
8466 add_AT_flag (decl_die, DW_AT_artificial, 1);
71dfc51f 8467
a94dbf2c
JM
8468 if (TREE_PROTECTED (decl))
8469 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
71dfc51f 8470
a94dbf2c
JM
8471 else if (TREE_PRIVATE (decl))
8472 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
a3f97cbb
JW
8473}
8474
ab72d377
JM
8475#if 0
8476/* Don't generate either pointer_type DIEs or reference_type DIEs here.
8477 Use modified_type_die instead.
a3f97cbb
JW
8478 We keep this code here just in case these types of DIEs may be needed to
8479 represent certain things in other languages (e.g. Pascal) someday. */
8480static void
8481gen_pointer_type_die (type, context_die)
8482 register tree type;
8483 register dw_die_ref context_die;
8484{
71dfc51f
RK
8485 register dw_die_ref ptr_die
8486 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8487
a3f97cbb 8488 equate_type_number_to_die (type, ptr_die);
a3f97cbb 8489 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
ab72d377 8490 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
a3f97cbb
JW
8491}
8492
ab72d377
JM
8493/* Don't generate either pointer_type DIEs or reference_type DIEs here.
8494 Use modified_type_die instead.
a3f97cbb
JW
8495 We keep this code here just in case these types of DIEs may be needed to
8496 represent certain things in other languages (e.g. Pascal) someday. */
8497static void
8498gen_reference_type_die (type, context_die)
8499 register tree type;
8500 register dw_die_ref context_die;
8501{
71dfc51f
RK
8502 register dw_die_ref ref_die
8503 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8504
a3f97cbb 8505 equate_type_number_to_die (type, ref_die);
a3f97cbb 8506 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
ab72d377 8507 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
a3f97cbb 8508}
ab72d377 8509#endif
a3f97cbb
JW
8510
8511/* Generate a DIE for a pointer to a member type. */
8512static void
8513gen_ptr_to_mbr_type_die (type, context_die)
8514 register tree type;
8515 register dw_die_ref context_die;
8516{
71dfc51f
RK
8517 register dw_die_ref ptr_die
8518 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8519
a3f97cbb 8520 equate_type_number_to_die (type, ptr_die);
a3f97cbb 8521 add_AT_die_ref (ptr_die, DW_AT_containing_type,
bdb669cb 8522 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
a3f97cbb
JW
8523 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8524}
8525
8526/* Generate the DIE for the compilation unit. */
71dfc51f 8527
a3f97cbb
JW
8528static void
8529gen_compile_unit_die (main_input_filename)
8530 register char *main_input_filename;
8531{
8532 char producer[250];
a3f97cbb
JW
8533 char *wd = getpwd ();
8534
8535 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
bdb669cb
JM
8536 add_name_attribute (comp_unit_die, main_input_filename);
8537
71dfc51f
RK
8538 if (wd != NULL)
8539 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
a3f97cbb
JW
8540
8541 sprintf (producer, "%s %s", language_string, version_string);
8542
8543#ifdef MIPS_DEBUGGING_INFO
8544 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8545 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8546 not appear in the producer string, the debugger reaches the conclusion
8547 that the object file is stripped and has no debugging information.
8548 To get the MIPS/SGI debugger to believe that there is debugging
8549 information in the object file, we add a -g to the producer string. */
4927276d
JM
8550 if (debug_info_level > DINFO_LEVEL_TERSE)
8551 strcat (producer, " -g");
a3f97cbb
JW
8552#endif
8553
8554 add_AT_string (comp_unit_die, DW_AT_producer, producer);
a9d38797 8555
a3f97cbb 8556 if (strcmp (language_string, "GNU C++") == 0)
a9d38797 8557 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
71dfc51f 8558
a3f97cbb 8559 else if (strcmp (language_string, "GNU Ada") == 0)
a9d38797 8560 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
71dfc51f 8561
a9d38797
JM
8562 else if (strcmp (language_string, "GNU F77") == 0)
8563 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
71dfc51f 8564
bc28c45b
RK
8565 else if (strcmp (language_string, "GNU Pascal") == 0)
8566 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Pascal83);
8567
a3f97cbb 8568 else if (flag_traditional)
a9d38797 8569 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
71dfc51f 8570
a3f97cbb 8571 else
a9d38797
JM
8572 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
8573
8574#if 0 /* unimplemented */
e90b62db 8575 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
a9d38797
JM
8576 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
8577#endif
a3f97cbb
JW
8578}
8579
8580/* Generate a DIE for a string type. */
71dfc51f 8581
a3f97cbb
JW
8582static void
8583gen_string_type_die (type, context_die)
8584 register tree type;
8585 register dw_die_ref context_die;
8586{
71dfc51f
RK
8587 register dw_die_ref type_die
8588 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8589
bdb669cb 8590 equate_type_number_to_die (type, type_die);
a3f97cbb
JW
8591
8592 /* Fudge the string length attribute for now. */
71dfc51f 8593
a3f97cbb 8594 /* TODO: add string length info.
71dfc51f 8595 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
a3f97cbb
JW
8596 bound_representation (upper_bound, 0, 'u'); */
8597}
8598
61b32c02 8599/* Generate the DIE for a base class. */
71dfc51f 8600
61b32c02
JM
8601static void
8602gen_inheritance_die (binfo, context_die)
8603 register tree binfo;
8604 register dw_die_ref context_die;
8605{
8606 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
71dfc51f 8607
61b32c02
JM
8608 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8609 add_data_member_location_attribute (die, binfo);
71dfc51f 8610
61b32c02
JM
8611 if (TREE_VIA_VIRTUAL (binfo))
8612 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8613 if (TREE_VIA_PUBLIC (binfo))
8614 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8615 else if (TREE_VIA_PROTECTED (binfo))
8616 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8617}
8618
956d6950 8619/* Generate a DIE for a class member. */
71dfc51f 8620
a3f97cbb
JW
8621static void
8622gen_member_die (type, context_die)
8623 register tree type;
8624 register dw_die_ref context_die;
8625{
61b32c02 8626 register tree member;
71dfc51f 8627
a3f97cbb
JW
8628 /* If this is not an incomplete type, output descriptions of each of its
8629 members. Note that as we output the DIEs necessary to represent the
8630 members of this record or union type, we will also be trying to output
8631 DIEs to represent the *types* of those members. However the `type'
8632 function (above) will specifically avoid generating type DIEs for member
8633 types *within* the list of member DIEs for this (containing) type execpt
8634 for those types (of members) which are explicitly marked as also being
8635 members of this (containing) type themselves. The g++ front- end can
8636 force any given type to be treated as a member of some other
8637 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8638 to point to the TREE node representing the appropriate (containing)
8639 type. */
8640
61b32c02
JM
8641 /* First output info about the base classes. */
8642 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
a3f97cbb 8643 {
61b32c02
JM
8644 register tree bases = TYPE_BINFO_BASETYPES (type);
8645 register int n_bases = TREE_VEC_LENGTH (bases);
8646 register int i;
8647
8648 for (i = 0; i < n_bases; i++)
8649 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
a3f97cbb
JW
8650 }
8651
61b32c02
JM
8652 /* Now output info about the data members and type members. */
8653 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8654 gen_decl_die (member, context_die);
8655
a3f97cbb 8656 /* Now output info about the function members (if any). */
61b32c02
JM
8657 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8658 gen_decl_die (member, context_die);
a3f97cbb
JW
8659}
8660
8661/* Generate a DIE for a structure or union type. */
71dfc51f 8662
a3f97cbb 8663static void
273dbe67 8664gen_struct_or_union_type_die (type, context_die)
a3f97cbb 8665 register tree type;
a3f97cbb
JW
8666 register dw_die_ref context_die;
8667{
273dbe67 8668 register dw_die_ref type_die = lookup_type_die (type);
a082c85a
JM
8669 register dw_die_ref scope_die = 0;
8670 register int nested = 0;
273dbe67
JM
8671
8672 if (type_die && ! TYPE_SIZE (type))
8673 return;
a082c85a 8674
71dfc51f 8675 if (TYPE_CONTEXT (type) != NULL_TREE
a082c85a
JM
8676 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
8677 nested = 1;
8678
a94dbf2c 8679 scope_die = scope_die_for (type, context_die);
a082c85a
JM
8680
8681 if (! type_die || (nested && scope_die == comp_unit_die))
273dbe67 8682 /* First occurrence of type or toplevel definition of nested class. */
a3f97cbb 8683 {
273dbe67 8684 register dw_die_ref old_die = type_die;
71dfc51f 8685
a3f97cbb
JW
8686 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8687 ? DW_TAG_structure_type : DW_TAG_union_type,
a082c85a 8688 scope_die);
a3f97cbb
JW
8689 equate_type_number_to_die (type, type_die);
8690 add_name_attribute (type_die, type_tag (type));
273dbe67
JM
8691 if (old_die)
8692 add_AT_die_ref (type_die, DW_AT_specification, old_die);
a3f97cbb 8693 }
4b674448 8694 else
273dbe67 8695 remove_AT (type_die, DW_AT_declaration);
a3f97cbb 8696
a94dbf2c
JM
8697 /* If we're not in the right context to be defining this type, defer to
8698 avoid tricky recursion. */
8699 if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
8700 {
8701 add_AT_flag (type_die, DW_AT_declaration, 1);
8702 pend_type (type);
8703 }
a3f97cbb
JW
8704 /* If this type has been completed, then give it a byte_size attribute and
8705 then give a list of members. */
a94dbf2c 8706 else if (TYPE_SIZE (type))
a3f97cbb
JW
8707 {
8708 /* Prevent infinite recursion in cases where the type of some member of
8709 this type is expressed in terms of this type itself. */
8710 TREE_ASM_WRITTEN (type) = 1;
273dbe67 8711 add_byte_size_attribute (type_die, type);
e9a25f70 8712 if (TYPE_STUB_DECL (type) != NULL_TREE)
b2932ae5 8713 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
71dfc51f 8714
ef76d03b
JW
8715 /* If the first reference to this type was as the return type of an
8716 inline function, then it may not have a parent. Fix this now. */
8717 if (type_die->die_parent == NULL)
8718 add_child_die (scope_die, type_die);
8719
273dbe67
JM
8720 push_decl_scope (type);
8721 gen_member_die (type, type_die);
8722 pop_decl_scope ();
71dfc51f 8723
a94dbf2c
JM
8724 /* GNU extension: Record what type our vtable lives in. */
8725 if (TYPE_VFIELD (type))
8726 {
8727 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
71dfc51f 8728
a94dbf2c
JM
8729 gen_type_die (vtype, context_die);
8730 add_AT_die_ref (type_die, DW_AT_containing_type,
8731 lookup_type_die (vtype));
8732 }
a3f97cbb 8733 }
4b674448
JM
8734 else
8735 add_AT_flag (type_die, DW_AT_declaration, 1);
a3f97cbb
JW
8736}
8737
8738/* Generate a DIE for a subroutine _type_. */
71dfc51f 8739
a3f97cbb
JW
8740static void
8741gen_subroutine_type_die (type, context_die)
8742 register tree type;
8743 register dw_die_ref context_die;
8744{
8745 register tree return_type = TREE_TYPE (type);
71dfc51f
RK
8746 register dw_die_ref subr_die
8747 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8748
a3f97cbb
JW
8749 equate_type_number_to_die (type, subr_die);
8750 add_prototyped_attribute (subr_die, type);
a3f97cbb 8751 add_type_attribute (subr_die, return_type, 0, 0, context_die);
a94dbf2c 8752 gen_formal_types_die (type, subr_die);
a3f97cbb
JW
8753}
8754
8755/* Generate a DIE for a type definition */
71dfc51f 8756
a3f97cbb
JW
8757static void
8758gen_typedef_die (decl, context_die)
8759 register tree decl;
8760 register dw_die_ref context_die;
8761{
a3f97cbb 8762 register dw_die_ref type_die;
a94dbf2c
JM
8763 register tree origin;
8764
8765 if (TREE_ASM_WRITTEN (decl))
8766 return;
8767 TREE_ASM_WRITTEN (decl) = 1;
8768
ab72d377 8769 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
a94dbf2c 8770 origin = decl_ultimate_origin (decl);
a3f97cbb 8771 if (origin != NULL)
a94dbf2c 8772 add_abstract_origin_attribute (type_die, origin);
a3f97cbb
JW
8773 else
8774 {
a94dbf2c 8775 register tree type;
a3f97cbb 8776 add_name_and_src_coords_attributes (type_die, decl);
a94dbf2c
JM
8777 if (DECL_ORIGINAL_TYPE (decl))
8778 {
8779 type = DECL_ORIGINAL_TYPE (decl);
8780 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8781 }
8782 else
8783 type = TREE_TYPE (decl);
8784 add_type_attribute (type_die, type, TREE_READONLY (decl),
8785 TREE_THIS_VOLATILE (decl), context_die);
a3f97cbb 8786 }
71dfc51f 8787
a3f97cbb 8788 if (DECL_ABSTRACT (decl))
a94dbf2c 8789 equate_decl_number_to_die (decl, type_die);
a3f97cbb
JW
8790}
8791
8792/* Generate a type description DIE. */
71dfc51f 8793
a3f97cbb
JW
8794static void
8795gen_type_die (type, context_die)
8796 register tree type;
8797 register dw_die_ref context_die;
8798{
71dfc51f
RK
8799 if (type == NULL_TREE || type == error_mark_node)
8800 return;
a3f97cbb
JW
8801
8802 /* We are going to output a DIE to represent the unqualified version of of
8803 this type (i.e. without any const or volatile qualifiers) so get the
8804 main variant (i.e. the unqualified version) of this type now. */
8805 type = type_main_variant (type);
8806
8807 if (TREE_ASM_WRITTEN (type))
71dfc51f 8808 return;
a3f97cbb 8809
a94dbf2c
JM
8810 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8811 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8812 {
8813 TREE_ASM_WRITTEN (type) = 1;
8814 gen_decl_die (TYPE_NAME (type), context_die);
8815 return;
8816 }
8817
a3f97cbb
JW
8818 switch (TREE_CODE (type))
8819 {
8820 case ERROR_MARK:
8821 break;
8822
8823 case POINTER_TYPE:
8824 case REFERENCE_TYPE:
956d6950
JL
8825 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
8826 ensures that the gen_type_die recursion will terminate even if the
8827 type is recursive. Recursive types are possible in Ada. */
8828 /* ??? We could perhaps do this for all types before the switch
8829 statement. */
8830 TREE_ASM_WRITTEN (type) = 1;
8831
a3f97cbb
JW
8832 /* For these types, all that is required is that we output a DIE (or a
8833 set of DIEs) to represent the "basis" type. */
8834 gen_type_die (TREE_TYPE (type), context_die);
8835 break;
8836
8837 case OFFSET_TYPE:
71dfc51f
RK
8838 /* This code is used for C++ pointer-to-data-member types.
8839 Output a description of the relevant class type. */
a3f97cbb 8840 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
71dfc51f 8841
a3f97cbb
JW
8842 /* Output a description of the type of the object pointed to. */
8843 gen_type_die (TREE_TYPE (type), context_die);
71dfc51f 8844
a3f97cbb
JW
8845 /* Now output a DIE to represent this pointer-to-data-member type
8846 itself. */
8847 gen_ptr_to_mbr_type_die (type, context_die);
8848 break;
8849
8850 case SET_TYPE:
8851 gen_type_die (TYPE_DOMAIN (type), context_die);
8852 gen_set_type_die (type, context_die);
8853 break;
8854
8855 case FILE_TYPE:
8856 gen_type_die (TREE_TYPE (type), context_die);
8857 abort (); /* No way to represent these in Dwarf yet! */
8858 break;
8859
8860 case FUNCTION_TYPE:
8861 /* Force out return type (in case it wasn't forced out already). */
8862 gen_type_die (TREE_TYPE (type), context_die);
8863 gen_subroutine_type_die (type, context_die);
8864 break;
8865
8866 case METHOD_TYPE:
8867 /* Force out return type (in case it wasn't forced out already). */
8868 gen_type_die (TREE_TYPE (type), context_die);
8869 gen_subroutine_type_die (type, context_die);
8870 break;
8871
8872 case ARRAY_TYPE:
8873 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
8874 {
8875 gen_type_die (TREE_TYPE (type), context_die);
8876 gen_string_type_die (type, context_die);
8877 }
8878 else
71dfc51f 8879 gen_array_type_die (type, context_die);
a3f97cbb
JW
8880 break;
8881
8882 case ENUMERAL_TYPE:
8883 case RECORD_TYPE:
8884 case UNION_TYPE:
8885 case QUAL_UNION_TYPE:
a082c85a
JM
8886 /* If this is a nested type whose containing class hasn't been
8887 written out yet, writing it out will cover this one, too. */
8888 if (TYPE_CONTEXT (type)
8889 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8890 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
a94dbf2c
JM
8891 {
8892 gen_type_die (TYPE_CONTEXT (type), context_die);
8893
8894 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8895 return;
8896
8897 /* If that failed, attach ourselves to the stub. */
8898 push_decl_scope (TYPE_CONTEXT (type));
8899 context_die = lookup_type_die (TYPE_CONTEXT (type));
8900 }
8901
8902 if (TREE_CODE (type) == ENUMERAL_TYPE)
273dbe67 8903 gen_enumeration_type_die (type, context_die);
a3f97cbb 8904 else
273dbe67 8905 gen_struct_or_union_type_die (type, context_die);
4b674448 8906
a94dbf2c
JM
8907 if (TYPE_CONTEXT (type)
8908 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8909 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8910 pop_decl_scope ();
8911
4b674448 8912 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
a082c85a
JM
8913 it up if it is ever completed. gen_*_type_die will set it for us
8914 when appropriate. */
8915 return;
a3f97cbb
JW
8916
8917 case VOID_TYPE:
8918 case INTEGER_TYPE:
8919 case REAL_TYPE:
8920 case COMPLEX_TYPE:
8921 case BOOLEAN_TYPE:
8922 case CHAR_TYPE:
8923 /* No DIEs needed for fundamental types. */
8924 break;
8925
8926 case LANG_TYPE:
8927 /* No Dwarf representation currently defined. */
8928 break;
8929
8930 default:
8931 abort ();
8932 }
8933
8934 TREE_ASM_WRITTEN (type) = 1;
8935}
8936
8937/* Generate a DIE for a tagged type instantiation. */
71dfc51f 8938
a3f97cbb
JW
8939static void
8940gen_tagged_type_instantiation_die (type, context_die)
8941 register tree type;
8942 register dw_die_ref context_die;
8943{
71dfc51f
RK
8944 if (type == NULL_TREE || type == error_mark_node)
8945 return;
a3f97cbb
JW
8946
8947 /* We are going to output a DIE to represent the unqualified version of of
8948 this type (i.e. without any const or volatile qualifiers) so make sure
8949 that we have the main variant (i.e. the unqualified version) of this
8950 type now. */
3a88cbd1
JL
8951 if (type != type_main_variant (type)
8952 || !TREE_ASM_WRITTEN (type))
8953 abort ();
a3f97cbb
JW
8954
8955 switch (TREE_CODE (type))
8956 {
8957 case ERROR_MARK:
8958 break;
8959
8960 case ENUMERAL_TYPE:
8961 gen_inlined_enumeration_type_die (type, context_die);
8962 break;
8963
8964 case RECORD_TYPE:
8965 gen_inlined_structure_type_die (type, context_die);
8966 break;
8967
8968 case UNION_TYPE:
8969 case QUAL_UNION_TYPE:
8970 gen_inlined_union_type_die (type, context_die);
8971 break;
8972
8973 default:
71dfc51f 8974 abort ();
a3f97cbb
JW
8975 }
8976}
8977
8978/* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
8979 things which are local to the given block. */
71dfc51f 8980
a3f97cbb 8981static void
d7248bff 8982gen_block_die (stmt, context_die, depth)
a3f97cbb
JW
8983 register tree stmt;
8984 register dw_die_ref context_die;
d7248bff 8985 int depth;
a3f97cbb
JW
8986{
8987 register int must_output_die = 0;
8988 register tree origin;
8989 register tree decl;
8990 register enum tree_code origin_code;
8991
8992 /* Ignore blocks never really used to make RTL. */
8993
71dfc51f
RK
8994 if (stmt == NULL_TREE || !TREE_USED (stmt))
8995 return;
a3f97cbb
JW
8996
8997 /* Determine the "ultimate origin" of this block. This block may be an
8998 inlined instance of an inlined instance of inline function, so we have
8999 to trace all of the way back through the origin chain to find out what
9000 sort of node actually served as the original seed for the creation of
9001 the current block. */
9002 origin = block_ultimate_origin (stmt);
9003 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9004
9005 /* Determine if we need to output any Dwarf DIEs at all to represent this
9006 block. */
9007 if (origin_code == FUNCTION_DECL)
71dfc51f
RK
9008 /* The outer scopes for inlinings *must* always be represented. We
9009 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9010 must_output_die = 1;
a3f97cbb
JW
9011 else
9012 {
9013 /* In the case where the current block represents an inlining of the
9014 "body block" of an inline function, we must *NOT* output any DIE for
9015 this block because we have already output a DIE to represent the
9016 whole inlined function scope and the "body block" of any function
9017 doesn't really represent a different scope according to ANSI C
9018 rules. So we check here to make sure that this block does not
9019 represent a "body block inlining" before trying to set the
9020 `must_output_die' flag. */
d7248bff 9021 if (! is_body_block (origin ? origin : stmt))
a3f97cbb
JW
9022 {
9023 /* Determine if this block directly contains any "significant"
9024 local declarations which we will need to output DIEs for. */
9025 if (debug_info_level > DINFO_LEVEL_TERSE)
71dfc51f
RK
9026 /* We are not in terse mode so *any* local declaration counts
9027 as being a "significant" one. */
9028 must_output_die = (BLOCK_VARS (stmt) != NULL);
a3f97cbb 9029 else
71dfc51f
RK
9030 /* We are in terse mode, so only local (nested) function
9031 definitions count as "significant" local declarations. */
9032 for (decl = BLOCK_VARS (stmt);
9033 decl != NULL; decl = TREE_CHAIN (decl))
9034 if (TREE_CODE (decl) == FUNCTION_DECL
9035 && DECL_INITIAL (decl))
a3f97cbb 9036 {
71dfc51f
RK
9037 must_output_die = 1;
9038 break;
a3f97cbb 9039 }
a3f97cbb
JW
9040 }
9041 }
9042
9043 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9044 DIE for any block which contains no significant local declarations at
9045 all. Rather, in such cases we just call `decls_for_scope' so that any
9046 needed Dwarf info for any sub-blocks will get properly generated. Note
9047 that in terse mode, our definition of what constitutes a "significant"
9048 local declaration gets restricted to include only inlined function
9049 instances and local (nested) function definitions. */
9050 if (must_output_die)
9051 {
9052 if (origin_code == FUNCTION_DECL)
71dfc51f 9053 gen_inlined_subroutine_die (stmt, context_die, depth);
a3f97cbb 9054 else
71dfc51f 9055 gen_lexical_block_die (stmt, context_die, depth);
a3f97cbb
JW
9056 }
9057 else
d7248bff 9058 decls_for_scope (stmt, context_die, depth);
a3f97cbb
JW
9059}
9060
9061/* Generate all of the decls declared within a given scope and (recursively)
9062 all of it's sub-blocks. */
71dfc51f 9063
a3f97cbb 9064static void
d7248bff 9065decls_for_scope (stmt, context_die, depth)
a3f97cbb
JW
9066 register tree stmt;
9067 register dw_die_ref context_die;
d7248bff 9068 int depth;
a3f97cbb
JW
9069{
9070 register tree decl;
9071 register tree subblocks;
71dfc51f 9072
a3f97cbb 9073 /* Ignore blocks never really used to make RTL. */
71dfc51f
RK
9074 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9075 return;
9076
d7248bff 9077 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
71dfc51f 9078 next_block_number++;
a3f97cbb 9079
88dad228
JM
9080 /* Output the DIEs to represent all of the data objects and typedefs
9081 declared directly within this block but not within any nested
9082 sub-blocks. Also, nested function and tag DIEs have been
9083 generated with a parent of NULL; fix that up now. */
a3f97cbb
JW
9084 for (decl = BLOCK_VARS (stmt);
9085 decl != NULL; decl = TREE_CHAIN (decl))
9086 {
a94dbf2c
JM
9087 register dw_die_ref die;
9088
88dad228 9089 if (TREE_CODE (decl) == FUNCTION_DECL)
a94dbf2c 9090 die = lookup_decl_die (decl);
88dad228 9091 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
a94dbf2c
JM
9092 die = lookup_type_die (TREE_TYPE (decl));
9093 else
9094 die = NULL;
9095
71dfc51f 9096 if (die != NULL && die->die_parent == NULL)
ef76d03b 9097 add_child_die (context_die, die);
88dad228
JM
9098 else
9099 gen_decl_die (decl, context_die);
a3f97cbb
JW
9100 }
9101
9102 /* Output the DIEs to represent all sub-blocks (and the items declared
9103 therein) of this block. */
9104 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9105 subblocks != NULL;
9106 subblocks = BLOCK_CHAIN (subblocks))
71dfc51f 9107 gen_block_die (subblocks, context_die, depth + 1);
a3f97cbb
JW
9108}
9109
a94dbf2c 9110/* Is this a typedef we can avoid emitting? */
71dfc51f
RK
9111
9112static inline int
a94dbf2c
JM
9113is_redundant_typedef (decl)
9114 register tree decl;
9115{
9116 if (TYPE_DECL_IS_STUB (decl))
9117 return 1;
71dfc51f 9118
a94dbf2c
JM
9119 if (DECL_ARTIFICIAL (decl)
9120 && DECL_CONTEXT (decl)
9121 && is_tagged_type (DECL_CONTEXT (decl))
9122 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9123 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9124 /* Also ignore the artificial member typedef for the class name. */
9125 return 1;
71dfc51f 9126
a94dbf2c
JM
9127 return 0;
9128}
9129
a3f97cbb 9130/* Generate Dwarf debug information for a decl described by DECL. */
71dfc51f 9131
a3f97cbb
JW
9132static void
9133gen_decl_die (decl, context_die)
9134 register tree decl;
9135 register dw_die_ref context_die;
9136{
9137 register tree origin;
71dfc51f 9138
a3f97cbb
JW
9139 /* Make a note of the decl node we are going to be working on. We may need
9140 to give the user the source coordinates of where it appeared in case we
9141 notice (later on) that something about it looks screwy. */
9142 dwarf_last_decl = decl;
9143
9144 if (TREE_CODE (decl) == ERROR_MARK)
71dfc51f 9145 return;
a3f97cbb
JW
9146
9147 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
9148 ignore a function definition, since that would screw up our count of
9149 blocks, and that it turn will completely screw up the the labels we will
9150 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9151 subsequent blocks). */
9152 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
71dfc51f 9153 return;
a3f97cbb 9154
a3f97cbb
JW
9155 switch (TREE_CODE (decl))
9156 {
9157 case CONST_DECL:
9158 /* The individual enumerators of an enum type get output when we output
9159 the Dwarf representation of the relevant enum type itself. */
9160 break;
9161
9162 case FUNCTION_DECL:
4edb7b60
JM
9163 /* Don't output any DIEs to represent mere function declarations,
9164 unless they are class members or explicit block externs. */
9165 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9166 && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
71dfc51f 9167 break;
bdb669cb 9168
4927276d 9169 if (debug_info_level > DINFO_LEVEL_TERSE)
a94dbf2c
JM
9170 {
9171 /* Before we describe the FUNCTION_DECL itself, make sure that we
9172 have described its return type. */
9173 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9174
9175 /* And its containing type. */
9176 origin = decl_class_context (decl);
71dfc51f 9177 if (origin != NULL_TREE)
a94dbf2c
JM
9178 gen_type_die (origin, context_die);
9179
9180 /* And its virtual context. */
71dfc51f 9181 if (DECL_VINDEX (decl) != NULL_TREE)
a94dbf2c
JM
9182 gen_type_die (DECL_CONTEXT (decl), context_die);
9183 }
a3f97cbb
JW
9184
9185 /* Now output a DIE to represent the function itself. */
9186 gen_subprogram_die (decl, context_die);
9187 break;
9188
9189 case TYPE_DECL:
9190 /* If we are in terse mode, don't generate any DIEs to represent any
4927276d 9191 actual typedefs. */
a3f97cbb 9192 if (debug_info_level <= DINFO_LEVEL_TERSE)
4927276d 9193 break;
a3f97cbb 9194
5c90448c
JM
9195 /* In the special case of a TYPE_DECL node representing the
9196 declaration of some type tag, if the given TYPE_DECL is marked as
a3f97cbb
JW
9197 having been instantiated from some other (original) TYPE_DECL node
9198 (e.g. one which was generated within the original definition of an
9199 inline function) we have to generate a special (abbreviated)
ef76d03b 9200 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
a3f97cbb 9201 DIE here. */
71dfc51f 9202 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
a3f97cbb
JW
9203 {
9204 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9205 break;
9206 }
a3f97cbb 9207
a94dbf2c
JM
9208 if (is_redundant_typedef (decl))
9209 gen_type_die (TREE_TYPE (decl), context_die);
9210 else
71dfc51f
RK
9211 /* Output a DIE to represent the typedef itself. */
9212 gen_typedef_die (decl, context_die);
a3f97cbb
JW
9213 break;
9214
9215 case LABEL_DECL:
9216 if (debug_info_level >= DINFO_LEVEL_NORMAL)
71dfc51f 9217 gen_label_die (decl, context_die);
a3f97cbb
JW
9218 break;
9219
9220 case VAR_DECL:
9221 /* If we are in terse mode, don't generate any DIEs to represent any
9222 variable declarations or definitions. */
9223 if (debug_info_level <= DINFO_LEVEL_TERSE)
71dfc51f 9224 break;
a3f97cbb
JW
9225
9226 /* Output any DIEs that are needed to specify the type of this data
9227 object. */
9228 gen_type_die (TREE_TYPE (decl), context_die);
9229
a94dbf2c
JM
9230 /* And its containing type. */
9231 origin = decl_class_context (decl);
71dfc51f 9232 if (origin != NULL_TREE)
a94dbf2c
JM
9233 gen_type_die (origin, context_die);
9234
a3f97cbb
JW
9235 /* Now output the DIE to represent the data object itself. This gets
9236 complicated because of the possibility that the VAR_DECL really
9237 represents an inlined instance of a formal parameter for an inline
9238 function. */
9239 origin = decl_ultimate_origin (decl);
71dfc51f
RK
9240 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9241 gen_formal_parameter_die (decl, context_die);
a3f97cbb 9242 else
71dfc51f 9243 gen_variable_die (decl, context_die);
a3f97cbb
JW
9244 break;
9245
9246 case FIELD_DECL:
a94dbf2c
JM
9247 /* Ignore the nameless fields that are used to skip bits, but
9248 handle C++ anonymous unions. */
71dfc51f
RK
9249 if (DECL_NAME (decl) != NULL_TREE
9250 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
a3f97cbb
JW
9251 {
9252 gen_type_die (member_declared_type (decl), context_die);
9253 gen_field_die (decl, context_die);
9254 }
9255 break;
9256
9257 case PARM_DECL:
9258 gen_type_die (TREE_TYPE (decl), context_die);
9259 gen_formal_parameter_die (decl, context_die);
9260 break;
9261
9262 default:
9263 abort ();
9264 }
a3f97cbb
JW
9265}
9266\f
71dfc51f
RK
9267/* Write the debugging output for DECL. */
9268
a3f97cbb 9269void
88dad228 9270dwarf2out_decl (decl)
a3f97cbb 9271 register tree decl;
a3f97cbb 9272{
88dad228
JM
9273 register dw_die_ref context_die = comp_unit_die;
9274
a3f97cbb 9275 if (TREE_CODE (decl) == ERROR_MARK)
71dfc51f 9276 return;
a3f97cbb
JW
9277
9278 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
9279 hope that the node in question doesn't represent a function definition.
9280 If it does, then totally ignoring it is bound to screw up our count of
9281 blocks, and that it turn will completely screw up the the labels we will
9282 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9283 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
9284 own sequence numbers with them!) */
9285 if (DECL_IGNORED_P (decl))
9286 {
9287 if (TREE_CODE (decl) == FUNCTION_DECL
9288 && DECL_INITIAL (decl) != NULL)
71dfc51f
RK
9289 abort ();
9290
a3f97cbb
JW
9291 return;
9292 }
9293
9294 switch (TREE_CODE (decl))
9295 {
9296 case FUNCTION_DECL:
9297 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9298 builtin function. Explicit programmer-supplied declarations of
9299 these same functions should NOT be ignored however. */
9300 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
b1ccbc24 9301 return;
a3f97cbb
JW
9302
9303 /* What we would really like to do here is to filter out all mere
9304 file-scope declarations of file-scope functions which are never
9305 referenced later within this translation unit (and keep all of ones
956d6950 9306 that *are* referenced later on) but we aren't clairvoyant, so we have
a3f97cbb
JW
9307 no idea which functions will be referenced in the future (i.e. later
9308 on within the current translation unit). So here we just ignore all
9309 file-scope function declarations which are not also definitions. If
956d6950 9310 and when the debugger needs to know something about these functions,
a3f97cbb
JW
9311 it wil have to hunt around and find the DWARF information associated
9312 with the definition of the function. Note that we can't just check
9313 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9314 definitions and which ones represent mere declarations. We have to
9315 check `DECL_INITIAL' instead. That's because the C front-end
9316 supports some weird semantics for "extern inline" function
9317 definitions. These can get inlined within the current translation
9318 unit (an thus, we need to generate DWARF info for their abstract
9319 instances so that the DWARF info for the concrete inlined instances
9320 can have something to refer to) but the compiler never generates any
9321 out-of-lines instances of such things (despite the fact that they
9322 *are* definitions). The important point is that the C front-end
9323 marks these "extern inline" functions as DECL_EXTERNAL, but we need
273dbe67 9324 to generate DWARF for them anyway. Note that the C++ front-end also
a3f97cbb
JW
9325 plays some similar games for inline function definitions appearing
9326 within include files which also contain
9327 `#pragma interface' pragmas. */
9328 if (DECL_INITIAL (decl) == NULL_TREE)
b1ccbc24 9329 return;
88dad228 9330
9c6cd30e
JM
9331 /* If we're a nested function, initially use a parent of NULL; if we're
9332 a plain function, this will be fixed up in decls_for_scope. If
9333 we're a method, it will be ignored, since we already have a DIE. */
88dad228 9334 if (decl_function_context (decl))
9c6cd30e 9335 context_die = NULL;
88dad228 9336
a3f97cbb
JW
9337 break;
9338
9339 case VAR_DECL:
9340 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9341 declaration and if the declaration was never even referenced from
9342 within this entire compilation unit. We suppress these DIEs in
9343 order to save space in the .debug section (by eliminating entries
9344 which are probably useless). Note that we must not suppress
9345 block-local extern declarations (whether used or not) because that
9346 would screw-up the debugger's name lookup mechanism and cause it to
9347 miss things which really ought to be in scope at a given point. */
9348 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
71dfc51f 9349 return;
a3f97cbb
JW
9350
9351 /* If we are in terse mode, don't generate any DIEs to represent any
9352 variable declarations or definitions. */
9353 if (debug_info_level <= DINFO_LEVEL_TERSE)
71dfc51f 9354 return;
a3f97cbb
JW
9355 break;
9356
9357 case TYPE_DECL:
9358 /* Don't bother trying to generate any DIEs to represent any of the
a9d38797
JM
9359 normal built-in types for the language we are compiling. */
9360 if (DECL_SOURCE_LINE (decl) == 0)
a94dbf2c
JM
9361 {
9362 /* OK, we need to generate one for `bool' so GDB knows what type
9363 comparisons have. */
9364 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9365 == DW_LANG_C_plus_plus)
9366 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9367 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
71dfc51f 9368
a94dbf2c
JM
9369 return;
9370 }
a3f97cbb 9371
88dad228 9372 /* If we are in terse mode, don't generate any DIEs for types. */
a3f97cbb 9373 if (debug_info_level <= DINFO_LEVEL_TERSE)
4927276d 9374 return;
88dad228
JM
9375
9376 /* If we're a function-scope tag, initially use a parent of NULL;
9377 this will be fixed up in decls_for_scope. */
9378 if (decl_function_context (decl))
3f76745e 9379 context_die = NULL;
88dad228 9380
a3f97cbb
JW
9381 break;
9382
9383 default:
9384 return;
9385 }
9386
88dad228 9387 gen_decl_die (decl, context_die);
a94dbf2c 9388 output_pending_types_for_scope (comp_unit_die);
a3f97cbb
JW
9389}
9390
9391/* Output a marker (i.e. a label) for the beginning of the generated code for
9392 a lexical block. */
71dfc51f 9393
a3f97cbb 9394void
9a666dda 9395dwarf2out_begin_block (blocknum)
a3f97cbb
JW
9396 register unsigned blocknum;
9397{
a3f97cbb 9398 function_section (current_function_decl);
5c90448c 9399 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
a3f97cbb
JW
9400}
9401
9402/* Output a marker (i.e. a label) for the end of the generated code for a
9403 lexical block. */
71dfc51f 9404
a3f97cbb 9405void
9a666dda 9406dwarf2out_end_block (blocknum)
a3f97cbb
JW
9407 register unsigned blocknum;
9408{
a3f97cbb 9409 function_section (current_function_decl);
5c90448c 9410 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
a3f97cbb
JW
9411}
9412
9413/* Output a marker (i.e. a label) at a point in the assembly code which
9414 corresponds to a given source level label. */
71dfc51f 9415
a3f97cbb 9416void
9a666dda 9417dwarf2out_label (insn)
a3f97cbb
JW
9418 register rtx insn;
9419{
9420 char label[MAX_ARTIFICIAL_LABEL_BYTES];
71dfc51f 9421
a3f97cbb
JW
9422 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9423 {
9424 function_section (current_function_decl);
5c90448c
JM
9425 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9426 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9427 (unsigned) INSN_UID (insn));
a3f97cbb
JW
9428 }
9429}
9430
a3f97cbb 9431/* Lookup a filename (in the list of filenames that we know about here in
9a666dda 9432 dwarf2out.c) and return its "index". The index of each (known) filename is
a3f97cbb
JW
9433 just a unique number which is associated with only that one filename.
9434 We need such numbers for the sake of generating labels
9435 (in the .debug_sfnames section) and references to those
9436 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9437 If the filename given as an argument is not found in our current list,
9438 add it to the list and assign it the next available unique index number.
9439 In order to speed up searches, we remember the index of the filename
9440 was looked up last. This handles the majority of all searches. */
71dfc51f 9441
a3f97cbb
JW
9442static unsigned
9443lookup_filename (file_name)
9444 char *file_name;
9445{
9446 static unsigned last_file_lookup_index = 0;
a3f97cbb
JW
9447 register unsigned i;
9448
9449 /* Check to see if the file name that was searched on the previous call
9450 matches this file name. If so, return the index. */
9451 if (last_file_lookup_index != 0)
71dfc51f
RK
9452 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9453 return last_file_lookup_index;
a3f97cbb
JW
9454
9455 /* Didn't match the previous lookup, search the table */
9456 for (i = 1; i < file_table_in_use; ++i)
71dfc51f
RK
9457 if (strcmp (file_name, file_table[i]) == 0)
9458 {
9459 last_file_lookup_index = i;
9460 return i;
9461 }
a3f97cbb
JW
9462
9463 /* Prepare to add a new table entry by making sure there is enough space in
9464 the table to do so. If not, expand the current table. */
9465 if (file_table_in_use == file_table_allocated)
9466 {
9467 file_table_allocated += FILE_TABLE_INCREMENT;
9468 file_table
71dfc51f
RK
9469 = (char **) xrealloc (file_table,
9470 file_table_allocated * sizeof (char *));
a3f97cbb
JW
9471 }
9472
71dfc51f 9473 /* Add the new entry to the end of the filename table. */
a3f97cbb
JW
9474 file_table[file_table_in_use] = xstrdup (file_name);
9475 last_file_lookup_index = file_table_in_use++;
71dfc51f 9476
a3f97cbb
JW
9477 return last_file_lookup_index;
9478}
9479
9480/* Output a label to mark the beginning of a source code line entry
9481 and record information relating to this source line, in
9482 'line_info_table' for later output of the .debug_line section. */
71dfc51f 9483
a3f97cbb 9484void
9a666dda 9485dwarf2out_line (filename, line)
a3f97cbb
JW
9486 register char *filename;
9487 register unsigned line;
9488{
a3f97cbb
JW
9489 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9490 {
9491 function_section (current_function_decl);
a3f97cbb 9492
e90b62db 9493 if (DECL_SECTION_NAME (current_function_decl))
a3f97cbb 9494 {
e90b62db 9495 register dw_separate_line_info_ref line_info;
5c90448c
JM
9496 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9497 separate_line_info_table_in_use);
e90b62db
JM
9498 fputc ('\n', asm_out_file);
9499
9500 /* expand the line info table if necessary */
9501 if (separate_line_info_table_in_use
9502 == separate_line_info_table_allocated)
9503 {
9504 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9505 separate_line_info_table
71dfc51f
RK
9506 = (dw_separate_line_info_ref)
9507 xrealloc (separate_line_info_table,
9508 separate_line_info_table_allocated
9509 * sizeof (dw_separate_line_info_entry));
e90b62db 9510 }
71dfc51f
RK
9511
9512 /* Add the new entry at the end of the line_info_table. */
e90b62db
JM
9513 line_info
9514 = &separate_line_info_table[separate_line_info_table_in_use++];
9515 line_info->dw_file_num = lookup_filename (filename);
9516 line_info->dw_line_num = line;
9517 line_info->function = current_funcdef_number;
9518 }
9519 else
9520 {
9521 register dw_line_info_ref line_info;
71dfc51f 9522
5c90448c
JM
9523 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9524 line_info_table_in_use);
e90b62db
JM
9525 fputc ('\n', asm_out_file);
9526
71dfc51f 9527 /* Expand the line info table if necessary. */
e90b62db
JM
9528 if (line_info_table_in_use == line_info_table_allocated)
9529 {
9530 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9531 line_info_table
71dfc51f
RK
9532 = (dw_line_info_ref)
9533 xrealloc (line_info_table,
9534 (line_info_table_allocated
9535 * sizeof (dw_line_info_entry)));
e90b62db 9536 }
71dfc51f
RK
9537
9538 /* Add the new entry at the end of the line_info_table. */
e90b62db
JM
9539 line_info = &line_info_table[line_info_table_in_use++];
9540 line_info->dw_file_num = lookup_filename (filename);
9541 line_info->dw_line_num = line;
a3f97cbb 9542 }
a3f97cbb
JW
9543 }
9544}
9545
9546/* Record the beginning of a new source file, for later output
9547 of the .debug_macinfo section. At present, unimplemented. */
71dfc51f 9548
a3f97cbb 9549void
9a666dda 9550dwarf2out_start_source_file (filename)
a3f97cbb
JW
9551 register char *filename;
9552{
9553}
9554
9a666dda 9555/* Record the end of a source file, for later output
a3f97cbb 9556 of the .debug_macinfo section. At present, unimplemented. */
71dfc51f 9557
a3f97cbb 9558void
9a666dda 9559dwarf2out_end_source_file ()
a3f97cbb
JW
9560{
9561}
9562
9563/* Called from check_newline in c-parse.y. The `buffer' parameter contains
9564 the tail part of the directive line, i.e. the part which is past the
9565 initial whitespace, #, whitespace, directive-name, whitespace part. */
71dfc51f 9566
a3f97cbb 9567void
9a666dda 9568dwarf2out_define (lineno, buffer)
a3f97cbb
JW
9569 register unsigned lineno;
9570 register char *buffer;
9571{
9572 static int initialized = 0;
9573 if (!initialized)
9574 {
9a666dda 9575 dwarf2out_start_source_file (primary_filename);
a3f97cbb
JW
9576 initialized = 1;
9577 }
9578}
9579
9580/* Called from check_newline in c-parse.y. The `buffer' parameter contains
9581 the tail part of the directive line, i.e. the part which is past the
9582 initial whitespace, #, whitespace, directive-name, whitespace part. */
71dfc51f 9583
a3f97cbb 9584void
9a666dda 9585dwarf2out_undef (lineno, buffer)
a3f97cbb
JW
9586 register unsigned lineno;
9587 register char *buffer;
9588{
9589}
9590
9591/* Set up for Dwarf output at the start of compilation. */
71dfc51f 9592
a3f97cbb 9593void
9a666dda 9594dwarf2out_init (asm_out_file, main_input_filename)
a3f97cbb
JW
9595 register FILE *asm_out_file;
9596 register char *main_input_filename;
9597{
a3f97cbb
JW
9598 /* Remember the name of the primary input file. */
9599 primary_filename = main_input_filename;
9600
9601 /* Allocate the initial hunk of the file_table. */
9602 file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
b1ccbc24 9603 bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *));
a3f97cbb 9604 file_table_allocated = FILE_TABLE_INCREMENT;
71dfc51f
RK
9605
9606 /* Skip the first entry - file numbers begin at 1. */
a3f97cbb
JW
9607 file_table_in_use = 1;
9608
a3f97cbb
JW
9609 /* Allocate the initial hunk of the decl_die_table. */
9610 decl_die_table
9611 = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
b1ccbc24
RK
9612 bzero ((char *) decl_die_table,
9613 DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
a3f97cbb
JW
9614 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9615 decl_die_table_in_use = 0;
9616
9617 /* Allocate the initial hunk of the decl_scope_table. */
9618 decl_scope_table
9619 = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
b1ccbc24
RK
9620 bzero ((char *) decl_scope_table,
9621 DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
a3f97cbb
JW
9622 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9623 decl_scope_depth = 0;
9624
9625 /* Allocate the initial hunk of the abbrev_die_table. */
9626 abbrev_die_table
9627 = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
9628 * sizeof (dw_die_ref));
b1ccbc24
RK
9629 bzero ((char *) abbrev_die_table,
9630 ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
a3f97cbb 9631 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
71dfc51f 9632 /* Zero-th entry is allocated, but unused */
a3f97cbb
JW
9633 abbrev_die_table_in_use = 1;
9634
9635 /* Allocate the initial hunk of the line_info_table. */
9636 line_info_table
9637 = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
9638 * sizeof (dw_line_info_entry));
b1ccbc24
RK
9639 bzero ((char *) line_info_table,
9640 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
a3f97cbb 9641 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
71dfc51f 9642 /* Zero-th entry is allocated, but unused */
a3f97cbb
JW
9643 line_info_table_in_use = 1;
9644
a3f97cbb
JW
9645 /* Generate the initial DIE for the .debug section. Note that the (string)
9646 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9647 will (typically) be a relative pathname and that this pathname should be
9648 taken as being relative to the directory from which the compiler was
9649 invoked when the given (base) source file was compiled. */
9650 gen_compile_unit_die (main_input_filename);
9651
5c90448c 9652 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
a3f97cbb
JW
9653}
9654
9655/* Output stuff that dwarf requires at the end of every file,
9656 and generate the DWARF-2 debugging info. */
71dfc51f 9657
a3f97cbb 9658void
9a666dda 9659dwarf2out_finish ()
a3f97cbb 9660{
ef76d03b
JW
9661 limbo_die_node *node, *next_node;
9662 dw_die_ref die;
9663 dw_attr_ref a;
9664
9665 /* Traverse the limbo die list, and add parent/child links. The only
9666 dies without parents that should be here are concrete instances of
9667 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9668 For concrete instances, we can get the parent die from the abstract
9669 instance. */
9670 for (node = limbo_die_list; node; node = next_node)
9671 {
9672 next_node = node->next;
9673 die = node->die;
9674
9675 if (die->die_parent == NULL)
9676 {
9677 a = get_AT (die, DW_AT_abstract_origin);
9678 if (a)
9679 add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die);
9680 else if (die == comp_unit_die)
9681 ;
9682 else
9683 abort ();
9684 }
9685 free (node);
9686 }
9687
a3f97cbb
JW
9688 /* Traverse the DIE tree and add sibling attributes to those DIE's
9689 that have children. */
9690 add_sibling_attributes (comp_unit_die);
9691
9692 /* Output a terminator label for the .text section. */
9693 fputc ('\n', asm_out_file);
9694 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
5c90448c 9695 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
a3f97cbb 9696
bdb669cb 9697#if 0
a3f97cbb
JW
9698 /* Output a terminator label for the .data section. */
9699 fputc ('\n', asm_out_file);
9700 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
5c90448c 9701 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
a3f97cbb
JW
9702
9703 /* Output a terminator label for the .bss section. */
9704 fputc ('\n', asm_out_file);
9705 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
5c90448c 9706 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
bdb669cb 9707#endif
a3f97cbb 9708
e90b62db
JM
9709 /* Output the source line correspondence table. */
9710 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9711 {
9712 fputc ('\n', asm_out_file);
c53aa195 9713 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
e90b62db
JM
9714 output_line_info ();
9715
9716 /* We can only use the low/high_pc attributes if all of the code
9717 was in .text. */
9718 if (separate_line_info_table_in_use == 0)
9719 {
9720 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
5c90448c 9721 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
e90b62db 9722 }
71dfc51f 9723
c53aa195 9724 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, DEBUG_LINE_SECTION);
e90b62db
JM
9725 }
9726
a3f97cbb
JW
9727 /* Output the abbreviation table. */
9728 fputc ('\n', asm_out_file);
9729 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9730 build_abbrev_table (comp_unit_die);
9731 output_abbrev_section ();
9732
a3f97cbb
JW
9733 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9734 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9735 calc_die_sizes (comp_unit_die);
9736
a3f97cbb
JW
9737 /* Output debugging information. */
9738 fputc ('\n', asm_out_file);
c53aa195 9739 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
a3f97cbb
JW
9740 output_compilation_unit_header ();
9741 output_die (comp_unit_die);
9742
d291dd49
JM
9743 if (pubname_table_in_use)
9744 {
9745 /* Output public names table. */
9746 fputc ('\n', asm_out_file);
9747 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9748 output_pubnames ();
9749 }
9750
a3f97cbb
JW
9751 if (fde_table_in_use)
9752 {
a3f97cbb
JW
9753 /* Output the address range information. */
9754 fputc ('\n', asm_out_file);
9755 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
9756 output_aranges ();
9757 }
9758}
9a666dda 9759#endif /* DWARF2_DEBUGGING_INFO */