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