1 /* wrstabs.c -- Output stabs debugging information
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2006
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., 51 Franklin Street - Fifth Floor, 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 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
177 static bfd_boolean stab_write_symbol
178 (struct stab_write_handle
*, int, int, bfd_vma
, const char *);
179 static bfd_boolean stab_push_string
180 (struct stab_write_handle
*, const char *, long, bfd_boolean
, unsigned int);
181 static bfd_boolean stab_push_defined_type
182 (struct stab_write_handle
*, long, unsigned int);
183 static char *stab_pop_type (struct stab_write_handle
*);
184 static bfd_boolean stab_modify_type
185 (struct stab_write_handle
*, int, unsigned int, long **, size_t *);
186 static long stab_get_struct_index
187 (struct stab_write_handle
*, const char *, unsigned int,
188 enum debug_type_kind
, unsigned int *);
189 static bfd_boolean stab_class_method_var
190 (struct stab_write_handle
*, const char *, enum debug_visibility
,
191 bfd_boolean
, bfd_boolean
, bfd_boolean
, bfd_vma
, bfd_boolean
);
192 static bfd_boolean
stab_start_compilation_unit (void *, const char *);
193 static bfd_boolean
stab_start_source (void *, const char *);
194 static bfd_boolean
stab_empty_type (void *);
195 static bfd_boolean
stab_void_type (void *);
196 static bfd_boolean
stab_int_type (void *, unsigned int, bfd_boolean
);
197 static bfd_boolean
stab_float_type (void *, unsigned int);
198 static bfd_boolean
stab_complex_type (void *, unsigned int);
199 static bfd_boolean
stab_bool_type (void *, unsigned int);
200 static bfd_boolean stab_enum_type
201 (void *, const char *, const char **, bfd_signed_vma
*);
202 static bfd_boolean
stab_pointer_type (void *);
203 static bfd_boolean
stab_function_type (void *, int, bfd_boolean
);
204 static bfd_boolean
stab_reference_type (void *);
205 static bfd_boolean
stab_range_type (void *, bfd_signed_vma
, bfd_signed_vma
);
206 static bfd_boolean stab_array_type
207 (void *, bfd_signed_vma
, bfd_signed_vma
, bfd_boolean
);
208 static bfd_boolean
stab_set_type (void *, bfd_boolean
);
209 static bfd_boolean
stab_offset_type (void *);
210 static bfd_boolean
stab_method_type (void *, bfd_boolean
, int, bfd_boolean
);
211 static bfd_boolean
stab_const_type (void *);
212 static bfd_boolean
stab_volatile_type (void *);
213 static bfd_boolean stab_start_struct_type
214 (void *, const char *, unsigned int, bfd_boolean
, unsigned int);
215 static bfd_boolean stab_struct_field
216 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
217 static bfd_boolean
stab_end_struct_type (void *);
218 static bfd_boolean stab_start_class_type
219 (void *, const char *, unsigned int, bfd_boolean
, unsigned int,
220 bfd_boolean
, bfd_boolean
);
221 static bfd_boolean stab_class_static_member
222 (void *, const char *, const char *, enum debug_visibility
);
223 static bfd_boolean stab_class_baseclass
224 (void *, bfd_vma
, bfd_boolean
, enum debug_visibility
);
225 static bfd_boolean
stab_class_start_method (void *, const char *);
226 static bfd_boolean stab_class_method_variant
227 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
,
228 bfd_vma
, bfd_boolean
);
229 static bfd_boolean stab_class_static_method_variant
230 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
);
231 static bfd_boolean
stab_class_end_method (void *);
232 static bfd_boolean
stab_end_class_type (void *);
233 static bfd_boolean
stab_typedef_type (void *, const char *);
234 static bfd_boolean stab_tag_type
235 (void *, const char *, unsigned int, enum debug_type_kind
);
236 static bfd_boolean
stab_typdef (void *, const char *);
237 static bfd_boolean
stab_tag (void *, const char *);
238 static bfd_boolean
stab_int_constant (void *, const char *, bfd_vma
);
239 static bfd_boolean
stab_float_constant (void *, const char *, double);
240 static bfd_boolean
stab_typed_constant (void *, const char *, bfd_vma
);
241 static bfd_boolean stab_variable
242 (void *, const char *, enum debug_var_kind
, bfd_vma
);
243 static bfd_boolean
stab_start_function (void *, const char *, bfd_boolean
);
244 static bfd_boolean stab_function_parameter
245 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
246 static bfd_boolean
stab_start_block (void *, bfd_vma
);
247 static bfd_boolean
stab_end_block (void *, bfd_vma
);
248 static bfd_boolean
stab_end_function (void *);
249 static bfd_boolean
stab_lineno (void *, const char *, unsigned long, bfd_vma
);
251 static const struct debug_write_fns stab_fns
=
253 stab_start_compilation_unit
,
272 stab_start_struct_type
,
274 stab_end_struct_type
,
275 stab_start_class_type
,
276 stab_class_static_member
,
277 stab_class_baseclass
,
278 stab_class_start_method
,
279 stab_class_method_variant
,
280 stab_class_static_method_variant
,
281 stab_class_end_method
,
292 stab_function_parameter
,
299 /* Routine to create an entry in a string hash table. */
301 static struct bfd_hash_entry
*
302 string_hash_newfunc (struct bfd_hash_entry
*entry
,
303 struct bfd_hash_table
*table
, const char *string
)
305 struct string_hash_entry
*ret
= (struct string_hash_entry
*) entry
;
307 /* Allocate the structure if it has not already been allocated by a
309 if (ret
== (struct string_hash_entry
*) NULL
)
310 ret
= ((struct string_hash_entry
*)
311 bfd_hash_allocate (table
, sizeof (struct string_hash_entry
)));
312 if (ret
== (struct string_hash_entry
*) NULL
)
315 /* Call the allocation method of the superclass. */
316 ret
= ((struct string_hash_entry
*)
317 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
321 /* Initialize the local fields. */
327 return (struct bfd_hash_entry
*) ret
;
330 /* Look up an entry in a string hash table. */
332 #define string_hash_lookup(t, string, create, copy) \
333 ((struct string_hash_entry *) \
334 bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
336 /* Add a symbol to the stabs debugging information we are building. */
339 stab_write_symbol (struct stab_write_handle
*info
, int type
, int desc
,
340 bfd_vma value
, const char *string
)
343 bfd_byte sym
[STAB_SYMBOL_SIZE
];
349 struct string_hash_entry
*h
;
351 h
= string_hash_lookup (&info
->strhash
, string
, TRUE
, TRUE
);
354 non_fatal (_("string_hash_lookup failed: %s"),
355 bfd_errmsg (bfd_get_error ()));
362 strx
= info
->strings_size
;
364 if (info
->last_string
== NULL
)
367 info
->last_string
->next
= h
;
368 info
->last_string
= h
;
369 info
->strings_size
+= strlen (string
) + 1;
373 /* This presumes 32 bit values. */
374 bfd_put_32 (info
->abfd
, strx
, sym
);
375 bfd_put_8 (info
->abfd
, type
, sym
+ 4);
376 bfd_put_8 (info
->abfd
, 0, sym
+ 5);
377 bfd_put_16 (info
->abfd
, desc
, sym
+ 6);
378 bfd_put_32 (info
->abfd
, value
, sym
+ 8);
380 if (info
->symbols_size
+ STAB_SYMBOL_SIZE
> info
->symbols_alloc
)
382 info
->symbols_alloc
*= 2;
383 info
->symbols
= (bfd_byte
*) xrealloc (info
->symbols
,
384 info
->symbols_alloc
);
387 memcpy (info
->symbols
+ info
->symbols_size
, sym
, STAB_SYMBOL_SIZE
);
389 info
->symbols_size
+= STAB_SYMBOL_SIZE
;
394 /* Push a string on to the type stack. */
397 stab_push_string (struct stab_write_handle
*info
, const char *string
,
398 long index
, bfd_boolean definition
, unsigned int size
)
400 struct stab_type_stack
*s
;
402 s
= (struct stab_type_stack
*) xmalloc (sizeof *s
);
403 s
->string
= xstrdup (string
);
405 s
->definition
= definition
;
409 s
->baseclasses
= NULL
;
413 s
->next
= info
->type_stack
;
414 info
->type_stack
= s
;
419 /* Push a type index which has already been defined. */
422 stab_push_defined_type (struct stab_write_handle
*info
, long index
,
427 sprintf (buf
, "%ld", index
);
428 return stab_push_string (info
, buf
, index
, FALSE
, size
);
431 /* Pop a type off the type stack. The caller is responsible for
432 freeing the string. */
435 stab_pop_type (struct stab_write_handle
*info
)
437 struct stab_type_stack
*s
;
440 s
= info
->type_stack
;
443 info
->type_stack
= s
->next
;
452 /* The general routine to write out stabs in sections debugging
453 information. This accumulates the stabs symbols and the strings in
454 two obstacks. We can't easily write out the information as we go
455 along, because we need to know the section sizes before we can
456 write out the section contents. ABFD is the BFD and DHANDLE is the
457 handle for the debugging information. This sets *PSYMS to point to
458 the symbols, *PSYMSIZE the size of the symbols, *PSTRINGS to the
459 strings, and *PSTRINGSIZE to the size of the strings. */
462 write_stabs_in_sections_debugging_info (bfd
*abfd
, void *dhandle
,
464 bfd_size_type
*psymsize
,
466 bfd_size_type
*pstringsize
)
468 struct stab_write_handle info
;
469 struct string_hash_entry
*h
;
474 info
.symbols_size
= 0;
475 info
.symbols_alloc
= 500;
476 info
.symbols
= (bfd_byte
*) xmalloc (info
.symbols_alloc
);
479 info
.last_string
= NULL
;
480 /* Reserve 1 byte for a null byte. */
481 info
.strings_size
= 1;
483 if (!bfd_hash_table_init (&info
.strhash
.table
, string_hash_newfunc
,
484 sizeof (struct string_hash_entry
))
485 || !bfd_hash_table_init (&info
.typedef_hash
.table
, string_hash_newfunc
,
486 sizeof (struct string_hash_entry
)))
488 non_fatal ("bfd_hash_table_init_failed: %s",
489 bfd_errmsg (bfd_get_error ()));
493 info
.type_stack
= NULL
;
495 memset (&info
.type_cache
, 0, sizeof info
.type_cache
);
497 info
.fun_offset
= -1;
498 info
.last_text_address
= 0;
501 info
.pending_lbrac
= (bfd_vma
) -1;
503 /* The initial symbol holds the string size. */
504 if (! stab_write_symbol (&info
, 0, 0, 0, (const char *) NULL
))
507 /* Output an initial N_SO symbol. */
508 info
.so_offset
= info
.symbols_size
;
509 if (! stab_write_symbol (&info
, N_SO
, 0, 0, bfd_get_filename (abfd
)))
512 if (! debug_write (dhandle
, &stab_fns
, (void *) &info
))
515 assert (info
.pending_lbrac
== (bfd_vma
) -1);
517 /* Output a trailing N_SO. */
518 if (! stab_write_symbol (&info
, N_SO
, 0, info
.last_text_address
,
519 (const char *) NULL
))
522 /* Put the string size in the initial symbol. */
523 bfd_put_32 (abfd
, info
.strings_size
, info
.symbols
+ 8);
525 *psyms
= info
.symbols
;
526 *psymsize
= info
.symbols_size
;
528 *pstringsize
= info
.strings_size
;
529 *pstrings
= (bfd_byte
*) xmalloc (info
.strings_size
);
533 for (h
= info
.strings
; h
!= NULL
; h
= h
->next
)
535 strcpy ((char *) p
, h
->root
.string
);
536 p
+= strlen ((char *) p
) + 1;
542 /* Start writing out information for a compilation unit. */
545 stab_start_compilation_unit (void *p
, const char *filename
)
547 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
549 /* We would normally output an N_SO symbol here. However, that
550 would force us to reset all of our type information. I think we
551 will be better off just outputting an N_SOL symbol, and not
552 worrying about splitting information between files. */
554 info
->lineno_filename
= filename
;
556 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
559 /* Start writing out information for a particular source file. */
562 stab_start_source (void *p
, const char *filename
)
564 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
566 /* FIXME: The symbol's value is supposed to be the text section
567 address. However, we would have to fill it in later, and gdb
568 doesn't care, so we don't bother with it. */
570 info
->lineno_filename
= filename
;
572 return stab_write_symbol (info
, N_SOL
, 0, 0, filename
);
575 /* Push an empty type. This shouldn't normally happen. We just use a
579 stab_empty_type (void *p
)
581 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
583 /* We don't call stab_void_type if the type is not yet defined,
584 because that might screw up the typedef. */
586 if (info
->type_cache
.void_type
!= 0)
587 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
593 index
= info
->type_index
;
596 sprintf (buf
, "%ld=%ld", index
, index
);
598 return stab_push_string (info
, buf
, index
, FALSE
, 0);
602 /* Push a void type. */
605 stab_void_type (void *p
)
607 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
609 if (info
->type_cache
.void_type
!= 0)
610 return stab_push_defined_type (info
, info
->type_cache
.void_type
, 0);
616 index
= info
->type_index
;
619 info
->type_cache
.void_type
= index
;
621 sprintf (buf
, "%ld=%ld", index
, index
);
623 return stab_push_string (info
, buf
, index
, TRUE
, 0);
627 /* Push an integer type. */
630 stab_int_type (void *p
, unsigned int size
, bfd_boolean unsignedp
)
632 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
635 if (size
<= 0 || (size
> sizeof (long) && size
!= 8))
637 non_fatal (_("stab_int_type: bad size %u"), size
);
642 cache
= info
->type_cache
.signed_integer_types
;
644 cache
= info
->type_cache
.unsigned_integer_types
;
646 if (cache
[size
- 1] != 0)
647 return stab_push_defined_type (info
, cache
[size
- 1], size
);
653 index
= info
->type_index
;
656 cache
[size
- 1] = index
;
658 sprintf (buf
, "%ld=r%ld;", index
, index
);
662 if (size
< sizeof (long))
663 sprintf (buf
+ strlen (buf
), "%ld;", ((long) 1 << (size
* 8)) - 1);
664 else if (size
== sizeof (long))
667 strcat (buf
, "01777777777777777777777;");
673 if (size
<= sizeof (long))
674 sprintf (buf
+ strlen (buf
), "%ld;%ld;",
675 (long) - ((unsigned long) 1 << (size
* 8 - 1)),
676 (long) (((unsigned long) 1 << (size
* 8 - 1)) - 1));
678 strcat (buf
, "01000000000000000000000;0777777777777777777777;");
683 return stab_push_string (info
, buf
, index
, TRUE
, size
);
687 /* Push a floating point type. */
690 stab_float_type (void *p
, unsigned int size
)
692 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
695 && size
- 1 < (sizeof info
->type_cache
.float_types
696 / sizeof info
->type_cache
.float_types
[0])
697 && info
->type_cache
.float_types
[size
- 1] != 0)
698 return stab_push_defined_type (info
,
699 info
->type_cache
.float_types
[size
- 1],
707 /* Floats are defined as a subrange of int. */
708 if (! stab_int_type (info
, 4, FALSE
))
710 int_type
= stab_pop_type (info
);
712 index
= info
->type_index
;
716 && size
- 1 < (sizeof info
->type_cache
.float_types
717 / sizeof info
->type_cache
.float_types
[0]))
718 info
->type_cache
.float_types
[size
- 1] = index
;
720 sprintf (buf
, "%ld=r%s;%u;0;", index
, int_type
, size
);
724 return stab_push_string (info
, buf
, index
, TRUE
, size
);
728 /* Push a complex type. */
731 stab_complex_type (void *p
, unsigned int size
)
733 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
737 index
= info
->type_index
;
740 sprintf (buf
, "%ld=r%ld;%u;0;", index
, index
, size
);
742 return stab_push_string (info
, buf
, index
, TRUE
, size
* 2);
745 /* Push a bfd_boolean type. We use an XCOFF predefined type, since gdb
746 always recognizes them. */
749 stab_bool_type (void *p
, unsigned int size
)
751 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
774 return stab_push_defined_type (info
, index
, size
);
777 /* Push an enum type. */
780 stab_enum_type (void *p
, const char *tag
, const char **names
,
781 bfd_signed_vma
*vals
)
783 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
792 assert (tag
!= NULL
);
794 buf
= (char *) xmalloc (10 + strlen (tag
));
795 sprintf (buf
, "xe%s:", tag
);
796 /* FIXME: The size is just a guess. */
797 if (! stab_push_string (info
, buf
, 0, FALSE
, 4))
806 for (pn
= names
; *pn
!= NULL
; pn
++)
807 len
+= strlen (*pn
) + 20;
809 buf
= (char *) xmalloc (len
);
815 index
= info
->type_index
;
817 sprintf (buf
, "%s:T%ld=e", tag
, index
);
820 for (pn
= names
, pv
= vals
; *pn
!= NULL
; pn
++, pv
++)
821 sprintf (buf
+ strlen (buf
), "%s:%ld,", *pn
, (long) *pv
);
826 /* FIXME: The size is just a guess. */
827 if (! stab_push_string (info
, buf
, 0, FALSE
, 4))
832 /* FIXME: The size is just a guess. */
833 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
)
834 || ! stab_push_defined_type (info
, index
, 4))
843 /* Push a modification of the top type on the stack. Cache the
844 results in CACHE and CACHE_ALLOC. */
847 stab_modify_type (struct stab_write_handle
*info
, int mod
,
848 unsigned int size
, long **cache
, size_t *cache_alloc
)
854 assert (info
->type_stack
!= NULL
);
855 targindex
= info
->type_stack
->index
;
860 bfd_boolean definition
;
862 /* Either the target type has no index, or we aren't caching
863 this modifier. Either way we have no way of recording the
864 new type, so we don't bother to define one. */
865 definition
= info
->type_stack
->definition
;
866 s
= stab_pop_type (info
);
867 buf
= (char *) xmalloc (strlen (s
) + 2);
868 sprintf (buf
, "%c%s", mod
, s
);
870 if (! stab_push_string (info
, buf
, 0, definition
, size
))
876 if ((size_t) targindex
>= *cache_alloc
)
880 alloc
= *cache_alloc
;
883 while ((size_t) targindex
>= alloc
)
885 *cache
= (long *) xrealloc (*cache
, alloc
* sizeof (long));
886 memset (*cache
+ *cache_alloc
, 0,
887 (alloc
- *cache_alloc
) * sizeof (long));
888 *cache_alloc
= alloc
;
891 index
= (*cache
)[targindex
];
892 if (index
!= 0 && ! info
->type_stack
->definition
)
894 /* We have already defined a modification of this type, and
895 the entry on the type stack is not a definition, so we
896 can safely discard it (we may have a definition on the
897 stack, even if we already defined a modification, if it
898 is a struct which we did not define at the time it was
900 free (stab_pop_type (info
));
901 if (! stab_push_defined_type (info
, index
, size
))
906 index
= info
->type_index
;
909 s
= stab_pop_type (info
);
910 buf
= (char *) xmalloc (strlen (s
) + 20);
911 sprintf (buf
, "%ld=%c%s", index
, mod
, s
);
914 (*cache
)[targindex
] = index
;
916 if (! stab_push_string (info
, buf
, index
, TRUE
, size
))
926 /* Push a pointer type. */
929 stab_pointer_type (void *p
)
931 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
933 /* FIXME: The size should depend upon the architecture. */
934 return stab_modify_type (info
, '*', 4, &info
->type_cache
.pointer_types
,
935 &info
->type_cache
.pointer_types_alloc
);
938 /* Push a function type. */
941 stab_function_type (void *p
, int argcount
,
942 bfd_boolean varargs ATTRIBUTE_UNUSED
)
944 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
947 /* We have no way to represent the argument types, so we just
948 discard them. However, if they define new types, we must output
949 them. We do this by producing empty typedefs. */
950 for (i
= 0; i
< argcount
; i
++)
952 if (! info
->type_stack
->definition
)
953 free (stab_pop_type (info
));
958 s
= stab_pop_type (info
);
960 buf
= (char *) xmalloc (strlen (s
) + 3);
961 sprintf (buf
, ":t%s", s
);
964 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
971 return stab_modify_type (info
, 'f', 0, &info
->type_cache
.function_types
,
972 &info
->type_cache
.function_types_alloc
);
975 /* Push a reference type. */
978 stab_reference_type (void *p
)
980 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
982 /* FIXME: The size should depend upon the architecture. */
983 return stab_modify_type (info
, '&', 4, &info
->type_cache
.reference_types
,
984 &info
->type_cache
.reference_types_alloc
);
987 /* Push a range type. */
990 stab_range_type (void *p
, bfd_signed_vma low
, bfd_signed_vma high
)
992 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
993 bfd_boolean definition
;
997 definition
= info
->type_stack
->definition
;
998 size
= info
->type_stack
->size
;
1000 s
= stab_pop_type (info
);
1001 buf
= (char *) xmalloc (strlen (s
) + 100);
1002 sprintf (buf
, "r%s;%ld;%ld;", s
, (long) low
, (long) high
);
1005 if (! stab_push_string (info
, buf
, 0, definition
, size
))
1013 /* Push an array type. */
1016 stab_array_type (void *p
, bfd_signed_vma low
, bfd_signed_vma high
,
1017 bfd_boolean stringp
)
1019 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1020 bfd_boolean definition
;
1021 unsigned int element_size
;
1022 char *range
, *element
, *buf
;
1026 definition
= info
->type_stack
->definition
;
1027 range
= stab_pop_type (info
);
1029 definition
= definition
|| info
->type_stack
->definition
;
1030 element_size
= info
->type_stack
->size
;
1031 element
= stab_pop_type (info
);
1033 buf
= (char *) xmalloc (strlen (range
) + strlen (element
) + 100);
1042 /* We need to define a type in order to include the string
1044 index
= info
->type_index
;
1047 sprintf (buf
, "%ld=@S;", index
);
1050 sprintf (buf
+ strlen (buf
), "ar%s;%ld;%ld;%s",
1051 range
, (long) low
, (long) high
, element
);
1058 size
= element_size
* ((high
- low
) + 1);
1059 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1067 /* Push a set type. */
1070 stab_set_type (void *p
, bfd_boolean bitstringp
)
1072 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1073 bfd_boolean definition
;
1077 definition
= info
->type_stack
->definition
;
1079 s
= stab_pop_type (info
);
1080 buf
= (char *) xmalloc (strlen (s
) + 30);
1089 /* We need to define a type in order to include the string
1091 index
= info
->type_index
;
1094 sprintf (buf
, "%ld=@S;", index
);
1097 sprintf (buf
+ strlen (buf
), "S%s", s
);
1100 if (! stab_push_string (info
, buf
, index
, definition
, 0))
1108 /* Push an offset type. */
1111 stab_offset_type (void *p
)
1113 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1114 bfd_boolean definition
;
1115 char *target
, *base
, *buf
;
1117 definition
= info
->type_stack
->definition
;
1118 target
= stab_pop_type (info
);
1120 definition
= definition
|| info
->type_stack
->definition
;
1121 base
= stab_pop_type (info
);
1123 buf
= (char *) xmalloc (strlen (target
) + strlen (base
) + 3);
1124 sprintf (buf
, "@%s,%s", base
, target
);
1128 if (! stab_push_string (info
, buf
, 0, definition
, 0))
1136 /* Push a method type. */
1139 stab_method_type (void *p
, bfd_boolean domainp
, int argcount
,
1140 bfd_boolean varargs
)
1142 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1143 bfd_boolean definition
;
1144 char *domain
, *return_type
, *buf
;
1149 /* We don't bother with stub method types, because that would
1150 require a mangler for C++ argument types. This will waste space
1151 in the debugging output. */
1153 /* We need a domain. I'm not sure DOMAINP can ever be false,
1157 if (! stab_empty_type (p
))
1161 definition
= info
->type_stack
->definition
;
1162 domain
= stab_pop_type (info
);
1164 /* A non-varargs function is indicated by making the last parameter
1172 else if (argcount
== 0)
1178 args
= (char **) xmalloc (1 * sizeof (*args
));
1179 if (! stab_empty_type (p
))
1181 definition
= definition
|| info
->type_stack
->definition
;
1182 args
[0] = stab_pop_type (info
);
1188 args
= (char **) xmalloc ((argcount
+ 1) * sizeof (*args
));
1189 for (i
= argcount
- 1; i
>= 0; i
--)
1191 definition
= definition
|| info
->type_stack
->definition
;
1192 args
[i
] = stab_pop_type (info
);
1196 if (! stab_empty_type (p
))
1198 definition
= definition
|| info
->type_stack
->definition
;
1199 args
[argcount
] = stab_pop_type (info
);
1204 definition
= definition
|| info
->type_stack
->definition
;
1205 return_type
= stab_pop_type (info
);
1207 len
= strlen (domain
) + strlen (return_type
) + 10;
1208 for (i
= 0; i
< argcount
; i
++)
1209 len
+= strlen (args
[i
]);
1211 buf
= (char *) xmalloc (len
);
1213 sprintf (buf
, "#%s,%s", domain
, return_type
);
1216 for (i
= 0; i
< argcount
; i
++)
1219 strcat (buf
, args
[i
]);
1227 if (! stab_push_string (info
, buf
, 0, definition
, 0))
1235 /* Push a const version of a type. */
1238 stab_const_type (void *p
)
1240 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1242 return stab_modify_type (info
, 'k', info
->type_stack
->size
,
1243 (long **) NULL
, (size_t *) NULL
);
1246 /* Push a volatile version of a type. */
1249 stab_volatile_type (void *p
)
1251 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1253 return stab_modify_type (info
, 'B', info
->type_stack
->size
,
1254 (long **) NULL
, (size_t *) NULL
);
1257 /* Get the type index to use for a struct/union/class ID. This should
1258 return -1 if it fails. */
1261 stab_get_struct_index (struct stab_write_handle
*info
, const char *tag
,
1262 unsigned int id
, enum debug_type_kind kind
,
1263 unsigned int *psize
)
1265 if (id
>= info
->type_cache
.struct_types_alloc
)
1269 alloc
= info
->type_cache
.struct_types_alloc
;
1274 info
->type_cache
.struct_types
=
1275 (struct stab_tag
*) xrealloc (info
->type_cache
.struct_types
,
1276 alloc
* sizeof (struct stab_tag
));
1277 memset ((info
->type_cache
.struct_types
1278 + info
->type_cache
.struct_types_alloc
),
1280 ((alloc
- info
->type_cache
.struct_types_alloc
)
1281 * sizeof (struct stab_tag
)));
1282 info
->type_cache
.struct_types_alloc
= alloc
;
1285 if (info
->type_cache
.struct_types
[id
].index
== 0)
1287 info
->type_cache
.struct_types
[id
].index
= info
->type_index
;
1289 info
->type_cache
.struct_types
[id
].tag
= tag
;
1290 info
->type_cache
.struct_types
[id
].kind
= kind
;
1293 if (kind
== DEBUG_KIND_ILLEGAL
)
1295 /* This is a definition of the struct. */
1296 info
->type_cache
.struct_types
[id
].kind
= kind
;
1297 info
->type_cache
.struct_types
[id
].size
= *psize
;
1300 *psize
= info
->type_cache
.struct_types
[id
].size
;
1302 return info
->type_cache
.struct_types
[id
].index
;
1305 /* Start outputting a struct. We ignore the tag, and handle it in
1309 stab_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1310 bfd_boolean structp
, unsigned int size
)
1312 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1314 bfd_boolean definition
;
1317 buf
= (char *) xmalloc (40);
1327 index
= stab_get_struct_index (info
, tag
, id
, DEBUG_KIND_ILLEGAL
,
1331 sprintf (buf
, "%ld=", index
);
1335 sprintf (buf
+ strlen (buf
), "%c%u",
1336 structp
? 's' : 'u',
1339 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1342 info
->type_stack
->fields
= (char *) xmalloc (1);
1343 info
->type_stack
->fields
[0] = '\0';
1348 /* Add a field to a struct. */
1351 stab_struct_field (void *p
, const char *name
, bfd_vma bitpos
,
1352 bfd_vma bitsize
, enum debug_visibility visibility
)
1354 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1355 bfd_boolean definition
;
1360 definition
= info
->type_stack
->definition
;
1361 size
= info
->type_stack
->size
;
1362 s
= stab_pop_type (info
);
1364 /* Add this field to the end of the current struct fields, which is
1365 currently on the top of the stack. */
1367 assert (info
->type_stack
->fields
!= NULL
);
1368 n
= (char *) xmalloc (strlen (info
->type_stack
->fields
)
1378 case DEBUG_VISIBILITY_PUBLIC
:
1382 case DEBUG_VISIBILITY_PRIVATE
:
1386 case DEBUG_VISIBILITY_PROTECTED
:
1395 non_fatal (_("%s: warning: unknown size for field `%s' in struct"),
1396 bfd_get_filename (info
->abfd
), name
);
1399 sprintf (n
, "%s%s:%s%s,%ld,%ld;", info
->type_stack
->fields
, name
, vis
, s
,
1400 (long) bitpos
, (long) bitsize
);
1402 free (info
->type_stack
->fields
);
1403 info
->type_stack
->fields
= n
;
1406 info
->type_stack
->definition
= TRUE
;
1411 /* Finish up a struct. */
1414 stab_end_struct_type (void *p
)
1416 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1417 bfd_boolean definition
;
1420 char *fields
, *first
, *buf
;
1422 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1424 definition
= info
->type_stack
->definition
;
1425 index
= info
->type_stack
->index
;
1426 size
= info
->type_stack
->size
;
1427 fields
= info
->type_stack
->fields
;
1428 first
= stab_pop_type (info
);
1430 buf
= (char *) xmalloc (strlen (first
) + strlen (fields
) + 2);
1431 sprintf (buf
, "%s%s;", first
, fields
);
1435 if (! stab_push_string (info
, buf
, index
, definition
, size
))
1443 /* Start outputting a class. */
1446 stab_start_class_type (void *p
, const char *tag
, unsigned int id
, bfd_boolean structp
, unsigned int size
, bfd_boolean vptr
, bfd_boolean ownvptr
)
1448 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1449 bfd_boolean definition
;
1452 if (! vptr
|| ownvptr
)
1459 definition
= info
->type_stack
->definition
;
1460 vstring
= stab_pop_type (info
);
1463 if (! stab_start_struct_type (p
, tag
, id
, structp
, size
))
1472 assert (info
->type_stack
->index
> 0);
1473 vtable
= (char *) xmalloc (20);
1474 sprintf (vtable
, "~%%%ld", info
->type_stack
->index
);
1478 vtable
= (char *) xmalloc (strlen (vstring
) + 3);
1479 sprintf (vtable
, "~%%%s", vstring
);
1483 info
->type_stack
->vtable
= vtable
;
1487 info
->type_stack
->definition
= TRUE
;
1492 /* Add a static member to the class on the type stack. */
1495 stab_class_static_member (void *p
, const char *name
, const char *physname
,
1496 enum debug_visibility visibility
)
1498 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1499 bfd_boolean definition
;
1503 definition
= info
->type_stack
->definition
;
1504 s
= stab_pop_type (info
);
1506 /* Add this field to the end of the current struct fields, which is
1507 currently on the top of the stack. */
1509 assert (info
->type_stack
->fields
!= NULL
);
1510 n
= (char *) xmalloc (strlen (info
->type_stack
->fields
)
1521 case DEBUG_VISIBILITY_PUBLIC
:
1525 case DEBUG_VISIBILITY_PRIVATE
:
1529 case DEBUG_VISIBILITY_PROTECTED
:
1534 sprintf (n
, "%s%s:%s%s:%s;", info
->type_stack
->fields
, name
, vis
, s
,
1537 free (info
->type_stack
->fields
);
1538 info
->type_stack
->fields
= n
;
1541 info
->type_stack
->definition
= TRUE
;
1546 /* Add a base class to the class on the type stack. */
1549 stab_class_baseclass (void *p
, bfd_vma bitpos
, bfd_boolean
virtual,
1550 enum debug_visibility visibility
)
1552 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1553 bfd_boolean definition
;
1559 definition
= info
->type_stack
->definition
;
1560 s
= stab_pop_type (info
);
1562 /* Build the base class specifier. */
1564 buf
= (char *) xmalloc (strlen (s
) + 25);
1565 buf
[0] = virtual ? '1' : '0';
1571 case DEBUG_VISIBILITY_PRIVATE
:
1575 case DEBUG_VISIBILITY_PROTECTED
:
1579 case DEBUG_VISIBILITY_PUBLIC
:
1584 sprintf (buf
+ 2, "%ld,%s;", (long) bitpos
, s
);
1587 /* Add the new baseclass to the existing ones. */
1589 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1591 if (info
->type_stack
->baseclasses
== NULL
)
1596 while (info
->type_stack
->baseclasses
[c
] != NULL
)
1600 baseclasses
= (char **) xrealloc (info
->type_stack
->baseclasses
,
1601 (c
+ 2) * sizeof (*baseclasses
));
1602 baseclasses
[c
] = buf
;
1603 baseclasses
[c
+ 1] = NULL
;
1605 info
->type_stack
->baseclasses
= baseclasses
;
1608 info
->type_stack
->definition
= TRUE
;
1613 /* Start adding a method to the class on the type stack. */
1616 stab_class_start_method (void *p
, const char *name
)
1618 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1621 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1623 if (info
->type_stack
->methods
== NULL
)
1625 m
= (char *) xmalloc (strlen (name
) + 3);
1630 m
= (char *) xrealloc (info
->type_stack
->methods
,
1631 (strlen (info
->type_stack
->methods
)
1636 sprintf (m
+ strlen (m
), "%s::", name
);
1638 info
->type_stack
->methods
= m
;
1643 /* Add a variant, either static or not, to the current method. */
1646 stab_class_method_var (struct stab_write_handle
*info
, const char *physname
,
1647 enum debug_visibility visibility
,
1648 bfd_boolean staticp
, bfd_boolean constp
,
1649 bfd_boolean volatilep
, bfd_vma voffset
,
1650 bfd_boolean contextp
)
1652 bfd_boolean definition
;
1654 char *context
= NULL
;
1655 char visc
, qualc
, typec
;
1657 definition
= info
->type_stack
->definition
;
1658 type
= stab_pop_type (info
);
1662 definition
= definition
|| info
->type_stack
->definition
;
1663 context
= stab_pop_type (info
);
1666 assert (info
->type_stack
!= NULL
&& info
->type_stack
->methods
!= NULL
);
1673 case DEBUG_VISIBILITY_PRIVATE
:
1677 case DEBUG_VISIBILITY_PROTECTED
:
1681 case DEBUG_VISIBILITY_PUBLIC
:
1703 else if (! contextp
)
1708 info
->type_stack
->methods
=
1709 (char *) xrealloc (info
->type_stack
->methods
,
1710 (strlen (info
->type_stack
->methods
)
1713 + (contextp
? strlen (context
) : 0)
1716 sprintf (info
->type_stack
->methods
+ strlen (info
->type_stack
->methods
),
1717 "%s:%s;%c%c%c", type
, physname
, visc
, qualc
, typec
);
1722 sprintf (info
->type_stack
->methods
+ strlen (info
->type_stack
->methods
),
1723 "%ld;%s;", (long) voffset
, context
);
1728 info
->type_stack
->definition
= TRUE
;
1733 /* Add a variant to the current method. */
1736 stab_class_method_variant (void *p
, const char *physname
,
1737 enum debug_visibility visibility
,
1738 bfd_boolean constp
, bfd_boolean volatilep
,
1739 bfd_vma voffset
, bfd_boolean contextp
)
1741 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1743 return stab_class_method_var (info
, physname
, visibility
, FALSE
, constp
,
1744 volatilep
, voffset
, contextp
);
1747 /* Add a static variant to the current method. */
1750 stab_class_static_method_variant (void *p
, const char *physname
,
1751 enum debug_visibility visibility
,
1752 bfd_boolean constp
, bfd_boolean volatilep
)
1754 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1756 return stab_class_method_var (info
, physname
, visibility
, TRUE
, constp
,
1757 volatilep
, 0, FALSE
);
1760 /* Finish up a method. */
1763 stab_class_end_method (void *p
)
1765 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1767 assert (info
->type_stack
!= NULL
&& info
->type_stack
->methods
!= NULL
);
1769 /* We allocated enough room on info->type_stack->methods to add the
1770 trailing semicolon. */
1771 strcat (info
->type_stack
->methods
, ";");
1776 /* Finish up a class. */
1779 stab_end_class_type (void *p
)
1781 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1786 assert (info
->type_stack
!= NULL
&& info
->type_stack
->fields
!= NULL
);
1788 /* Work out the size we need to allocate for the class definition. */
1790 len
= (strlen (info
->type_stack
->string
)
1791 + strlen (info
->type_stack
->fields
)
1793 if (info
->type_stack
->baseclasses
!= NULL
)
1796 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1797 len
+= strlen (info
->type_stack
->baseclasses
[i
]);
1799 if (info
->type_stack
->methods
!= NULL
)
1800 len
+= strlen (info
->type_stack
->methods
);
1801 if (info
->type_stack
->vtable
!= NULL
)
1802 len
+= strlen (info
->type_stack
->vtable
);
1804 /* Build the class definition. */
1806 buf
= (char *) xmalloc (len
);
1808 strcpy (buf
, info
->type_stack
->string
);
1810 if (info
->type_stack
->baseclasses
!= NULL
)
1812 sprintf (buf
+ strlen (buf
), "!%u,", i
);
1813 for (i
= 0; info
->type_stack
->baseclasses
[i
] != NULL
; i
++)
1815 strcat (buf
, info
->type_stack
->baseclasses
[i
]);
1816 free (info
->type_stack
->baseclasses
[i
]);
1818 free (info
->type_stack
->baseclasses
);
1819 info
->type_stack
->baseclasses
= NULL
;
1822 strcat (buf
, info
->type_stack
->fields
);
1823 free (info
->type_stack
->fields
);
1824 info
->type_stack
->fields
= NULL
;
1826 if (info
->type_stack
->methods
!= NULL
)
1828 strcat (buf
, info
->type_stack
->methods
);
1829 free (info
->type_stack
->methods
);
1830 info
->type_stack
->methods
= NULL
;
1835 if (info
->type_stack
->vtable
!= NULL
)
1837 strcat (buf
, info
->type_stack
->vtable
);
1838 free (info
->type_stack
->vtable
);
1839 info
->type_stack
->vtable
= NULL
;
1842 /* Replace the string on the top of the stack with the complete
1843 class definition. */
1844 free (info
->type_stack
->string
);
1845 info
->type_stack
->string
= buf
;
1850 /* Push a typedef which was previously defined. */
1853 stab_typedef_type (void *p
, const char *name
)
1855 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1856 struct string_hash_entry
*h
;
1858 h
= string_hash_lookup (&info
->typedef_hash
, name
, FALSE
, FALSE
);
1859 assert (h
!= NULL
&& h
->index
> 0);
1861 return stab_push_defined_type (info
, h
->index
, h
->size
);
1864 /* Push a struct, union or class tag. */
1867 stab_tag_type (void *p
, const char *name
, unsigned int id
,
1868 enum debug_type_kind kind
)
1870 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1872 unsigned int size
= 0;
1874 index
= stab_get_struct_index (info
, name
, id
, kind
, &size
);
1878 return stab_push_defined_type (info
, index
, size
);
1881 /* Define a typedef. */
1884 stab_typdef (void *p
, const char *name
)
1886 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1890 struct string_hash_entry
*h
;
1892 index
= info
->type_stack
->index
;
1893 size
= info
->type_stack
->size
;
1894 s
= stab_pop_type (info
);
1896 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 20);
1899 sprintf (buf
, "%s:t%s", name
, s
);
1902 index
= info
->type_index
;
1904 sprintf (buf
, "%s:t%ld=%s", name
, index
, s
);
1909 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
1914 h
= string_hash_lookup (&info
->typedef_hash
, name
, TRUE
, FALSE
);
1917 non_fatal (_("string_hash_lookup failed: %s"),
1918 bfd_errmsg (bfd_get_error ()));
1922 /* I don't think we care about redefinitions. */
1933 stab_tag (void *p
, const char *tag
)
1935 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1938 s
= stab_pop_type (info
);
1940 buf
= (char *) xmalloc (strlen (tag
) + strlen (s
) + 3);
1942 sprintf (buf
, "%s:T%s", tag
, s
);
1945 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
1953 /* Define an integer constant. */
1956 stab_int_constant (void *p
, const char *name
, bfd_vma val
)
1958 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1961 buf
= (char *) xmalloc (strlen (name
) + 20);
1962 sprintf (buf
, "%s:c=i%ld", name
, (long) val
);
1964 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
1972 /* Define a floating point constant. */
1975 stab_float_constant (void *p
, const char *name
, double val
)
1977 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1980 buf
= (char *) xmalloc (strlen (name
) + 20);
1981 sprintf (buf
, "%s:c=f%g", name
, val
);
1983 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
1991 /* Define a typed constant. */
1994 stab_typed_constant (void *p
, const char *name
, bfd_vma val
)
1996 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
1999 s
= stab_pop_type (info
);
2001 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 20);
2002 sprintf (buf
, "%s:c=e%s,%ld", name
, s
, (long) val
);
2005 if (! stab_write_symbol (info
, N_LSYM
, 0, 0, buf
))
2013 /* Record a variable. */
2016 stab_variable (void *p
, const char *name
, enum debug_var_kind kind
,
2019 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2022 const char *kindstr
;
2024 s
= stab_pop_type (info
);
2037 stab_type
= N_STSYM
;
2041 case DEBUG_LOCAL_STATIC
:
2042 stab_type
= N_STSYM
;
2050 /* Make sure that this is a type reference or definition. */
2056 index
= info
->type_index
;
2058 n
= (char *) xmalloc (strlen (s
) + 20);
2059 sprintf (n
, "%ld=%s", index
, s
);
2065 case DEBUG_REGISTER
:
2071 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 3);
2072 sprintf (buf
, "%s:%s%s", name
, kindstr
, s
);
2075 if (! stab_write_symbol (info
, stab_type
, 0, val
, buf
))
2083 /* Start outputting a function. */
2086 stab_start_function (void *p
, const char *name
, bfd_boolean globalp
)
2088 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2089 char *rettype
, *buf
;
2091 assert (info
->nesting
== 0 && info
->fun_offset
== -1);
2093 rettype
= stab_pop_type (info
);
2095 buf
= (char *) xmalloc (strlen (name
) + strlen (rettype
) + 3);
2096 sprintf (buf
, "%s:%c%s", name
,
2097 globalp
? 'F' : 'f',
2100 /* We don't know the value now, so we set it in start_block. */
2101 info
->fun_offset
= info
->symbols_size
;
2103 if (! stab_write_symbol (info
, N_FUN
, 0, 0, buf
))
2111 /* Output a function parameter. */
2114 stab_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
, bfd_vma val
)
2116 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2121 s
= stab_pop_type (info
);
2128 case DEBUG_PARM_STACK
:
2133 case DEBUG_PARM_REG
:
2138 case DEBUG_PARM_REFERENCE
:
2143 case DEBUG_PARM_REF_REG
:
2149 buf
= (char *) xmalloc (strlen (name
) + strlen (s
) + 3);
2150 sprintf (buf
, "%s:%c%s", name
, kindc
, s
);
2153 if (! stab_write_symbol (info
, stab_type
, 0, val
, buf
))
2161 /* Start a block. */
2164 stab_start_block (void *p
, bfd_vma addr
)
2166 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2168 /* Fill in any slots which have been waiting for the first known
2171 if (info
->so_offset
!= -1)
2173 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->so_offset
+ 8);
2174 info
->so_offset
= -1;
2177 if (info
->fun_offset
!= -1)
2179 bfd_put_32 (info
->abfd
, addr
, info
->symbols
+ info
->fun_offset
+ 8);
2180 info
->fun_offset
= -1;
2185 /* We will be called with a top level block surrounding the
2186 function, but stabs information does not output that block, so we
2189 if (info
->nesting
== 1)
2191 info
->fnaddr
= addr
;
2195 /* We have to output the LBRAC symbol after any variables which are
2196 declared inside the block. We postpone the LBRAC until the next
2197 start_block or end_block. */
2199 /* If we have postponed an LBRAC, output it now. */
2200 if (info
->pending_lbrac
!= (bfd_vma
) -1)
2202 if (! stab_write_symbol (info
, N_LBRAC
, 0, info
->pending_lbrac
,
2203 (const char *) NULL
))
2207 /* Remember the address and output it later. */
2209 info
->pending_lbrac
= addr
- info
->fnaddr
;
2217 stab_end_block (void *p
, bfd_vma addr
)
2219 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2221 if (addr
> info
->last_text_address
)
2222 info
->last_text_address
= addr
;
2224 /* If we have postponed an LBRAC, output it now. */
2225 if (info
->pending_lbrac
!= (bfd_vma
) -1)
2227 if (! stab_write_symbol (info
, N_LBRAC
, 0, info
->pending_lbrac
,
2228 (const char *) NULL
))
2230 info
->pending_lbrac
= (bfd_vma
) -1;
2233 assert (info
->nesting
> 0);
2237 /* We ignore the outermost block. */
2238 if (info
->nesting
== 0)
2241 return stab_write_symbol (info
, N_RBRAC
, 0, addr
- info
->fnaddr
,
2242 (const char *) NULL
);
2245 /* End a function. */
2248 stab_end_function (void *p ATTRIBUTE_UNUSED
)
2253 /* Output a line number. */
2256 stab_lineno (void *p
, const char *file
, unsigned long lineno
, bfd_vma addr
)
2258 struct stab_write_handle
*info
= (struct stab_write_handle
*) p
;
2260 assert (info
->lineno_filename
!= NULL
);
2262 if (addr
> info
->last_text_address
)
2263 info
->last_text_address
= addr
;
2265 if (strcmp (file
, info
->lineno_filename
) != 0)
2267 if (! stab_write_symbol (info
, N_SOL
, 0, addr
, file
))
2269 info
->lineno_filename
= file
;
2272 return stab_write_symbol (info
, N_SLINE
, lineno
, addr
- info
->fnaddr
,
2273 (const char *) NULL
);