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