1 /* wrstabs.c -- Output stabs debugging information
2 Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 /* This file contains code which writes out stabs debugging
31 #include "libiberty.h"
32 #include "safe-ctype.h"
35 #include "aout/aout64.h"
36 #include "aout/stab_gnu.h"
38 /* The size of a stabs symbol. This presumes 32 bit values. */
40 #define STAB_SYMBOL_SIZE (12)
42 /* An entry in a string hash table. */
44 struct string_hash_entry
46 struct bfd_hash_entry root
;
47 /* Next string in this table. */
48 struct string_hash_entry
*next
;
49 /* Index in string table. */
51 /* Size of type if this is a typedef. */
55 /* A string hash table. */
57 struct string_hash_table
59 struct bfd_hash_table table
;
62 /* The type stack. Each element on the stack is a string. */
64 struct stab_type_stack
66 /* The next element on the stack. */
67 struct stab_type_stack
*next
;
68 /* This element as a string. */
70 /* The type index of this element. */
72 /* The size of the type. */
74 /* Whether type string defines a new type. */
75 bfd_boolean definition
;
76 /* String defining struct fields. */
78 /* NULL terminated array of strings defining base classes for a
81 /* String defining class methods. */
83 /* String defining vtable pointer for a class. */
87 /* This structure is used to keep track of type indices for tagged
96 /* The kind of type. This is set to DEBUG_KIND_ILLEGAL when the
98 enum debug_type_kind kind
;
99 /* The size of the struct. */
103 /* We remember various sorts of type indices. They are not related,
104 but, for convenience, we keep all the information in this
107 struct stab_type_cache
109 /* The void type index. */
111 /* Signed integer type indices, indexed by size - 1. */
112 long signed_integer_types
[8];
113 /* Unsigned integer type indices, indexed by size - 1. */
114 long unsigned_integer_types
[8];
115 /* Floating point types, indexed by size - 1. */
116 long float_types
[16];
117 /* Pointers to types, indexed by the type index. */
119 size_t pointer_types_alloc
;
120 /* Functions returning types, indexed by the type index. */
121 long *function_types
;
122 size_t function_types_alloc
;
123 /* References to types, indexed by the type index. */
124 long *reference_types
;
125 size_t reference_types_alloc
;
126 /* Struct/union/class type indices, indexed by the struct id. */
127 struct stab_tag
*struct_types
;
128 size_t struct_types_alloc
;
131 /* This is the handle passed through debug_write. */
133 struct stab_write_handle
137 /* This buffer holds the symbols. */
140 size_t symbols_alloc
;
141 /* This is a list of hash table entries for the strings. */
142 struct string_hash_entry
*strings
;
143 /* The last string hash table entry. */
144 struct string_hash_entry
*last_string
;
145 /* The size of the strings. */
147 /* This hash table eliminates duplicate strings. */
148 struct string_hash_table strhash
;
149 /* The type stack. */
150 struct stab_type_stack
*type_stack
;
151 /* The next type index. */
153 /* The type cache. */
154 struct stab_type_cache type_cache
;
155 /* A mapping from typedef names to type indices. */
156 struct string_hash_table typedef_hash
;
157 /* If this is not -1, it is the offset to the most recent N_SO
158 symbol, and the value of that symbol needs to be set. */
160 /* If this is not -1, it is the offset to the most recent N_FUN
161 symbol, and the value of that symbol needs to be set. */
163 /* The last text section address seen. */
164 bfd_vma last_text_address
;
165 /* The block nesting depth. */
166 unsigned int nesting
;
167 /* The function address. */
169 /* A pending LBRAC symbol. */
170 bfd_vma pending_lbrac
;
171 /* The current line number file name. */
172 const char *lineno_filename
;
175 static struct bfd_hash_entry
*string_hash_newfunc
176 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
177 static bfd_boolean stab_write_symbol
178 PARAMS ((struct stab_write_handle
*, int, int, bfd_vma
, const char *));
179 static bfd_boolean stab_push_string
180 PARAMS ((struct stab_write_handle
*, const char *, long, bfd_boolean
,
182 static bfd_boolean stab_push_defined_type
183 PARAMS ((struct stab_write_handle
*, long, unsigned int));
184 static char *stab_pop_type
185 PARAMS ((struct stab_write_handle
*));
186 static bfd_boolean stab_modify_type
187 PARAMS ((struct stab_write_handle
*, int, unsigned int, long **, size_t *));
188 static long stab_get_struct_index
189 PARAMS ((struct stab_write_handle
*, const char *, unsigned int,
190 enum debug_type_kind
, unsigned int *));
191 static bfd_boolean stab_class_method_var
192 PARAMS ((struct stab_write_handle
*, const char *, enum debug_visibility
,
193 bfd_boolean
, bfd_boolean
, bfd_boolean
, bfd_vma
, bfd_boolean
));
194 static bfd_boolean stab_start_compilation_unit
195 PARAMS ((PTR
, const char *));
196 static bfd_boolean stab_start_source
197 PARAMS ((PTR
, const char *));
198 static bfd_boolean stab_empty_type
200 static bfd_boolean stab_void_type
202 static bfd_boolean stab_int_type
203 PARAMS ((PTR
, unsigned int, bfd_boolean
));
204 static bfd_boolean stab_float_type
205 PARAMS ((PTR
, unsigned int));
206 static bfd_boolean stab_complex_type
207 PARAMS ((PTR
, unsigned int));
208 static bfd_boolean stab_bool_type
209 PARAMS ((PTR
, unsigned int));
210 static bfd_boolean stab_enum_type
211 PARAMS ((PTR
, const char *, const char **, bfd_signed_vma
*));
212 static bfd_boolean stab_pointer_type
214 static bfd_boolean stab_function_type
215 PARAMS ((PTR
, int, bfd_boolean
));
216 static bfd_boolean stab_reference_type
218 static bfd_boolean stab_range_type
219 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
));
220 static bfd_boolean stab_array_type
221 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
, bfd_boolean
));
222 static bfd_boolean stab_set_type
223 PARAMS ((PTR
, bfd_boolean
));
224 static bfd_boolean stab_offset_type
226 static bfd_boolean stab_method_type
227 PARAMS ((PTR
, bfd_boolean
, int, bfd_boolean
));
228 static bfd_boolean stab_const_type
230 static bfd_boolean stab_volatile_type
232 static bfd_boolean stab_start_struct_type
233 PARAMS ((PTR
, const char *, unsigned int, bfd_boolean
, unsigned int));
234 static bfd_boolean stab_struct_field
235 PARAMS ((PTR
, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
));
236 static bfd_boolean stab_end_struct_type
238 static bfd_boolean stab_start_class_type
239 PARAMS ((PTR
, const char *, unsigned int, bfd_boolean
, unsigned int,
240 bfd_boolean
, bfd_boolean
));
241 static bfd_boolean stab_class_static_member
242 PARAMS ((PTR
, const char *, const char *, enum debug_visibility
));
243 static bfd_boolean stab_class_baseclass
244 PARAMS ((PTR
, bfd_vma
, bfd_boolean
, enum debug_visibility
));
245 static bfd_boolean stab_class_start_method
246 PARAMS ((PTR
, const char *));
247 static bfd_boolean stab_class_method_variant
248 PARAMS ((PTR
, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
,
249 bfd_vma
, bfd_boolean
));
250 static bfd_boolean stab_class_static_method_variant
251 PARAMS ((PTR
, const char *, enum debug_visibility
, bfd_boolean
,
253 static bfd_boolean stab_class_end_method
255 static bfd_boolean stab_end_class_type
257 static bfd_boolean stab_typedef_type
258 PARAMS ((PTR
, const char *));
259 static bfd_boolean stab_tag_type
260 PARAMS ((PTR
, const char *, unsigned int, enum debug_type_kind
));
261 static bfd_boolean stab_typdef
262 PARAMS ((PTR
, const char *));
263 static bfd_boolean stab_tag
264 PARAMS ((PTR
, const char *));
265 static bfd_boolean stab_int_constant
266 PARAMS ((PTR
, const char *, bfd_vma
));
267 static bfd_boolean stab_float_constant
268 PARAMS ((PTR
, const char *, double));
269 static bfd_boolean stab_typed_constant
270 PARAMS ((PTR
, const char *, bfd_vma
));
271 static bfd_boolean stab_variable
272 PARAMS ((PTR
, const char *, enum debug_var_kind
, bfd_vma
));
273 static bfd_boolean stab_start_function
274 PARAMS ((PTR
, const char *, bfd_boolean
));
275 static bfd_boolean stab_function_parameter
276 PARAMS ((PTR
, const char *, enum debug_parm_kind
, bfd_vma
));
277 static bfd_boolean stab_start_block
278 PARAMS ((PTR
, bfd_vma
));
279 static bfd_boolean stab_end_block
280 PARAMS ((PTR
, bfd_vma
));
281 static bfd_boolean stab_end_function
283 static bfd_boolean stab_lineno
284 PARAMS ((PTR
, const char *, unsigned long, bfd_vma
));
286 static const struct debug_write_fns stab_fns
=
288 stab_start_compilation_unit
,
307 stab_start_struct_type
,
309 stab_end_struct_type
,
310 stab_start_class_type
,
311 stab_class_static_member
,
312 stab_class_baseclass
,
313 stab_class_start_method
,
314 stab_class_method_variant
,
315 stab_class_static_method_variant
,
316 stab_class_end_method
,
327 stab_function_parameter
,
334 /* Routine to create an entry in a string hash table. */
336 static struct bfd_hash_entry
*
337 string_hash_newfunc (entry
, table
, string
)
338 struct bfd_hash_entry
*entry
;
339 struct bfd_hash_table
*table
;
342 struct string_hash_entry
*ret
= (struct string_hash_entry
*) entry
;
344 /* Allocate the structure if it has not already been allocated by a
346 if (ret
== (struct string_hash_entry
*) NULL
)
347 ret
= ((struct string_hash_entry
*)
348 bfd_hash_allocate (table
, sizeof (struct string_hash_entry
)));
349 if (ret
== (struct string_hash_entry
*) NULL
)
352 /* Call the allocation method of the superclass. */
353 ret
= ((struct string_hash_entry
*)
354 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
358 /* Initialize the local fields. */
364 return (struct bfd_hash_entry
*) ret
;
367 /* Look up an entry in a string hash table. */
369 #define string_hash_lookup(t, string, create, copy) \
370 ((struct string_hash_entry *) \
371 bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
373 /* Add a symbol to the stabs debugging information we are building. */
376 stab_write_symbol (info
, type
, desc
, value
, string
)
377 struct stab_write_handle
*info
;
384 bfd_byte sym
[STAB_SYMBOL_SIZE
];
390 struct string_hash_entry
*h
;
392 h
= string_hash_lookup (&info
->strhash
, string
, TRUE
, TRUE
);
395 non_fatal (_("string_hash_lookup failed: %s"),
396 bfd_errmsg (bfd_get_error ()));
403 strx
= info
->strings_size
;
405 if (info
->last_string
== NULL
)
408 info
->last_string
->next
= h
;
409 info
->last_string
= h
;
410 info
->strings_size
+= strlen (string
) + 1;
414 /* This presumes 32 bit values. */
415 bfd_put_32 (info
->abfd
, strx
, sym
);
416 bfd_put_8 (info
->abfd
, type
, sym
+ 4);
417 bfd_put_8 (info
->abfd
, 0, sym
+ 5);
418 bfd_put_16 (info
->abfd
, desc
, sym
+ 6);
419 bfd_put_32 (info
->abfd
, value
, sym
+ 8);
421 if (info
->symbols_size
+ STAB_SYMBOL_SIZE
> info
->symbols_alloc
)
423 info
->symbols_alloc
*= 2;
424 info
->symbols
= (bfd_byte
*) xrealloc (info
->symbols
,
425 info
->symbols_alloc
);
428 memcpy (info
->symbols
+ info
->symbols_size
, sym
, STAB_SYMBOL_SIZE
);
430 info
->symbols_size
+= STAB_SYMBOL_SIZE
;
435 /* Push a string on to the type stack. */
438 stab_push_string (info
, string
, index
, definition
, size
)
439 struct stab_write_handle
*info
;
442 bfd_boolean definition
;
445 struct stab_type_stack
*s
;
447 s
= (struct stab_type_stack
*) xmalloc (sizeof *s
);
448 s
->string
= xstrdup (string
);
450 s
->definition
= definition
;
454 s
->baseclasses
= NULL
;
458 s
->next
= info
->type_stack
;
459 info
->type_stack
= s
;
464 /* Push a type index which has already been defined. */
467 stab_push_defined_type (info
, index
, size
)
468 struct stab_write_handle
*info
;
474 sprintf (buf
, "%ld", index
);
475 return stab_push_string (info
, buf
, index
, FALSE
, size
);
478 /* Pop a type off the type stack. The caller is responsible for
479 freeing the string. */
483 struct stab_write_handle
*info
;
485 struct stab_type_stack
*s
;
488 s
= info
->type_stack
;
491 info
->type_stack
= s
->next
;
500 /* The general routine to write out stabs in sections debugging
501 information. This accumulates the stabs symbols and the strings in
502 two obstacks. We can't easily write out the information as we go
503 along, because we need to know the section sizes before we can
504 write out the section contents. ABFD is the BFD and DHANDLE is the
505 handle for the debugging information. This sets *PSYMS to point to
506 the symbols, *PSYMSIZE the size of the symbols, *PSTRINGS to the
507 strings, and *PSTRINGSIZE to the size of the strings. */
510 write_stabs_in_sections_debugging_info (abfd
, dhandle
, psyms
, psymsize
,
511 pstrings
, pstringsize
)
515 bfd_size_type
*psymsize
;
517 bfd_size_type
*pstringsize
;
519 struct stab_write_handle info
;
520 struct string_hash_entry
*h
;
525 info
.symbols_size
= 0;
526 info
.symbols_alloc
= 500;
527 info
.symbols
= (bfd_byte
*) xmalloc (info
.symbols_alloc
);
530 info
.last_string
= NULL
;
531 /* Reserve 1 byte for a null byte. */
532 info
.strings_size
= 1;
534 if (! bfd_hash_table_init (&info
.strhash
.table
, string_hash_newfunc
)
535 || ! bfd_hash_table_init (&info
.typedef_hash
.table
, string_hash_newfunc
))
537 non_fatal ("bfd_hash_table_init_failed: %s",
538 bfd_errmsg (bfd_get_error ()));
542 info
.type_stack
= NULL
;
544 memset (&info
.type_cache
, 0, sizeof info
.type_cache
);
546 info
.fun_offset
= -1;
547 info
.last_text_address
= 0;
550 info
.pending_lbrac
= (bfd_vma
) -1;
552 /* The initial symbol holds the string size. */
553 if (! stab_write_symbol (&info
, 0, 0, 0, (const char *) NULL
))
556 /* Output an initial N_SO symbol. */
557 info
.so_offset
= info
.symbols_size
;
558 if (! stab_write_symbol (&info
, N_SO
, 0, 0, bfd_get_filename (abfd
)))
561 if (! debug_write (dhandle
, &stab_fns
, (PTR
) &info
))
564 assert (info
.pending_lbrac
== (bfd_vma
) -1);
566 /* Output a trailing N_SO. */
567 if (! stab_write_symbol (&info
, N_SO
, 0, info
.last_text_address
,
568 (const char *) NULL
))
571 /* Put the string size in the initial symbol. */
572 bfd_put_32 (abfd
, info
.strings_size
, info
.symbols
+ 8);
574 *psyms
= info
.symbols
;
575 *psymsize
= info
.symbols_size
;
577 *pstringsize
= info
.strings_size
;
578 *pstrings
= (bfd_byte
*) xmalloc (info
.strings_size
);
582 for (h
= info
.strings
; h
!= NULL
; h
= h
->next
)
584 strcpy ((char *) p
, h
->root
.string
);
585 p
+= strlen ((char *) p
) + 1;
591 /* Start writing out information for a compilation unit. */
594 stab_start_compilation_unit (p
, filename
)
596 const char *filename
;
598 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
600 /* We would normally output an N_SO symbol here. However, that
601 would force us to reset all of our type information. I think we
602 will be better off just outputting an N_SOL symbol, and not
603 worrying about splitting information between files. */
605 info
->lineno_filename
= filename
;
607 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
610 /* Start writing out information for a particular source file. */
613 stab_start_source (p
, filename
)
615 const char *filename
;
617 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
619 /* FIXME: The symbol's value is supposed to be the text section
620 address. However, we would have to fill it in later, and gdb
621 doesn't care, so we don't bother with it. */
623 info
->lineno_filename
= filename
;
625 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
628 /* Push an empty type. This shouldn't normally happen. We just use a
635 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
637 /* We don't call stab_void_type if the type is not yet defined,
638 because that might screw up the typedef. */
640 if (info
->type_cache
.void_type
!= 0)
641 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
647 index
= info
->type_index
;
650 sprintf (buf
, "%ld=%ld", index
, index
);
652 return stab_push_string (info
, buf
, index
, FALSE
, 0);
656 /* Push a void type. */
662 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
664 if (info
->type_cache
.void_type
!= 0)
665 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
671 index
= info
->type_index
;
674 info
->type_cache
.void_type
= index
;
676 sprintf (buf
, "%ld=%ld", index
, index
);
678 return stab_push_string (info
, buf
, index
, TRUE
, 0);
682 /* Push an integer type. */
685 stab_int_type (p
, size
, unsignedp
)
688 bfd_boolean unsignedp
;
690 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
693 if (size
<= 0 || (size
> sizeof (long) && size
!= 8))
695 non_fatal (_("stab_int_type: bad size %u"), size
);
700 cache
= info
->type_cache
.signed_integer_types
;
702 cache
= info
->type_cache
.unsigned_integer_types
;
704 if (cache
[size
- 1] != 0)
705 return stab_push_defined_type (info
, cache
[size
- 1], size
);
711 index
= info
->type_index
;
714 cache
[size
- 1] = index
;
716 sprintf (buf
, "%ld=r%ld;", index
, index
);
720 if (size
< sizeof (long))
721 sprintf (buf
+ strlen (buf
), "%ld;", ((long) 1 << (size
* 8)) - 1);
722 else if (size
== sizeof (long))
725 strcat (buf
, "01777777777777777777777;");
731 if (size
<= sizeof (long))
732 sprintf (buf
+ strlen (buf
), "%ld;%ld;",
733 (long) - ((unsigned long) 1 << (size
* 8 - 1)),
734 (long) (((unsigned long) 1 << (size
* 8 - 1)) - 1));
736 strcat (buf
, "01000000000000000000000;0777777777777777777777;");
741 return stab_push_string (info
, buf
, index
, TRUE
, size
);
745 /* Push a floating point type. */
748 stab_float_type (p
, size
)
752 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
755 && size
- 1 < (sizeof info
->type_cache
.float_types
756 / sizeof info
->type_cache
.float_types
[0])
757 && info
->type_cache
.float_types
[size
- 1] != 0)
758 return stab_push_defined_type (info
,
759 info
->type_cache
.float_types
[size
- 1],
767 /* Floats are defined as a subrange of int. */
768 if (! stab_int_type (info
, 4, FALSE
))
770 int_type
= stab_pop_type (info
);
772 index
= info
->type_index
;
776 && size
- 1 < (sizeof info
->type_cache
.float_types
777 / sizeof info
->type_cache
.float_types
[0]))
778 info
->type_cache
.float_types
[size
- 1] = index
;
780 sprintf (buf
, "%ld=r%s;%u;0;", index
, int_type
, size
);
784 return stab_push_string (info
, buf
, index
, TRUE
, size
);
788 /* Push a complex type. */
791 stab_complex_type (p
, size
)
795 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
799 index
= info
->type_index
;
802 sprintf (buf
, "%ld=r%ld;%u;0;", index
, index
, size
);
804 return stab_push_string (info
, buf
, index
, TRUE
, size
* 2);
807 /* Push a bfd_boolean type. We use an XCOFF predefined type, since gdb
808 always recognizes them. */
811 stab_bool_type (p
, size
)
815 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
838 return stab_push_defined_type (info
, index
, size
);
841 /* Push an enum type. */
844 stab_enum_type (p
, tag
, names
, vals
)
848 bfd_signed_vma
*vals
;
850 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
859 assert (tag
!= NULL
);
861 buf
= (char *) xmalloc (10 + strlen (tag
));
862 sprintf (buf
, "xe%s:", tag
);
863 /* FIXME: The size is just a guess. */
864 if (! stab_push_string (info
, buf
, 0, FALSE
, 4))
873 for (pn
= names
; *pn
!= NULL
; pn
++)
874 len
+= strlen (*pn
) + 20;
876 buf
= (char *) xmalloc (len
);
882 index
= info
->type_index
;
884 sprintf (buf
, "%s:T%ld=e", tag
, index
);
887 for (pn
= names
, pv
= vals
; *pn
!= NULL
; pn
++, pv
++)
888 sprintf (buf
+ strlen (buf
), "%s:%ld,", *pn
, (long) *pv
);
893 /* FIXME: The size is just a guess. */
894 if (! stab_push_string (info
, buf
, 0, FALSE
, 4))
899 /* FIXME: The size is just a guess. */
900 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
)
901 || ! stab_push_defined_type (info
, index
, 4))
910 /* Push a modification of the top type on the stack. Cache the
911 results in CACHE and CACHE_ALLOC. */
914 stab_modify_type (info
, mod
, size
, cache
, cache_alloc
)
915 struct stab_write_handle
*info
;
925 assert (info
->type_stack
!= NULL
);
926 targindex
= info
->type_stack
->index
;
931 bfd_boolean definition
;
933 /* Either the target type has no index, or we aren't caching
934 this modifier. Either way we have no way of recording the
935 new type, so we don't bother to define one. */
936 definition
= info
->type_stack
->definition
;
937 s
= stab_pop_type (info
);
938 buf
= (char *) xmalloc (strlen (s
) + 2);
939 sprintf (buf
, "%c%s", mod
, s
);
941 if (! stab_push_string (info
, buf
, 0, definition
, size
))
947 if ((size_t) targindex
>= *cache_alloc
)
951 alloc
= *cache_alloc
;
954 while ((size_t) targindex
>= alloc
)
956 *cache
= (long *) xrealloc (*cache
, alloc
* sizeof (long));
957 memset (*cache
+ *cache_alloc
, 0,
958 (alloc
- *cache_alloc
) * sizeof (long));
959 *cache_alloc
= alloc
;
962 index
= (*cache
)[targindex
];
963 if (index
!= 0 && ! info
->type_stack
->definition
)
965 /* We have already defined a modification of this type, and
966 the entry on the type stack is not a definition, so we
967 can safely discard it (we may have a definition on the
968 stack, even if we already defined a modification, if it
969 is a struct which we did not define at the time it was
971 free (stab_pop_type (info
));
972 if (! stab_push_defined_type (info
, index
, size
))
977 index
= info
->type_index
;
980 s
= stab_pop_type (info
);
981 buf
= (char *) xmalloc (strlen (s
) + 20);
982 sprintf (buf
, "%ld=%c%s", index
, mod
, s
);
985 (*cache
)[targindex
] = index
;
987 if (! stab_push_string (info
, buf
, index
, TRUE
, size
))
997 /* Push a pointer type. */
1000 stab_pointer_type (p
)
1003 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1005 /* FIXME: The size should depend upon the architecture. */
1006 return stab_modify_type (info
, '*', 4, &info
->type_cache
.pointer_types
,
1007 &info
->type_cache
.pointer_types_alloc
);
1010 /* Push a function type. */
1013 stab_function_type (p
, argcount
, varargs
)
1016 bfd_boolean varargs ATTRIBUTE_UNUSED
;
1018 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1021 /* We have no way to represent the argument types, so we just
1022 discard them. However, if they define new types, we must output
1023 them. We do this by producing empty typedefs. */
1024 for (i
= 0; i
< argcount
; i
++)
1026 if (! info
->type_stack
->definition
)
1027 free (stab_pop_type (info
));
1032 s
= stab_pop_type (info
);
1034 buf
= (char *) xmalloc (strlen (s
) + 3);
1035 sprintf (buf
, ":t%s", s
);
1038 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
1045 return stab_modify_type (info
, 'f', 0, &info
->type_cache
.function_types
,
1046 &info
->type_cache
.function_types_alloc
);
1049 /* Push a reference type. */
1052 stab_reference_type (p
)
1055 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1057 /* FIXME: The size should depend upon the architecture. */
1058 return stab_modify_type (info
, '&', 4, &info
->type_cache
.reference_types
,
1059 &info
->type_cache
.reference_types_alloc
);
1062 /* Push a range type. */
1065 stab_range_type (p
, low
, high
)
1068 bfd_signed_vma high
;
1070 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1071 bfd_boolean definition
;
1075 definition
= info
->type_stack
->definition
;
1076 size
= info
->type_stack
->size
;
1078 s
= stab_pop_type (info
);
1079 buf
= (char *) xmalloc (strlen (s
) + 100);
1080 sprintf (buf
, "r%s;%ld;%ld;", s
, (long) low
, (long) high
);
1083 if (! stab_push_string (info
, buf
, 0, definition
, size
))
1091 /* Push an array type. */
1094 stab_array_type (p
, low
, high
, stringp
)
1097 bfd_signed_vma high
;
1098 bfd_boolean stringp
;
1100 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1101 bfd_boolean definition
;
1102 unsigned int element_size
;
1103 char *range
, *element
, *buf
;
1107 definition
= info
->type_stack
->definition
;
1108 range
= stab_pop_type (info
);
1110 definition
= definition
|| info
->type_stack
->definition
;
1111 element_size
= info
->type_stack
->size
;
1112 element
= stab_pop_type (info
);
1114 buf
= (char *) xmalloc (strlen (range
) + strlen (element
) + 100);
1123 /* We need to define a type in order to include the string
1125 index
= info
->type_index
;
1128 sprintf (buf
, "%ld=@S;", index
);
1131 sprintf (buf
+ strlen (buf
), "ar%s;%ld;%ld;%s",
1132 range
, (long) low
, (long) high
, element
);
1139 size
= element_size
* ((high
- low
) + 1);
1140 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1148 /* Push a set type. */
1151 stab_set_type (p
, bitstringp
)
1153 bfd_boolean bitstringp
;
1155 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1156 bfd_boolean definition
;
1160 definition
= info
->type_stack
->definition
;
1162 s
= stab_pop_type (info
);
1163 buf
= (char *) xmalloc (strlen (s
) + 30);
1172 /* We need to define a type in order to include the string
1174 index
= info
->type_index
;
1177 sprintf (buf
, "%ld=@S;", index
);
1180 sprintf (buf
+ strlen (buf
), "S%s", s
);
1183 if (! stab_push_string (info
, buf
, index
, definition
, 0))
1191 /* Push an offset type. */
1194 stab_offset_type (p
)
1197 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1198 bfd_boolean definition
;
1199 char *target
, *base
, *buf
;
1201 definition
= info
->type_stack
->definition
;
1202 target
= stab_pop_type (info
);
1204 definition
= definition
|| info
->type_stack
->definition
;
1205 base
= stab_pop_type (info
);
1207 buf
= (char *) xmalloc (strlen (target
) + strlen (base
) + 3);
1208 sprintf (buf
, "@%s,%s", base
, target
);
1212 if (! stab_push_string (info
, buf
, 0, definition
, 0))
1220 /* Push a method type. */
1223 stab_method_type (p
, domainp
, argcount
, varargs
)
1225 bfd_boolean domainp
;
1227 bfd_boolean varargs
;
1229 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1230 bfd_boolean definition
;
1231 char *domain
, *return_type
, *buf
;
1236 /* We don't bother with stub method types, because that would
1237 require a mangler for C++ argument types. This will waste space
1238 in the debugging output. */
1240 /* We need a domain. I'm not sure DOMAINP can ever be false,
1244 if (! stab_empty_type (p
))
1248 definition
= info
->type_stack
->definition
;
1249 domain
= stab_pop_type (info
);
1251 /* A non-varargs function is indicated by making the last parameter
1259 else if (argcount
== 0)
1265 args
= (char **) xmalloc (1 * sizeof (*args
));
1266 if (! stab_empty_type (p
))
1268 definition
= definition
|| info
->type_stack
->definition
;
1269 args
[0] = stab_pop_type (info
);
1275 args
= (char **) xmalloc ((argcount
+ 1) * sizeof (*args
));
1276 for (i
= argcount
- 1; i
>= 0; i
--)
1278 definition
= definition
|| info
->type_stack
->definition
;
1279 args
[i
] = stab_pop_type (info
);
1283 if (! stab_empty_type (p
))
1285 definition
= definition
|| info
->type_stack
->definition
;
1286 args
[argcount
] = stab_pop_type (info
);
1291 definition
= definition
|| info
->type_stack
->definition
;
1292 return_type
= stab_pop_type (info
);
1294 len
= strlen (domain
) + strlen (return_type
) + 10;
1295 for (i
= 0; i
< argcount
; i
++)
1296 len
+= strlen (args
[i
]);
1298 buf
= (char *) xmalloc (len
);
1300 sprintf (buf
, "#%s,%s", domain
, return_type
);
1303 for (i
= 0; i
< argcount
; i
++)
1306 strcat (buf
, args
[i
]);
1314 if (! stab_push_string (info
, buf
, 0, definition
, 0))
1322 /* Push a const version of a type. */
1328 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1330 return stab_modify_type (info
, 'k', info
->type_stack
->size
,
1331 (long **) NULL
, (size_t *) NULL
);
1334 /* Push a volatile version of a type. */
1337 stab_volatile_type (p
)
1340 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1342 return stab_modify_type (info
, 'B', info
->type_stack
->size
,
1343 (long **) NULL
, (size_t *) NULL
);
1346 /* Get the type index to use for a struct/union/class ID. This should
1347 return -1 if it fails. */
1350 stab_get_struct_index (info
, tag
, id
, kind
, psize
)
1351 struct stab_write_handle
*info
;
1354 enum debug_type_kind kind
;
1355 unsigned int *psize
;
1357 if (id
>= info
->type_cache
.struct_types_alloc
)
1361 alloc
= info
->type_cache
.struct_types_alloc
;
1366 info
->type_cache
.struct_types
=
1367 (struct stab_tag
*) xrealloc (info
->type_cache
.struct_types
,
1368 alloc
* sizeof (struct stab_tag
));
1369 memset ((info
->type_cache
.struct_types
1370 + info
->type_cache
.struct_types_alloc
),
1372 ((alloc
- info
->type_cache
.struct_types_alloc
)
1373 * sizeof (struct stab_tag
)));
1374 info
->type_cache
.struct_types_alloc
= alloc
;
1377 if (info
->type_cache
.struct_types
[id
].index
== 0)
1379 info
->type_cache
.struct_types
[id
].index
= info
->type_index
;
1381 info
->type_cache
.struct_types
[id
].tag
= tag
;
1382 info
->type_cache
.struct_types
[id
].kind
= kind
;
1385 if (kind
== DEBUG_KIND_ILLEGAL
)
1387 /* This is a definition of the struct. */
1388 info
->type_cache
.struct_types
[id
].kind
= kind
;
1389 info
->type_cache
.struct_types
[id
].size
= *psize
;
1392 *psize
= info
->type_cache
.struct_types
[id
].size
;
1394 return info
->type_cache
.struct_types
[id
].index
;
1397 /* Start outputting a struct. We ignore the tag, and handle it in
1401 stab_start_struct_type (p
, tag
, id
, structp
, size
)
1405 bfd_boolean structp
;
1408 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1410 bfd_boolean definition
;
1413 buf
= (char *) xmalloc (40);
1423 index
= stab_get_struct_index (info
, tag
, id
, DEBUG_KIND_ILLEGAL
,
1427 sprintf (buf
, "%ld=", index
);
1431 sprintf (buf
+ strlen (buf
), "%c%u",
1432 structp
? 's' : 'u',
1435 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1438 info
->type_stack
->fields
= (char *) xmalloc (1);
1439 info
->type_stack
->fields
[0] = '\0';
1444 /* Add a field to a struct. */
1447 stab_struct_field (p
, name
, bitpos
, bitsize
, visibility
)
1452 enum debug_visibility visibility
;
1454 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1455 bfd_boolean definition
;
1460 definition
= info
->type_stack
->definition
;
1461 size
= info
->type_stack
->size
;
1462 s
= stab_pop_type (info
);
1464 /* Add this field to the end of the current struct fields, which is
1465 currently on the top of the stack. */
1467 assert (info
->type_stack
->fields
!= NULL
);
1468 n
= (char *) xmalloc (strlen (info
->type_stack
->fields
)
1478 case DEBUG_VISIBILITY_PUBLIC
:
1482 case DEBUG_VISIBILITY_PRIVATE
:
1486 case DEBUG_VISIBILITY_PROTECTED
:
1495 non_fatal (_("%s: warning: unknown size for field `%s' in struct"),
1496 bfd_get_filename (info
->abfd
), name
);
1499 sprintf (n
, "%s%s:%s%s,%ld,%ld;", info
->type_stack
->fields
, name
, vis
, s
,
1500 (long) bitpos
, (long) bitsize
);
1502 free (info
->type_stack
->fields
);
1503 info
->type_stack
->fields
= n
;
1506 info
->type_stack
->definition
= TRUE
;
1511 /* Finish up a struct. */
1514 stab_end_struct_type (p
)
1517 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1518 bfd_boolean definition
;
1521 char *fields
, *first
, *buf
;
1523 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1525 definition
= info
->type_stack
->definition
;
1526 index
= info
->type_stack
->index
;
1527 size
= info
->type_stack
->size
;
1528 fields
= info
->type_stack
->fields
;
1529 first
= stab_pop_type (info
);
1531 buf
= (char *) xmalloc (strlen (first
) + strlen (fields
) + 2);
1532 sprintf (buf
, "%s%s;", first
, fields
);
1536 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1544 /* Start outputting a class. */
1547 stab_start_class_type (p
, tag
, id
, structp
, size
, vptr
, ownvptr
)
1551 bfd_boolean structp
;
1554 bfd_boolean ownvptr
;
1556 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1557 bfd_boolean definition
;
1560 if (! vptr
|| ownvptr
)
1567 definition
= info
->type_stack
->definition
;
1568 vstring
= stab_pop_type (info
);
1571 if (! stab_start_struct_type (p
, tag
, id
, structp
, size
))
1580 assert (info
->type_stack
->index
> 0);
1581 vtable
= (char *) xmalloc (20);
1582 sprintf (vtable
, "~%%%ld", info
->type_stack
->index
);
1586 vtable
= (char *) xmalloc (strlen (vstring
) + 3);
1587 sprintf (vtable
, "~%%%s", vstring
);
1591 info
->type_stack
->vtable
= vtable
;
1595 info
->type_stack
->definition
= TRUE
;
1600 /* Add a static member to the class on the type stack. */
1603 stab_class_static_member (p
, name
, physname
, visibility
)
1606 const char *physname
;
1607 enum debug_visibility visibility
;
1609 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1610 bfd_boolean definition
;
1614 definition
= info
->type_stack
->definition
;
1615 s
= stab_pop_type (info
);
1617 /* Add this field to the end of the current struct fields, which is
1618 currently on the top of the stack. */
1620 assert (info
->type_stack
->fields
!= NULL
);
1621 n
= (char *) xmalloc (strlen (info
->type_stack
->fields
)
1632 case DEBUG_VISIBILITY_PUBLIC
:
1636 case DEBUG_VISIBILITY_PRIVATE
:
1640 case DEBUG_VISIBILITY_PROTECTED
:
1645 sprintf (n
, "%s%s:%s%s:%s;", info
->type_stack
->fields
, name
, vis
, s
,
1648 free (info
->type_stack
->fields
);
1649 info
->type_stack
->fields
= n
;
1652 info
->type_stack
->definition
= TRUE
;
1657 /* Add a base class to the class on the type stack. */
1660 stab_class_baseclass (p
, bitpos
, virtual, visibility
)
1663 bfd_boolean
virtual;
1664 enum debug_visibility visibility
;
1666 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1667 bfd_boolean definition
;
1673 definition
= info
->type_stack
->definition
;
1674 s
= stab_pop_type (info
);
1676 /* Build the base class specifier. */
1678 buf
= (char *) xmalloc (strlen (s
) + 25);
1679 buf
[0] = virtual ? '1' : '0';
1685 case DEBUG_VISIBILITY_PRIVATE
:
1689 case DEBUG_VISIBILITY_PROTECTED
:
1693 case DEBUG_VISIBILITY_PUBLIC
:
1698 sprintf (buf
+ 2, "%ld,%s;", (long) bitpos
, s
);
1701 /* Add the new baseclass to the existing ones. */
1703 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1705 if (info
->type_stack
->baseclasses
== NULL
)
1710 while (info
->type_stack
->baseclasses
[c
] != NULL
)
1714 baseclasses
= (char **) xrealloc (info
->type_stack
->baseclasses
,
1715 (c
+ 2) * sizeof (*baseclasses
));
1716 baseclasses
[c
] = buf
;
1717 baseclasses
[c
+ 1] = NULL
;
1719 info
->type_stack
->baseclasses
= baseclasses
;
1722 info
->type_stack
->definition
= TRUE
;
1727 /* Start adding a method to the class on the type stack. */
1730 stab_class_start_method (p
, name
)
1734 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1737 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1739 if (info
->type_stack
->methods
== NULL
)
1741 m
= (char *) xmalloc (strlen (name
) + 3);
1746 m
= (char *) xrealloc (info
->type_stack
->methods
,
1747 (strlen (info
->type_stack
->methods
)
1752 sprintf (m
+ strlen (m
), "%s::", name
);
1754 info
->type_stack
->methods
= m
;
1759 /* Add a variant, either static or not, to the current method. */
1762 stab_class_method_var (info
, physname
, visibility
, staticp
, constp
, volatilep
,
1764 struct stab_write_handle
*info
;
1765 const char *physname
;
1766 enum debug_visibility visibility
;
1767 bfd_boolean staticp
;
1769 bfd_boolean volatilep
;
1771 bfd_boolean contextp
;
1773 bfd_boolean definition
;
1775 char *context
= NULL
;
1776 char visc
, qualc
, typec
;
1778 definition
= info
->type_stack
->definition
;
1779 type
= stab_pop_type (info
);
1783 definition
= definition
|| info
->type_stack
->definition
;
1784 context
= stab_pop_type (info
);
1787 assert (info
->type_stack
!= NULL
&& info
->type_stack
->methods
!= NULL
);
1794 case DEBUG_VISIBILITY_PRIVATE
:
1798 case DEBUG_VISIBILITY_PROTECTED
:
1802 case DEBUG_VISIBILITY_PUBLIC
:
1824 else if (! contextp
)
1829 info
->type_stack
->methods
=
1830 (char *) xrealloc (info
->type_stack
->methods
,
1831 (strlen (info
->type_stack
->methods
)
1834 + (contextp
? strlen (context
) : 0)
1837 sprintf (info
->type_stack
->methods
+ strlen (info
->type_stack
->methods
),
1838 "%s:%s;%c%c%c", type
, physname
, visc
, qualc
, typec
);
1843 sprintf (info
->type_stack
->methods
+ strlen (info
->type_stack
->methods
),
1844 "%ld;%s;", (long) voffset
, context
);
1849 info
->type_stack
->definition
= TRUE
;
1854 /* Add a variant to the current method. */
1857 stab_class_method_variant (p
, physname
, visibility
, constp
, volatilep
,
1860 const char *physname
;
1861 enum debug_visibility visibility
;
1863 bfd_boolean volatilep
;
1865 bfd_boolean contextp
;
1867 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1869 return stab_class_method_var (info
, physname
, visibility
, FALSE
, constp
,
1870 volatilep
, voffset
, contextp
);
1873 /* Add a static variant to the current method. */
1876 stab_class_static_method_variant (p
, physname
, visibility
, constp
, volatilep
)
1878 const char *physname
;
1879 enum debug_visibility visibility
;
1881 bfd_boolean volatilep
;
1883 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1885 return stab_class_method_var (info
, physname
, visibility
, TRUE
, constp
,
1886 volatilep
, 0, FALSE
);
1889 /* Finish up a method. */
1892 stab_class_end_method (p
)
1895 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1897 assert (info
->type_stack
!= NULL
&& info
->type_stack
->methods
!= NULL
);
1899 /* We allocated enough room on info->type_stack->methods to add the
1900 trailing semicolon. */
1901 strcat (info
->type_stack
->methods
, ";");
1906 /* Finish up a class. */
1909 stab_end_class_type (p
)
1912 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1917 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1919 /* Work out the size we need to allocate for the class definition. */
1921 len
= (strlen (info
->type_stack
->string
)
1922 + strlen (info
->type_stack
->fields
)
1924 if (info
->type_stack
->baseclasses
!= NULL
)
1927 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1928 len
+= strlen (info
->type_stack
->baseclasses
[i
]);
1930 if (info
->type_stack
->methods
!= NULL
)
1931 len
+= strlen (info
->type_stack
->methods
);
1932 if (info
->type_stack
->vtable
!= NULL
)
1933 len
+= strlen (info
->type_stack
->vtable
);
1935 /* Build the class definition. */
1937 buf
= (char *) xmalloc (len
);
1939 strcpy (buf
, info
->type_stack
->string
);
1941 if (info
->type_stack
->baseclasses
!= NULL
)
1943 sprintf (buf
+ strlen (buf
), "!%u,", i
);
1944 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1946 strcat (buf
, info
->type_stack
->baseclasses
[i
]);
1947 free (info
->type_stack
->baseclasses
[i
]);
1949 free (info
->type_stack
->baseclasses
);
1950 info
->type_stack
->baseclasses
= NULL
;
1953 strcat (buf
, info
->type_stack
->fields
);
1954 free (info
->type_stack
->fields
);
1955 info
->type_stack
->fields
= NULL
;
1957 if (info
->type_stack
->methods
!= NULL
)
1959 strcat (buf
, info
->type_stack
->methods
);
1960 free (info
->type_stack
->methods
);
1961 info
->type_stack
->methods
= NULL
;
1966 if (info
->type_stack
->vtable
!= NULL
)
1968 strcat (buf
, info
->type_stack
->vtable
);
1969 free (info
->type_stack
->vtable
);
1970 info
->type_stack
->vtable
= NULL
;
1973 /* Replace the string on the top of the stack with the complete
1974 class definition. */
1975 free (info
->type_stack
->string
);
1976 info
->type_stack
->string
= buf
;
1981 /* Push a typedef which was previously defined. */
1984 stab_typedef_type (p
, name
)
1988 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1989 struct string_hash_entry
*h
;
1991 h
= string_hash_lookup (&info
->typedef_hash
, name
, FALSE
, FALSE
);
1992 assert (h
!= NULL
&& h
->index
> 0);
1994 return stab_push_defined_type (info
, h
->index
, h
->size
);
1997 /* Push a struct, union or class tag. */
2000 stab_tag_type (p
, name
, id
, kind
)
2004 enum debug_type_kind kind
;
2006 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2010 index
= stab_get_struct_index (info
, name
, id
, kind
, &size
);
2014 return stab_push_defined_type (info
, index
, size
);
2017 /* Define a typedef. */
2020 stab_typdef (p
, name
)
2024 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2028 struct string_hash_entry
*h
;
2030 index
= info
->type_stack
->index
;
2031 size
= info
->type_stack
->size
;
2032 s
= stab_pop_type (info
);
2034 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 20);
2037 sprintf (buf
, "%s:t%s", name
, s
);
2040 index
= info
->type_index
;
2042 sprintf (buf
, "%s:t%ld=%s", name
, index
, s
);
2047 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2052 h
= string_hash_lookup (&info
->typedef_hash
, name
, TRUE
, FALSE
);
2055 non_fatal (_("string_hash_lookup failed: %s"),
2056 bfd_errmsg (bfd_get_error ()));
2060 /* I don't think we care about redefinitions. */
2075 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2078 s
= stab_pop_type (info
);
2080 buf
= (char *) xmalloc (strlen (tag
) + strlen (s
) + 3);
2082 sprintf (buf
, "%s:T%s", tag
, s
);
2085 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2093 /* Define an integer constant. */
2096 stab_int_constant (p
, name
, val
)
2101 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2104 buf
= (char *) xmalloc (strlen (name
) + 20);
2105 sprintf (buf
, "%s:c=i%ld", name
, (long) val
);
2107 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2115 /* Define a floating point constant. */
2118 stab_float_constant (p
, name
, val
)
2123 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2126 buf
= (char *) xmalloc (strlen (name
) + 20);
2127 sprintf (buf
, "%s:c=f%g", name
, val
);
2129 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2137 /* Define a typed constant. */
2140 stab_typed_constant (p
, name
, val
)
2145 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2148 s
= stab_pop_type (info
);
2150 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 20);
2151 sprintf (buf
, "%s:c=e%s,%ld", name
, s
, (long) val
);
2154 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2162 /* Record a variable. */
2165 stab_variable (p
, name
, kind
, val
)
2168 enum debug_var_kind kind
;
2171 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2174 const char *kindstr
;
2176 s
= stab_pop_type (info
);
2189 stab_type
= N_STSYM
;
2193 case DEBUG_LOCAL_STATIC
:
2194 stab_type
= N_STSYM
;
2202 /* Make sure that this is a type reference or definition. */
2208 index
= info
->type_index
;
2210 n
= (char *) xmalloc (strlen (s
) + 20);
2211 sprintf (n
, "%ld=%s", index
, s
);
2217 case DEBUG_REGISTER
:
2223 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 3);
2224 sprintf (buf
, "%s:%s%s", name
, kindstr
, s
);
2227 if (! stab_write_symbol (info
, stab_type
, 0, val
, buf
))
2235 /* Start outputting a function. */
2238 stab_start_function (p
, name
, globalp
)
2241 bfd_boolean globalp
;
2243 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2244 char *rettype
, *buf
;
2246 assert (info
->nesting
== 0 && info
->fun_offset
== -1);
2248 rettype
= stab_pop_type (info
);
2250 buf
= (char *) xmalloc (strlen (name
) + strlen (rettype
) + 3);
2251 sprintf (buf
, "%s:%c%s", name
,
2252 globalp
? 'F' : 'f',
2255 /* We don't know the value now, so we set it in start_block. */
2256 info
->fun_offset
= info
->symbols_size
;
2258 if (! stab_write_symbol (info
, N_FUN
, 0, 0, buf
))
2266 /* Output a function parameter. */
2269 stab_function_parameter (p
, name
, kind
, val
)
2272 enum debug_parm_kind kind
;
2275 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2280 s
= stab_pop_type (info
);
2287 case DEBUG_PARM_STACK
:
2292 case DEBUG_PARM_REG
:
2297 case DEBUG_PARM_REFERENCE
:
2302 case DEBUG_PARM_REF_REG
:
2308 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 3);
2309 sprintf (buf
, "%s:%c%s", name
, kindc
, s
);
2312 if (! stab_write_symbol (info
, stab_type
, 0, val
, buf
))
2320 /* Start a block. */
2323 stab_start_block (p
, addr
)
2327 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2329 /* Fill in any slots which have been waiting for the first known
2332 if (info
->so_offset
!= -1)
2334 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->so_offset
+ 8);
2335 info
->so_offset
= -1;
2338 if (info
->fun_offset
!= -1)
2340 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->fun_offset
+ 8);
2341 info
->fun_offset
= -1;
2346 /* We will be called with a top level block surrounding the
2347 function, but stabs information does not output that block, so we
2350 if (info
->nesting
== 1)
2352 info
->fnaddr
= addr
;
2356 /* We have to output the LBRAC symbol after any variables which are
2357 declared inside the block. We postpone the LBRAC until the next
2358 start_block or end_block. */
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
))
2368 /* Remember the address and output it later. */
2370 info
->pending_lbrac
= addr
- info
->fnaddr
;
2378 stab_end_block (p
, addr
)
2382 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2384 if (addr
> info
->last_text_address
)
2385 info
->last_text_address
= addr
;
2387 /* If we have postponed an LBRAC, output it now. */
2388 if (info
->pending_lbrac
!= (bfd_vma
) -1)
2390 if (! stab_write_symbol (info
, N_LBRAC
, 0, info
->pending_lbrac
,
2391 (const char *) NULL
))
2393 info
->pending_lbrac
= (bfd_vma
) -1;
2396 assert (info
->nesting
> 0);
2400 /* We ignore the outermost block. */
2401 if (info
->nesting
== 0)
2404 return stab_write_symbol (info
, N_RBRAC
, 0, addr
- info
->fnaddr
,
2405 (const char *) NULL
);
2408 /* End a function. */
2411 stab_end_function (p
)
2412 PTR p ATTRIBUTE_UNUSED
;
2417 /* Output a line number. */
2420 stab_lineno (p
, file
, lineno
, addr
)
2423 unsigned long lineno
;
2426 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2428 assert (info
->lineno_filename
!= NULL
);
2430 if (addr
> info
->last_text_address
)
2431 info
->last_text_address
= addr
;
2433 if (strcmp (file
, info
->lineno_filename
) != 0)
2435 if (! stab_write_symbol (info
, N_SOL
, 0, addr
, file
))
2437 info
->lineno_filename
= file
;
2440 return stab_write_symbol (info
, N_SLINE
, lineno
, addr
- info
->fnaddr
,
2441 (const char *) NULL
);