1 /* wrstabs.c -- Output stabs debugging information
2 Copyright 1996, 1997, 1998, 2000, 2001, 2002
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"
36 /* Meaningless definition needs by aout64.h. FIXME. */
37 #define BYTES_IN_WORD 4
39 #include "aout/aout64.h"
40 #include "aout/stab_gnu.h"
42 /* The size of a stabs symbol. This presumes 32 bit values. */
44 #define STAB_SYMBOL_SIZE (12)
46 /* An entry in a string hash table. */
48 struct string_hash_entry
50 struct bfd_hash_entry root
;
51 /* Next string in this table. */
52 struct string_hash_entry
*next
;
53 /* Index in string table. */
55 /* Size of type if this is a typedef. */
59 /* A string hash table. */
61 struct string_hash_table
63 struct bfd_hash_table table
;
66 /* The type stack. Each element on the stack is a string. */
68 struct stab_type_stack
70 /* The next element on the stack. */
71 struct stab_type_stack
*next
;
72 /* This element as a string. */
74 /* The type index of this element. */
76 /* The size of the type. */
78 /* Whether type string defines a new type. */
79 bfd_boolean definition
;
80 /* String defining struct fields. */
82 /* NULL terminated array of strings defining base classes for a
85 /* String defining class methods. */
87 /* String defining vtable pointer for a class. */
91 /* This structure is used to keep track of type indices for tagged
100 /* The kind of type. This is set to DEBUG_KIND_ILLEGAL when the
102 enum debug_type_kind kind
;
103 /* The size of the struct. */
107 /* We remember various sorts of type indices. They are not related,
108 but, for convenience, we keep all the information in this
111 struct stab_type_cache
113 /* The void type index. */
115 /* Signed integer type indices, indexed by size - 1. */
116 long signed_integer_types
[8];
117 /* Unsigned integer type indices, indexed by size - 1. */
118 long unsigned_integer_types
[8];
119 /* Floating point types, indexed by size - 1. */
120 long float_types
[16];
121 /* Pointers to types, indexed by the type index. */
123 size_t pointer_types_alloc
;
124 /* Functions returning types, indexed by the type index. */
125 long *function_types
;
126 size_t function_types_alloc
;
127 /* References to types, indexed by the type index. */
128 long *reference_types
;
129 size_t reference_types_alloc
;
130 /* Struct/union/class type indices, indexed by the struct id. */
131 struct stab_tag
*struct_types
;
132 size_t struct_types_alloc
;
135 /* This is the handle passed through debug_write. */
137 struct stab_write_handle
141 /* This buffer holds the symbols. */
144 size_t symbols_alloc
;
145 /* This is a list of hash table entries for the strings. */
146 struct string_hash_entry
*strings
;
147 /* The last string hash table entry. */
148 struct string_hash_entry
*last_string
;
149 /* The size of the strings. */
151 /* This hash table eliminates duplicate strings. */
152 struct string_hash_table strhash
;
153 /* The type stack. */
154 struct stab_type_stack
*type_stack
;
155 /* The next type index. */
157 /* The type cache. */
158 struct stab_type_cache type_cache
;
159 /* A mapping from typedef names to type indices. */
160 struct string_hash_table typedef_hash
;
161 /* If this is not -1, it is the offset to the most recent N_SO
162 symbol, and the value of that symbol needs to be set. */
164 /* If this is not -1, it is the offset to the most recent N_FUN
165 symbol, and the value of that symbol needs to be set. */
167 /* The last text section address seen. */
168 bfd_vma last_text_address
;
169 /* The block nesting depth. */
170 unsigned int nesting
;
171 /* The function address. */
173 /* A pending LBRAC symbol. */
174 bfd_vma pending_lbrac
;
175 /* The current line number file name. */
176 const char *lineno_filename
;
179 static struct bfd_hash_entry
*string_hash_newfunc
180 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
181 static bfd_boolean stab_write_symbol
182 PARAMS ((struct stab_write_handle
*, int, int, bfd_vma
, const char *));
183 static bfd_boolean stab_push_string
184 PARAMS ((struct stab_write_handle
*, const char *, long, bfd_boolean
,
186 static bfd_boolean stab_push_defined_type
187 PARAMS ((struct stab_write_handle
*, long, unsigned int));
188 static char *stab_pop_type
189 PARAMS ((struct stab_write_handle
*));
190 static bfd_boolean stab_modify_type
191 PARAMS ((struct stab_write_handle
*, int, unsigned int, long **, size_t *));
192 static long stab_get_struct_index
193 PARAMS ((struct stab_write_handle
*, const char *, unsigned int,
194 enum debug_type_kind
, unsigned int *));
195 static bfd_boolean stab_class_method_var
196 PARAMS ((struct stab_write_handle
*, const char *, enum debug_visibility
,
197 bfd_boolean
, bfd_boolean
, bfd_boolean
, bfd_vma
, bfd_boolean
));
198 static bfd_boolean stab_start_compilation_unit
199 PARAMS ((PTR
, const char *));
200 static bfd_boolean stab_start_source
201 PARAMS ((PTR
, const char *));
202 static bfd_boolean stab_empty_type
204 static bfd_boolean stab_void_type
206 static bfd_boolean stab_int_type
207 PARAMS ((PTR
, unsigned int, bfd_boolean
));
208 static bfd_boolean stab_float_type
209 PARAMS ((PTR
, unsigned int));
210 static bfd_boolean stab_complex_type
211 PARAMS ((PTR
, unsigned int));
212 static bfd_boolean stab_bool_type
213 PARAMS ((PTR
, unsigned int));
214 static bfd_boolean stab_enum_type
215 PARAMS ((PTR
, const char *, const char **, bfd_signed_vma
*));
216 static bfd_boolean stab_pointer_type
218 static bfd_boolean stab_function_type
219 PARAMS ((PTR
, int, bfd_boolean
));
220 static bfd_boolean stab_reference_type
222 static bfd_boolean stab_range_type
223 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
));
224 static bfd_boolean stab_array_type
225 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
, bfd_boolean
));
226 static bfd_boolean stab_set_type
227 PARAMS ((PTR
, bfd_boolean
));
228 static bfd_boolean stab_offset_type
230 static bfd_boolean stab_method_type
231 PARAMS ((PTR
, bfd_boolean
, int, bfd_boolean
));
232 static bfd_boolean stab_const_type
234 static bfd_boolean stab_volatile_type
236 static bfd_boolean stab_start_struct_type
237 PARAMS ((PTR
, const char *, unsigned int, bfd_boolean
, unsigned int));
238 static bfd_boolean stab_struct_field
239 PARAMS ((PTR
, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
));
240 static bfd_boolean stab_end_struct_type
242 static bfd_boolean stab_start_class_type
243 PARAMS ((PTR
, const char *, unsigned int, bfd_boolean
, unsigned int,
244 bfd_boolean
, bfd_boolean
));
245 static bfd_boolean stab_class_static_member
246 PARAMS ((PTR
, const char *, const char *, enum debug_visibility
));
247 static bfd_boolean stab_class_baseclass
248 PARAMS ((PTR
, bfd_vma
, bfd_boolean
, enum debug_visibility
));
249 static bfd_boolean stab_class_start_method
250 PARAMS ((PTR
, const char *));
251 static bfd_boolean stab_class_method_variant
252 PARAMS ((PTR
, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
,
253 bfd_vma
, bfd_boolean
));
254 static bfd_boolean stab_class_static_method_variant
255 PARAMS ((PTR
, const char *, enum debug_visibility
, bfd_boolean
,
257 static bfd_boolean stab_class_end_method
259 static bfd_boolean stab_end_class_type
261 static bfd_boolean stab_typedef_type
262 PARAMS ((PTR
, const char *));
263 static bfd_boolean stab_tag_type
264 PARAMS ((PTR
, const char *, unsigned int, enum debug_type_kind
));
265 static bfd_boolean stab_typdef
266 PARAMS ((PTR
, const char *));
267 static bfd_boolean stab_tag
268 PARAMS ((PTR
, const char *));
269 static bfd_boolean stab_int_constant
270 PARAMS ((PTR
, const char *, bfd_vma
));
271 static bfd_boolean stab_float_constant
272 PARAMS ((PTR
, const char *, double));
273 static bfd_boolean stab_typed_constant
274 PARAMS ((PTR
, const char *, bfd_vma
));
275 static bfd_boolean stab_variable
276 PARAMS ((PTR
, const char *, enum debug_var_kind
, bfd_vma
));
277 static bfd_boolean stab_start_function
278 PARAMS ((PTR
, const char *, bfd_boolean
));
279 static bfd_boolean stab_function_parameter
280 PARAMS ((PTR
, const char *, enum debug_parm_kind
, bfd_vma
));
281 static bfd_boolean stab_start_block
282 PARAMS ((PTR
, bfd_vma
));
283 static bfd_boolean stab_end_block
284 PARAMS ((PTR
, bfd_vma
));
285 static bfd_boolean stab_end_function
287 static bfd_boolean stab_lineno
288 PARAMS ((PTR
, const char *, unsigned long, bfd_vma
));
290 static const struct debug_write_fns stab_fns
=
292 stab_start_compilation_unit
,
311 stab_start_struct_type
,
313 stab_end_struct_type
,
314 stab_start_class_type
,
315 stab_class_static_member
,
316 stab_class_baseclass
,
317 stab_class_start_method
,
318 stab_class_method_variant
,
319 stab_class_static_method_variant
,
320 stab_class_end_method
,
331 stab_function_parameter
,
338 /* Routine to create an entry in a string hash table. */
340 static struct bfd_hash_entry
*
341 string_hash_newfunc (entry
, table
, string
)
342 struct bfd_hash_entry
*entry
;
343 struct bfd_hash_table
*table
;
346 struct string_hash_entry
*ret
= (struct string_hash_entry
*) entry
;
348 /* Allocate the structure if it has not already been allocated by a
350 if (ret
== (struct string_hash_entry
*) NULL
)
351 ret
= ((struct string_hash_entry
*)
352 bfd_hash_allocate (table
, sizeof (struct string_hash_entry
)));
353 if (ret
== (struct string_hash_entry
*) NULL
)
356 /* Call the allocation method of the superclass. */
357 ret
= ((struct string_hash_entry
*)
358 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
362 /* Initialize the local fields. */
368 return (struct bfd_hash_entry
*) ret
;
371 /* Look up an entry in a string hash table. */
373 #define string_hash_lookup(t, string, create, copy) \
374 ((struct string_hash_entry *) \
375 bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
377 /* Add a symbol to the stabs debugging information we are building. */
380 stab_write_symbol (info
, type
, desc
, value
, string
)
381 struct stab_write_handle
*info
;
388 bfd_byte sym
[STAB_SYMBOL_SIZE
];
394 struct string_hash_entry
*h
;
396 h
= string_hash_lookup (&info
->strhash
, string
, TRUE
, TRUE
);
399 non_fatal (_("string_hash_lookup failed: %s"),
400 bfd_errmsg (bfd_get_error ()));
407 strx
= info
->strings_size
;
409 if (info
->last_string
== NULL
)
412 info
->last_string
->next
= h
;
413 info
->last_string
= h
;
414 info
->strings_size
+= strlen (string
) + 1;
418 /* This presumes 32 bit values. */
419 bfd_put_32 (info
->abfd
, strx
, sym
);
420 bfd_put_8 (info
->abfd
, type
, sym
+ 4);
421 bfd_put_8 (info
->abfd
, 0, sym
+ 5);
422 bfd_put_16 (info
->abfd
, desc
, sym
+ 6);
423 bfd_put_32 (info
->abfd
, value
, sym
+ 8);
425 if (info
->symbols_size
+ STAB_SYMBOL_SIZE
> info
->symbols_alloc
)
427 info
->symbols_alloc
*= 2;
428 info
->symbols
= (bfd_byte
*) xrealloc (info
->symbols
,
429 info
->symbols_alloc
);
432 memcpy (info
->symbols
+ info
->symbols_size
, sym
, STAB_SYMBOL_SIZE
);
434 info
->symbols_size
+= STAB_SYMBOL_SIZE
;
439 /* Push a string on to the type stack. */
442 stab_push_string (info
, string
, index
, definition
, size
)
443 struct stab_write_handle
*info
;
446 bfd_boolean definition
;
449 struct stab_type_stack
*s
;
451 s
= (struct stab_type_stack
*) xmalloc (sizeof *s
);
452 s
->string
= xstrdup (string
);
454 s
->definition
= definition
;
458 s
->baseclasses
= NULL
;
462 s
->next
= info
->type_stack
;
463 info
->type_stack
= s
;
468 /* Push a type index which has already been defined. */
471 stab_push_defined_type (info
, index
, size
)
472 struct stab_write_handle
*info
;
478 sprintf (buf
, "%ld", index
);
479 return stab_push_string (info
, buf
, index
, FALSE
, size
);
482 /* Pop a type off the type stack. The caller is responsible for
483 freeing the string. */
487 struct stab_write_handle
*info
;
489 struct stab_type_stack
*s
;
492 s
= info
->type_stack
;
495 info
->type_stack
= s
->next
;
504 /* The general routine to write out stabs in sections debugging
505 information. This accumulates the stabs symbols and the strings in
506 two obstacks. We can't easily write out the information as we go
507 along, because we need to know the section sizes before we can
508 write out the section contents. ABFD is the BFD and DHANDLE is the
509 handle for the debugging information. This sets *PSYMS to point to
510 the symbols, *PSYMSIZE the size of the symbols, *PSTRINGS to the
511 strings, and *PSTRINGSIZE to the size of the strings. */
514 write_stabs_in_sections_debugging_info (abfd
, dhandle
, psyms
, psymsize
,
515 pstrings
, pstringsize
)
519 bfd_size_type
*psymsize
;
521 bfd_size_type
*pstringsize
;
523 struct stab_write_handle info
;
524 struct string_hash_entry
*h
;
529 info
.symbols_size
= 0;
530 info
.symbols_alloc
= 500;
531 info
.symbols
= (bfd_byte
*) xmalloc (info
.symbols_alloc
);
534 info
.last_string
= NULL
;
535 /* Reserve 1 byte for a null byte. */
536 info
.strings_size
= 1;
538 if (! bfd_hash_table_init (&info
.strhash
.table
, string_hash_newfunc
)
539 || ! bfd_hash_table_init (&info
.typedef_hash
.table
, string_hash_newfunc
))
541 non_fatal ("bfd_hash_table_init_failed: %s",
542 bfd_errmsg (bfd_get_error ()));
546 info
.type_stack
= NULL
;
548 memset (&info
.type_cache
, 0, sizeof info
.type_cache
);
550 info
.fun_offset
= -1;
551 info
.last_text_address
= 0;
554 info
.pending_lbrac
= (bfd_vma
) -1;
556 /* The initial symbol holds the string size. */
557 if (! stab_write_symbol (&info
, 0, 0, 0, (const char *) NULL
))
560 /* Output an initial N_SO symbol. */
561 info
.so_offset
= info
.symbols_size
;
562 if (! stab_write_symbol (&info
, N_SO
, 0, 0, bfd_get_filename (abfd
)))
565 if (! debug_write (dhandle
, &stab_fns
, (PTR
) &info
))
568 assert (info
.pending_lbrac
== (bfd_vma
) -1);
570 /* Output a trailing N_SO. */
571 if (! stab_write_symbol (&info
, N_SO
, 0, info
.last_text_address
,
572 (const char *) NULL
))
575 /* Put the string size in the initial symbol. */
576 bfd_put_32 (abfd
, info
.strings_size
, info
.symbols
+ 8);
578 *psyms
= info
.symbols
;
579 *psymsize
= info
.symbols_size
;
581 *pstringsize
= info
.strings_size
;
582 *pstrings
= (bfd_byte
*) xmalloc (info
.strings_size
);
586 for (h
= info
.strings
; h
!= NULL
; h
= h
->next
)
588 strcpy ((char *) p
, h
->root
.string
);
589 p
+= strlen ((char *) p
) + 1;
595 /* Start writing out information for a compilation unit. */
598 stab_start_compilation_unit (p
, filename
)
600 const char *filename
;
602 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
604 /* We would normally output an N_SO symbol here. However, that
605 would force us to reset all of our type information. I think we
606 will be better off just outputting an N_SOL symbol, and not
607 worrying about splitting information between files. */
609 info
->lineno_filename
= filename
;
611 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
614 /* Start writing out information for a particular source file. */
617 stab_start_source (p
, filename
)
619 const char *filename
;
621 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
623 /* FIXME: The symbol's value is supposed to be the text section
624 address. However, we would have to fill it in later, and gdb
625 doesn't care, so we don't bother with it. */
627 info
->lineno_filename
= filename
;
629 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
632 /* Push an empty type. This shouldn't normally happen. We just use a
639 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
641 /* We don't call stab_void_type if the type is not yet defined,
642 because that might screw up the typedef. */
644 if (info
->type_cache
.void_type
!= 0)
645 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
651 index
= info
->type_index
;
654 sprintf (buf
, "%ld=%ld", index
, index
);
656 return stab_push_string (info
, buf
, index
, FALSE
, 0);
660 /* Push a void type. */
666 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
668 if (info
->type_cache
.void_type
!= 0)
669 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
675 index
= info
->type_index
;
678 info
->type_cache
.void_type
= index
;
680 sprintf (buf
, "%ld=%ld", index
, index
);
682 return stab_push_string (info
, buf
, index
, TRUE
, 0);
686 /* Push an integer type. */
689 stab_int_type (p
, size
, unsignedp
)
692 bfd_boolean unsignedp
;
694 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
697 if (size
<= 0 || (size
> sizeof (long) && size
!= 8))
699 non_fatal (_("stab_int_type: bad size %u"), size
);
704 cache
= info
->type_cache
.signed_integer_types
;
706 cache
= info
->type_cache
.unsigned_integer_types
;
708 if (cache
[size
- 1] != 0)
709 return stab_push_defined_type (info
, cache
[size
- 1], size
);
715 index
= info
->type_index
;
718 cache
[size
- 1] = index
;
720 sprintf (buf
, "%ld=r%ld;", index
, index
);
724 if (size
< sizeof (long))
725 sprintf (buf
+ strlen (buf
), "%ld;", ((long) 1 << (size
* 8)) - 1);
726 else if (size
== sizeof (long))
729 strcat (buf
, "01777777777777777777777;");
735 if (size
<= sizeof (long))
736 sprintf (buf
+ strlen (buf
), "%ld;%ld;",
737 (long) - ((unsigned long) 1 << (size
* 8 - 1)),
738 (long) (((unsigned long) 1 << (size
* 8 - 1)) - 1));
740 strcat (buf
, "01000000000000000000000;0777777777777777777777;");
745 return stab_push_string (info
, buf
, index
, TRUE
, size
);
749 /* Push a floating point type. */
752 stab_float_type (p
, size
)
756 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
759 && size
- 1 < (sizeof info
->type_cache
.float_types
760 / sizeof info
->type_cache
.float_types
[0])
761 && info
->type_cache
.float_types
[size
- 1] != 0)
762 return stab_push_defined_type (info
,
763 info
->type_cache
.float_types
[size
- 1],
771 /* Floats are defined as a subrange of int. */
772 if (! stab_int_type (info
, 4, FALSE
))
774 int_type
= stab_pop_type (info
);
776 index
= info
->type_index
;
780 && size
- 1 < (sizeof info
->type_cache
.float_types
781 / sizeof info
->type_cache
.float_types
[0]))
782 info
->type_cache
.float_types
[size
- 1] = index
;
784 sprintf (buf
, "%ld=r%s;%u;0;", index
, int_type
, size
);
788 return stab_push_string (info
, buf
, index
, TRUE
, size
);
792 /* Push a complex type. */
795 stab_complex_type (p
, size
)
799 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
803 index
= info
->type_index
;
806 sprintf (buf
, "%ld=r%ld;%u;0;", index
, index
, size
);
808 return stab_push_string (info
, buf
, index
, TRUE
, size
* 2);
811 /* Push a bfd_boolean type. We use an XCOFF predefined type, since gdb
812 always recognizes them. */
815 stab_bool_type (p
, size
)
819 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
842 return stab_push_defined_type (info
, index
, size
);
845 /* Push an enum type. */
848 stab_enum_type (p
, tag
, names
, vals
)
852 bfd_signed_vma
*vals
;
854 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
863 assert (tag
!= NULL
);
865 buf
= (char *) xmalloc (10 + strlen (tag
));
866 sprintf (buf
, "xe%s:", tag
);
867 /* FIXME: The size is just a guess. */
868 if (! stab_push_string (info
, buf
, 0, FALSE
, 4))
877 for (pn
= names
; *pn
!= NULL
; pn
++)
878 len
+= strlen (*pn
) + 20;
880 buf
= (char *) xmalloc (len
);
886 index
= info
->type_index
;
888 sprintf (buf
, "%s:T%ld=e", tag
, index
);
891 for (pn
= names
, pv
= vals
; *pn
!= NULL
; pn
++, pv
++)
892 sprintf (buf
+ strlen (buf
), "%s:%ld,", *pn
, (long) *pv
);
897 /* FIXME: The size is just a guess. */
898 if (! stab_push_string (info
, buf
, 0, FALSE
, 4))
903 /* FIXME: The size is just a guess. */
904 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
)
905 || ! stab_push_defined_type (info
, index
, 4))
914 /* Push a modification of the top type on the stack. Cache the
915 results in CACHE and CACHE_ALLOC. */
918 stab_modify_type (info
, mod
, size
, cache
, cache_alloc
)
919 struct stab_write_handle
*info
;
929 assert (info
->type_stack
!= NULL
);
930 targindex
= info
->type_stack
->index
;
935 bfd_boolean definition
;
937 /* Either the target type has no index, or we aren't caching
938 this modifier. Either way we have no way of recording the
939 new type, so we don't bother to define one. */
940 definition
= info
->type_stack
->definition
;
941 s
= stab_pop_type (info
);
942 buf
= (char *) xmalloc (strlen (s
) + 2);
943 sprintf (buf
, "%c%s", mod
, s
);
945 if (! stab_push_string (info
, buf
, 0, definition
, size
))
951 if ((size_t) targindex
>= *cache_alloc
)
955 alloc
= *cache_alloc
;
958 while ((size_t) targindex
>= alloc
)
960 *cache
= (long *) xrealloc (*cache
, alloc
* sizeof (long));
961 memset (*cache
+ *cache_alloc
, 0,
962 (alloc
- *cache_alloc
) * sizeof (long));
963 *cache_alloc
= alloc
;
966 index
= (*cache
)[targindex
];
967 if (index
!= 0 && ! info
->type_stack
->definition
)
969 /* We have already defined a modification of this type, and
970 the entry on the type stack is not a definition, so we
971 can safely discard it (we may have a definition on the
972 stack, even if we already defined a modification, if it
973 is a struct which we did not define at the time it was
975 free (stab_pop_type (info
));
976 if (! stab_push_defined_type (info
, index
, size
))
981 index
= info
->type_index
;
984 s
= stab_pop_type (info
);
985 buf
= (char *) xmalloc (strlen (s
) + 20);
986 sprintf (buf
, "%ld=%c%s", index
, mod
, s
);
989 (*cache
)[targindex
] = index
;
991 if (! stab_push_string (info
, buf
, index
, TRUE
, size
))
1001 /* Push a pointer type. */
1004 stab_pointer_type (p
)
1007 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1009 /* FIXME: The size should depend upon the architecture. */
1010 return stab_modify_type (info
, '*', 4, &info
->type_cache
.pointer_types
,
1011 &info
->type_cache
.pointer_types_alloc
);
1014 /* Push a function type. */
1017 stab_function_type (p
, argcount
, varargs
)
1020 bfd_boolean varargs ATTRIBUTE_UNUSED
;
1022 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1025 /* We have no way to represent the argument types, so we just
1026 discard them. However, if they define new types, we must output
1027 them. We do this by producing empty typedefs. */
1028 for (i
= 0; i
< argcount
; i
++)
1030 if (! info
->type_stack
->definition
)
1031 free (stab_pop_type (info
));
1036 s
= stab_pop_type (info
);
1038 buf
= (char *) xmalloc (strlen (s
) + 3);
1039 sprintf (buf
, ":t%s", s
);
1042 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
1049 return stab_modify_type (info
, 'f', 0, &info
->type_cache
.function_types
,
1050 &info
->type_cache
.function_types_alloc
);
1053 /* Push a reference type. */
1056 stab_reference_type (p
)
1059 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1061 /* FIXME: The size should depend upon the architecture. */
1062 return stab_modify_type (info
, '&', 4, &info
->type_cache
.reference_types
,
1063 &info
->type_cache
.reference_types_alloc
);
1066 /* Push a range type. */
1069 stab_range_type (p
, low
, high
)
1072 bfd_signed_vma high
;
1074 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1075 bfd_boolean definition
;
1079 definition
= info
->type_stack
->definition
;
1080 size
= info
->type_stack
->size
;
1082 s
= stab_pop_type (info
);
1083 buf
= (char *) xmalloc (strlen (s
) + 100);
1084 sprintf (buf
, "r%s;%ld;%ld;", s
, (long) low
, (long) high
);
1087 if (! stab_push_string (info
, buf
, 0, definition
, size
))
1095 /* Push an array type. */
1098 stab_array_type (p
, low
, high
, stringp
)
1101 bfd_signed_vma high
;
1102 bfd_boolean stringp
;
1104 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1105 bfd_boolean definition
;
1106 unsigned int element_size
;
1107 char *range
, *element
, *buf
;
1111 definition
= info
->type_stack
->definition
;
1112 range
= stab_pop_type (info
);
1114 definition
= definition
|| info
->type_stack
->definition
;
1115 element_size
= info
->type_stack
->size
;
1116 element
= stab_pop_type (info
);
1118 buf
= (char *) xmalloc (strlen (range
) + strlen (element
) + 100);
1127 /* We need to define a type in order to include the string
1129 index
= info
->type_index
;
1132 sprintf (buf
, "%ld=@S;", index
);
1135 sprintf (buf
+ strlen (buf
), "ar%s;%ld;%ld;%s",
1136 range
, (long) low
, (long) high
, element
);
1143 size
= element_size
* ((high
- low
) + 1);
1144 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1152 /* Push a set type. */
1155 stab_set_type (p
, bitstringp
)
1157 bfd_boolean bitstringp
;
1159 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1160 bfd_boolean definition
;
1164 definition
= info
->type_stack
->definition
;
1166 s
= stab_pop_type (info
);
1167 buf
= (char *) xmalloc (strlen (s
) + 30);
1176 /* We need to define a type in order to include the string
1178 index
= info
->type_index
;
1181 sprintf (buf
, "%ld=@S;", index
);
1184 sprintf (buf
+ strlen (buf
), "S%s", s
);
1187 if (! stab_push_string (info
, buf
, index
, definition
, 0))
1195 /* Push an offset type. */
1198 stab_offset_type (p
)
1201 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1202 bfd_boolean definition
;
1203 char *target
, *base
, *buf
;
1205 definition
= info
->type_stack
->definition
;
1206 target
= stab_pop_type (info
);
1208 definition
= definition
|| info
->type_stack
->definition
;
1209 base
= stab_pop_type (info
);
1211 buf
= (char *) xmalloc (strlen (target
) + strlen (base
) + 3);
1212 sprintf (buf
, "@%s,%s", base
, target
);
1216 if (! stab_push_string (info
, buf
, 0, definition
, 0))
1224 /* Push a method type. */
1227 stab_method_type (p
, domainp
, argcount
, varargs
)
1229 bfd_boolean domainp
;
1231 bfd_boolean varargs
;
1233 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1234 bfd_boolean definition
;
1235 char *domain
, *return_type
, *buf
;
1240 /* We don't bother with stub method types, because that would
1241 require a mangler for C++ argument types. This will waste space
1242 in the debugging output. */
1244 /* We need a domain. I'm not sure DOMAINP can ever be false,
1248 if (! stab_empty_type (p
))
1252 definition
= info
->type_stack
->definition
;
1253 domain
= stab_pop_type (info
);
1255 /* A non-varargs function is indicated by making the last parameter
1263 else if (argcount
== 0)
1269 args
= (char **) xmalloc (1 * sizeof (*args
));
1270 if (! stab_empty_type (p
))
1272 definition
= definition
|| info
->type_stack
->definition
;
1273 args
[0] = stab_pop_type (info
);
1279 args
= (char **) xmalloc ((argcount
+ 1) * sizeof (*args
));
1280 for (i
= argcount
- 1; i
>= 0; i
--)
1282 definition
= definition
|| info
->type_stack
->definition
;
1283 args
[i
] = stab_pop_type (info
);
1287 if (! stab_empty_type (p
))
1289 definition
= definition
|| info
->type_stack
->definition
;
1290 args
[argcount
] = stab_pop_type (info
);
1295 definition
= definition
|| info
->type_stack
->definition
;
1296 return_type
= stab_pop_type (info
);
1298 len
= strlen (domain
) + strlen (return_type
) + 10;
1299 for (i
= 0; i
< argcount
; i
++)
1300 len
+= strlen (args
[i
]);
1302 buf
= (char *) xmalloc (len
);
1304 sprintf (buf
, "#%s,%s", domain
, return_type
);
1307 for (i
= 0; i
< argcount
; i
++)
1310 strcat (buf
, args
[i
]);
1318 if (! stab_push_string (info
, buf
, 0, definition
, 0))
1326 /* Push a const version of a type. */
1332 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1334 return stab_modify_type (info
, 'k', info
->type_stack
->size
,
1335 (long **) NULL
, (size_t *) NULL
);
1338 /* Push a volatile version of a type. */
1341 stab_volatile_type (p
)
1344 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1346 return stab_modify_type (info
, 'B', info
->type_stack
->size
,
1347 (long **) NULL
, (size_t *) NULL
);
1350 /* Get the type index to use for a struct/union/class ID. This should
1351 return -1 if it fails. */
1354 stab_get_struct_index (info
, tag
, id
, kind
, psize
)
1355 struct stab_write_handle
*info
;
1358 enum debug_type_kind kind
;
1359 unsigned int *psize
;
1361 if (id
>= info
->type_cache
.struct_types_alloc
)
1365 alloc
= info
->type_cache
.struct_types_alloc
;
1370 info
->type_cache
.struct_types
=
1371 (struct stab_tag
*) xrealloc (info
->type_cache
.struct_types
,
1372 alloc
* sizeof (struct stab_tag
));
1373 memset ((info
->type_cache
.struct_types
1374 + info
->type_cache
.struct_types_alloc
),
1376 ((alloc
- info
->type_cache
.struct_types_alloc
)
1377 * sizeof (struct stab_tag
)));
1378 info
->type_cache
.struct_types_alloc
= alloc
;
1381 if (info
->type_cache
.struct_types
[id
].index
== 0)
1383 info
->type_cache
.struct_types
[id
].index
= info
->type_index
;
1385 info
->type_cache
.struct_types
[id
].tag
= tag
;
1386 info
->type_cache
.struct_types
[id
].kind
= kind
;
1389 if (kind
== DEBUG_KIND_ILLEGAL
)
1391 /* This is a definition of the struct. */
1392 info
->type_cache
.struct_types
[id
].kind
= kind
;
1393 info
->type_cache
.struct_types
[id
].size
= *psize
;
1396 *psize
= info
->type_cache
.struct_types
[id
].size
;
1398 return info
->type_cache
.struct_types
[id
].index
;
1401 /* Start outputting a struct. We ignore the tag, and handle it in
1405 stab_start_struct_type (p
, tag
, id
, structp
, size
)
1409 bfd_boolean structp
;
1412 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1414 bfd_boolean definition
;
1417 buf
= (char *) xmalloc (40);
1427 index
= stab_get_struct_index (info
, tag
, id
, DEBUG_KIND_ILLEGAL
,
1431 sprintf (buf
, "%ld=", index
);
1435 sprintf (buf
+ strlen (buf
), "%c%u",
1436 structp
? 's' : 'u',
1439 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1442 info
->type_stack
->fields
= (char *) xmalloc (1);
1443 info
->type_stack
->fields
[0] = '\0';
1448 /* Add a field to a struct. */
1451 stab_struct_field (p
, name
, bitpos
, bitsize
, visibility
)
1456 enum debug_visibility visibility
;
1458 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1459 bfd_boolean definition
;
1464 definition
= info
->type_stack
->definition
;
1465 size
= info
->type_stack
->size
;
1466 s
= stab_pop_type (info
);
1468 /* Add this field to the end of the current struct fields, which is
1469 currently on the top of the stack. */
1471 assert (info
->type_stack
->fields
!= NULL
);
1472 n
= (char *) xmalloc (strlen (info
->type_stack
->fields
)
1482 case DEBUG_VISIBILITY_PUBLIC
:
1486 case DEBUG_VISIBILITY_PRIVATE
:
1490 case DEBUG_VISIBILITY_PROTECTED
:
1499 non_fatal (_("%s: warning: unknown size for field `%s' in struct"),
1500 bfd_get_filename (info
->abfd
), name
);
1503 sprintf (n
, "%s%s:%s%s,%ld,%ld;", info
->type_stack
->fields
, name
, vis
, s
,
1504 (long) bitpos
, (long) bitsize
);
1506 free (info
->type_stack
->fields
);
1507 info
->type_stack
->fields
= n
;
1510 info
->type_stack
->definition
= TRUE
;
1515 /* Finish up a struct. */
1518 stab_end_struct_type (p
)
1521 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1522 bfd_boolean definition
;
1525 char *fields
, *first
, *buf
;
1527 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1529 definition
= info
->type_stack
->definition
;
1530 index
= info
->type_stack
->index
;
1531 size
= info
->type_stack
->size
;
1532 fields
= info
->type_stack
->fields
;
1533 first
= stab_pop_type (info
);
1535 buf
= (char *) xmalloc (strlen (first
) + strlen (fields
) + 2);
1536 sprintf (buf
, "%s%s;", first
, fields
);
1540 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1548 /* Start outputting a class. */
1551 stab_start_class_type (p
, tag
, id
, structp
, size
, vptr
, ownvptr
)
1555 bfd_boolean structp
;
1558 bfd_boolean ownvptr
;
1560 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1561 bfd_boolean definition
;
1564 if (! vptr
|| ownvptr
)
1571 definition
= info
->type_stack
->definition
;
1572 vstring
= stab_pop_type (info
);
1575 if (! stab_start_struct_type (p
, tag
, id
, structp
, size
))
1584 assert (info
->type_stack
->index
> 0);
1585 vtable
= (char *) xmalloc (20);
1586 sprintf (vtable
, "~%%%ld", info
->type_stack
->index
);
1590 vtable
= (char *) xmalloc (strlen (vstring
) + 3);
1591 sprintf (vtable
, "~%%%s", vstring
);
1595 info
->type_stack
->vtable
= vtable
;
1599 info
->type_stack
->definition
= TRUE
;
1604 /* Add a static member to the class on the type stack. */
1607 stab_class_static_member (p
, name
, physname
, visibility
)
1610 const char *physname
;
1611 enum debug_visibility visibility
;
1613 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1614 bfd_boolean definition
;
1618 definition
= info
->type_stack
->definition
;
1619 s
= stab_pop_type (info
);
1621 /* Add this field to the end of the current struct fields, which is
1622 currently on the top of the stack. */
1624 assert (info
->type_stack
->fields
!= NULL
);
1625 n
= (char *) xmalloc (strlen (info
->type_stack
->fields
)
1636 case DEBUG_VISIBILITY_PUBLIC
:
1640 case DEBUG_VISIBILITY_PRIVATE
:
1644 case DEBUG_VISIBILITY_PROTECTED
:
1649 sprintf (n
, "%s%s:%s%s:%s;", info
->type_stack
->fields
, name
, vis
, s
,
1652 free (info
->type_stack
->fields
);
1653 info
->type_stack
->fields
= n
;
1656 info
->type_stack
->definition
= TRUE
;
1661 /* Add a base class to the class on the type stack. */
1664 stab_class_baseclass (p
, bitpos
, virtual, visibility
)
1667 bfd_boolean
virtual;
1668 enum debug_visibility visibility
;
1670 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1671 bfd_boolean definition
;
1677 definition
= info
->type_stack
->definition
;
1678 s
= stab_pop_type (info
);
1680 /* Build the base class specifier. */
1682 buf
= (char *) xmalloc (strlen (s
) + 25);
1683 buf
[0] = virtual ? '1' : '0';
1689 case DEBUG_VISIBILITY_PRIVATE
:
1693 case DEBUG_VISIBILITY_PROTECTED
:
1697 case DEBUG_VISIBILITY_PUBLIC
:
1702 sprintf (buf
+ 2, "%ld,%s;", (long) bitpos
, s
);
1705 /* Add the new baseclass to the existing ones. */
1707 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1709 if (info
->type_stack
->baseclasses
== NULL
)
1714 while (info
->type_stack
->baseclasses
[c
] != NULL
)
1718 baseclasses
= (char **) xrealloc (info
->type_stack
->baseclasses
,
1719 (c
+ 2) * sizeof (*baseclasses
));
1720 baseclasses
[c
] = buf
;
1721 baseclasses
[c
+ 1] = NULL
;
1723 info
->type_stack
->baseclasses
= baseclasses
;
1726 info
->type_stack
->definition
= TRUE
;
1731 /* Start adding a method to the class on the type stack. */
1734 stab_class_start_method (p
, name
)
1738 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1741 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1743 if (info
->type_stack
->methods
== NULL
)
1745 m
= (char *) xmalloc (strlen (name
) + 3);
1750 m
= (char *) xrealloc (info
->type_stack
->methods
,
1751 (strlen (info
->type_stack
->methods
)
1756 sprintf (m
+ strlen (m
), "%s::", name
);
1758 info
->type_stack
->methods
= m
;
1763 /* Add a variant, either static or not, to the current method. */
1766 stab_class_method_var (info
, physname
, visibility
, staticp
, constp
, volatilep
,
1768 struct stab_write_handle
*info
;
1769 const char *physname
;
1770 enum debug_visibility visibility
;
1771 bfd_boolean staticp
;
1773 bfd_boolean volatilep
;
1775 bfd_boolean contextp
;
1777 bfd_boolean definition
;
1779 char *context
= NULL
;
1780 char visc
, qualc
, typec
;
1782 definition
= info
->type_stack
->definition
;
1783 type
= stab_pop_type (info
);
1787 definition
= definition
|| info
->type_stack
->definition
;
1788 context
= stab_pop_type (info
);
1791 assert (info
->type_stack
!= NULL
&& info
->type_stack
->methods
!= NULL
);
1798 case DEBUG_VISIBILITY_PRIVATE
:
1802 case DEBUG_VISIBILITY_PROTECTED
:
1806 case DEBUG_VISIBILITY_PUBLIC
:
1828 else if (! contextp
)
1833 info
->type_stack
->methods
=
1834 (char *) xrealloc (info
->type_stack
->methods
,
1835 (strlen (info
->type_stack
->methods
)
1838 + (contextp
? strlen (context
) : 0)
1841 sprintf (info
->type_stack
->methods
+ strlen (info
->type_stack
->methods
),
1842 "%s:%s;%c%c%c", type
, physname
, visc
, qualc
, typec
);
1847 sprintf (info
->type_stack
->methods
+ strlen (info
->type_stack
->methods
),
1848 "%ld;%s;", (long) voffset
, context
);
1853 info
->type_stack
->definition
= TRUE
;
1858 /* Add a variant to the current method. */
1861 stab_class_method_variant (p
, physname
, visibility
, constp
, volatilep
,
1864 const char *physname
;
1865 enum debug_visibility visibility
;
1867 bfd_boolean volatilep
;
1869 bfd_boolean contextp
;
1871 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1873 return stab_class_method_var (info
, physname
, visibility
, FALSE
, constp
,
1874 volatilep
, voffset
, contextp
);
1877 /* Add a static variant to the current method. */
1880 stab_class_static_method_variant (p
, physname
, visibility
, constp
, volatilep
)
1882 const char *physname
;
1883 enum debug_visibility visibility
;
1885 bfd_boolean volatilep
;
1887 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1889 return stab_class_method_var (info
, physname
, visibility
, TRUE
, constp
,
1890 volatilep
, 0, FALSE
);
1893 /* Finish up a method. */
1896 stab_class_end_method (p
)
1899 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1901 assert (info
->type_stack
!= NULL
&& info
->type_stack
->methods
!= NULL
);
1903 /* We allocated enough room on info->type_stack->methods to add the
1904 trailing semicolon. */
1905 strcat (info
->type_stack
->methods
, ";");
1910 /* Finish up a class. */
1913 stab_end_class_type (p
)
1916 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1921 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1923 /* Work out the size we need to allocate for the class definition. */
1925 len
= (strlen (info
->type_stack
->string
)
1926 + strlen (info
->type_stack
->fields
)
1928 if (info
->type_stack
->baseclasses
!= NULL
)
1931 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1932 len
+= strlen (info
->type_stack
->baseclasses
[i
]);
1934 if (info
->type_stack
->methods
!= NULL
)
1935 len
+= strlen (info
->type_stack
->methods
);
1936 if (info
->type_stack
->vtable
!= NULL
)
1937 len
+= strlen (info
->type_stack
->vtable
);
1939 /* Build the class definition. */
1941 buf
= (char *) xmalloc (len
);
1943 strcpy (buf
, info
->type_stack
->string
);
1945 if (info
->type_stack
->baseclasses
!= NULL
)
1947 sprintf (buf
+ strlen (buf
), "!%u,", i
);
1948 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1950 strcat (buf
, info
->type_stack
->baseclasses
[i
]);
1951 free (info
->type_stack
->baseclasses
[i
]);
1953 free (info
->type_stack
->baseclasses
);
1954 info
->type_stack
->baseclasses
= NULL
;
1957 strcat (buf
, info
->type_stack
->fields
);
1958 free (info
->type_stack
->fields
);
1959 info
->type_stack
->fields
= NULL
;
1961 if (info
->type_stack
->methods
!= NULL
)
1963 strcat (buf
, info
->type_stack
->methods
);
1964 free (info
->type_stack
->methods
);
1965 info
->type_stack
->methods
= NULL
;
1970 if (info
->type_stack
->vtable
!= NULL
)
1972 strcat (buf
, info
->type_stack
->vtable
);
1973 free (info
->type_stack
->vtable
);
1974 info
->type_stack
->vtable
= NULL
;
1977 /* Replace the string on the top of the stack with the complete
1978 class definition. */
1979 free (info
->type_stack
->string
);
1980 info
->type_stack
->string
= buf
;
1985 /* Push a typedef which was previously defined. */
1988 stab_typedef_type (p
, name
)
1992 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1993 struct string_hash_entry
*h
;
1995 h
= string_hash_lookup (&info
->typedef_hash
, name
, FALSE
, FALSE
);
1996 assert (h
!= NULL
&& h
->index
> 0);
1998 return stab_push_defined_type (info
, h
->index
, h
->size
);
2001 /* Push a struct, union or class tag. */
2004 stab_tag_type (p
, name
, id
, kind
)
2008 enum debug_type_kind kind
;
2010 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2014 index
= stab_get_struct_index (info
, name
, id
, kind
, &size
);
2018 return stab_push_defined_type (info
, index
, size
);
2021 /* Define a typedef. */
2024 stab_typdef (p
, name
)
2028 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2032 struct string_hash_entry
*h
;
2034 index
= info
->type_stack
->index
;
2035 size
= info
->type_stack
->size
;
2036 s
= stab_pop_type (info
);
2038 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 20);
2041 sprintf (buf
, "%s:t%s", name
, s
);
2044 index
= info
->type_index
;
2046 sprintf (buf
, "%s:t%ld=%s", name
, index
, s
);
2051 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2056 h
= string_hash_lookup (&info
->typedef_hash
, name
, TRUE
, FALSE
);
2059 non_fatal (_("string_hash_lookup failed: %s"),
2060 bfd_errmsg (bfd_get_error ()));
2064 /* I don't think we care about redefinitions. */
2079 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2082 s
= stab_pop_type (info
);
2084 buf
= (char *) xmalloc (strlen (tag
) + strlen (s
) + 3);
2086 sprintf (buf
, "%s:T%s", tag
, s
);
2089 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2097 /* Define an integer constant. */
2100 stab_int_constant (p
, name
, val
)
2105 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2108 buf
= (char *) xmalloc (strlen (name
) + 20);
2109 sprintf (buf
, "%s:c=i%ld", name
, (long) val
);
2111 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2119 /* Define a floating point constant. */
2122 stab_float_constant (p
, name
, val
)
2127 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2130 buf
= (char *) xmalloc (strlen (name
) + 20);
2131 sprintf (buf
, "%s:c=f%g", name
, val
);
2133 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2141 /* Define a typed constant. */
2144 stab_typed_constant (p
, name
, val
)
2149 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2152 s
= stab_pop_type (info
);
2154 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 20);
2155 sprintf (buf
, "%s:c=e%s,%ld", name
, s
, (long) val
);
2158 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2166 /* Record a variable. */
2169 stab_variable (p
, name
, kind
, val
)
2172 enum debug_var_kind kind
;
2175 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2178 const char *kindstr
;
2180 s
= stab_pop_type (info
);
2193 stab_type
= N_STSYM
;
2197 case DEBUG_LOCAL_STATIC
:
2198 stab_type
= N_STSYM
;
2206 /* Make sure that this is a type reference or definition. */
2212 index
= info
->type_index
;
2214 n
= (char *) xmalloc (strlen (s
) + 20);
2215 sprintf (n
, "%ld=%s", index
, s
);
2221 case DEBUG_REGISTER
:
2227 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 3);
2228 sprintf (buf
, "%s:%s%s", name
, kindstr
, s
);
2231 if (! stab_write_symbol (info
, stab_type
, 0, val
, buf
))
2239 /* Start outputting a function. */
2242 stab_start_function (p
, name
, globalp
)
2245 bfd_boolean globalp
;
2247 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2248 char *rettype
, *buf
;
2250 assert (info
->nesting
== 0 && info
->fun_offset
== -1);
2252 rettype
= stab_pop_type (info
);
2254 buf
= (char *) xmalloc (strlen (name
) + strlen (rettype
) + 3);
2255 sprintf (buf
, "%s:%c%s", name
,
2256 globalp
? 'F' : 'f',
2259 /* We don't know the value now, so we set it in start_block. */
2260 info
->fun_offset
= info
->symbols_size
;
2262 if (! stab_write_symbol (info
, N_FUN
, 0, 0, buf
))
2270 /* Output a function parameter. */
2273 stab_function_parameter (p
, name
, kind
, val
)
2276 enum debug_parm_kind kind
;
2279 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2284 s
= stab_pop_type (info
);
2291 case DEBUG_PARM_STACK
:
2296 case DEBUG_PARM_REG
:
2301 case DEBUG_PARM_REFERENCE
:
2306 case DEBUG_PARM_REF_REG
:
2312 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 3);
2313 sprintf (buf
, "%s:%c%s", name
, kindc
, s
);
2316 if (! stab_write_symbol (info
, stab_type
, 0, val
, buf
))
2324 /* Start a block. */
2327 stab_start_block (p
, addr
)
2331 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2333 /* Fill in any slots which have been waiting for the first known
2336 if (info
->so_offset
!= -1)
2338 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->so_offset
+ 8);
2339 info
->so_offset
= -1;
2342 if (info
->fun_offset
!= -1)
2344 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->fun_offset
+ 8);
2345 info
->fun_offset
= -1;
2350 /* We will be called with a top level block surrounding the
2351 function, but stabs information does not output that block, so we
2354 if (info
->nesting
== 1)
2356 info
->fnaddr
= addr
;
2360 /* We have to output the LBRAC symbol after any variables which are
2361 declared inside the block. We postpone the LBRAC until the next
2362 start_block or end_block. */
2364 /* If we have postponed an LBRAC, output it now. */
2365 if (info
->pending_lbrac
!= (bfd_vma
) -1)
2367 if (! stab_write_symbol (info
, N_LBRAC
, 0, info
->pending_lbrac
,
2368 (const char *) NULL
))
2372 /* Remember the address and output it later. */
2374 info
->pending_lbrac
= addr
- info
->fnaddr
;
2382 stab_end_block (p
, addr
)
2386 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2388 if (addr
> info
->last_text_address
)
2389 info
->last_text_address
= addr
;
2391 /* If we have postponed an LBRAC, output it now. */
2392 if (info
->pending_lbrac
!= (bfd_vma
) -1)
2394 if (! stab_write_symbol (info
, N_LBRAC
, 0, info
->pending_lbrac
,
2395 (const char *) NULL
))
2397 info
->pending_lbrac
= (bfd_vma
) -1;
2400 assert (info
->nesting
> 0);
2404 /* We ignore the outermost block. */
2405 if (info
->nesting
== 0)
2408 return stab_write_symbol (info
, N_RBRAC
, 0, addr
- info
->fnaddr
,
2409 (const char *) NULL
);
2412 /* End a function. */
2415 stab_end_function (p
)
2416 PTR p ATTRIBUTE_UNUSED
;
2421 /* Output a line number. */
2424 stab_lineno (p
, file
, lineno
, addr
)
2427 unsigned long lineno
;
2430 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2432 assert (info
->lineno_filename
!= NULL
);
2434 if (addr
> info
->last_text_address
)
2435 info
->last_text_address
= addr
;
2437 if (strcmp (file
, info
->lineno_filename
) != 0)
2439 if (! stab_write_symbol (info
, N_SOL
, 0, addr
, file
))
2441 info
->lineno_filename
= file
;
2444 return stab_write_symbol (info
, N_SLINE
, lineno
, addr
- info
->fnaddr
,
2445 (const char *) NULL
);