1 /* wrstabs.c -- Output stabs debugging information
2 Copyright (C) 1996-2023 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 /* This file contains code which writes out stabs debugging
28 #include "libiberty.h"
29 #include "filenames.h"
30 #include "safe-ctype.h"
34 #include "aout/aout64.h"
35 #include "aout/stab_gnu.h"
37 /* The size of a stabs symbol. This presumes 32 bit values. */
39 #define STAB_SYMBOL_SIZE (12)
41 /* An entry in a string hash table. */
43 struct string_hash_entry
45 struct bfd_hash_entry root
;
46 /* Next string in this table. */
47 struct string_hash_entry
*next
;
48 /* Index in string table. */
50 /* Size of type if this is a typedef. */
54 /* A string hash table. */
56 struct string_hash_table
58 struct bfd_hash_table table
;
61 /* The type stack. Each element on the stack is a string. */
63 struct stab_type_stack
65 /* The next element on the stack. */
66 struct stab_type_stack
*next
;
67 /* This element as a string. */
69 /* The type index of this element. */
71 /* The size of the type. */
73 /* Whether type string defines a new type. */
75 /* String defining struct fields. */
77 /* NULL terminated array of strings defining base classes for a
80 /* String defining class methods. */
82 /* String defining vtable pointer for a class. */
86 /* This structure is used to keep track of type indices for tagged
95 /* The kind of type. This is set to DEBUG_KIND_ILLEGAL when the
97 enum debug_type_kind kind
;
98 /* The size of the struct. */
102 /* We remember various sorts of type indices. They are not related,
103 but, for convenience, we keep all the information in this
106 struct stab_type_cache
108 /* The void type index. */
110 /* Signed integer type indices, indexed by size - 1. */
111 long signed_integer_types
[8];
112 /* Unsigned integer type indices, indexed by size - 1. */
113 long unsigned_integer_types
[8];
114 /* Floating point types, indexed by size - 1. */
115 long float_types
[16];
116 /* Pointers to types, indexed by the type index. */
118 size_t pointer_types_alloc
;
119 /* Functions returning types, indexed by the type index. */
120 long *function_types
;
121 size_t function_types_alloc
;
122 /* References to types, indexed by the type index. */
123 long *reference_types
;
124 size_t reference_types_alloc
;
125 /* Struct/union/class type indices, indexed by the struct id. */
126 struct stab_tag
*struct_types
;
127 size_t struct_types_alloc
;
130 /* This is the handle passed through debug_write. */
132 struct stab_write_handle
136 /* This buffer holds the symbols. */
139 size_t symbols_alloc
;
140 /* This is a list of hash table entries for the strings. */
141 struct string_hash_entry
*strings
;
142 /* The last string hash table entry. */
143 struct string_hash_entry
*last_string
;
144 /* The size of the strings. */
146 /* This hash table eliminates duplicate strings. */
147 struct string_hash_table strhash
;
148 /* The type stack. */
149 struct stab_type_stack
*type_stack
;
150 /* The next type index. */
152 /* The type cache. */
153 struct stab_type_cache type_cache
;
154 /* A mapping from typedef names to type indices. */
155 struct string_hash_table typedef_hash
;
156 /* If this is not -1, it is the offset to the most recent N_SO
157 symbol, and the value of that symbol needs to be set. */
159 /* If this is not -1, it is the offset to the most recent N_FUN
160 symbol, and the value of that symbol needs to be set. */
162 /* The last text section address seen. */
163 bfd_vma last_text_address
;
164 /* The block nesting depth. */
165 unsigned int nesting
;
166 /* The function address. */
168 /* A pending LBRAC symbol. */
169 bfd_vma pending_lbrac
;
170 /* The current line number file name. */
171 const char *lineno_filename
;
174 static bool stab_start_compilation_unit (void *, const char *);
175 static bool stab_start_source (void *, const char *);
176 static bool stab_empty_type (void *);
177 static bool stab_void_type (void *);
178 static bool stab_int_type (void *, unsigned int, bool);
179 static bool stab_float_type (void *, unsigned int);
180 static bool stab_complex_type (void *, unsigned int);
181 static bool stab_bool_type (void *, unsigned int);
182 static bool stab_enum_type
183 (void *, const char *, const char **, bfd_signed_vma
*);
184 static bool stab_pointer_type (void *);
185 static bool stab_function_type (void *, int, bool);
186 static bool stab_reference_type (void *);
187 static bool stab_range_type (void *, bfd_signed_vma
, bfd_signed_vma
);
188 static bool stab_array_type
189 (void *, bfd_signed_vma
, bfd_signed_vma
, bool);
190 static bool stab_set_type (void *, bool);
191 static bool stab_offset_type (void *);
192 static bool stab_method_type (void *, bool, int, bool);
193 static bool stab_const_type (void *);
194 static bool stab_volatile_type (void *);
195 static bool stab_start_struct_type
196 (void *, const char *, unsigned int, bool, unsigned int);
197 static bool stab_struct_field
198 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
199 static bool stab_end_struct_type (void *);
200 static bool stab_start_class_type
201 (void *, const char *, unsigned int, bool, unsigned int,
203 static bool stab_class_static_member
204 (void *, const char *, const char *, enum debug_visibility
);
205 static bool stab_class_baseclass
206 (void *, bfd_vma
, bool, enum debug_visibility
);
207 static bool stab_class_start_method (void *, const char *);
208 static bool stab_class_method_variant
209 (void *, const char *, enum debug_visibility
, bool, bool,
211 static bool stab_class_static_method_variant
212 (void *, const char *, enum debug_visibility
, bool, bool);
213 static bool stab_class_end_method (void *);
214 static bool stab_end_class_type (void *);
215 static bool stab_typedef_type (void *, const char *);
216 static bool stab_tag_type
217 (void *, const char *, unsigned int, enum debug_type_kind
);
218 static bool stab_typdef (void *, const char *);
219 static bool stab_tag (void *, const char *);
220 static bool stab_int_constant (void *, const char *, bfd_vma
);
221 static bool stab_float_constant (void *, const char *, double);
222 static bool stab_typed_constant (void *, const char *, bfd_vma
);
223 static bool stab_variable
224 (void *, const char *, enum debug_var_kind
, bfd_vma
);
225 static bool stab_start_function (void *, const char *, bool);
226 static bool stab_function_parameter
227 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
228 static bool stab_start_block (void *, bfd_vma
);
229 static bool stab_end_block (void *, bfd_vma
);
230 static bool stab_end_function (void *);
231 static bool stab_lineno (void *, const char *, unsigned long, bfd_vma
);
233 static const struct debug_write_fns stab_fns
=
235 stab_start_compilation_unit
,
254 stab_start_struct_type
,
256 stab_end_struct_type
,
257 stab_start_class_type
,
258 stab_class_static_member
,
259 stab_class_baseclass
,
260 stab_class_start_method
,
261 stab_class_method_variant
,
262 stab_class_static_method_variant
,
263 stab_class_end_method
,
274 stab_function_parameter
,
281 /* Routine to create an entry in a string hash table. */
283 static struct bfd_hash_entry
*
284 string_hash_newfunc (struct bfd_hash_entry
*entry
,
285 struct bfd_hash_table
*table
, const char *string
)
287 struct string_hash_entry
*ret
= (struct string_hash_entry
*) entry
;
289 /* Allocate the structure if it has not already been allocated by a
291 if (ret
== (struct string_hash_entry
*) NULL
)
292 ret
= ((struct string_hash_entry
*)
293 bfd_hash_allocate (table
, sizeof (struct string_hash_entry
)));
294 if (ret
== (struct string_hash_entry
*) NULL
)
297 /* Call the allocation method of the superclass. */
298 ret
= ((struct string_hash_entry
*)
299 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
303 /* Initialize the local fields. */
309 return (struct bfd_hash_entry
*) ret
;
312 /* Look up an entry in a string hash table. */
314 #define string_hash_lookup(t, string, create, copy) \
315 ((struct string_hash_entry *) \
316 bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
318 /* Add a symbol to the stabs debugging information we are building. */
321 stab_write_symbol (struct stab_write_handle
*info
, int type
, int desc
,
322 bfd_vma value
, const char *string
)
325 bfd_byte sym
[STAB_SYMBOL_SIZE
];
331 struct string_hash_entry
*h
;
333 h
= string_hash_lookup (&info
->strhash
, string
, true, true);
336 non_fatal (_("string_hash_lookup failed: %s"),
337 bfd_errmsg (bfd_get_error ()));
344 strx
= info
->strings_size
;
346 if (info
->last_string
== NULL
)
349 info
->last_string
->next
= h
;
350 info
->last_string
= h
;
351 info
->strings_size
+= strlen (string
) + 1;
355 /* This presumes 32 bit values. */
356 bfd_put_32 (info
->abfd
, strx
, sym
);
357 bfd_put_8 (info
->abfd
, type
, sym
+ 4);
358 bfd_put_8 (info
->abfd
, 0, sym
+ 5);
359 bfd_put_16 (info
->abfd
, desc
, sym
+ 6);
360 bfd_put_32 (info
->abfd
, value
, sym
+ 8);
362 if (info
->symbols_size
+ STAB_SYMBOL_SIZE
> info
->symbols_alloc
)
364 info
->symbols_alloc
*= 2;
365 info
->symbols
= xrealloc (info
->symbols
, info
->symbols_alloc
);
368 memcpy (info
->symbols
+ info
->symbols_size
, sym
, STAB_SYMBOL_SIZE
);
370 info
->symbols_size
+= STAB_SYMBOL_SIZE
;
376 stab_write_symbol_and_free (struct stab_write_handle
*info
, int type
, int desc
,
377 bfd_vma value
, char *string
)
379 bool ret
= stab_write_symbol (info
, type
, desc
, value
, string
);
384 /* Push a string on to the type stack. */
387 stab_push_string (struct stab_write_handle
*info
, char *string
,
388 long tindex
, bool definition
, unsigned int size
)
390 struct stab_type_stack
*s
;
392 s
= xmalloc (sizeof *s
);
395 s
->definition
= definition
;
399 s
->baseclasses
= NULL
;
403 s
->next
= info
->type_stack
;
404 info
->type_stack
= s
;
410 stab_push_string_dup (struct stab_write_handle
*info
, const char *string
,
411 long tindex
, bool definition
, unsigned int size
)
413 return stab_push_string (info
, xstrdup (string
), tindex
, definition
, size
);
416 /* Push a type index which has already been defined. */
419 stab_push_defined_type (struct stab_write_handle
*info
, long tindex
,
424 sprintf (buf
, "%ld", tindex
);
425 return stab_push_string_dup (info
, buf
, tindex
, false, size
);
428 /* Pop a type off the type stack. The caller is responsible for
429 freeing the string. */
432 stab_pop_type (struct stab_write_handle
*info
)
434 struct stab_type_stack
*s
;
437 s
= info
->type_stack
;
441 info
->type_stack
= s
->next
;
450 /* The general routine to write out stabs in sections debugging
451 information. This accumulates the stabs symbols and the strings in
452 two obstacks. We can't easily write out the information as we go
453 along, because we need to know the section sizes before we can
454 write out the section contents. ABFD is the BFD and DHANDLE is the
455 handle for the debugging information. This sets *PSYMS to point to
456 the symbols, *PSYMSIZE the size of the symbols, *PSTRINGS to the
457 strings, and *PSTRINGSIZE to the size of the strings. */
460 write_stabs_in_sections_debugging_info (bfd
*abfd
, void *dhandle
,
462 bfd_size_type
*psymsize
,
464 bfd_size_type
*pstringsize
)
466 struct stab_write_handle info
;
467 struct string_hash_entry
*h
;
471 memset (&info
, 0, sizeof info
);
474 info
.symbols_alloc
= 500;
475 info
.symbols
= xmalloc (info
.symbols_alloc
);
477 /* Reserve 1 byte for a null byte. */
478 info
.strings_size
= 1;
481 info
.fun_offset
= -1;
482 info
.pending_lbrac
= (bfd_vma
) -1;
484 if (!bfd_hash_table_init (&info
.strhash
.table
, string_hash_newfunc
,
485 sizeof (struct string_hash_entry
))
486 || !bfd_hash_table_init (&info
.typedef_hash
.table
, string_hash_newfunc
,
487 sizeof (struct string_hash_entry
)))
489 non_fatal ("bfd_hash_table_init_failed: %s",
490 bfd_errmsg (bfd_get_error ()));
494 /* The initial symbol holds the string size. */
495 if (! stab_write_symbol (&info
, 0, 0, 0, (const char *) NULL
))
498 /* Output an initial N_SO symbol. */
499 info
.so_offset
= info
.symbols_size
;
500 if (! stab_write_symbol (&info
, N_SO
, 0, 0, bfd_get_filename (abfd
)))
503 if (! debug_write (dhandle
, &stab_fns
, (void *) &info
))
506 if (info
.pending_lbrac
!= (bfd_vma
) -1)
509 /* Output a trailing N_SO. */
510 if (! stab_write_symbol (&info
, N_SO
, 0, info
.last_text_address
,
511 (const char *) NULL
))
514 /* Put the string size in the initial symbol. */
515 bfd_put_32 (abfd
, info
.strings_size
, info
.symbols
+ 8);
517 *psyms
= info
.symbols
;
518 *psymsize
= info
.symbols_size
;
520 *pstringsize
= info
.strings_size
;
521 *pstrings
= xmalloc (info
.strings_size
);
525 for (h
= info
.strings
; h
!= NULL
; h
= h
->next
)
527 strcpy ((char *) p
, h
->root
.string
);
528 p
+= strlen ((char *) p
) + 1;
538 while (info
.type_stack
!= NULL
)
540 struct stab_type_stack
*s
= info
.type_stack
;
541 info
.type_stack
= s
->next
;
544 if (s
->baseclasses
!= NULL
)
546 for (int i
= 0; s
->baseclasses
[i
] != NULL
; i
++)
547 free (s
->baseclasses
[i
]);
548 free (s
->baseclasses
);
554 free (info
.type_cache
.pointer_types
);
555 free (info
.type_cache
.function_types
);
556 free (info
.type_cache
.reference_types
);
557 free (info
.type_cache
.struct_types
);
558 if (info
.typedef_hash
.table
.memory
)
559 bfd_hash_table_free (&info
.typedef_hash
.table
);
560 if (info
.strhash
.table
.memory
)
561 bfd_hash_table_free (&info
.strhash
.table
);
565 /* Start writing out information for a compilation unit. */
568 stab_start_compilation_unit (void *p
, const char *filename
)
570 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
572 /* We would normally output an N_SO symbol here. However, that
573 would force us to reset all of our type information. I think we
574 will be better off just outputting an N_SOL symbol, and not
575 worrying about splitting information between files. */
577 info
->lineno_filename
= filename
;
579 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
582 /* Start writing out information for a particular source file. */
585 stab_start_source (void *p
, const char *filename
)
587 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
589 /* FIXME: The symbol's value is supposed to be the text section
590 address. However, we would have to fill it in later, and gdb
591 doesn't care, so we don't bother with it. */
593 info
->lineno_filename
= filename
;
595 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
598 /* Push an empty type. This shouldn't normally happen. We just use a
602 stab_empty_type (void *p
)
604 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
606 /* We don't call stab_void_type if the type is not yet defined,
607 because that might screw up the typedef. */
609 if (info
->type_cache
.void_type
!= 0)
610 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
616 tindex
= info
->type_index
;
619 sprintf (buf
, "%ld=%ld", tindex
, tindex
);
621 return stab_push_string_dup (info
, buf
, tindex
, false, 0);
625 /* Push a void type. */
628 stab_void_type (void *p
)
630 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
632 if (info
->type_cache
.void_type
!= 0)
633 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
639 tindex
= info
->type_index
;
642 info
->type_cache
.void_type
= tindex
;
644 sprintf (buf
, "%ld=%ld", tindex
, tindex
);
646 return stab_push_string_dup (info
, buf
, tindex
, true, 0);
650 /* Push an integer type. */
653 stab_int_type (void *p
, unsigned int size
, bool unsignedp
)
655 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
658 if (size
<= 0 || (size
> sizeof (long) && size
!= 8))
660 non_fatal (_("stab_int_type: bad size %u"), size
);
665 cache
= info
->type_cache
.signed_integer_types
;
667 cache
= info
->type_cache
.unsigned_integer_types
;
669 if (cache
[size
- 1] != 0)
670 return stab_push_defined_type (info
, cache
[size
- 1], size
);
676 tindex
= info
->type_index
;
679 cache
[size
- 1] = tindex
;
681 int len
= sprintf (buf
, "%ld=r%ld;", tindex
, tindex
);
684 strcpy (buf
+ len
, "0;");
686 if (size
< sizeof (long))
687 sprintf (buf
+ len
, "%ld;", ((long) 1 << (size
* 8)) - 1);
688 else if (size
== sizeof (long))
689 strcpy (buf
+ len
, "-1;");
691 strcpy (buf
+ len
, "01777777777777777777777;");
697 if (size
<= sizeof (long))
698 sprintf (buf
+ len
, "%ld;%ld;",
699 (long) - ((unsigned long) 1 << (size
* 8 - 1)),
700 (long) (((unsigned long) 1 << (size
* 8 - 1)) - 1));
703 "01000000000000000000000;0777777777777777777777;");
708 return stab_push_string_dup (info
, buf
, tindex
, true, size
);
712 /* Push a floating point type. */
715 stab_float_type (void *p
, unsigned int size
)
717 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
720 && size
- 1 < (sizeof info
->type_cache
.float_types
721 / sizeof info
->type_cache
.float_types
[0])
722 && info
->type_cache
.float_types
[size
- 1] != 0)
723 return stab_push_defined_type (info
,
724 info
->type_cache
.float_types
[size
- 1],
732 /* Floats are defined as a subrange of int. */
733 if (! stab_int_type (info
, 4, false))
735 int_type
= stab_pop_type (info
);
737 tindex
= info
->type_index
;
741 && size
- 1 < (sizeof info
->type_cache
.float_types
742 / sizeof info
->type_cache
.float_types
[0]))
743 info
->type_cache
.float_types
[size
- 1] = tindex
;
745 sprintf (buf
, "%ld=r%s;%u;0;", tindex
, int_type
, size
);
749 return stab_push_string_dup (info
, buf
, tindex
, true, size
);
753 /* Push a complex type. */
756 stab_complex_type (void *p
, unsigned int size
)
758 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
762 tindex
= info
->type_index
;
765 sprintf (buf
, "%ld=r%ld;%u;0;", tindex
, tindex
, size
);
767 return stab_push_string_dup (info
, buf
, tindex
, true, size
* 2);
770 /* Push a bool type. We use an XCOFF predefined type, since gdb
771 always recognizes them. */
774 stab_bool_type (void *p
, unsigned int size
)
776 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
799 return stab_push_defined_type (info
, tindex
, size
);
802 /* Push an enum type. */
805 stab_enum_type (void *p
, const char *tag
, const char **names
,
806 bfd_signed_vma
*vals
)
808 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
820 buf
= xmalloc (4 + strlen (tag
));
821 sprintf (buf
, "xe%s:", tag
);
822 /* FIXME: The size is just a guess. */
823 return stab_push_string (info
, buf
, 0, false, 4);
829 for (pn
= names
; *pn
!= NULL
; pn
++)
830 len
+= strlen (*pn
) + 22;
835 out
= stpcpy (out
, "e");
838 tindex
= info
->type_index
;
840 out
+= sprintf (out
, "%s:T%ld=e", tag
, tindex
);
843 for (pn
= names
, pv
= vals
; *pn
!= NULL
; pn
++, pv
++)
844 out
+= sprintf (out
, "%s:%ld,", *pn
, (long) *pv
);
849 /* FIXME: The size is just a guess. */
850 return stab_push_string (info
, buf
, 0, false, 4);
854 /* FIXME: The size is just a guess. */
855 return (stab_write_symbol_and_free (info
, N_LSYM
, 0, 0, buf
)
856 && stab_push_defined_type (info
, tindex
, 4));
860 /* Push a modification of the top type on the stack. Cache the
861 results in CACHE and CACHE_ALLOC. */
864 stab_modify_type (struct stab_write_handle
*info
, int mod
,
865 unsigned int size
, long **cache
, size_t *cache_alloc
)
871 if (info
->type_stack
== NULL
)
873 targindex
= info
->type_stack
->index
;
880 /* Either the target type has no index, or we aren't caching
881 this modifier. Either way we have no way of recording the
882 new type, so we don't bother to define one. */
883 definition
= info
->type_stack
->definition
;
884 s
= stab_pop_type (info
);
885 buf
= xmalloc (strlen (s
) + 2);
886 sprintf (buf
, "%c%s", mod
, s
);
888 return stab_push_string (info
, buf
, 0, definition
, size
);
892 if ((size_t) targindex
>= *cache_alloc
)
896 alloc
= *cache_alloc
;
899 while ((size_t) targindex
>= alloc
)
901 *cache
= xrealloc (*cache
, alloc
* sizeof (**cache
));
902 memset (*cache
+ *cache_alloc
, 0,
903 (alloc
- *cache_alloc
) * sizeof (**cache
));
904 *cache_alloc
= alloc
;
907 tindex
= (*cache
)[targindex
];
908 if (tindex
!= 0 && ! info
->type_stack
->definition
)
910 /* We have already defined a modification of this type, and
911 the entry on the type stack is not a definition, so we
912 can safely discard it (we may have a definition on the
913 stack, even if we already defined a modification, if it
914 is a struct which we did not define at the time it was
916 free (stab_pop_type (info
));
917 return stab_push_defined_type (info
, tindex
, size
);
921 tindex
= info
->type_index
;
924 s
= stab_pop_type (info
);
925 buf
= xmalloc (strlen (s
) + 23);
926 sprintf (buf
, "%ld=%c%s", tindex
, mod
, s
);
929 (*cache
)[targindex
] = tindex
;
931 return stab_push_string (info
, buf
, tindex
, true, size
);
936 /* Push a pointer type. */
939 stab_pointer_type (void *p
)
941 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
943 /* FIXME: The size should depend upon the architecture. */
944 return stab_modify_type (info
, '*', 4, &info
->type_cache
.pointer_types
,
945 &info
->type_cache
.pointer_types_alloc
);
948 /* Push a function type. */
951 stab_function_type (void *p
, int argcount
,
952 bool varargs ATTRIBUTE_UNUSED
)
954 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
957 /* We have no way to represent the argument types, so we just
958 discard them. However, if they define new types, we must output
959 them. We do this by producing empty typedefs. */
960 for (i
= 0; i
< argcount
; i
++)
962 if (! info
->type_stack
->definition
)
963 free (stab_pop_type (info
));
968 s
= stab_pop_type (info
);
970 buf
= xmalloc (strlen (s
) + 3);
971 sprintf (buf
, ":t%s", s
);
974 return stab_write_symbol_and_free (info
, N_LSYM
, 0, 0, buf
);
978 return stab_modify_type (info
, 'f', 0, &info
->type_cache
.function_types
,
979 &info
->type_cache
.function_types_alloc
);
982 /* Push a reference type. */
985 stab_reference_type (void *p
)
987 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
989 /* FIXME: The size should depend upon the architecture. */
990 return stab_modify_type (info
, '&', 4, &info
->type_cache
.reference_types
,
991 &info
->type_cache
.reference_types_alloc
);
994 /* Push a range type. */
997 stab_range_type (void *p
, bfd_signed_vma low
, bfd_signed_vma high
)
999 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1004 definition
= info
->type_stack
->definition
;
1005 size
= info
->type_stack
->size
;
1007 s
= stab_pop_type (info
);
1008 buf
= xmalloc (strlen (s
) + 45);
1009 sprintf (buf
, "r%s;%ld;%ld;", s
, (long) low
, (long) high
);
1012 return stab_push_string (info
, buf
, 0, definition
, size
);
1015 /* Push an array type. */
1018 stab_array_type (void *p
, bfd_signed_vma low
, bfd_signed_vma high
,
1021 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1023 unsigned int element_size
;
1024 char *range
, *element
, *buf
;
1028 definition
= info
->type_stack
->definition
;
1029 range
= stab_pop_type (info
);
1031 definition
= definition
|| info
->type_stack
->definition
;
1032 element_size
= info
->type_stack
->size
;
1033 element
= stab_pop_type (info
);
1035 buf
= xmalloc (strlen (range
) + strlen (element
) + 70);
1041 /* We need to define a type in order to include the string
1043 tindex
= info
->type_index
;
1046 out
+= sprintf (out
, "%ld=@S;", tindex
);
1049 sprintf (out
, "ar%s;%ld;%ld;%s",
1050 range
, (long) low
, (long) high
, element
);
1057 size
= element_size
* ((high
- low
) + 1);
1058 return stab_push_string (info
, buf
, tindex
, definition
, size
);
1061 /* Push a set type. */
1064 stab_set_type (void *p
, bool bitstringp
)
1066 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1071 definition
= info
->type_stack
->definition
;
1073 s
= stab_pop_type (info
);
1074 buf
= xmalloc (strlen (s
) + 26);
1080 /* We need to define a type in order to include the string
1082 tindex
= info
->type_index
;
1085 out
+= sprintf (out
, "%ld=@S;", tindex
);
1088 sprintf (out
, "S%s", s
);
1091 return stab_push_string (info
, buf
, tindex
, definition
, 0);
1094 /* Push an offset type. */
1097 stab_offset_type (void *p
)
1099 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1101 char *target
, *base
, *buf
;
1103 definition
= info
->type_stack
->definition
;
1104 target
= stab_pop_type (info
);
1106 definition
= definition
|| info
->type_stack
->definition
;
1107 base
= stab_pop_type (info
);
1109 buf
= xmalloc (strlen (target
) + strlen (base
) + 3);
1110 sprintf (buf
, "@%s,%s", base
, target
);
1114 return stab_push_string (info
, buf
, 0, definition
, 0);
1117 /* Push a method type. */
1120 stab_method_type (void *p
, bool domainp
, int argcount
,
1123 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1125 char *domain
, *return_type
, *buf
;
1130 /* We don't bother with stub method types, because that would
1131 require a mangler for C++ argument types. This will waste space
1132 in the debugging output. */
1134 /* We need a domain. I'm not sure DOMAINP can ever be false,
1138 if (! stab_empty_type (p
))
1142 definition
= info
->type_stack
->definition
;
1143 domain
= stab_pop_type (info
);
1145 /* A non-varargs function is indicated by making the last parameter
1153 else if (argcount
== 0)
1159 args
= xmalloc (1 * sizeof (*args
));
1160 if (! stab_empty_type (p
))
1165 definition
= definition
|| info
->type_stack
->definition
;
1166 args
[0] = stab_pop_type (info
);
1172 args
= xmalloc ((argcount
+ 1) * sizeof (*args
));
1173 for (i
= argcount
- 1; i
>= 0; i
--)
1175 definition
= definition
|| info
->type_stack
->definition
;
1176 args
[i
] = stab_pop_type (info
);
1180 if (! stab_empty_type (p
))
1182 for (i
= 0; i
< argcount
; i
++)
1187 definition
= definition
|| info
->type_stack
->definition
;
1188 args
[argcount
] = stab_pop_type (info
);
1193 definition
= definition
|| info
->type_stack
->definition
;
1194 return_type
= stab_pop_type (info
);
1196 len
= strlen (domain
) + strlen (return_type
) + 4 + argcount
;
1197 for (i
= 0; i
< argcount
; i
++)
1198 len
+= strlen (args
[i
]);
1200 buf
= xmalloc (len
);
1203 out
= stpcpy (out
, domain
);
1205 out
= stpcpy (out
, return_type
);
1208 for (i
= 0; i
< argcount
; i
++)
1211 out
= stpcpy (out
, args
[i
]);
1219 return stab_push_string (info
, buf
, 0, definition
, 0);
1222 /* Push a const version of a type. */
1225 stab_const_type (void *p
)
1227 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1229 return stab_modify_type (info
, 'k', info
->type_stack
->size
,
1230 (long **) NULL
, (size_t *) NULL
);
1233 /* Push a volatile version of a type. */
1236 stab_volatile_type (void *p
)
1238 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1240 return stab_modify_type (info
, 'B', info
->type_stack
->size
,
1241 (long **) NULL
, (size_t *) NULL
);
1244 /* Get the type index to use for a struct/union/class ID. This should
1245 return -1 if it fails. */
1248 stab_get_struct_index (struct stab_write_handle
*info
, const char *tag
,
1249 unsigned int id
, enum debug_type_kind kind
,
1250 unsigned int *psize
)
1252 if (id
>= info
->type_cache
.struct_types_alloc
)
1256 alloc
= info
->type_cache
.struct_types_alloc
;
1261 info
->type_cache
.struct_types
=
1262 xrealloc (info
->type_cache
.struct_types
,
1263 alloc
* sizeof (*info
->type_cache
.struct_types
));
1264 memset ((info
->type_cache
.struct_types
1265 + info
->type_cache
.struct_types_alloc
),
1267 ((alloc
- info
->type_cache
.struct_types_alloc
)
1268 * sizeof (*info
->type_cache
.struct_types
)));
1269 info
->type_cache
.struct_types_alloc
= alloc
;
1272 if (info
->type_cache
.struct_types
[id
].index
== 0)
1274 info
->type_cache
.struct_types
[id
].index
= info
->type_index
;
1276 info
->type_cache
.struct_types
[id
].tag
= tag
;
1277 info
->type_cache
.struct_types
[id
].kind
= kind
;
1280 if (kind
== DEBUG_KIND_ILLEGAL
)
1282 /* This is a definition of the struct. */
1283 info
->type_cache
.struct_types
[id
].kind
= kind
;
1284 info
->type_cache
.struct_types
[id
].size
= *psize
;
1287 *psize
= info
->type_cache
.struct_types
[id
].size
;
1289 return info
->type_cache
.struct_types
[id
].index
;
1292 /* Start outputting a struct. We ignore the tag, and handle it in
1296 stab_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1297 bool structp
, unsigned int size
)
1299 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1312 tindex
= stab_get_struct_index (info
, tag
, id
, DEBUG_KIND_ILLEGAL
,
1316 out
+= sprintf (out
, "%ld=", tindex
);
1320 sprintf (out
, "%c%u",
1321 structp
? 's' : 'u',
1324 if (!stab_push_string_dup (info
, buf
, tindex
, definition
, size
))
1327 info
->type_stack
->fields
= xmalloc (1);
1328 info
->type_stack
->fields
[0] = '\0';
1333 /* Add a field to a struct. */
1336 stab_struct_field (void *p
, const char *name
, bfd_vma bitpos
,
1337 bfd_vma bitsize
, enum debug_visibility visibility
)
1339 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1345 definition
= info
->type_stack
->definition
;
1346 size
= info
->type_stack
->size
;
1347 s
= stab_pop_type (info
);
1349 /* Add this field to the end of the current struct fields, which is
1350 currently on the top of the stack. */
1351 if (info
->type_stack
->fields
== NULL
)
1357 n
= xmalloc (strlen (info
->type_stack
->fields
)
1358 + strlen (name
) + strlen (s
) + 50);
1365 case DEBUG_VISIBILITY_PUBLIC
:
1369 case DEBUG_VISIBILITY_PRIVATE
:
1373 case DEBUG_VISIBILITY_PROTECTED
:
1382 non_fatal (_("%s: warning: unknown size for field `%s' in struct"),
1383 bfd_get_filename (info
->abfd
), name
);
1386 sprintf (n
, "%s%s:%s%s,%ld,%ld;", info
->type_stack
->fields
, name
, vis
, s
,
1387 (long) bitpos
, (long) bitsize
);
1389 free (info
->type_stack
->fields
);
1391 info
->type_stack
->fields
= n
;
1394 info
->type_stack
->definition
= true;
1399 /* Finish up a struct. */
1402 stab_end_struct_type (void *p
)
1404 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1408 char *fields
, *first
, *buf
;
1410 if (info
->type_stack
== NULL
|| info
->type_stack
->fields
== NULL
)
1413 definition
= info
->type_stack
->definition
;
1414 tindex
= info
->type_stack
->index
;
1415 size
= info
->type_stack
->size
;
1416 fields
= info
->type_stack
->fields
;
1417 first
= stab_pop_type (info
);
1419 buf
= xmalloc (strlen (first
) + strlen (fields
) + 2);
1420 sprintf (buf
, "%s%s;", first
, fields
);
1424 return stab_push_string (info
, buf
, tindex
, definition
, size
);
1427 /* Start outputting a class. */
1430 stab_start_class_type (void *p
, const char *tag
, unsigned int id
,
1431 bool structp
, unsigned int size
,
1432 bool vptr
, bool ownvptr
)
1434 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1435 bool definition
= false;
1436 char *vstring
= NULL
;
1438 if (vptr
&& !ownvptr
)
1440 definition
= info
->type_stack
->definition
;
1441 vstring
= stab_pop_type (info
);
1444 if (! stab_start_struct_type (p
, tag
, id
, structp
, size
))
1456 if (info
->type_stack
->index
< 1)
1458 vtable
= xmalloc (23);
1459 sprintf (vtable
, "~%%%ld", info
->type_stack
->index
);
1463 if (vstring
== NULL
)
1465 vtable
= xmalloc (strlen (vstring
) + 3);
1466 sprintf (vtable
, "~%%%s", vstring
);
1469 info
->type_stack
->definition
= true;
1471 info
->type_stack
->vtable
= vtable
;
1477 /* Add a static member to the class on the type stack. */
1480 stab_class_static_member (void *p
, const char *name
, const char *physname
,
1481 enum debug_visibility visibility
)
1483 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1488 definition
= info
->type_stack
->definition
;
1489 s
= stab_pop_type (info
);
1491 /* Add this field to the end of the current struct fields, which is
1492 currently on the top of the stack. */
1494 if (info
->type_stack
->fields
== NULL
)
1496 n
= xmalloc (strlen (info
->type_stack
->fields
) + strlen (name
)
1497 + strlen (s
) + strlen (physname
) + 10);
1504 case DEBUG_VISIBILITY_PUBLIC
:
1508 case DEBUG_VISIBILITY_PRIVATE
:
1512 case DEBUG_VISIBILITY_PROTECTED
:
1517 sprintf (n
, "%s%s:%s%s:%s;", info
->type_stack
->fields
, name
, vis
, s
,
1521 free (info
->type_stack
->fields
);
1522 info
->type_stack
->fields
= n
;
1525 info
->type_stack
->definition
= true;
1530 /* Add a base class to the class on the type stack. */
1533 stab_class_baseclass (void *p
, bfd_vma bitpos
, bool is_virtual
,
1534 enum debug_visibility visibility
)
1536 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1543 definition
= info
->type_stack
->definition
;
1544 s
= stab_pop_type (info
);
1546 /* Build the base class specifier. */
1548 buf
= xmalloc (strlen (s
) + 25);
1549 buf
[0] = is_virtual
? '1' : '0';
1555 case DEBUG_VISIBILITY_PRIVATE
:
1559 case DEBUG_VISIBILITY_PROTECTED
:
1563 case DEBUG_VISIBILITY_PUBLIC
:
1568 sprintf (buf
+ 2, "%ld,%s;", (long) bitpos
, s
);
1571 /* Add the new baseclass to the existing ones. */
1573 if (info
->type_stack
== NULL
|| info
->type_stack
->fields
== NULL
)
1579 if (info
->type_stack
->baseclasses
== NULL
)
1584 while (info
->type_stack
->baseclasses
[c
] != NULL
)
1588 baseclasses
= xrealloc (info
->type_stack
->baseclasses
,
1589 (c
+ 2) * sizeof (*baseclasses
));
1590 baseclasses
[c
] = buf
;
1591 baseclasses
[c
+ 1] = NULL
;
1593 info
->type_stack
->baseclasses
= baseclasses
;
1596 info
->type_stack
->definition
= true;
1601 /* Start adding a method to the class on the type stack. */
1604 stab_class_start_method (void *p
, const char *name
)
1606 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1609 if (info
->type_stack
== NULL
|| info
->type_stack
->fields
== NULL
)
1612 if (info
->type_stack
->methods
== NULL
)
1614 m
= xmalloc (strlen (name
) + 3);
1618 m
= xrealloc (info
->type_stack
->methods
,
1619 strlen (info
->type_stack
->methods
) + strlen (name
) + 3);
1621 sprintf (m
+ strlen (m
), "%s::", name
);
1623 info
->type_stack
->methods
= m
;
1628 /* Add a variant, either static or not, to the current method. */
1631 stab_class_method_var (struct stab_write_handle
*info
, const char *physname
,
1632 enum debug_visibility visibility
,
1633 bool staticp
, bool constp
,
1634 bool volatilep
, bfd_vma voffset
,
1639 char *context
= NULL
;
1640 char visc
, qualc
, typec
;
1642 definition
= info
->type_stack
->definition
;
1643 type
= stab_pop_type (info
);
1647 definition
= definition
|| info
->type_stack
->definition
;
1648 context
= stab_pop_type (info
);
1651 if (info
->type_stack
== NULL
|| info
->type_stack
->methods
== NULL
)
1663 case DEBUG_VISIBILITY_PRIVATE
:
1667 case DEBUG_VISIBILITY_PROTECTED
:
1671 case DEBUG_VISIBILITY_PUBLIC
:
1693 else if (! contextp
)
1698 size_t cur_len
= strlen (info
->type_stack
->methods
);
1699 info
->type_stack
->methods
=
1700 xrealloc (info
->type_stack
->methods
, (cur_len
1703 + (contextp
? strlen (context
) : 0)
1706 char *out
= info
->type_stack
->methods
+ cur_len
;
1707 out
+= sprintf (out
, "%s:%s;%c%c%c", type
, physname
, visc
, qualc
, typec
);
1712 sprintf (out
, "%ld;%s;", (long) voffset
, context
);
1717 info
->type_stack
->definition
= true;
1722 /* Add a variant to the current method. */
1725 stab_class_method_variant (void *p
, const char *physname
,
1726 enum debug_visibility visibility
,
1727 bool constp
, bool volatilep
,
1728 bfd_vma voffset
, bool contextp
)
1730 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1732 return stab_class_method_var (info
, physname
, visibility
, false, constp
,
1733 volatilep
, voffset
, contextp
);
1736 /* Add a static variant to the current method. */
1739 stab_class_static_method_variant (void *p
, const char *physname
,
1740 enum debug_visibility visibility
,
1741 bool constp
, bool volatilep
)
1743 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1745 return stab_class_method_var (info
, physname
, visibility
, true, constp
,
1746 volatilep
, 0, false);
1749 /* Finish up a method. */
1752 stab_class_end_method (void *p
)
1754 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1756 if (info
->type_stack
== NULL
|| info
->type_stack
->methods
== NULL
)
1759 /* We allocated enough room on info->type_stack->methods to add the
1760 trailing semicolon. */
1761 strcat (info
->type_stack
->methods
, ";");
1766 /* Finish up a class. */
1769 stab_end_class_type (void *p
)
1771 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1776 if (info
->type_stack
== NULL
1777 || info
->type_stack
->string
== NULL
1778 || info
->type_stack
->fields
== NULL
)
1781 /* Work out the size we need to allocate for the class definition. */
1783 len
= (strlen (info
->type_stack
->string
)
1784 + strlen (info
->type_stack
->fields
)
1786 if (info
->type_stack
->baseclasses
!= NULL
)
1789 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1790 len
+= strlen (info
->type_stack
->baseclasses
[i
]);
1792 if (info
->type_stack
->methods
!= NULL
)
1793 len
+= strlen (info
->type_stack
->methods
);
1794 if (info
->type_stack
->vtable
!= NULL
)
1795 len
+= strlen (info
->type_stack
->vtable
);
1797 /* Build the class definition. */
1799 buf
= xmalloc (len
);
1801 char *out
= stpcpy (buf
, info
->type_stack
->string
);
1803 if (info
->type_stack
->baseclasses
!= NULL
)
1805 out
+= sprintf (out
, "!%u,", i
);
1806 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1808 out
= stpcpy (out
, info
->type_stack
->baseclasses
[i
]);
1809 free (info
->type_stack
->baseclasses
[i
]);
1811 free (info
->type_stack
->baseclasses
);
1812 info
->type_stack
->baseclasses
= NULL
;
1815 out
= stpcpy (out
, info
->type_stack
->fields
);
1816 free (info
->type_stack
->fields
);
1817 info
->type_stack
->fields
= NULL
;
1819 if (info
->type_stack
->methods
!= NULL
)
1821 out
= stpcpy (out
, info
->type_stack
->methods
);
1822 free (info
->type_stack
->methods
);
1823 info
->type_stack
->methods
= NULL
;
1826 out
= stpcpy (out
, ";");
1828 if (info
->type_stack
->vtable
!= NULL
)
1830 out
= stpcpy (out
, info
->type_stack
->vtable
);
1831 free (info
->type_stack
->vtable
);
1832 info
->type_stack
->vtable
= NULL
;
1835 /* Replace the string on the top of the stack with the complete
1836 class definition. */
1837 free (info
->type_stack
->string
);
1838 info
->type_stack
->string
= buf
;
1843 /* Push a typedef which was previously defined. */
1846 stab_typedef_type (void *p
, const char *name
)
1848 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1849 struct string_hash_entry
*h
;
1851 h
= string_hash_lookup (&info
->typedef_hash
, name
, false, false);
1852 if (h
== NULL
|| h
->index
< 1)
1855 return stab_push_defined_type (info
, h
->index
, h
->size
);
1858 /* Push a struct, union or class tag. */
1861 stab_tag_type (void *p
, const char *name
, unsigned int id
,
1862 enum debug_type_kind kind
)
1864 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1866 unsigned int size
= 0;
1868 tindex
= stab_get_struct_index (info
, name
, id
, kind
, &size
);
1872 return stab_push_defined_type (info
, tindex
, size
);
1875 /* Define a typedef. */
1878 stab_typdef (void *p
, const char *name
)
1880 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1884 struct string_hash_entry
*h
;
1886 tindex
= info
->type_stack
->index
;
1887 size
= info
->type_stack
->size
;
1888 s
= stab_pop_type (info
);
1890 buf
= xmalloc (strlen (name
) + strlen (s
) + 20);
1893 sprintf (buf
, "%s:t%s", name
, s
);
1896 tindex
= info
->type_index
;
1898 sprintf (buf
, "%s:t%ld=%s", name
, tindex
, s
);
1903 if (!stab_write_symbol_and_free (info
, N_LSYM
, 0, 0, buf
))
1906 h
= string_hash_lookup (&info
->typedef_hash
, name
, true, false);
1909 non_fatal (_("string_hash_lookup failed: %s"),
1910 bfd_errmsg (bfd_get_error ()));
1914 /* I don't think we care about redefinitions. */
1925 stab_tag (void *p
, const char *tag
)
1927 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1930 s
= stab_pop_type (info
);
1932 buf
= xmalloc (strlen (tag
) + strlen (s
) + 3);
1934 sprintf (buf
, "%s:T%s", tag
, s
);
1937 return stab_write_symbol_and_free (info
, N_LSYM
, 0, 0, buf
);
1940 /* Define an integer constant. */
1943 stab_int_constant (void *p
, const char *name
, bfd_vma val
)
1945 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1948 buf
= xmalloc (strlen (name
) + 20);
1949 sprintf (buf
, "%s:c=i%ld", name
, (long) val
);
1951 return stab_write_symbol_and_free (info
, N_LSYM
, 0, 0, buf
);
1954 /* Define a floating point constant. */
1957 stab_float_constant (void *p
, const char *name
, double val
)
1959 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1962 buf
= xmalloc (strlen (name
) + 20);
1963 sprintf (buf
, "%s:c=f%g", name
, val
);
1965 return stab_write_symbol_and_free (info
, N_LSYM
, 0, 0, buf
);
1968 /* Define a typed constant. */
1971 stab_typed_constant (void *p
, const char *name
, bfd_vma val
)
1973 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1976 s
= stab_pop_type (info
);
1978 buf
= xmalloc (strlen (name
) + strlen (s
) + 20);
1979 sprintf (buf
, "%s:c=e%s,%ld", name
, s
, (long) val
);
1982 return stab_write_symbol_and_free (info
, N_LSYM
, 0, 0, buf
);
1985 /* Record a variable. */
1988 stab_variable (void *p
, const char *name
, enum debug_var_kind kind
,
1991 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1994 const char *kindstr
;
1996 s
= stab_pop_type (info
);
2009 stab_type
= N_STSYM
;
2013 case DEBUG_LOCAL_STATIC
:
2014 stab_type
= N_STSYM
;
2022 /* Make sure that this is a type reference or definition. */
2028 tindex
= info
->type_index
;
2030 n
= xmalloc (strlen (s
) + 20);
2031 sprintf (n
, "%ld=%s", tindex
, s
);
2037 case DEBUG_REGISTER
:
2043 buf
= xmalloc (strlen (name
) + strlen (s
) + 3);
2044 sprintf (buf
, "%s:%s%s", name
, kindstr
, s
);
2047 return stab_write_symbol_and_free (info
, stab_type
, 0, val
, buf
);
2050 /* Start outputting a function. */
2053 stab_start_function (void *p
, const char *name
, bool globalp
)
2055 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2056 char *rettype
, *buf
;
2058 if (info
->nesting
!= 0 || info
->fun_offset
!= -1)
2061 rettype
= stab_pop_type (info
);
2063 buf
= xmalloc (strlen (name
) + strlen (rettype
) + 3);
2064 sprintf (buf
, "%s:%c%s", name
,
2065 globalp
? 'F' : 'f',
2069 /* We don't know the value now, so we set it in start_block. */
2070 info
->fun_offset
= info
->symbols_size
;
2072 return stab_write_symbol_and_free (info
, N_FUN
, 0, 0, buf
);
2075 /* Output a function parameter. */
2078 stab_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
, bfd_vma val
)
2080 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2085 s
= stab_pop_type (info
);
2092 case DEBUG_PARM_STACK
:
2097 case DEBUG_PARM_REG
:
2102 case DEBUG_PARM_REFERENCE
:
2107 case DEBUG_PARM_REF_REG
:
2113 buf
= xmalloc (strlen (name
) + strlen (s
) + 3);
2114 sprintf (buf
, "%s:%c%s", name
, kindc
, s
);
2117 return stab_write_symbol_and_free (info
, stab_type
, 0, val
, buf
);
2120 /* Start a block. */
2123 stab_start_block (void *p
, bfd_vma addr
)
2125 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2127 /* Fill in any slots which have been waiting for the first known
2130 if (info
->so_offset
!= -1)
2132 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->so_offset
+ 8);
2133 info
->so_offset
= -1;
2136 if (info
->fun_offset
!= -1)
2138 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->fun_offset
+ 8);
2139 info
->fun_offset
= -1;
2144 /* We will be called with a top level block surrounding the
2145 function, but stabs information does not output that block, so we
2148 if (info
->nesting
== 1)
2150 info
->fnaddr
= addr
;
2154 /* We have to output the LBRAC symbol after any variables which are
2155 declared inside the block. We postpone the LBRAC until the next
2156 start_block or end_block. */
2158 /* If we have postponed an LBRAC, output it now. */
2159 if (info
->pending_lbrac
!= (bfd_vma
) -1)
2161 if (! stab_write_symbol (info
, N_LBRAC
, 0, info
->pending_lbrac
,
2162 (const char *) NULL
))
2166 /* Remember the address and output it later. */
2168 info
->pending_lbrac
= addr
- info
->fnaddr
;
2176 stab_end_block (void *p
, bfd_vma addr
)
2178 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2180 if (addr
> info
->last_text_address
)
2181 info
->last_text_address
= addr
;
2183 /* If we have postponed an LBRAC, output it now. */
2184 if (info
->pending_lbrac
!= (bfd_vma
) -1)
2186 if (! stab_write_symbol (info
, N_LBRAC
, 0, info
->pending_lbrac
,
2187 (const char *) NULL
))
2189 info
->pending_lbrac
= (bfd_vma
) -1;
2192 if (info
->nesting
< 1)
2197 /* We ignore the outermost block. */
2198 if (info
->nesting
== 0)
2201 return stab_write_symbol (info
, N_RBRAC
, 0, addr
- info
->fnaddr
,
2202 (const char *) NULL
);
2205 /* End a function. */
2208 stab_end_function (void *p ATTRIBUTE_UNUSED
)
2213 /* Output a line number. */
2216 stab_lineno (void *p
, const char *file
, unsigned long lineno
, bfd_vma addr
)
2218 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2220 if (info
->lineno_filename
== NULL
)
2223 if (addr
> info
->last_text_address
)
2224 info
->last_text_address
= addr
;
2226 if (filename_cmp (file
, info
->lineno_filename
) != 0)
2228 if (! stab_write_symbol (info
, N_SOL
, 0, addr
, file
))
2230 info
->lineno_filename
= file
;
2233 return stab_write_symbol (info
, N_SLINE
, lineno
, addr
- info
->fnaddr
,
2234 (const char *) NULL
);