1 /* wrstabs.c -- Output stabs debugging information
2 Copyright (C) 1996, 1997, 1998, 1999 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 2 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., 59 Temple Place - Suite 330, Boston, MA
22 /* This file contains code which writes out stabs debugging
31 #include "libiberty.h"
35 /* Meaningless definition needs by aout64.h. FIXME. */
36 #define BYTES_IN_WORD 4
38 #include "aout/aout64.h"
39 #include "aout/stab_gnu.h"
41 /* The size of a stabs symbol. This presumes 32 bit values. */
43 #define STAB_SYMBOL_SIZE (12)
45 /* An entry in a string hash table. */
47 struct string_hash_entry
49 struct bfd_hash_entry root
;
50 /* Next string in this table. */
51 struct string_hash_entry
*next
;
52 /* Index in string table. */
54 /* Size of type if this is a typedef. */
58 /* A string hash table. */
60 struct string_hash_table
62 struct bfd_hash_table table
;
65 /* The type stack. Each element on the stack is a string. */
67 struct stab_type_stack
69 /* The next element on the stack. */
70 struct stab_type_stack
*next
;
71 /* This element as a string. */
73 /* The type index of this element. */
75 /* The size of the type. */
77 /* Whether type string defines a new type. */
79 /* String defining struct fields. */
81 /* NULL terminated array of strings defining base classes for a
84 /* String defining class methods. */
86 /* String defining vtable pointer for a class. */
90 /* This structure is used to keep track of type indices for tagged
99 /* The kind of type. This is set to DEBUG_KIND_ILLEGAL when the
101 enum debug_type_kind kind
;
102 /* The size of the struct. */
106 /* We remember various sorts of type indices. They are not related,
107 but, for convenience, we keep all the information in this
110 struct stab_type_cache
112 /* The void type index. */
114 /* Signed integer type indices, indexed by size - 1. */
115 long signed_integer_types
[8];
116 /* Unsigned integer type indices, indexed by size - 1. */
117 long unsigned_integer_types
[8];
118 /* Floating point types, indexed by size - 1. */
119 long float_types
[16];
120 /* Pointers to types, indexed by the type index. */
122 size_t pointer_types_alloc
;
123 /* Functions returning types, indexed by the type index. */
124 long *function_types
;
125 size_t function_types_alloc
;
126 /* References to types, indexed by the type index. */
127 long *reference_types
;
128 size_t reference_types_alloc
;
129 /* Struct/union/class type indices, indexed by the struct id. */
130 struct stab_tag
*struct_types
;
131 size_t struct_types_alloc
;
134 /* This is the handle passed through debug_write. */
136 struct stab_write_handle
140 /* This buffer holds the symbols. */
143 size_t symbols_alloc
;
144 /* This is a list of hash table entries for the strings. */
145 struct string_hash_entry
*strings
;
146 /* The last string hash table entry. */
147 struct string_hash_entry
*last_string
;
148 /* The size of the strings. */
150 /* This hash table eliminates duplicate strings. */
151 struct string_hash_table strhash
;
152 /* The type stack. */
153 struct stab_type_stack
*type_stack
;
154 /* The next type index. */
156 /* The type cache. */
157 struct stab_type_cache type_cache
;
158 /* A mapping from typedef names to type indices. */
159 struct string_hash_table typedef_hash
;
160 /* If this is not -1, it is the offset to the most recent N_SO
161 symbol, and the value of that symbol needs to be set. */
163 /* If this is not -1, it is the offset to the most recent N_FUN
164 symbol, and the value of that symbol needs to be set. */
166 /* The last text section address seen. */
167 bfd_vma last_text_address
;
168 /* The block nesting depth. */
169 unsigned int nesting
;
170 /* The function address. */
172 /* A pending LBRAC symbol. */
173 bfd_vma pending_lbrac
;
174 /* The current line number file name. */
175 const char *lineno_filename
;
178 static struct bfd_hash_entry
*string_hash_newfunc
179 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
180 static boolean stab_write_symbol
181 PARAMS ((struct stab_write_handle
*, int, int, bfd_vma
, const char *));
182 static boolean stab_push_string
183 PARAMS ((struct stab_write_handle
*, const char *, long, boolean
,
185 static boolean stab_push_defined_type
186 PARAMS ((struct stab_write_handle
*, long, unsigned int));
187 static char *stab_pop_type
PARAMS ((struct stab_write_handle
*));
188 static boolean stab_modify_type
189 PARAMS ((struct stab_write_handle
*, int, unsigned int, long **, size_t *));
190 static long stab_get_struct_index
191 PARAMS ((struct stab_write_handle
*, const char *, unsigned int,
192 enum debug_type_kind
, unsigned int *));
193 static boolean stab_class_method_var
194 PARAMS ((struct stab_write_handle
*, const char *, enum debug_visibility
,
195 boolean
, boolean
, boolean
, bfd_vma
, boolean
));
197 static boolean stab_start_compilation_unit
PARAMS ((PTR
, const char *));
198 static boolean stab_start_source
PARAMS ((PTR
, const char *));
199 static boolean stab_empty_type
PARAMS ((PTR
));
200 static boolean stab_void_type
PARAMS ((PTR
));
201 static boolean stab_int_type
PARAMS ((PTR
, unsigned int, boolean
));
202 static boolean stab_float_type
PARAMS ((PTR
, unsigned int));
203 static boolean stab_complex_type
PARAMS ((PTR
, unsigned int));
204 static boolean stab_bool_type
PARAMS ((PTR
, unsigned int));
205 static boolean stab_enum_type
206 PARAMS ((PTR
, const char *, const char **, bfd_signed_vma
*));
207 static boolean stab_pointer_type
PARAMS ((PTR
));
208 static boolean stab_function_type
PARAMS ((PTR
, int, boolean
));
209 static boolean stab_reference_type
PARAMS ((PTR
));
210 static boolean stab_range_type
PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
));
211 static boolean stab_array_type
212 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
, boolean
));
213 static boolean stab_set_type
PARAMS ((PTR
, boolean
));
214 static boolean stab_offset_type
PARAMS ((PTR
));
215 static boolean stab_method_type
PARAMS ((PTR
, boolean
, int, boolean
));
216 static boolean stab_const_type
PARAMS ((PTR
));
217 static boolean stab_volatile_type
PARAMS ((PTR
));
218 static boolean stab_start_struct_type
219 PARAMS ((PTR
, const char *, unsigned int, boolean
, unsigned int));
220 static boolean stab_struct_field
221 PARAMS ((PTR
, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
));
222 static boolean stab_end_struct_type
PARAMS ((PTR
));
223 static boolean stab_start_class_type
224 PARAMS ((PTR
, const char *, unsigned int, boolean
, unsigned int, boolean
,
226 static boolean stab_class_static_member
227 PARAMS ((PTR
, const char *, const char *, enum debug_visibility
));
228 static boolean stab_class_baseclass
229 PARAMS ((PTR
, bfd_vma
, boolean
, enum debug_visibility
));
230 static boolean stab_class_start_method
PARAMS ((PTR
, const char *));
231 static boolean stab_class_method_variant
232 PARAMS ((PTR
, const char *, enum debug_visibility
, boolean
, boolean
,
234 static boolean stab_class_static_method_variant
235 PARAMS ((PTR
, const char *, enum debug_visibility
, boolean
, boolean
));
236 static boolean stab_class_end_method
PARAMS ((PTR
));
237 static boolean stab_end_class_type
PARAMS ((PTR
));
238 static boolean stab_typedef_type
PARAMS ((PTR
, const char *));
239 static boolean stab_tag_type
240 PARAMS ((PTR
, const char *, unsigned int, enum debug_type_kind
));
241 static boolean stab_typdef
PARAMS ((PTR
, const char *));
242 static boolean stab_tag
PARAMS ((PTR
, const char *));
243 static boolean stab_int_constant
PARAMS ((PTR
, const char *, bfd_vma
));
244 static boolean stab_float_constant
PARAMS ((PTR
, const char *, double));
245 static boolean stab_typed_constant
PARAMS ((PTR
, const char *, bfd_vma
));
246 static boolean stab_variable
247 PARAMS ((PTR
, const char *, enum debug_var_kind
, bfd_vma
));
248 static boolean stab_start_function
PARAMS ((PTR
, const char *, boolean
));
249 static boolean stab_function_parameter
250 PARAMS ((PTR
, const char *, enum debug_parm_kind
, bfd_vma
));
251 static boolean stab_start_block
PARAMS ((PTR
, bfd_vma
));
252 static boolean stab_end_block
PARAMS ((PTR
, bfd_vma
));
253 static boolean stab_end_function
PARAMS ((PTR
));
254 static boolean stab_lineno
255 PARAMS ((PTR
, const char *, unsigned long, bfd_vma
));
257 static const struct debug_write_fns stab_fns
=
259 stab_start_compilation_unit
,
278 stab_start_struct_type
,
280 stab_end_struct_type
,
281 stab_start_class_type
,
282 stab_class_static_member
,
283 stab_class_baseclass
,
284 stab_class_start_method
,
285 stab_class_method_variant
,
286 stab_class_static_method_variant
,
287 stab_class_end_method
,
298 stab_function_parameter
,
305 /* Routine to create an entry in a string hash table. */
307 static struct bfd_hash_entry
*
308 string_hash_newfunc (entry
, table
, string
)
309 struct bfd_hash_entry
*entry
;
310 struct bfd_hash_table
*table
;
313 struct string_hash_entry
*ret
= (struct string_hash_entry
*) entry
;
315 /* Allocate the structure if it has not already been allocated by a
317 if (ret
== (struct string_hash_entry
*) NULL
)
318 ret
= ((struct string_hash_entry
*)
319 bfd_hash_allocate (table
, sizeof (struct string_hash_entry
)));
320 if (ret
== (struct string_hash_entry
*) NULL
)
323 /* Call the allocation method of the superclass. */
324 ret
= ((struct string_hash_entry
*)
325 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
329 /* Initialize the local fields. */
335 return (struct bfd_hash_entry
*) ret
;
338 /* Look up an entry in a string hash table. */
340 #define string_hash_lookup(t, string, create, copy) \
341 ((struct string_hash_entry *) \
342 bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
344 /* Add a symbol to the stabs debugging information we are building. */
347 stab_write_symbol (info
, type
, desc
, value
, string
)
348 struct stab_write_handle
*info
;
355 bfd_byte sym
[STAB_SYMBOL_SIZE
];
361 struct string_hash_entry
*h
;
363 h
= string_hash_lookup (&info
->strhash
, string
, true, true);
366 fprintf (stderr
, _("string_hash_lookup failed: %s\n"),
367 bfd_errmsg (bfd_get_error ()));
374 strx
= info
->strings_size
;
376 if (info
->last_string
== NULL
)
379 info
->last_string
->next
= h
;
380 info
->last_string
= h
;
381 info
->strings_size
+= strlen (string
) + 1;
385 /* This presumes 32 bit values. */
386 bfd_put_32 (info
->abfd
, strx
, sym
);
387 bfd_put_8 (info
->abfd
, type
, sym
+ 4);
388 bfd_put_8 (info
->abfd
, 0, sym
+ 5);
389 bfd_put_16 (info
->abfd
, desc
, sym
+ 6);
390 bfd_put_32 (info
->abfd
, value
, sym
+ 8);
392 if (info
->symbols_size
+ STAB_SYMBOL_SIZE
> info
->symbols_alloc
)
394 info
->symbols_alloc
*= 2;
395 info
->symbols
= (bfd_byte
*) xrealloc (info
->symbols
,
396 info
->symbols_alloc
);
399 memcpy (info
->symbols
+ info
->symbols_size
, sym
, STAB_SYMBOL_SIZE
);
401 info
->symbols_size
+= STAB_SYMBOL_SIZE
;
406 /* Push a string on to the type stack. */
409 stab_push_string (info
, string
, index
, definition
, size
)
410 struct stab_write_handle
*info
;
416 struct stab_type_stack
*s
;
418 s
= (struct stab_type_stack
*) xmalloc (sizeof *s
);
419 s
->string
= xstrdup (string
);
421 s
->definition
= definition
;
425 s
->baseclasses
= NULL
;
429 s
->next
= info
->type_stack
;
430 info
->type_stack
= s
;
435 /* Push a type index which has already been defined. */
438 stab_push_defined_type (info
, index
, size
)
439 struct stab_write_handle
*info
;
445 sprintf (buf
, "%ld", index
);
446 return stab_push_string (info
, buf
, index
, false, size
);
449 /* Pop a type off the type stack. The caller is responsible for
450 freeing the string. */
454 struct stab_write_handle
*info
;
456 struct stab_type_stack
*s
;
459 s
= info
->type_stack
;
462 info
->type_stack
= s
->next
;
471 /* The general routine to write out stabs in sections debugging
472 information. This accumulates the stabs symbols and the strings in
473 two obstacks. We can't easily write out the information as we go
474 along, because we need to know the section sizes before we can
475 write out the section contents. ABFD is the BFD and DHANDLE is the
476 handle for the debugging information. This sets *PSYMS to point to
477 the symbols, *PSYMSIZE the size of the symbols, *PSTRINGS to the
478 strings, and *PSTRINGSIZE to the size of the strings. */
481 write_stabs_in_sections_debugging_info (abfd
, dhandle
, psyms
, psymsize
,
482 pstrings
, pstringsize
)
486 bfd_size_type
*psymsize
;
488 bfd_size_type
*pstringsize
;
490 struct stab_write_handle info
;
491 struct string_hash_entry
*h
;
496 info
.symbols_size
= 0;
497 info
.symbols_alloc
= 500;
498 info
.symbols
= (bfd_byte
*) xmalloc (info
.symbols_alloc
);
501 info
.last_string
= NULL
;
502 /* Reserve 1 byte for a null byte. */
503 info
.strings_size
= 1;
505 if (! bfd_hash_table_init (&info
.strhash
.table
, string_hash_newfunc
)
506 || ! bfd_hash_table_init (&info
.typedef_hash
.table
, string_hash_newfunc
))
508 fprintf (stderr
, "bfd_hash_table_init_failed: %s\n",
509 bfd_errmsg (bfd_get_error ()));
513 info
.type_stack
= NULL
;
515 memset (&info
.type_cache
, 0, sizeof info
.type_cache
);
517 info
.fun_offset
= -1;
518 info
.last_text_address
= 0;
521 info
.pending_lbrac
= (bfd_vma
) -1;
523 /* The initial symbol holds the string size. */
524 if (! stab_write_symbol (&info
, 0, 0, 0, (const char *) NULL
))
527 /* Output an initial N_SO symbol. */
528 info
.so_offset
= info
.symbols_size
;
529 if (! stab_write_symbol (&info
, N_SO
, 0, 0, bfd_get_filename (abfd
)))
532 if (! debug_write (dhandle
, &stab_fns
, (PTR
) &info
))
535 assert (info
.pending_lbrac
== (bfd_vma
) -1);
537 /* Output a trailing N_SO. */
538 if (! stab_write_symbol (&info
, N_SO
, 0, info
.last_text_address
,
539 (const char *) NULL
))
542 /* Put the string size in the initial symbol. */
543 bfd_put_32 (abfd
, info
.strings_size
, info
.symbols
+ 8);
545 *psyms
= info
.symbols
;
546 *psymsize
= info
.symbols_size
;
548 *pstringsize
= info
.strings_size
;
549 *pstrings
= (bfd_byte
*) xmalloc (info
.strings_size
);
553 for (h
= info
.strings
; h
!= NULL
; h
= h
->next
)
555 strcpy ((char *) p
, h
->root
.string
);
556 p
+= strlen ((char *) p
) + 1;
562 /* Start writing out information for a compilation unit. */
565 stab_start_compilation_unit (p
, filename
)
567 const char *filename
;
569 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
571 /* We would normally output an N_SO symbol here. However, that
572 would force us to reset all of our type information. I think we
573 will be better off just outputting an N_SOL symbol, and not
574 worrying about splitting information between files. */
576 info
->lineno_filename
= filename
;
578 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
581 /* Start writing out information for a particular source file. */
584 stab_start_source (p
, filename
)
586 const char *filename
;
588 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
590 /* FIXME: The symbol's value is supposed to be the text section
591 address. However, we would have to fill it in later, and gdb
592 doesn't care, so we don't bother with it. */
594 info
->lineno_filename
= filename
;
596 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
599 /* Push an empty type. This shouldn't normally happen. We just use a
606 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
608 /* We don't call stab_void_type if the type is not yet defined,
609 because that might screw up the typedef. */
611 if (info
->type_cache
.void_type
!= 0)
612 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
618 index
= info
->type_index
;
621 sprintf (buf
, "%ld=%ld", index
, index
);
623 return stab_push_string (info
, buf
, index
, false, 0);
627 /* Push a void type. */
633 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
635 if (info
->type_cache
.void_type
!= 0)
636 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
642 index
= info
->type_index
;
645 info
->type_cache
.void_type
= index
;
647 sprintf (buf
, "%ld=%ld", index
, index
);
649 return stab_push_string (info
, buf
, index
, true, 0);
653 /* Push an integer type. */
656 stab_int_type (p
, size
, unsignedp
)
661 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
664 if (size
<= 0 || (size
> sizeof (long) && size
!= 8))
666 fprintf (stderr
, _("stab_int_type: bad size %u\n"), size
);
671 cache
= info
->type_cache
.signed_integer_types
;
673 cache
= info
->type_cache
.unsigned_integer_types
;
675 if (cache
[size
- 1] != 0)
676 return stab_push_defined_type (info
, cache
[size
- 1], size
);
682 index
= info
->type_index
;
685 cache
[size
- 1] = index
;
687 sprintf (buf
, "%ld=r%ld;", index
, index
);
691 if (size
< sizeof (long))
692 sprintf (buf
+ strlen (buf
), "%ld;", ((long) 1 << (size
* 8)) - 1);
693 else if (size
== sizeof (long))
696 strcat (buf
, "01777777777777777777777;");
702 if (size
<= sizeof (long))
703 sprintf (buf
+ strlen (buf
), "%ld;%ld;",
704 (long) - ((unsigned long) 1 << (size
* 8 - 1)),
705 (long) (((unsigned long) 1 << (size
* 8 - 1)) - 1));
707 strcat (buf
, "01000000000000000000000;0777777777777777777777;");
712 return stab_push_string (info
, buf
, index
, true, size
);
716 /* Push a floating point type. */
719 stab_float_type (p
, size
)
723 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
726 && size
- 1 < (sizeof info
->type_cache
.float_types
727 / sizeof info
->type_cache
.float_types
[0])
728 && info
->type_cache
.float_types
[size
- 1] != 0)
729 return stab_push_defined_type (info
,
730 info
->type_cache
.float_types
[size
- 1],
738 /* Floats are defined as a subrange of int. */
739 if (! stab_int_type (info
, 4, false))
741 int_type
= stab_pop_type (info
);
743 index
= info
->type_index
;
747 && size
- 1 < (sizeof info
->type_cache
.float_types
748 / sizeof info
->type_cache
.float_types
[0]))
749 info
->type_cache
.float_types
[size
- 1] = index
;
751 sprintf (buf
, "%ld=r%s;%u;0;", index
, int_type
, size
);
755 return stab_push_string (info
, buf
, index
, true, size
);
759 /* Push a complex type. */
762 stab_complex_type (p
, size
)
766 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
770 index
= info
->type_index
;
773 sprintf (buf
, "%ld=r%ld;%u;0;", index
, index
, size
);
775 return stab_push_string (info
, buf
, index
, true, size
* 2);
778 /* Push a boolean type. We use an XCOFF predefined type, since gdb
779 always recognizes them. */
782 stab_bool_type (p
, size
)
786 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
809 return stab_push_defined_type (info
, index
, size
);
812 /* Push an enum type. */
815 stab_enum_type (p
, tag
, names
, vals
)
819 bfd_signed_vma
*vals
;
821 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
830 assert (tag
!= NULL
);
832 buf
= (char *) xmalloc (10 + strlen (tag
));
833 sprintf (buf
, "xe%s:", tag
);
834 /* FIXME: The size is just a guess. */
835 if (! stab_push_string (info
, buf
, 0, false, 4))
844 for (pn
= names
; *pn
!= NULL
; pn
++)
845 len
+= strlen (*pn
) + 20;
847 buf
= (char *) xmalloc (len
);
853 index
= info
->type_index
;
855 sprintf (buf
, "%s:T%ld=e", tag
, index
);
858 for (pn
= names
, pv
= vals
; *pn
!= NULL
; pn
++, pv
++)
859 sprintf (buf
+ strlen (buf
), "%s:%ld,", *pn
, (long) *pv
);
864 /* FIXME: The size is just a guess. */
865 if (! stab_push_string (info
, buf
, 0, false, 4))
870 /* FIXME: The size is just a guess. */
871 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
)
872 || ! stab_push_defined_type (info
, index
, 4))
881 /* Push a modification of the top type on the stack. Cache the
882 results in CACHE and CACHE_ALLOC. */
885 stab_modify_type (info
, mod
, size
, cache
, cache_alloc
)
886 struct stab_write_handle
*info
;
896 assert (info
->type_stack
!= NULL
);
897 targindex
= info
->type_stack
->index
;
904 /* Either the target type has no index, or we aren't caching
905 this modifier. Either way we have no way of recording the
906 new type, so we don't bother to define one. */
907 definition
= info
->type_stack
->definition
;
908 s
= stab_pop_type (info
);
909 buf
= (char *) xmalloc (strlen (s
) + 2);
910 sprintf (buf
, "%c%s", mod
, s
);
912 if (! stab_push_string (info
, buf
, 0, definition
, size
))
918 if ((size_t) targindex
>= *cache_alloc
)
922 alloc
= *cache_alloc
;
925 while ((size_t) targindex
>= alloc
)
927 *cache
= (long *) xrealloc (*cache
, alloc
* sizeof (long));
928 memset (*cache
+ *cache_alloc
, 0,
929 (alloc
- *cache_alloc
) * sizeof (long));
930 *cache_alloc
= alloc
;
933 index
= (*cache
)[targindex
];
934 if (index
!= 0 && ! info
->type_stack
->definition
)
936 /* We have already defined a modification of this type, and
937 the entry on the type stack is not a definition, so we
938 can safely discard it (we may have a definition on the
939 stack, even if we already defined a modification, if it
940 is a struct which we did not define at the time it was
942 free (stab_pop_type (info
));
943 if (! stab_push_defined_type (info
, index
, size
))
948 index
= info
->type_index
;
951 s
= stab_pop_type (info
);
952 buf
= (char *) xmalloc (strlen (s
) + 20);
953 sprintf (buf
, "%ld=%c%s", index
, mod
, s
);
956 (*cache
)[targindex
] = index
;
958 if (! stab_push_string (info
, buf
, index
, true, size
))
968 /* Push a pointer type. */
971 stab_pointer_type (p
)
974 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
976 /* FIXME: The size should depend upon the architecture. */
977 return stab_modify_type (info
, '*', 4, &info
->type_cache
.pointer_types
,
978 &info
->type_cache
.pointer_types_alloc
);
981 /* Push a function type. */
984 stab_function_type (p
, argcount
, varargs
)
987 boolean varargs ATTRIBUTE_UNUSED
;
989 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
992 /* We have no way to represent the argument types, so we just
993 discard them. However, if they define new types, we must output
994 them. We do this by producing empty typedefs. */
995 for (i
= 0; i
< argcount
; i
++)
997 if (! info
->type_stack
->definition
)
998 free (stab_pop_type (info
));
1003 s
= stab_pop_type (info
);
1005 buf
= (char *) xmalloc (strlen (s
) + 3);
1006 sprintf (buf
, ":t%s", s
);
1009 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
1016 return stab_modify_type (info
, 'f', 0, &info
->type_cache
.function_types
,
1017 &info
->type_cache
.function_types_alloc
);
1020 /* Push a reference type. */
1023 stab_reference_type (p
)
1026 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1028 /* FIXME: The size should depend upon the architecture. */
1029 return stab_modify_type (info
, '&', 4, &info
->type_cache
.reference_types
,
1030 &info
->type_cache
.reference_types_alloc
);
1033 /* Push a range type. */
1036 stab_range_type (p
, low
, high
)
1039 bfd_signed_vma high
;
1041 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1046 definition
= info
->type_stack
->definition
;
1047 size
= info
->type_stack
->size
;
1049 s
= stab_pop_type (info
);
1050 buf
= (char *) xmalloc (strlen (s
) + 100);
1051 sprintf (buf
, "r%s;%ld;%ld;", s
, (long) low
, (long) high
);
1054 if (! stab_push_string (info
, buf
, 0, definition
, size
))
1062 /* Push an array type. */
1065 stab_array_type (p
, low
, high
, stringp
)
1068 bfd_signed_vma high
;
1071 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1073 unsigned int element_size
;
1074 char *range
, *element
, *buf
;
1078 definition
= info
->type_stack
->definition
;
1079 range
= stab_pop_type (info
);
1081 definition
= definition
|| info
->type_stack
->definition
;
1082 element_size
= info
->type_stack
->size
;
1083 element
= stab_pop_type (info
);
1085 buf
= (char *) xmalloc (strlen (range
) + strlen (element
) + 100);
1094 /* We need to define a type in order to include the string
1096 index
= info
->type_index
;
1099 sprintf (buf
, "%ld=@S;", index
);
1102 sprintf (buf
+ strlen (buf
), "ar%s;%ld;%ld;%s",
1103 range
, (long) low
, (long) high
, element
);
1110 size
= element_size
* ((high
- low
) + 1);
1111 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1119 /* Push a set type. */
1122 stab_set_type (p
, bitstringp
)
1126 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1131 definition
= info
->type_stack
->definition
;
1133 s
= stab_pop_type (info
);
1134 buf
= (char *) xmalloc (strlen (s
) + 30);
1143 /* We need to define a type in order to include the string
1145 index
= info
->type_index
;
1148 sprintf (buf
, "%ld=@S;", index
);
1151 sprintf (buf
+ strlen (buf
), "S%s", s
);
1154 if (! stab_push_string (info
, buf
, index
, definition
, 0))
1162 /* Push an offset type. */
1165 stab_offset_type (p
)
1168 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1170 char *target
, *base
, *buf
;
1172 definition
= info
->type_stack
->definition
;
1173 target
= stab_pop_type (info
);
1175 definition
= definition
|| info
->type_stack
->definition
;
1176 base
= stab_pop_type (info
);
1178 buf
= (char *) xmalloc (strlen (target
) + strlen (base
) + 3);
1179 sprintf (buf
, "@%s,%s", base
, target
);
1183 if (! stab_push_string (info
, buf
, 0, definition
, 0))
1191 /* Push a method type. */
1194 stab_method_type (p
, domainp
, argcount
, varargs
)
1200 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1202 char *domain
, *return_type
, *buf
;
1207 /* We don't bother with stub method types, because that would
1208 require a mangler for C++ argument types. This will waste space
1209 in the debugging output. */
1211 /* We need a domain. I'm not sure DOMAINP can ever be false,
1215 if (! stab_empty_type (p
))
1219 definition
= info
->type_stack
->definition
;
1220 domain
= stab_pop_type (info
);
1222 /* A non-varargs function is indicated by making the last parameter
1230 else if (argcount
== 0)
1236 args
= (char **) xmalloc (1 * sizeof (*args
));
1237 if (! stab_empty_type (p
))
1239 definition
= definition
|| info
->type_stack
->definition
;
1240 args
[0] = stab_pop_type (info
);
1246 args
= (char **) xmalloc ((argcount
+ 1) * sizeof (*args
));
1247 for (i
= argcount
- 1; i
>= 0; i
--)
1249 definition
= definition
|| info
->type_stack
->definition
;
1250 args
[i
] = stab_pop_type (info
);
1254 if (! stab_empty_type (p
))
1256 definition
= definition
|| info
->type_stack
->definition
;
1257 args
[argcount
] = stab_pop_type (info
);
1262 definition
= definition
|| info
->type_stack
->definition
;
1263 return_type
= stab_pop_type (info
);
1265 len
= strlen (domain
) + strlen (return_type
) + 10;
1266 for (i
= 0; i
< argcount
; i
++)
1267 len
+= strlen (args
[i
]);
1269 buf
= (char *) xmalloc (len
);
1271 sprintf (buf
, "#%s,%s", domain
, return_type
);
1274 for (i
= 0; i
< argcount
; i
++)
1277 strcat (buf
, args
[i
]);
1285 if (! stab_push_string (info
, buf
, 0, definition
, 0))
1293 /* Push a const version of a type. */
1299 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1301 return stab_modify_type (info
, 'k', info
->type_stack
->size
,
1302 (long **) NULL
, (size_t *) NULL
);
1305 /* Push a volatile version of a type. */
1308 stab_volatile_type (p
)
1311 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1313 return stab_modify_type (info
, 'B', info
->type_stack
->size
,
1314 (long **) NULL
, (size_t *) NULL
);
1317 /* Get the type index to use for a struct/union/class ID. This should
1318 return -1 if it fails. */
1321 stab_get_struct_index (info
, tag
, id
, kind
, psize
)
1322 struct stab_write_handle
*info
;
1325 enum debug_type_kind kind
;
1326 unsigned int *psize
;
1328 if (id
>= info
->type_cache
.struct_types_alloc
)
1332 alloc
= info
->type_cache
.struct_types_alloc
;
1337 info
->type_cache
.struct_types
=
1338 (struct stab_tag
*) xrealloc (info
->type_cache
.struct_types
,
1339 alloc
* sizeof (struct stab_tag
));
1340 memset ((info
->type_cache
.struct_types
1341 + info
->type_cache
.struct_types_alloc
),
1343 ((alloc
- info
->type_cache
.struct_types_alloc
)
1344 * sizeof (struct stab_tag
)));
1345 info
->type_cache
.struct_types_alloc
= alloc
;
1348 if (info
->type_cache
.struct_types
[id
].index
== 0)
1350 info
->type_cache
.struct_types
[id
].index
= info
->type_index
;
1352 info
->type_cache
.struct_types
[id
].tag
= tag
;
1353 info
->type_cache
.struct_types
[id
].kind
= kind
;
1356 if (kind
== DEBUG_KIND_ILLEGAL
)
1358 /* This is a definition of the struct. */
1359 info
->type_cache
.struct_types
[id
].kind
= kind
;
1360 info
->type_cache
.struct_types
[id
].size
= *psize
;
1363 *psize
= info
->type_cache
.struct_types
[id
].size
;
1365 return info
->type_cache
.struct_types
[id
].index
;
1368 /* Start outputting a struct. We ignore the tag, and handle it in
1373 stab_start_struct_type (p
, tag
, id
, structp
, size
)
1380 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1385 buf
= (char *) xmalloc (40);
1395 index
= stab_get_struct_index (info
, tag
, id
, DEBUG_KIND_ILLEGAL
,
1399 sprintf (buf
, "%ld=", index
);
1403 sprintf (buf
+ strlen (buf
), "%c%u",
1404 structp
? 's' : 'u',
1407 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1410 info
->type_stack
->fields
= (char *) xmalloc (1);
1411 info
->type_stack
->fields
[0] = '\0';
1416 /* Add a field to a struct. */
1419 stab_struct_field (p
, name
, bitpos
, bitsize
, visibility
)
1424 enum debug_visibility visibility
;
1426 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1432 definition
= info
->type_stack
->definition
;
1433 size
= info
->type_stack
->size
;
1434 s
= stab_pop_type (info
);
1436 /* Add this field to the end of the current struct fields, which is
1437 currently on the top of the stack. */
1439 assert (info
->type_stack
->fields
!= NULL
);
1440 n
= (char *) xmalloc (strlen (info
->type_stack
->fields
)
1450 case DEBUG_VISIBILITY_PUBLIC
:
1454 case DEBUG_VISIBILITY_PRIVATE
:
1458 case DEBUG_VISIBILITY_PROTECTED
:
1468 _("%s: warning: unknown size for field `%s' in struct\n"),
1469 bfd_get_filename (info
->abfd
), name
);
1472 sprintf (n
, "%s%s:%s%s,%ld,%ld;", info
->type_stack
->fields
, name
, vis
, s
,
1473 (long) bitpos
, (long) bitsize
);
1475 free (info
->type_stack
->fields
);
1476 info
->type_stack
->fields
= n
;
1479 info
->type_stack
->definition
= true;
1484 /* Finish up a struct. */
1487 stab_end_struct_type (p
)
1490 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1494 char *fields
, *first
, *buf
;
1496 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1498 definition
= info
->type_stack
->definition
;
1499 index
= info
->type_stack
->index
;
1500 size
= info
->type_stack
->size
;
1501 fields
= info
->type_stack
->fields
;
1502 first
= stab_pop_type (info
);
1504 buf
= (char *) xmalloc (strlen (first
) + strlen (fields
) + 2);
1505 sprintf (buf
, "%s%s;", first
, fields
);
1509 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1517 /* Start outputting a class. */
1520 stab_start_class_type (p
, tag
, id
, structp
, size
, vptr
, ownvptr
)
1529 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1533 if (! vptr
|| ownvptr
)
1540 definition
= info
->type_stack
->definition
;
1541 vstring
= stab_pop_type (info
);
1544 if (! stab_start_struct_type (p
, tag
, id
, structp
, size
))
1553 assert (info
->type_stack
->index
> 0);
1554 vtable
= (char *) xmalloc (20);
1555 sprintf (vtable
, "~%%%ld", info
->type_stack
->index
);
1559 vtable
= (char *) xmalloc (strlen (vstring
) + 3);
1560 sprintf (vtable
, "~%%%s", vstring
);
1564 info
->type_stack
->vtable
= vtable
;
1568 info
->type_stack
->definition
= true;
1573 /* Add a static member to the class on the type stack. */
1576 stab_class_static_member (p
, name
, physname
, visibility
)
1579 const char *physname
;
1580 enum debug_visibility visibility
;
1582 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1587 definition
= info
->type_stack
->definition
;
1588 s
= stab_pop_type (info
);
1590 /* Add this field to the end of the current struct fields, which is
1591 currently on the top of the stack. */
1593 assert (info
->type_stack
->fields
!= NULL
);
1594 n
= (char *) xmalloc (strlen (info
->type_stack
->fields
)
1605 case DEBUG_VISIBILITY_PUBLIC
:
1609 case DEBUG_VISIBILITY_PRIVATE
:
1613 case DEBUG_VISIBILITY_PROTECTED
:
1618 sprintf (n
, "%s%s:%s%s:%s;", info
->type_stack
->fields
, name
, vis
, s
,
1621 free (info
->type_stack
->fields
);
1622 info
->type_stack
->fields
= n
;
1625 info
->type_stack
->definition
= true;
1630 /* Add a base class to the class on the type stack. */
1633 stab_class_baseclass (p
, bitpos
, virtual, visibility
)
1637 enum debug_visibility visibility
;
1639 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1646 definition
= info
->type_stack
->definition
;
1647 s
= stab_pop_type (info
);
1649 /* Build the base class specifier. */
1651 buf
= (char *) xmalloc (strlen (s
) + 25);
1652 buf
[0] = virtual ? '1' : '0';
1658 case DEBUG_VISIBILITY_PRIVATE
:
1662 case DEBUG_VISIBILITY_PROTECTED
:
1666 case DEBUG_VISIBILITY_PUBLIC
:
1671 sprintf (buf
+ 2, "%ld,%s;", (long) bitpos
, s
);
1674 /* Add the new baseclass to the existing ones. */
1676 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1678 if (info
->type_stack
->baseclasses
== NULL
)
1683 while (info
->type_stack
->baseclasses
[c
] != NULL
)
1687 baseclasses
= (char **) xrealloc (info
->type_stack
->baseclasses
,
1688 (c
+ 2) * sizeof (*baseclasses
));
1689 baseclasses
[c
] = buf
;
1690 baseclasses
[c
+ 1] = NULL
;
1692 info
->type_stack
->baseclasses
= baseclasses
;
1695 info
->type_stack
->definition
= true;
1700 /* Start adding a method to the class on the type stack. */
1703 stab_class_start_method (p
, name
)
1707 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1710 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1712 if (info
->type_stack
->methods
== NULL
)
1714 m
= (char *) xmalloc (strlen (name
) + 3);
1719 m
= (char *) xrealloc (info
->type_stack
->methods
,
1720 (strlen (info
->type_stack
->methods
)
1725 sprintf (m
+ strlen (m
), "%s::", name
);
1727 info
->type_stack
->methods
= m
;
1732 /* Add a variant, either static or not, to the current method. */
1735 stab_class_method_var (info
, physname
, visibility
, staticp
, constp
, volatilep
,
1737 struct stab_write_handle
*info
;
1738 const char *physname
;
1739 enum debug_visibility visibility
;
1748 char *context
= NULL
;
1749 char visc
, qualc
, typec
;
1751 definition
= info
->type_stack
->definition
;
1752 type
= stab_pop_type (info
);
1756 definition
= definition
|| info
->type_stack
->definition
;
1757 context
= stab_pop_type (info
);
1760 assert (info
->type_stack
!= NULL
&& info
->type_stack
->methods
!= NULL
);
1767 case DEBUG_VISIBILITY_PRIVATE
:
1771 case DEBUG_VISIBILITY_PROTECTED
:
1775 case DEBUG_VISIBILITY_PUBLIC
:
1797 else if (! contextp
)
1802 info
->type_stack
->methods
=
1803 (char *) xrealloc (info
->type_stack
->methods
,
1804 (strlen (info
->type_stack
->methods
)
1807 + (contextp
? strlen (context
) : 0)
1810 sprintf (info
->type_stack
->methods
+ strlen (info
->type_stack
->methods
),
1811 "%s:%s;%c%c%c", type
, physname
, visc
, qualc
, typec
);
1816 sprintf (info
->type_stack
->methods
+ strlen (info
->type_stack
->methods
),
1817 "%ld;%s;", (long) voffset
, context
);
1822 info
->type_stack
->definition
= true;
1827 /* Add a variant to the current method. */
1830 stab_class_method_variant (p
, physname
, visibility
, constp
, volatilep
,
1833 const char *physname
;
1834 enum debug_visibility visibility
;
1840 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1842 return stab_class_method_var (info
, physname
, visibility
, false, constp
,
1843 volatilep
, voffset
, contextp
);
1846 /* Add a static variant to the current method. */
1849 stab_class_static_method_variant (p
, physname
, visibility
, constp
, volatilep
)
1851 const char *physname
;
1852 enum debug_visibility visibility
;
1856 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1858 return stab_class_method_var (info
, physname
, visibility
, true, constp
,
1859 volatilep
, 0, false);
1862 /* Finish up a method. */
1865 stab_class_end_method (p
)
1868 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1870 assert (info
->type_stack
!= NULL
&& info
->type_stack
->methods
!= NULL
);
1872 /* We allocated enough room on info->type_stack->methods to add the
1873 trailing semicolon. */
1874 strcat (info
->type_stack
->methods
, ";");
1879 /* Finish up a class. */
1882 stab_end_class_type (p
)
1885 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1890 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1892 /* Work out the size we need to allocate for the class definition. */
1894 len
= (strlen (info
->type_stack
->string
)
1895 + strlen (info
->type_stack
->fields
)
1897 if (info
->type_stack
->baseclasses
!= NULL
)
1900 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1901 len
+= strlen (info
->type_stack
->baseclasses
[i
]);
1903 if (info
->type_stack
->methods
!= NULL
)
1904 len
+= strlen (info
->type_stack
->methods
);
1905 if (info
->type_stack
->vtable
!= NULL
)
1906 len
+= strlen (info
->type_stack
->vtable
);
1908 /* Build the class definition. */
1910 buf
= (char *) xmalloc (len
);
1912 strcpy (buf
, info
->type_stack
->string
);
1914 if (info
->type_stack
->baseclasses
!= NULL
)
1916 sprintf (buf
+ strlen (buf
), "!%u,", i
);
1917 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1919 strcat (buf
, info
->type_stack
->baseclasses
[i
]);
1920 free (info
->type_stack
->baseclasses
[i
]);
1922 free (info
->type_stack
->baseclasses
);
1923 info
->type_stack
->baseclasses
= NULL
;
1926 strcat (buf
, info
->type_stack
->fields
);
1927 free (info
->type_stack
->fields
);
1928 info
->type_stack
->fields
= NULL
;
1930 if (info
->type_stack
->methods
!= NULL
)
1932 strcat (buf
, info
->type_stack
->methods
);
1933 free (info
->type_stack
->methods
);
1934 info
->type_stack
->methods
= NULL
;
1939 if (info
->type_stack
->vtable
!= NULL
)
1941 strcat (buf
, info
->type_stack
->vtable
);
1942 free (info
->type_stack
->vtable
);
1943 info
->type_stack
->vtable
= NULL
;
1946 /* Replace the string on the top of the stack with the complete
1947 class definition. */
1948 free (info
->type_stack
->string
);
1949 info
->type_stack
->string
= buf
;
1954 /* Push a typedef which was previously defined. */
1957 stab_typedef_type (p
, name
)
1961 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1962 struct string_hash_entry
*h
;
1964 h
= string_hash_lookup (&info
->typedef_hash
, name
, false, false);
1965 assert (h
!= NULL
&& h
->index
> 0);
1967 return stab_push_defined_type (info
, h
->index
, h
->size
);
1970 /* Push a struct, union or class tag. */
1973 stab_tag_type (p
, name
, id
, kind
)
1977 enum debug_type_kind kind
;
1979 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1983 index
= stab_get_struct_index (info
, name
, id
, kind
, &size
);
1987 return stab_push_defined_type (info
, index
, size
);
1990 /* Define a typedef. */
1993 stab_typdef (p
, name
)
1997 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2001 struct string_hash_entry
*h
;
2003 index
= info
->type_stack
->index
;
2004 size
= info
->type_stack
->size
;
2005 s
= stab_pop_type (info
);
2007 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 20);
2010 sprintf (buf
, "%s:t%s", name
, s
);
2013 index
= info
->type_index
;
2015 sprintf (buf
, "%s:t%ld=%s", name
, index
, s
);
2020 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2025 h
= string_hash_lookup (&info
->typedef_hash
, name
, true, false);
2028 fprintf (stderr
, _("string_hash_lookup failed: %s\n"),
2029 bfd_errmsg (bfd_get_error ()));
2033 /* I don't think we care about redefinitions. */
2048 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2051 s
= stab_pop_type (info
);
2053 buf
= (char *) xmalloc (strlen (tag
) + strlen (s
) + 3);
2055 sprintf (buf
, "%s:T%s", tag
, s
);
2058 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2066 /* Define an integer constant. */
2069 stab_int_constant (p
, name
, val
)
2074 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2077 buf
= (char *) xmalloc (strlen (name
) + 20);
2078 sprintf (buf
, "%s:c=i%ld", name
, (long) val
);
2080 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2088 /* Define a floating point constant. */
2091 stab_float_constant (p
, name
, val
)
2096 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2099 buf
= (char *) xmalloc (strlen (name
) + 20);
2100 sprintf (buf
, "%s:c=f%g", name
, val
);
2102 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2110 /* Define a typed constant. */
2113 stab_typed_constant (p
, name
, val
)
2118 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2121 s
= stab_pop_type (info
);
2123 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 20);
2124 sprintf (buf
, "%s:c=e%s,%ld", name
, s
, (long) val
);
2127 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2135 /* Record a variable. */
2138 stab_variable (p
, name
, kind
, val
)
2141 enum debug_var_kind kind
;
2144 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2147 const char *kindstr
;
2149 s
= stab_pop_type (info
);
2162 stab_type
= N_STSYM
;
2166 case DEBUG_LOCAL_STATIC
:
2167 stab_type
= N_STSYM
;
2175 /* Make sure that this is a type reference or definition. */
2176 if (! isdigit ((unsigned char) *s
))
2181 index
= info
->type_index
;
2183 n
= (char *) xmalloc (strlen (s
) + 20);
2184 sprintf (n
, "%ld=%s", index
, s
);
2190 case DEBUG_REGISTER
:
2196 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 3);
2197 sprintf (buf
, "%s:%s%s", name
, kindstr
, s
);
2200 if (! stab_write_symbol (info
, stab_type
, 0, val
, buf
))
2208 /* Start outputting a function. */
2211 stab_start_function (p
, name
, globalp
)
2216 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2217 char *rettype
, *buf
;
2219 assert (info
->nesting
== 0 && info
->fun_offset
== -1);
2221 rettype
= stab_pop_type (info
);
2223 buf
= (char *) xmalloc (strlen (name
) + strlen (rettype
) + 3);
2224 sprintf (buf
, "%s:%c%s", name
,
2225 globalp
? 'F' : 'f',
2228 /* We don't know the value now, so we set it in start_block. */
2229 info
->fun_offset
= info
->symbols_size
;
2231 if (! stab_write_symbol (info
, N_FUN
, 0, 0, buf
))
2239 /* Output a function parameter. */
2242 stab_function_parameter (p
, name
, kind
, val
)
2245 enum debug_parm_kind kind
;
2248 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2253 s
= stab_pop_type (info
);
2260 case DEBUG_PARM_STACK
:
2265 case DEBUG_PARM_REG
:
2270 case DEBUG_PARM_REFERENCE
:
2275 case DEBUG_PARM_REF_REG
:
2281 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 3);
2282 sprintf (buf
, "%s:%c%s", name
, kindc
, s
);
2285 if (! stab_write_symbol (info
, stab_type
, 0, val
, buf
))
2293 /* Start a block. */
2296 stab_start_block (p
, addr
)
2300 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2302 /* Fill in any slots which have been waiting for the first known
2305 if (info
->so_offset
!= -1)
2307 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->so_offset
+ 8);
2308 info
->so_offset
= -1;
2311 if (info
->fun_offset
!= -1)
2313 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->fun_offset
+ 8);
2314 info
->fun_offset
= -1;
2319 /* We will be called with a top level block surrounding the
2320 function, but stabs information does not output that block, so we
2323 if (info
->nesting
== 1)
2325 info
->fnaddr
= addr
;
2329 /* We have to output the LBRAC symbol after any variables which are
2330 declared inside the block. We postpone the LBRAC until the next
2331 start_block or end_block. */
2333 /* If we have postponed an LBRAC, output it now. */
2334 if (info
->pending_lbrac
!= (bfd_vma
) -1)
2336 if (! stab_write_symbol (info
, N_LBRAC
, 0, info
->pending_lbrac
,
2337 (const char *) NULL
))
2341 /* Remember the address and output it later. */
2343 info
->pending_lbrac
= addr
- info
->fnaddr
;
2351 stab_end_block (p
, addr
)
2355 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2357 if (addr
> info
->last_text_address
)
2358 info
->last_text_address
= addr
;
2360 /* If we have postponed an LBRAC, output it now. */
2361 if (info
->pending_lbrac
!= (bfd_vma
) -1)
2363 if (! stab_write_symbol (info
, N_LBRAC
, 0, info
->pending_lbrac
,
2364 (const char *) NULL
))
2366 info
->pending_lbrac
= (bfd_vma
) -1;
2369 assert (info
->nesting
> 0);
2373 /* We ignore the outermost block. */
2374 if (info
->nesting
== 0)
2377 return stab_write_symbol (info
, N_RBRAC
, 0, addr
- info
->fnaddr
,
2378 (const char *) NULL
);
2381 /* End a function. */
2385 stab_end_function (p
)
2386 PTR p ATTRIBUTE_UNUSED
;
2391 /* Output a line number. */
2394 stab_lineno (p
, file
, lineno
, addr
)
2397 unsigned long lineno
;
2400 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2402 assert (info
->lineno_filename
!= NULL
);
2404 if (addr
> info
->last_text_address
)
2405 info
->last_text_address
= addr
;
2407 if (strcmp (file
, info
->lineno_filename
) != 0)
2409 if (! stab_write_symbol (info
, N_SOL
, 0, addr
, file
))
2411 info
->lineno_filename
= file
;
2414 return stab_write_symbol (info
, N_SLINE
, lineno
, addr
- info
->fnaddr
,
2415 (const char *) NULL
);