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