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 struct bfd_hash_entry
*string_hash_newfunc
175 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
176 static bool stab_write_symbol
177 (struct stab_write_handle
*, int, int, bfd_vma
, const char *);
178 static bool stab_push_string
179 (struct stab_write_handle
*, const char *, long, bool, unsigned int);
180 static bool stab_push_defined_type
181 (struct stab_write_handle
*, long, unsigned int);
182 static char *stab_pop_type (struct stab_write_handle
*);
183 static bool stab_modify_type
184 (struct stab_write_handle
*, int, unsigned int, long **, size_t *);
185 static long stab_get_struct_index
186 (struct stab_write_handle
*, const char *, unsigned int,
187 enum debug_type_kind
, unsigned int *);
188 static bool stab_class_method_var
189 (struct stab_write_handle
*, const char *, enum debug_visibility
,
190 bool, bool, bool, bfd_vma
, bool);
191 static bool stab_start_compilation_unit (void *, const char *);
192 static bool stab_start_source (void *, const char *);
193 static bool stab_empty_type (void *);
194 static bool stab_void_type (void *);
195 static bool stab_int_type (void *, unsigned int, bool);
196 static bool stab_float_type (void *, unsigned int);
197 static bool stab_complex_type (void *, unsigned int);
198 static bool stab_bool_type (void *, unsigned int);
199 static bool stab_enum_type
200 (void *, const char *, const char **, bfd_signed_vma
*);
201 static bool stab_pointer_type (void *);
202 static bool stab_function_type (void *, int, bool);
203 static bool stab_reference_type (void *);
204 static bool stab_range_type (void *, bfd_signed_vma
, bfd_signed_vma
);
205 static bool stab_array_type
206 (void *, bfd_signed_vma
, bfd_signed_vma
, bool);
207 static bool stab_set_type (void *, bool);
208 static bool stab_offset_type (void *);
209 static bool stab_method_type (void *, bool, int, bool);
210 static bool stab_const_type (void *);
211 static bool stab_volatile_type (void *);
212 static bool stab_start_struct_type
213 (void *, const char *, unsigned int, bool, unsigned int);
214 static bool stab_struct_field
215 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
216 static bool stab_end_struct_type (void *);
217 static bool stab_start_class_type
218 (void *, const char *, unsigned int, bool, unsigned int,
220 static bool stab_class_static_member
221 (void *, const char *, const char *, enum debug_visibility
);
222 static bool stab_class_baseclass
223 (void *, bfd_vma
, bool, enum debug_visibility
);
224 static bool stab_class_start_method (void *, const char *);
225 static bool stab_class_method_variant
226 (void *, const char *, enum debug_visibility
, bool, bool,
228 static bool stab_class_static_method_variant
229 (void *, const char *, enum debug_visibility
, bool, bool);
230 static bool stab_class_end_method (void *);
231 static bool stab_end_class_type (void *);
232 static bool stab_typedef_type (void *, const char *);
233 static bool stab_tag_type
234 (void *, const char *, unsigned int, enum debug_type_kind
);
235 static bool stab_typdef (void *, const char *);
236 static bool stab_tag (void *, const char *);
237 static bool stab_int_constant (void *, const char *, bfd_vma
);
238 static bool stab_float_constant (void *, const char *, double);
239 static bool stab_typed_constant (void *, const char *, bfd_vma
);
240 static bool stab_variable
241 (void *, const char *, enum debug_var_kind
, bfd_vma
);
242 static bool stab_start_function (void *, const char *, bool);
243 static bool stab_function_parameter
244 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
245 static bool stab_start_block (void *, bfd_vma
);
246 static bool stab_end_block (void *, bfd_vma
);
247 static bool stab_end_function (void *);
248 static bool stab_lineno (void *, const char *, unsigned long, bfd_vma
);
250 static const struct debug_write_fns stab_fns
=
252 stab_start_compilation_unit
,
271 stab_start_struct_type
,
273 stab_end_struct_type
,
274 stab_start_class_type
,
275 stab_class_static_member
,
276 stab_class_baseclass
,
277 stab_class_start_method
,
278 stab_class_method_variant
,
279 stab_class_static_method_variant
,
280 stab_class_end_method
,
291 stab_function_parameter
,
298 /* Routine to create an entry in a string hash table. */
300 static struct bfd_hash_entry
*
301 string_hash_newfunc (struct bfd_hash_entry
*entry
,
302 struct bfd_hash_table
*table
, const char *string
)
304 struct string_hash_entry
*ret
= (struct string_hash_entry
*) entry
;
306 /* Allocate the structure if it has not already been allocated by a
308 if (ret
== (struct string_hash_entry
*) NULL
)
309 ret
= ((struct string_hash_entry
*)
310 bfd_hash_allocate (table
, sizeof (struct string_hash_entry
)));
311 if (ret
== (struct string_hash_entry
*) NULL
)
314 /* Call the allocation method of the superclass. */
315 ret
= ((struct string_hash_entry
*)
316 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
320 /* Initialize the local fields. */
326 return (struct bfd_hash_entry
*) ret
;
329 /* Look up an entry in a string hash table. */
331 #define string_hash_lookup(t, string, create, copy) \
332 ((struct string_hash_entry *) \
333 bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
335 /* Add a symbol to the stabs debugging information we are building. */
338 stab_write_symbol (struct stab_write_handle
*info
, int type
, int desc
,
339 bfd_vma value
, const char *string
)
342 bfd_byte sym
[STAB_SYMBOL_SIZE
];
348 struct string_hash_entry
*h
;
350 h
= string_hash_lookup (&info
->strhash
, string
, true, true);
353 non_fatal (_("string_hash_lookup failed: %s"),
354 bfd_errmsg (bfd_get_error ()));
361 strx
= info
->strings_size
;
363 if (info
->last_string
== NULL
)
366 info
->last_string
->next
= h
;
367 info
->last_string
= h
;
368 info
->strings_size
+= strlen (string
) + 1;
372 /* This presumes 32 bit values. */
373 bfd_put_32 (info
->abfd
, strx
, sym
);
374 bfd_put_8 (info
->abfd
, type
, sym
+ 4);
375 bfd_put_8 (info
->abfd
, 0, sym
+ 5);
376 bfd_put_16 (info
->abfd
, desc
, sym
+ 6);
377 bfd_put_32 (info
->abfd
, value
, sym
+ 8);
379 if (info
->symbols_size
+ STAB_SYMBOL_SIZE
> info
->symbols_alloc
)
381 info
->symbols_alloc
*= 2;
382 info
->symbols
= (bfd_byte
*) xrealloc (info
->symbols
,
383 info
->symbols_alloc
);
386 memcpy (info
->symbols
+ info
->symbols_size
, sym
, STAB_SYMBOL_SIZE
);
388 info
->symbols_size
+= STAB_SYMBOL_SIZE
;
393 /* Push a string on to the type stack. */
396 stab_push_string (struct stab_write_handle
*info
, const char *string
,
397 long tindex
, bool definition
, unsigned int size
)
399 struct stab_type_stack
*s
;
401 s
= (struct stab_type_stack
*) xmalloc (sizeof *s
);
402 s
->string
= xstrdup (string
);
404 s
->definition
= definition
;
408 s
->baseclasses
= NULL
;
412 s
->next
= info
->type_stack
;
413 info
->type_stack
= s
;
418 /* Push a type index which has already been defined. */
421 stab_push_defined_type (struct stab_write_handle
*info
, long tindex
,
426 sprintf (buf
, "%ld", tindex
);
427 return stab_push_string (info
, buf
, tindex
, false, size
);
430 /* Pop a type off the type stack. The caller is responsible for
431 freeing the string. */
434 stab_pop_type (struct stab_write_handle
*info
)
436 struct stab_type_stack
*s
;
439 s
= info
->type_stack
;
443 info
->type_stack
= s
->next
;
452 /* The general routine to write out stabs in sections debugging
453 information. This accumulates the stabs symbols and the strings in
454 two obstacks. We can't easily write out the information as we go
455 along, because we need to know the section sizes before we can
456 write out the section contents. ABFD is the BFD and DHANDLE is the
457 handle for the debugging information. This sets *PSYMS to point to
458 the symbols, *PSYMSIZE the size of the symbols, *PSTRINGS to the
459 strings, and *PSTRINGSIZE to the size of the strings. */
462 write_stabs_in_sections_debugging_info (bfd
*abfd
, void *dhandle
,
464 bfd_size_type
*psymsize
,
466 bfd_size_type
*pstringsize
)
468 struct stab_write_handle info
;
469 struct string_hash_entry
*h
;
472 memset (&info
, 0, sizeof info
);
475 info
.symbols_alloc
= 500;
476 info
.symbols
= (bfd_byte
*) xmalloc (info
.symbols_alloc
);
478 /* Reserve 1 byte for a null byte. */
479 info
.strings_size
= 1;
482 info
.fun_offset
= -1;
483 info
.pending_lbrac
= (bfd_vma
) -1;
485 if (!bfd_hash_table_init (&info
.strhash
.table
, string_hash_newfunc
,
486 sizeof (struct string_hash_entry
))
487 || !bfd_hash_table_init (&info
.typedef_hash
.table
, string_hash_newfunc
,
488 sizeof (struct string_hash_entry
)))
490 non_fatal ("bfd_hash_table_init_failed: %s",
491 bfd_errmsg (bfd_get_error ()));
495 /* The initial symbol holds the string size. */
496 if (! stab_write_symbol (&info
, 0, 0, 0, (const char *) NULL
))
499 /* Output an initial N_SO symbol. */
500 info
.so_offset
= info
.symbols_size
;
501 if (! stab_write_symbol (&info
, N_SO
, 0, 0, bfd_get_filename (abfd
)))
504 if (! debug_write (dhandle
, &stab_fns
, (void *) &info
))
507 if (info
.pending_lbrac
!= (bfd_vma
) -1)
510 /* Output a trailing N_SO. */
511 if (! stab_write_symbol (&info
, N_SO
, 0, info
.last_text_address
,
512 (const char *) NULL
))
515 /* Put the string size in the initial symbol. */
516 bfd_put_32 (abfd
, info
.strings_size
, info
.symbols
+ 8);
518 *psyms
= info
.symbols
;
519 *psymsize
= info
.symbols_size
;
521 *pstringsize
= info
.strings_size
;
522 *pstrings
= (bfd_byte
*) xmalloc (info
.strings_size
);
526 for (h
= info
.strings
; h
!= NULL
; h
= h
->next
)
528 strcpy ((char *) p
, h
->root
.string
);
529 p
+= strlen ((char *) p
) + 1;
532 bfd_hash_table_free (&info
.typedef_hash
.table
);
533 bfd_hash_table_free (&info
.strhash
.table
);
537 if (info
.typedef_hash
.table
.memory
)
538 bfd_hash_table_free (&info
.typedef_hash
.table
);
539 if (info
.strhash
.table
.memory
)
540 bfd_hash_table_free (&info
.strhash
.table
);
545 /* Start writing out information for a compilation unit. */
548 stab_start_compilation_unit (void *p
, const char *filename
)
550 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
552 /* We would normally output an N_SO symbol here. However, that
553 would force us to reset all of our type information. I think we
554 will be better off just outputting an N_SOL symbol, and not
555 worrying about splitting information between files. */
557 info
->lineno_filename
= filename
;
559 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
562 /* Start writing out information for a particular source file. */
565 stab_start_source (void *p
, const char *filename
)
567 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
569 /* FIXME: The symbol's value is supposed to be the text section
570 address. However, we would have to fill it in later, and gdb
571 doesn't care, so we don't bother with it. */
573 info
->lineno_filename
= filename
;
575 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
578 /* Push an empty type. This shouldn't normally happen. We just use a
582 stab_empty_type (void *p
)
584 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
586 /* We don't call stab_void_type if the type is not yet defined,
587 because that might screw up the typedef. */
589 if (info
->type_cache
.void_type
!= 0)
590 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
596 tindex
= info
->type_index
;
599 sprintf (buf
, "%ld=%ld", tindex
, tindex
);
601 return stab_push_string (info
, buf
, tindex
, false, 0);
605 /* Push a void type. */
608 stab_void_type (void *p
)
610 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
612 if (info
->type_cache
.void_type
!= 0)
613 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
619 tindex
= info
->type_index
;
622 info
->type_cache
.void_type
= tindex
;
624 sprintf (buf
, "%ld=%ld", tindex
, tindex
);
626 return stab_push_string (info
, buf
, tindex
, true, 0);
630 /* Push an integer type. */
633 stab_int_type (void *p
, unsigned int size
, bool unsignedp
)
635 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
638 if (size
<= 0 || (size
> sizeof (long) && size
!= 8))
640 non_fatal (_("stab_int_type: bad size %u"), size
);
645 cache
= info
->type_cache
.signed_integer_types
;
647 cache
= info
->type_cache
.unsigned_integer_types
;
649 if (cache
[size
- 1] != 0)
650 return stab_push_defined_type (info
, cache
[size
- 1], size
);
656 tindex
= info
->type_index
;
659 cache
[size
- 1] = tindex
;
661 sprintf (buf
, "%ld=r%ld;", tindex
, tindex
);
665 if (size
< sizeof (long))
666 sprintf (buf
+ strlen (buf
), "%ld;", ((long) 1 << (size
* 8)) - 1);
667 else if (size
== sizeof (long))
670 strcat (buf
, "01777777777777777777777;");
676 if (size
<= sizeof (long))
677 sprintf (buf
+ strlen (buf
), "%ld;%ld;",
678 (long) - ((unsigned long) 1 << (size
* 8 - 1)),
679 (long) (((unsigned long) 1 << (size
* 8 - 1)) - 1));
681 strcat (buf
, "01000000000000000000000;0777777777777777777777;");
686 return stab_push_string (info
, buf
, tindex
, true, size
);
690 /* Push a floating point type. */
693 stab_float_type (void *p
, unsigned int size
)
695 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
698 && size
- 1 < (sizeof info
->type_cache
.float_types
699 / sizeof info
->type_cache
.float_types
[0])
700 && info
->type_cache
.float_types
[size
- 1] != 0)
701 return stab_push_defined_type (info
,
702 info
->type_cache
.float_types
[size
- 1],
710 /* Floats are defined as a subrange of int. */
711 if (! stab_int_type (info
, 4, false))
713 int_type
= stab_pop_type (info
);
715 tindex
= info
->type_index
;
719 && size
- 1 < (sizeof info
->type_cache
.float_types
720 / sizeof info
->type_cache
.float_types
[0]))
721 info
->type_cache
.float_types
[size
- 1] = tindex
;
723 sprintf (buf
, "%ld=r%s;%u;0;", tindex
, int_type
, size
);
727 return stab_push_string (info
, buf
, tindex
, true, size
);
731 /* Push a complex type. */
734 stab_complex_type (void *p
, unsigned int size
)
736 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
740 tindex
= info
->type_index
;
743 sprintf (buf
, "%ld=r%ld;%u;0;", tindex
, tindex
, size
);
745 return stab_push_string (info
, buf
, tindex
, true, size
* 2);
748 /* Push a bool type. We use an XCOFF predefined type, since gdb
749 always recognizes them. */
752 stab_bool_type (void *p
, unsigned int size
)
754 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
777 return stab_push_defined_type (info
, tindex
, size
);
780 /* Push an enum type. */
783 stab_enum_type (void *p
, const char *tag
, const char **names
,
784 bfd_signed_vma
*vals
)
786 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
798 buf
= (char *) xmalloc (10 + strlen (tag
));
799 sprintf (buf
, "xe%s:", tag
);
800 /* FIXME: The size is just a guess. */
801 if (! stab_push_string (info
, buf
, 0, false, 4))
810 for (pn
= names
; *pn
!= NULL
; pn
++)
811 len
+= strlen (*pn
) + 20;
813 buf
= (char *) xmalloc (len
);
819 tindex
= info
->type_index
;
821 sprintf (buf
, "%s:T%ld=e", tag
, tindex
);
824 for (pn
= names
, pv
= vals
; *pn
!= NULL
; pn
++, pv
++)
825 sprintf (buf
+ strlen (buf
), "%s:%ld,", *pn
, (long) *pv
);
830 /* FIXME: The size is just a guess. */
831 if (! stab_push_string (info
, buf
, 0, false, 4))
836 /* FIXME: The size is just a guess. */
837 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
)
838 || ! stab_push_defined_type (info
, tindex
, 4))
847 /* Push a modification of the top type on the stack. Cache the
848 results in CACHE and CACHE_ALLOC. */
851 stab_modify_type (struct stab_write_handle
*info
, int mod
,
852 unsigned int size
, long **cache
, size_t *cache_alloc
)
858 if (info
->type_stack
== NULL
)
860 targindex
= info
->type_stack
->index
;
867 /* Either the target type has no index, or we aren't caching
868 this modifier. Either way we have no way of recording the
869 new type, so we don't bother to define one. */
870 definition
= info
->type_stack
->definition
;
871 s
= stab_pop_type (info
);
872 buf
= (char *) xmalloc (strlen (s
) + 2);
873 sprintf (buf
, "%c%s", mod
, s
);
875 if (! stab_push_string (info
, buf
, 0, definition
, size
))
881 if ((size_t) targindex
>= *cache_alloc
)
885 alloc
= *cache_alloc
;
888 while ((size_t) targindex
>= alloc
)
890 *cache
= (long *) xrealloc (*cache
, alloc
* sizeof (long));
891 memset (*cache
+ *cache_alloc
, 0,
892 (alloc
- *cache_alloc
) * sizeof (long));
893 *cache_alloc
= alloc
;
896 tindex
= (*cache
)[targindex
];
897 if (tindex
!= 0 && ! info
->type_stack
->definition
)
899 /* We have already defined a modification of this type, and
900 the entry on the type stack is not a definition, so we
901 can safely discard it (we may have a definition on the
902 stack, even if we already defined a modification, if it
903 is a struct which we did not define at the time it was
905 free (stab_pop_type (info
));
906 if (! stab_push_defined_type (info
, tindex
, size
))
911 tindex
= info
->type_index
;
914 s
= stab_pop_type (info
);
915 buf
= (char *) xmalloc (strlen (s
) + 20);
916 sprintf (buf
, "%ld=%c%s", tindex
, mod
, s
);
919 (*cache
)[targindex
] = tindex
;
921 if (! stab_push_string (info
, buf
, tindex
, true, size
))
931 /* Push a pointer type. */
934 stab_pointer_type (void *p
)
936 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
938 /* FIXME: The size should depend upon the architecture. */
939 return stab_modify_type (info
, '*', 4, &info
->type_cache
.pointer_types
,
940 &info
->type_cache
.pointer_types_alloc
);
943 /* Push a function type. */
946 stab_function_type (void *p
, int argcount
,
947 bool varargs ATTRIBUTE_UNUSED
)
949 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
952 /* We have no way to represent the argument types, so we just
953 discard them. However, if they define new types, we must output
954 them. We do this by producing empty typedefs. */
955 for (i
= 0; i
< argcount
; i
++)
957 if (! info
->type_stack
->definition
)
958 free (stab_pop_type (info
));
963 s
= stab_pop_type (info
);
965 buf
= (char *) xmalloc (strlen (s
) + 3);
966 sprintf (buf
, ":t%s", s
);
969 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
976 return stab_modify_type (info
, 'f', 0, &info
->type_cache
.function_types
,
977 &info
->type_cache
.function_types_alloc
);
980 /* Push a reference type. */
983 stab_reference_type (void *p
)
985 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
987 /* FIXME: The size should depend upon the architecture. */
988 return stab_modify_type (info
, '&', 4, &info
->type_cache
.reference_types
,
989 &info
->type_cache
.reference_types_alloc
);
992 /* Push a range type. */
995 stab_range_type (void *p
, bfd_signed_vma low
, bfd_signed_vma high
)
997 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1002 definition
= info
->type_stack
->definition
;
1003 size
= info
->type_stack
->size
;
1005 s
= stab_pop_type (info
);
1006 buf
= (char *) xmalloc (strlen (s
) + 100);
1007 sprintf (buf
, "r%s;%ld;%ld;", s
, (long) low
, (long) high
);
1010 if (! stab_push_string (info
, buf
, 0, definition
, size
))
1018 /* Push an array type. */
1021 stab_array_type (void *p
, bfd_signed_vma low
, bfd_signed_vma high
,
1024 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1026 unsigned int element_size
;
1027 char *range
, *element
, *buf
;
1031 definition
= info
->type_stack
->definition
;
1032 range
= stab_pop_type (info
);
1034 definition
= definition
|| info
->type_stack
->definition
;
1035 element_size
= info
->type_stack
->size
;
1036 element
= stab_pop_type (info
);
1038 buf
= (char *) xmalloc (strlen (range
) + strlen (element
) + 100);
1047 /* We need to define a type in order to include the string
1049 tindex
= info
->type_index
;
1052 sprintf (buf
, "%ld=@S;", tindex
);
1055 sprintf (buf
+ strlen (buf
), "ar%s;%ld;%ld;%s",
1056 range
, (long) low
, (long) high
, element
);
1063 size
= element_size
* ((high
- low
) + 1);
1064 if (! stab_push_string (info
, buf
, tindex
, definition
, size
))
1072 /* Push a set type. */
1075 stab_set_type (void *p
, bool bitstringp
)
1077 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1082 definition
= info
->type_stack
->definition
;
1084 s
= stab_pop_type (info
);
1085 buf
= (char *) xmalloc (strlen (s
) + 30);
1094 /* We need to define a type in order to include the string
1096 tindex
= info
->type_index
;
1099 sprintf (buf
, "%ld=@S;", tindex
);
1102 sprintf (buf
+ strlen (buf
), "S%s", s
);
1105 if (! stab_push_string (info
, buf
, tindex
, definition
, 0))
1113 /* Push an offset type. */
1116 stab_offset_type (void *p
)
1118 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1120 char *target
, *base
, *buf
;
1122 definition
= info
->type_stack
->definition
;
1123 target
= stab_pop_type (info
);
1125 definition
= definition
|| info
->type_stack
->definition
;
1126 base
= stab_pop_type (info
);
1128 buf
= (char *) xmalloc (strlen (target
) + strlen (base
) + 3);
1129 sprintf (buf
, "@%s,%s", base
, target
);
1133 if (! stab_push_string (info
, buf
, 0, definition
, 0))
1141 /* Push a method type. */
1144 stab_method_type (void *p
, bool domainp
, int argcount
,
1147 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1149 char *domain
, *return_type
, *buf
;
1154 /* We don't bother with stub method types, because that would
1155 require a mangler for C++ argument types. This will waste space
1156 in the debugging output. */
1158 /* We need a domain. I'm not sure DOMAINP can ever be false,
1162 if (! stab_empty_type (p
))
1166 definition
= info
->type_stack
->definition
;
1167 domain
= stab_pop_type (info
);
1169 /* A non-varargs function is indicated by making the last parameter
1177 else if (argcount
== 0)
1183 args
= (char **) xmalloc (1 * sizeof (*args
));
1184 if (! stab_empty_type (p
))
1186 definition
= definition
|| info
->type_stack
->definition
;
1187 args
[0] = stab_pop_type (info
);
1193 args
= (char **) xmalloc ((argcount
+ 1) * sizeof (*args
));
1194 for (i
= argcount
- 1; i
>= 0; i
--)
1196 definition
= definition
|| info
->type_stack
->definition
;
1197 args
[i
] = stab_pop_type (info
);
1201 if (! stab_empty_type (p
))
1203 definition
= definition
|| info
->type_stack
->definition
;
1204 args
[argcount
] = stab_pop_type (info
);
1209 definition
= definition
|| info
->type_stack
->definition
;
1210 return_type
= stab_pop_type (info
);
1212 len
= strlen (domain
) + strlen (return_type
) + 10;
1213 for (i
= 0; i
< argcount
; i
++)
1214 len
+= strlen (args
[i
]);
1216 buf
= (char *) xmalloc (len
);
1218 sprintf (buf
, "#%s,%s", domain
, return_type
);
1221 for (i
= 0; i
< argcount
; i
++)
1224 strcat (buf
, args
[i
]);
1231 if (! stab_push_string (info
, buf
, 0, definition
, 0))
1239 /* Push a const version of a type. */
1242 stab_const_type (void *p
)
1244 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1246 return stab_modify_type (info
, 'k', info
->type_stack
->size
,
1247 (long **) NULL
, (size_t *) NULL
);
1250 /* Push a volatile version of a type. */
1253 stab_volatile_type (void *p
)
1255 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1257 return stab_modify_type (info
, 'B', info
->type_stack
->size
,
1258 (long **) NULL
, (size_t *) NULL
);
1261 /* Get the type index to use for a struct/union/class ID. This should
1262 return -1 if it fails. */
1265 stab_get_struct_index (struct stab_write_handle
*info
, const char *tag
,
1266 unsigned int id
, enum debug_type_kind kind
,
1267 unsigned int *psize
)
1269 if (id
>= info
->type_cache
.struct_types_alloc
)
1273 alloc
= info
->type_cache
.struct_types_alloc
;
1278 info
->type_cache
.struct_types
=
1279 (struct stab_tag
*) xrealloc (info
->type_cache
.struct_types
,
1280 alloc
* sizeof (struct stab_tag
));
1281 memset ((info
->type_cache
.struct_types
1282 + info
->type_cache
.struct_types_alloc
),
1284 ((alloc
- info
->type_cache
.struct_types_alloc
)
1285 * sizeof (struct stab_tag
)));
1286 info
->type_cache
.struct_types_alloc
= alloc
;
1289 if (info
->type_cache
.struct_types
[id
].index
== 0)
1291 info
->type_cache
.struct_types
[id
].index
= info
->type_index
;
1293 info
->type_cache
.struct_types
[id
].tag
= tag
;
1294 info
->type_cache
.struct_types
[id
].kind
= kind
;
1297 if (kind
== DEBUG_KIND_ILLEGAL
)
1299 /* This is a definition of the struct. */
1300 info
->type_cache
.struct_types
[id
].kind
= kind
;
1301 info
->type_cache
.struct_types
[id
].size
= *psize
;
1304 *psize
= info
->type_cache
.struct_types
[id
].size
;
1306 return info
->type_cache
.struct_types
[id
].index
;
1309 /* Start outputting a struct. We ignore the tag, and handle it in
1313 stab_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1314 bool structp
, unsigned int size
)
1316 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1329 tindex
= stab_get_struct_index (info
, tag
, id
, DEBUG_KIND_ILLEGAL
,
1333 sprintf (buf
, "%ld=", tindex
);
1337 sprintf (buf
+ strlen (buf
), "%c%u",
1338 structp
? 's' : 'u',
1341 if (! stab_push_string (info
, buf
, tindex
, definition
, size
))
1344 info
->type_stack
->fields
= (char *) xmalloc (1);
1345 info
->type_stack
->fields
[0] = '\0';
1350 /* Add a field to a struct. */
1353 stab_struct_field (void *p
, const char *name
, bfd_vma bitpos
,
1354 bfd_vma bitsize
, enum debug_visibility visibility
)
1356 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1362 definition
= info
->type_stack
->definition
;
1363 size
= info
->type_stack
->size
;
1364 s
= stab_pop_type (info
);
1366 /* Add this field to the end of the current struct fields, which is
1367 currently on the top of the stack. */
1368 if (info
->type_stack
->fields
== NULL
)
1371 n
= (char *) xmalloc (strlen (info
->type_stack
->fields
)
1381 case DEBUG_VISIBILITY_PUBLIC
:
1385 case DEBUG_VISIBILITY_PRIVATE
:
1389 case DEBUG_VISIBILITY_PROTECTED
:
1398 non_fatal (_("%s: warning: unknown size for field `%s' in struct"),
1399 bfd_get_filename (info
->abfd
), name
);
1402 sprintf (n
, "%s%s:%s%s,%ld,%ld;", info
->type_stack
->fields
, name
, vis
, s
,
1403 (long) bitpos
, (long) bitsize
);
1405 free (info
->type_stack
->fields
);
1406 info
->type_stack
->fields
= n
;
1409 info
->type_stack
->definition
= true;
1414 /* Finish up a struct. */
1417 stab_end_struct_type (void *p
)
1419 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1423 char *fields
, *first
, *buf
;
1425 if (info
->type_stack
== NULL
|| info
->type_stack
->fields
== NULL
)
1428 definition
= info
->type_stack
->definition
;
1429 tindex
= info
->type_stack
->index
;
1430 size
= info
->type_stack
->size
;
1431 fields
= info
->type_stack
->fields
;
1432 first
= stab_pop_type (info
);
1434 buf
= (char *) xmalloc (strlen (first
) + strlen (fields
) + 2);
1435 sprintf (buf
, "%s%s;", first
, fields
);
1439 if (! stab_push_string (info
, buf
, tindex
, definition
, size
))
1447 /* Start outputting a class. */
1450 stab_start_class_type (void *p
, const char *tag
, unsigned int id
,
1451 bool structp
, unsigned int size
,
1452 bool vptr
, bool ownvptr
)
1454 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1455 bool definition
= false;
1456 char *vstring
= NULL
;
1458 if (vptr
&& !ownvptr
)
1460 definition
= info
->type_stack
->definition
;
1461 vstring
= stab_pop_type (info
);
1464 if (! stab_start_struct_type (p
, tag
, id
, structp
, size
))
1473 if (info
->type_stack
->index
< 1)
1475 vtable
= (char *) xmalloc (20);
1476 sprintf (vtable
, "~%%%ld", info
->type_stack
->index
);
1480 if (vstring
== NULL
)
1482 vtable
= (char *) xmalloc (strlen (vstring
) + 3);
1483 sprintf (vtable
, "~%%%s", vstring
);
1486 info
->type_stack
->definition
= true;
1488 info
->type_stack
->vtable
= vtable
;
1494 /* Add a static member to the class on the type stack. */
1497 stab_class_static_member (void *p
, const char *name
, const char *physname
,
1498 enum debug_visibility visibility
)
1500 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1505 definition
= info
->type_stack
->definition
;
1506 s
= stab_pop_type (info
);
1508 /* Add this field to the end of the current struct fields, which is
1509 currently on the top of the stack. */
1511 if (info
->type_stack
->fields
== NULL
)
1513 n
= (char *) xmalloc (strlen (info
->type_stack
->fields
)
1524 case DEBUG_VISIBILITY_PUBLIC
:
1528 case DEBUG_VISIBILITY_PRIVATE
:
1532 case DEBUG_VISIBILITY_PROTECTED
:
1537 sprintf (n
, "%s%s:%s%s:%s;", info
->type_stack
->fields
, name
, vis
, s
,
1540 free (info
->type_stack
->fields
);
1541 info
->type_stack
->fields
= n
;
1544 info
->type_stack
->definition
= true;
1549 /* Add a base class to the class on the type stack. */
1552 stab_class_baseclass (void *p
, bfd_vma bitpos
, bool is_virtual
,
1553 enum debug_visibility visibility
)
1555 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1562 definition
= info
->type_stack
->definition
;
1563 s
= stab_pop_type (info
);
1565 /* Build the base class specifier. */
1567 buf
= (char *) xmalloc (strlen (s
) + 25);
1568 buf
[0] = is_virtual
? '1' : '0';
1574 case DEBUG_VISIBILITY_PRIVATE
:
1578 case DEBUG_VISIBILITY_PROTECTED
:
1582 case DEBUG_VISIBILITY_PUBLIC
:
1587 sprintf (buf
+ 2, "%ld,%s;", (long) bitpos
, s
);
1590 /* Add the new baseclass to the existing ones. */
1592 if (info
->type_stack
== NULL
|| info
->type_stack
->fields
== NULL
)
1595 if (info
->type_stack
->baseclasses
== NULL
)
1600 while (info
->type_stack
->baseclasses
[c
] != NULL
)
1604 baseclasses
= (char **) xrealloc (info
->type_stack
->baseclasses
,
1605 (c
+ 2) * sizeof (*baseclasses
));
1606 baseclasses
[c
] = buf
;
1607 baseclasses
[c
+ 1] = NULL
;
1609 info
->type_stack
->baseclasses
= baseclasses
;
1612 info
->type_stack
->definition
= true;
1617 /* Start adding a method to the class on the type stack. */
1620 stab_class_start_method (void *p
, const char *name
)
1622 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1625 if (info
->type_stack
== NULL
|| info
->type_stack
->fields
== NULL
)
1628 if (info
->type_stack
->methods
== NULL
)
1630 m
= (char *) xmalloc (strlen (name
) + 3);
1635 m
= (char *) xrealloc (info
->type_stack
->methods
,
1636 (strlen (info
->type_stack
->methods
)
1641 sprintf (m
+ strlen (m
), "%s::", name
);
1643 info
->type_stack
->methods
= m
;
1648 /* Add a variant, either static or not, to the current method. */
1651 stab_class_method_var (struct stab_write_handle
*info
, const char *physname
,
1652 enum debug_visibility visibility
,
1653 bool staticp
, bool constp
,
1654 bool volatilep
, bfd_vma voffset
,
1659 char *context
= NULL
;
1660 char visc
, qualc
, typec
;
1662 definition
= info
->type_stack
->definition
;
1663 type
= stab_pop_type (info
);
1667 definition
= definition
|| info
->type_stack
->definition
;
1668 context
= stab_pop_type (info
);
1671 if (info
->type_stack
== NULL
|| info
->type_stack
->methods
== NULL
)
1679 case DEBUG_VISIBILITY_PRIVATE
:
1683 case DEBUG_VISIBILITY_PROTECTED
:
1687 case DEBUG_VISIBILITY_PUBLIC
:
1709 else if (! contextp
)
1714 info
->type_stack
->methods
=
1715 (char *) xrealloc (info
->type_stack
->methods
,
1716 (strlen (info
->type_stack
->methods
)
1719 + (contextp
? strlen (context
) : 0)
1722 sprintf (info
->type_stack
->methods
+ strlen (info
->type_stack
->methods
),
1723 "%s:%s;%c%c%c", type
, physname
, visc
, qualc
, typec
);
1728 sprintf (info
->type_stack
->methods
+ strlen (info
->type_stack
->methods
),
1729 "%ld;%s;", (long) voffset
, context
);
1734 info
->type_stack
->definition
= true;
1739 /* Add a variant to the current method. */
1742 stab_class_method_variant (void *p
, const char *physname
,
1743 enum debug_visibility visibility
,
1744 bool constp
, bool volatilep
,
1745 bfd_vma voffset
, bool contextp
)
1747 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1749 return stab_class_method_var (info
, physname
, visibility
, false, constp
,
1750 volatilep
, voffset
, contextp
);
1753 /* Add a static variant to the current method. */
1756 stab_class_static_method_variant (void *p
, const char *physname
,
1757 enum debug_visibility visibility
,
1758 bool constp
, bool volatilep
)
1760 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1762 return stab_class_method_var (info
, physname
, visibility
, true, constp
,
1763 volatilep
, 0, false);
1766 /* Finish up a method. */
1769 stab_class_end_method (void *p
)
1771 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1773 if (info
->type_stack
== NULL
|| info
->type_stack
->methods
== NULL
)
1776 /* We allocated enough room on info->type_stack->methods to add the
1777 trailing semicolon. */
1778 strcat (info
->type_stack
->methods
, ";");
1783 /* Finish up a class. */
1786 stab_end_class_type (void *p
)
1788 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1793 if (info
->type_stack
== NULL
1794 || info
->type_stack
->string
== NULL
1795 || info
->type_stack
->fields
== NULL
)
1798 /* Work out the size we need to allocate for the class definition. */
1800 len
= (strlen (info
->type_stack
->string
)
1801 + strlen (info
->type_stack
->fields
)
1803 if (info
->type_stack
->baseclasses
!= NULL
)
1806 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1807 len
+= strlen (info
->type_stack
->baseclasses
[i
]);
1809 if (info
->type_stack
->methods
!= NULL
)
1810 len
+= strlen (info
->type_stack
->methods
);
1811 if (info
->type_stack
->vtable
!= NULL
)
1812 len
+= strlen (info
->type_stack
->vtable
);
1814 /* Build the class definition. */
1816 buf
= (char *) xmalloc (len
);
1818 strcpy (buf
, info
->type_stack
->string
);
1820 if (info
->type_stack
->baseclasses
!= NULL
)
1822 sprintf (buf
+ strlen (buf
), "!%u,", i
);
1823 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1825 strcat (buf
, info
->type_stack
->baseclasses
[i
]);
1826 free (info
->type_stack
->baseclasses
[i
]);
1828 free (info
->type_stack
->baseclasses
);
1829 info
->type_stack
->baseclasses
= NULL
;
1832 strcat (buf
, info
->type_stack
->fields
);
1833 free (info
->type_stack
->fields
);
1834 info
->type_stack
->fields
= NULL
;
1836 if (info
->type_stack
->methods
!= NULL
)
1838 strcat (buf
, info
->type_stack
->methods
);
1839 free (info
->type_stack
->methods
);
1840 info
->type_stack
->methods
= NULL
;
1845 if (info
->type_stack
->vtable
!= NULL
)
1847 strcat (buf
, info
->type_stack
->vtable
);
1848 free (info
->type_stack
->vtable
);
1849 info
->type_stack
->vtable
= NULL
;
1852 /* Replace the string on the top of the stack with the complete
1853 class definition. */
1854 free (info
->type_stack
->string
);
1855 info
->type_stack
->string
= buf
;
1860 /* Push a typedef which was previously defined. */
1863 stab_typedef_type (void *p
, const char *name
)
1865 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1866 struct string_hash_entry
*h
;
1868 h
= string_hash_lookup (&info
->typedef_hash
, name
, false, false);
1869 if (h
== NULL
|| h
->index
< 1)
1872 return stab_push_defined_type (info
, h
->index
, h
->size
);
1875 /* Push a struct, union or class tag. */
1878 stab_tag_type (void *p
, const char *name
, unsigned int id
,
1879 enum debug_type_kind kind
)
1881 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1883 unsigned int size
= 0;
1885 tindex
= stab_get_struct_index (info
, name
, id
, kind
, &size
);
1889 return stab_push_defined_type (info
, tindex
, size
);
1892 /* Define a typedef. */
1895 stab_typdef (void *p
, const char *name
)
1897 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1901 struct string_hash_entry
*h
;
1903 tindex
= info
->type_stack
->index
;
1904 size
= info
->type_stack
->size
;
1905 s
= stab_pop_type (info
);
1907 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 20);
1910 sprintf (buf
, "%s:t%s", name
, s
);
1913 tindex
= info
->type_index
;
1915 sprintf (buf
, "%s:t%ld=%s", name
, tindex
, s
);
1920 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
1925 h
= string_hash_lookup (&info
->typedef_hash
, name
, true, false);
1928 non_fatal (_("string_hash_lookup failed: %s"),
1929 bfd_errmsg (bfd_get_error ()));
1933 /* I don't think we care about redefinitions. */
1944 stab_tag (void *p
, const char *tag
)
1946 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1949 s
= stab_pop_type (info
);
1951 buf
= (char *) xmalloc (strlen (tag
) + strlen (s
) + 3);
1953 sprintf (buf
, "%s:T%s", tag
, s
);
1956 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
1964 /* Define an integer constant. */
1967 stab_int_constant (void *p
, const char *name
, bfd_vma val
)
1969 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1972 buf
= (char *) xmalloc (strlen (name
) + 20);
1973 sprintf (buf
, "%s:c=i%ld", name
, (long) val
);
1975 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
1983 /* Define a floating point constant. */
1986 stab_float_constant (void *p
, const char *name
, double val
)
1988 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1991 buf
= (char *) xmalloc (strlen (name
) + 20);
1992 sprintf (buf
, "%s:c=f%g", name
, val
);
1994 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2002 /* Define a typed constant. */
2005 stab_typed_constant (void *p
, const char *name
, bfd_vma val
)
2007 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2010 s
= stab_pop_type (info
);
2012 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 20);
2013 sprintf (buf
, "%s:c=e%s,%ld", name
, s
, (long) val
);
2016 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2024 /* Record a variable. */
2027 stab_variable (void *p
, const char *name
, enum debug_var_kind kind
,
2030 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2033 const char *kindstr
;
2035 s
= stab_pop_type (info
);
2048 stab_type
= N_STSYM
;
2052 case DEBUG_LOCAL_STATIC
:
2053 stab_type
= N_STSYM
;
2061 /* Make sure that this is a type reference or definition. */
2067 tindex
= info
->type_index
;
2069 n
= (char *) xmalloc (strlen (s
) + 20);
2070 sprintf (n
, "%ld=%s", tindex
, s
);
2076 case DEBUG_REGISTER
:
2082 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 3);
2083 sprintf (buf
, "%s:%s%s", name
, kindstr
, s
);
2086 if (! stab_write_symbol (info
, stab_type
, 0, val
, buf
))
2094 /* Start outputting a function. */
2097 stab_start_function (void *p
, const char *name
, bool globalp
)
2099 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2100 char *rettype
, *buf
;
2102 if (info
->nesting
!= 0 || info
->fun_offset
!= -1)
2105 rettype
= stab_pop_type (info
);
2107 buf
= (char *) xmalloc (strlen (name
) + strlen (rettype
) + 3);
2108 sprintf (buf
, "%s:%c%s", name
,
2109 globalp
? 'F' : 'f',
2112 /* We don't know the value now, so we set it in start_block. */
2113 info
->fun_offset
= info
->symbols_size
;
2115 if (! stab_write_symbol (info
, N_FUN
, 0, 0, buf
))
2123 /* Output a function parameter. */
2126 stab_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
, bfd_vma val
)
2128 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2133 s
= stab_pop_type (info
);
2140 case DEBUG_PARM_STACK
:
2145 case DEBUG_PARM_REG
:
2150 case DEBUG_PARM_REFERENCE
:
2155 case DEBUG_PARM_REF_REG
:
2161 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 3);
2162 sprintf (buf
, "%s:%c%s", name
, kindc
, s
);
2165 if (! stab_write_symbol (info
, stab_type
, 0, val
, buf
))
2173 /* Start a block. */
2176 stab_start_block (void *p
, bfd_vma addr
)
2178 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2180 /* Fill in any slots which have been waiting for the first known
2183 if (info
->so_offset
!= -1)
2185 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->so_offset
+ 8);
2186 info
->so_offset
= -1;
2189 if (info
->fun_offset
!= -1)
2191 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->fun_offset
+ 8);
2192 info
->fun_offset
= -1;
2197 /* We will be called with a top level block surrounding the
2198 function, but stabs information does not output that block, so we
2201 if (info
->nesting
== 1)
2203 info
->fnaddr
= addr
;
2207 /* We have to output the LBRAC symbol after any variables which are
2208 declared inside the block. We postpone the LBRAC until the next
2209 start_block or end_block. */
2211 /* If we have postponed an LBRAC, output it now. */
2212 if (info
->pending_lbrac
!= (bfd_vma
) -1)
2214 if (! stab_write_symbol (info
, N_LBRAC
, 0, info
->pending_lbrac
,
2215 (const char *) NULL
))
2219 /* Remember the address and output it later. */
2221 info
->pending_lbrac
= addr
- info
->fnaddr
;
2229 stab_end_block (void *p
, bfd_vma addr
)
2231 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2233 if (addr
> info
->last_text_address
)
2234 info
->last_text_address
= addr
;
2236 /* If we have postponed an LBRAC, output it now. */
2237 if (info
->pending_lbrac
!= (bfd_vma
) -1)
2239 if (! stab_write_symbol (info
, N_LBRAC
, 0, info
->pending_lbrac
,
2240 (const char *) NULL
))
2242 info
->pending_lbrac
= (bfd_vma
) -1;
2245 if (info
->nesting
< 1)
2250 /* We ignore the outermost block. */
2251 if (info
->nesting
== 0)
2254 return stab_write_symbol (info
, N_RBRAC
, 0, addr
- info
->fnaddr
,
2255 (const char *) NULL
);
2258 /* End a function. */
2261 stab_end_function (void *p ATTRIBUTE_UNUSED
)
2266 /* Output a line number. */
2269 stab_lineno (void *p
, const char *file
, unsigned long lineno
, bfd_vma addr
)
2271 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2273 if (info
->lineno_filename
== NULL
)
2276 if (addr
> info
->last_text_address
)
2277 info
->last_text_address
= addr
;
2279 if (filename_cmp (file
, info
->lineno_filename
) != 0)
2281 if (! stab_write_symbol (info
, N_SOL
, 0, addr
, file
))
2283 info
->lineno_filename
= file
;
2286 return stab_write_symbol (info
, N_SLINE
, lineno
, addr
- info
->fnaddr
,
2287 (const char *) NULL
);