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