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