118334Speter/* Output dbx-format symbol table information from GNU compiler.
290085Sobrien   Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3169699Skan   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
4169699Skan   Free Software Foundation, Inc.
518334Speter
690085SobrienThis file is part of GCC.
718334Speter
890085SobrienGCC is free software; you can redistribute it and/or modify it under
990085Sobrienthe terms of the GNU General Public License as published by the Free
1090085SobrienSoftware Foundation; either version 2, or (at your option) any later
1190085Sobrienversion.
1218334Speter
1390085SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1490085SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or
1590085SobrienFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1690085Sobrienfor more details.
1718334Speter
1818334SpeterYou should have received a copy of the GNU General Public License
1990085Sobrienalong with GCC; see the file COPYING.  If not, write to the Free
20169699SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21169699Skan02110-1301, USA.  */
2218334Speter
2318334Speter
2418334Speter/* Output dbx-format symbol table data.
2518334Speter   This consists of many symbol table entries, each of them
2618334Speter   a .stabs assembler pseudo-op with four operands:
2718334Speter   a "name" which is really a description of one symbol and its type,
2818334Speter   a "code", which is a symbol defined in stab.h whose name starts with N_,
2918334Speter   an unused operand always 0,
3018334Speter   and a "value" which is an address or an offset.
3118334Speter   The name is enclosed in doublequote characters.
3218334Speter
3318334Speter   Each function, variable, typedef, and structure tag
3418334Speter   has a symbol table entry to define it.
3518334Speter   The beginning and end of each level of name scoping within
3618334Speter   a function are also marked by special symbol table entries.
3718334Speter
3818334Speter   The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
3918334Speter   and a data type number.  The data type number may be followed by
4018334Speter   "=" and a type definition; normally this will happen the first time
4118334Speter   the type number is mentioned.  The type definition may refer to
4218334Speter   other types by number, and those type numbers may be followed
4318334Speter   by "=" and nested definitions.
4418334Speter
4518334Speter   This can make the "name" quite long.
4618334Speter   When a name is more than 80 characters, we split the .stabs pseudo-op
4718334Speter   into two .stabs pseudo-ops, both sharing the same "code" and "value".
4818334Speter   The first one is marked as continued with a double-backslash at the
4918334Speter   end of its "name".
5018334Speter
5118334Speter   The kind-of-symbol letter distinguished function names from global
5218334Speter   variables from file-scope variables from parameters from auto
5318334Speter   variables in memory from typedef names from register variables.
5418334Speter   See `dbxout_symbol'.
5518334Speter
5618334Speter   The "code" is mostly redundant with the kind-of-symbol letter
5718334Speter   that goes in the "name", but not entirely: for symbols located
5818334Speter   in static storage, the "code" says which segment the address is in,
5918334Speter   which controls how it is relocated.
6018334Speter
6118334Speter   The "value" for a symbol in static storage
6218334Speter   is the core address of the symbol (actually, the assembler
6318334Speter   label for the symbol).  For a symbol located in a stack slot
6418334Speter   it is the stack offset; for one in a register, the register number.
6518334Speter   For a typedef symbol, it is zero.
6618334Speter
6718334Speter   If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
6818334Speter   output while in the text section.
6918334Speter
7018334Speter   For more on data type definitions, see `dbxout_type'.  */
7118334Speter
7250495Sobrien#include "config.h"
7350495Sobrien#include "system.h"
74132727Skan#include "coretypes.h"
75132727Skan#include "tm.h"
7618334Speter
7718334Speter#include "tree.h"
7818334Speter#include "rtl.h"
7918334Speter#include "flags.h"
8018334Speter#include "regs.h"
8118334Speter#include "insn-config.h"
8218334Speter#include "reload.h"
83169699Skan#include "output.h"
8450495Sobrien#include "dbxout.h"
8550495Sobrien#include "toplev.h"
8690085Sobrien#include "tm_p.h"
8790085Sobrien#include "ggc.h"
8890085Sobrien#include "debug.h"
8990085Sobrien#include "function.h"
9090085Sobrien#include "target.h"
9190085Sobrien#include "langhooks.h"
92169699Skan#include "obstack.h"
93169699Skan#include "expr.h"
9418334Speter
9518334Speter#ifdef XCOFF_DEBUGGING_INFO
9618334Speter#include "xcoffout.h"
9718334Speter#endif
9818334Speter
99132727Skan#define DBXOUT_DECR_NESTING \
100132727Skan  if (--debug_nesting == 0 && symbol_queue_index > 0) \
101132727Skan    { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
102132727Skan
103132727Skan#define DBXOUT_DECR_NESTING_AND_RETURN(x) \
104132727Skan  do {--debug_nesting; return (x);} while (0)
105132727Skan
10618334Speter#ifndef ASM_STABS_OP
107169699Skan# ifdef XCOFF_DEBUGGING_INFO
108169699Skan#  define ASM_STABS_OP "\t.stabx\t"
109169699Skan# else
110169699Skan#  define ASM_STABS_OP "\t.stabs\t"
111169699Skan# endif
11218334Speter#endif
11318334Speter
11418334Speter#ifndef ASM_STABN_OP
11590085Sobrien#define ASM_STABN_OP "\t.stabn\t"
11618334Speter#endif
11718334Speter
118169699Skan#ifndef ASM_STABD_OP
119169699Skan#define ASM_STABD_OP "\t.stabd\t"
120169699Skan#endif
121169699Skan
12218334Speter#ifndef DBX_TYPE_DECL_STABS_CODE
12318334Speter#define DBX_TYPE_DECL_STABS_CODE N_LSYM
12418334Speter#endif
12518334Speter
12618334Speter#ifndef DBX_STATIC_CONST_VAR_CODE
12718334Speter#define DBX_STATIC_CONST_VAR_CODE N_FUN
12818334Speter#endif
12918334Speter
13018334Speter#ifndef DBX_REGPARM_STABS_CODE
13118334Speter#define DBX_REGPARM_STABS_CODE N_RSYM
13218334Speter#endif
13318334Speter
13418334Speter#ifndef DBX_REGPARM_STABS_LETTER
13518334Speter#define DBX_REGPARM_STABS_LETTER 'P'
13618334Speter#endif
13718334Speter
138169699Skan#ifndef NO_DBX_FUNCTION_END
139169699Skan#define NO_DBX_FUNCTION_END 0
14018334Speter#endif
14118334Speter
142169699Skan#ifndef NO_DBX_BNSYM_ENSYM
143169699Skan#define NO_DBX_BNSYM_ENSYM 0
14418334Speter#endif
14518334Speter
146169699Skan#ifndef NO_DBX_MAIN_SOURCE_DIRECTORY
147169699Skan#define NO_DBX_MAIN_SOURCE_DIRECTORY 0
14818334Speter#endif
14918334Speter
150169699Skan#ifndef DBX_BLOCKS_FUNCTION_RELATIVE
151169699Skan#define DBX_BLOCKS_FUNCTION_RELATIVE 0
15250495Sobrien#endif
15350495Sobrien
154169699Skan#ifndef DBX_LINES_FUNCTION_RELATIVE
155169699Skan#define DBX_LINES_FUNCTION_RELATIVE 0
156169699Skan#endif
157169699Skan
158169699Skan#ifndef DBX_CONTIN_LENGTH
159169699Skan#define DBX_CONTIN_LENGTH 80
160169699Skan#endif
161169699Skan
162169699Skan#ifndef DBX_CONTIN_CHAR
163169699Skan#define DBX_CONTIN_CHAR '\\'
164169699Skan#endif
165169699Skan
16618334Speterenum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
16718334Speter
16850495Sobrien/* Structure recording information about a C data type.
16950495Sobrien   The status element says whether we have yet output
17050495Sobrien   the definition of the type.  TYPE_XREF says we have
17150495Sobrien   output it as a cross-reference only.
17250495Sobrien   The file_number and type_number elements are used if DBX_USE_BINCL
17350495Sobrien   is defined.  */
17450495Sobrien
175132727Skanstruct typeinfo GTY(())
17650495Sobrien{
17750495Sobrien  enum typestatus status;
17850495Sobrien  int file_number;
17950495Sobrien  int type_number;
18050495Sobrien};
18150495Sobrien
18250495Sobrien/* Vector recording information about C data types.
18318334Speter   When we first notice a data type (a tree node),
18418334Speter   we assign it a number using next_type_number.
18550495Sobrien   That is its index in this vector.  */
18618334Speter
187132727Skanstatic GTY ((length ("typevec_len"))) struct typeinfo *typevec;
18818334Speter
18918334Speter/* Number of elements of space allocated in `typevec'.  */
19018334Speter
191132727Skanstatic GTY(()) int typevec_len;
19218334Speter
19318334Speter/* In dbx output, each type gets a unique number.
19418334Speter   This is the number for the next type output.
19518334Speter   The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field.  */
19618334Speter
197132727Skanstatic GTY(()) int next_type_number;
19818334Speter
199169699Skan/* The C front end may call dbxout_symbol before dbxout_init runs.
200169699Skan   We save all such decls in this list and output them when we get
201169699Skan   to dbxout_init.  */
202169699Skan
203169699Skanstatic GTY(()) tree preinit_symbols;
204169699Skan
205132727Skanenum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
20650495Sobrien
20750495Sobrien/* When using N_BINCL in dbx output, each type number is actually a
20850495Sobrien   pair of the file number and the type number within the file.
20950495Sobrien   This is a stack of input files.  */
21050495Sobrien
21150495Sobrienstruct dbx_file
21250495Sobrien{
21350495Sobrien  struct dbx_file *next;
21450495Sobrien  int file_number;
21550495Sobrien  int next_type_number;
216132727Skan  enum binclstatus bincl_status;  /* Keep track of lazy bincl.  */
217132727Skan  const char *pending_bincl_name; /* Name of bincl.  */
218132727Skan  struct dbx_file *prev;          /* Chain to traverse all pending bincls.  */
21950495Sobrien};
22050495Sobrien
221132727Skan/* This is the top of the stack.
222132727Skan
223132727Skan   This is not saved for PCH, because restoring a PCH should not change it.
224132727Skan   next_file_number does have to be saved, because the PCH may use some
225132727Skan   file numbers; however, just before restoring a PCH, next_file_number
226132727Skan   should always be 0 because we should not have needed any file numbers
227132727Skan   yet.  */
22850495Sobrien
229132727Skan#if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
230132727Skan    && defined (DBX_USE_BINCL)
23150495Sobrienstatic struct dbx_file *current_file;
232132727Skan#endif
23350495Sobrien
23450495Sobrien/* This is the next file number to use.  */
23550495Sobrien
236132727Skanstatic GTY(()) int next_file_number;
23750495Sobrien
238132727Skan/* A counter for dbxout_function_end.  */
23950495Sobrien
240132727Skanstatic GTY(()) int scope_labelno;
241132727Skan
242132727Skan/* A counter for dbxout_source_line.  */
243132727Skan
244132727Skanstatic GTY(()) int dbxout_source_line_counter;
245132727Skan
246132727Skan/* Number for the next N_SOL filename stabs label.  The number 0 is reserved
247132727Skan   for the N_SO filename stabs label.  */
248132727Skan
249132727Skanstatic GTY(()) int source_label_number = 1;
250132727Skan
251132727Skan/* Last source file name mentioned in a NOTE insn.  */
252132727Skan
253132727Skanstatic GTY(()) const char *lastfile;
254132727Skan
255132727Skan/* Used by PCH machinery to detect if 'lastfile' should be reset to
256132727Skan   base_input_file.  */
257132727Skanstatic GTY(()) int lastfile_is_base;
258132727Skan
259132727Skan/* Typical USG systems don't have stab.h, and they also have
260132727Skan   no use for DBX-format debugging info.  */
261132727Skan
262132727Skan#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
263132727Skan
264132727Skan#ifdef DBX_USE_BINCL
265132727Skan/* If zero then there is no pending BINCL.  */
266132727Skanstatic int pending_bincls = 0;
267132727Skan#endif
268132727Skan
269132727Skan/* The original input file name.  */
270132727Skanstatic const char *base_input_file;
271132727Skan
272132727Skan#ifdef DEBUG_SYMS_TEXT
273169699Skan#define FORCE_TEXT switch_to_section (current_function_section ())
274132727Skan#else
275132727Skan#define FORCE_TEXT
276132727Skan#endif
277132727Skan
278132727Skan#include "gstab.h"
279132727Skan
280132727Skan#define STAB_CODE_TYPE enum __stab_debug_code
281132727Skan
282132727Skan/* 1 if PARM is passed to this function in memory.  */
283132727Skan
284132727Skan#define PARM_PASSED_IN_MEMORY(PARM) \
285169699Skan (MEM_P (DECL_INCOMING_RTL (PARM)))
286132727Skan
287132727Skan/* A C expression for the integer offset value of an automatic variable
288132727Skan   (N_LSYM) having address X (an RTX).  */
289132727Skan#ifndef DEBUGGER_AUTO_OFFSET
290132727Skan#define DEBUGGER_AUTO_OFFSET(X) \
291132727Skan  (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
292132727Skan#endif
293132727Skan
294132727Skan/* A C expression for the integer offset value of an argument (N_PSYM)
295132727Skan   having address X (an RTX).  The nominal offset is OFFSET.  */
296132727Skan#ifndef DEBUGGER_ARG_OFFSET
297132727Skan#define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
298132727Skan#endif
299132727Skan
300169699Skan/* This obstack holds the stab string currently being constructed.  We
301169699Skan   build it up here, then write it out, so we can split long lines up
302169699Skan   properly (see dbxout_finish_complex_stabs).  */
303169699Skanstatic struct obstack stabstr_ob;
304169699Skanstatic size_t stabstr_last_contin_point;
305132727Skan
306132727Skan#ifdef DBX_USE_BINCL
307132727Skanstatic void emit_bincl_stab             (const char *c);
308132727Skanstatic void emit_pending_bincls         (void);
309132727Skan#endif
310132727Skanstatic inline void emit_pending_bincls_if_required (void);
311132727Skan
312132727Skanstatic void dbxout_init (const char *);
313169699Skan
314132727Skanstatic void dbxout_finish (const char *);
315132727Skanstatic void dbxout_start_source_file (unsigned, const char *);
316132727Skanstatic void dbxout_end_source_file (unsigned);
317132727Skanstatic void dbxout_typedefs (tree);
318132727Skanstatic void dbxout_type_index (tree);
319132727Skanstatic void dbxout_args (tree);
320132727Skanstatic void dbxout_type_fields (tree);
321169699Skanstatic void dbxout_type_method_1 (tree);
322132727Skanstatic void dbxout_type_methods (tree);
323132727Skanstatic void dbxout_range_type (tree);
324132727Skanstatic void dbxout_type (tree, int);
325132727Skanstatic bool print_int_cst_bounds_in_octal_p (tree);
326132727Skanstatic void dbxout_type_name (tree);
327132727Skanstatic void dbxout_class_name_qualifiers (tree);
328132727Skanstatic int dbxout_symbol_location (tree, tree, const char *, rtx);
329132727Skanstatic void dbxout_symbol_name (tree, const char *, int);
330132727Skanstatic void dbxout_block (tree, int, tree);
331132727Skanstatic void dbxout_global_decl (tree);
332169699Skanstatic void dbxout_type_decl (tree, int);
333132727Skanstatic void dbxout_handle_pch (unsigned);
33418334Speter
33590085Sobrien/* The debug hooks structure.  */
33690085Sobrien#if defined (DBX_DEBUGGING_INFO)
33790085Sobrien
338132727Skanstatic void dbxout_source_line (unsigned int, const char *);
339169699Skanstatic void dbxout_begin_prologue (unsigned int, const char *);
340169699Skanstatic void dbxout_source_file (const char *);
341169699Skanstatic void dbxout_function_end (tree);
342132727Skanstatic void dbxout_begin_function (tree);
343132727Skanstatic void dbxout_begin_block (unsigned, unsigned);
344132727Skanstatic void dbxout_end_block (unsigned, unsigned);
345132727Skanstatic void dbxout_function_decl (tree);
34690085Sobrien
347117404Skanconst struct gcc_debug_hooks dbx_debug_hooks =
34890085Sobrien{
34990085Sobrien  dbxout_init,
35090085Sobrien  dbxout_finish,
35190085Sobrien  debug_nothing_int_charstar,
35290085Sobrien  debug_nothing_int_charstar,
35390085Sobrien  dbxout_start_source_file,
35490085Sobrien  dbxout_end_source_file,
35590085Sobrien  dbxout_begin_block,
35690085Sobrien  dbxout_end_block,
357169699Skan  debug_true_tree,		         /* ignore_block */
358169699Skan  dbxout_source_line,		         /* source_line */
359169699Skan  dbxout_begin_prologue,	         /* begin_prologue */
360169699Skan  debug_nothing_int_charstar,	         /* end_prologue */
361169699Skan  debug_nothing_int_charstar,	         /* end_epilogue */
36290085Sobrien#ifdef DBX_FUNCTION_FIRST
36390085Sobrien  dbxout_begin_function,
36490085Sobrien#else
365169699Skan  debug_nothing_tree,		         /* begin_function */
36690085Sobrien#endif
367169699Skan  debug_nothing_int,		         /* end_function */
36890085Sobrien  dbxout_function_decl,
369169699Skan  dbxout_global_decl,		         /* global_decl */
370169699Skan  dbxout_type_decl,			 /* type_decl */
371169699Skan  debug_nothing_tree_tree,               /* imported_module_or_decl */
372169699Skan  debug_nothing_tree,		         /* deferred_inline_function */
373169699Skan  debug_nothing_tree,		         /* outlining_inline_function */
374169699Skan  debug_nothing_rtx,		         /* label */
375169699Skan  dbxout_handle_pch,		         /* handle_pch */
376169699Skan  debug_nothing_rtx,		         /* var_location */
377169699Skan  debug_nothing_void,                    /* switch_text_section */
378169699Skan  0                                      /* start_end_main_source_file */
37990085Sobrien};
38090085Sobrien#endif /* DBX_DEBUGGING_INFO  */
38190085Sobrien
38290085Sobrien#if defined (XCOFF_DEBUGGING_INFO)
383117404Skanconst struct gcc_debug_hooks xcoff_debug_hooks =
38490085Sobrien{
38590085Sobrien  dbxout_init,
38690085Sobrien  dbxout_finish,
38790085Sobrien  debug_nothing_int_charstar,
38890085Sobrien  debug_nothing_int_charstar,
38990085Sobrien  dbxout_start_source_file,
39090085Sobrien  dbxout_end_source_file,
39190085Sobrien  xcoffout_begin_block,
39290085Sobrien  xcoffout_end_block,
393169699Skan  debug_true_tree,		         /* ignore_block */
39490085Sobrien  xcoffout_source_line,
395169699Skan  xcoffout_begin_prologue,	         /* begin_prologue */
396169699Skan  debug_nothing_int_charstar,	         /* end_prologue */
39790085Sobrien  xcoffout_end_epilogue,
398169699Skan  debug_nothing_tree,		         /* begin_function */
39990085Sobrien  xcoffout_end_function,
400169699Skan  debug_nothing_tree,		         /* function_decl */
401169699Skan  dbxout_global_decl,		         /* global_decl */
402169699Skan  dbxout_type_decl,			 /* type_decl */
403169699Skan  debug_nothing_tree_tree,               /* imported_module_or_decl */
404169699Skan  debug_nothing_tree,		         /* deferred_inline_function */
405169699Skan  debug_nothing_tree,		         /* outlining_inline_function */
406169699Skan  debug_nothing_rtx,		         /* label */
407169699Skan  dbxout_handle_pch,		         /* handle_pch */
408169699Skan  debug_nothing_rtx,		         /* var_location */
409169699Skan  debug_nothing_void,                    /* switch_text_section */
410169699Skan  0                                      /* start_end_main_source_file */
41190085Sobrien};
41290085Sobrien#endif /* XCOFF_DEBUGGING_INFO  */
41390085Sobrien
414169699Skan/* Numeric formatting helper macro.  Note that this does not handle
415169699Skan   hexadecimal.  */
416169699Skan#define NUMBER_FMT_LOOP(P, NUM, BASE)		\
417169699Skan  do						\
418169699Skan    {						\
419169699Skan      int digit = NUM % BASE;			\
420169699Skan      NUM /= BASE;				\
421169699Skan      *--P = digit + '0';			\
422169699Skan    }						\
423169699Skan  while (NUM > 0)
424169699Skan
425169699Skan/* Utility: write a decimal integer NUM to asm_out_file.  */
426169699Skanvoid
427169699Skandbxout_int (int num)
428169699Skan{
429169699Skan  char buf[64];
430169699Skan  char *p = buf + sizeof buf;
431169699Skan  unsigned int unum;
432169699Skan
433169699Skan  if (num == 0)
434169699Skan    {
435169699Skan      putc ('0', asm_out_file);
436169699Skan      return;
437169699Skan    }
438169699Skan  if (num < 0)
439169699Skan    {
440169699Skan      putc ('-', asm_out_file);
441169699Skan      unum = -num;
442169699Skan    }
443169699Skan  else
444169699Skan    unum = num;
445169699Skan
446169699Skan  NUMBER_FMT_LOOP (p, unum, 10);
447169699Skan
448169699Skan  while (p < buf + sizeof buf)
449169699Skan    {
450169699Skan      putc (*p, asm_out_file);
451169699Skan      p++;
452169699Skan    }
453169699Skan}
454169699Skan
455169699Skan
456169699Skan/* Primitives for emitting simple stabs directives.  All other stabs
457169699Skan   routines should use these functions instead of directly emitting
458169699Skan   stabs.  They are exported because machine-dependent code may need
459169699Skan   to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition
460169699Skan   forwards to code in CPU.c.  */
461169699Skan
462169699Skan/* The following functions should all be called immediately after one
463169699Skan   of the dbxout_begin_stab* functions (below).  They write out
464169699Skan   various things as the value of a stab.  */
465169699Skan
466169699Skan/* Write out a literal zero as the value of a stab.  */
467169699Skanvoid
468169699Skandbxout_stab_value_zero (void)
469169699Skan{
470169699Skan  fputs ("0\n", asm_out_file);
471169699Skan}
472169699Skan
473169699Skan/* Write out the label LABEL as the value of a stab.  */
474169699Skanvoid
475169699Skandbxout_stab_value_label (const char *label)
476169699Skan{
477169699Skan  assemble_name (asm_out_file, label);
478169699Skan  putc ('\n', asm_out_file);
479169699Skan}
480169699Skan
481169699Skan/* Write out the difference of two labels, LABEL - BASE, as the value
482169699Skan   of a stab.  */
483169699Skanvoid
484169699Skandbxout_stab_value_label_diff (const char *label, const char *base)
485169699Skan{
486169699Skan  assemble_name (asm_out_file, label);
487169699Skan  putc ('-', asm_out_file);
488169699Skan  assemble_name (asm_out_file, base);
489169699Skan  putc ('\n', asm_out_file);
490169699Skan}
491169699Skan
492169699Skan/* Write out an internal label as the value of a stab, and immediately
493169699Skan   emit that internal label.  This should be used only when
494169699Skan   dbxout_stabd will not work.  STEM is the name stem of the label,
495169699Skan   COUNTERP is a pointer to a counter variable which will be used to
496169699Skan   guarantee label uniqueness.  */
497169699Skanvoid
498169699Skandbxout_stab_value_internal_label (const char *stem, int *counterp)
499169699Skan{
500169699Skan  char label[100];
501169699Skan  int counter = counterp ? (*counterp)++ : 0;
502169699Skan
503169699Skan  ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
504169699Skan  dbxout_stab_value_label (label);
505169699Skan  targetm.asm_out.internal_label (asm_out_file, stem, counter);
506169699Skan}
507169699Skan
508169699Skan/* Write out the difference between BASE and an internal label as the
509169699Skan   value of a stab, and immediately emit that internal label.  STEM and
510169699Skan   COUNTERP are as for dbxout_stab_value_internal_label.  */
511169699Skanvoid
512169699Skandbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
513169699Skan				       const char *base)
514169699Skan{
515169699Skan  char label[100];
516169699Skan  int counter = counterp ? (*counterp)++ : 0;
517169699Skan
518169699Skan  ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
519169699Skan  dbxout_stab_value_label_diff (label, base);
520169699Skan  targetm.asm_out.internal_label (asm_out_file, stem, counter);
521169699Skan}
522169699Skan
523169699Skan/* The following functions produce specific kinds of stab directives.  */
524169699Skan
525169699Skan/* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file.  */
526169699Skanvoid
527169699Skandbxout_stabd (int stype, int sdesc)
528169699Skan{
529169699Skan  fputs (ASM_STABD_OP, asm_out_file);
530169699Skan  dbxout_int (stype);
531169699Skan  fputs (",0,", asm_out_file);
532169699Skan  dbxout_int (sdesc);
533169699Skan  putc ('\n', asm_out_file);
534169699Skan}
535169699Skan
536169699Skan/* Write a .stabn directive with type STYPE.  This function stops
537169699Skan   short of emitting the value field, which is the responsibility of
538169699Skan   the caller (normally it will be either a symbol or the difference
539169699Skan   of two symbols).  */
540169699Skan
541169699Skanvoid
542169699Skandbxout_begin_stabn (int stype)
543169699Skan{
544169699Skan  fputs (ASM_STABN_OP, asm_out_file);
545169699Skan  dbxout_int (stype);
546169699Skan  fputs (",0,0,", asm_out_file);
547169699Skan}
548169699Skan
549169699Skan/* Write a .stabn directive with type N_SLINE and desc LINE.  As above,
550169699Skan   the value field is the responsibility of the caller.  */
551169699Skanvoid
552169699Skandbxout_begin_stabn_sline (int lineno)
553169699Skan{
554169699Skan  fputs (ASM_STABN_OP, asm_out_file);
555169699Skan  dbxout_int (N_SLINE);
556169699Skan  fputs (",0,", asm_out_file);
557169699Skan  dbxout_int (lineno);
558169699Skan  putc (',', asm_out_file);
559169699Skan}
560169699Skan
561169699Skan/* Begin a .stabs directive with string "", type STYPE, and desc and
562169699Skan   other fields 0.  The value field is the responsibility of the
563169699Skan   caller.  This function cannot be used for .stabx directives.  */
564169699Skanvoid
565169699Skandbxout_begin_empty_stabs (int stype)
566169699Skan{
567169699Skan  fputs (ASM_STABS_OP, asm_out_file);
568169699Skan  fputs ("\"\",", asm_out_file);
569169699Skan  dbxout_int (stype);
570169699Skan  fputs (",0,0,", asm_out_file);
571169699Skan}
572169699Skan
573169699Skan/* Begin a .stabs directive with string STR, type STYPE, and desc 0.
574169699Skan   The value field is the responsibility of the caller.  */
575169699Skanvoid
576169699Skandbxout_begin_simple_stabs (const char *str, int stype)
577169699Skan{
578169699Skan  fputs (ASM_STABS_OP, asm_out_file);
579169699Skan  output_quoted_string (asm_out_file, str);
580169699Skan  putc (',', asm_out_file);
581169699Skan  dbxout_int (stype);
582169699Skan  fputs (",0,0,", asm_out_file);
583169699Skan}
584169699Skan
585169699Skan/* As above but use SDESC for the desc field.  */
586169699Skanvoid
587169699Skandbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc)
588169699Skan{
589169699Skan  fputs (ASM_STABS_OP, asm_out_file);
590169699Skan  output_quoted_string (asm_out_file, str);
591169699Skan  putc (',', asm_out_file);
592169699Skan  dbxout_int (stype);
593169699Skan  fputs (",0,", asm_out_file);
594169699Skan  dbxout_int (sdesc);
595169699Skan  putc (',', asm_out_file);
596169699Skan}
597169699Skan
598169699Skan/* The next set of functions are entirely concerned with production of
599169699Skan   "complex" .stabs directives: that is, .stabs directives whose
600169699Skan   strings have to be constructed piecemeal.  dbxout_type,
601169699Skan   dbxout_symbol, etc. use these routines heavily.  The string is queued
602169699Skan   up in an obstack, then written out by dbxout_finish_complex_stabs, which
603169699Skan   is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH.
604169699Skan   (You might think it would be more efficient to go straight to stdio
605169699Skan   when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns
606169699Skan   out not to be the case, and anyway this needs fewer #ifdefs.)  */
607169699Skan
608169699Skan/* Begin a complex .stabs directive.  If we can, write the initial
609169699Skan   ASM_STABS_OP to the asm_out_file.  */
610169699Skan
611169699Skanstatic void
612169699Skandbxout_begin_complex_stabs (void)
613169699Skan{
614169699Skan  emit_pending_bincls_if_required ();
615169699Skan  FORCE_TEXT;
616169699Skan  fputs (ASM_STABS_OP, asm_out_file);
617169699Skan  putc ('"', asm_out_file);
618169699Skan  gcc_assert (stabstr_last_contin_point == 0);
619169699Skan}
620169699Skan
621169699Skan/* As above, but do not force text or emit pending bincls.  This is
622169699Skan   used by dbxout_symbol_location, which needs to do something else.  */
623169699Skanstatic void
624169699Skandbxout_begin_complex_stabs_noforcetext (void)
625169699Skan{
626169699Skan  fputs (ASM_STABS_OP, asm_out_file);
627169699Skan  putc ('"', asm_out_file);
628169699Skan  gcc_assert (stabstr_last_contin_point == 0);
629169699Skan}
630169699Skan
631169699Skan/* Add CHR, a single character, to the string being built.  */
632169699Skan#define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr)
633169699Skan
634169699Skan/* Add STR, a normal C string, to the string being built.  */
635169699Skan#define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen(str))
636169699Skan
637169699Skan/* Add the text of ID, an IDENTIFIER_NODE, to the string being built.  */
638169699Skan#define stabstr_I(id) obstack_grow (&stabstr_ob, \
639169699Skan                                    IDENTIFIER_POINTER (id), \
640169699Skan                                    IDENTIFIER_LENGTH (id))
641169699Skan
642169699Skan/* Add NUM, a signed decimal number, to the string being built.  */
643169699Skanstatic void
644169699Skanstabstr_D (HOST_WIDE_INT num)
645169699Skan{
646169699Skan  char buf[64];
647169699Skan  char *p = buf + sizeof buf;
648169699Skan  unsigned int unum;
649169699Skan
650169699Skan  if (num == 0)
651169699Skan    {
652169699Skan      stabstr_C ('0');
653169699Skan      return;
654169699Skan    }
655169699Skan  if (num < 0)
656169699Skan    {
657169699Skan      stabstr_C ('-');
658169699Skan      unum = -num;
659169699Skan    }
660169699Skan  else
661169699Skan    unum = num;
662169699Skan
663169699Skan  NUMBER_FMT_LOOP (p, unum, 10);
664169699Skan
665169699Skan  obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
666169699Skan}
667169699Skan
668169699Skan/* Add NUM, an unsigned decimal number, to the string being built.  */
669169699Skanstatic void
670169699Skanstabstr_U (unsigned HOST_WIDE_INT num)
671169699Skan{
672169699Skan  char buf[64];
673169699Skan  char *p = buf + sizeof buf;
674169699Skan  if (num == 0)
675169699Skan    {
676169699Skan      stabstr_C ('0');
677169699Skan      return;
678169699Skan    }
679169699Skan  NUMBER_FMT_LOOP (p, num, 10);
680169699Skan  obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
681169699Skan}
682169699Skan
683169699Skan/* Add CST, an INTEGER_CST tree, to the string being built as an
684169699Skan   unsigned octal number.  This routine handles values which are
685169699Skan   larger than a single HOST_WIDE_INT.  */
686169699Skanstatic void
687169699Skanstabstr_O (tree cst)
688169699Skan{
689169699Skan  unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (cst);
690169699Skan  unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (cst);
691169699Skan
692169699Skan  char buf[128];
693169699Skan  char *p = buf + sizeof buf;
694169699Skan
695169699Skan  /* GDB wants constants with no extra leading "1" bits, so
696169699Skan     we need to remove any sign-extension that might be
697169699Skan     present.  */
698169699Skan  {
699169699Skan    const unsigned int width = TYPE_PRECISION (TREE_TYPE (cst));
700169699Skan    if (width == HOST_BITS_PER_WIDE_INT * 2)
701169699Skan      ;
702169699Skan    else if (width > HOST_BITS_PER_WIDE_INT)
703169699Skan      high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
704169699Skan    else if (width == HOST_BITS_PER_WIDE_INT)
705169699Skan      high = 0;
706169699Skan    else
707169699Skan      high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
708169699Skan  }
709169699Skan
710169699Skan  /* Leading zero for base indicator.  */
711169699Skan  stabstr_C ('0');
712169699Skan
713169699Skan  /* If the value is zero, the base indicator will serve as the value
714169699Skan     all by itself.  */
715169699Skan  if (high == 0 && low == 0)
716169699Skan    return;
717169699Skan
718169699Skan  /* If the high half is zero, we need only print the low half normally.  */
719169699Skan  if (high == 0)
720169699Skan    NUMBER_FMT_LOOP (p, low, 8);
721169699Skan  else
722169699Skan    {
723169699Skan      /* When high != 0, we need to print enough zeroes from low to
724169699Skan	 give the digits from high their proper place-values.  Hence
725169699Skan	 NUMBER_FMT_LOOP cannot be used.  */
726169699Skan      const int n_digits = HOST_BITS_PER_WIDE_INT / 3;
727169699Skan      int i;
728169699Skan
729169699Skan      for (i = 1; i <= n_digits; i++)
730169699Skan	{
731169699Skan	  unsigned int digit = low % 8;
732169699Skan	  low /= 8;
733169699Skan	  *--p = '0' + digit;
734169699Skan	}
735169699Skan
736169699Skan      /* Octal digits carry exactly three bits of information.  The
737169699Skan	 width of a HOST_WIDE_INT is not normally a multiple of three.
738169699Skan	 Therefore, the next digit printed probably needs to carry
739169699Skan	 information from both low and high.  */
740169699Skan      if (HOST_BITS_PER_WIDE_INT % 3 != 0)
741169699Skan	{
742169699Skan	  const int n_leftover_bits = HOST_BITS_PER_WIDE_INT % 3;
743169699Skan	  const int n_bits_from_high = 3 - n_leftover_bits;
744169699Skan
745169699Skan	  const unsigned HOST_WIDE_INT
746169699Skan	    low_mask = (((unsigned HOST_WIDE_INT)1) << n_leftover_bits) - 1;
747169699Skan	  const unsigned HOST_WIDE_INT
748169699Skan	    high_mask = (((unsigned HOST_WIDE_INT)1) << n_bits_from_high) - 1;
749169699Skan
750169699Skan	  unsigned int digit;
751169699Skan
752169699Skan	  /* At this point, only the bottom n_leftover_bits bits of low
753169699Skan	     should be set.  */
754169699Skan	  gcc_assert (!(low & ~low_mask));
755169699Skan
756169699Skan	  digit = (low | ((high & high_mask) << n_leftover_bits));
757169699Skan	  high >>= n_bits_from_high;
758169699Skan
759169699Skan	  *--p = '0' + digit;
760169699Skan	}
761169699Skan
762169699Skan      /* Now we can format high in the normal manner.  However, if
763169699Skan	 the only bits of high that were set were handled by the
764169699Skan	 digit split between low and high, high will now be zero, and
765169699Skan	 we don't want to print extra digits in that case.  */
766169699Skan      if (high)
767169699Skan	NUMBER_FMT_LOOP (p, high, 8);
768169699Skan    }
769169699Skan
770169699Skan  obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
771169699Skan}
772169699Skan
773169699Skan/* Called whenever it is safe to break a stabs string into multiple
774169699Skan   .stabs directives.  If the current string has exceeded the limit
775169699Skan   set by DBX_CONTIN_LENGTH, mark the current position in the buffer
776169699Skan   as a continuation point by inserting DBX_CONTIN_CHAR (doubled if
777169699Skan   it is a backslash) and a null character.  */
778169699Skanstatic inline void
779169699Skanstabstr_continue (void)
780169699Skan{
781169699Skan  if (DBX_CONTIN_LENGTH > 0
782169699Skan      && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
783169699Skan	 > DBX_CONTIN_LENGTH)
784169699Skan    {
785169699Skan      if (DBX_CONTIN_CHAR == '\\')
786169699Skan	obstack_1grow (&stabstr_ob, '\\');
787169699Skan      obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR);
788169699Skan      obstack_1grow (&stabstr_ob, '\0');
789169699Skan      stabstr_last_contin_point = obstack_object_size (&stabstr_ob);
790169699Skan    }
791169699Skan}
792169699Skan#define CONTIN stabstr_continue ()
793169699Skan
794169699Skan/* Macro subroutine of dbxout_finish_complex_stabs, which emits
795169699Skan   all of the arguments to the .stabs directive after the string.
796169699Skan   Overridden by xcoffout.h.  CODE is the stabs code for this symbol;
797169699Skan   LINE is the source line to write into the desc field (in extended
798169699Skan   mode); SYM is the symbol itself.
799169699Skan
800169699Skan   ADDR, LABEL, and NUMBER are three different ways to represent the
801169699Skan   stabs value field.  At most one of these should be nonzero.
802169699Skan
803169699Skan     ADDR is used most of the time; it represents the value as an
804169699Skan     RTL address constant.
805169699Skan
806169699Skan     LABEL is used (currently) only for N_CATCH stabs; it represents
807169699Skan     the value as a string suitable for assemble_name.
808169699Skan
809169699Skan     NUMBER is used when the value is an offset from an implicit base
810169699Skan     pointer (e.g. for a stack variable), or an index (e.g. for a
811169699Skan     register variable).  It represents the value as a decimal integer.  */
812169699Skan
813169699Skan#ifndef DBX_FINISH_STABS
814169699Skan#define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER)	\
815169699Skando {								\
816169699Skan  int line_ = use_gnu_debug_info_extensions ? LINE : 0;		\
817169699Skan								\
818169699Skan  dbxout_int (CODE);						\
819169699Skan  fputs (",0,", asm_out_file);					\
820169699Skan  dbxout_int (line_);						\
821169699Skan  putc (',', asm_out_file);					\
822169699Skan  if (ADDR)							\
823169699Skan    output_addr_const (asm_out_file, ADDR);			\
824169699Skan  else if (LABEL)						\
825169699Skan    assemble_name (asm_out_file, LABEL);			\
826169699Skan  else								\
827169699Skan    dbxout_int (NUMBER);					\
828169699Skan  putc ('\n', asm_out_file);					\
829169699Skan} while (0)
830169699Skan#endif
831169699Skan
832169699Skan/* Finish the emission of a complex .stabs directive.  When DBX_CONTIN_LENGTH
833169699Skan   is zero, this has only to emit the close quote and the remainder of
834169699Skan   the arguments.  When it is nonzero, the string has been marshalled in
835169699Skan   stabstr_ob, and this routine is responsible for breaking it up into
836169699Skan   DBX_CONTIN_LENGTH-sized chunks.
837169699Skan
838169699Skan   SYM is the DECL of the symbol under consideration; it is used only
839169699Skan   for its DECL_SOURCE_LINE.  The other arguments are all passed directly
840169699Skan   to DBX_FINISH_STABS; see above for details.  */
841169699Skan
842169699Skanstatic void
843169699Skandbxout_finish_complex_stabs (tree sym, STAB_CODE_TYPE code,
844169699Skan			     rtx addr, const char *label, int number)
845169699Skan{
846169699Skan  int line ATTRIBUTE_UNUSED;
847169699Skan  char *str;
848169699Skan  size_t len;
849169699Skan
850169699Skan  line = sym ? DECL_SOURCE_LINE (sym) : 0;
851169699Skan  if (DBX_CONTIN_LENGTH > 0)
852169699Skan    {
853169699Skan      char *chunk;
854169699Skan      size_t chunklen;
855169699Skan
856169699Skan      /* Nul-terminate the growing string, then get its size and
857169699Skan	 address.  */
858169699Skan      obstack_1grow (&stabstr_ob, '\0');
859169699Skan
860169699Skan      len = obstack_object_size (&stabstr_ob);
861169699Skan      chunk = str = XOBFINISH (&stabstr_ob, char *);
862169699Skan
863169699Skan      /* Within the buffer are a sequence of NUL-separated strings,
864169699Skan	 each of which is to be written out as a separate stab
865169699Skan	 directive.  */
866169699Skan      for (;;)
867169699Skan	{
868169699Skan	  chunklen = strlen (chunk);
869169699Skan	  fwrite (chunk, 1, chunklen, asm_out_file);
870169699Skan	  fputs ("\",", asm_out_file);
871169699Skan
872169699Skan	  /* Must add an extra byte to account for the NUL separator.  */
873169699Skan	  chunk += chunklen + 1;
874169699Skan	  len   -= chunklen + 1;
875169699Skan
876169699Skan	  /* Only put a line number on the last stab in the sequence.  */
877169699Skan	  DBX_FINISH_STABS (sym, code, len == 0 ? line : 0,
878169699Skan			    addr, label, number);
879169699Skan	  if (len == 0)
880169699Skan	    break;
881169699Skan
882169699Skan	  fputs (ASM_STABS_OP, asm_out_file);
883169699Skan	  putc ('"', asm_out_file);
884169699Skan	}
885169699Skan      stabstr_last_contin_point = 0;
886169699Skan    }
887169699Skan  else
888169699Skan    {
889169699Skan      /* No continuations - we can put the whole string out at once.
890169699Skan	 It is faster to augment the string with the close quote and
891169699Skan	 comma than to do a two-character fputs.  */
892169699Skan      obstack_grow (&stabstr_ob, "\",", 2);
893169699Skan      len = obstack_object_size (&stabstr_ob);
894169699Skan      str = XOBFINISH (&stabstr_ob, char *);
895169699Skan
896169699Skan      fwrite (str, 1, len, asm_out_file);
897169699Skan      DBX_FINISH_STABS (sym, code, line, addr, label, number);
898169699Skan    }
899169699Skan  obstack_free (&stabstr_ob, str);
900169699Skan}
901169699Skan
90290085Sobrien#if defined (DBX_DEBUGGING_INFO)
903169699Skan
90450495Sobrienstatic void
905169699Skandbxout_function_end (tree decl)
90618334Speter{
90750495Sobrien  char lscope_label_name[100];
908146906Skan
909146906Skan  /* The Lscope label must be emitted even if we aren't doing anything
910146906Skan     else; dbxout_block needs it.  */
911169699Skan  switch_to_section (function_section (current_function_decl));
912169699Skan
913169699Skan  /* Convert Lscope into the appropriate format for local labels in case
91450495Sobrien     the system doesn't insert underscores in front of user generated
91550495Sobrien     labels.  */
91650495Sobrien  ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
917169699Skan  targetm.asm_out.internal_label (asm_out_file, "Lscope", scope_labelno);
91818334Speter
919146906Skan  /* The N_FUN tag at the end of the function is a GNU extension,
920146906Skan     which may be undesirable, and is unnecessary if we do not have
921146906Skan     named sections.  */
922146906Skan  if (!use_gnu_debug_info_extensions
923146906Skan      || NO_DBX_FUNCTION_END
924169699Skan      || !targetm.have_named_sections
925169699Skan      || DECL_IGNORED_P (decl))
926146906Skan    return;
927146906Skan
92850495Sobrien  /* By convention, GCC will mark the end of a function with an N_FUN
92950495Sobrien     symbol and an empty string.  */
930169699Skan  if (flag_reorder_blocks_and_partition)
931169699Skan    {
932169699Skan      dbxout_begin_empty_stabs (N_FUN);
933169699Skan      dbxout_stab_value_label_diff (cfun->hot_section_end_label,
934169699Skan				    cfun->hot_section_label);
935169699Skan      dbxout_begin_empty_stabs (N_FUN);
936169699Skan      dbxout_stab_value_label_diff (cfun->cold_section_end_label,
937169699Skan				    cfun->cold_section_label);
938169699Skan    }
939169699Skan  else
940169699Skan    {
941169699Skan      char begin_label[20];
942169699Skan      /* Reference current function start using LFBB.  */
943169699Skan      ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
944169699Skan      dbxout_begin_empty_stabs (N_FUN);
945169699Skan      dbxout_stab_value_label_diff (lscope_label_name, begin_label);
946169699Skan    }
947169699Skan
948169699Skan  if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols)
949169699Skan    dbxout_stabd (N_ENSYM, 0);
95050495Sobrien}
95190085Sobrien#endif /* DBX_DEBUGGING_INFO */
95218334Speter
953169699Skan/* Get lang description for N_SO stab.  */
954169699Skanstatic unsigned int ATTRIBUTE_UNUSED
955169699Skanget_lang_number (void)
956169699Skan{
957169699Skan  const char *language_string = lang_hooks.name;
958169699Skan
959169699Skan  if (strcmp (language_string, "GNU C") == 0)
960169699Skan    return N_SO_C;
961169699Skan  else if (strcmp (language_string, "GNU C++") == 0)
962169699Skan    return N_SO_CC;
963169699Skan  else if (strcmp (language_string, "GNU F77") == 0)
964169699Skan    return N_SO_FORTRAN;
965169699Skan  else if (strcmp (language_string, "GNU F95") == 0)
966169699Skan    return N_SO_FORTRAN90; /* CHECKME */
967169699Skan  else if (strcmp (language_string, "GNU Pascal") == 0)
968169699Skan    return N_SO_PASCAL;
969169699Skan  else if (strcmp (language_string, "GNU Objective-C") == 0)
970169699Skan    return N_SO_OBJC;
971169699Skan  else if (strcmp (language_string, "GNU Objective-C++") == 0)
972169699Skan    return N_SO_OBJCPLUS;
973169699Skan  else
974169699Skan    return 0;
975169699Skan
976169699Skan}
977169699Skan
97818334Speter/* At the beginning of compilation, start writing the symbol table.
97918334Speter   Initialize `typevec' and output the standard data types of C.  */
98018334Speter
98190085Sobrienstatic void
982132727Skandbxout_init (const char *input_file_name)
98318334Speter{
98418334Speter  char ltext_label_name[100];
985169699Skan  bool used_ltext_label_name = false;
986169699Skan  tree syms = lang_hooks.decls.getdecls ();
98718334Speter
98818334Speter  typevec_len = 100;
989132727Skan  typevec = ggc_calloc (typevec_len, sizeof typevec[0]);
99018334Speter
991169699Skan  /* stabstr_ob contains one string, which will be just fine with
992169699Skan     1-byte alignment.  */
993169699Skan  obstack_specify_allocation (&stabstr_ob, 0, 1, xmalloc, free);
994169699Skan
99518334Speter  /* Convert Ltext into the appropriate format for local labels in case
99618334Speter     the system doesn't insert underscores in front of user generated
99718334Speter     labels.  */
99818334Speter  ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
99918334Speter
100018334Speter  /* Put the current working directory in an N_SO symbol.  */
1001169699Skan  if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY)
100218334Speter    {
1003169699Skan      static const char *cwd;
1004169699Skan
1005169699Skan      if (!cwd)
100618334Speter	{
1007169699Skan	  cwd = get_src_pwd ();
1008169699Skan	  if (cwd[0] == '\0')
1009169699Skan	    cwd = "/";
1010169699Skan	  else if (!IS_DIR_SEPARATOR (cwd[strlen (cwd) - 1]))
1011169699Skan	    cwd = concat (cwd, "/", NULL);
1012169699Skan	}
101318334Speter#ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
1014169699Skan      DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asm_out_file, cwd);
101518334Speter#else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1016169699Skan      dbxout_begin_simple_stabs_desc (cwd, N_SO, get_lang_number ());
1017169699Skan      dbxout_stab_value_label (ltext_label_name);
1018169699Skan      used_ltext_label_name = true;
101918334Speter#endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
102018334Speter    }
102118334Speter
102218334Speter#ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
1023169699Skan  DBX_OUTPUT_MAIN_SOURCE_FILENAME (asm_out_file, input_file_name);
102490085Sobrien#else
1025169699Skan  dbxout_begin_simple_stabs_desc (input_file_name, N_SO, get_lang_number ());
1026169699Skan  dbxout_stab_value_label (ltext_label_name);
1027169699Skan  used_ltext_label_name = true;
102818334Speter#endif
102918334Speter
1030169699Skan  if (used_ltext_label_name)
1031169699Skan    {
1032169699Skan      switch_to_section (text_section);
1033169699Skan      targetm.asm_out.internal_label (asm_out_file, "Ltext", 0);
1034169699Skan    }
1035169699Skan
1036169699Skan  /* Emit an N_OPT stab to indicate that this file was compiled by GCC.
1037169699Skan     The string used is historical.  */
1038169699Skan#ifndef NO_DBX_GCC_MARKER
1039169699Skan  dbxout_begin_simple_stabs ("gcc2_compiled.", N_OPT);
1040169699Skan  dbxout_stab_value_zero ();
1041169699Skan#endif
1042169699Skan
1043132727Skan  base_input_file = lastfile = input_file_name;
104418334Speter
104518334Speter  next_type_number = 1;
104618334Speter
104750495Sobrien#ifdef DBX_USE_BINCL
1048169699Skan  current_file = XNEW (struct dbx_file);
104950495Sobrien  current_file->next = NULL;
105050495Sobrien  current_file->file_number = 0;
105150495Sobrien  current_file->next_type_number = 1;
105250495Sobrien  next_file_number = 1;
1053132727Skan  current_file->prev = NULL;
1054132727Skan  current_file->bincl_status = BINCL_NOT_REQUIRED;
1055132727Skan  current_file->pending_bincl_name = NULL;
105650495Sobrien#endif
105750495Sobrien
1058132727Skan  /* Get all permanent types that have typedef names, and output them
1059132727Skan     all, except for those already output.  Some language front ends
1060169699Skan     put these declarations in the top-level scope; some do not;
1061169699Skan     the latter are responsible for calling debug_hooks->type_decl from
1062169699Skan     their record_builtin_type function.  */
106318334Speter  dbxout_typedefs (syms);
1064169699Skan
1065169699Skan  if (preinit_symbols)
1066169699Skan    {
1067169699Skan      tree t;
1068169699Skan      for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1069169699Skan	dbxout_symbol (TREE_VALUE (t), 0);
1070169699Skan      preinit_symbols = 0;
1071169699Skan    }
107218334Speter}
107318334Speter
1074132727Skan/* Output any typedef names for types described by TYPE_DECLs in SYMS.  */
107518334Speter
107618334Speterstatic void
1077132727Skandbxout_typedefs (tree syms)
107818334Speter{
1079132727Skan  for (; syms != NULL_TREE; syms = TREE_CHAIN (syms))
108018334Speter    {
108118334Speter      if (TREE_CODE (syms) == TYPE_DECL)
108218334Speter	{
108318334Speter	  tree type = TREE_TYPE (syms);
108418334Speter	  if (TYPE_NAME (type)
108518334Speter	      && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1086122190Skan	      && COMPLETE_OR_VOID_TYPE_P (type)
108718334Speter	      && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
108818334Speter	    dbxout_symbol (TYPE_NAME (type), 0);
108918334Speter	}
109018334Speter    }
109118334Speter}
109218334Speter
1093132727Skan#ifdef DBX_USE_BINCL
1094132727Skan/* Emit BINCL stab using given name.  */
1095132727Skanstatic void
1096132727Skanemit_bincl_stab (const char *name)
1097132727Skan{
1098169699Skan  dbxout_begin_simple_stabs (name, N_BINCL);
1099169699Skan  dbxout_stab_value_zero ();
1100132727Skan}
1101132727Skan
1102132727Skan/* If there are pending bincls then it is time to emit all of them.  */
1103132727Skan
1104132727Skanstatic inline void
1105132727Skanemit_pending_bincls_if_required (void)
1106132727Skan{
1107132727Skan  if (pending_bincls)
1108132727Skan    emit_pending_bincls ();
1109132727Skan}
1110132727Skan
1111132727Skan/* Emit all pending bincls.  */
1112132727Skan
1113132727Skanstatic void
1114132727Skanemit_pending_bincls (void)
1115132727Skan{
1116132727Skan  struct dbx_file *f = current_file;
1117132727Skan
1118132727Skan  /* Find first pending bincl.  */
1119132727Skan  while (f->bincl_status == BINCL_PENDING)
1120132727Skan    f = f->next;
1121132727Skan
1122132727Skan  /* Now emit all bincls.  */
1123132727Skan  f = f->prev;
1124132727Skan
1125132727Skan  while (f)
1126132727Skan    {
1127132727Skan      if (f->bincl_status == BINCL_PENDING)
1128132727Skan        {
1129132727Skan          emit_bincl_stab (f->pending_bincl_name);
1130132727Skan
1131132727Skan	  /* Update file number and status.  */
1132132727Skan          f->file_number = next_file_number++;
1133132727Skan          f->bincl_status = BINCL_PROCESSED;
1134132727Skan        }
1135132727Skan      if (f == current_file)
1136132727Skan        break;
1137132727Skan      f = f->prev;
1138132727Skan    }
1139132727Skan
1140132727Skan  /* All pending bincls have been emitted.  */
1141132727Skan  pending_bincls = 0;
1142132727Skan}
1143132727Skan
1144132727Skan#else
1145132727Skan
1146132727Skanstatic inline void
1147132727Skanemit_pending_bincls_if_required (void) {}
1148132727Skan#endif
1149132727Skan
115050495Sobrien/* Change to reading from a new source file.  Generate a N_BINCL stab.  */
115150495Sobrien
115290085Sobrienstatic void
1153132727Skandbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1154132727Skan			  const char *filename ATTRIBUTE_UNUSED)
115550495Sobrien{
115650495Sobrien#ifdef DBX_USE_BINCL
1157169699Skan  struct dbx_file *n = XNEW (struct dbx_file);
115850495Sobrien
115950495Sobrien  n->next = current_file;
116050495Sobrien  n->next_type_number = 1;
1161132727Skan  /* Do not assign file number now.
1162132727Skan     Delay it until we actually emit BINCL.  */
1163132727Skan  n->file_number = 0;
1164132727Skan  n->prev = NULL;
1165132727Skan  current_file->prev = n;
1166132727Skan  n->bincl_status = BINCL_PENDING;
1167132727Skan  n->pending_bincl_name = filename;
1168132727Skan  pending_bincls = 1;
116950495Sobrien  current_file = n;
117050495Sobrien#endif
117150495Sobrien}
117250495Sobrien
117350495Sobrien/* Revert to reading a previous source file.  Generate a N_EINCL stab.  */
117450495Sobrien
117590085Sobrienstatic void
1176132727Skandbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
117750495Sobrien{
117850495Sobrien#ifdef DBX_USE_BINCL
1179132727Skan  /* Emit EINCL stab only if BINCL is not pending.  */
1180132727Skan  if (current_file->bincl_status == BINCL_PROCESSED)
1181169699Skan    {
1182169699Skan      dbxout_begin_stabn (N_EINCL);
1183169699Skan      dbxout_stab_value_zero ();
1184169699Skan    }
1185132727Skan  current_file->bincl_status = BINCL_NOT_REQUIRED;
1186132727Skan  current_file = current_file->next;
118750495Sobrien#endif
118850495Sobrien}
118950495Sobrien
1190132727Skan/* Handle a few odd cases that occur when trying to make PCH files work.  */
1191132727Skan
1192132727Skanstatic void
1193132727Skandbxout_handle_pch (unsigned at_end)
1194132727Skan{
1195132727Skan  if (! at_end)
1196132727Skan    {
1197132727Skan      /* When using the PCH, this file will be included, so we need to output
1198132727Skan	 a BINCL.  */
1199132727Skan      dbxout_start_source_file (0, lastfile);
1200132727Skan
1201132727Skan      /* The base file when using the PCH won't be the same as
1202132727Skan	 the base file when it's being generated.  */
1203132727Skan      lastfile = NULL;
1204132727Skan    }
1205132727Skan  else
1206132727Skan    {
1207132727Skan      /* ... and an EINCL.  */
1208132727Skan      dbxout_end_source_file (0);
1209132727Skan
1210132727Skan      /* Deal with cases where 'lastfile' was never actually changed.  */
1211132727Skan      lastfile_is_base = lastfile == NULL;
1212132727Skan    }
1213132727Skan}
1214132727Skan
121590085Sobrien#if defined (DBX_DEBUGGING_INFO)
121618334Speter/* Output debugging info to FILE to switch to sourcefile FILENAME.  */
121718334Speter
121890085Sobrienstatic void
1219169699Skandbxout_source_file (const char *filename)
122018334Speter{
1221132727Skan  if (lastfile == 0 && lastfile_is_base)
1222132727Skan    {
1223132727Skan      lastfile = base_input_file;
1224132727Skan      lastfile_is_base = 0;
1225132727Skan    }
1226132727Skan
122718334Speter  if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
122818334Speter    {
1229169699Skan      /* Don't change section amid function.  */
1230169699Skan      if (current_function_decl == NULL_TREE)
1231169699Skan	switch_to_section (text_section);
123290085Sobrien
1233169699Skan      dbxout_begin_simple_stabs (filename, N_SOL);
1234169699Skan      dbxout_stab_value_internal_label ("Ltext", &source_label_number);
123518334Speter      lastfile = filename;
123618334Speter    }
123718334Speter}
123818334Speter
1239169699Skan/* Output N_BNSYM, line number symbol entry, and local symbol at
1240169699Skan   function scope  */
1241169699Skan
1242169699Skanstatic void
1243169699Skandbxout_begin_prologue (unsigned int lineno, const char *filename)
1244169699Skan{
1245169699Skan  if (use_gnu_debug_info_extensions
1246169699Skan      && !NO_DBX_FUNCTION_END
1247169699Skan      && !NO_DBX_BNSYM_ENSYM
1248169699Skan      && !flag_debug_only_used_symbols)
1249169699Skan    dbxout_stabd (N_BNSYM, 0);
1250169699Skan
1251169699Skan  /* pre-increment the scope counter */
1252169699Skan  scope_labelno++;
1253169699Skan
1254169699Skan  dbxout_source_line (lineno, filename);
1255169699Skan  /* Output function begin block at function scope, referenced
1256169699Skan     by dbxout_block, dbxout_source_line and dbxout_function_end.  */
1257169699Skan  emit_pending_bincls_if_required ();
1258169699Skan  targetm.asm_out.internal_label (asm_out_file, "LFBB", scope_labelno);
1259169699Skan}
1260169699Skan
126190085Sobrien/* Output a line number symbol entry for source file FILENAME and line
126290085Sobrien   number LINENO.  */
126318334Speter
126490085Sobrienstatic void
1265132727Skandbxout_source_line (unsigned int lineno, const char *filename)
126618334Speter{
1267169699Skan  dbxout_source_file (filename);
126818334Speter
1269169699Skan#ifdef DBX_OUTPUT_SOURCE_LINE
1270169699Skan  DBX_OUTPUT_SOURCE_LINE (asm_out_file, lineno, dbxout_source_line_counter);
127118334Speter#else
1272169699Skan  if (DBX_LINES_FUNCTION_RELATIVE)
1273169699Skan    {
1274169699Skan      char begin_label[20];
1275169699Skan      dbxout_begin_stabn_sline (lineno);
1276169699Skan      /* Reference current function start using LFBB.  */
1277169699Skan      ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
1278169699Skan      dbxout_stab_value_internal_label_diff ("LM", &dbxout_source_line_counter,
1279169699Skan					     begin_label);
1280169699Skan    }
1281169699Skan  else
1282169699Skan    dbxout_stabd (N_SLINE, lineno);
128318334Speter#endif
128418334Speter}
128518334Speter
128690085Sobrien/* Describe the beginning of an internal block within a function.  */
128790085Sobrien
128890085Sobrienstatic void
1289132727Skandbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
129090085Sobrien{
1291132727Skan  emit_pending_bincls_if_required ();
1292169699Skan  targetm.asm_out.internal_label (asm_out_file, "LBB", n);
129390085Sobrien}
129490085Sobrien
129590085Sobrien/* Describe the end line-number of an internal block within a function.  */
129690085Sobrien
129790085Sobrienstatic void
1298132727Skandbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
129990085Sobrien{
1300132727Skan  emit_pending_bincls_if_required ();
1301169699Skan  targetm.asm_out.internal_label (asm_out_file, "LBE", n);
130290085Sobrien}
130390085Sobrien
130490085Sobrien/* Output dbx data for a function definition.
130590085Sobrien   This includes a definition of the function name itself (a symbol),
130690085Sobrien   definitions of the parameters (locating them in the parameter list)
130790085Sobrien   and then output the block that makes up the function's body
130890085Sobrien   (including all the auto variables of the function).  */
130990085Sobrien
131090085Sobrienstatic void
1311132727Skandbxout_function_decl (tree decl)
131290085Sobrien{
1313132727Skan  emit_pending_bincls_if_required ();
131490085Sobrien#ifndef DBX_FUNCTION_FIRST
131590085Sobrien  dbxout_begin_function (decl);
131690085Sobrien#endif
131790085Sobrien  dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
1318169699Skan  dbxout_function_end (decl);
131990085Sobrien}
132090085Sobrien
132190085Sobrien#endif /* DBX_DEBUGGING_INFO  */
132290085Sobrien
132390085Sobrien/* Debug information for a global DECL.  Called from toplev.c after
132490085Sobrien   compilation proper has finished.  */
132590085Sobrienstatic void
1326132727Skandbxout_global_decl (tree decl)
132790085Sobrien{
1328169699Skan  if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
1329132727Skan    {
1330132727Skan      int saved_tree_used = TREE_USED (decl);
1331132727Skan      TREE_USED (decl) = 1;
1332132727Skan      dbxout_symbol (decl, 0);
1333132727Skan      TREE_USED (decl) = saved_tree_used;
1334132727Skan    }
1335117404Skan}
133690085Sobrien
1337169699Skan/* This is just a function-type adapter; dbxout_symbol does exactly
1338169699Skan   what we want but returns an int.  */
1339169699Skanstatic void
1340169699Skandbxout_type_decl (tree decl, int local)
1341169699Skan{
1342169699Skan  dbxout_symbol (decl, local);
1343169699Skan}
1344169699Skan
134518334Speter/* At the end of compilation, finish writing the symbol table.
1346169699Skan   The default is to call debug_free_queue but do nothing else.  */
134718334Speter
134890085Sobrienstatic void
1349132727Skandbxout_finish (const char *filename ATTRIBUTE_UNUSED)
135018334Speter{
135118334Speter#ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
1352169699Skan  DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename);
1353169699Skan#elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
1354169699Skan {
1355169699Skan   switch_to_section (text_section);
1356169699Skan   dbxout_begin_empty_stabs (N_SO);
1357169699Skan   dbxout_stab_value_internal_label ("Letext", 0);
1358169699Skan }
1359169699Skan#endif
1360132727Skan  debug_free_queue ();
1361110621Skan}
1362110621Skan
136350495Sobrien/* Output the index of a type.  */
136450495Sobrien
136550495Sobrienstatic void
1366132727Skandbxout_type_index (tree type)
136750495Sobrien{
136850495Sobrien#ifndef DBX_USE_BINCL
1369169699Skan  stabstr_D (TYPE_SYMTAB_ADDRESS (type));
137050495Sobrien#else
137150495Sobrien  struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
1372169699Skan  stabstr_C ('(');
1373169699Skan  stabstr_D (t->file_number);
1374169699Skan  stabstr_C (',');
1375169699Skan  stabstr_D (t->type_number);
1376169699Skan  stabstr_C (')');
137750495Sobrien#endif
137850495Sobrien}
137950495Sobrien
1380169699Skan
138118334Speter
1382169699Skan/* Used in several places: evaluates to '0' for a private decl,
1383169699Skan   '1' for a protected decl, '2' for a public decl.  */
1384169699Skan#define DECL_ACCESSIBILITY_CHAR(DECL) \
1385169699Skan(TREE_PRIVATE (DECL) ? '0' : TREE_PROTECTED (DECL) ? '1' : '2')
1386169699Skan
138718334Speter/* Subroutine of `dbxout_type'.  Output the type fields of TYPE.
138818334Speter   This must be a separate function because anonymous unions require
138918334Speter   recursive calls.  */
139018334Speter
139118334Speterstatic void
1392132727Skandbxout_type_fields (tree type)
139318334Speter{
139418334Speter  tree tem;
139590085Sobrien
139618334Speter  /* Output the name, type, position (in bits), size (in bits) of each
139790085Sobrien     field that we can support.  */
139818334Speter  for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
139918334Speter    {
1400169699Skan      /* If one of the nodes is an error_mark or its type is then
1401169699Skan	 return early.  */
1402132727Skan      if (tem == error_mark_node || TREE_TYPE (tem) == error_mark_node)
1403132727Skan	return;
1404132727Skan
140518334Speter      /* Omit here local type decls until we know how to support them.  */
140690085Sobrien      if (TREE_CODE (tem) == TYPE_DECL
1407169699Skan	  /* Omit here the nameless fields that are used to skip bits.  */
1408169699Skan	  || DECL_IGNORED_P (tem)
140990085Sobrien	  /* Omit fields whose position or size are variable or too large to
141090085Sobrien	     represent.  */
141190085Sobrien	  || (TREE_CODE (tem) == FIELD_DECL
141290085Sobrien	      && (! host_integerp (bit_position (tem), 0)
141390085Sobrien		  || ! DECL_SIZE (tem)
1414169699Skan		  || ! host_integerp (DECL_SIZE (tem), 1))))
141518334Speter	continue;
141690085Sobrien
141718334Speter      else if (TREE_CODE (tem) != CONST_DECL)
141818334Speter	{
141918334Speter	  /* Continue the line if necessary,
142018334Speter	     but not before the first field.  */
142118334Speter	  if (tem != TYPE_FIELDS (type))
142290085Sobrien	    CONTIN;
142318334Speter
142418334Speter	  if (DECL_NAME (tem))
1425169699Skan	    stabstr_I (DECL_NAME (tem));
1426169699Skan	  stabstr_C (':');
142718334Speter
142818334Speter	  if (use_gnu_debug_info_extensions
142918334Speter	      && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
143018334Speter		  || TREE_CODE (tem) != FIELD_DECL))
143118334Speter	    {
1432169699Skan	      stabstr_C ('/');
1433169699Skan	      stabstr_C (DECL_ACCESSIBILITY_CHAR (tem));
143418334Speter	    }
143518334Speter
143618334Speter	  dbxout_type ((TREE_CODE (tem) == FIELD_DECL
143718334Speter			&& DECL_BIT_FIELD_TYPE (tem))
143890085Sobrien		       ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
143918334Speter
144018334Speter	  if (TREE_CODE (tem) == VAR_DECL)
144118334Speter	    {
144218334Speter	      if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
144318334Speter		{
144490085Sobrien		  tree name = DECL_ASSEMBLER_NAME (tem);
144590085Sobrien
1446169699Skan		  stabstr_C (':');
1447169699Skan		  stabstr_I (name);
1448169699Skan		  stabstr_C (';');
144918334Speter		}
145018334Speter	      else
1451169699Skan		/* If TEM is non-static, GDB won't understand it.  */
1452169699Skan		stabstr_S (",0,0;");
145318334Speter	    }
145490085Sobrien	  else
145518334Speter	    {
1456169699Skan	      stabstr_C (',');
1457169699Skan	      stabstr_D (int_bit_position (tem));
1458169699Skan	      stabstr_C (',');
1459169699Skan	      stabstr_D (tree_low_cst (DECL_SIZE (tem), 1));
1460169699Skan	      stabstr_C (';');
146118334Speter	    }
146218334Speter	}
146318334Speter    }
146418334Speter}
146518334Speter
146618334Speter/* Subroutine of `dbxout_type_methods'.  Output debug info about the
1467169699Skan   method described DECL.  */
146818334Speter
146918334Speterstatic void
1470169699Skandbxout_type_method_1 (tree decl)
147118334Speter{
147218334Speter  char c1 = 'A', c2;
147318334Speter
147418334Speter  if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
147518334Speter    c2 = '?';
147618334Speter  else /* it's a METHOD_TYPE.  */
147718334Speter    {
147818334Speter      tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
147918334Speter      /* A for normal functions.
148018334Speter	 B for `const' member functions.
148118334Speter	 C for `volatile' member functions.
148218334Speter	 D for `const volatile' member functions.  */
148318334Speter      if (TYPE_READONLY (TREE_TYPE (firstarg)))
148418334Speter	c1 += 1;
148518334Speter      if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
148618334Speter	c1 += 2;
148718334Speter
148818334Speter      if (DECL_VINDEX (decl))
148918334Speter	c2 = '*';
149018334Speter      else
149118334Speter	c2 = '.';
149218334Speter    }
149318334Speter
1494169699Skan  /* ??? Output the mangled name, which contains an encoding of the
1495169699Skan     method's type signature.  May not be necessary anymore.  */
1496169699Skan  stabstr_C (':');
1497169699Skan  stabstr_I (DECL_ASSEMBLER_NAME (decl));
1498169699Skan  stabstr_C (';');
1499169699Skan  stabstr_C (DECL_ACCESSIBILITY_CHAR (decl));
1500169699Skan  stabstr_C (c1);
1501169699Skan  stabstr_C (c2);
150290085Sobrien
150390085Sobrien  if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
150418334Speter    {
1505169699Skan      stabstr_D (tree_low_cst (DECL_VINDEX (decl), 0));
1506169699Skan      stabstr_C (';');
150790085Sobrien      dbxout_type (DECL_CONTEXT (decl), 0);
1508169699Skan      stabstr_C (';');
150918334Speter    }
151018334Speter}
151118334Speter
151218334Speter/* Subroutine of `dbxout_type'.  Output debug info about the methods defined
151318334Speter   in TYPE.  */
151418334Speter
151518334Speterstatic void
1516132727Skandbxout_type_methods (tree type)
151718334Speter{
151818334Speter  /* C++: put out the method names and their parameter lists */
151918334Speter  tree methods = TYPE_METHODS (type);
152090085Sobrien  tree fndecl;
152190085Sobrien  tree last;
152218334Speter
152318334Speter  if (methods == NULL_TREE)
152418334Speter    return;
152518334Speter
152650495Sobrien  if (TREE_CODE (methods) != TREE_VEC)
152718334Speter    fndecl = methods;
152818334Speter  else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
152918334Speter    fndecl = TREE_VEC_ELT (methods, 0);
153018334Speter  else
153118334Speter    fndecl = TREE_VEC_ELT (methods, 1);
153218334Speter
153318334Speter  while (fndecl)
153418334Speter    {
153518334Speter      int need_prefix = 1;
153618334Speter
153718334Speter      /* Group together all the methods for the same operation.
153818334Speter	 These differ in the types of the arguments.  */
153918334Speter      for (last = NULL_TREE;
154018334Speter	   fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
154118334Speter	   fndecl = TREE_CHAIN (fndecl))
154218334Speter	/* Output the name of the field (after overloading), as
154318334Speter	   well as the name of the field before overloading, along
154418334Speter	   with its parameter list */
154518334Speter	{
154690085Sobrien	  /* Skip methods that aren't FUNCTION_DECLs.  (In C++, these
154790085Sobrien	     include TEMPLATE_DECLs.)  The debugger doesn't know what
154890085Sobrien	     to do with such entities anyhow.  */
154990085Sobrien	  if (TREE_CODE (fndecl) != FUNCTION_DECL)
155090085Sobrien	    continue;
155190085Sobrien
155218334Speter	  CONTIN;
155318334Speter
155418334Speter	  last = fndecl;
155518334Speter
155690085Sobrien	  /* Also ignore abstract methods; those are only interesting to
155790085Sobrien	     the DWARF backends.  */
155890085Sobrien	  if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
155918334Speter	    continue;
156018334Speter
156190085Sobrien	  /* Redundantly output the plain name, since that's what gdb
156290085Sobrien	     expects.  */
156390085Sobrien	  if (need_prefix)
156418334Speter	    {
1565169699Skan	      stabstr_I (DECL_NAME (fndecl));
1566169699Skan	      stabstr_S ("::");
156790085Sobrien	      need_prefix = 0;
156818334Speter	    }
156918334Speter
157090085Sobrien	  dbxout_type (TREE_TYPE (fndecl), 0);
1571169699Skan	  dbxout_type_method_1 (fndecl);
157218334Speter	}
157318334Speter      if (!need_prefix)
1574169699Skan	stabstr_C (';');
157518334Speter    }
157618334Speter}
157718334Speter
157818334Speter/* Emit a "range" type specification, which has the form:
157918334Speter   "r<index type>;<lower bound>;<upper bound>;".
158050495Sobrien   TYPE is an INTEGER_TYPE.  */
158118334Speter
158218334Speterstatic void
1583132727Skandbxout_range_type (tree type)
158418334Speter{
1585169699Skan  stabstr_C ('r');
158618334Speter  if (TREE_TYPE (type))
158790085Sobrien    dbxout_type (TREE_TYPE (type), 0);
158818334Speter  else if (TREE_CODE (type) != INTEGER_TYPE)
158990085Sobrien    dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
159018334Speter  else
159118334Speter    {
159250495Sobrien      /* Traditionally, we made sure 'int' was type 1, and builtin types
159350495Sobrien	 were defined to be sub-ranges of int.  Unfortunately, this
159450495Sobrien	 does not allow us to distinguish true sub-ranges from integer
159550495Sobrien	 types.  So, instead we define integer (non-sub-range) types as
159650495Sobrien	 sub-ranges of themselves.  This matters for Chill.  If this isn't
159750495Sobrien	 a subrange type, then we want to define it in terms of itself.
159850495Sobrien	 However, in C, this may be an anonymous integer type, and we don't
159950495Sobrien	 want to emit debug info referring to it.  Just calling
160050495Sobrien	 dbxout_type_index won't work anyways, because the type hasn't been
160150495Sobrien	 defined yet.  We make this work for both cases by checked to see
160250495Sobrien	 whether this is a defined type, referring to it if it is, and using
160350495Sobrien	 'int' otherwise.  */
160450495Sobrien      if (TYPE_SYMTAB_ADDRESS (type) != 0)
160550495Sobrien	dbxout_type_index (type);
160650495Sobrien      else
160750495Sobrien	dbxout_type_index (integer_type_node);
160818334Speter    }
160990085Sobrien
1610169699Skan  stabstr_C (';');
161190085Sobrien  if (TYPE_MIN_VALUE (type) != 0
161290085Sobrien      && host_integerp (TYPE_MIN_VALUE (type), 0))
161350495Sobrien    {
1614132727Skan      if (print_int_cst_bounds_in_octal_p (type))
1615169699Skan        stabstr_O (TYPE_MIN_VALUE (type));
1616132727Skan      else
1617169699Skan        stabstr_D (tree_low_cst (TYPE_MIN_VALUE (type), 0));
161850495Sobrien    }
161918334Speter  else
1620169699Skan    stabstr_C ('0');
162190085Sobrien
1622169699Skan  stabstr_C (';');
162390085Sobrien  if (TYPE_MAX_VALUE (type) != 0
162490085Sobrien      && host_integerp (TYPE_MAX_VALUE (type), 0))
162590085Sobrien    {
1626132727Skan      if (print_int_cst_bounds_in_octal_p (type))
1627169699Skan        stabstr_O (TYPE_MAX_VALUE (type));
1628132727Skan      else
1629169699Skan        stabstr_D (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1630169699Skan      stabstr_C (';');
163190085Sobrien    }
163218334Speter  else
1633169699Skan    stabstr_S ("-1;");
163418334Speter}
163518334Speter
1636132727Skan
163718334Speter/* Output a reference to a type.  If the type has not yet been
163818334Speter   described in the dbx output, output its definition now.
163918334Speter   For a type already defined, just refer to its definition
164018334Speter   using the type number.
164118334Speter
164218334Speter   If FULL is nonzero, and the type has been described only with
164318334Speter   a forward-reference, output the definition now.
164418334Speter   If FULL is zero in this case, just refer to the forward-reference
164590085Sobrien   using the number previously allocated.  */
164618334Speter
164718334Speterstatic void
1648132727Skandbxout_type (tree type, int full)
164918334Speter{
165090085Sobrien  tree tem;
165190085Sobrien  tree main_variant;
165218334Speter  static int anonymous_type_number = 0;
1653169699Skan  bool vector_type = false;
165418334Speter
165590085Sobrien  if (TREE_CODE (type) == VECTOR_TYPE)
1656169699Skan    {
1657169699Skan      /* The frontend feeds us a representation for the vector as a struct
1658169699Skan	 containing an array.  Pull out the array type.  */
1659169699Skan      type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1660169699Skan      vector_type = true;
1661169699Skan    }
166290085Sobrien
166318334Speter  /* If there was an input error and we don't really have a type,
166418334Speter     avoid crashing and write something that is at least valid
166518334Speter     by assuming `int'.  */
166618334Speter  if (type == error_mark_node)
166718334Speter    type = integer_type_node;
166818334Speter  else
166918334Speter    {
167018334Speter      if (TYPE_NAME (type)
167118334Speter	  && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
167218334Speter	  && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
167318334Speter	full = 0;
167418334Speter    }
167518334Speter
167690085Sobrien  /* Try to find the "main variant" with the same name.  */
167790085Sobrien  if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
167890085Sobrien      && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
167990085Sobrien    main_variant = TREE_TYPE (TYPE_NAME (type));
168090085Sobrien  else
168190085Sobrien    main_variant = TYPE_MAIN_VARIANT (type);
168290085Sobrien
168390085Sobrien  /* If we are not using extensions, stabs does not distinguish const and
168490085Sobrien     volatile, so there is no need to make them separate types.  */
168590085Sobrien  if (!use_gnu_debug_info_extensions)
168690085Sobrien    type = main_variant;
168790085Sobrien
168818334Speter  if (TYPE_SYMTAB_ADDRESS (type) == 0)
168918334Speter    {
169018334Speter      /* Type has no dbx number assigned.  Assign next available number.  */
169118334Speter      TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
169218334Speter
169318334Speter      /* Make sure type vector is long enough to record about this type.  */
169418334Speter
169518334Speter      if (next_type_number == typevec_len)
169618334Speter	{
169750495Sobrien	  typevec
1698132727Skan	    = ggc_realloc (typevec, (typevec_len * 2 * sizeof typevec[0]));
1699132727Skan	  memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
170018334Speter	  typevec_len *= 2;
170118334Speter	}
170250495Sobrien
170350495Sobrien#ifdef DBX_USE_BINCL
1704132727Skan      emit_pending_bincls_if_required ();
170550495Sobrien      typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
170650495Sobrien	= current_file->file_number;
170750495Sobrien      typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
170850495Sobrien	= current_file->next_type_number++;
170950495Sobrien#endif
171018334Speter    }
171118334Speter
1712132727Skan  if (flag_debug_only_used_symbols)
1713132727Skan    {
1714132727Skan      if ((TREE_CODE (type) == RECORD_TYPE
1715132727Skan	   || TREE_CODE (type) == UNION_TYPE
1716132727Skan	   || TREE_CODE (type) == QUAL_UNION_TYPE
1717132727Skan	   || TREE_CODE (type) == ENUMERAL_TYPE)
1718132727Skan	  && TYPE_STUB_DECL (type)
1719169699Skan	  && DECL_P (TYPE_STUB_DECL (type))
1720132727Skan	  && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1721132727Skan	debug_queue_symbol (TYPE_STUB_DECL (type));
1722132727Skan      else if (TYPE_NAME (type)
1723132727Skan	       && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1724132727Skan	debug_queue_symbol (TYPE_NAME (type));
1725132727Skan    }
1726132727Skan
172718334Speter  /* Output the number of this type, to refer to it.  */
172850495Sobrien  dbxout_type_index (type);
172918334Speter
173018334Speter#ifdef DBX_TYPE_DEFINED
173118334Speter  if (DBX_TYPE_DEFINED (type))
173218334Speter    return;
173318334Speter#endif
173418334Speter
173518334Speter  /* If this type's definition has been output or is now being output,
173618334Speter     that is all.  */
173718334Speter
173850495Sobrien  switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
173918334Speter    {
174018334Speter    case TYPE_UNSEEN:
174118334Speter      break;
174218334Speter    case TYPE_XREF:
174318334Speter      /* If we have already had a cross reference,
174418334Speter	 and either that's all we want or that's the best we could do,
174518334Speter	 don't repeat the cross reference.
174618334Speter	 Sun dbx crashes if we do.  */
174790085Sobrien      if (! full || !COMPLETE_TYPE_P (type)
174818334Speter	  /* No way in DBX fmt to describe a variable size.  */
174990085Sobrien	  || ! host_integerp (TYPE_SIZE (type), 1))
175018334Speter	return;
175118334Speter      break;
175218334Speter    case TYPE_DEFINED:
175318334Speter      return;
175418334Speter    }
175518334Speter
175618334Speter#ifdef DBX_NO_XREFS
175718334Speter  /* For systems where dbx output does not allow the `=xsNAME:' syntax,
175818334Speter     leave the type-number completely undefined rather than output
175918334Speter     a cross-reference.  If we have already used GNU debug info extensions,
176018334Speter     then it is OK to output a cross reference.  This is necessary to get
176118334Speter     proper C++ debug output.  */
176218334Speter  if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
176318334Speter       || TREE_CODE (type) == QUAL_UNION_TYPE
176418334Speter       || TREE_CODE (type) == ENUMERAL_TYPE)
176518334Speter      && ! use_gnu_debug_info_extensions)
176618334Speter    /* We must use the same test here as we use twice below when deciding
176718334Speter       whether to emit a cross-reference.  */
176818334Speter    if ((TYPE_NAME (type) != 0
176918334Speter	 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
177018334Speter	       && DECL_IGNORED_P (TYPE_NAME (type)))
177118334Speter	 && !full)
177290085Sobrien	|| !COMPLETE_TYPE_P (type)
177318334Speter	/* No way in DBX fmt to describe a variable size.  */
177490085Sobrien	|| ! host_integerp (TYPE_SIZE (type), 1))
177518334Speter      {
177650495Sobrien	typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
177718334Speter	return;
177818334Speter      }
177918334Speter#endif
178018334Speter
178118334Speter  /* Output a definition now.  */
1782169699Skan  stabstr_C ('=');
178318334Speter
178418334Speter  /* Mark it as defined, so that if it is self-referent
178518334Speter     we will not get into an infinite recursion of definitions.  */
178618334Speter
178750495Sobrien  typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
178818334Speter
178990085Sobrien  /* If this type is a variant of some other, hand off.  Types with
179090085Sobrien     different names are usefully distinguished.  We only distinguish
179190085Sobrien     cv-qualified types if we're using extensions.  */
179290085Sobrien  if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
179390085Sobrien    {
1794169699Skan      stabstr_C ('k');
179590085Sobrien      dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
179650495Sobrien      return;
179750495Sobrien    }
179890085Sobrien  else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
179990085Sobrien    {
1800169699Skan      stabstr_C ('B');
180190085Sobrien      dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
180290085Sobrien      return;
180390085Sobrien    }
180490085Sobrien  else if (main_variant != TYPE_MAIN_VARIANT (type))
180590085Sobrien    {
1806132727Skan      if (flag_debug_only_used_symbols)
1807132727Skan        {
1808132727Skan          tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1809132727Skan
1810132727Skan          if ((TREE_CODE (orig_type) == RECORD_TYPE
1811132727Skan               || TREE_CODE (orig_type) == UNION_TYPE
1812132727Skan               || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1813132727Skan               || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1814132727Skan              && TYPE_STUB_DECL (orig_type)
1815132727Skan              && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1816132727Skan            debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1817132727Skan        }
181890085Sobrien      /* 'type' is a typedef; output the type it refers to.  */
181990085Sobrien      dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
182090085Sobrien      return;
182190085Sobrien    }
182290085Sobrien  /* else continue.  */
182350495Sobrien
182418334Speter  switch (TREE_CODE (type))
182518334Speter    {
182618334Speter    case VOID_TYPE:
182718334Speter    case LANG_TYPE:
1828261188Spfg      /* APPLE LOCAL blocks 6034272 */
1829261188Spfg    case BLOCK_POINTER_TYPE:
1830169699Skan      /* For a void type, just define it as itself; i.e., "5=5".
183118334Speter	 This makes us consider it defined
183218334Speter	 without saying what it is.  The debugger will make it
183318334Speter	 a void type when the reference is seen, and nothing will
183418334Speter	 ever override that default.  */
183550495Sobrien      dbxout_type_index (type);
183618334Speter      break;
183718334Speter
183818334Speter    case INTEGER_TYPE:
1839169699Skan      if (type == char_type_node && ! TYPE_UNSIGNED (type))
184050495Sobrien	{
184150495Sobrien	  /* Output the type `char' as a subrange of itself!
184250495Sobrien	     I don't understand this definition, just copied it
184350495Sobrien	     from the output of pcc.
184450495Sobrien	     This used to use `r2' explicitly and we used to
184550495Sobrien	     take care to make sure that `char' was type number 2.  */
1846169699Skan	  stabstr_C ('r');
184750495Sobrien	  dbxout_type_index (type);
1848169699Skan	  stabstr_S (";0;127;");
184950495Sobrien	}
185090085Sobrien
185190085Sobrien      /* If this is a subtype of another integer type, always prefer to
185290085Sobrien	 write it as a subtype.  */
185390085Sobrien      else if (TREE_TYPE (type) != 0
185490085Sobrien	       && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1855117404Skan	{
185696280Sobrien	  /* If the size is non-standard, say what it is if we can use
185796280Sobrien	     GDB extensions.  */
185890085Sobrien
185996280Sobrien	  if (use_gnu_debug_info_extensions
186096280Sobrien	      && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
186196280Sobrien	    {
1862169699Skan	      stabstr_S ("@s");
1863169699Skan	      stabstr_D (TYPE_PRECISION (type));
1864169699Skan	      stabstr_C (';');
186596280Sobrien	    }
186696280Sobrien
186796280Sobrien	  dbxout_range_type (type);
1868117404Skan	}
186996280Sobrien
187090085Sobrien      else
1871117404Skan	{
187290085Sobrien	  /* If the size is non-standard, say what it is if we can use
187390085Sobrien	     GDB extensions.  */
187490085Sobrien
187590085Sobrien	  if (use_gnu_debug_info_extensions
187690085Sobrien	      && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
187790085Sobrien	    {
1878169699Skan	      stabstr_S ("@s");
1879169699Skan	      stabstr_D (TYPE_PRECISION (type));
1880169699Skan	      stabstr_C (';');
188190085Sobrien	    }
188290085Sobrien
1883132727Skan	  if (print_int_cst_bounds_in_octal_p (type))
188490085Sobrien	    {
1885169699Skan	      stabstr_C ('r');
1886132727Skan
1887132727Skan              /* If this type derives from another type, output type index of
1888132727Skan		 parent type. This is particularly important when parent type
1889132727Skan		 is an enumerated type, because not generating the parent type
1890132727Skan		 index would transform the definition of this enumerated type
1891132727Skan		 into a plain unsigned type.  */
1892132727Skan              if (TREE_TYPE (type) != 0)
1893132727Skan                dbxout_type_index (TREE_TYPE (type));
1894132727Skan              else
1895132727Skan                dbxout_type_index (type);
1896132727Skan
1897169699Skan	      stabstr_C (';');
1898169699Skan	      stabstr_O (TYPE_MIN_VALUE (type));
1899169699Skan	      stabstr_C (';');
1900169699Skan	      stabstr_O (TYPE_MAX_VALUE (type));
1901169699Skan	      stabstr_C (';');
190290085Sobrien	    }
190390085Sobrien
190490085Sobrien	  else
190590085Sobrien	    /* Output other integer types as subranges of `int'.  */
190690085Sobrien	    dbxout_range_type (type);
1907117404Skan	}
190890085Sobrien
190918334Speter      break;
191018334Speter
191118334Speter    case REAL_TYPE:
191218334Speter      /* This used to say `r1' and we used to take care
191318334Speter	 to make sure that `int' was type number 1.  */
1914169699Skan      stabstr_C ('r');
191550495Sobrien      dbxout_type_index (integer_type_node);
1916169699Skan      stabstr_C (';');
1917169699Skan      stabstr_D (int_size_in_bytes (type));
1918169699Skan      stabstr_S (";0;");
191918334Speter      break;
192018334Speter
192118334Speter    case BOOLEAN_TYPE:
192218334Speter      if (use_gnu_debug_info_extensions)
192350495Sobrien	{
1924169699Skan	  stabstr_S ("@s");
1925169699Skan	  stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1926169699Skan	  stabstr_S (";-16;");
192750495Sobrien	}
192818334Speter      else /* Define as enumeral type (False, True) */
1929169699Skan	stabstr_S ("eFalse:0,True:1,;");
193018334Speter      break;
193118334Speter
193218334Speter    case COMPLEX_TYPE:
1933132727Skan      /* Differs from the REAL_TYPE by its new data type number.
1934132727Skan	 R3 is NF_COMPLEX.  We don't try to use any of the other NF_*
1935132727Skan	 codes since gdb doesn't care anyway.  */
193618334Speter
193718334Speter      if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
193818334Speter	{
1939169699Skan	  stabstr_S ("R3;");
1940169699Skan	  stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type)));
1941169699Skan	  stabstr_S (";0;");
194218334Speter	}
194318334Speter      else
194418334Speter	{
194518334Speter	  /* Output a complex integer type as a structure,
194618334Speter	     pending some other way to do it.  */
1947169699Skan	  stabstr_C ('s');
1948169699Skan	  stabstr_D (int_size_in_bytes (type));
194918334Speter
1950169699Skan	  stabstr_S ("real:");
195190085Sobrien	  dbxout_type (TREE_TYPE (type), 0);
1952169699Skan	  stabstr_S (",0,");
1953169699Skan	  stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1954169699Skan
1955169699Skan	  stabstr_S (";imag:");
195690085Sobrien	  dbxout_type (TREE_TYPE (type), 0);
1957169699Skan	  stabstr_C (',');
1958169699Skan	  stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1959169699Skan	  stabstr_C (',');
1960169699Skan	  stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1961169699Skan	  stabstr_S (";;");
196218334Speter	}
196318334Speter      break;
196418334Speter
196518334Speter    case ARRAY_TYPE:
196650495Sobrien      /* Make arrays of packed bits look like bitstrings for chill.  */
196750495Sobrien      if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
196850495Sobrien	{
1969169699Skan	  stabstr_S ("@s");
1970169699Skan	  stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1971169699Skan	  stabstr_S (";@S;S");
197290085Sobrien	  dbxout_type (TYPE_DOMAIN (type), 0);
197350495Sobrien	  break;
197450495Sobrien	}
197590085Sobrien
1976169699Skan      if (use_gnu_debug_info_extensions && vector_type)
1977169699Skan	stabstr_S ("@V;");
1978169699Skan
197918334Speter      /* Output "a" followed by a range type definition
198018334Speter	 for the index type of the array
198118334Speter	 followed by a reference to the target-type.
198218334Speter	 ar1;0;N;M for a C array of type M and size N+1.  */
198318334Speter      /* Check if a character string type, which in Chill is
198450495Sobrien	 different from an array of characters.  */
198518334Speter      if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
198618334Speter	{
1987169699Skan	  stabstr_S ("@S;");
198818334Speter	}
198918334Speter      tem = TYPE_DOMAIN (type);
199018334Speter      if (tem == NULL)
199150495Sobrien	{
1992169699Skan	  stabstr_S ("ar");
199350495Sobrien	  dbxout_type_index (integer_type_node);
1994169699Skan	  stabstr_S (";0;-1;");
199550495Sobrien	}
199618334Speter      else
199718334Speter	{
1998169699Skan	  stabstr_C ('a');
199918334Speter	  dbxout_range_type (tem);
200018334Speter	}
200190085Sobrien
200290085Sobrien      dbxout_type (TREE_TYPE (type), 0);
200318334Speter      break;
200418334Speter
200518334Speter    case RECORD_TYPE:
200618334Speter    case UNION_TYPE:
200718334Speter    case QUAL_UNION_TYPE:
200818334Speter      {
2009169699Skan	tree binfo = TYPE_BINFO (type);
201018334Speter
201118334Speter	/* Output a structure type.  We must use the same test here as we
201218334Speter	   use in the DBX_NO_XREFS case above.  */
201318334Speter	if ((TYPE_NAME (type) != 0
201418334Speter	     && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
201518334Speter		   && DECL_IGNORED_P (TYPE_NAME (type)))
201618334Speter	     && !full)
201790085Sobrien	    || !COMPLETE_TYPE_P (type)
201818334Speter	    /* No way in DBX fmt to describe a variable size.  */
201990085Sobrien	    || ! host_integerp (TYPE_SIZE (type), 1))
202018334Speter	  {
202118334Speter	    /* If the type is just a cross reference, output one
202218334Speter	       and mark the type as partially described.
202318334Speter	       If it later becomes defined, we will output
202418334Speter	       its real definition.
202518334Speter	       If the type has a name, don't nest its definition within
202618334Speter	       another type's definition; instead, output an xref
202718334Speter	       and let the definition come when the name is defined.  */
2028169699Skan	    stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
202918334Speter	    if (TYPE_NAME (type) != 0)
203018334Speter	      dbxout_type_name (type);
203118334Speter	    else
203290085Sobrien	      {
2033169699Skan		stabstr_S ("$$");
2034169699Skan		stabstr_D (anonymous_type_number++);
203590085Sobrien	      }
203690085Sobrien
2037169699Skan	    stabstr_C (':');
203850495Sobrien	    typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
203918334Speter	    break;
204018334Speter	  }
204118334Speter
204218334Speter	/* Identify record or union, and print its size.  */
2043169699Skan	stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u');
2044169699Skan	stabstr_D (int_size_in_bytes (type));
204518334Speter
2046169699Skan	if (binfo)
204718334Speter	  {
2048169699Skan	    int i;
2049169699Skan	    tree child;
2050169699Skan	    VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
2051169699Skan
2052169699Skan	    if (use_gnu_debug_info_extensions)
205318334Speter	      {
2054169699Skan		if (BINFO_N_BASE_BINFOS (binfo))
2055169699Skan		  {
2056169699Skan		    stabstr_C ('!');
2057169699Skan		    stabstr_U (BINFO_N_BASE_BINFOS (binfo));
2058169699Skan		    stabstr_C (',');
2059169699Skan		  }
206018334Speter	      }
2061169699Skan	    for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
2062169699Skan	      {
2063169699Skan		tree access = (accesses ? VEC_index (tree, accesses, i)
2064169699Skan			       : access_public_node);
206590085Sobrien
2066169699Skan		if (use_gnu_debug_info_extensions)
2067169699Skan		  {
2068169699Skan		    stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0');
2069169699Skan		    stabstr_C (access == access_public_node ? '2' :
2070169699Skan				   access == access_protected_node
2071169699Skan				   ? '1' :'0');
2072169699Skan		    if (BINFO_VIRTUAL_P (child)
2073169699Skan			&& (strcmp (lang_hooks.name, "GNU C++") == 0
2074169699Skan			    || strcmp (lang_hooks.name, "GNU Objective-C++") == 0))
2075169699Skan		      /* For a virtual base, print the (negative)
2076169699Skan		     	 offset within the vtable where we must look
2077169699Skan		     	 to find the necessary adjustment.  */
2078169699Skan		      stabstr_D
2079169699Skan			(tree_low_cst (BINFO_VPTR_FIELD (child), 0)
2080169699Skan			 * BITS_PER_UNIT);
2081169699Skan		    else
2082169699Skan		      stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2083169699Skan				       * BITS_PER_UNIT);
2084169699Skan		    stabstr_C (',');
2085169699Skan		    dbxout_type (BINFO_TYPE (child), 0);
2086169699Skan		    stabstr_C (';');
2087169699Skan		  }
208890085Sobrien		else
2089169699Skan		  {
2090169699Skan		    /* Print out the base class information with
2091169699Skan		       fields which have the same names at the types
2092169699Skan		       they hold.  */
2093169699Skan		    dbxout_type_name (BINFO_TYPE (child));
2094169699Skan		    stabstr_C (':');
2095169699Skan		    dbxout_type (BINFO_TYPE (child), full);
2096169699Skan		    stabstr_C (',');
2097169699Skan		    stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2098169699Skan				     * BITS_PER_UNIT);
2099169699Skan		    stabstr_C (',');
2100169699Skan		    stabstr_D
2101169699Skan		      (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)), 0)
2102169699Skan		       * BITS_PER_UNIT);
2103169699Skan		    stabstr_C (';');
2104169699Skan		  }
210518334Speter	      }
210618334Speter	  }
210718334Speter      }
210818334Speter
210918334Speter      /* Write out the field declarations.  */
211018334Speter      dbxout_type_fields (type);
211118334Speter      if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
211218334Speter	{
211318334Speter	  dbxout_type_methods (type);
211418334Speter	}
211590085Sobrien
2116169699Skan      stabstr_C (';');
211718334Speter
211818334Speter      if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
211918334Speter	  /* Avoid the ~ if we don't really need it--it confuses dbx.  */
212018334Speter	  && TYPE_VFIELD (type))
212118334Speter	{
212218334Speter
212318334Speter	  /* We need to write out info about what field this class
212418334Speter	     uses as its "main" vtable pointer field, because if this
212518334Speter	     field is inherited from a base class, GDB cannot necessarily
212618334Speter	     figure out which field it's using in time.  */
2127169699Skan	  stabstr_S ("~%");
2128169699Skan	  dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
2129169699Skan	  stabstr_C (';');
213018334Speter	}
213118334Speter      break;
213218334Speter
213318334Speter    case ENUMERAL_TYPE:
213418334Speter      /* We must use the same test here as we use in the DBX_NO_XREFS case
213518334Speter	 above.  We simplify it a bit since an enum will never have a variable
213618334Speter	 size.  */
213718334Speter      if ((TYPE_NAME (type) != 0
213818334Speter	   && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
213918334Speter		 && DECL_IGNORED_P (TYPE_NAME (type)))
214018334Speter	   && !full)
214190085Sobrien	  || !COMPLETE_TYPE_P (type))
214218334Speter	{
2143169699Skan	  stabstr_S ("xe");
214418334Speter	  dbxout_type_name (type);
214550495Sobrien	  typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2146169699Skan	  stabstr_C (':');
214718334Speter	  return;
214818334Speter	}
214918334Speter      if (use_gnu_debug_info_extensions
215018334Speter	  && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
215190085Sobrien	{
2152169699Skan	  stabstr_S ("@s");
2153169699Skan	  stabstr_D (TYPE_PRECISION (type));
2154169699Skan	  stabstr_C (';');
215590085Sobrien	}
215690085Sobrien
2157169699Skan      stabstr_C ('e');
215818334Speter      for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
215918334Speter	{
2160169699Skan	  stabstr_I (TREE_PURPOSE (tem));
2161169699Skan	  stabstr_C (':');
2162169699Skan
216318334Speter	  if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
2164169699Skan	    stabstr_D (TREE_INT_CST_LOW (TREE_VALUE (tem)));
216518334Speter	  else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
216690085Sobrien		   && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
2167169699Skan	    stabstr_D (TREE_INT_CST_LOW (TREE_VALUE (tem)));
216818334Speter	  else
2169169699Skan	    stabstr_O (TREE_VALUE (tem));
217090085Sobrien
2171169699Skan	  stabstr_C (',');
217218334Speter	  if (TREE_CHAIN (tem) != 0)
217390085Sobrien	    CONTIN;
217418334Speter	}
217590085Sobrien
2176169699Skan      stabstr_C (';');
217718334Speter      break;
217818334Speter
217918334Speter    case POINTER_TYPE:
2180169699Skan      stabstr_C ('*');
218190085Sobrien      dbxout_type (TREE_TYPE (type), 0);
218218334Speter      break;
218318334Speter
218418334Speter    case METHOD_TYPE:
218518334Speter      if (use_gnu_debug_info_extensions)
218618334Speter	{
2187169699Skan	  stabstr_C ('#');
218890085Sobrien
218990085Sobrien	  /* Write the argument types out longhand.  */
219090085Sobrien	  dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
2191169699Skan	  stabstr_C (',');
219290085Sobrien	  dbxout_type (TREE_TYPE (type), 0);
219390085Sobrien	  dbxout_args (TYPE_ARG_TYPES (type));
2194169699Skan	  stabstr_C (';');
219518334Speter	}
219618334Speter      else
219790085Sobrien	/* Treat it as a function type.  */
219890085Sobrien	dbxout_type (TREE_TYPE (type), 0);
219918334Speter      break;
220018334Speter
220118334Speter    case OFFSET_TYPE:
220218334Speter      if (use_gnu_debug_info_extensions)
220318334Speter	{
2204169699Skan	  stabstr_C ('@');
220590085Sobrien	  dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
2206169699Skan	  stabstr_C (',');
220790085Sobrien	  dbxout_type (TREE_TYPE (type), 0);
220818334Speter	}
220918334Speter      else
221090085Sobrien	/* Should print as an int, because it is really just an offset.  */
221190085Sobrien	dbxout_type (integer_type_node, 0);
221218334Speter      break;
221318334Speter
221418334Speter    case REFERENCE_TYPE:
221518334Speter      if (use_gnu_debug_info_extensions)
2216169699Skan	{
2217169699Skan	  stabstr_C ('&');
2218169699Skan	}
2219169699Skan      else
2220169699Skan	stabstr_C ('*');
222190085Sobrien      dbxout_type (TREE_TYPE (type), 0);
222218334Speter      break;
222318334Speter
222418334Speter    case FUNCTION_TYPE:
2225169699Skan      stabstr_C ('f');
222690085Sobrien      dbxout_type (TREE_TYPE (type), 0);
222718334Speter      break;
222818334Speter
222918334Speter    default:
2230169699Skan      gcc_unreachable ();
223118334Speter    }
223218334Speter}
223318334Speter
2234132727Skan/* Return nonzero if the given type represents an integer whose bounds
2235132727Skan   should be printed in octal format.  */
2236132727Skan
2237132727Skanstatic bool
2238132727Skanprint_int_cst_bounds_in_octal_p (tree type)
2239132727Skan{
2240132727Skan  /* If we can use GDB extensions and the size is wider than a long
2241132727Skan     (the size used by GDB to read them) or we may have trouble writing
2242132727Skan     the bounds the usual way, write them in octal.  Note the test is for
2243132727Skan     the *target's* size of "long", not that of the host.  The host test
2244132727Skan     is just to make sure we can write it out in case the host wide int
2245132727Skan     is narrower than the target "long".
2246132727Skan
2247132727Skan     For unsigned types, we use octal if they are the same size or larger.
2248132727Skan     This is because we print the bounds as signed decimal, and hence they
2249132727Skan     can't span same size unsigned types.  */
2250132727Skan
2251132727Skan  if (use_gnu_debug_info_extensions
2252132727Skan      && TYPE_MIN_VALUE (type) != 0
2253132727Skan      && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
2254132727Skan      && TYPE_MAX_VALUE (type) != 0
2255132727Skan      && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
2256132727Skan      && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
2257132727Skan	  || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2258169699Skan	      && TYPE_UNSIGNED (type))
2259132727Skan	  || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
2260132727Skan	  || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
2261169699Skan	      && TYPE_UNSIGNED (type))))
2262132727Skan    return TRUE;
2263132727Skan  else
2264132727Skan    return FALSE;
2265132727Skan}
2266132727Skan
2267169699Skan/* Output the name of type TYPE, with no punctuation.
2268169699Skan   Such names can be set up either by typedef declarations
2269169699Skan   or by struct, enum and union tags.  */
227018334Speter
227118334Speterstatic void
2272169699Skandbxout_type_name (tree type)
227318334Speter{
2274169699Skan  tree t = TYPE_NAME (type);
2275169699Skan
2276169699Skan  gcc_assert (t);
2277169699Skan  switch (TREE_CODE (t))
2278169699Skan    {
2279169699Skan    case IDENTIFIER_NODE:
2280169699Skan      break;
2281169699Skan    case TYPE_DECL:
2282169699Skan      t = DECL_NAME (t);
2283169699Skan      break;
2284169699Skan    default:
2285169699Skan      gcc_unreachable ();
2286169699Skan    }
228718334Speter
2288169699Skan  stabstr_I (t);
2289169699Skan}
229018334Speter
2291169699Skan/* Output leading leading struct or class names needed for qualifying
2292169699Skan   type whose scope is limited to a struct or class.  */
229318334Speter
2294169699Skanstatic void
2295169699Skandbxout_class_name_qualifiers (tree decl)
2296169699Skan{
2297169699Skan  tree context = decl_type_context (decl);
2298169699Skan
2299169699Skan  if (context != NULL_TREE
2300169699Skan      && TREE_CODE(context) == RECORD_TYPE
2301169699Skan      && TYPE_NAME (context) != 0
2302169699Skan      && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2303169699Skan          || (DECL_NAME (TYPE_NAME (context)) != 0)))
230418334Speter    {
2305169699Skan      tree name = TYPE_NAME (context);
230618334Speter
2307169699Skan      if (TREE_CODE (name) == TYPE_DECL)
2308169699Skan	{
2309169699Skan	  dbxout_class_name_qualifiers (name);
2310169699Skan	  name = DECL_NAME (name);
2311169699Skan	}
2312169699Skan      stabstr_I (name);
2313169699Skan      stabstr_S ("::");
231418334Speter    }
231518334Speter}
2316169699Skan
2317169699Skan/* This is a specialized subset of expand_expr for use by dbxout_symbol in
2318169699Skan   evaluating DECL_VALUE_EXPR.  In particular, we stop if we find decls that
2319169699Skan   havn't been expanded, or if the expression is getting so complex we won't
2320169699Skan   be able to represent it in stabs anyway.  Returns NULL on failure.  */
232118334Speter
2322169699Skanstatic rtx
2323169699Skandbxout_expand_expr (tree expr)
232418334Speter{
2325169699Skan  switch (TREE_CODE (expr))
2326169699Skan    {
2327169699Skan    case VAR_DECL:
2328169699Skan    case PARM_DECL:
2329169699Skan      if (DECL_HAS_VALUE_EXPR_P (expr))
2330169699Skan	return dbxout_expand_expr (DECL_VALUE_EXPR (expr));
2331169699Skan      /* FALLTHRU */
233218334Speter
2333169699Skan    case CONST_DECL:
2334169699Skan    case RESULT_DECL:
2335169699Skan      return DECL_RTL_IF_SET (expr);
233690085Sobrien
2337169699Skan    case INTEGER_CST:
2338169699Skan      return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
2339169699Skan
2340169699Skan    case COMPONENT_REF:
2341169699Skan    case ARRAY_REF:
2342169699Skan    case ARRAY_RANGE_REF:
2343169699Skan    case BIT_FIELD_REF:
2344169699Skan      {
2345169699Skan	enum machine_mode mode;
2346169699Skan	HOST_WIDE_INT bitsize, bitpos;
2347169699Skan	tree offset, tem;
2348169699Skan	int volatilep = 0, unsignedp = 0;
2349169699Skan	rtx x;
2350169699Skan
2351169699Skan	tem = get_inner_reference (expr, &bitsize, &bitpos, &offset,
2352169699Skan				   &mode, &unsignedp, &volatilep, true);
2353169699Skan
2354169699Skan	x = dbxout_expand_expr (tem);
2355169699Skan	if (x == NULL || !MEM_P (x))
2356169699Skan	  return NULL;
2357169699Skan	if (offset != NULL)
2358169699Skan	  {
2359169699Skan	    if (!host_integerp (offset, 0))
2360169699Skan	      return NULL;
2361169699Skan	    x = adjust_address_nv (x, mode, tree_low_cst (offset, 0));
2362169699Skan	  }
2363169699Skan	if (bitpos != 0)
2364169699Skan	  x = adjust_address_nv (x, mode, bitpos / BITS_PER_UNIT);
2365169699Skan
2366169699Skan	return x;
2367169699Skan      }
2368169699Skan
2369169699Skan    default:
2370169699Skan      return NULL;
2371169699Skan    }
237218334Speter}
237318334Speter
2374169699Skan/* Helper function for output_used_types.  Queue one entry from the
2375169699Skan   used types hash to be output.  */
237690085Sobrien
2377169699Skanstatic int
2378169699Skanoutput_used_types_helper (void **slot, void *data)
237990085Sobrien{
2380169699Skan  tree type = *slot;
2381169699Skan  VEC(tree, heap) **types_p = data;
238290085Sobrien
2383169699Skan  if ((TREE_CODE (type) == RECORD_TYPE
2384169699Skan       || TREE_CODE (type) == UNION_TYPE
2385169699Skan       || TREE_CODE (type) == QUAL_UNION_TYPE
2386169699Skan       || TREE_CODE (type) == ENUMERAL_TYPE)
2387169699Skan      && TYPE_STUB_DECL (type)
2388169699Skan      && DECL_P (TYPE_STUB_DECL (type))
2389169699Skan      && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
2390169699Skan    VEC_quick_push (tree, *types_p, TYPE_STUB_DECL (type));
2391169699Skan  else if (TYPE_NAME (type)
2392169699Skan	   && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2393169699Skan    VEC_quick_push (tree, *types_p, TYPE_NAME (type));
239490085Sobrien
2395169699Skan  return 1;
239690085Sobrien}
2397117404Skan
2398169699Skan/* This is a qsort callback which sorts types and declarations into a
2399169699Skan   predictable order (types, then declarations, sorted by UID
2400169699Skan   within).  */
240118334Speter
2402169699Skanstatic int
2403169699Skanoutput_types_sort (const void *pa, const void *pb)
240418334Speter{
2405169699Skan  const tree lhs = *((const tree *)pa);
2406169699Skan  const tree rhs = *((const tree *)pb);
2407169699Skan
2408169699Skan  if (TYPE_P (lhs))
240918334Speter    {
2410169699Skan      if (TYPE_P (rhs))
2411169699Skan	return TYPE_UID (lhs) - TYPE_UID (rhs);
2412169699Skan      else
2413169699Skan	return 1;
241418334Speter    }
2415169699Skan  else
241618334Speter    {
2417169699Skan      if (TYPE_P (rhs))
2418169699Skan	return -1;
2419169699Skan      else
2420169699Skan	return DECL_UID (lhs) - DECL_UID (rhs);
242118334Speter    }
242218334Speter}
2423117404Skan
2424117404Skan
2425169699Skan/* Force all types used by this function to be output in debug
2426169699Skan   information.  */
2427169699Skan
2428117404Skanstatic void
2429169699Skanoutput_used_types (void)
2430117404Skan{
2431169699Skan  if (cfun && cfun->used_types_hash)
2432117404Skan    {
2433169699Skan      VEC(tree, heap) *types;
2434169699Skan      int i;
2435169699Skan      tree type;
2436117404Skan
2437169699Skan      types = VEC_alloc (tree, heap, htab_elements (cfun->used_types_hash));
2438169699Skan      htab_traverse (cfun->used_types_hash, output_used_types_helper, &types);
2439132727Skan
2440169699Skan      /* Sort by UID to prevent dependence on hash table ordering.  */
2441169699Skan      qsort (VEC_address (tree, types), VEC_length (tree, types),
2442169699Skan	     sizeof (tree), output_types_sort);
2443169699Skan
2444169699Skan      for (i = 0; VEC_iterate (tree, types, i, type); i++)
2445169699Skan	debug_queue_symbol (type);
2446169699Skan
2447169699Skan      VEC_free (tree, heap, types);
2448117404Skan    }
2449117404Skan}
2450169699Skan
245118334Speter/* Output a .stabs for the symbol defined by DECL,
245218334Speter   which must be a ..._DECL node in the normal namespace.
245318334Speter   It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
245490085Sobrien   LOCAL is nonzero if the scope is less than the entire file.
245590085Sobrien   Return 1 if a stabs might have been emitted.  */
245618334Speter
245790085Sobrienint
2458132727Skandbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
245918334Speter{
246018334Speter  tree type = TREE_TYPE (decl);
246118334Speter  tree context = NULL_TREE;
246290085Sobrien  int result = 0;
2463169699Skan  rtx decl_rtl;
246418334Speter
2465132727Skan  /* "Intercept" dbxout_symbol() calls like we do all debug_hooks.  */
2466132727Skan  ++debug_nesting;
246718334Speter
246818334Speter  /* Ignore nameless syms, but don't ignore type tags.  */
246918334Speter
247018334Speter  if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
247118334Speter      || DECL_IGNORED_P (decl))
2472132727Skan    DBXOUT_DECR_NESTING_AND_RETURN (0);
247318334Speter
2474132727Skan  /* If we are to generate only the symbols actually used then such
2475169699Skan     symbol nodes are flagged with TREE_USED.  Ignore any that
2476132727Skan     aren't flaged as TREE_USED.  */
2477132727Skan
2478169699Skan  if (flag_debug_only_used_symbols
2479169699Skan      && (!TREE_USED (decl)
2480169699Skan          && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2481169699Skan    DBXOUT_DECR_NESTING_AND_RETURN (0);
2482169699Skan
2483169699Skan  /* If dbxout_init has not yet run, queue this symbol for later.  */
2484169699Skan  if (!typevec)
2485169699Skan    {
2486169699Skan      preinit_symbols = tree_cons (0, decl, preinit_symbols);
2487169699Skan      DBXOUT_DECR_NESTING_AND_RETURN (0);
2488169699Skan    }
2489169699Skan
2490132727Skan  if (flag_debug_only_used_symbols)
2491132727Skan    {
2492132727Skan      tree t;
2493132727Skan
2494132727Skan      /* We now have a used symbol.  We need to generate the info for
2495132727Skan         the symbol's type in addition to the symbol itself.  These
2496132727Skan         type symbols are queued to be generated after were done with
2497169699Skan         the symbol itself (otherwise they would fight over the
2498169699Skan         stabstr obstack).
2499132727Skan
2500132727Skan         Note, because the TREE_TYPE(type) might be something like a
2501132727Skan         pointer to a named type we need to look for the first name
2502132727Skan         we see following the TREE_TYPE chain.  */
2503132727Skan
2504132727Skan      t = type;
2505132727Skan      while (POINTER_TYPE_P (t))
2506132727Skan        t = TREE_TYPE (t);
2507132727Skan
2508132727Skan      /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2509132727Skan         need special treatment.  The TYPE_STUB_DECL field in these
2510132727Skan         types generally represents the tag name type we want to
2511132727Skan         output.  In addition there  could be a typedef type with
2512132727Skan         a different name.  In that case we also want to output
2513132727Skan         that.  */
2514132727Skan
2515169699Skan      if (TREE_CODE (t) == RECORD_TYPE
2516132727Skan           || TREE_CODE (t) == UNION_TYPE
2517132727Skan           || TREE_CODE (t) == QUAL_UNION_TYPE
2518132727Skan           || TREE_CODE (t) == ENUMERAL_TYPE)
2519132727Skan        {
2520169699Skan	    if (TYPE_STUB_DECL (t)
2521169699Skan		&& TYPE_STUB_DECL (t) != decl
2522169699Skan		&& DECL_P (TYPE_STUB_DECL (t))
2523169699Skan		&& ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2524169699Skan	    {
2525169699Skan	      debug_queue_symbol (TYPE_STUB_DECL (t));
2526169699Skan	      if (TYPE_NAME (t)
2527169699Skan		  && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2528169699Skan		  && TYPE_NAME (t) != decl
2529169699Skan		  && DECL_P (TYPE_NAME (t)))
2530169699Skan		debug_queue_symbol (TYPE_NAME (t));
2531169699Skan	    }
2532169699Skan	}
2533132727Skan      else if (TYPE_NAME (t)
2534132727Skan	       && TYPE_NAME (t) != decl
2535169699Skan	       && DECL_P (TYPE_NAME (t)))
2536132727Skan        debug_queue_symbol (TYPE_NAME (t));
2537132727Skan    }
2538132727Skan
2539132727Skan  emit_pending_bincls_if_required ();
2540132727Skan
254118334Speter  switch (TREE_CODE (decl))
254218334Speter    {
254318334Speter    case CONST_DECL:
254418334Speter      /* Enum values are defined by defining the enum type.  */
254518334Speter      break;
254618334Speter
254718334Speter    case FUNCTION_DECL:
2548169699Skan      decl_rtl = DECL_RTL_IF_SET (decl);
2549169699Skan      if (!decl_rtl)
2550132727Skan	DBXOUT_DECR_NESTING_AND_RETURN (0);
255118334Speter      if (DECL_EXTERNAL (decl))
255218334Speter	break;
255318334Speter      /* Don't mention a nested function under its parent.  */
255418334Speter      context = decl_function_context (decl);
255518334Speter      if (context == current_function_decl)
255618334Speter	break;
2557169699Skan      /* Don't mention an inline instance of a nested function.  */
2558169699Skan      if (context && DECL_FROM_INLINE (decl))
255918334Speter	break;
2560169699Skan      if (!MEM_P (decl_rtl)
2561169699Skan	  || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF)
2562169699Skan	break;
256318334Speter
2564169699Skan      if (flag_debug_only_used_symbols)
2565169699Skan	output_used_types ();
2566169699Skan
2567169699Skan      dbxout_begin_complex_stabs ();
2568169699Skan      stabstr_I (DECL_ASSEMBLER_NAME (decl));
2569169699Skan      stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f");
257090085Sobrien      result = 1;
257118334Speter
257218334Speter      if (TREE_TYPE (type))
257390085Sobrien	dbxout_type (TREE_TYPE (type), 0);
257418334Speter      else
257590085Sobrien	dbxout_type (void_type_node, 0);
257618334Speter
257718334Speter      /* For a nested function, when that function is compiled,
257818334Speter	 mention the containing function name
257918334Speter	 as well as (since dbx wants it) our own assembler-name.  */
258018334Speter      if (context != 0)
2581169699Skan	{
2582169699Skan	  stabstr_C (',');
2583169699Skan	  stabstr_I (DECL_ASSEMBLER_NAME (decl));
2584169699Skan	  stabstr_C (',');
2585169699Skan	  stabstr_I (DECL_NAME (context));
2586169699Skan	}
258718334Speter
2588169699Skan      dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0);
258918334Speter      break;
259018334Speter
259118334Speter    case TYPE_DECL:
259218334Speter      /* Don't output the same typedef twice.
259318334Speter         And don't output what language-specific stuff doesn't want output.  */
259418334Speter      if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2595132727Skan	DBXOUT_DECR_NESTING_AND_RETURN (0);
259618334Speter
2597169699Skan      /* Don't output typedefs for types with magic type numbers (XCOFF).  */
2598169699Skan#ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2599169699Skan      {
2600169699Skan	int fundamental_type_number =
2601169699Skan	  DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2602169699Skan
2603169699Skan	if (fundamental_type_number != 0)
2604169699Skan	  {
2605169699Skan	    TREE_ASM_WRITTEN (decl) = 1;
2606169699Skan	    TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2607169699Skan	    DBXOUT_DECR_NESTING_AND_RETURN (0);
2608169699Skan	  }
2609169699Skan      }
2610169699Skan#endif
261118334Speter      FORCE_TEXT;
261290085Sobrien      result = 1;
261318334Speter      {
261418334Speter	int tag_needed = 1;
261518334Speter	int did_output = 0;
261618334Speter
261718334Speter	if (DECL_NAME (decl))
261818334Speter	  {
261918334Speter	    /* Nonzero means we must output a tag as well as a typedef.  */
262018334Speter	    tag_needed = 0;
262118334Speter
262218334Speter	    /* Handle the case of a C++ structure or union
262318334Speter	       where the TYPE_NAME is a TYPE_DECL
262418334Speter	       which gives both a typedef name and a tag.  */
262518334Speter	    /* dbx requires the tag first and the typedef second.  */
262618334Speter	    if ((TREE_CODE (type) == RECORD_TYPE
262718334Speter		 || TREE_CODE (type) == UNION_TYPE
262818334Speter		 || TREE_CODE (type) == QUAL_UNION_TYPE)
262918334Speter		&& TYPE_NAME (type) == decl
2630169699Skan		&& !use_gnu_debug_info_extensions
263118334Speter		&& !TREE_ASM_WRITTEN (TYPE_NAME (type))
263218334Speter		/* Distinguish the implicit typedefs of C++
263318334Speter		   from explicit ones that might be found in C.  */
2634117404Skan		&& DECL_ARTIFICIAL (decl)
2635132727Skan                /* Do not generate a tag for incomplete records.  */
2636132727Skan                && COMPLETE_TYPE_P (type)
263790085Sobrien		/* Do not generate a tag for records of variable size,
263890085Sobrien		   since this type can not be properly described in the
263990085Sobrien		   DBX format, and it confuses some tools such as objdump.  */
264090085Sobrien		&& host_integerp (TYPE_SIZE (type), 1))
264118334Speter	      {
264218334Speter		tree name = TYPE_NAME (type);
264318334Speter		if (TREE_CODE (name) == TYPE_DECL)
264418334Speter		  name = DECL_NAME (name);
264518334Speter
2646169699Skan		dbxout_begin_complex_stabs ();
2647169699Skan		stabstr_I (name);
2648169699Skan		stabstr_S (":T");
264990085Sobrien		dbxout_type (type, 1);
2650169699Skan		dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
2651169699Skan					     0, 0, 0);
265218334Speter	      }
265318334Speter
2654169699Skan	    dbxout_begin_complex_stabs ();
2655117404Skan
2656169699Skan	    /* Output leading class/struct qualifiers.  */
2657117404Skan	    if (use_gnu_debug_info_extensions)
2658169699Skan	      dbxout_class_name_qualifiers (decl);
2659117404Skan
266018334Speter	    /* Output typedef name.  */
2661169699Skan	    stabstr_I (DECL_NAME (decl));
2662169699Skan	    stabstr_C (':');
266318334Speter
266418334Speter	    /* Short cut way to output a tag also.  */
266518334Speter	    if ((TREE_CODE (type) == RECORD_TYPE
266618334Speter		 || TREE_CODE (type) == UNION_TYPE
266718334Speter		 || TREE_CODE (type) == QUAL_UNION_TYPE)
266850495Sobrien		&& TYPE_NAME (type) == decl
266950495Sobrien		/* Distinguish the implicit typedefs of C++
267050495Sobrien		   from explicit ones that might be found in C.  */
2671117404Skan		&& DECL_ARTIFICIAL (decl))
267218334Speter	      {
2673169699Skan		if (use_gnu_debug_info_extensions)
267418334Speter		  {
2675169699Skan		    stabstr_C ('T');
267618334Speter		    TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
267718334Speter		  }
267818334Speter	      }
267918334Speter
2680169699Skan	    stabstr_C ('t');
268190085Sobrien	    dbxout_type (type, 1);
2682169699Skan	    dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
2683169699Skan					 0, 0, 0);
268418334Speter	    did_output = 1;
268518334Speter	  }
268618334Speter
268790085Sobrien	/* Don't output a tag if this is an incomplete type.  This prevents
268890085Sobrien	   the sun4 Sun OS 4.x dbx from crashing.  */
268918334Speter
269018334Speter	if (tag_needed && TYPE_NAME (type) != 0
269118334Speter	    && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
269218334Speter		|| (DECL_NAME (TYPE_NAME (type)) != 0))
269390085Sobrien	    && COMPLETE_TYPE_P (type)
269418334Speter	    && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
269518334Speter	  {
269618334Speter	    /* For a TYPE_DECL with no name, but the type has a name,
269718334Speter	       output a tag.
269818334Speter	       This is what represents `struct foo' with no typedef.  */
269918334Speter	    /* In C++, the name of a type is the corresponding typedef.
270018334Speter	       In C, it is an IDENTIFIER_NODE.  */
270118334Speter	    tree name = TYPE_NAME (type);
270218334Speter	    if (TREE_CODE (name) == TYPE_DECL)
270318334Speter	      name = DECL_NAME (name);
270418334Speter
2705169699Skan	    dbxout_begin_complex_stabs ();
2706169699Skan	    stabstr_I (name);
2707169699Skan	    stabstr_S (":T");
270890085Sobrien	    dbxout_type (type, 1);
2709169699Skan	    dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
271018334Speter	    did_output = 1;
271118334Speter	  }
271218334Speter
2713169699Skan	/* If an enum type has no name, it cannot be referred to, but
2714169699Skan	   we must output it anyway, to record the enumeration
2715169699Skan	   constants.  */
2716169699Skan
271718334Speter	if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
271818334Speter	  {
2719169699Skan	    dbxout_begin_complex_stabs ();
272018334Speter	    /* Some debuggers fail when given NULL names, so give this a
2721169699Skan	       harmless name of " " (Why not "(anon)"?).  */
2722169699Skan	    stabstr_S (" :T");
272390085Sobrien	    dbxout_type (type, 1);
2724169699Skan	    dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
272518334Speter	  }
272618334Speter
272718334Speter	/* Prevent duplicate output of a typedef.  */
272818334Speter	TREE_ASM_WRITTEN (decl) = 1;
272918334Speter	break;
273018334Speter      }
273118334Speter
273218334Speter    case PARM_DECL:
273318334Speter      /* Parm decls go in their own separate chains
273418334Speter	 and are output by dbxout_reg_parms and dbxout_parms.  */
2735169699Skan      gcc_unreachable ();
273618334Speter
273718334Speter    case RESULT_DECL:
273818334Speter    case VAR_DECL:
273918334Speter      /* Don't mention a variable that is external.
274018334Speter	 Let the file that defines it describe it.  */
274118334Speter      if (DECL_EXTERNAL (decl))
274218334Speter	break;
274318334Speter
274418334Speter      /* If the variable is really a constant
2745169699Skan	 and not written in memory, inform the debugger.
2746169699Skan
2747169699Skan	 ??? Why do we skip emitting the type and location in this case?  */
274818334Speter      if (TREE_STATIC (decl) && TREE_READONLY (decl)
274918334Speter	  && DECL_INITIAL (decl) != 0
275090085Sobrien	  && host_integerp (DECL_INITIAL (decl), 0)
275118334Speter	  && ! TREE_ASM_WRITTEN (decl)
275290085Sobrien	  && (DECL_CONTEXT (decl) == NULL_TREE
2753169699Skan	      || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK
2754169699Skan	      || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
2755169699Skan	  && TREE_PUBLIC (decl) == 0)
275618334Speter	{
2757169699Skan	  /* The sun4 assembler does not grok this.  */
2758169699Skan
2759169699Skan	  if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2760169699Skan	      || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
276118334Speter	    {
2762169699Skan	      HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
276390085Sobrien
2764169699Skan	      dbxout_begin_complex_stabs ();
2765169699Skan	      dbxout_symbol_name (decl, NULL, 'c');
2766169699Skan	      stabstr_S ("=i");
2767169699Skan	      stabstr_D (ival);
2768169699Skan	      dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
2769169699Skan	      DBXOUT_DECR_NESTING;
2770169699Skan	      return 1;
277118334Speter	    }
2772169699Skan	  else
2773169699Skan	    break;
277418334Speter	}
2775169699Skan      /* else it is something we handle like a normal variable.  */
277618334Speter
2777169699Skan      decl_rtl = dbxout_expand_expr (decl);
2778169699Skan      if (!decl_rtl)
2779169699Skan	DBXOUT_DECR_NESTING_AND_RETURN (0);
2780169699Skan
2781169699Skan      decl_rtl = eliminate_regs (decl_rtl, 0, NULL_RTX);
278218334Speter#ifdef LEAF_REG_REMAP
278352517Sobrien      if (current_function_uses_only_leaf_regs)
2784169699Skan	leaf_renumber_regs_insn (decl_rtl);
278518334Speter#endif
278618334Speter
2787169699Skan      result = dbxout_symbol_location (decl, type, 0, decl_rtl);
278850495Sobrien      break;
2789117404Skan
279050495Sobrien    default:
279150495Sobrien      break;
279218334Speter    }
2793132727Skan  DBXOUT_DECR_NESTING;
279490085Sobrien  return result;
279518334Speter}
279618334Speter
279718334Speter/* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
279818334Speter   Add SUFFIX to its name, if SUFFIX is not 0.
279918334Speter   Describe the variable as residing in HOME
280090085Sobrien   (usually HOME is DECL_RTL (DECL), but not always).
280190085Sobrien   Returns 1 if the stab was really emitted.  */
280218334Speter
280390085Sobrienstatic int
2804132727Skandbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
280518334Speter{
280618334Speter  int letter = 0;
2807169699Skan  STAB_CODE_TYPE code;
2808169699Skan  rtx addr = 0;
2809169699Skan  int number = 0;
281018334Speter  int regno = -1;
281118334Speter
281218334Speter  /* Don't mention a variable at all
281318334Speter     if it was completely optimized into nothingness.
2814117404Skan
281550495Sobrien     If the decl was from an inline function, then its rtl
281618334Speter     is not identically the rtl that was used in this
281718334Speter     particular compilation.  */
281890085Sobrien  if (GET_CODE (home) == SUBREG)
281918334Speter    {
282018334Speter      rtx value = home;
282190085Sobrien
282218334Speter      while (GET_CODE (value) == SUBREG)
282390085Sobrien	value = SUBREG_REG (value);
2824169699Skan      if (REG_P (value))
282518334Speter	{
282690085Sobrien	  if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
282790085Sobrien	    return 0;
282818334Speter	}
282990085Sobrien      home = alter_subreg (&home);
283018334Speter    }
2831169699Skan  if (REG_P (home))
283290085Sobrien    {
283390085Sobrien      regno = REGNO (home);
283490085Sobrien      if (regno >= FIRST_PSEUDO_REGISTER)
283590085Sobrien	return 0;
283690085Sobrien    }
283718334Speter
283818334Speter  /* The kind-of-variable letter depends on where
283918334Speter     the variable is and on the scope of its name:
284018334Speter     G and N_GSYM for static storage and global scope,
284118334Speter     S for static storage and file scope,
284218334Speter     V for static storage and local scope,
284318334Speter     for those two, use N_LCSYM if data is in bss segment,
284418334Speter     N_STSYM if in data segment, N_FUN otherwise.
284518334Speter     (We used N_FUN originally, then changed to N_STSYM
284618334Speter     to please GDB.  However, it seems that confused ld.
284718334Speter     Now GDB has been fixed to like N_FUN, says Kingdon.)
284818334Speter     no letter at all, and N_LSYM, for auto variable,
284918334Speter     r and N_RSYM for register variable.  */
285018334Speter
2851169699Skan  if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
285218334Speter    {
285318334Speter      if (TREE_PUBLIC (decl))
285418334Speter	{
285518334Speter	  letter = 'G';
2856169699Skan	  code = N_GSYM;
285718334Speter	}
285818334Speter      else
285918334Speter	{
2860169699Skan	  addr = XEXP (home, 0);
286118334Speter
286218334Speter	  letter = decl_function_context (decl) ? 'V' : 'S';
286318334Speter
2864146906Skan	  /* Some ports can transform a symbol ref into a label ref,
2865146906Skan	     because the symbol ref is too far away and has to be
2866146906Skan	     dumped into a constant pool.  Alternatively, the symbol
2867146906Skan	     in the constant pool might be referenced by a different
2868146906Skan	     symbol.  */
2869169699Skan	  if (GET_CODE (addr) == SYMBOL_REF
2870169699Skan	      && CONSTANT_POOL_ADDRESS_P (addr))
2871146906Skan	    {
2872146906Skan	      bool marked;
2873169699Skan	      rtx tmp = get_pool_constant_mark (addr, &marked);
2874146906Skan
2875146906Skan	      if (GET_CODE (tmp) == SYMBOL_REF)
2876146906Skan		{
2877169699Skan		  addr = tmp;
2878169699Skan		  if (CONSTANT_POOL_ADDRESS_P (addr))
2879169699Skan		    get_pool_constant_mark (addr, &marked);
2880146906Skan		  else
2881146906Skan		    marked = true;
2882146906Skan		}
2883146906Skan	      else if (GET_CODE (tmp) == LABEL_REF)
2884146906Skan		{
2885169699Skan		  addr = tmp;
2886146906Skan		  marked = true;
2887146906Skan		}
2888146906Skan
2889146906Skan	      /* If all references to the constant pool were optimized
2890146906Skan		 out, we just ignore the symbol.  */
2891146906Skan	      if (!marked)
2892146906Skan		return 0;
2893146906Skan	    }
2894146906Skan
289518334Speter	  /* This should be the same condition as in assemble_variable, but
289618334Speter	     we don't have access to dont_output_data here.  So, instead,
289718334Speter	     we rely on the fact that error_mark_node initializers always
289818334Speter	     end up in bss for C++ and never end up in bss for C.  */
289918334Speter	  if (DECL_INITIAL (decl) == 0
290090085Sobrien	      || (!strcmp (lang_hooks.name, "GNU C++")
290118334Speter		  && DECL_INITIAL (decl) == error_mark_node))
2902169699Skan	    code = N_LCSYM;
290318334Speter	  else if (DECL_IN_TEXT_SECTION (decl))
290418334Speter	    /* This is not quite right, but it's the closest
290518334Speter	       of all the codes that Unix defines.  */
2906169699Skan	    code = DBX_STATIC_CONST_VAR_CODE;
290718334Speter	  else
290818334Speter	    {
290918334Speter	      /* Ultrix `as' seems to need this.  */
291018334Speter#ifdef DBX_STATIC_STAB_DATA_SECTION
2911169699Skan	      switch_to_section (data_section);
291218334Speter#endif
2913169699Skan	      code = N_STSYM;
291418334Speter	    }
291518334Speter	}
291618334Speter    }
291718334Speter  else if (regno >= 0)
291818334Speter    {
291918334Speter      letter = 'r';
2920169699Skan      code = N_RSYM;
2921169699Skan      number = DBX_REGISTER_NUMBER (regno);
292218334Speter    }
2923169699Skan  else if (MEM_P (home)
2924169699Skan	   && (MEM_P (XEXP (home, 0))
2925169699Skan	       || (REG_P (XEXP (home, 0))
292650495Sobrien		   && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
292750495Sobrien		   && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
292850495Sobrien#if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
292950495Sobrien		   && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
293050495Sobrien#endif
293150495Sobrien		   )))
293218334Speter    /* If the value is indirect by memory or by a register
293318334Speter       that isn't the frame pointer
293418334Speter       then it means the object is variable-sized and address through
293518334Speter       that register or stack slot.  DBX has no way to represent this
293618334Speter       so all we can do is output the variable as a pointer.
2937169699Skan       If it's not a parameter, ignore it.  */
293818334Speter    {
2939169699Skan      if (REG_P (XEXP (home, 0)))
294018334Speter	{
294118334Speter	  letter = 'r';
2942169699Skan	  code = N_RSYM;
294390085Sobrien	  if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
294490085Sobrien	    return 0;
2945169699Skan	  number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
294618334Speter	}
294718334Speter      else
294818334Speter	{
2949169699Skan	  code = N_LSYM;
295018334Speter	  /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
295118334Speter	     We want the value of that CONST_INT.  */
2952169699Skan	  number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
295318334Speter	}
295418334Speter
295518334Speter      /* Effectively do build_pointer_type, but don't cache this type,
295618334Speter	 since it might be temporary whereas the type it points to
295718334Speter	 might have been saved for inlining.  */
295818334Speter      /* Don't use REFERENCE_TYPE because dbx can't handle that.  */
295918334Speter      type = make_node (POINTER_TYPE);
296018334Speter      TREE_TYPE (type) = TREE_TYPE (decl);
296118334Speter    }
2962169699Skan  else if (MEM_P (home)
2963169699Skan	   && REG_P (XEXP (home, 0)))
296418334Speter    {
2965169699Skan      code = N_LSYM;
2966169699Skan      number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
296718334Speter    }
2968169699Skan  else if (MEM_P (home)
296918334Speter	   && GET_CODE (XEXP (home, 0)) == PLUS
297018334Speter	   && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
297118334Speter    {
2972169699Skan      code = N_LSYM;
297318334Speter      /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
297418334Speter	 We want the value of that CONST_INT.  */
2975169699Skan      number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
297618334Speter    }
2977169699Skan  else if (MEM_P (home)
297818334Speter	   && GET_CODE (XEXP (home, 0)) == CONST)
297918334Speter    {
298018334Speter      /* Handle an obscure case which can arise when optimizing and
298118334Speter	 when there are few available registers.  (This is *always*
298218334Speter	 the case for i386/i486 targets).  The RTL looks like
298318334Speter	 (MEM (CONST ...)) even though this variable is a local `auto'
298418334Speter	 or a local `register' variable.  In effect, what has happened
298518334Speter	 is that the reload pass has seen that all assignments and
298618334Speter	 references for one such a local variable can be replaced by
298718334Speter	 equivalent assignments and references to some static storage
298818334Speter	 variable, thereby avoiding the need for a register.  In such
298918334Speter	 cases we're forced to lie to debuggers and tell them that
299018334Speter	 this variable was itself `static'.  */
2991169699Skan      code = N_LCSYM;
299218334Speter      letter = 'V';
2993169699Skan      addr = XEXP (XEXP (home, 0), 0);
299418334Speter    }
299518334Speter  else if (GET_CODE (home) == CONCAT)
299618334Speter    {
299790085Sobrien      tree subtype;
299818334Speter
299990085Sobrien      /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
300090085Sobrien	 for example), then there is no easy way to figure out
300190085Sobrien	 what SUBTYPE should be.  So, we give up.  */
300290085Sobrien      if (TREE_CODE (type) != COMPLEX_TYPE)
300390085Sobrien	return 0;
300490085Sobrien
300590085Sobrien      subtype = TREE_TYPE (type);
300690085Sobrien
300718334Speter      /* If the variable's storage is in two parts,
300818334Speter	 output each as a separate stab with a modified name.  */
300918334Speter      if (WORDS_BIG_ENDIAN)
301018334Speter	dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
301118334Speter      else
301218334Speter	dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
301318334Speter
301418334Speter      if (WORDS_BIG_ENDIAN)
301518334Speter	dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
301618334Speter      else
301718334Speter	dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
301890085Sobrien      return 1;
301918334Speter    }
302018334Speter  else
302118334Speter    /* Address might be a MEM, when DECL is a variable-sized object.
302218334Speter       Or it might be const0_rtx, meaning previous passes
302318334Speter       want us to ignore this variable.  */
302490085Sobrien    return 0;
302518334Speter
302618334Speter  /* Ok, start a symtab entry and output the variable name.  */
3027169699Skan  emit_pending_bincls_if_required ();
302818334Speter  FORCE_TEXT;
302918334Speter
303018334Speter#ifdef DBX_STATIC_BLOCK_START
3031169699Skan  DBX_STATIC_BLOCK_START (asm_out_file, code);
303218334Speter#endif
303318334Speter
3034169699Skan  dbxout_begin_complex_stabs_noforcetext ();
303518334Speter  dbxout_symbol_name (decl, suffix, letter);
303690085Sobrien  dbxout_type (type, 0);
3037169699Skan  dbxout_finish_complex_stabs (decl, code, addr, 0, number);
303818334Speter
303918334Speter#ifdef DBX_STATIC_BLOCK_END
3040169699Skan  DBX_STATIC_BLOCK_END (asm_out_file, code);
304118334Speter#endif
304290085Sobrien  return 1;
304318334Speter}
304418334Speter
304518334Speter/* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
304618334Speter   Then output LETTER to indicate the kind of location the symbol has.  */
304718334Speter
304818334Speterstatic void
3049132727Skandbxout_symbol_name (tree decl, const char *suffix, int letter)
305018334Speter{
3051169699Skan  tree name;
305290085Sobrien
3053132727Skan  if (DECL_CONTEXT (decl)
3054132727Skan      && (TYPE_P (DECL_CONTEXT (decl))
3055132727Skan	  || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
3056132727Skan    /* One slight hitch: if this is a VAR_DECL which is a class member
3057132727Skan       or a namespace member, we must put out the mangled name instead of the
305890085Sobrien       DECL_NAME.  Note also that static member (variable) names DO NOT begin
305990085Sobrien       with underscores in .stabs directives.  */
3060169699Skan    name = DECL_ASSEMBLER_NAME (decl);
306190085Sobrien  else
306290085Sobrien    /* ...but if we're function-local, we don't want to include the junk
306390085Sobrien       added by ASM_FORMAT_PRIVATE_NAME.  */
3064169699Skan    name = DECL_NAME (decl);
306590085Sobrien
3066169699Skan  if (name)
3067169699Skan    stabstr_I (name);
3068169699Skan  else
3069169699Skan    stabstr_S ("(anon)");
307018334Speter
3071169699Skan  if (suffix)
3072169699Skan    stabstr_S (suffix);
3073169699Skan  stabstr_C (':');
307490085Sobrien  if (letter)
3075169699Skan    stabstr_C (letter);
307618334Speter}
307718334Speter
3078117404Skan/* Output definitions of all the decls in a chain. Return nonzero if
307990085Sobrien   anything was output */
308018334Speter
308190085Sobrienint
3082132727Skandbxout_syms (tree syms)
308318334Speter{
308490085Sobrien  int result = 0;
308518334Speter  while (syms)
308618334Speter    {
308790085Sobrien      result += dbxout_symbol (syms, 1);
308818334Speter      syms = TREE_CHAIN (syms);
308918334Speter    }
309090085Sobrien  return result;
309118334Speter}
309218334Speter
309318334Speter/* The following two functions output definitions of function parameters.
309418334Speter   Each parameter gets a definition locating it in the parameter list.
309518334Speter   Each parameter that is a register variable gets a second definition
309618334Speter   locating it in the register.
309718334Speter
309818334Speter   Printing or argument lists in gdb uses the definitions that
309918334Speter   locate in the parameter list.  But reference to the variable in
310018334Speter   expressions uses preferentially the definition as a register.  */
310118334Speter
310218334Speter/* Output definitions, referring to storage in the parmlist,
310318334Speter   of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
310418334Speter
310518334Spetervoid
3106132727Skandbxout_parms (tree parms)
310718334Speter{
3108132727Skan  ++debug_nesting;
3109132727Skan  emit_pending_bincls_if_required ();
3110132727Skan
311118334Speter  for (; parms; parms = TREE_CHAIN (parms))
3112169699Skan    if (DECL_NAME (parms)
3113169699Skan	&& TREE_TYPE (parms) != error_mark_node
3114169699Skan	&& DECL_RTL_SET_P (parms)
3115169699Skan	&& DECL_INCOMING_RTL (parms))
311618334Speter      {
3117169699Skan	tree eff_type;
3118169699Skan	char letter;
3119169699Skan	STAB_CODE_TYPE code;
3120169699Skan	int number;
312118334Speter
312218334Speter	/* Perform any necessary register eliminations on the parameter's rtl,
312318334Speter	   so that the debugging output will be accurate.  */
312418334Speter	DECL_INCOMING_RTL (parms)
312518334Speter	  = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
312690085Sobrien	SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
312718334Speter#ifdef LEAF_REG_REMAP
312852517Sobrien	if (current_function_uses_only_leaf_regs)
312918334Speter	  {
313018334Speter	    leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
313118334Speter	    leaf_renumber_regs_insn (DECL_RTL (parms));
313218334Speter	  }
313318334Speter#endif
313418334Speter
313518334Speter	if (PARM_PASSED_IN_MEMORY (parms))
313618334Speter	  {
3137169699Skan	    rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0);
313818334Speter
313918334Speter	    /* ??? Here we assume that the parm address is indexed
314018334Speter	       off the frame pointer or arg pointer.
314118334Speter	       If that is not true, we produce meaningless results,
314218334Speter	       but do not crash.  */
3143169699Skan	    if (GET_CODE (inrtl) == PLUS
3144169699Skan		&& GET_CODE (XEXP (inrtl, 1)) == CONST_INT)
3145169699Skan	      number = INTVAL (XEXP (inrtl, 1));
314618334Speter	    else
3147169699Skan	      number = 0;
314818334Speter
3149169699Skan	    code = N_PSYM;
3150169699Skan	    number = DEBUGGER_ARG_OFFSET (number, inrtl);
3151169699Skan	    letter = 'p';
315218334Speter
3153169699Skan	    /* It is quite tempting to use TREE_TYPE (parms) instead
3154169699Skan	       of DECL_ARG_TYPE (parms) for the eff_type, so that gcc
3155169699Skan	       reports the actual type of the parameter, rather than
3156169699Skan	       the promoted type.  This certainly makes GDB's life
3157169699Skan	       easier, at least for some ports.  The change is a bad
3158169699Skan	       idea however, since GDB expects to be able access the
3159169699Skan	       type without performing any conversions.  So for
3160169699Skan	       example, if we were passing a float to an unprototyped
3161169699Skan	       function, gcc will store a double on the stack, but if
3162169699Skan	       we emit a stab saying the type is a float, then gdb
3163169699Skan	       will only read in a single value, and this will produce
3164169699Skan	       an erroneous value.  */
3165169699Skan	    eff_type = DECL_ARG_TYPE (parms);
316618334Speter	  }
3167169699Skan	else if (REG_P (DECL_RTL (parms)))
316818334Speter	  {
316918334Speter	    rtx best_rtl;
3170169699Skan
317118334Speter	    /* Parm passed in registers and lives in registers or nowhere.  */
3172169699Skan	    code = DBX_REGPARM_STABS_CODE;
3173169699Skan	    letter = DBX_REGPARM_STABS_LETTER;
317418334Speter
3175169699Skan	    /* For parms passed in registers, it is better to use the
3176169699Skan	       declared type of the variable, not the type it arrived in.  */
3177169699Skan	    eff_type = TREE_TYPE (parms);
317818334Speter
3179169699Skan	    /* If parm lives in a register, use that register; pretend
3180169699Skan	       the parm was passed there.  It would be more consistent
3181169699Skan	       to describe the register where the parm was passed, but
3182169699Skan	       in practice that register usually holds something else.
3183169699Skan	       If the parm lives nowhere, use the register where it
3184169699Skan	       was passed.  */
318590085Sobrien	    if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3186169699Skan	      best_rtl = DECL_RTL (parms);
318718334Speter	    else
3188169699Skan	      best_rtl = DECL_INCOMING_RTL (parms);
318918334Speter
3190169699Skan	    number = DBX_REGISTER_NUMBER (REGNO (best_rtl));
319118334Speter	  }
3192169699Skan	else if (MEM_P (DECL_RTL (parms))
3193169699Skan		 && REG_P (XEXP (DECL_RTL (parms), 0))
319418334Speter		 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
319518334Speter		 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
319618334Speter#if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
319718334Speter		 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
319818334Speter#endif
319918334Speter		 )
320018334Speter	  {
320118334Speter	    /* Parm was passed via invisible reference.
320218334Speter	       That is, its address was passed in a register.
320318334Speter	       Output it as if it lived in that register.
320418334Speter	       The debugger will know from the type
320518334Speter	       that it was actually passed by invisible reference.  */
320618334Speter
3207169699Skan	    code = DBX_REGPARM_STABS_CODE;
3208169699Skan
3209169699Skan	    /* GDB likes this marked with a special letter.  */
3210169699Skan	    letter = (use_gnu_debug_info_extensions
3211169699Skan		      ? 'a' : DBX_REGPARM_STABS_LETTER);
3212169699Skan	    eff_type = TREE_TYPE (parms);
321318334Speter
321418334Speter	    /* DECL_RTL looks like (MEM (REG...).  Get the register number.
321518334Speter	       If it is an unallocated pseudo-reg, then use the register where
3216169699Skan	       it was passed instead.
3217169699Skan	       ??? Why is DBX_REGISTER_NUMBER not used here?  */
3218169699Skan
321990085Sobrien	    if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
3220169699Skan	      number = REGNO (XEXP (DECL_RTL (parms), 0));
322118334Speter	    else
3222169699Skan	      number = REGNO (DECL_INCOMING_RTL (parms));
322318334Speter	  }
3224169699Skan	else if (MEM_P (DECL_RTL (parms))
3225169699Skan		 && MEM_P (XEXP (DECL_RTL (parms), 0)))
322690085Sobrien	  {
322790085Sobrien	    /* Parm was passed via invisible reference, with the reference
322890085Sobrien	       living on the stack.  DECL_RTL looks like
322990085Sobrien	       (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
323090085Sobrien	       could look like (MEM (MEM (REG))).  */
3231169699Skan
3232169699Skan	    code = N_PSYM;
3233169699Skan	    letter = 'v';
3234169699Skan	    eff_type = TREE_TYPE (parms);
3235169699Skan
3236169699Skan	    if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
3237169699Skan	      number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
323890085Sobrien	    else
3239169699Skan	      number = 0;
3240117404Skan
3241169699Skan	    number = DEBUGGER_ARG_OFFSET (number,
3242169699Skan					  XEXP (XEXP (DECL_RTL (parms), 0), 0));
324390085Sobrien	  }
3244169699Skan	else if (MEM_P (DECL_RTL (parms))
324518334Speter		 && XEXP (DECL_RTL (parms), 0) != const0_rtx
324618334Speter		 /* ??? A constant address for a parm can happen
324718334Speter		    when the reg it lives in is equiv to a constant in memory.
324818334Speter		    Should make this not happen, after 2.4.  */
324918334Speter		 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
325018334Speter	  {
325118334Speter	    /* Parm was passed in registers but lives on the stack.  */
325218334Speter
3253169699Skan	    code = N_PSYM;
3254169699Skan	    letter = 'p';
3255169699Skan	    eff_type = TREE_TYPE (parms);
3256169699Skan
325718334Speter	    /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
325818334Speter	       in which case we want the value of that CONST_INT,
325990085Sobrien	       or (MEM (REG ...)),
326018334Speter	       in which case we use a value of zero.  */
3261169699Skan	    if (!REG_P (XEXP (DECL_RTL (parms), 0)))
3262169699Skan	      number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
326318334Speter	    else
3264169699Skan	      number = 0;
326590085Sobrien
326650495Sobrien	    /* Make a big endian correction if the mode of the type of the
326750495Sobrien	       parameter is not the same as the mode of the rtl.  */
326850495Sobrien	    if (BYTES_BIG_ENDIAN
326950495Sobrien		&& TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
327050495Sobrien		&& GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
3271169699Skan	      number += (GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3272169699Skan			 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))));
3273169699Skan	  }
3274169699Skan	else
3275169699Skan	  /* ??? We don't know how to represent this argument.  */
3276169699Skan	  continue;
327750495Sobrien
3278169699Skan	dbxout_begin_complex_stabs ();
3279169699Skan
3280169699Skan	if (DECL_NAME (parms))
3281169699Skan	  {
3282169699Skan	    stabstr_I (DECL_NAME (parms));
3283169699Skan	    stabstr_C (':');
328418334Speter	  }
3285169699Skan	else
3286169699Skan	  stabstr_S ("(anon):");
3287169699Skan	stabstr_C (letter);
3288169699Skan	dbxout_type (eff_type, 0);
3289169699Skan	dbxout_finish_complex_stabs (parms, code, 0, 0, number);
329018334Speter      }
3291132727Skan  DBXOUT_DECR_NESTING;
329218334Speter}
329318334Speter
329418334Speter/* Output definitions for the places where parms live during the function,
329518334Speter   when different from where they were passed, when the parms were passed
329618334Speter   in memory.
329718334Speter
329818334Speter   It is not useful to do this for parms passed in registers
329918334Speter   that live during the function in different registers, because it is
330018334Speter   impossible to look in the passed register for the passed value,
330118334Speter   so we use the within-the-function register to begin with.
330218334Speter
330318334Speter   PARMS is a chain of PARM_DECL nodes.  */
330418334Speter
330518334Spetervoid
3306132727Skandbxout_reg_parms (tree parms)
330718334Speter{
3308132727Skan  ++debug_nesting;
3309132727Skan
331018334Speter  for (; parms; parms = TREE_CHAIN (parms))
331118334Speter    if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
331218334Speter      {
331318334Speter	/* Report parms that live in registers during the function
331418334Speter	   but were passed in memory.  */
3315169699Skan	if (REG_P (DECL_RTL (parms))
331618334Speter	    && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
331718334Speter	  dbxout_symbol_location (parms, TREE_TYPE (parms),
331818334Speter				  0, DECL_RTL (parms));
331918334Speter	else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
332018334Speter	  dbxout_symbol_location (parms, TREE_TYPE (parms),
332118334Speter				  0, DECL_RTL (parms));
332218334Speter	/* Report parms that live in memory but not where they were passed.  */
3323169699Skan	else if (MEM_P (DECL_RTL (parms))
332418334Speter		 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
332518334Speter	  dbxout_symbol_location (parms, TREE_TYPE (parms),
332618334Speter				  0, DECL_RTL (parms));
332718334Speter      }
3328132727Skan  DBXOUT_DECR_NESTING;
332918334Speter}
333018334Speter
333118334Speter/* Given a chain of ..._TYPE nodes (as come in a parameter list),
333218334Speter   output definitions of those names, in raw form */
333318334Speter
333490085Sobrienstatic void
3335132727Skandbxout_args (tree args)
333618334Speter{
333718334Speter  while (args)
333818334Speter    {
3339169699Skan      stabstr_C (',');
334090085Sobrien      dbxout_type (TREE_VALUE (args), 0);
334118334Speter      args = TREE_CHAIN (args);
334218334Speter    }
334318334Speter}
334418334Speter
3345146906Skan/* Subroutine of dbxout_block.  Emit an N_LBRAC stab referencing LABEL.
3346146906Skan   BEGIN_LABEL is the name of the beginning of the function, which may
3347146906Skan   be required.  */
3348146906Skanstatic void
3349146906Skandbx_output_lbrac (const char *label,
3350146906Skan		  const char *begin_label ATTRIBUTE_UNUSED)
3351146906Skan{
3352169699Skan  dbxout_begin_stabn (N_LBRAC);
3353169699Skan  if (DBX_BLOCKS_FUNCTION_RELATIVE)
3354169699Skan    dbxout_stab_value_label_diff (label, begin_label);
3355169699Skan  else
3356169699Skan    dbxout_stab_value_label (label);
3357146906Skan}
3358146906Skan
3359146906Skan/* Subroutine of dbxout_block.  Emit an N_RBRAC stab referencing LABEL.
3360146906Skan   BEGIN_LABEL is the name of the beginning of the function, which may
3361146906Skan   be required.  */
3362146906Skanstatic void
3363146906Skandbx_output_rbrac (const char *label,
3364146906Skan		  const char *begin_label ATTRIBUTE_UNUSED)
3365146906Skan{
3366169699Skan  dbxout_begin_stabn (N_RBRAC);
3367169699Skan  if (DBX_BLOCKS_FUNCTION_RELATIVE)
3368169699Skan    dbxout_stab_value_label_diff (label, begin_label);
3369169699Skan  else
3370169699Skan    dbxout_stab_value_label (label);
3371146906Skan}
3372146906Skan
337318334Speter/* Output everything about a symbol block (a BLOCK node
337418334Speter   that represents a scope level),
337518334Speter   including recursive output of contained blocks.
337618334Speter
337718334Speter   BLOCK is the BLOCK node.
337818334Speter   DEPTH is its depth within containing symbol blocks.
337918334Speter   ARGS is usually zero; but for the outermost block of the
338018334Speter   body of a function, it is a chain of PARM_DECLs for the function parameters.
338118334Speter   We output definitions of all the register parms
338218334Speter   as if they were local variables of that block.
338318334Speter
338418334Speter   If -g1 was used, we count blocks just the same, but output nothing
338518334Speter   except for the outermost block.
338618334Speter
338718334Speter   Actually, BLOCK may be several blocks chained together.
338818334Speter   We handle them all in sequence.  */
338918334Speter
339018334Speterstatic void
3391132727Skandbxout_block (tree block, int depth, tree args)
339218334Speter{
3393169699Skan  char begin_label[20];
3394169699Skan  /* Reference current function start using LFBB.  */
3395169699Skan  ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
339690085Sobrien
339718334Speter  while (block)
339818334Speter    {
339918334Speter      /* Ignore blocks never expanded or otherwise marked as real.  */
340090085Sobrien      if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
340118334Speter	{
340290085Sobrien	  int did_output;
3403146906Skan	  int blocknum = BLOCK_NUMBER (block);
340490085Sobrien
340590085Sobrien	  /* In dbx format, the syms of a block come before the N_LBRAC.
340690085Sobrien	     If nothing is output, we don't need the N_LBRAC, either.  */
340790085Sobrien	  did_output = 0;
340818334Speter	  if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
340990085Sobrien	    did_output = dbxout_syms (BLOCK_VARS (block));
341018334Speter	  if (args)
341118334Speter	    dbxout_reg_parms (args);
341218334Speter
341318334Speter	  /* Now output an N_LBRAC symbol to represent the beginning of
341418334Speter	     the block.  Use the block's tree-walk order to generate
341518334Speter	     the assembler symbols LBBn and LBEn
341618334Speter	     that final will define around the code in this block.  */
3417146906Skan	  if (did_output)
341818334Speter	    {
341918334Speter	      char buf[20];
3420146906Skan	      const char *scope_start;
342118334Speter
3422146906Skan	      if (depth == 0)
3423146906Skan		/* The outermost block doesn't get LBB labels; use
3424169699Skan		   the LFBB local symbol emitted by dbxout_begin_prologue.  */
3425146906Skan		scope_start = begin_label;
3426146906Skan	      else
3427146906Skan		{
3428146906Skan		  ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3429146906Skan		  scope_start = buf;
3430146906Skan		}
3431146906Skan
343218334Speter	      if (BLOCK_HANDLER_BLOCK (block))
343318334Speter		{
343418334Speter		  /* A catch block.  Must precede N_LBRAC.  */
343518334Speter		  tree decl = BLOCK_VARS (block);
343618334Speter		  while (decl)
343718334Speter		    {
3438169699Skan		      dbxout_begin_complex_stabs ();
3439169699Skan		      stabstr_I (DECL_NAME (decl));
3440169699Skan		      stabstr_S (":C1");
3441169699Skan		      dbxout_finish_complex_stabs (0, N_CATCH, 0,
3442169699Skan						   scope_start, 0);
344318334Speter		      decl = TREE_CHAIN (decl);
344418334Speter		    }
344518334Speter		}
3446146906Skan	      dbx_output_lbrac (scope_start, begin_label);
344718334Speter	    }
344818334Speter
344918334Speter	  /* Output the subblocks.  */
345018334Speter	  dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
345118334Speter
345218334Speter	  /* Refer to the marker for the end of the block.  */
3453146906Skan	  if (did_output)
345418334Speter	    {
3455146906Skan	      char buf[100];
3456146906Skan	      if (depth == 0)
3457146906Skan		/* The outermost block doesn't get LBE labels;
3458146906Skan		   use the "scope" label which will be emitted
3459146906Skan		   by dbxout_function_end.  */
3460146906Skan		ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3461146906Skan	      else
3462146906Skan		ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3463146906Skan
3464146906Skan	      dbx_output_rbrac (buf, begin_label);
346518334Speter	    }
346618334Speter	}
346718334Speter      block = BLOCK_CHAIN (block);
346818334Speter    }
346918334Speter}
347018334Speter
347118334Speter/* Output the information about a function and its arguments and result.
347218334Speter   Usually this follows the function's code,
347318334Speter   but on some systems, it comes before.  */
347418334Speter
347590085Sobrien#if defined (DBX_DEBUGGING_INFO)
347618334Speterstatic void
3477132727Skandbxout_begin_function (tree decl)
347818334Speter{
3479169699Skan  int saved_tree_used1;
3480169699Skan
3481169699Skan  if (DECL_IGNORED_P (decl))
3482169699Skan    return;
3483169699Skan
3484169699Skan  saved_tree_used1 = TREE_USED (decl);
3485132727Skan  TREE_USED (decl) = 1;
3486132727Skan  if (DECL_NAME (DECL_RESULT (decl)) != 0)
3487132727Skan    {
3488132727Skan      int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3489132727Skan      TREE_USED (DECL_RESULT (decl)) = 1;
3490132727Skan      dbxout_symbol (decl, 0);
3491132727Skan      TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3492132727Skan    }
3493132727Skan  else
3494132727Skan    dbxout_symbol (decl, 0);
3495132727Skan  TREE_USED (decl) = saved_tree_used1;
3496132727Skan
349718334Speter  dbxout_parms (DECL_ARGUMENTS (decl));
349818334Speter  if (DECL_NAME (DECL_RESULT (decl)) != 0)
349918334Speter    dbxout_symbol (DECL_RESULT (decl), 1);
350018334Speter}
350190085Sobrien#endif /* DBX_DEBUGGING_INFO */
350218334Speter
350350495Sobrien#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3504132727Skan
3505132727Skan#include "gt-dbxout.h"
3506