OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [sdbout.c] - Blame information for rev 38

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.