source: trunk/third/gcc/sdbout.c @ 11288

Revision 11288, 45.8 KB checked in by ghudson, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r11287, which included commits to RCS files with non-trunk default branches.
Line 
1/* Output sdb-format symbol table information from GNU compiler.
2   Copyright (C) 1988, 92-97, 1998 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING.  If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA.  */
20
21/*  mike@tredysvr.Tredydev.Unisys.COM says:
22I modified the struct.c example and have a nm of a .o resulting from the
23AT&T C compiler.  From the example below I would conclude the following:
24
251. All .defs from structures are emitted as scanned.  The example below
26   clearly shows the symbol table entries for BoxRec2 are after the first
27   function.
28
292. All functions and their locals (including statics) are emitted as scanned.
30
313. All nested unnamed union and structure .defs must be emitted before
32   the structure in which they are nested.  The AT&T assembler is a
33   one pass beast as far as symbolics are concerned.
34
354. All structure .defs are emitted before the typedefs that refer to them.
36
375. All top level static and external variable definitions are moved to the
38   end of file with all top level statics occurring first before externs.
39
406. All undefined references are at the end of the file.
41*/
42
43#include "config.h"
44
45#ifdef SDB_DEBUGGING_INFO
46
47#include <stdio.h>
48#include "tree.h"
49#include "rtl.h"
50#include "regs.h"
51#include "defaults.h"
52#include "flags.h"
53#include "insn-config.h"
54#include "reload.h"
55
56/* Mips systems use the SDB functions to dump out symbols, but do not
57   supply usable syms.h include files.  Which syms.h file to use is a
58   target parameter so don't use the native one if we're cross compiling.  */
59
60#if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(_WIN32) && !defined(__linux__) && !defined(CROSS_COMPILE)
61#include <syms.h>
62/* Use T_INT if we don't have T_VOID.  */
63#ifndef T_VOID
64#define T_VOID T_INT
65#endif
66#else
67#include "gsyms.h"
68#endif
69
70/* #include <storclass.h>  used to be this instead of syms.h.  */
71
72/* 1 if PARM is passed to this function in memory.  */
73
74#define PARM_PASSED_IN_MEMORY(PARM) \
75 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
76
77/* A C expression for the integer offset value of an automatic variable
78   (C_AUTO) having address X (an RTX).  */
79#ifndef DEBUGGER_AUTO_OFFSET
80#define DEBUGGER_AUTO_OFFSET(X) \
81  (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
82#endif
83
84/* A C expression for the integer offset value of an argument (C_ARG)
85   having address X (an RTX).  The nominal offset is OFFSET.  */
86#ifndef DEBUGGER_ARG_OFFSET
87#define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
88#endif
89
90/* Line number of beginning of current function, minus one.
91   Negative means not in a function or not using sdb.  */
92
93int sdb_begin_function_line = -1;
94
95/* Counter to generate unique "names" for nameless struct members.  */
96
97static int unnamed_struct_number = 0;
98
99extern FILE *asm_out_file;
100
101extern tree current_function_decl;
102
103void sdbout_init ();
104void sdbout_symbol ();
105void sdbout_types();
106
107static char *gen_fake_label             PROTO((void));
108static int plain_type                   PROTO((tree));
109static int template_name_p              PROTO((tree));
110static void sdbout_record_type_name     PROTO((tree));
111static int plain_type_1                 PROTO((tree, int));
112static void sdbout_block                PROTO((tree));
113static void sdbout_syms                 PROTO((tree));
114static void sdbout_queue_anonymous_type PROTO((tree));
115static void sdbout_dequeue_anonymous_types PROTO((void));
116static void sdbout_type                 PROTO((tree));
117static void sbdout_field_types          PROTO((tree));
118static void sdbout_one_type             PROTO((tree));
119static void sdbout_parms                PROTO((tree));
120static void sdbout_reg_parms            PROTO((tree));
121
122/* Define the default sizes for various types.  */
123
124#ifndef CHAR_TYPE_SIZE
125#define CHAR_TYPE_SIZE BITS_PER_UNIT
126#endif
127
128#ifndef SHORT_TYPE_SIZE
129#define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
130#endif
131
132#ifndef INT_TYPE_SIZE
133#define INT_TYPE_SIZE BITS_PER_WORD
134#endif
135
136#ifndef LONG_TYPE_SIZE
137#define LONG_TYPE_SIZE BITS_PER_WORD
138#endif
139
140#ifndef LONG_LONG_TYPE_SIZE
141#define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
142#endif
143
144#ifndef FLOAT_TYPE_SIZE
145#define FLOAT_TYPE_SIZE BITS_PER_WORD
146#endif
147
148#ifndef DOUBLE_TYPE_SIZE
149#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
150#endif
151
152#ifndef LONG_DOUBLE_TYPE_SIZE
153#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
154#endif
155
156/* Random macros describing parts of SDB data.  */
157
158/* Put something here if lines get too long */
159#define CONTIN
160
161/* Default value of delimiter is ";".  */
162#ifndef SDB_DELIM
163#define SDB_DELIM       ";"
164#endif
165
166/* Maximum number of dimensions the assembler will allow.  */
167#ifndef SDB_MAX_DIM
168#define SDB_MAX_DIM 4
169#endif
170
171#ifndef PUT_SDB_SCL
172#define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
173#endif
174
175#ifndef PUT_SDB_INT_VAL
176#define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d%s", (a), SDB_DELIM)
177#endif
178
179#ifndef PUT_SDB_VAL
180#define PUT_SDB_VAL(a)                          \
181( fputs ("\t.val\t", asm_out_file),             \
182  output_addr_const (asm_out_file, (a)),        \
183  fprintf (asm_out_file, SDB_DELIM))
184#endif
185
186#ifndef PUT_SDB_DEF
187#define PUT_SDB_DEF(a)                          \
188do { fprintf (asm_out_file, "\t.def\t");        \
189     ASM_OUTPUT_LABELREF (asm_out_file, a);     \
190     fprintf (asm_out_file, SDB_DELIM); } while (0)
191#endif
192
193#ifndef PUT_SDB_PLAIN_DEF
194#define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
195#endif
196
197#ifndef PUT_SDB_ENDEF
198#define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
199#endif
200
201#ifndef PUT_SDB_TYPE
202#define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
203#endif
204
205#ifndef PUT_SDB_SIZE
206#define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d%s", a, SDB_DELIM)
207#endif
208
209#ifndef PUT_SDB_START_DIM
210#define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
211#endif
212
213#ifndef PUT_SDB_NEXT_DIM
214#define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
215#endif
216
217#ifndef PUT_SDB_LAST_DIM
218#define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
219#endif
220
221#ifndef PUT_SDB_TAG
222#define PUT_SDB_TAG(a)                          \
223do { fprintf (asm_out_file, "\t.tag\t");        \
224     ASM_OUTPUT_LABELREF (asm_out_file, a);     \
225     fprintf (asm_out_file, SDB_DELIM); } while (0)
226#endif
227
228#ifndef PUT_SDB_BLOCK_START
229#define PUT_SDB_BLOCK_START(LINE)               \
230  fprintf (asm_out_file,                        \
231           "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
232           SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
233#endif
234
235#ifndef PUT_SDB_BLOCK_END
236#define PUT_SDB_BLOCK_END(LINE)                 \
237  fprintf (asm_out_file,                        \
238           "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n",  \
239           SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
240#endif
241
242#ifndef PUT_SDB_FUNCTION_START
243#define PUT_SDB_FUNCTION_START(LINE)            \
244  fprintf (asm_out_file,                        \
245           "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
246           SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
247#endif
248
249#ifndef PUT_SDB_FUNCTION_END
250#define PUT_SDB_FUNCTION_END(LINE)              \
251  fprintf (asm_out_file,                        \
252           "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
253           SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
254#endif
255
256#ifndef PUT_SDB_EPILOGUE_END
257#define PUT_SDB_EPILOGUE_END(NAME)                      \
258do { fprintf (asm_out_file, "\t.def\t");                \
259     ASM_OUTPUT_LABELREF (asm_out_file, NAME);          \
260     fprintf (asm_out_file,                             \
261              "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",    \
262              SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
263#endif
264
265#ifndef SDB_GENERATE_FAKE
266#define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
267  sprintf ((BUFFER), ".%dfake", (NUMBER));
268#endif
269
270/* Return the sdb tag identifier string for TYPE
271   if TYPE has already been defined; otherwise return a null pointer.   */
272
273#define KNOWN_TYPE_TAG(type)  TYPE_SYMTAB_POINTER (type)
274
275/* Set the sdb tag identifier string for TYPE to NAME.  */
276
277#define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
278  TYPE_SYMTAB_POINTER (TYPE) = (NAME)
279
280/* Return the name (a string) of the struct, union or enum tag
281   described by the TREE_LIST node LINK.  This is 0 for an anonymous one.  */
282
283#define TAG_NAME(link) \
284  (((link) && TREE_PURPOSE ((link)) \
285    && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
286   ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
287
288/* Ensure we don't output a negative line number.  */
289#define MAKE_LINE_SAFE(line)  \
290  if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
291
292/* Perform linker optimization of merging header file definitions together
293   for targets with MIPS_DEBUGGING_INFO defined.  This won't work without a
294   post 960826 version of GAS.  Nothing breaks with earlier versions of GAS,
295   the optimization just won't be done.  The native assembler already has the
296   necessary support.  */
297
298#ifdef MIPS_DEBUGGING_INFO
299
300#ifndef PUT_SDB_SRC_FILE
301#define PUT_SDB_SRC_FILE(FILENAME) \
302output_file_directive (asm_out_file, (FILENAME))
303#endif
304
305/* ECOFF linkers have an optimization that does the same kind of thing as
306   N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
307   executable.  To achieve this, GCC must output a .file for each file
308   name change.  */
309
310/* This is a stack of input files.  */
311
312struct sdb_file
313{
314  struct sdb_file *next;
315  char *name;
316};
317
318/* This is the top of the stack.  */
319
320static struct sdb_file *current_file;
321
322#endif /* MIPS_DEBUGGING_INFO */
323
324/* Set up for SDB output at the start of compilation.  */
325
326void
327sdbout_init (asm_file, input_file_name, syms)
328     FILE *asm_file;
329     char *input_file_name;
330     tree syms;
331{
332#ifdef MIPS_DEBUGGING_INFO
333  current_file = (struct sdb_file *) xmalloc (sizeof *current_file);
334  current_file->next = NULL;
335  current_file->name = input_file_name;
336#endif
337
338#ifdef RMS_QUICK_HACK_1
339  tree t;
340  for (t = syms; t; t = TREE_CHAIN (t))
341    if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
342        && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
343      sdbout_symbol (t, 0);
344#endif 
345}
346
347#if 0
348
349/* return the tag identifier for type
350 */
351
352char *
353tag_of_ru_type (type,link)
354     tree type,link;
355{
356  if (TYPE_SYMTAB_ADDRESS (type))
357    return TYPE_SYMTAB_ADDRESS (type);
358  if (link && TREE_PURPOSE (link)
359      && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
360    TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
361  else
362    return (char *) TYPE_SYMTAB_ADDRESS (type);
363}
364#endif
365
366/* Return a unique string to name an anonymous type.  */
367
368static char *
369gen_fake_label ()
370{
371  char label[10];
372  char *labelstr;
373  SDB_GENERATE_FAKE (label, unnamed_struct_number);
374  unnamed_struct_number++;
375  labelstr = (char *) permalloc (strlen (label) + 1);
376  strcpy (labelstr, label);
377  return labelstr;
378}
379
380/* Return the number which describes TYPE for SDB.
381   For pointers, etc., this function is recursive.
382   Each record, union or enumeral type must already have had a
383   tag number output.  */
384
385/* The number is given by d6d5d4d3d2d1bbbb
386   where bbbb is 4 bit basic type, and di indicate  one of notype,ptr,fn,array.
387   Thus, char *foo () has bbbb=T_CHAR
388                          d1=D_FCN
389                          d2=D_PTR
390 N_BTMASK=     017       1111     basic type field.
391 N_TSHIFT=       2                derived type shift
392 N_BTSHFT=       4                Basic type shift */
393
394/* Produce the number that describes a pointer, function or array type.
395   PREV is the number describing the target, value or element type.
396   DT_type describes how to transform that type.  */
397#define PUSH_DERIVED_LEVEL(DT_type,PREV)                \
398  ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT)         \
399   | ((int)DT_type << (int)N_BTSHFT)                    \
400   | ((PREV) & (int)N_BTMASK))
401
402/* Number of elements used in sdb_dims.  */
403static int sdb_n_dims = 0;
404
405/* Table of array dimensions of current type.  */
406static int sdb_dims[SDB_MAX_DIM];
407
408/* Size of outermost array currently being processed.  */
409static int sdb_type_size = -1;
410
411static int
412plain_type (type)
413     tree type;
414{
415  int val = plain_type_1 (type, 0);
416
417  /* If we have already saved up some array dimensions, print them now.  */
418  if (sdb_n_dims > 0)
419    {
420      int i;
421      PUT_SDB_START_DIM;
422      for (i = sdb_n_dims - 1; i > 0; i--)
423        PUT_SDB_NEXT_DIM (sdb_dims[i]);
424      PUT_SDB_LAST_DIM (sdb_dims[0]);
425      sdb_n_dims = 0;
426
427      sdb_type_size = int_size_in_bytes (type);
428      /* Don't kill sdb if type is not laid out or has variable size.  */
429      if (sdb_type_size < 0)
430        sdb_type_size = 0;
431    }
432  /* If we have computed the size of an array containing this type,
433     print it now.  */
434  if (sdb_type_size >= 0)
435    {
436      PUT_SDB_SIZE (sdb_type_size);
437      sdb_type_size = -1;
438    }
439  return val;
440}
441
442static int
443template_name_p (name)
444     tree name;
445{
446  register char *ptr = IDENTIFIER_POINTER (name);
447  while (*ptr && *ptr != '<')
448    ptr++;
449
450  return *ptr != '\0';
451}
452
453static void
454sdbout_record_type_name (type)
455     tree type;
456{
457  char *name = 0;
458  int no_name;
459
460  if (KNOWN_TYPE_TAG (type))
461    return;
462
463  if (TYPE_NAME (type) != 0)
464    {
465      tree t = 0;
466      /* Find the IDENTIFIER_NODE for the type name.  */
467      if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
468        t = TYPE_NAME (type);
469      else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
470        {
471          t = DECL_NAME (TYPE_NAME (type));
472          /* The DECL_NAME for templates includes "<>", which breaks
473             most assemblers.  Use its assembler name instead, which
474             has been mangled into being safe.  */
475          if (t && template_name_p (t))
476            t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
477        }
478
479      /* Now get the name as a string, or invent one.  */
480      if (t != NULL_TREE)
481        name = IDENTIFIER_POINTER (t);
482    }
483
484  no_name = (name == 0 || *name == 0);
485  if (no_name)
486    name = gen_fake_label ();
487
488  SET_KNOWN_TYPE_TAG (type, name);
489#ifdef SDB_ALLOW_FORWARD_REFERENCES
490  if (no_name)
491    sdbout_queue_anonymous_type (type);
492#endif
493}
494
495/* Return the .type value for type TYPE.
496
497   LEVEL indicates how many levels deep we have recursed into the type.
498   The SDB debug format can only represent 6 derived levels of types.
499   After that, we must output inaccurate debug info.  We deliberately
500   stop before the 7th level, so that ADA recursive types will not give an
501   infinite loop.  */
502
503static int
504plain_type_1 (type, level)
505     tree type;
506     int level;
507{
508  if (type == 0)
509    type = void_type_node;
510  else if (type == error_mark_node)
511    type = integer_type_node;
512  else
513    type = TYPE_MAIN_VARIANT (type);
514
515  switch (TREE_CODE (type))
516    {
517    case VOID_TYPE:
518      return T_VOID;
519    case INTEGER_TYPE:
520      {
521        int size = int_size_in_bytes (type) * BITS_PER_UNIT;
522
523        /* Carefully distinguish all the standard types of C,
524           without messing up if the language is not C.
525           Note that we check only for the names that contain spaces;
526           other names might occur by coincidence in other languages.  */
527        if (TYPE_NAME (type) != 0
528            && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
529            && DECL_NAME (TYPE_NAME (type)) != 0
530            && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
531          {
532            char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
533
534            if (!strcmp (name, "char"))
535              return T_CHAR;
536            if (!strcmp (name, "unsigned char"))
537              return T_UCHAR;
538            if (!strcmp (name, "signed char"))
539              return T_CHAR;
540            if (!strcmp (name, "int"))
541              return T_INT;
542            if (!strcmp (name, "unsigned int"))
543              return T_UINT;
544            if (!strcmp (name, "short int"))
545              return T_SHORT;
546            if (!strcmp (name, "short unsigned int"))
547              return T_USHORT;
548            if (!strcmp (name, "long int"))
549              return T_LONG;
550            if (!strcmp (name, "long unsigned int"))
551              return T_ULONG;
552          }
553
554        if (size == INT_TYPE_SIZE)
555          return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
556        if (size == CHAR_TYPE_SIZE)
557          return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
558        if (size == SHORT_TYPE_SIZE)
559          return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
560        if (size == LONG_TYPE_SIZE)
561          return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
562        if (size == LONG_LONG_TYPE_SIZE)        /* better than nothing */
563          return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
564        return 0;
565      }
566
567    case REAL_TYPE:
568      {
569        int precision = TYPE_PRECISION (type);
570        if (precision == FLOAT_TYPE_SIZE)
571          return T_FLOAT;
572        if (precision == DOUBLE_TYPE_SIZE)
573          return T_DOUBLE;
574#ifdef EXTENDED_SDB_BASIC_TYPES
575        if (precision == LONG_DOUBLE_TYPE_SIZE)
576          return T_LNGDBL;
577#else
578        if (precision == LONG_DOUBLE_TYPE_SIZE)
579          return T_DOUBLE;      /* better than nothing */
580#endif
581        return 0;
582      }
583
584    case ARRAY_TYPE:
585      {
586        int m;
587        if (level >= 6)
588          return T_VOID;
589        else
590          m = plain_type_1 (TREE_TYPE (type), level+1);
591        if (sdb_n_dims < SDB_MAX_DIM)
592          sdb_dims[sdb_n_dims++]
593            = (TYPE_DOMAIN (type)
594               && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST
595               && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST
596               ? (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
597                  - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
598               : 0);
599        return PUSH_DERIVED_LEVEL (DT_ARY, m);
600      }
601
602    case RECORD_TYPE:
603    case UNION_TYPE:
604    case QUAL_UNION_TYPE:
605    case ENUMERAL_TYPE:
606      {
607        char *tag;
608#ifdef SDB_ALLOW_FORWARD_REFERENCES
609        sdbout_record_type_name (type);
610#endif
611#ifndef SDB_ALLOW_UNKNOWN_REFERENCES
612        if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
613#ifdef SDB_ALLOW_FORWARD_REFERENCES
614            || TYPE_MODE (type) != VOIDmode
615#endif
616            )
617#endif
618          {
619            /* Output the referenced structure tag name
620               only if the .def has already been finished.
621               At least on 386, the Unix assembler
622               cannot handle forward references to tags.  */
623            /* But the 88100, it requires them, sigh...  */
624            /* And the MIPS requires unknown refs as well...  */
625            tag = KNOWN_TYPE_TAG (type);
626            PUT_SDB_TAG (tag);
627            /* These 3 lines used to follow the close brace.
628               However, a size of 0 without a tag implies a tag of 0,
629               so if we don't know a tag, we can't mention the size.  */
630            sdb_type_size = int_size_in_bytes (type);
631            if (sdb_type_size < 0)
632              sdb_type_size = 0;
633          }
634        return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
635                : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
636                : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
637                : T_ENUM);
638      }
639    case POINTER_TYPE:
640    case REFERENCE_TYPE:
641      {
642        int m;
643        if (level >= 6)
644          return T_VOID;
645        else
646          m = plain_type_1 (TREE_TYPE (type), level+1);
647        return PUSH_DERIVED_LEVEL (DT_PTR, m);
648      }
649    case FUNCTION_TYPE:
650    case METHOD_TYPE:
651      {
652        int m;
653        if (level >= 6)
654          return T_VOID;
655        else
656          m = plain_type_1 (TREE_TYPE (type), level+1);
657        return PUSH_DERIVED_LEVEL (DT_FCN, m);
658      }
659    default:
660      return 0;
661    }
662}
663
664/* Output the symbols defined in block number DO_BLOCK.
665   Set NEXT_BLOCK_NUMBER to 0 before calling.
666
667   This function works by walking the tree structure of blocks,
668   counting blocks until it finds the desired block.  */
669
670static int do_block = 0;
671
672static int next_block_number;
673
674static void
675sdbout_block (block)
676     register tree block;
677{
678  while (block)
679    {
680      /* Ignore blocks never expanded or otherwise marked as real.  */
681      if (TREE_USED (block))
682        {
683          /* When we reach the specified block, output its symbols.  */
684          if (next_block_number == do_block)
685            {
686              sdbout_syms (BLOCK_VARS (block));
687            }
688
689          /* If we are past the specified block, stop the scan.  */
690          if (next_block_number > do_block)
691            return;
692
693          next_block_number++;
694
695          /* Scan the blocks within this block.  */
696          sdbout_block (BLOCK_SUBBLOCKS (block));
697        }
698
699      block = BLOCK_CHAIN (block);
700    }
701}
702
703/* Call sdbout_symbol on each decl in the chain SYMS.  */
704
705static void
706sdbout_syms (syms)
707     tree syms;
708{
709  while (syms)
710    {
711      if (TREE_CODE (syms) != LABEL_DECL)
712        sdbout_symbol (syms, 1);
713      syms = TREE_CHAIN (syms);
714    }
715}
716
717/* Output SDB information for a symbol described by DECL.
718   LOCAL is nonzero if the symbol is not file-scope.  */
719
720void
721sdbout_symbol (decl, local)
722     tree decl;
723     int local;
724{
725  tree type = TREE_TYPE (decl);
726  tree context = NULL_TREE;
727  rtx value;
728  int regno = -1;
729  char *name;
730
731  sdbout_one_type (type);
732
733#if 0 /* This loses when functions are marked to be ignored,
734         which happens in the C++ front end.  */
735  if (DECL_IGNORED_P (decl))
736    return;
737#endif
738
739  switch (TREE_CODE (decl))
740    {
741    case CONST_DECL:
742      /* Enum values are defined by defining the enum type.  */
743      return;
744
745    case FUNCTION_DECL:
746      /* Don't mention a nested function under its parent.  */
747      context = decl_function_context (decl);
748      if (context == current_function_decl)
749        return;
750      /* Check DECL_INITIAL to distinguish declarations from definitions.
751         Don't output debug info here for declarations; they will have
752         a DECL_INITIAL value of 0.  */
753      if (! DECL_INITIAL (decl))
754        return;
755      if (GET_CODE (DECL_RTL (decl)) != MEM
756          || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
757        return;
758      PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
759      PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
760      PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
761      break;
762
763    case TYPE_DECL:
764      /* Done with tagged types.  */
765      if (DECL_NAME (decl) == 0)
766        return;
767      if (DECL_IGNORED_P (decl))
768        return;
769
770      /* Output typedef name.  */
771      if (template_name_p (DECL_NAME (decl)))
772        PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
773      else
774        PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
775      PUT_SDB_SCL (C_TPDEF);
776      break;
777
778    case PARM_DECL:
779      /* Parm decls go in their own separate chains
780         and are output by sdbout_reg_parms and sdbout_parms.  */
781      abort ();
782
783    case VAR_DECL:
784      /* Don't mention a variable that is external.
785         Let the file that defines it describe it.  */
786      if (DECL_EXTERNAL (decl))
787        return;
788
789      /* Ignore __FUNCTION__, etc.  */
790      if (DECL_IGNORED_P (decl))
791        return;
792
793      /* If there was an error in the declaration, don't dump core
794         if there is no RTL associated with the variable doesn't
795         exist.  */
796      if (DECL_RTL (decl) == 0)
797        return;
798
799      DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX, 0);
800#ifdef LEAF_REG_REMAP
801      if (leaf_function)
802        leaf_renumber_regs_insn (DECL_RTL (decl));
803#endif
804      value = DECL_RTL (decl);
805
806      /* Don't mention a variable at all
807         if it was completely optimized into nothingness.
808
809         If DECL was from an inline function, then its rtl
810         is not identically the rtl that was used in this
811         particular compilation.  */
812      if (GET_CODE (value) == REG)
813        {
814          regno = REGNO (DECL_RTL (decl));
815          if (regno >= FIRST_PSEUDO_REGISTER)
816            return;
817        }
818      else if (GET_CODE (value) == SUBREG)
819        {
820          int offset = 0;
821          while (GET_CODE (value) == SUBREG)
822            {
823              offset += SUBREG_WORD (value);
824              value = SUBREG_REG (value);
825            }
826          if (GET_CODE (value) == REG)
827            {
828              regno = REGNO (value);
829              if (regno >= FIRST_PSEUDO_REGISTER)
830                return;
831              regno += offset;
832            }
833          alter_subreg (DECL_RTL (decl));
834          value = DECL_RTL (decl);
835        }
836      /* Don't output anything if an auto variable
837         gets RTL that is static.
838         GAS version 2.2 can't handle such output.  */
839      else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
840               && ! TREE_STATIC (decl))
841        return;
842
843      /* Emit any structure, union, or enum type that has not been output.
844         This occurs for tag-less structs (et al) used to declare variables
845         within functions.  */
846      if (TREE_CODE (type) == ENUMERAL_TYPE
847          || TREE_CODE (type) == RECORD_TYPE
848          || TREE_CODE (type) == UNION_TYPE
849          || TREE_CODE (type) == QUAL_UNION_TYPE)
850        {
851          if (TYPE_SIZE (type) != 0             /* not a forward reference */
852              && KNOWN_TYPE_TAG (type) == 0)    /* not yet declared */
853            sdbout_one_type (type);
854        }
855
856      /* Defer SDB information for top-level initialized variables! */
857      if (! local
858          && GET_CODE (value) == MEM
859          && DECL_INITIAL (decl))
860        return;
861
862      /* C++ in 2.3 makes nameless symbols.  That will be fixed later.
863         For now, avoid crashing.  */
864      if (DECL_NAME (decl) == NULL_TREE)
865        return;
866
867      /* Record the name for, starting a symtab entry.  */
868      name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
869
870      if (GET_CODE (value) == MEM
871          && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
872        {
873          PUT_SDB_DEF (name);
874          if (TREE_PUBLIC (decl))
875            {
876              PUT_SDB_VAL (XEXP (value, 0));
877              PUT_SDB_SCL (C_EXT);
878            }
879          else
880            {
881              PUT_SDB_VAL (XEXP (value, 0));
882              PUT_SDB_SCL (C_STAT);
883            }
884        }
885      else if (regno >= 0)
886        {
887          PUT_SDB_DEF (name);
888          PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
889          PUT_SDB_SCL (C_REG);
890        }
891      else if (GET_CODE (value) == MEM
892               && (GET_CODE (XEXP (value, 0)) == MEM
893                   || (GET_CODE (XEXP (value, 0)) == REG
894                       && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
895                       && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
896        /* If the value is indirect by memory or by a register
897           that isn't the frame pointer
898           then it means the object is variable-sized and address through
899           that register or stack slot.  COFF has no way to represent this
900           so all we can do is output the variable as a pointer.  */
901        {
902          PUT_SDB_DEF (name);
903          if (GET_CODE (XEXP (value, 0)) == REG)
904            {
905              PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
906              PUT_SDB_SCL (C_REG);
907            }
908          else
909            {
910              /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
911                 (CONST_INT...)))).
912                 We want the value of that CONST_INT.  */
913              /* Encore compiler hates a newline in a macro arg, it seems.  */
914              PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
915                               (XEXP (XEXP (value, 0), 0)));
916              PUT_SDB_SCL (C_AUTO);
917            }
918
919          type = build_pointer_type (TREE_TYPE (decl));
920        }
921      else if (GET_CODE (value) == MEM
922               && ((GET_CODE (XEXP (value, 0)) == PLUS
923                    && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
924                    && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
925                   /* This is for variables which are at offset zero from
926                      the frame pointer.  This happens on the Alpha.
927                      Non-frame pointer registers are excluded above.  */
928                   || (GET_CODE (XEXP (value, 0)) == REG)))
929        {
930          /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
931             or (MEM (REG...)).  We want the value of that CONST_INT
932             or zero.  */
933          PUT_SDB_DEF (name);
934          PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
935          PUT_SDB_SCL (C_AUTO);
936        }
937      else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
938        {
939          /* Handle an obscure case which can arise when optimizing and
940             when there are few available registers.  (This is *always*
941             the case for i386/i486 targets).  The DECL_RTL looks like
942             (MEM (CONST ...)) even though this variable is a local `auto'
943             or a local `register' variable.  In effect, what has happened
944             is that the reload pass has seen that all assignments and
945             references for one such a local variable can be replaced by
946             equivalent assignments and references to some static storage
947             variable, thereby avoiding the need for a register.  In such
948             cases we're forced to lie to debuggers and tell them that
949             this variable was itself `static'.  */
950          PUT_SDB_DEF (name);
951          PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
952          PUT_SDB_SCL (C_STAT);
953        }
954      else
955        {
956          /* It is something we don't know how to represent for SDB.  */
957          return;
958        }
959      break;
960    }
961  PUT_SDB_TYPE (plain_type (type));
962  PUT_SDB_ENDEF;
963}
964
965/* Output SDB information for a top-level initialized variable
966   that has been delayed.  */
967
968void
969sdbout_toplevel_data (decl)
970     tree decl;
971{
972  tree type = TREE_TYPE (decl);
973
974  if (DECL_IGNORED_P (decl))
975    return;
976
977  if (! (TREE_CODE (decl) == VAR_DECL
978         && GET_CODE (DECL_RTL (decl)) == MEM
979         && DECL_INITIAL (decl)))
980    abort ();
981
982  PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
983  PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
984  if (TREE_PUBLIC (decl))
985    {
986      PUT_SDB_SCL (C_EXT);
987    }
988  else
989    {
990      PUT_SDB_SCL (C_STAT);
991    }
992  PUT_SDB_TYPE (plain_type (type));
993  PUT_SDB_ENDEF;
994}
995
996#ifdef SDB_ALLOW_FORWARD_REFERENCES
997
998/* Machinery to record and output anonymous types.  */
999
1000static tree anonymous_types;
1001
1002static void
1003sdbout_queue_anonymous_type (type)
1004     tree type;
1005{
1006  anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
1007}
1008
1009static void
1010sdbout_dequeue_anonymous_types ()
1011{
1012  register tree types, link;
1013
1014  while (anonymous_types)
1015    {
1016      types = nreverse (anonymous_types);
1017      anonymous_types = NULL_TREE;
1018
1019      for (link = types; link; link = TREE_CHAIN (link))
1020        {
1021          register tree type = TREE_VALUE (link);
1022
1023          if (type && ! TREE_ASM_WRITTEN (type))
1024            sdbout_one_type (type);
1025        }
1026    }
1027}
1028
1029#endif
1030
1031/* Given a chain of ..._TYPE nodes, all of which have names,
1032   output definitions of those names, as typedefs.  */
1033
1034void
1035sdbout_types (types)
1036     register tree types;
1037{
1038  register tree link;
1039
1040  for (link = types; link; link = TREE_CHAIN (link))
1041    sdbout_one_type (link);
1042
1043#ifdef SDB_ALLOW_FORWARD_REFERENCES
1044  sdbout_dequeue_anonymous_types ();
1045#endif
1046}
1047
1048static void
1049sdbout_type (type)
1050     tree type;
1051{
1052  if (type == error_mark_node)
1053    type = integer_type_node;
1054  PUT_SDB_TYPE (plain_type (type));
1055}
1056
1057/* Output types of the fields of type TYPE, if they are structs.
1058
1059   Formerly did not chase through pointer types, since that could be circular.
1060   They must come before TYPE, since forward refs are not allowed.
1061   Now james@bigtex.cactus.org says to try them.  */
1062
1063static void
1064sdbout_field_types (type)
1065     tree type;
1066{
1067  tree tail;
1068
1069  for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1070    if (POINTER_TYPE_P (TREE_TYPE (tail)))
1071      sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1072    else
1073      sdbout_one_type (TREE_TYPE (tail));
1074}
1075
1076/* Use this to put out the top level defined record and union types
1077   for later reference.  If this is a struct with a name, then put that
1078   name out.  Other unnamed structs will have .xxfake labels generated so
1079   that they may be referred to later.
1080   The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1081   It may NOT be called recursively.  */
1082
1083static void
1084sdbout_one_type (type)
1085     tree type;
1086{
1087  if (current_function_decl != NULL_TREE
1088      && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1089    ; /* Don't change section amid function.  */
1090  else
1091    text_section ();
1092
1093  switch (TREE_CODE (type))
1094    {
1095    case RECORD_TYPE:
1096    case UNION_TYPE:
1097    case QUAL_UNION_TYPE:
1098    case ENUMERAL_TYPE:
1099      type = TYPE_MAIN_VARIANT (type);
1100      /* Don't output a type twice.  */
1101      if (TREE_ASM_WRITTEN (type))
1102        /* James said test TREE_ASM_BEING_WRITTEN here.  */
1103        return;
1104
1105      /* Output nothing if type is not yet defined.  */
1106      if (TYPE_SIZE (type) == 0)
1107        return;
1108
1109      TREE_ASM_WRITTEN (type) = 1;
1110#if 1
1111      /* This is reputed to cause trouble with the following case,
1112         but perhaps checking TYPE_SIZE above will fix it.  */
1113
1114      /* Here is a test case:
1115
1116        struct foo {
1117          struct badstr *bbb;
1118        } forwardref;
1119
1120        typedef struct intermediate {
1121          int aaaa;
1122        } intermediate_ref;
1123
1124        typedef struct badstr {
1125          int ccccc;
1126        } badtype;   */
1127
1128#if 0
1129      TREE_ASM_BEING_WRITTEN (type) = 1;
1130#endif
1131      /* This change, which ought to make better output,
1132         used to make the COFF assembler unhappy.
1133         Changes involving KNOWN_TYPE_TAG may fix the problem.  */
1134      /* Before really doing anything, output types we want to refer to.  */
1135      /* Note that in version 1 the following two lines
1136         are not used if forward references are in use.  */
1137      if (TREE_CODE (type) != ENUMERAL_TYPE)
1138        sdbout_field_types (type);
1139#if 0
1140      TREE_ASM_WRITTEN (type) = 1;
1141#endif
1142#endif
1143
1144      /* Output a structure type.  */
1145      {
1146        int size = int_size_in_bytes (type);
1147        int member_scl;
1148        tree tem;
1149        int i, n_baseclasses = 0;
1150
1151        /* Record the type tag, but not in its permanent place just yet.  */
1152        sdbout_record_type_name (type);
1153
1154        PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1155
1156        switch (TREE_CODE (type))
1157          {
1158          case UNION_TYPE:
1159          case QUAL_UNION_TYPE:
1160            PUT_SDB_SCL (C_UNTAG);
1161            PUT_SDB_TYPE (T_UNION);
1162            member_scl = C_MOU;
1163            break;
1164
1165          case RECORD_TYPE:
1166            PUT_SDB_SCL (C_STRTAG);
1167            PUT_SDB_TYPE (T_STRUCT);
1168            member_scl = C_MOS;
1169            break;
1170
1171          case ENUMERAL_TYPE:
1172            PUT_SDB_SCL (C_ENTAG);
1173            PUT_SDB_TYPE (T_ENUM);
1174            member_scl = C_MOE;
1175            break;
1176          }
1177
1178        PUT_SDB_SIZE (size);
1179        PUT_SDB_ENDEF;
1180
1181        /* Print out the base class information with fields
1182           named after the types they hold.  */
1183        if (TYPE_BINFO (type)
1184            && TYPE_BINFO_BASETYPES (type))
1185          n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1186        for (i = 0; i < n_baseclasses; i++)
1187          {
1188            tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1189            tree child_type = BINFO_TYPE (child);
1190            tree child_type_name;
1191            if (TYPE_NAME (child_type) == 0)
1192              continue;
1193            if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1194              child_type_name = TYPE_NAME (child_type);
1195            else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1196              {
1197                child_type_name = DECL_NAME (TYPE_NAME (child_type));
1198                if (child_type_name && template_name_p (child_type_name))
1199                  child_type_name
1200                    = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1201              }
1202            else
1203              continue;
1204
1205            CONTIN;
1206            PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1207            PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
1208            PUT_SDB_SCL (member_scl);
1209            sdbout_type (BINFO_TYPE (child));
1210            PUT_SDB_ENDEF;
1211          }
1212
1213        /* output the individual fields */
1214
1215        if (TREE_CODE (type) == ENUMERAL_TYPE)
1216          for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1217            {
1218              PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1219              PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1220              PUT_SDB_SCL (C_MOE);
1221              PUT_SDB_TYPE (T_MOE);
1222              PUT_SDB_ENDEF;
1223            }
1224
1225        else                    /* record or union type */
1226          for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1227            /* Output the name, type, position (in bits), size (in bits)
1228               of each field.  */
1229
1230            /* Omit here the nameless fields that are used to skip bits.
1231               Also omit fields with variable size or position.
1232               Also omit non FIELD_DECL nodes that GNU C++ may put here.  */
1233            if (TREE_CODE (tem) == FIELD_DECL
1234                && DECL_NAME (tem) != 0
1235                && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
1236                && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
1237              {
1238                char *name;
1239
1240                CONTIN;
1241                name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
1242                PUT_SDB_DEF (name);
1243                if (DECL_BIT_FIELD_TYPE (tem))
1244                  {
1245                    PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
1246                    PUT_SDB_SCL (C_FIELD);
1247                    sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1248                    PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
1249                  }
1250                else
1251                  {
1252                    PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
1253                                     / BITS_PER_UNIT);
1254                    PUT_SDB_SCL (member_scl);
1255                    sdbout_type (TREE_TYPE (tem));
1256                  }
1257                PUT_SDB_ENDEF;
1258              }
1259        /* output end of a structure,union, or enumeral definition */
1260
1261        PUT_SDB_PLAIN_DEF ("eos");
1262        PUT_SDB_INT_VAL (size);
1263        PUT_SDB_SCL (C_EOS);
1264        PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1265        PUT_SDB_SIZE (size);
1266        PUT_SDB_ENDEF;
1267        break;
1268      }
1269    }
1270}
1271
1272/* The following two functions output definitions of function parameters.
1273   Each parameter gets a definition locating it in the parameter list.
1274   Each parameter that is a register variable gets a second definition
1275   locating it in the register.
1276
1277   Printing or argument lists in gdb uses the definitions that
1278   locate in the parameter list.  But reference to the variable in
1279   expressions uses preferentially the definition as a register.  */
1280
1281/* Output definitions, referring to storage in the parmlist,
1282   of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
1283
1284static void
1285sdbout_parms (parms)
1286     tree parms;
1287{
1288  for (; parms; parms = TREE_CHAIN (parms))
1289    if (DECL_NAME (parms))
1290      {
1291        int current_sym_value = 0;
1292        char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1293
1294        if (name == 0 || *name == 0)
1295          name = gen_fake_label ();
1296
1297        /* Perform any necessary register eliminations on the parameter's rtl,
1298           so that the debugging output will be accurate.  */
1299        DECL_INCOMING_RTL (parms)
1300          = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX, 0);
1301        DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX, 0);
1302
1303        if (PARM_PASSED_IN_MEMORY (parms))
1304          {
1305            rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1306            tree type;
1307
1308            /* ??? Here we assume that the parm address is indexed
1309               off the frame pointer or arg pointer.
1310               If that is not true, we produce meaningless results,
1311               but do not crash.  */
1312            if (GET_CODE (addr) == PLUS
1313                && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1314              current_sym_value = INTVAL (XEXP (addr, 1));
1315            else
1316              current_sym_value = 0;
1317
1318            if (GET_CODE (DECL_RTL (parms)) == REG
1319                && REGNO (DECL_RTL (parms)) >= 0
1320                && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1321              type = DECL_ARG_TYPE (parms);
1322            else
1323              {
1324                int original_sym_value = current_sym_value;
1325
1326                /* This is the case where the parm is passed as an int or
1327                   double and it is converted to a char, short or float
1328                   and stored back in the parmlist.  In this case, describe
1329                   the parm with the variable's declared type, and adjust
1330                   the address if the least significant bytes (which we are
1331                   using) are not the first ones.  */
1332                if (BYTES_BIG_ENDIAN
1333                    && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1334                  current_sym_value +=
1335                    (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1336                     - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1337
1338                if (GET_CODE (DECL_RTL (parms)) == MEM
1339                    && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1340                    && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1341                        == CONST_INT)
1342                    && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1343                        == current_sym_value))
1344                  type = TREE_TYPE (parms);
1345                else
1346                  {
1347                    current_sym_value = original_sym_value;
1348                    type = DECL_ARG_TYPE (parms);
1349                  }
1350              }
1351
1352            PUT_SDB_DEF (name);
1353            PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1354            PUT_SDB_SCL (C_ARG);
1355            PUT_SDB_TYPE (plain_type (type));
1356            PUT_SDB_ENDEF;
1357          }
1358        else if (GET_CODE (DECL_RTL (parms)) == REG)
1359          {
1360            rtx best_rtl;
1361            /* Parm passed in registers and lives in registers or nowhere.  */
1362
1363            /* If parm lives in a register, use that register;
1364               pretend the parm was passed there.  It would be more consistent
1365               to describe the register where the parm was passed,
1366               but in practice that register usually holds something else.  */
1367            if (REGNO (DECL_RTL (parms)) >= 0
1368                && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1369              best_rtl = DECL_RTL (parms);
1370            /* If the parm lives nowhere,
1371               use the register where it was passed.  */
1372            else
1373              best_rtl = DECL_INCOMING_RTL (parms);
1374
1375            PUT_SDB_DEF (name);
1376            PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1377            PUT_SDB_SCL (C_REGPARM);
1378            PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1379            PUT_SDB_ENDEF;
1380          }
1381        else if (GET_CODE (DECL_RTL (parms)) == MEM
1382                 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1383          {
1384            /* Parm was passed in registers but lives on the stack.  */
1385
1386            /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1387               in which case we want the value of that CONST_INT,
1388               or (MEM (REG ...)) or (MEM (MEM ...)),
1389               in which case we use a value of zero.  */
1390            if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1391                || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1392              current_sym_value = 0;
1393            else
1394              current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1395
1396            /* Again, this assumes the offset is based on the arg pointer.  */
1397            PUT_SDB_DEF (name);
1398            PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1399                                                  XEXP (DECL_RTL (parms), 0)));
1400            PUT_SDB_SCL (C_ARG);
1401            PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1402            PUT_SDB_ENDEF;
1403          }
1404      }
1405}
1406
1407/* Output definitions for the places where parms live during the function,
1408   when different from where they were passed, when the parms were passed
1409   in memory.
1410
1411   It is not useful to do this for parms passed in registers
1412   that live during the function in different registers, because it is
1413   impossible to look in the passed register for the passed value,
1414   so we use the within-the-function register to begin with.
1415
1416   PARMS is a chain of PARM_DECL nodes.  */
1417
1418static void
1419sdbout_reg_parms (parms)
1420     tree parms;
1421{
1422  for (; parms; parms = TREE_CHAIN (parms))
1423    if (DECL_NAME (parms))
1424      {
1425        char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1426
1427        /* Report parms that live in registers during the function
1428           but were passed in memory.  */
1429        if (GET_CODE (DECL_RTL (parms)) == REG
1430            && REGNO (DECL_RTL (parms)) >= 0
1431            && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1432            && PARM_PASSED_IN_MEMORY (parms))
1433          {
1434            if (name == 0 || *name == 0)
1435              name = gen_fake_label ();
1436            PUT_SDB_DEF (name);
1437            PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1438            PUT_SDB_SCL (C_REG);
1439            PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1440            PUT_SDB_ENDEF;
1441          }
1442        /* Report parms that live in memory but not where they were passed.  */
1443        else if (GET_CODE (DECL_RTL (parms)) == MEM
1444                 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1445                 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1446                 && PARM_PASSED_IN_MEMORY (parms)
1447                 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1448          {
1449#if 0 /* ??? It is not clear yet what should replace this.  */
1450            int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1451            /* A parm declared char is really passed as an int,
1452               so it occupies the least significant bytes.
1453               On a big-endian machine those are not the low-numbered ones.  */
1454            if (BYTES_BIG_ENDIAN
1455                && offset != -1
1456                && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1457              offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1458                         - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1459            if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1460#endif
1461              {
1462                if (name == 0 || *name == 0)
1463                  name = gen_fake_label ();
1464                PUT_SDB_DEF (name);
1465                PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1466                                 (XEXP (DECL_RTL (parms), 0)));
1467                PUT_SDB_SCL (C_AUTO);
1468                PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1469                PUT_SDB_ENDEF;
1470              }
1471          }
1472      }
1473}
1474
1475/* Describe the beginning of an internal block within a function.
1476   Also output descriptions of variables defined in this block.
1477
1478   N is the number of the block, by order of beginning, counting from 1,
1479   and not counting the outermost (function top-level) block.
1480   The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1481   if the count starts at 0 for the outermost one.  */
1482
1483void
1484sdbout_begin_block (file, line, n)
1485     FILE *file;
1486     int line;
1487     int n;
1488{
1489  tree decl = current_function_decl;
1490  MAKE_LINE_SAFE (line);
1491
1492  /* The SCO compiler does not emit a separate block for the function level
1493     scope, so we avoid it here also.  However, mips ECOFF compilers do emit
1494     a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined.  */
1495#ifndef MIPS_DEBUGGING_INFO
1496  if (n != 1)
1497#endif
1498    PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1499
1500  if (n == 1)
1501    {
1502      /* Include the outermost BLOCK's variables in block 1.  */
1503      next_block_number = 0;
1504      do_block = 0;
1505      sdbout_block (DECL_INITIAL (decl));
1506    }
1507  /* If -g1, suppress all the internal symbols of functions
1508     except for arguments.  */
1509  if (debug_info_level != DINFO_LEVEL_TERSE)
1510    {
1511      next_block_number = 0;
1512      do_block = n;
1513      sdbout_block (DECL_INITIAL (decl));
1514    }
1515
1516#ifdef SDB_ALLOW_FORWARD_REFERENCES
1517  sdbout_dequeue_anonymous_types ();
1518#endif
1519}
1520
1521/* Describe the end line-number of an internal block within a function.  */
1522
1523void
1524sdbout_end_block (file, line, n)
1525     FILE *file;
1526     int line;
1527     int n;
1528{
1529  MAKE_LINE_SAFE (line);
1530
1531  /* The SCO compiler does not emit a separate block for the function level
1532     scope, so we avoid it here also.  However, mips ECOFF compilers do emit
1533     a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined.  */
1534#ifndef MIPS_DEBUGGING_INFO
1535  if (n != 1)
1536#endif
1537  PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1538}
1539
1540/* Output sdb info for the current function name.
1541   Called from assemble_start_function.  */
1542
1543void
1544sdbout_mark_begin_function ()
1545{
1546  sdbout_symbol (current_function_decl, 0);
1547}
1548
1549/* Called at beginning of function body (after prologue).
1550   Record the function's starting line number, so we can output
1551   relative line numbers for the other lines.
1552   Describe beginning of outermost block.
1553   Also describe the parameter list.  */
1554
1555void
1556sdbout_begin_function (line)
1557     int line;
1558{
1559  sdb_begin_function_line = line - 1;
1560  PUT_SDB_FUNCTION_START (line);
1561  sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1562  sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1563}
1564
1565/* Called at end of function (before epilogue).
1566   Describe end of outermost block.  */
1567
1568void
1569sdbout_end_function (line)
1570     int line;
1571{
1572#ifdef SDB_ALLOW_FORWARD_REFERENCES
1573  sdbout_dequeue_anonymous_types ();
1574#endif
1575
1576  MAKE_LINE_SAFE (line);
1577  PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1578
1579  /* Indicate we are between functions, for line-number output.  */
1580  sdb_begin_function_line = -1;
1581}
1582
1583/* Output sdb info for the absolute end of a function.
1584   Called after the epilogue is output.  */
1585
1586void
1587sdbout_end_epilogue ()
1588{
1589  char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1590  PUT_SDB_EPILOGUE_END (name);
1591}
1592
1593/* Output sdb info for the given label.  Called only if LABEL_NAME (insn)
1594   is present.  */
1595
1596void
1597sdbout_label (insn)
1598     register rtx insn;
1599{
1600  PUT_SDB_DEF (LABEL_NAME (insn));
1601  PUT_SDB_VAL (insn);
1602  PUT_SDB_SCL (C_LABEL);
1603  PUT_SDB_TYPE (T_NULL);
1604  PUT_SDB_ENDEF;
1605}
1606
1607/* Change to reading from a new source file.  */
1608
1609void
1610sdbout_start_new_source_file (filename)
1611     char *filename;
1612{
1613#ifdef MIPS_DEBUGGING_INFO
1614  struct sdb_file *n = (struct sdb_file *) xmalloc (sizeof *n);
1615
1616  n->next = current_file;
1617  n->name = filename;
1618  current_file = n;
1619  PUT_SDB_SRC_FILE (filename);
1620#endif
1621}
1622
1623/* Revert to reading a previous source file.  */
1624
1625void
1626sdbout_resume_previous_source_file ()
1627{
1628#ifdef MIPS_DEBUGGING_INFO
1629  struct sdb_file *next;
1630
1631  next = current_file->next;
1632  free (current_file);
1633  current_file = next;
1634  PUT_SDB_SRC_FILE (current_file->name);
1635#endif
1636}
1637
1638#endif /* SDB_DEBUGGING_INFO */
Note: See TracBrowser for help on using the repository browser.