]>
Commit | Line | Data |
---|---|---|
e1c14599 | 1 | /* debug.c -- Handle generic debugging information. |
63840d26 | 2 | Copyright (C) 1995, 1996 Free Software Foundation, Inc. |
e1c14599 ILT |
3 | Written by Ian Lance Taylor <[email protected]>. |
4 | ||
5 | This file is part of GNU Binutils. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
21 | ||
22 | /* This file implements a generic debugging format. We may eventually | |
23 | have readers which convert different formats into this generic | |
24 | format, and writers which write it out. The initial impetus for | |
25 | this was writing a convertor from stabs to HP IEEE-695 debugging | |
26 | format. */ | |
27 | ||
28 | #include <stdio.h> | |
29 | #include <assert.h> | |
30 | ||
31 | #include "bfd.h" | |
32 | #include "bucomm.h" | |
33 | #include "libiberty.h" | |
34 | #include "debug.h" | |
35 | ||
36 | /* Global information we keep for debugging. A pointer to this | |
37 | structure is the debugging handle passed to all the routines. */ | |
38 | ||
39 | struct debug_handle | |
40 | { | |
41 | /* A linked list of compilation units. */ | |
42 | struct debug_unit *units; | |
43 | /* The current compilation unit. */ | |
44 | struct debug_unit *current_unit; | |
45 | /* The current source file. */ | |
46 | struct debug_file *current_file; | |
47 | /* The current function. */ | |
48 | struct debug_function *current_function; | |
49 | /* The current block. */ | |
50 | struct debug_block *current_block; | |
63840d26 | 51 | /* The current line number information for the current unit. */ |
e1c14599 ILT |
52 | struct debug_lineno *current_lineno; |
53 | /* Mark. This is used by debug_write. */ | |
54 | unsigned int mark; | |
07aa1e1b ILT |
55 | /* A struct/class ID used by debug_write. */ |
56 | unsigned int class_id; | |
57 | /* The base for class_id for this call to debug_write. */ | |
58 | unsigned int base_id; | |
e1b88109 ILT |
59 | /* A list of classes which have assigned ID's during debug_write. |
60 | This is linked through the next_id field of debug_class_type. */ | |
61 | struct debug_class_id *id_list; | |
62 | /* A list used to avoid recursion during debug_type_samep. */ | |
63 | struct debug_type_compare_list *compare_list; | |
e1c14599 ILT |
64 | }; |
65 | ||
66 | /* Information we keep for a single compilation unit. */ | |
67 | ||
68 | struct debug_unit | |
69 | { | |
70 | /* The next compilation unit. */ | |
71 | struct debug_unit *next; | |
72 | /* A list of files included in this compilation unit. The first | |
73 | file is always the main one, and that is where the main file name | |
74 | is stored. */ | |
75 | struct debug_file *files; | |
63840d26 ILT |
76 | /* Line number information for this compilation unit. This is not |
77 | stored by function, because assembler code may have line number | |
78 | information without function information. */ | |
79 | struct debug_lineno *linenos; | |
e1c14599 ILT |
80 | }; |
81 | ||
82 | /* Information kept for a single source file. */ | |
83 | ||
84 | struct debug_file | |
85 | { | |
86 | /* The next source file in this compilation unit. */ | |
87 | struct debug_file *next; | |
88 | /* The name of the source file. */ | |
89 | const char *filename; | |
90 | /* Global functions, variables, types, etc. */ | |
91 | struct debug_namespace *globals; | |
92 | }; | |
93 | ||
94 | /* A type. */ | |
95 | ||
96 | struct debug_type | |
97 | { | |
98 | /* Kind of type. */ | |
99 | enum debug_type_kind kind; | |
100 | /* Size of type (0 if not known). */ | |
101 | unsigned int size; | |
102 | /* Type which is a pointer to this type. */ | |
103 | debug_type pointer; | |
104 | /* Tagged union with additional information about the type. */ | |
105 | union | |
106 | { | |
107 | /* DEBUG_KIND_INDIRECT. */ | |
108 | struct debug_indirect_type *kindirect; | |
109 | /* DEBUG_KIND_INT. */ | |
110 | /* Whether the integer is unsigned. */ | |
111 | boolean kint; | |
112 | /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS, | |
113 | DEBUG_KIND_UNION_CLASS. */ | |
114 | struct debug_class_type *kclass; | |
115 | /* DEBUG_KIND_ENUM. */ | |
116 | struct debug_enum_type *kenum; | |
117 | /* DEBUG_KIND_POINTER. */ | |
118 | struct debug_type *kpointer; | |
119 | /* DEBUG_KIND_FUNCTION. */ | |
120 | struct debug_function_type *kfunction; | |
121 | /* DEBUG_KIND_REFERENCE. */ | |
122 | struct debug_type *kreference; | |
123 | /* DEBUG_KIND_RANGE. */ | |
124 | struct debug_range_type *krange; | |
125 | /* DEBUG_KIND_ARRAY. */ | |
126 | struct debug_array_type *karray; | |
127 | /* DEBUG_KIND_SET. */ | |
128 | struct debug_set_type *kset; | |
129 | /* DEBUG_KIND_OFFSET. */ | |
130 | struct debug_offset_type *koffset; | |
131 | /* DEBUG_KIND_METHOD. */ | |
132 | struct debug_method_type *kmethod; | |
133 | /* DEBUG_KIND_CONST. */ | |
134 | struct debug_type *kconst; | |
135 | /* DEBUG_KIND_VOLATILE. */ | |
136 | struct debug_type *kvolatile; | |
137 | /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */ | |
138 | struct debug_named_type *knamed; | |
139 | } u; | |
140 | }; | |
141 | ||
142 | /* Information kept for an indirect type. */ | |
143 | ||
144 | struct debug_indirect_type | |
145 | { | |
146 | /* Slot where the final type will appear. */ | |
147 | debug_type *slot; | |
148 | /* Tag. */ | |
149 | const char *tag; | |
150 | }; | |
151 | ||
152 | /* Information kept for a struct, union, or class. */ | |
153 | ||
154 | struct debug_class_type | |
155 | { | |
156 | /* NULL terminated array of fields. */ | |
157 | debug_field *fields; | |
e1b88109 ILT |
158 | /* A mark field which indicates whether the struct has already been |
159 | printed. */ | |
e1c14599 | 160 | unsigned int mark; |
07aa1e1b ILT |
161 | /* This is used to uniquely identify unnamed structs when printing. */ |
162 | unsigned int id; | |
e1c14599 ILT |
163 | /* The remaining fields are only used for DEBUG_KIND_CLASS and |
164 | DEBUG_KIND_UNION_CLASS. */ | |
165 | /* NULL terminated array of base classes. */ | |
166 | debug_baseclass *baseclasses; | |
167 | /* NULL terminated array of methods. */ | |
168 | debug_method *methods; | |
169 | /* The type of the class providing the virtual function table for | |
170 | this class. This may point to the type itself. */ | |
171 | debug_type vptrbase; | |
172 | }; | |
173 | ||
174 | /* Information kept for an enum. */ | |
175 | ||
176 | struct debug_enum_type | |
177 | { | |
178 | /* NULL terminated array of names. */ | |
179 | const char **names; | |
180 | /* Array of corresponding values. */ | |
181 | bfd_signed_vma *values; | |
182 | }; | |
183 | ||
184 | /* Information kept for a function. FIXME: We should be able to | |
185 | record the parameter types. */ | |
186 | ||
187 | struct debug_function_type | |
188 | { | |
189 | /* Return type. */ | |
190 | debug_type return_type; | |
267e5298 ILT |
191 | /* NULL terminated array of argument types. */ |
192 | debug_type *arg_types; | |
193 | /* Whether the function takes a variable number of arguments. */ | |
194 | boolean varargs; | |
e1c14599 ILT |
195 | }; |
196 | ||
197 | /* Information kept for a range. */ | |
198 | ||
199 | struct debug_range_type | |
200 | { | |
201 | /* Range base type. */ | |
202 | debug_type type; | |
203 | /* Lower bound. */ | |
204 | bfd_signed_vma lower; | |
205 | /* Upper bound. */ | |
206 | bfd_signed_vma upper; | |
207 | }; | |
208 | ||
209 | /* Information kept for an array. */ | |
210 | ||
211 | struct debug_array_type | |
212 | { | |
213 | /* Element type. */ | |
214 | debug_type element_type; | |
215 | /* Range type. */ | |
216 | debug_type range_type; | |
217 | /* Lower bound. */ | |
218 | bfd_signed_vma lower; | |
219 | /* Upper bound. */ | |
220 | bfd_signed_vma upper; | |
221 | /* Whether this array is really a string. */ | |
222 | boolean stringp; | |
223 | }; | |
224 | ||
225 | /* Information kept for a set. */ | |
226 | ||
227 | struct debug_set_type | |
228 | { | |
229 | /* Base type. */ | |
230 | debug_type type; | |
231 | /* Whether this set is really a bitstring. */ | |
232 | boolean bitstringp; | |
233 | }; | |
234 | ||
235 | /* Information kept for an offset type (a based pointer). */ | |
236 | ||
237 | struct debug_offset_type | |
238 | { | |
239 | /* The type the pointer is an offset from. */ | |
240 | debug_type base_type; | |
241 | /* The type the pointer points to. */ | |
242 | debug_type target_type; | |
243 | }; | |
244 | ||
245 | /* Information kept for a method type. */ | |
246 | ||
247 | struct debug_method_type | |
248 | { | |
249 | /* The return type. */ | |
250 | debug_type return_type; | |
251 | /* The object type which this method is for. */ | |
252 | debug_type domain_type; | |
253 | /* A NULL terminated array of argument types. */ | |
254 | debug_type *arg_types; | |
267e5298 ILT |
255 | /* Whether the method takes a variable number of arguments. */ |
256 | boolean varargs; | |
e1c14599 ILT |
257 | }; |
258 | ||
259 | /* Information kept for a named type. */ | |
260 | ||
261 | struct debug_named_type | |
262 | { | |
263 | /* Name. */ | |
264 | struct debug_name *name; | |
265 | /* Real type. */ | |
266 | debug_type type; | |
267 | }; | |
268 | ||
269 | /* A field in a struct or union. */ | |
270 | ||
271 | struct debug_field | |
272 | { | |
273 | /* Name of the field. */ | |
274 | const char *name; | |
275 | /* Type of the field. */ | |
276 | struct debug_type *type; | |
277 | /* Visibility of the field. */ | |
278 | enum debug_visibility visibility; | |
279 | /* Whether this is a static member. */ | |
280 | boolean static_member; | |
281 | union | |
282 | { | |
283 | /* If static_member is false. */ | |
284 | struct | |
285 | { | |
286 | /* Bit position of the field in the struct. */ | |
287 | unsigned int bitpos; | |
288 | /* Size of the field in bits. */ | |
289 | unsigned int bitsize; | |
290 | } f; | |
291 | /* If static_member is true. */ | |
292 | struct | |
293 | { | |
294 | const char *physname; | |
295 | } s; | |
296 | } u; | |
297 | }; | |
298 | ||
299 | /* A base class for an object. */ | |
300 | ||
301 | struct debug_baseclass | |
302 | { | |
303 | /* Type of the base class. */ | |
304 | struct debug_type *type; | |
305 | /* Bit position of the base class in the object. */ | |
306 | unsigned int bitpos; | |
307 | /* Whether the base class is virtual. */ | |
308 | boolean virtual; | |
309 | /* Visibility of the base class. */ | |
310 | enum debug_visibility visibility; | |
311 | }; | |
312 | ||
313 | /* A method of an object. */ | |
314 | ||
315 | struct debug_method | |
316 | { | |
317 | /* The name of the method. */ | |
318 | const char *name; | |
319 | /* A NULL terminated array of different types of variants. */ | |
320 | struct debug_method_variant **variants; | |
321 | }; | |
322 | ||
323 | /* The variants of a method function of an object. These indicate | |
324 | which method to run. */ | |
325 | ||
326 | struct debug_method_variant | |
327 | { | |
07aa1e1b ILT |
328 | /* The physical name of the function. */ |
329 | const char *physname; | |
e1c14599 ILT |
330 | /* The type of the function. */ |
331 | struct debug_type *type; | |
332 | /* The visibility of the function. */ | |
333 | enum debug_visibility visibility; | |
334 | /* Whether the function is const. */ | |
335 | boolean constp; | |
336 | /* Whether the function is volatile. */ | |
337 | boolean volatilep; | |
338 | /* The offset to the function in the virtual function table. */ | |
339 | bfd_vma voffset; | |
340 | /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */ | |
e1b88109 | 341 | #define VOFFSET_STATIC_METHOD ((bfd_vma) -1) |
e1c14599 ILT |
342 | /* Context of a virtual method function. */ |
343 | struct debug_type *context; | |
344 | }; | |
345 | ||
346 | /* A variable. This is the information we keep for a variable object. | |
347 | This has no name; a name is associated with a variable in a | |
348 | debug_name structure. */ | |
349 | ||
350 | struct debug_variable | |
351 | { | |
352 | /* Kind of variable. */ | |
353 | enum debug_var_kind kind; | |
354 | /* Type. */ | |
355 | debug_type type; | |
356 | /* Value. The interpretation of the value depends upon kind. */ | |
357 | bfd_vma val; | |
358 | }; | |
359 | ||
360 | /* A function. This has no name; a name is associated with a function | |
361 | in a debug_name structure. */ | |
362 | ||
363 | struct debug_function | |
364 | { | |
365 | /* Return type. */ | |
366 | debug_type return_type; | |
367 | /* Parameter information. */ | |
368 | struct debug_parameter *parameters; | |
369 | /* Block information. The first structure on the list is the main | |
370 | block of the function, and describes function local variables. */ | |
371 | struct debug_block *blocks; | |
372 | }; | |
373 | ||
374 | /* A function parameter. */ | |
375 | ||
376 | struct debug_parameter | |
377 | { | |
378 | /* Next parameter. */ | |
379 | struct debug_parameter *next; | |
380 | /* Name. */ | |
381 | const char *name; | |
382 | /* Type. */ | |
383 | debug_type type; | |
384 | /* Kind. */ | |
385 | enum debug_parm_kind kind; | |
386 | /* Value (meaning depends upon kind). */ | |
387 | bfd_vma val; | |
388 | }; | |
389 | ||
390 | /* A typed constant. */ | |
391 | ||
392 | struct debug_typed_constant | |
393 | { | |
394 | /* Type. */ | |
395 | debug_type type; | |
396 | /* Value. FIXME: We may eventually need to support non-integral | |
397 | values. */ | |
398 | bfd_vma val; | |
399 | }; | |
400 | ||
401 | /* Information about a block within a function. */ | |
402 | ||
403 | struct debug_block | |
404 | { | |
405 | /* Next block with the same parent. */ | |
406 | struct debug_block *next; | |
407 | /* Parent block. */ | |
408 | struct debug_block *parent; | |
409 | /* List of child blocks. */ | |
410 | struct debug_block *children; | |
411 | /* Start address of the block. */ | |
412 | bfd_vma start; | |
413 | /* End address of the block. */ | |
414 | bfd_vma end; | |
415 | /* Local variables. */ | |
416 | struct debug_namespace *locals; | |
e1c14599 ILT |
417 | }; |
418 | ||
63840d26 ILT |
419 | /* Line number information we keep for a compilation unit. FIXME: |
420 | This structure is easy to create, but can be very space | |
421 | inefficient. */ | |
e1c14599 ILT |
422 | |
423 | struct debug_lineno | |
424 | { | |
425 | /* More line number information for this block. */ | |
426 | struct debug_lineno *next; | |
427 | /* Source file. */ | |
428 | struct debug_file *file; | |
429 | /* Line numbers, terminated by a -1 or the end of the array. */ | |
430 | #define DEBUG_LINENO_COUNT 10 | |
431 | unsigned long linenos[DEBUG_LINENO_COUNT]; | |
432 | /* Addresses for the line numbers. */ | |
433 | bfd_vma addrs[DEBUG_LINENO_COUNT]; | |
434 | }; | |
435 | ||
436 | /* A namespace. This is a mapping from names to objects. FIXME: This | |
437 | should be implemented as a hash table. */ | |
438 | ||
439 | struct debug_namespace | |
440 | { | |
441 | /* List of items in this namespace. */ | |
442 | struct debug_name *list; | |
443 | /* Pointer to where the next item in this namespace should go. */ | |
444 | struct debug_name **tail; | |
445 | }; | |
446 | ||
447 | /* Kinds of objects that appear in a namespace. */ | |
448 | ||
449 | enum debug_object_kind | |
450 | { | |
451 | /* A type. */ | |
452 | DEBUG_OBJECT_TYPE, | |
453 | /* A tagged type (really a different sort of namespace). */ | |
454 | DEBUG_OBJECT_TAG, | |
455 | /* A variable. */ | |
456 | DEBUG_OBJECT_VARIABLE, | |
457 | /* A function. */ | |
458 | DEBUG_OBJECT_FUNCTION, | |
459 | /* An integer constant. */ | |
460 | DEBUG_OBJECT_INT_CONSTANT, | |
461 | /* A floating point constant. */ | |
462 | DEBUG_OBJECT_FLOAT_CONSTANT, | |
463 | /* A typed constant. */ | |
464 | DEBUG_OBJECT_TYPED_CONSTANT | |
465 | }; | |
466 | ||
467 | /* Linkage of an object that appears in a namespace. */ | |
468 | ||
469 | enum debug_object_linkage | |
470 | { | |
471 | /* Local variable. */ | |
472 | DEBUG_LINKAGE_AUTOMATIC, | |
473 | /* Static--either file static or function static, depending upon the | |
474 | namespace is. */ | |
475 | DEBUG_LINKAGE_STATIC, | |
476 | /* Global. */ | |
477 | DEBUG_LINKAGE_GLOBAL, | |
478 | /* No linkage. */ | |
479 | DEBUG_LINKAGE_NONE | |
480 | }; | |
481 | ||
482 | /* A name in a namespace. */ | |
483 | ||
484 | struct debug_name | |
485 | { | |
486 | /* Next name in this namespace. */ | |
487 | struct debug_name *next; | |
488 | /* Name. */ | |
489 | const char *name; | |
490 | /* Mark. This is used by debug_write. */ | |
491 | unsigned int mark; | |
492 | /* Kind of object. */ | |
493 | enum debug_object_kind kind; | |
494 | /* Linkage of object. */ | |
495 | enum debug_object_linkage linkage; | |
496 | /* Tagged union with additional information about the object. */ | |
497 | union | |
498 | { | |
499 | /* DEBUG_OBJECT_TYPE. */ | |
500 | struct debug_type *type; | |
501 | /* DEBUG_OBJECT_TAG. */ | |
502 | struct debug_type *tag; | |
503 | /* DEBUG_OBJECT_VARIABLE. */ | |
504 | struct debug_variable *variable; | |
505 | /* DEBUG_OBJECT_FUNCTION. */ | |
506 | struct debug_function *function; | |
507 | /* DEBUG_OBJECT_INT_CONSTANT. */ | |
508 | bfd_vma int_constant; | |
509 | /* DEBUG_OBJECT_FLOAT_CONSTANT. */ | |
510 | double float_constant; | |
511 | /* DEBUG_OBJECT_TYPED_CONSTANT. */ | |
512 | struct debug_typed_constant *typed_constant; | |
513 | } u; | |
514 | }; | |
515 | ||
e1b88109 ILT |
516 | /* During debug_write, a linked list of these structures is used to |
517 | keep track of ID numbers that have been assigned to classes. */ | |
518 | ||
519 | struct debug_class_id | |
520 | { | |
521 | /* Next ID number. */ | |
522 | struct debug_class_id *next; | |
523 | /* The type with the ID. */ | |
524 | struct debug_type *type; | |
525 | /* The tag; NULL if no tag. */ | |
526 | const char *tag; | |
527 | }; | |
528 | ||
529 | /* During debug_type_samep, a linked list of these structures is kept | |
530 | on the stack to avoid infinite recursion. */ | |
531 | ||
532 | struct debug_type_compare_list | |
533 | { | |
534 | /* Next type on list. */ | |
535 | struct debug_type_compare_list *next; | |
536 | /* The types we are comparing. */ | |
537 | struct debug_type *t1; | |
538 | struct debug_type *t2; | |
539 | }; | |
540 | ||
07aa1e1b ILT |
541 | /* Local functions. */ |
542 | ||
e1c14599 ILT |
543 | static void debug_error PARAMS ((const char *)); |
544 | static struct debug_name *debug_add_to_namespace | |
545 | PARAMS ((struct debug_handle *, struct debug_namespace **, const char *, | |
546 | enum debug_object_kind, enum debug_object_linkage)); | |
547 | static struct debug_name *debug_add_to_current_namespace | |
548 | PARAMS ((struct debug_handle *, const char *, enum debug_object_kind, | |
549 | enum debug_object_linkage)); | |
550 | static struct debug_type *debug_make_type | |
551 | PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int)); | |
07aa1e1b | 552 | static struct debug_type *debug_get_real_type PARAMS ((PTR, debug_type)); |
e1c14599 ILT |
553 | static boolean debug_write_name |
554 | PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, | |
555 | struct debug_name *)); | |
556 | static boolean debug_write_type | |
557 | PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, | |
558 | struct debug_type *, struct debug_name *)); | |
559 | static boolean debug_write_class_type | |
560 | PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, | |
63840d26 | 561 | struct debug_type *, const char *)); |
e1c14599 ILT |
562 | static boolean debug_write_function |
563 | PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, | |
564 | const char *, enum debug_object_linkage, struct debug_function *)); | |
565 | static boolean debug_write_block | |
566 | PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, | |
567 | struct debug_block *)); | |
e1b88109 ILT |
568 | static boolean debug_set_class_id |
569 | PARAMS ((struct debug_handle *, const char *, struct debug_type *)); | |
570 | static boolean debug_type_samep | |
571 | PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *)); | |
572 | static boolean debug_class_type_samep | |
573 | PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *)); | |
e1c14599 ILT |
574 | \f |
575 | /* Issue an error message. */ | |
576 | ||
577 | static void | |
578 | debug_error (message) | |
579 | const char *message; | |
580 | { | |
581 | fprintf (stderr, "%s\n", message); | |
582 | } | |
583 | ||
584 | /* Add an object to a namespace. */ | |
585 | ||
586 | static struct debug_name * | |
587 | debug_add_to_namespace (info, nsp, name, kind, linkage) | |
588 | struct debug_handle *info; | |
589 | struct debug_namespace **nsp; | |
590 | const char *name; | |
591 | enum debug_object_kind kind; | |
592 | enum debug_object_linkage linkage; | |
593 | { | |
594 | struct debug_name *n; | |
595 | struct debug_namespace *ns; | |
596 | ||
597 | n = (struct debug_name *) xmalloc (sizeof *n); | |
598 | memset (n, 0, sizeof *n); | |
599 | ||
600 | n->name = name; | |
601 | n->kind = kind; | |
602 | n->linkage = linkage; | |
603 | ||
604 | ns = *nsp; | |
605 | if (ns == NULL) | |
606 | { | |
607 | ns = (struct debug_namespace *) xmalloc (sizeof *ns); | |
608 | memset (ns, 0, sizeof *ns); | |
609 | ||
610 | ns->tail = &ns->list; | |
611 | ||
612 | *nsp = ns; | |
613 | } | |
614 | ||
615 | *ns->tail = n; | |
616 | ns->tail = &n->next; | |
617 | ||
618 | return n; | |
619 | } | |
620 | ||
621 | /* Add an object to the current namespace. */ | |
622 | ||
623 | static struct debug_name * | |
624 | debug_add_to_current_namespace (info, name, kind, linkage) | |
625 | struct debug_handle *info; | |
626 | const char *name; | |
627 | enum debug_object_kind kind; | |
628 | enum debug_object_linkage linkage; | |
629 | { | |
630 | struct debug_namespace **nsp; | |
631 | ||
632 | if (info->current_unit == NULL | |
633 | || info->current_file == NULL) | |
634 | { | |
635 | debug_error ("debug_add_to_current_namespace: no current file"); | |
636 | return NULL; | |
637 | } | |
638 | ||
639 | if (info->current_block != NULL) | |
640 | nsp = &info->current_block->locals; | |
641 | else | |
642 | nsp = &info->current_file->globals; | |
643 | ||
644 | return debug_add_to_namespace (info, nsp, name, kind, linkage); | |
645 | } | |
646 | \f | |
647 | /* Return a handle for debugging information. */ | |
648 | ||
649 | PTR | |
650 | debug_init () | |
651 | { | |
652 | struct debug_handle *ret; | |
653 | ||
654 | ret = (struct debug_handle *) xmalloc (sizeof *ret); | |
655 | memset (ret, 0, sizeof *ret); | |
656 | return (PTR) ret; | |
657 | } | |
658 | ||
659 | /* Set the source filename. This implicitly starts a new compilation | |
660 | unit. */ | |
661 | ||
662 | boolean | |
663 | debug_set_filename (handle, name) | |
664 | PTR handle; | |
665 | const char *name; | |
666 | { | |
667 | struct debug_handle *info = (struct debug_handle *) handle; | |
668 | struct debug_file *nfile; | |
669 | struct debug_unit *nunit; | |
670 | ||
671 | if (name == NULL) | |
672 | name = ""; | |
673 | ||
674 | nfile = (struct debug_file *) xmalloc (sizeof *nfile); | |
675 | memset (nfile, 0, sizeof *nfile); | |
676 | ||
677 | nfile->filename = name; | |
678 | ||
679 | nunit = (struct debug_unit *) xmalloc (sizeof *nunit); | |
680 | memset (nunit, 0, sizeof *nunit); | |
681 | ||
682 | nunit->files = nfile; | |
683 | info->current_file = nfile; | |
684 | ||
685 | if (info->current_unit != NULL) | |
686 | info->current_unit->next = nunit; | |
687 | else | |
688 | { | |
689 | assert (info->units == NULL); | |
690 | info->units = nunit; | |
691 | } | |
692 | ||
693 | info->current_unit = nunit; | |
694 | ||
695 | info->current_function = NULL; | |
696 | info->current_block = NULL; | |
697 | info->current_lineno = NULL; | |
698 | ||
699 | return true; | |
700 | } | |
701 | ||
e1c14599 ILT |
702 | /* Change source files to the given file name. This is used for |
703 | include files in a single compilation unit. */ | |
704 | ||
705 | boolean | |
706 | debug_start_source (handle, name) | |
707 | PTR handle; | |
708 | const char *name; | |
709 | { | |
710 | struct debug_handle *info = (struct debug_handle *) handle; | |
711 | struct debug_file *f, **pf; | |
712 | ||
713 | if (name == NULL) | |
714 | name = ""; | |
715 | ||
716 | if (info->current_unit == NULL) | |
717 | { | |
718 | debug_error ("debug_start_source: no debug_set_filename call"); | |
719 | return false; | |
720 | } | |
721 | ||
722 | for (f = info->current_unit->files; f != NULL; f = f->next) | |
723 | { | |
724 | if (f->filename[0] == name[0] | |
725 | && f->filename[1] == name[1] | |
726 | && strcmp (f->filename, name) == 0) | |
727 | { | |
728 | info->current_file = f; | |
729 | return true; | |
730 | } | |
731 | } | |
732 | ||
733 | f = (struct debug_file *) xmalloc (sizeof *f); | |
734 | memset (f, 0, sizeof *f); | |
735 | ||
736 | f->filename = name; | |
737 | ||
738 | for (pf = &info->current_file->next; | |
739 | *pf != NULL; | |
740 | pf = &(*pf)->next) | |
741 | ; | |
742 | *pf = f; | |
743 | ||
744 | info->current_file = f; | |
745 | ||
746 | return true; | |
747 | } | |
748 | ||
749 | /* Record a function definition. This implicitly starts a function | |
750 | block. The debug_type argument is the type of the return value. | |
751 | The boolean indicates whether the function is globally visible. | |
752 | The bfd_vma is the address of the start of the function. Currently | |
753 | the parameter types are specified by calls to | |
754 | debug_record_parameter. FIXME: There is no way to specify nested | |
a837b8fc | 755 | functions. */ |
e1c14599 ILT |
756 | |
757 | boolean | |
758 | debug_record_function (handle, name, return_type, global, addr) | |
759 | PTR handle; | |
760 | const char *name; | |
761 | debug_type return_type; | |
762 | boolean global; | |
763 | bfd_vma addr; | |
764 | { | |
765 | struct debug_handle *info = (struct debug_handle *) handle; | |
766 | struct debug_function *f; | |
767 | struct debug_block *b; | |
768 | struct debug_name *n; | |
769 | ||
770 | if (name == NULL) | |
771 | name = ""; | |
772 | if (return_type == NULL) | |
773 | return false; | |
774 | ||
775 | if (info->current_unit == NULL) | |
776 | { | |
777 | debug_error ("debug_record_function: no debug_set_filename call"); | |
778 | return false; | |
779 | } | |
780 | ||
781 | f = (struct debug_function *) xmalloc (sizeof *f); | |
782 | memset (f, 0, sizeof *f); | |
783 | ||
784 | f->return_type = return_type; | |
785 | ||
786 | b = (struct debug_block *) xmalloc (sizeof *b); | |
787 | memset (b, 0, sizeof *b); | |
788 | ||
789 | b->start = addr; | |
790 | b->end = (bfd_vma) -1; | |
791 | ||
792 | f->blocks = b; | |
793 | ||
794 | info->current_function = f; | |
795 | info->current_block = b; | |
e1c14599 ILT |
796 | |
797 | /* FIXME: If we could handle nested functions, this would be the | |
798 | place: we would want to use a different namespace. */ | |
799 | n = debug_add_to_namespace (info, | |
800 | &info->current_file->globals, | |
801 | name, | |
802 | DEBUG_OBJECT_FUNCTION, | |
803 | (global | |
804 | ? DEBUG_LINKAGE_GLOBAL | |
805 | : DEBUG_LINKAGE_STATIC)); | |
806 | if (n == NULL) | |
807 | return false; | |
808 | ||
809 | n->u.function = f; | |
810 | ||
811 | return true; | |
812 | } | |
813 | ||
814 | /* Record a parameter for the current function. */ | |
815 | ||
816 | boolean | |
817 | debug_record_parameter (handle, name, type, kind, val) | |
818 | PTR handle; | |
819 | const char *name; | |
820 | debug_type type; | |
821 | enum debug_parm_kind kind; | |
822 | bfd_vma val; | |
823 | { | |
824 | struct debug_handle *info = (struct debug_handle *) handle; | |
825 | struct debug_parameter *p, **pp; | |
826 | ||
827 | if (name == NULL || type == NULL) | |
828 | return false; | |
829 | ||
830 | if (info->current_unit == NULL | |
831 | || info->current_function == NULL) | |
832 | { | |
833 | debug_error ("debug_record_parameter: no current function"); | |
834 | return false; | |
835 | } | |
836 | ||
837 | p = (struct debug_parameter *) xmalloc (sizeof *p); | |
838 | memset (p, 0, sizeof *p); | |
839 | ||
840 | p->name = name; | |
841 | p->type = type; | |
842 | p->kind = kind; | |
843 | p->val = val; | |
844 | ||
845 | for (pp = &info->current_function->parameters; | |
846 | *pp != NULL; | |
847 | pp = &(*pp)->next) | |
848 | ; | |
849 | *pp = p; | |
850 | ||
851 | return true; | |
852 | } | |
853 | ||
854 | /* End a function. FIXME: This should handle function nesting. */ | |
855 | ||
856 | boolean | |
857 | debug_end_function (handle, addr) | |
858 | PTR handle; | |
859 | bfd_vma addr; | |
860 | { | |
861 | struct debug_handle *info = (struct debug_handle *) handle; | |
862 | ||
863 | if (info->current_unit == NULL | |
864 | || info->current_block == NULL | |
865 | || info->current_function == NULL) | |
866 | { | |
867 | debug_error ("debug_end_function: no current function"); | |
868 | return false; | |
869 | } | |
870 | ||
871 | if (info->current_block->parent != NULL) | |
872 | { | |
873 | debug_error ("debug_end_function: some blocks were not closed"); | |
874 | return false; | |
875 | } | |
876 | ||
877 | info->current_block->end = addr; | |
878 | ||
879 | info->current_function = NULL; | |
880 | info->current_block = NULL; | |
e1c14599 ILT |
881 | |
882 | return true; | |
883 | } | |
884 | ||
885 | /* Start a block in a function. All local information will be | |
886 | recorded in this block, until the matching call to debug_end_block. | |
887 | debug_start_block and debug_end_block may be nested. The bfd_vma | |
888 | argument is the address at which this block starts. */ | |
889 | ||
890 | boolean | |
891 | debug_start_block (handle, addr) | |
892 | PTR handle; | |
893 | bfd_vma addr; | |
894 | { | |
895 | struct debug_handle *info = (struct debug_handle *) handle; | |
896 | struct debug_block *b, **pb; | |
897 | ||
898 | /* We must always have a current block: debug_record_function sets | |
899 | one up. */ | |
900 | if (info->current_unit == NULL | |
901 | || info->current_block == NULL) | |
902 | { | |
903 | debug_error ("debug_start_block: no current block"); | |
904 | return false; | |
905 | } | |
906 | ||
907 | b = (struct debug_block *) xmalloc (sizeof *b); | |
908 | memset (b, 0, sizeof *b); | |
909 | ||
910 | b->parent = info->current_block; | |
911 | b->start = addr; | |
912 | b->end = (bfd_vma) -1; | |
913 | ||
914 | /* This new block is a child of the current block. */ | |
915 | for (pb = &info->current_block->children; | |
916 | *pb != NULL; | |
917 | pb = &(*pb)->next) | |
918 | ; | |
919 | *pb = b; | |
920 | ||
921 | info->current_block = b; | |
e1c14599 ILT |
922 | |
923 | return true; | |
924 | } | |
925 | ||
926 | /* Finish a block in a function. This matches the call to | |
927 | debug_start_block. The argument is the address at which this block | |
928 | ends. */ | |
929 | ||
930 | boolean | |
931 | debug_end_block (handle, addr) | |
932 | PTR handle; | |
933 | bfd_vma addr; | |
934 | { | |
935 | struct debug_handle *info = (struct debug_handle *) handle; | |
936 | struct debug_block *parent; | |
937 | ||
938 | if (info->current_unit == NULL | |
939 | || info->current_block == NULL) | |
940 | { | |
941 | debug_error ("debug_end_block: no current block"); | |
942 | return false; | |
943 | } | |
944 | ||
945 | parent = info->current_block->parent; | |
946 | if (parent == NULL) | |
947 | { | |
948 | debug_error ("debug_end_block: attempt to close top level block"); | |
949 | return false; | |
950 | } | |
951 | ||
952 | info->current_block->end = addr; | |
953 | ||
954 | info->current_block = parent; | |
e1c14599 ILT |
955 | |
956 | return true; | |
957 | } | |
958 | ||
959 | /* Associate a line number in the current source file and function | |
960 | with a given address. */ | |
961 | ||
962 | boolean | |
963 | debug_record_line (handle, lineno, addr) | |
964 | PTR handle; | |
965 | unsigned long lineno; | |
966 | bfd_vma addr; | |
967 | { | |
968 | struct debug_handle *info = (struct debug_handle *) handle; | |
969 | struct debug_lineno *l; | |
970 | unsigned int i; | |
971 | ||
63840d26 | 972 | if (info->current_unit == NULL) |
e1c14599 | 973 | { |
63840d26 | 974 | debug_error ("debug_record_line: no current unit"); |
e1c14599 ILT |
975 | return false; |
976 | } | |
977 | ||
978 | l = info->current_lineno; | |
979 | if (l != NULL && l->file == info->current_file) | |
980 | { | |
981 | for (i = 0; i < DEBUG_LINENO_COUNT; i++) | |
982 | { | |
983 | if (l->linenos[i] == (unsigned long) -1) | |
984 | { | |
985 | l->linenos[i] = lineno; | |
986 | l->addrs[i] = addr; | |
987 | return true; | |
988 | } | |
989 | } | |
990 | } | |
991 | ||
992 | /* If we get here, then either 1) there is no current_lineno | |
63840d26 ILT |
993 | structure, which means this is the first line number in this |
994 | compilation unit, 2) the current_lineno structure is for a | |
995 | different file, or 3) the current_lineno structure is full. | |
996 | Regardless, we want to allocate a new debug_lineno structure, put | |
997 | it in the right place, and make it the new current_lineno | |
998 | structure. */ | |
e1c14599 ILT |
999 | |
1000 | l = (struct debug_lineno *) xmalloc (sizeof *l); | |
1001 | memset (l, 0, sizeof *l); | |
1002 | ||
1003 | l->file = info->current_file; | |
1004 | l->linenos[0] = lineno; | |
1005 | l->addrs[0] = addr; | |
1006 | for (i = 1; i < DEBUG_LINENO_COUNT; i++) | |
1007 | l->linenos[i] = (unsigned long) -1; | |
1008 | ||
1009 | if (info->current_lineno != NULL) | |
1010 | info->current_lineno->next = l; | |
1011 | else | |
63840d26 | 1012 | info->current_unit->linenos = l; |
e1c14599 ILT |
1013 | |
1014 | info->current_lineno = l; | |
1015 | ||
1016 | return true; | |
1017 | } | |
1018 | ||
1019 | /* Start a named common block. This is a block of variables that may | |
1020 | move in memory. */ | |
1021 | ||
1022 | boolean | |
1023 | debug_start_common_block (handle, name) | |
1024 | PTR handle; | |
1025 | const char *name; | |
1026 | { | |
1027 | /* FIXME */ | |
1028 | debug_error ("debug_start_common_block: not implemented"); | |
1029 | return false; | |
1030 | } | |
1031 | ||
1032 | /* End a named common block. */ | |
1033 | ||
1034 | boolean | |
1035 | debug_end_common_block (handle, name) | |
1036 | PTR handle; | |
1037 | const char *name; | |
1038 | { | |
1039 | /* FIXME */ | |
1040 | debug_error ("debug_end_common_block: not implemented"); | |
1041 | return false; | |
1042 | } | |
1043 | ||
1044 | /* Record a named integer constant. */ | |
1045 | ||
1046 | boolean | |
1047 | debug_record_int_const (handle, name, val) | |
1048 | PTR handle; | |
1049 | const char *name; | |
1050 | bfd_vma val; | |
1051 | { | |
1052 | struct debug_handle *info = (struct debug_handle *) handle; | |
1053 | struct debug_name *n; | |
1054 | ||
1055 | if (name == NULL) | |
1056 | return false; | |
1057 | ||
1058 | n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT, | |
1059 | DEBUG_LINKAGE_NONE); | |
1060 | if (n == NULL) | |
1061 | return false; | |
1062 | ||
1063 | n->u.int_constant = val; | |
1064 | ||
1065 | return true; | |
1066 | } | |
1067 | ||
1068 | /* Record a named floating point constant. */ | |
1069 | ||
1070 | boolean | |
1071 | debug_record_float_const (handle, name, val) | |
1072 | PTR handle; | |
1073 | const char *name; | |
1074 | double val; | |
1075 | { | |
1076 | struct debug_handle *info = (struct debug_handle *) handle; | |
1077 | struct debug_name *n; | |
1078 | ||
1079 | if (name == NULL) | |
1080 | return false; | |
1081 | ||
1082 | n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT, | |
1083 | DEBUG_LINKAGE_NONE); | |
1084 | if (n == NULL) | |
1085 | return false; | |
1086 | ||
1087 | n->u.float_constant = val; | |
1088 | ||
1089 | return true; | |
1090 | } | |
1091 | ||
1092 | /* Record a typed constant with an integral value. */ | |
1093 | ||
1094 | boolean | |
1095 | debug_record_typed_const (handle, name, type, val) | |
1096 | PTR handle; | |
1097 | const char *name; | |
1098 | debug_type type; | |
1099 | bfd_vma val; | |
1100 | { | |
1101 | struct debug_handle *info = (struct debug_handle *) handle; | |
1102 | struct debug_name *n; | |
1103 | struct debug_typed_constant *tc; | |
1104 | ||
1105 | if (name == NULL || type == NULL) | |
1106 | return false; | |
1107 | ||
1108 | n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT, | |
1109 | DEBUG_LINKAGE_NONE); | |
1110 | if (n == NULL) | |
1111 | return false; | |
1112 | ||
1113 | tc = (struct debug_typed_constant *) xmalloc (sizeof *tc); | |
1114 | memset (tc, 0, sizeof *tc); | |
1115 | ||
1116 | tc->type = type; | |
1117 | tc->val = val; | |
1118 | ||
1119 | n->u.typed_constant = tc; | |
1120 | ||
1121 | return true; | |
1122 | } | |
1123 | ||
1124 | /* Record a label. */ | |
1125 | ||
1126 | boolean | |
1127 | debug_record_label (handle, name, type, addr) | |
1128 | PTR handle; | |
1129 | const char *name; | |
1130 | debug_type type; | |
1131 | bfd_vma addr; | |
1132 | { | |
1133 | /* FIXME. */ | |
1134 | debug_error ("debug_record_label not implemented"); | |
1135 | return false; | |
1136 | } | |
1137 | ||
1138 | /* Record a variable. */ | |
1139 | ||
1140 | boolean | |
1141 | debug_record_variable (handle, name, type, kind, val) | |
1142 | PTR handle; | |
1143 | const char *name; | |
1144 | debug_type type; | |
1145 | enum debug_var_kind kind; | |
1146 | bfd_vma val; | |
1147 | { | |
1148 | struct debug_handle *info = (struct debug_handle *) handle; | |
1149 | struct debug_namespace **nsp; | |
1150 | enum debug_object_linkage linkage; | |
1151 | struct debug_name *n; | |
1152 | struct debug_variable *v; | |
1153 | ||
1154 | if (name == NULL || type == NULL) | |
1155 | return false; | |
1156 | ||
1157 | if (info->current_unit == NULL | |
1158 | || info->current_file == NULL) | |
1159 | { | |
1160 | debug_error ("debug_record_variable: no current file"); | |
1161 | return false; | |
1162 | } | |
1163 | ||
1164 | if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC) | |
1165 | { | |
1166 | nsp = &info->current_file->globals; | |
1167 | if (kind == DEBUG_GLOBAL) | |
1168 | linkage = DEBUG_LINKAGE_GLOBAL; | |
1169 | else | |
1170 | linkage = DEBUG_LINKAGE_STATIC; | |
1171 | } | |
1172 | else | |
1173 | { | |
1174 | if (info->current_block == NULL) | |
1175 | { | |
1176 | debug_error ("debug_record_variable: no current block"); | |
1177 | return false; | |
1178 | } | |
1179 | nsp = &info->current_block->locals; | |
1180 | linkage = DEBUG_LINKAGE_AUTOMATIC; | |
1181 | } | |
1182 | ||
1183 | n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage); | |
1184 | if (n == NULL) | |
1185 | return false; | |
1186 | ||
1187 | v = (struct debug_variable *) xmalloc (sizeof *v); | |
1188 | memset (v, 0, sizeof *v); | |
1189 | ||
1190 | v->kind = kind; | |
1191 | v->type = type; | |
1192 | v->val = val; | |
1193 | ||
1194 | n->u.variable = v; | |
1195 | ||
1196 | return true; | |
1197 | } | |
1198 | ||
1199 | /* Make a type with a given kind and size. */ | |
1200 | ||
1201 | /*ARGSUSED*/ | |
1202 | static struct debug_type * | |
1203 | debug_make_type (info, kind, size) | |
1204 | struct debug_handle *info; | |
1205 | enum debug_type_kind kind; | |
1206 | unsigned int size; | |
1207 | { | |
1208 | struct debug_type *t; | |
1209 | ||
1210 | t = (struct debug_type *) xmalloc (sizeof *t); | |
1211 | memset (t, 0, sizeof *t); | |
1212 | ||
1213 | t->kind = kind; | |
1214 | t->size = size; | |
1215 | ||
1216 | return t; | |
1217 | } | |
1218 | ||
1219 | /* Make an indirect type which may be used as a placeholder for a type | |
1220 | which is referenced before it is defined. */ | |
1221 | ||
1222 | debug_type | |
1223 | debug_make_indirect_type (handle, slot, tag) | |
1224 | PTR handle; | |
1225 | debug_type *slot; | |
1226 | const char *tag; | |
1227 | { | |
1228 | struct debug_handle *info = (struct debug_handle *) handle; | |
1229 | struct debug_type *t; | |
1230 | struct debug_indirect_type *i; | |
1231 | ||
1232 | t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0); | |
1233 | if (t == NULL) | |
1234 | return DEBUG_TYPE_NULL; | |
1235 | ||
1236 | i = (struct debug_indirect_type *) xmalloc (sizeof *i); | |
1237 | memset (i, 0, sizeof *i); | |
1238 | ||
1239 | i->slot = slot; | |
1240 | i->tag = tag; | |
1241 | ||
1242 | t->u.kindirect = i; | |
1243 | ||
1244 | return t; | |
1245 | } | |
1246 | ||
1247 | /* Make a void type. There is only one of these. */ | |
1248 | ||
1249 | debug_type | |
1250 | debug_make_void_type (handle) | |
1251 | PTR handle; | |
1252 | { | |
1253 | struct debug_handle *info = (struct debug_handle *) handle; | |
1254 | ||
1255 | return debug_make_type (info, DEBUG_KIND_VOID, 0); | |
1256 | } | |
1257 | ||
1258 | /* Make an integer type of a given size. The boolean argument is true | |
1259 | if the integer is unsigned. */ | |
1260 | ||
1261 | debug_type | |
1262 | debug_make_int_type (handle, size, unsignedp) | |
1263 | PTR handle; | |
1264 | unsigned int size; | |
1265 | boolean unsignedp; | |
1266 | { | |
1267 | struct debug_handle *info = (struct debug_handle *) handle; | |
1268 | struct debug_type *t; | |
1269 | ||
1270 | t = debug_make_type (info, DEBUG_KIND_INT, size); | |
1271 | if (t == NULL) | |
1272 | return DEBUG_TYPE_NULL; | |
1273 | ||
1274 | t->u.kint = unsignedp; | |
1275 | ||
1276 | return t; | |
1277 | } | |
1278 | ||
1279 | /* Make a floating point type of a given size. FIXME: On some | |
1280 | platforms, like an Alpha, you probably need to be able to specify | |
1281 | the format. */ | |
1282 | ||
1283 | debug_type | |
1284 | debug_make_float_type (handle, size) | |
1285 | PTR handle; | |
1286 | unsigned int size; | |
1287 | { | |
1288 | struct debug_handle *info = (struct debug_handle *) handle; | |
1289 | ||
1290 | return debug_make_type (info, DEBUG_KIND_FLOAT, size); | |
1291 | } | |
1292 | ||
1293 | /* Make a boolean type of a given size. */ | |
1294 | ||
1295 | debug_type | |
1296 | debug_make_bool_type (handle, size) | |
1297 | PTR handle; | |
1298 | unsigned int size; | |
1299 | { | |
1300 | struct debug_handle *info = (struct debug_handle *) handle; | |
1301 | ||
1302 | return debug_make_type (info, DEBUG_KIND_BOOL, size); | |
1303 | } | |
1304 | ||
1305 | /* Make a complex type of a given size. */ | |
1306 | ||
1307 | debug_type | |
1308 | debug_make_complex_type (handle, size) | |
1309 | PTR handle; | |
1310 | unsigned int size; | |
1311 | { | |
1312 | struct debug_handle *info = (struct debug_handle *) handle; | |
1313 | ||
1314 | return debug_make_type (info, DEBUG_KIND_COMPLEX, size); | |
1315 | } | |
1316 | ||
1317 | /* Make a structure type. The second argument is true for a struct, | |
1318 | false for a union. The third argument is the size of the struct. | |
1319 | The fourth argument is a NULL terminated array of fields. */ | |
1320 | ||
1321 | debug_type | |
1322 | debug_make_struct_type (handle, structp, size, fields) | |
1323 | PTR handle; | |
1324 | boolean structp; | |
1325 | bfd_vma size; | |
1326 | debug_field *fields; | |
1327 | { | |
1328 | struct debug_handle *info = (struct debug_handle *) handle; | |
1329 | struct debug_type *t; | |
1330 | struct debug_class_type *c; | |
1331 | ||
1332 | t = debug_make_type (info, | |
1333 | structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION, | |
1334 | size); | |
1335 | if (t == NULL) | |
1336 | return DEBUG_TYPE_NULL; | |
1337 | ||
1338 | c = (struct debug_class_type *) xmalloc (sizeof *c); | |
1339 | memset (c, 0, sizeof *c); | |
1340 | ||
1341 | c->fields = fields; | |
1342 | ||
1343 | t->u.kclass = c; | |
1344 | ||
1345 | return t; | |
1346 | } | |
1347 | ||
1348 | /* Make an object type. The first three arguments after the handle | |
1349 | are the same as for debug_make_struct_type. The next arguments are | |
1350 | a NULL terminated array of base classes, a NULL terminated array of | |
1351 | methods, the type of the object holding the virtual function table | |
1352 | if it is not this object, and a boolean which is true if this | |
1353 | object has its own virtual function table. */ | |
1354 | ||
1355 | debug_type | |
1356 | debug_make_object_type (handle, structp, size, fields, baseclasses, | |
1357 | methods, vptrbase, ownvptr) | |
1358 | PTR handle; | |
1359 | boolean structp; | |
1360 | bfd_vma size; | |
1361 | debug_field *fields; | |
1362 | debug_baseclass *baseclasses; | |
1363 | debug_method *methods; | |
1364 | debug_type vptrbase; | |
1365 | boolean ownvptr; | |
1366 | { | |
1367 | struct debug_handle *info = (struct debug_handle *) handle; | |
1368 | struct debug_type *t; | |
1369 | struct debug_class_type *c; | |
1370 | ||
1371 | t = debug_make_type (info, | |
1372 | structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS, | |
1373 | size); | |
1374 | if (t == NULL) | |
1375 | return DEBUG_TYPE_NULL; | |
1376 | ||
1377 | c = (struct debug_class_type *) xmalloc (sizeof *c); | |
1378 | memset (c, 0, sizeof *c); | |
1379 | ||
1380 | c->fields = fields; | |
1381 | c->baseclasses = baseclasses; | |
1382 | c->methods = methods; | |
1383 | if (ownvptr) | |
1384 | c->vptrbase = t; | |
1385 | else | |
1386 | c->vptrbase = vptrbase; | |
1387 | ||
1388 | t->u.kclass = c; | |
1389 | ||
1390 | return t; | |
1391 | } | |
1392 | ||
1393 | /* Make an enumeration type. The arguments are a null terminated | |
1394 | array of strings, and an array of corresponding values. */ | |
1395 | ||
1396 | debug_type | |
1397 | debug_make_enum_type (handle, names, values) | |
1398 | PTR handle; | |
1399 | const char **names; | |
1400 | bfd_signed_vma *values; | |
1401 | { | |
1402 | struct debug_handle *info = (struct debug_handle *) handle; | |
1403 | struct debug_type *t; | |
1404 | struct debug_enum_type *e; | |
1405 | ||
1406 | t = debug_make_type (info, DEBUG_KIND_ENUM, 0); | |
1407 | if (t == NULL) | |
1408 | return DEBUG_TYPE_NULL; | |
1409 | ||
1410 | e = (struct debug_enum_type *) xmalloc (sizeof *e); | |
1411 | memset (e, 0, sizeof *e); | |
1412 | ||
1413 | e->names = names; | |
1414 | e->values = values; | |
1415 | ||
1416 | t->u.kenum = e; | |
1417 | ||
1418 | return t; | |
1419 | } | |
1420 | ||
1421 | /* Make a pointer to a given type. */ | |
1422 | ||
1423 | debug_type | |
1424 | debug_make_pointer_type (handle, type) | |
1425 | PTR handle; | |
1426 | debug_type type; | |
1427 | { | |
1428 | struct debug_handle *info = (struct debug_handle *) handle; | |
1429 | struct debug_type *t; | |
1430 | ||
1431 | if (type == NULL) | |
1432 | return DEBUG_TYPE_NULL; | |
1433 | ||
1434 | if (type->pointer != DEBUG_TYPE_NULL) | |
1435 | return type->pointer; | |
1436 | ||
1437 | t = debug_make_type (info, DEBUG_KIND_POINTER, 0); | |
1438 | if (t == NULL) | |
1439 | return DEBUG_TYPE_NULL; | |
1440 | ||
1441 | t->u.kpointer = type; | |
1442 | ||
1443 | type->pointer = t; | |
1444 | ||
1445 | return t; | |
1446 | } | |
1447 | ||
1448 | /* Make a function returning a given type. FIXME: We should be able | |
1449 | to record the parameter types. */ | |
1450 | ||
1451 | debug_type | |
267e5298 | 1452 | debug_make_function_type (handle, type, arg_types, varargs) |
e1c14599 ILT |
1453 | PTR handle; |
1454 | debug_type type; | |
267e5298 ILT |
1455 | debug_type *arg_types; |
1456 | boolean varargs; | |
e1c14599 ILT |
1457 | { |
1458 | struct debug_handle *info = (struct debug_handle *) handle; | |
1459 | struct debug_type *t; | |
1460 | struct debug_function_type *f; | |
1461 | ||
1462 | if (type == NULL) | |
1463 | return DEBUG_TYPE_NULL; | |
1464 | ||
1465 | t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0); | |
1466 | if (t == NULL) | |
1467 | return DEBUG_TYPE_NULL; | |
1468 | ||
1469 | f = (struct debug_function_type *) xmalloc (sizeof *f); | |
1470 | memset (f, 0, sizeof *f); | |
1471 | ||
1472 | f->return_type = type; | |
267e5298 ILT |
1473 | f->arg_types = arg_types; |
1474 | f->varargs = varargs; | |
e1c14599 ILT |
1475 | |
1476 | t->u.kfunction = f; | |
1477 | ||
1478 | return t; | |
1479 | } | |
1480 | ||
1481 | /* Make a reference to a given type. */ | |
1482 | ||
1483 | debug_type | |
1484 | debug_make_reference_type (handle, type) | |
1485 | PTR handle; | |
1486 | debug_type type; | |
1487 | { | |
1488 | struct debug_handle *info = (struct debug_handle *) handle; | |
1489 | struct debug_type *t; | |
1490 | ||
1491 | if (type == NULL) | |
1492 | return DEBUG_TYPE_NULL; | |
1493 | ||
1494 | t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0); | |
1495 | if (t == NULL) | |
1496 | return DEBUG_TYPE_NULL; | |
1497 | ||
1498 | t->u.kreference = type; | |
1499 | ||
1500 | return t; | |
1501 | } | |
1502 | ||
1503 | /* Make a range of a given type from a lower to an upper bound. */ | |
1504 | ||
1505 | debug_type | |
1506 | debug_make_range_type (handle, type, lower, upper) | |
1507 | PTR handle; | |
1508 | debug_type type; | |
1509 | bfd_signed_vma lower; | |
1510 | bfd_signed_vma upper; | |
1511 | { | |
1512 | struct debug_handle *info = (struct debug_handle *) handle; | |
1513 | struct debug_type *t; | |
1514 | struct debug_range_type *r; | |
1515 | ||
1516 | if (type == NULL) | |
1517 | return DEBUG_TYPE_NULL; | |
1518 | ||
1519 | t = debug_make_type (info, DEBUG_KIND_RANGE, 0); | |
1520 | if (t == NULL) | |
1521 | return DEBUG_TYPE_NULL; | |
1522 | ||
1523 | r = (struct debug_range_type *) xmalloc (sizeof *r); | |
1524 | memset (r, 0, sizeof *r); | |
1525 | ||
1526 | r->type = type; | |
1527 | r->lower = lower; | |
1528 | r->upper = upper; | |
1529 | ||
1530 | t->u.krange = r; | |
1531 | ||
1532 | return t; | |
1533 | } | |
1534 | ||
1535 | /* Make an array type. The second argument is the type of an element | |
1536 | of the array. The third argument is the type of a range of the | |
1537 | array. The fourth and fifth argument are the lower and upper | |
1538 | bounds, respectively. The sixth argument is true if this array is | |
1539 | actually a string, as in C. */ | |
1540 | ||
1541 | debug_type | |
1542 | debug_make_array_type (handle, element_type, range_type, lower, upper, | |
1543 | stringp) | |
1544 | PTR handle; | |
1545 | debug_type element_type; | |
1546 | debug_type range_type; | |
1547 | bfd_signed_vma lower; | |
1548 | bfd_signed_vma upper; | |
1549 | boolean stringp; | |
1550 | { | |
1551 | struct debug_handle *info = (struct debug_handle *) handle; | |
1552 | struct debug_type *t; | |
1553 | struct debug_array_type *a; | |
1554 | ||
1555 | if (element_type == NULL || range_type == NULL) | |
1556 | return DEBUG_TYPE_NULL; | |
1557 | ||
1558 | t = debug_make_type (info, DEBUG_KIND_ARRAY, 0); | |
1559 | if (t == NULL) | |
1560 | return DEBUG_TYPE_NULL; | |
1561 | ||
1562 | a = (struct debug_array_type *) xmalloc (sizeof *a); | |
1563 | memset (a, 0, sizeof *a); | |
1564 | ||
1565 | a->element_type = element_type; | |
1566 | a->range_type = range_type; | |
1567 | a->lower = lower; | |
1568 | a->upper = upper; | |
1569 | a->stringp = stringp; | |
1570 | ||
1571 | t->u.karray = a; | |
1572 | ||
1573 | return t; | |
1574 | } | |
1575 | ||
1576 | /* Make a set of a given type. For example, a Pascal set type. The | |
1577 | boolean argument is true if this set is actually a bitstring, as in | |
1578 | CHILL. */ | |
1579 | ||
1580 | debug_type | |
1581 | debug_make_set_type (handle, type, bitstringp) | |
1582 | PTR handle; | |
1583 | debug_type type; | |
1584 | boolean bitstringp; | |
1585 | { | |
1586 | struct debug_handle *info = (struct debug_handle *) handle; | |
1587 | struct debug_type *t; | |
1588 | struct debug_set_type *s; | |
1589 | ||
1590 | if (type == NULL) | |
1591 | return DEBUG_TYPE_NULL; | |
1592 | ||
1593 | t = debug_make_type (info, DEBUG_KIND_SET, 0); | |
1594 | if (t == NULL) | |
1595 | return DEBUG_TYPE_NULL; | |
1596 | ||
1597 | s = (struct debug_set_type *) xmalloc (sizeof *s); | |
1598 | memset (s, 0, sizeof *s); | |
1599 | ||
1600 | s->type = type; | |
1601 | s->bitstringp = bitstringp; | |
1602 | ||
1603 | t->u.kset = s; | |
1604 | ||
1605 | return t; | |
1606 | } | |
1607 | ||
1608 | /* Make a type for a pointer which is relative to an object. The | |
1609 | second argument is the type of the object to which the pointer is | |
1610 | relative. The third argument is the type that the pointer points | |
1611 | to. */ | |
1612 | ||
1613 | debug_type | |
1614 | debug_make_offset_type (handle, base_type, target_type) | |
1615 | PTR handle; | |
1616 | debug_type base_type; | |
1617 | debug_type target_type; | |
1618 | { | |
1619 | struct debug_handle *info = (struct debug_handle *) handle; | |
1620 | struct debug_type *t; | |
1621 | struct debug_offset_type *o; | |
1622 | ||
1623 | if (base_type == NULL || target_type == NULL) | |
1624 | return DEBUG_TYPE_NULL; | |
1625 | ||
1626 | t = debug_make_type (info, DEBUG_KIND_OFFSET, 0); | |
1627 | if (t == NULL) | |
1628 | return DEBUG_TYPE_NULL; | |
1629 | ||
1630 | o = (struct debug_offset_type *) xmalloc (sizeof *o); | |
1631 | memset (o, 0, sizeof *o); | |
1632 | ||
1633 | o->base_type = base_type; | |
1634 | o->target_type = target_type; | |
1635 | ||
1636 | t->u.koffset = o; | |
1637 | ||
1638 | return t; | |
1639 | } | |
1640 | ||
1641 | /* Make a type for a method function. The second argument is the | |
1642 | return type, the third argument is the domain, and the fourth | |
1643 | argument is a NULL terminated array of argument types. */ | |
1644 | ||
1645 | debug_type | |
267e5298 | 1646 | debug_make_method_type (handle, return_type, domain_type, arg_types, varargs) |
e1c14599 ILT |
1647 | PTR handle; |
1648 | debug_type return_type; | |
1649 | debug_type domain_type; | |
1650 | debug_type *arg_types; | |
267e5298 | 1651 | boolean varargs; |
e1c14599 ILT |
1652 | { |
1653 | struct debug_handle *info = (struct debug_handle *) handle; | |
1654 | struct debug_type *t; | |
1655 | struct debug_method_type *m; | |
1656 | ||
1657 | if (return_type == NULL) | |
1658 | return DEBUG_TYPE_NULL; | |
1659 | ||
1660 | t = debug_make_type (info, DEBUG_KIND_METHOD, 0); | |
1661 | if (t == NULL) | |
1662 | return DEBUG_TYPE_NULL; | |
1663 | ||
1664 | m = (struct debug_method_type *) xmalloc (sizeof *m); | |
1665 | memset (m, 0, sizeof *m); | |
1666 | ||
1667 | m->return_type = return_type; | |
1668 | m->domain_type = domain_type; | |
1669 | m->arg_types = arg_types; | |
267e5298 | 1670 | m->varargs = varargs; |
e1c14599 ILT |
1671 | |
1672 | t->u.kmethod = m; | |
1673 | ||
1674 | return t; | |
1675 | } | |
1676 | ||
1677 | /* Make a const qualified version of a given type. */ | |
1678 | ||
1679 | debug_type | |
1680 | debug_make_const_type (handle, type) | |
1681 | PTR handle; | |
1682 | debug_type type; | |
1683 | { | |
1684 | struct debug_handle *info = (struct debug_handle *) handle; | |
1685 | struct debug_type *t; | |
1686 | ||
1687 | if (type == NULL) | |
1688 | return DEBUG_TYPE_NULL; | |
1689 | ||
1690 | t = debug_make_type (info, DEBUG_KIND_CONST, 0); | |
1691 | if (t == NULL) | |
1692 | return DEBUG_TYPE_NULL; | |
1693 | ||
1694 | t->u.kconst = type; | |
1695 | ||
1696 | return t; | |
1697 | } | |
1698 | ||
1699 | /* Make a volatile qualified version of a given type. */ | |
1700 | ||
1701 | debug_type | |
1702 | debug_make_volatile_type (handle, type) | |
1703 | PTR handle; | |
1704 | debug_type type; | |
1705 | { | |
1706 | struct debug_handle *info = (struct debug_handle *) handle; | |
1707 | struct debug_type *t; | |
1708 | ||
1709 | if (type == NULL) | |
1710 | return DEBUG_TYPE_NULL; | |
1711 | ||
1712 | t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0); | |
1713 | if (t == NULL) | |
1714 | return DEBUG_TYPE_NULL; | |
1715 | ||
1716 | t->u.kvolatile = type; | |
1717 | ||
1718 | return t; | |
1719 | } | |
1720 | ||
1721 | /* Make an undefined tagged type. For example, a struct which has | |
1722 | been mentioned, but not defined. */ | |
1723 | ||
1724 | debug_type | |
1725 | debug_make_undefined_tagged_type (handle, name, kind) | |
1726 | PTR handle; | |
1727 | const char *name; | |
1728 | enum debug_type_kind kind; | |
1729 | { | |
1730 | struct debug_handle *info = (struct debug_handle *) handle; | |
1731 | struct debug_type *t; | |
1732 | ||
1733 | if (name == NULL) | |
1734 | return DEBUG_TYPE_NULL; | |
1735 | ||
36302909 ILT |
1736 | switch (kind) |
1737 | { | |
1738 | case DEBUG_KIND_STRUCT: | |
1739 | case DEBUG_KIND_UNION: | |
1740 | case DEBUG_KIND_CLASS: | |
1741 | case DEBUG_KIND_UNION_CLASS: | |
1742 | case DEBUG_KIND_ENUM: | |
1743 | break; | |
1744 | ||
1745 | default: | |
1746 | debug_error ("debug_make_undefined_type: unsupported kind"); | |
1747 | return DEBUG_TYPE_NULL; | |
1748 | } | |
1749 | ||
e1c14599 ILT |
1750 | t = debug_make_type (info, kind, 0); |
1751 | if (t == NULL) | |
1752 | return DEBUG_TYPE_NULL; | |
1753 | ||
1754 | return debug_tag_type (handle, name, t); | |
1755 | } | |
1756 | ||
1757 | /* Make a base class for an object. The second argument is the base | |
1758 | class type. The third argument is the bit position of this base | |
1759 | class in the object (always 0 unless doing multiple inheritance). | |
1760 | The fourth argument is whether this is a virtual class. The fifth | |
1761 | argument is the visibility of the base class. */ | |
1762 | ||
1763 | /*ARGSUSED*/ | |
1764 | debug_baseclass | |
1765 | debug_make_baseclass (handle, type, bitpos, virtual, visibility) | |
1766 | PTR handle; | |
1767 | debug_type type; | |
1768 | bfd_vma bitpos; | |
1769 | boolean virtual; | |
1770 | enum debug_visibility visibility; | |
1771 | { | |
1772 | struct debug_baseclass *b; | |
1773 | ||
1774 | b = (struct debug_baseclass *) xmalloc (sizeof *b); | |
1775 | memset (b, 0, sizeof *b); | |
1776 | ||
1777 | b->type = type; | |
1778 | b->bitpos = bitpos; | |
1779 | b->virtual = virtual; | |
1780 | b->visibility = visibility; | |
1781 | ||
1782 | return b; | |
1783 | } | |
1784 | ||
1785 | /* Make a field for a struct. The second argument is the name. The | |
1786 | third argument is the type of the field. The fourth argument is | |
1787 | the bit position of the field. The fifth argument is the size of | |
1788 | the field (it may be zero). The sixth argument is the visibility | |
1789 | of the field. */ | |
1790 | ||
1791 | /*ARGSUSED*/ | |
1792 | debug_field | |
1793 | debug_make_field (handle, name, type, bitpos, bitsize, visibility) | |
1794 | PTR handle; | |
1795 | const char *name; | |
1796 | debug_type type; | |
1797 | bfd_vma bitpos; | |
1798 | bfd_vma bitsize; | |
1799 | enum debug_visibility visibility; | |
1800 | { | |
1801 | struct debug_field *f; | |
1802 | ||
1803 | f = (struct debug_field *) xmalloc (sizeof *f); | |
1804 | memset (f, 0, sizeof *f); | |
1805 | ||
1806 | f->name = name; | |
1807 | f->type = type; | |
1808 | f->static_member = false; | |
1809 | f->u.f.bitpos = bitpos; | |
1810 | f->u.f.bitsize = bitsize; | |
1811 | f->visibility = visibility; | |
1812 | ||
1813 | return f; | |
1814 | } | |
1815 | ||
1816 | /* Make a static member of an object. The second argument is the | |
1817 | name. The third argument is the type of the member. The fourth | |
1818 | argument is the physical name of the member (i.e., the name as a | |
1819 | global variable). The fifth argument is the visibility of the | |
1820 | member. */ | |
1821 | ||
1822 | /*ARGSUSED*/ | |
1823 | debug_field | |
1824 | debug_make_static_member (handle, name, type, physname, visibility) | |
1825 | PTR handle; | |
1826 | const char *name; | |
1827 | debug_type type; | |
1828 | const char *physname; | |
1829 | enum debug_visibility visibility; | |
1830 | { | |
1831 | struct debug_field *f; | |
1832 | ||
1833 | f = (struct debug_field *) xmalloc (sizeof *f); | |
1834 | memset (f, 0, sizeof *f); | |
1835 | ||
1836 | f->name = name; | |
1837 | f->type = type; | |
1838 | f->static_member = true; | |
1839 | f->u.s.physname = physname; | |
1840 | f->visibility = visibility; | |
1841 | ||
1842 | return f; | |
1843 | } | |
1844 | ||
1845 | /* Make a method. The second argument is the name, and the third | |
1846 | argument is a NULL terminated array of method variants. */ | |
1847 | ||
1848 | /*ARGSUSED*/ | |
1849 | debug_method | |
1850 | debug_make_method (handle, name, variants) | |
1851 | PTR handle; | |
1852 | const char *name; | |
1853 | debug_method_variant *variants; | |
1854 | { | |
1855 | struct debug_method *m; | |
1856 | ||
1857 | m = (struct debug_method *) xmalloc (sizeof *m); | |
1858 | memset (m, 0, sizeof *m); | |
1859 | ||
1860 | m->name = name; | |
1861 | m->variants = variants; | |
1862 | ||
1863 | return m; | |
1864 | } | |
1865 | ||
1866 | /* Make a method argument. The second argument is the real name of | |
1867 | the function. The third argument is the type of the function. The | |
1868 | fourth argument is the visibility. The fifth argument is whether | |
1869 | this is a const function. The sixth argument is whether this is a | |
1870 | volatile function. The seventh argument is the offset in the | |
1871 | virtual function table, if any. The eighth argument is the virtual | |
1872 | function context. FIXME: Are the const and volatile arguments | |
1873 | necessary? Could we just use debug_make_const_type? */ | |
1874 | ||
1875 | /*ARGSUSED*/ | |
1876 | debug_method_variant | |
07aa1e1b | 1877 | debug_make_method_variant (handle, physname, type, visibility, constp, |
e1c14599 ILT |
1878 | volatilep, voffset, context) |
1879 | PTR handle; | |
07aa1e1b | 1880 | const char *physname; |
e1c14599 ILT |
1881 | debug_type type; |
1882 | enum debug_visibility visibility; | |
1883 | boolean constp; | |
1884 | boolean volatilep; | |
1885 | bfd_vma voffset; | |
1886 | debug_type context; | |
1887 | { | |
1888 | struct debug_method_variant *m; | |
1889 | ||
1890 | m = (struct debug_method_variant *) xmalloc (sizeof *m); | |
1891 | memset (m, 0, sizeof *m); | |
1892 | ||
07aa1e1b | 1893 | m->physname = physname; |
e1c14599 ILT |
1894 | m->type = type; |
1895 | m->visibility = visibility; | |
1896 | m->constp = constp; | |
1897 | m->volatilep = volatilep; | |
1898 | m->voffset = voffset; | |
1899 | m->context = context; | |
1900 | ||
1901 | return m; | |
1902 | } | |
1903 | ||
1904 | /* Make a static method argument. The arguments are the same as for | |
1905 | debug_make_method_variant, except that the last two are omitted | |
1906 | since a static method can not also be virtual. */ | |
1907 | ||
1908 | debug_method_variant | |
07aa1e1b | 1909 | debug_make_static_method_variant (handle, physname, type, visibility, |
e1c14599 ILT |
1910 | constp, volatilep) |
1911 | PTR handle; | |
07aa1e1b | 1912 | const char *physname; |
e1c14599 ILT |
1913 | debug_type type; |
1914 | enum debug_visibility visibility; | |
1915 | boolean constp; | |
1916 | boolean volatilep; | |
1917 | { | |
1918 | struct debug_method_variant *m; | |
1919 | ||
1920 | m = (struct debug_method_variant *) xmalloc (sizeof *m); | |
1921 | memset (m, 0, sizeof *m); | |
1922 | ||
07aa1e1b | 1923 | m->physname = physname; |
e1c14599 ILT |
1924 | m->type = type; |
1925 | m->visibility = visibility; | |
1926 | m->constp = constp; | |
1927 | m->volatilep = volatilep; | |
1928 | m->voffset = VOFFSET_STATIC_METHOD; | |
1929 | ||
1930 | return m; | |
1931 | } | |
1932 | ||
1933 | /* Name a type. */ | |
1934 | ||
1935 | debug_type | |
1936 | debug_name_type (handle, name, type) | |
1937 | PTR handle; | |
1938 | const char *name; | |
1939 | debug_type type; | |
1940 | { | |
1941 | struct debug_handle *info = (struct debug_handle *) handle; | |
1942 | struct debug_type *t; | |
1943 | struct debug_named_type *n; | |
1944 | struct debug_name *nm; | |
1945 | ||
1946 | if (name == NULL || type == NULL) | |
1947 | return DEBUG_TYPE_NULL; | |
1948 | ||
07aa1e1b ILT |
1949 | if (info->current_unit == NULL |
1950 | || info->current_file == NULL) | |
1951 | { | |
1952 | debug_error ("debug_record_variable: no current file"); | |
1953 | return false; | |
1954 | } | |
1955 | ||
e1c14599 ILT |
1956 | t = debug_make_type (info, DEBUG_KIND_NAMED, 0); |
1957 | if (t == NULL) | |
1958 | return DEBUG_TYPE_NULL; | |
1959 | ||
1960 | n = (struct debug_named_type *) xmalloc (sizeof *n); | |
1961 | memset (n, 0, sizeof *n); | |
1962 | ||
1963 | n->type = type; | |
1964 | ||
1965 | t->u.knamed = n; | |
1966 | ||
07aa1e1b ILT |
1967 | /* We always add the name to the global namespace. This is probably |
1968 | wrong in some cases, but it seems to be right for stabs. FIXME. */ | |
e1c14599 | 1969 | |
07aa1e1b ILT |
1970 | nm = debug_add_to_namespace (info, &info->current_file->globals, name, |
1971 | DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE); | |
e1c14599 ILT |
1972 | if (nm == NULL) |
1973 | return false; | |
1974 | ||
1975 | nm->u.type = t; | |
1976 | ||
1977 | n->name = nm; | |
1978 | ||
1979 | return t; | |
1980 | } | |
1981 | ||
1982 | /* Tag a type. */ | |
1983 | ||
1984 | debug_type | |
1985 | debug_tag_type (handle, name, type) | |
1986 | PTR handle; | |
1987 | const char *name; | |
1988 | debug_type type; | |
1989 | { | |
1990 | struct debug_handle *info = (struct debug_handle *) handle; | |
1991 | struct debug_type *t; | |
1992 | struct debug_named_type *n; | |
1993 | struct debug_name *nm; | |
1994 | ||
1995 | if (name == NULL || type == NULL) | |
1996 | return DEBUG_TYPE_NULL; | |
1997 | ||
1998 | if (info->current_file == NULL) | |
1999 | { | |
2000 | debug_error ("debug_tag_type: no current file"); | |
2001 | return DEBUG_TYPE_NULL; | |
2002 | } | |
2003 | ||
2004 | if (type->kind == DEBUG_KIND_TAGGED) | |
2005 | { | |
2006 | if (strcmp (type->u.knamed->name->name, name) == 0) | |
2007 | return type; | |
2008 | debug_error ("debug_tag_type: extra tag attempted"); | |
2009 | return DEBUG_TYPE_NULL; | |
2010 | } | |
2011 | ||
2012 | t = debug_make_type (info, DEBUG_KIND_TAGGED, 0); | |
2013 | if (t == NULL) | |
2014 | return DEBUG_TYPE_NULL; | |
2015 | ||
2016 | n = (struct debug_named_type *) xmalloc (sizeof *n); | |
2017 | memset (n, 0, sizeof *n); | |
2018 | ||
2019 | n->type = type; | |
2020 | ||
2021 | t->u.knamed = n; | |
2022 | ||
2023 | /* We keep a global namespace of tags for each compilation unit. I | |
2024 | don't know if that is the right thing to do. */ | |
2025 | ||
2026 | nm = debug_add_to_namespace (info, &info->current_file->globals, name, | |
2027 | DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE); | |
2028 | if (nm == NULL) | |
2029 | return false; | |
2030 | ||
2031 | nm->u.tag = t; | |
2032 | ||
2033 | n->name = nm; | |
2034 | ||
2035 | return t; | |
2036 | } | |
2037 | ||
2038 | /* Record the size of a given type. */ | |
2039 | ||
2040 | /*ARGSUSED*/ | |
2041 | boolean | |
2042 | debug_record_type_size (handle, type, size) | |
2043 | PTR handle; | |
2044 | debug_type type; | |
2045 | unsigned int size; | |
2046 | { | |
2047 | if (type->size != 0 && type->size != size) | |
2048 | fprintf (stderr, "Warning: changing type size from %d to %d\n", | |
2049 | type->size, size); | |
2050 | ||
2051 | type->size = size; | |
2052 | ||
2053 | return true; | |
2054 | } | |
2055 | ||
07aa1e1b ILT |
2056 | /* Find a named type. */ |
2057 | ||
2058 | debug_type | |
2059 | debug_find_named_type (handle, name) | |
2060 | PTR handle; | |
2061 | const char *name; | |
2062 | { | |
2063 | struct debug_handle *info = (struct debug_handle *) handle; | |
2064 | struct debug_block *b; | |
2065 | struct debug_file *f; | |
2066 | ||
2067 | /* We only search the current compilation unit. I don't know if | |
2068 | this is right or not. */ | |
2069 | ||
2070 | if (info->current_unit == NULL) | |
2071 | { | |
2072 | debug_error ("debug_find_named_type: no current compilation unit"); | |
2073 | return DEBUG_TYPE_NULL; | |
2074 | } | |
2075 | ||
2076 | for (b = info->current_block; b != NULL; b = b->parent) | |
2077 | { | |
2078 | if (b->locals != NULL) | |
2079 | { | |
2080 | struct debug_name *n; | |
2081 | ||
2082 | for (n = b->locals->list; n != NULL; n = n->next) | |
2083 | { | |
2084 | if (n->kind == DEBUG_OBJECT_TYPE | |
2085 | && n->name[0] == name[0] | |
2086 | && strcmp (n->name, name) == 0) | |
2087 | return n->u.type; | |
2088 | } | |
2089 | } | |
2090 | } | |
2091 | ||
2092 | for (f = info->current_unit->files; f != NULL; f = f->next) | |
2093 | { | |
2094 | if (f->globals != NULL) | |
2095 | { | |
2096 | struct debug_name *n; | |
2097 | ||
2098 | for (n = f->globals->list; n != NULL; n = n->next) | |
2099 | { | |
2100 | if (n->kind == DEBUG_OBJECT_TYPE | |
2101 | && n->name[0] == name[0] | |
2102 | && strcmp (n->name, name) == 0) | |
2103 | return n->u.type; | |
2104 | } | |
2105 | } | |
2106 | } | |
2107 | ||
2108 | return DEBUG_TYPE_NULL; | |
2109 | } | |
2110 | ||
e1c14599 ILT |
2111 | /* Find a tagged type. */ |
2112 | ||
2113 | debug_type | |
2114 | debug_find_tagged_type (handle, name, kind) | |
2115 | PTR handle; | |
2116 | const char *name; | |
2117 | enum debug_type_kind kind; | |
2118 | { | |
2119 | struct debug_handle *info = (struct debug_handle *) handle; | |
2120 | struct debug_unit *u; | |
2121 | ||
2122 | /* We search the globals of all the compilation units. I don't know | |
2123 | if this is correct or not. It would be easy to change. */ | |
2124 | ||
2125 | for (u = info->units; u != NULL; u = u->next) | |
2126 | { | |
2127 | struct debug_file *f; | |
2128 | ||
2129 | for (f = u->files; f != NULL; f = f->next) | |
2130 | { | |
2131 | struct debug_name *n; | |
2132 | ||
2133 | if (f->globals != NULL) | |
2134 | { | |
2135 | for (n = f->globals->list; n != NULL; n = n->next) | |
2136 | { | |
2137 | if (n->kind == DEBUG_OBJECT_TAG | |
07aa1e1b | 2138 | && (kind == DEBUG_KIND_ILLEGAL |
e1c14599 ILT |
2139 | || n->u.tag->kind == kind) |
2140 | && n->name[0] == name[0] | |
2141 | && strcmp (n->name, name) == 0) | |
2142 | return n->u.tag; | |
2143 | } | |
2144 | } | |
2145 | } | |
2146 | } | |
2147 | ||
2148 | return DEBUG_TYPE_NULL; | |
2149 | } | |
2150 | ||
07aa1e1b ILT |
2151 | /* Get a base type. */ |
2152 | ||
2153 | static struct debug_type * | |
2154 | debug_get_real_type (handle, type) | |
2155 | PTR handle; | |
2156 | debug_type type; | |
2157 | { | |
2158 | switch (type->kind) | |
2159 | { | |
2160 | default: | |
2161 | return type; | |
2162 | case DEBUG_KIND_INDIRECT: | |
2163 | if (*type->u.kindirect->slot != NULL) | |
2164 | return debug_get_real_type (handle, *type->u.kindirect->slot); | |
2165 | return type; | |
2166 | case DEBUG_KIND_NAMED: | |
35aa91b9 | 2167 | case DEBUG_KIND_TAGGED: |
07aa1e1b ILT |
2168 | return debug_get_real_type (handle, type->u.knamed->type); |
2169 | } | |
2170 | /*NOTREACHED*/ | |
2171 | } | |
2172 | ||
2173 | /* Get the kind of a type. */ | |
2174 | ||
2175 | enum debug_type_kind | |
2176 | debug_get_type_kind (handle, type) | |
2177 | PTR handle; | |
2178 | debug_type type; | |
2179 | { | |
2180 | if (type == NULL) | |
2181 | return DEBUG_KIND_ILLEGAL; | |
2182 | type = debug_get_real_type (handle, type); | |
2183 | return type->kind; | |
2184 | } | |
2185 | ||
e1c14599 ILT |
2186 | /* Get the name of a type. */ |
2187 | ||
e1c14599 ILT |
2188 | const char * |
2189 | debug_get_type_name (handle, type) | |
2190 | PTR handle; | |
2191 | debug_type type; | |
2192 | { | |
2193 | if (type->kind == DEBUG_KIND_INDIRECT) | |
2194 | { | |
2195 | if (*type->u.kindirect->slot != NULL) | |
2196 | return debug_get_type_name (handle, *type->u.kindirect->slot); | |
2197 | return type->u.kindirect->tag; | |
2198 | } | |
2199 | if (type->kind == DEBUG_KIND_NAMED | |
2200 | || type->kind == DEBUG_KIND_TAGGED) | |
2201 | return type->u.knamed->name->name; | |
2202 | return NULL; | |
2203 | } | |
07aa1e1b | 2204 | |
35aa91b9 ILT |
2205 | /* Get the size of a type. */ |
2206 | ||
2207 | bfd_vma | |
2208 | debug_get_type_size (handle, type) | |
2209 | PTR handle; | |
2210 | debug_type type; | |
2211 | { | |
2212 | if (type == NULL) | |
2213 | return 0; | |
2214 | ||
2215 | /* We don't call debug_get_real_type, because somebody might have | |
2216 | called debug_record_type_size on a named or indirect type. */ | |
2217 | ||
2218 | if (type->size != 0) | |
2219 | return type->size; | |
2220 | ||
2221 | switch (type->kind) | |
2222 | { | |
2223 | default: | |
2224 | return 0; | |
2225 | case DEBUG_KIND_INDIRECT: | |
2226 | if (*type->u.kindirect->slot != NULL) | |
2227 | return debug_get_type_size (handle, *type->u.kindirect->slot); | |
2228 | return 0; | |
2229 | case DEBUG_KIND_NAMED: | |
2230 | case DEBUG_KIND_TAGGED: | |
2231 | return debug_get_type_size (handle, type->u.knamed->type); | |
2232 | } | |
2233 | /*NOTREACHED*/ | |
2234 | } | |
2235 | ||
07aa1e1b ILT |
2236 | /* Get the return type of a function or method type. */ |
2237 | ||
2238 | debug_type | |
2239 | debug_get_return_type (handle, type) | |
2240 | PTR handle; | |
2241 | debug_type type; | |
2242 | { | |
2243 | if (type == NULL) | |
2244 | return DEBUG_TYPE_NULL; | |
2245 | type = debug_get_real_type (handle, type); | |
2246 | switch (type->kind) | |
2247 | { | |
2248 | default: | |
2249 | return DEBUG_TYPE_NULL; | |
2250 | case DEBUG_KIND_FUNCTION: | |
2251 | return type->u.kfunction->return_type; | |
2252 | case DEBUG_KIND_METHOD: | |
2253 | return type->u.kmethod->return_type; | |
2254 | } | |
2255 | /*NOTREACHED*/ | |
2256 | } | |
2257 | ||
2258 | /* Get the parameter types of a function or method type (except that | |
2259 | we don't currently store the parameter types of a function). */ | |
2260 | ||
2261 | const debug_type * | |
267e5298 | 2262 | debug_get_parameter_types (handle, type, pvarargs) |
07aa1e1b ILT |
2263 | PTR handle; |
2264 | debug_type type; | |
267e5298 | 2265 | boolean *pvarargs; |
07aa1e1b ILT |
2266 | { |
2267 | if (type == NULL) | |
2268 | return NULL; | |
2269 | type = debug_get_real_type (handle, type); | |
2270 | switch (type->kind) | |
2271 | { | |
2272 | default: | |
2273 | return NULL; | |
501be095 ILT |
2274 | case DEBUG_KIND_FUNCTION: |
2275 | *pvarargs = type->u.kfunction->varargs; | |
2276 | return type->u.kfunction->arg_types; | |
07aa1e1b | 2277 | case DEBUG_KIND_METHOD: |
267e5298 | 2278 | *pvarargs = type->u.kmethod->varargs; |
07aa1e1b ILT |
2279 | return type->u.kmethod->arg_types; |
2280 | } | |
2281 | /*NOTREACHED*/ | |
2282 | } | |
2283 | ||
267e5298 ILT |
2284 | /* Get the target type of a type. */ |
2285 | ||
2286 | debug_type | |
2287 | debug_get_target_type (handle, type) | |
2288 | PTR handle; | |
2289 | debug_type type; | |
2290 | { | |
2291 | if (type == NULL) | |
2292 | return NULL; | |
2293 | type = debug_get_real_type (handle, type); | |
2294 | switch (type->kind) | |
2295 | { | |
2296 | default: | |
2297 | return NULL; | |
2298 | case DEBUG_KIND_POINTER: | |
2299 | return type->u.kpointer; | |
2300 | case DEBUG_KIND_REFERENCE: | |
2301 | return type->u.kreference; | |
2302 | case DEBUG_KIND_CONST: | |
2303 | return type->u.kconst; | |
2304 | case DEBUG_KIND_VOLATILE: | |
2305 | return type->u.kvolatile; | |
2306 | } | |
2307 | /*NOTREACHED*/ | |
2308 | } | |
2309 | ||
07aa1e1b ILT |
2310 | /* Get the NULL terminated array of fields for a struct, union, or |
2311 | class. */ | |
2312 | ||
2313 | const debug_field * | |
2314 | debug_get_fields (handle, type) | |
2315 | PTR handle; | |
2316 | debug_type type; | |
2317 | { | |
2318 | if (type == NULL) | |
2319 | return NULL; | |
2320 | type = debug_get_real_type (handle, type); | |
2321 | switch (type->kind) | |
2322 | { | |
2323 | default: | |
2324 | return NULL; | |
2325 | case DEBUG_KIND_STRUCT: | |
2326 | case DEBUG_KIND_UNION: | |
2327 | case DEBUG_KIND_CLASS: | |
2328 | case DEBUG_KIND_UNION_CLASS: | |
2329 | return type->u.kclass->fields; | |
2330 | } | |
2331 | /*NOTREACHED*/ | |
2332 | } | |
2333 | ||
2334 | /* Get the type of a field. */ | |
2335 | ||
2336 | /*ARGSUSED*/ | |
2337 | debug_type | |
2338 | debug_get_field_type (handle, field) | |
2339 | PTR handle; | |
2340 | debug_field field; | |
2341 | { | |
2342 | if (field == NULL) | |
2343 | return NULL; | |
2344 | return field->type; | |
2345 | } | |
35aa91b9 ILT |
2346 | |
2347 | /* Get the name of a field. */ | |
2348 | ||
2349 | /*ARGSUSED*/ | |
2350 | const char * | |
2351 | debug_get_field_name (handle, field) | |
2352 | PTR handle; | |
2353 | debug_field field; | |
2354 | { | |
2355 | if (field == NULL) | |
2356 | return NULL; | |
2357 | return field->name; | |
2358 | } | |
2359 | ||
2360 | /* Get the bit position of a field. */ | |
2361 | ||
2362 | /*ARGSUSED*/ | |
2363 | bfd_vma | |
2364 | debug_get_field_bitpos (handle, field) | |
2365 | PTR handle; | |
2366 | debug_field field; | |
2367 | { | |
2368 | if (field == NULL || field->static_member) | |
2369 | return (bfd_vma) -1; | |
2370 | return field->u.f.bitpos; | |
2371 | } | |
2372 | ||
2373 | /* Get the bit size of a field. */ | |
2374 | ||
2375 | /*ARGSUSED*/ | |
2376 | bfd_vma | |
2377 | debug_get_field_bitsize (handle, field) | |
2378 | PTR handle; | |
2379 | debug_field field; | |
2380 | { | |
2381 | if (field == NULL || field->static_member) | |
2382 | return (bfd_vma) -1; | |
2383 | return field->u.f.bitsize; | |
2384 | } | |
2385 | ||
2386 | /* Get the visibility of a field. */ | |
2387 | ||
2388 | /*ARGSUSED*/ | |
2389 | enum debug_visibility | |
2390 | debug_get_field_visibility (handle, field) | |
2391 | PTR handle; | |
2392 | debug_field field; | |
2393 | { | |
2394 | if (field == NULL) | |
2395 | return DEBUG_VISIBILITY_IGNORE; | |
2396 | return field->visibility; | |
2397 | } | |
2398 | ||
2399 | /* Get the physical name of a field. */ | |
2400 | ||
2401 | const char * | |
2402 | debug_get_field_physname (handle, field) | |
2403 | PTR handle; | |
2404 | debug_field field; | |
2405 | { | |
2406 | if (field == NULL || ! field->static_member) | |
2407 | return NULL; | |
2408 | return field->u.s.physname; | |
2409 | } | |
e1c14599 ILT |
2410 | \f |
2411 | /* Write out the debugging information. This is given a handle to | |
2412 | debugging information, and a set of function pointers to call. */ | |
2413 | ||
2414 | boolean | |
2415 | debug_write (handle, fns, fhandle) | |
2416 | PTR handle; | |
2417 | const struct debug_write_fns *fns; | |
2418 | PTR fhandle; | |
2419 | { | |
2420 | struct debug_handle *info = (struct debug_handle *) handle; | |
2421 | struct debug_unit *u; | |
2422 | ||
2423 | /* We use a mark to tell whether we have already written out a | |
2424 | particular name. We use an integer, so that we don't have to | |
2425 | clear the mark fields if we happen to write out the same | |
2426 | information more than once. */ | |
2427 | ++info->mark; | |
2428 | ||
07aa1e1b ILT |
2429 | /* The base_id field holds an ID value which will never be used, so |
2430 | that we can tell whether we have assigned an ID during this call | |
2431 | to debug_write. */ | |
2432 | info->base_id = info->class_id; | |
2433 | ||
e1b88109 ILT |
2434 | /* We keep a linked list of classes for which was have assigned ID's |
2435 | during this call to debug_write. */ | |
2436 | info->id_list = NULL; | |
2437 | ||
e1c14599 ILT |
2438 | for (u = info->units; u != NULL; u = u->next) |
2439 | { | |
2440 | struct debug_file *f; | |
2441 | boolean first_file; | |
63840d26 | 2442 | struct debug_lineno *l; |
e1c14599 ILT |
2443 | |
2444 | if (! (*fns->start_compilation_unit) (fhandle, u->files->filename)) | |
2445 | return false; | |
2446 | ||
2447 | first_file = true; | |
2448 | for (f = u->files; f != NULL; f = f->next) | |
2449 | { | |
2450 | struct debug_name *n; | |
2451 | ||
2452 | if (first_file) | |
2453 | first_file = false; | |
2454 | else | |
2455 | { | |
2456 | if (! (*fns->start_source) (fhandle, f->filename)) | |
2457 | return false; | |
2458 | } | |
2459 | ||
2460 | if (f->globals != NULL) | |
2461 | { | |
2462 | for (n = f->globals->list; n != NULL; n = n->next) | |
2463 | { | |
2464 | if (! debug_write_name (info, fns, fhandle, n)) | |
2465 | return false; | |
2466 | } | |
2467 | } | |
2468 | } | |
63840d26 ILT |
2469 | |
2470 | for (l = u->linenos; l != NULL; l = l->next) | |
2471 | { | |
2472 | unsigned int i; | |
2473 | ||
2474 | for (i = 0; i < DEBUG_LINENO_COUNT; i++) | |
2475 | { | |
2476 | if (l->linenos[i] == (unsigned long) -1) | |
2477 | break; | |
2478 | if (! (*fns->lineno) (fhandle, l->file->filename, l->linenos[i], | |
2479 | l->addrs[i])) | |
2480 | return false; | |
2481 | } | |
2482 | } | |
e1c14599 ILT |
2483 | } |
2484 | ||
2485 | return true; | |
2486 | } | |
2487 | ||
2488 | /* Write out an element in a namespace. */ | |
2489 | ||
2490 | static boolean | |
2491 | debug_write_name (info, fns, fhandle, n) | |
2492 | struct debug_handle *info; | |
2493 | const struct debug_write_fns *fns; | |
2494 | PTR fhandle; | |
2495 | struct debug_name *n; | |
2496 | { | |
e1c14599 ILT |
2497 | switch (n->kind) |
2498 | { | |
2499 | case DEBUG_OBJECT_TYPE: | |
2500 | if (! debug_write_type (info, fns, fhandle, n->u.type, n) | |
2501 | || ! (*fns->typdef) (fhandle, n->name)) | |
2502 | return false; | |
2503 | return true; | |
2504 | case DEBUG_OBJECT_TAG: | |
2505 | if (! debug_write_type (info, fns, fhandle, n->u.tag, n)) | |
2506 | return false; | |
2507 | return (*fns->tag) (fhandle, n->name); | |
2508 | case DEBUG_OBJECT_VARIABLE: | |
2509 | if (! debug_write_type (info, fns, fhandle, n->u.variable->type, | |
2510 | (struct debug_name *) NULL)) | |
2511 | return false; | |
2512 | return (*fns->variable) (fhandle, n->name, n->u.variable->kind, | |
2513 | n->u.variable->val); | |
2514 | case DEBUG_OBJECT_FUNCTION: | |
2515 | return debug_write_function (info, fns, fhandle, n->name, | |
2516 | n->linkage, n->u.function); | |
2517 | case DEBUG_OBJECT_INT_CONSTANT: | |
2518 | return (*fns->int_constant) (fhandle, n->name, n->u.int_constant); | |
2519 | case DEBUG_OBJECT_FLOAT_CONSTANT: | |
2520 | return (*fns->float_constant) (fhandle, n->name, n->u.float_constant); | |
2521 | case DEBUG_OBJECT_TYPED_CONSTANT: | |
2522 | if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type, | |
2523 | (struct debug_name *) NULL)) | |
2524 | return false; | |
2525 | return (*fns->typed_constant) (fhandle, n->name, | |
2526 | n->u.typed_constant->val); | |
2527 | default: | |
2528 | abort (); | |
2529 | return false; | |
2530 | } | |
2531 | /*NOTREACHED*/ | |
2532 | } | |
2533 | ||
63840d26 ILT |
2534 | /* Write out a type. If the type is DEBUG_KIND_NAMED or |
2535 | DEBUG_KIND_TAGGED, then the name argument is the name for which we | |
2536 | are about to call typedef or tag. If the type is anything else, | |
2537 | then the name argument is a tag from a DEBUG_KIND_TAGGED type which | |
2538 | points to this one. */ | |
e1c14599 ILT |
2539 | |
2540 | static boolean | |
2541 | debug_write_type (info, fns, fhandle, type, name) | |
2542 | struct debug_handle *info; | |
2543 | const struct debug_write_fns *fns; | |
2544 | PTR fhandle; | |
2545 | struct debug_type *type; | |
2546 | struct debug_name *name; | |
2547 | { | |
2548 | unsigned int i; | |
267e5298 | 2549 | int is; |
63840d26 | 2550 | const char *tag; |
e1c14599 ILT |
2551 | |
2552 | /* If we have a name for this type, just output it. We only output | |
2553 | typedef names after they have been defined. We output type tags | |
2554 | whenever we are not actually defining them. */ | |
2555 | if ((type->kind == DEBUG_KIND_NAMED | |
2556 | || type->kind == DEBUG_KIND_TAGGED) | |
2557 | && (type->u.knamed->name->mark == info->mark | |
2558 | || (type->kind == DEBUG_KIND_TAGGED | |
2559 | && type->u.knamed->name != name))) | |
2560 | { | |
2561 | if (type->kind == DEBUG_KIND_NAMED) | |
2562 | return (*fns->typedef_type) (fhandle, type->u.knamed->name->name); | |
2563 | else | |
35aa91b9 ILT |
2564 | { |
2565 | struct debug_type *real; | |
e1b88109 | 2566 | unsigned int id; |
35aa91b9 ILT |
2567 | |
2568 | real = debug_get_real_type ((PTR) info, type); | |
e1b88109 ILT |
2569 | id = 0; |
2570 | if ((real->kind == DEBUG_KIND_STRUCT | |
2571 | || real->kind == DEBUG_KIND_UNION | |
2572 | || real->kind == DEBUG_KIND_CLASS | |
2573 | || real->kind == DEBUG_KIND_UNION_CLASS) | |
2574 | && real->u.kclass != NULL) | |
2575 | { | |
2576 | if (real->u.kclass->id <= info->base_id) | |
2577 | { | |
2578 | if (! debug_set_class_id (info, | |
2579 | type->u.knamed->name->name, | |
2580 | real)) | |
2581 | return false; | |
2582 | } | |
2583 | id = real->u.kclass->id; | |
2584 | } | |
2585 | ||
2586 | return (*fns->tag_type) (fhandle, type->u.knamed->name->name, id, | |
35aa91b9 ILT |
2587 | real->kind); |
2588 | } | |
e1c14599 ILT |
2589 | } |
2590 | ||
2591 | /* Mark the name after we have already looked for a known name, so | |
2592 | that we don't just define a type in terms of itself. We need to | |
2593 | mark the name here so that a struct containing a pointer to | |
2594 | itself will work. */ | |
2595 | if (name != NULL) | |
2596 | name->mark = info->mark; | |
2597 | ||
63840d26 ILT |
2598 | tag = NULL; |
2599 | if (name != NULL | |
2600 | && type->kind != DEBUG_KIND_NAMED | |
2601 | && type->kind != DEBUG_KIND_TAGGED) | |
2602 | { | |
2603 | assert (name->kind == DEBUG_OBJECT_TAG); | |
2604 | tag = name->name; | |
2605 | } | |
2606 | ||
e1c14599 ILT |
2607 | switch (type->kind) |
2608 | { | |
07aa1e1b ILT |
2609 | case DEBUG_KIND_ILLEGAL: |
2610 | debug_error ("debug_write_type: illegal type encountered"); | |
2611 | return false; | |
e1c14599 ILT |
2612 | case DEBUG_KIND_INDIRECT: |
2613 | if (*type->u.kindirect->slot == DEBUG_TYPE_NULL) | |
2614 | return (*fns->empty_type) (fhandle); | |
2615 | return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot, | |
35aa91b9 | 2616 | name); |
e1c14599 ILT |
2617 | case DEBUG_KIND_VOID: |
2618 | return (*fns->void_type) (fhandle); | |
2619 | case DEBUG_KIND_INT: | |
2620 | return (*fns->int_type) (fhandle, type->size, type->u.kint); | |
2621 | case DEBUG_KIND_FLOAT: | |
2622 | return (*fns->float_type) (fhandle, type->size); | |
2623 | case DEBUG_KIND_COMPLEX: | |
2624 | return (*fns->complex_type) (fhandle, type->size); | |
2625 | case DEBUG_KIND_BOOL: | |
2626 | return (*fns->bool_type) (fhandle, type->size); | |
2627 | case DEBUG_KIND_STRUCT: | |
2628 | case DEBUG_KIND_UNION: | |
36302909 | 2629 | if (type->u.kclass != NULL) |
e1c14599 | 2630 | { |
e1b88109 ILT |
2631 | if (type->u.kclass->id <= info->base_id) |
2632 | { | |
2633 | if (! debug_set_class_id (info, tag, type)) | |
2634 | return false; | |
2635 | } | |
2636 | ||
2637 | if (info->mark == type->u.kclass->mark) | |
36302909 | 2638 | { |
07aa1e1b ILT |
2639 | /* We are currently outputting this struct, or we have |
2640 | already output it. I don't know if this can happen, | |
2641 | but it can happen for a class. */ | |
2642 | assert (type->u.kclass->id > info->base_id); | |
2643 | return (*fns->tag_type) (fhandle, tag, type->u.kclass->id, | |
2644 | type->kind); | |
36302909 | 2645 | } |
e1b88109 | 2646 | type->u.kclass->mark = info->mark; |
e1c14599 | 2647 | } |
e1c14599 | 2648 | |
63840d26 | 2649 | if (! (*fns->start_struct_type) (fhandle, tag, |
07aa1e1b ILT |
2650 | (type->u.kclass != NULL |
2651 | ? type->u.kclass->id | |
2652 | : 0), | |
e1c14599 ILT |
2653 | type->kind == DEBUG_KIND_STRUCT, |
2654 | type->size)) | |
2655 | return false; | |
36302909 ILT |
2656 | if (type->u.kclass != NULL |
2657 | && type->u.kclass->fields != NULL) | |
e1c14599 ILT |
2658 | { |
2659 | for (i = 0; type->u.kclass->fields[i] != NULL; i++) | |
2660 | { | |
2661 | struct debug_field *f; | |
2662 | ||
2663 | f = type->u.kclass->fields[i]; | |
2664 | if (! debug_write_type (info, fns, fhandle, f->type, | |
2665 | (struct debug_name *) NULL) | |
2666 | || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos, | |
2667 | f->u.f.bitsize, f->visibility)) | |
2668 | return false; | |
2669 | } | |
2670 | } | |
2671 | return (*fns->end_struct_type) (fhandle); | |
2672 | case DEBUG_KIND_CLASS: | |
2673 | case DEBUG_KIND_UNION_CLASS: | |
63840d26 | 2674 | return debug_write_class_type (info, fns, fhandle, type, tag); |
e1c14599 | 2675 | case DEBUG_KIND_ENUM: |
36302909 ILT |
2676 | if (type->u.kenum == NULL) |
2677 | return (*fns->enum_type) (fhandle, tag, (const char **) NULL, | |
2678 | (bfd_signed_vma *) NULL); | |
63840d26 | 2679 | return (*fns->enum_type) (fhandle, tag, type->u.kenum->names, |
e1c14599 ILT |
2680 | type->u.kenum->values); |
2681 | case DEBUG_KIND_POINTER: | |
2682 | if (! debug_write_type (info, fns, fhandle, type->u.kpointer, | |
2683 | (struct debug_name *) NULL)) | |
2684 | return false; | |
2685 | return (*fns->pointer_type) (fhandle); | |
2686 | case DEBUG_KIND_FUNCTION: | |
267e5298 ILT |
2687 | if (type->u.kfunction->arg_types == NULL) |
2688 | is = -1; | |
2689 | else | |
2690 | { | |
2691 | for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++) | |
2692 | if (! debug_write_type (info, fns, fhandle, | |
2693 | type->u.kfunction->arg_types[is], | |
2694 | (struct debug_name *) NULL)) | |
2695 | return false; | |
2696 | } | |
e1c14599 ILT |
2697 | if (! debug_write_type (info, fns, fhandle, |
2698 | type->u.kfunction->return_type, | |
2699 | (struct debug_name *) NULL)) | |
2700 | return false; | |
267e5298 ILT |
2701 | return (*fns->function_type) (fhandle, is, |
2702 | type->u.kfunction->varargs); | |
e1c14599 ILT |
2703 | case DEBUG_KIND_REFERENCE: |
2704 | if (! debug_write_type (info, fns, fhandle, type->u.kreference, | |
2705 | (struct debug_name *) NULL)) | |
2706 | return false; | |
2707 | return (*fns->reference_type) (fhandle); | |
2708 | case DEBUG_KIND_RANGE: | |
2709 | if (! debug_write_type (info, fns, fhandle, type->u.krange->type, | |
2710 | (struct debug_name *) NULL)) | |
2711 | return false; | |
2712 | return (*fns->range_type) (fhandle, type->u.krange->lower, | |
2713 | type->u.krange->upper); | |
2714 | case DEBUG_KIND_ARRAY: | |
2715 | if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type, | |
2716 | (struct debug_name *) NULL) | |
2717 | || ! debug_write_type (info, fns, fhandle, | |
2718 | type->u.karray->range_type, | |
2719 | (struct debug_name *) NULL)) | |
2720 | return false; | |
2721 | return (*fns->array_type) (fhandle, type->u.karray->lower, | |
2722 | type->u.karray->upper, | |
2723 | type->u.karray->stringp); | |
2724 | case DEBUG_KIND_SET: | |
2725 | if (! debug_write_type (info, fns, fhandle, type->u.kset->type, | |
2726 | (struct debug_name *) NULL)) | |
2727 | return false; | |
2728 | return (*fns->set_type) (fhandle, type->u.kset->bitstringp); | |
2729 | case DEBUG_KIND_OFFSET: | |
2730 | if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type, | |
2731 | (struct debug_name *) NULL) | |
2732 | || ! debug_write_type (info, fns, fhandle, | |
2733 | type->u.koffset->target_type, | |
2734 | (struct debug_name *) NULL)) | |
2735 | return false; | |
2736 | return (*fns->offset_type) (fhandle); | |
2737 | case DEBUG_KIND_METHOD: | |
2738 | if (! debug_write_type (info, fns, fhandle, | |
2739 | type->u.kmethod->return_type, | |
2740 | (struct debug_name *) NULL)) | |
2741 | return false; | |
2742 | if (type->u.kmethod->arg_types == NULL) | |
267e5298 | 2743 | is = -1; |
e1c14599 ILT |
2744 | else |
2745 | { | |
267e5298 ILT |
2746 | for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++) |
2747 | if (! debug_write_type (info, fns, fhandle, | |
2748 | type->u.kmethod->arg_types[is], | |
2749 | (struct debug_name *) NULL)) | |
2750 | return false; | |
e1c14599 ILT |
2751 | } |
2752 | if (type->u.kmethod->domain_type != NULL) | |
2753 | { | |
2754 | if (! debug_write_type (info, fns, fhandle, | |
2755 | type->u.kmethod->domain_type, | |
2756 | (struct debug_name *) NULL)) | |
2757 | return false; | |
2758 | } | |
2759 | return (*fns->method_type) (fhandle, | |
2760 | type->u.kmethod->domain_type != NULL, | |
267e5298 ILT |
2761 | is, |
2762 | type->u.kmethod->varargs); | |
e1c14599 ILT |
2763 | case DEBUG_KIND_CONST: |
2764 | if (! debug_write_type (info, fns, fhandle, type->u.kconst, | |
2765 | (struct debug_name *) NULL)) | |
2766 | return false; | |
2767 | return (*fns->const_type) (fhandle); | |
2768 | case DEBUG_KIND_VOLATILE: | |
2769 | if (! debug_write_type (info, fns, fhandle, type->u.kvolatile, | |
2770 | (struct debug_name *) NULL)) | |
2771 | return false; | |
2772 | return (*fns->volatile_type) (fhandle); | |
2773 | case DEBUG_KIND_NAMED: | |
e1c14599 ILT |
2774 | return debug_write_type (info, fns, fhandle, type->u.knamed->type, |
2775 | (struct debug_name *) NULL); | |
63840d26 ILT |
2776 | case DEBUG_KIND_TAGGED: |
2777 | return debug_write_type (info, fns, fhandle, type->u.knamed->type, | |
2778 | type->u.knamed->name); | |
e1c14599 ILT |
2779 | default: |
2780 | abort (); | |
2781 | return false; | |
2782 | } | |
2783 | } | |
2784 | ||
2785 | /* Write out a class type. */ | |
2786 | ||
2787 | static boolean | |
63840d26 | 2788 | debug_write_class_type (info, fns, fhandle, type, tag) |
e1c14599 ILT |
2789 | struct debug_handle *info; |
2790 | const struct debug_write_fns *fns; | |
2791 | PTR fhandle; | |
2792 | struct debug_type *type; | |
63840d26 | 2793 | const char *tag; |
e1c14599 ILT |
2794 | { |
2795 | unsigned int i; | |
07aa1e1b ILT |
2796 | unsigned int id; |
2797 | struct debug_type *vptrbase; | |
e1c14599 | 2798 | |
07aa1e1b | 2799 | if (type->u.kclass == NULL) |
e1c14599 | 2800 | { |
07aa1e1b ILT |
2801 | id = 0; |
2802 | vptrbase = NULL; | |
2803 | } | |
2804 | else | |
2805 | { | |
e1b88109 ILT |
2806 | if (type->u.kclass->id <= info->base_id) |
2807 | { | |
2808 | if (! debug_set_class_id (info, tag, type)) | |
2809 | return false; | |
2810 | } | |
2811 | ||
2812 | if (info->mark == type->u.kclass->mark) | |
36302909 | 2813 | { |
07aa1e1b ILT |
2814 | /* We are currently outputting this class, or we have |
2815 | already output it. This can happen when there are | |
2816 | methods for an anonymous class. */ | |
2817 | assert (type->u.kclass->id > info->base_id); | |
2818 | return (*fns->tag_type) (fhandle, tag, type->u.kclass->id, | |
2819 | type->kind); | |
36302909 | 2820 | } |
e1b88109 | 2821 | type->u.kclass->mark = info->mark; |
76e45938 | 2822 | id = type->u.kclass->id; |
e1c14599 | 2823 | |
07aa1e1b ILT |
2824 | vptrbase = type->u.kclass->vptrbase; |
2825 | if (vptrbase != NULL && vptrbase != type) | |
36302909 | 2826 | { |
07aa1e1b | 2827 | if (! debug_write_type (info, fns, fhandle, vptrbase, |
36302909 ILT |
2828 | (struct debug_name *) NULL)) |
2829 | return false; | |
2830 | } | |
e1c14599 ILT |
2831 | } |
2832 | ||
07aa1e1b | 2833 | if (! (*fns->start_class_type) (fhandle, tag, id, |
e1c14599 ILT |
2834 | type->kind == DEBUG_KIND_CLASS, |
2835 | type->size, | |
07aa1e1b ILT |
2836 | vptrbase != NULL, |
2837 | vptrbase == type)) | |
e1c14599 | 2838 | return false; |
36302909 ILT |
2839 | |
2840 | if (type->u.kclass != NULL) | |
e1c14599 | 2841 | { |
36302909 | 2842 | if (type->u.kclass->fields != NULL) |
e1c14599 | 2843 | { |
36302909 | 2844 | for (i = 0; type->u.kclass->fields[i] != NULL; i++) |
e1c14599 | 2845 | { |
36302909 ILT |
2846 | struct debug_field *f; |
2847 | ||
2848 | f = type->u.kclass->fields[i]; | |
2849 | if (! debug_write_type (info, fns, fhandle, f->type, | |
2850 | (struct debug_name *) NULL)) | |
e1c14599 | 2851 | return false; |
36302909 ILT |
2852 | if (f->static_member) |
2853 | { | |
2854 | if (! (*fns->class_static_member) (fhandle, f->name, | |
2855 | f->u.s.physname, | |
2856 | f->visibility)) | |
2857 | return false; | |
2858 | } | |
2859 | else | |
2860 | { | |
2861 | if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos, | |
2862 | f->u.f.bitsize, f->visibility)) | |
2863 | return false; | |
2864 | } | |
e1c14599 ILT |
2865 | } |
2866 | } | |
e1c14599 | 2867 | |
36302909 | 2868 | if (type->u.kclass->baseclasses != NULL) |
e1c14599 | 2869 | { |
36302909 ILT |
2870 | for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++) |
2871 | { | |
2872 | struct debug_baseclass *b; | |
e1c14599 | 2873 | |
36302909 ILT |
2874 | b = type->u.kclass->baseclasses[i]; |
2875 | if (! debug_write_type (info, fns, fhandle, b->type, | |
2876 | (struct debug_name *) NULL)) | |
2877 | return false; | |
2878 | if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual, | |
2879 | b->visibility)) | |
2880 | return false; | |
2881 | } | |
e1c14599 | 2882 | } |
e1c14599 | 2883 | |
36302909 | 2884 | if (type->u.kclass->methods != NULL) |
e1c14599 | 2885 | { |
36302909 | 2886 | for (i = 0; type->u.kclass->methods[i] != NULL; i++) |
e1c14599 | 2887 | { |
36302909 ILT |
2888 | struct debug_method *m; |
2889 | unsigned int j; | |
e1c14599 | 2890 | |
36302909 ILT |
2891 | m = type->u.kclass->methods[i]; |
2892 | if (! (*fns->class_start_method) (fhandle, m->name)) | |
2893 | return false; | |
2894 | for (j = 0; m->variants[j] != NULL; j++) | |
e1c14599 | 2895 | { |
36302909 ILT |
2896 | struct debug_method_variant *v; |
2897 | ||
2898 | v = m->variants[j]; | |
2899 | if (v->context != NULL) | |
2900 | { | |
2901 | if (! debug_write_type (info, fns, fhandle, v->context, | |
2902 | (struct debug_name *) NULL)) | |
2903 | return false; | |
2904 | } | |
2905 | if (! debug_write_type (info, fns, fhandle, v->type, | |
e1c14599 ILT |
2906 | (struct debug_name *) NULL)) |
2907 | return false; | |
36302909 ILT |
2908 | if (v->voffset != VOFFSET_STATIC_METHOD) |
2909 | { | |
07aa1e1b | 2910 | if (! (*fns->class_method_variant) (fhandle, v->physname, |
36302909 ILT |
2911 | v->visibility, |
2912 | v->constp, | |
2913 | v->volatilep, | |
2914 | v->voffset, | |
2915 | v->context != NULL)) | |
2916 | return false; | |
2917 | } | |
2918 | else | |
2919 | { | |
2920 | if (! (*fns->class_static_method_variant) (fhandle, | |
07aa1e1b | 2921 | v->physname, |
36302909 ILT |
2922 | v->visibility, |
2923 | v->constp, | |
2924 | v->volatilep)) | |
2925 | return false; | |
2926 | } | |
e1c14599 | 2927 | } |
36302909 | 2928 | if (! (*fns->class_end_method) (fhandle)) |
e1c14599 | 2929 | return false; |
e1c14599 | 2930 | } |
e1c14599 ILT |
2931 | } |
2932 | } | |
2933 | ||
2934 | return (*fns->end_class_type) (fhandle); | |
2935 | } | |
2936 | ||
2937 | /* Write out information for a function. */ | |
2938 | ||
2939 | static boolean | |
2940 | debug_write_function (info, fns, fhandle, name, linkage, function) | |
2941 | struct debug_handle *info; | |
2942 | const struct debug_write_fns *fns; | |
2943 | PTR fhandle; | |
2944 | const char *name; | |
2945 | enum debug_object_linkage linkage; | |
2946 | struct debug_function *function; | |
2947 | { | |
2948 | struct debug_parameter *p; | |
2949 | struct debug_block *b; | |
2950 | ||
2951 | if (! debug_write_type (info, fns, fhandle, function->return_type, | |
2952 | (struct debug_name *) NULL)) | |
2953 | return false; | |
2954 | ||
2955 | if (! (*fns->start_function) (fhandle, name, | |
2956 | linkage == DEBUG_LINKAGE_GLOBAL)) | |
2957 | return false; | |
2958 | ||
2959 | for (p = function->parameters; p != NULL; p = p->next) | |
2960 | { | |
2961 | if (! debug_write_type (info, fns, fhandle, p->type, | |
2962 | (struct debug_name *) NULL) | |
2963 | || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val)) | |
2964 | return false; | |
2965 | } | |
2966 | ||
2967 | for (b = function->blocks; b != NULL; b = b->next) | |
2968 | { | |
2969 | if (! debug_write_block (info, fns, fhandle, b)) | |
2970 | return false; | |
2971 | } | |
2972 | ||
2973 | return (*fns->end_function) (fhandle); | |
2974 | } | |
2975 | ||
2976 | /* Write out information for a block. */ | |
2977 | ||
2978 | static boolean | |
2979 | debug_write_block (info, fns, fhandle, block) | |
2980 | struct debug_handle *info; | |
2981 | const struct debug_write_fns *fns; | |
2982 | PTR fhandle; | |
2983 | struct debug_block *block; | |
2984 | { | |
2985 | struct debug_name *n; | |
e1c14599 ILT |
2986 | struct debug_block *b; |
2987 | ||
e1b88109 ILT |
2988 | /* I can't see any point to writing out a block with no local |
2989 | variables, so we don't bother, except for the top level block. */ | |
2990 | if (block->locals != NULL || block->parent == NULL) | |
2991 | { | |
2992 | if (! (*fns->start_block) (fhandle, block->start)) | |
2993 | return false; | |
2994 | } | |
e1c14599 ILT |
2995 | |
2996 | if (block->locals != NULL) | |
2997 | { | |
2998 | for (n = block->locals->list; n != NULL; n = n->next) | |
2999 | { | |
3000 | if (! debug_write_name (info, fns, fhandle, n)) | |
3001 | return false; | |
3002 | } | |
3003 | } | |
3004 | ||
e1c14599 ILT |
3005 | for (b = block->children; b != NULL; b = b->next) |
3006 | { | |
3007 | if (! debug_write_block (info, fns, fhandle, b)) | |
3008 | return false; | |
3009 | } | |
3010 | ||
e1b88109 ILT |
3011 | if (block->locals != NULL || block->parent == NULL) |
3012 | { | |
3013 | if (! (*fns->end_block) (fhandle, block->end)) | |
3014 | return false; | |
3015 | } | |
3016 | ||
3017 | return true; | |
3018 | } | |
3019 | ||
3020 | /* Get the ID number for a class. If during the same call to | |
3021 | debug_write we find a struct with the same definition with the same | |
3022 | name, we use the same ID. This type of things happens because the | |
3023 | same struct will be defined by multiple compilation units. */ | |
3024 | ||
3025 | static boolean | |
3026 | debug_set_class_id (info, tag, type) | |
3027 | struct debug_handle *info; | |
3028 | const char *tag; | |
3029 | struct debug_type *type; | |
3030 | { | |
3031 | struct debug_class_type *c; | |
3032 | struct debug_class_id *l; | |
3033 | ||
3034 | assert (type->kind == DEBUG_KIND_STRUCT | |
3035 | || type->kind == DEBUG_KIND_UNION | |
3036 | || type->kind == DEBUG_KIND_CLASS | |
3037 | || type->kind == DEBUG_KIND_UNION_CLASS); | |
3038 | ||
3039 | c = type->u.kclass; | |
3040 | ||
3041 | if (c->id > info->base_id) | |
3042 | return true; | |
3043 | ||
3044 | for (l = info->id_list; l != NULL; l = l->next) | |
3045 | { | |
3046 | if (l->type->kind != type->kind) | |
3047 | continue; | |
3048 | ||
3049 | if (tag == NULL) | |
3050 | { | |
3051 | if (l->tag != NULL) | |
3052 | continue; | |
3053 | } | |
3054 | else | |
3055 | { | |
3056 | if (l->tag == NULL | |
3057 | || l->tag[0] != tag[0] | |
3058 | || strcmp (l->tag, tag) != 0) | |
3059 | continue; | |
3060 | } | |
3061 | ||
3062 | if (debug_type_samep (info, l->type, type)) | |
3063 | { | |
3064 | c->id = l->type->u.kclass->id; | |
3065 | return true; | |
3066 | } | |
3067 | } | |
3068 | ||
3069 | /* There are no identical types. Use a new ID, and add it to the | |
3070 | list. */ | |
3071 | ++info->class_id; | |
3072 | c->id = info->class_id; | |
3073 | ||
3074 | l = (struct debug_class_id *) xmalloc (sizeof *l); | |
3075 | memset (l, 0, sizeof *l); | |
3076 | ||
3077 | l->type = type; | |
3078 | l->tag = tag; | |
3079 | ||
3080 | l->next = info->id_list; | |
3081 | info->id_list = l; | |
3082 | ||
3083 | return true; | |
3084 | } | |
3085 | ||
3086 | /* See if two types are the same. At this point, we don't care about | |
3087 | tags and the like. */ | |
3088 | ||
3089 | static boolean | |
3090 | debug_type_samep (info, t1, t2) | |
3091 | struct debug_handle *info; | |
3092 | struct debug_type *t1; | |
3093 | struct debug_type *t2; | |
3094 | { | |
3095 | struct debug_type_compare_list *l; | |
3096 | struct debug_type_compare_list top; | |
3097 | boolean ret; | |
3098 | ||
3099 | while (t1->kind == DEBUG_KIND_INDIRECT) | |
3100 | { | |
3101 | t1 = *t1->u.kindirect->slot; | |
3102 | if (t1 == NULL) | |
3103 | return false; | |
3104 | } | |
3105 | while (t2->kind == DEBUG_KIND_INDIRECT) | |
3106 | { | |
3107 | t2 = *t2->u.kindirect->slot; | |
3108 | if (t2 == NULL) | |
3109 | return false; | |
3110 | } | |
3111 | ||
3112 | if (t1 == t2) | |
3113 | return true; | |
3114 | ||
3115 | /* As a special case, permit a typedef to match a tag, since C++ | |
3116 | debugging output will sometimes add a typedef where C debugging | |
3117 | output will not. */ | |
3118 | if (t1->kind == DEBUG_KIND_NAMED | |
3119 | && t2->kind == DEBUG_KIND_TAGGED) | |
3120 | return debug_type_samep (info, t1->u.knamed->type, t2); | |
3121 | else if (t1->kind == DEBUG_KIND_TAGGED | |
3122 | && t2->kind == DEBUG_KIND_NAMED) | |
3123 | return debug_type_samep (info, t1, t2->u.knamed->type); | |
3124 | ||
3125 | if (t1->kind != t2->kind | |
3126 | || t1->size != t2->size) | |
3127 | return false; | |
3128 | ||
3129 | /* Get rid of the trivial cases first. */ | |
3130 | switch (t1->kind) | |
3131 | { | |
3132 | default: | |
3133 | break; | |
3134 | case DEBUG_KIND_VOID: | |
3135 | case DEBUG_KIND_FLOAT: | |
3136 | case DEBUG_KIND_COMPLEX: | |
3137 | case DEBUG_KIND_BOOL: | |
3138 | return true; | |
3139 | case DEBUG_KIND_INT: | |
3140 | return t1->u.kint == t2->u.kint; | |
3141 | } | |
3142 | ||
3143 | /* We have to avoid an infinite recursion. We do this by keeping a | |
3144 | list of types which we are comparing. We just keep the list on | |
3145 | the stack. If we encounter a pair of types we are currently | |
3146 | comparing, we just assume that they are equal. */ | |
3147 | for (l = info->compare_list; l != NULL; l = l->next) | |
3148 | { | |
3149 | if (l->t1 == t1 && l->t2 == t2) | |
3150 | return true; | |
3151 | } | |
3152 | ||
3153 | top.t1 = t1; | |
3154 | top.t2 = t2; | |
3155 | top.next = info->compare_list; | |
3156 | info->compare_list = ⊤ | |
3157 | ||
3158 | switch (t1->kind) | |
3159 | { | |
3160 | default: | |
3161 | abort (); | |
3162 | ret = false; | |
3163 | break; | |
3164 | ||
3165 | case DEBUG_KIND_STRUCT: | |
3166 | case DEBUG_KIND_UNION: | |
3167 | case DEBUG_KIND_CLASS: | |
3168 | case DEBUG_KIND_UNION_CLASS: | |
3169 | if (t1->u.kclass == NULL) | |
3170 | ret = t2->u.kclass == NULL; | |
3171 | else if (t2->u.kclass == NULL) | |
3172 | ret = false; | |
3173 | else if (t1->u.kclass->id > info->base_id | |
3174 | && t1->u.kclass->id == t2->u.kclass->id) | |
3175 | ret = true; | |
3176 | else | |
3177 | ret = debug_class_type_samep (info, t1, t2); | |
3178 | break; | |
3179 | ||
3180 | case DEBUG_KIND_ENUM: | |
3181 | if (t1->u.kenum == NULL) | |
3182 | ret = t2->u.kenum == NULL; | |
3183 | else if (t2->u.kenum == NULL) | |
3184 | ret = false; | |
3185 | else | |
3186 | { | |
3187 | const char **pn1, **pn2; | |
3188 | bfd_signed_vma *pv1, *pv2; | |
3189 | ||
3190 | pn1 = t1->u.kenum->names; | |
3191 | pn2 = t2->u.kenum->names; | |
3192 | pv1 = t1->u.kenum->values; | |
3193 | pv2 = t2->u.kenum->values; | |
3194 | while (*pn1 != NULL && *pn2 != NULL) | |
3195 | { | |
3196 | if (**pn1 != **pn2 | |
3197 | || *pv1 != *pv2 | |
3198 | || strcmp (*pn1, *pn2) != 0) | |
3199 | break; | |
3200 | ++pn1; | |
3201 | ++pn2; | |
7826d7e1 ILT |
3202 | ++pv1; |
3203 | ++pv2; | |
e1b88109 ILT |
3204 | } |
3205 | ret = *pn1 == NULL && *pn2 == NULL; | |
3206 | } | |
3207 | break; | |
3208 | ||
3209 | case DEBUG_KIND_POINTER: | |
3210 | ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer); | |
3211 | break; | |
3212 | ||
3213 | case DEBUG_KIND_FUNCTION: | |
3214 | if (t1->u.kfunction->varargs != t2->u.kfunction->varargs | |
3215 | || ! debug_type_samep (info, t1->u.kfunction->return_type, | |
3216 | t2->u.kfunction->return_type) | |
3217 | || ((t1->u.kfunction->arg_types == NULL) | |
3218 | != (t2->u.kfunction->arg_types == NULL))) | |
3219 | ret = false; | |
3220 | else if (t1->u.kfunction->arg_types == NULL) | |
3221 | ret = true; | |
3222 | else | |
3223 | { | |
3224 | struct debug_type **a1, **a2; | |
3225 | ||
3226 | a1 = t1->u.kfunction->arg_types; | |
3227 | a2 = t2->u.kfunction->arg_types; | |
3228 | while (*a1 != NULL && *a2 != NULL) | |
3229 | if (! debug_type_samep (info, *a1, *a2)) | |
3230 | break; | |
3231 | ret = *a1 == NULL && *a2 == NULL; | |
3232 | } | |
3233 | break; | |
3234 | ||
3235 | case DEBUG_KIND_REFERENCE: | |
3236 | ret = debug_type_samep (info, t1->u.kreference, t2->u.kreference); | |
3237 | break; | |
3238 | ||
3239 | case DEBUG_KIND_RANGE: | |
3240 | ret = (t1->u.krange->lower == t2->u.krange->lower | |
3241 | && t1->u.krange->upper == t2->u.krange->upper | |
3242 | && debug_type_samep (info, t1->u.krange->type, | |
3243 | t2->u.krange->type)); | |
3244 | ||
3245 | case DEBUG_KIND_ARRAY: | |
3246 | ret = (t1->u.karray->lower == t2->u.karray->lower | |
3247 | && t1->u.karray->upper == t2->u.karray->upper | |
3248 | && t1->u.karray->stringp == t2->u.karray->stringp | |
3249 | && debug_type_samep (info, t1->u.karray->element_type, | |
3250 | t2->u.karray->element_type)); | |
3251 | break; | |
3252 | ||
3253 | case DEBUG_KIND_SET: | |
3254 | ret = (t1->u.kset->bitstringp == t2->u.kset->bitstringp | |
3255 | && debug_type_samep (info, t1->u.kset->type, t2->u.kset->type)); | |
3256 | break; | |
3257 | ||
3258 | case DEBUG_KIND_OFFSET: | |
3259 | ret = (debug_type_samep (info, t1->u.koffset->base_type, | |
3260 | t2->u.koffset->base_type) | |
3261 | && debug_type_samep (info, t1->u.koffset->target_type, | |
3262 | t2->u.koffset->target_type)); | |
3263 | break; | |
3264 | ||
3265 | case DEBUG_KIND_METHOD: | |
3266 | if (t1->u.kmethod->varargs != t2->u.kmethod->varargs | |
3267 | || ! debug_type_samep (info, t1->u.kmethod->return_type, | |
3268 | t2->u.kmethod->return_type) | |
3269 | || ! debug_type_samep (info, t1->u.kmethod->domain_type, | |
3270 | t2->u.kmethod->domain_type) | |
3271 | || ((t1->u.kmethod->arg_types == NULL) | |
3272 | != (t2->u.kmethod->arg_types == NULL))) | |
3273 | ret = false; | |
3274 | else if (t1->u.kmethod->arg_types == NULL) | |
3275 | ret = true; | |
3276 | else | |
3277 | { | |
3278 | struct debug_type **a1, **a2; | |
3279 | ||
3280 | a1 = t1->u.kmethod->arg_types; | |
3281 | a2 = t2->u.kmethod->arg_types; | |
3282 | while (*a1 != NULL && *a2 != NULL) | |
3283 | if (! debug_type_samep (info, *a1, *a2)) | |
3284 | break; | |
3285 | ret = *a1 == NULL && *a2 == NULL; | |
3286 | } | |
3287 | break; | |
3288 | ||
3289 | case DEBUG_KIND_CONST: | |
3290 | ret = debug_type_samep (info, t1->u.kconst, t2->u.kconst); | |
3291 | break; | |
3292 | ||
3293 | case DEBUG_KIND_VOLATILE: | |
3294 | ret = debug_type_samep (info, t1->u.kvolatile, t2->u.kvolatile); | |
3295 | break; | |
3296 | ||
3297 | case DEBUG_KIND_NAMED: | |
3298 | case DEBUG_KIND_TAGGED: | |
3299 | ret = (strcmp (t1->u.knamed->name->name, t2->u.knamed->name->name) == 0 | |
3300 | && debug_type_samep (info, t1->u.knamed->type, | |
3301 | t2->u.knamed->type)); | |
3302 | break; | |
3303 | } | |
3304 | ||
3305 | info->compare_list = top.next; | |
3306 | ||
3307 | return ret; | |
3308 | } | |
3309 | ||
3310 | /* See if two classes are the same. This is a subroutine of | |
3311 | debug_type_samep. */ | |
3312 | ||
3313 | static boolean | |
3314 | debug_class_type_samep (info, t1, t2) | |
3315 | struct debug_handle *info; | |
3316 | struct debug_type *t1; | |
3317 | struct debug_type *t2; | |
3318 | { | |
3319 | struct debug_class_type *c1, *c2; | |
3320 | ||
3321 | c1 = t1->u.kclass; | |
3322 | c2 = t2->u.kclass; | |
3323 | ||
3324 | if ((c1->fields == NULL) != (c2->fields == NULL) | |
3325 | || (c1->baseclasses == NULL) != (c2->baseclasses == NULL) | |
3326 | || (c1->methods == NULL) != (c2->methods == NULL) | |
3327 | || (c1->vptrbase == NULL) != (c2->vptrbase == NULL)) | |
3328 | return false; | |
3329 | ||
3330 | if (c1->fields != NULL) | |
3331 | { | |
3332 | struct debug_field **pf1, **pf2; | |
3333 | ||
3334 | for (pf1 = c1->fields, pf2 = c2->fields; | |
3335 | *pf1 != NULL && *pf2 != NULL; | |
3336 | pf1++, pf2++) | |
3337 | { | |
3338 | struct debug_field *f1, *f2; | |
3339 | ||
3340 | f1 = *pf1; | |
3341 | f2 = *pf2; | |
3342 | if (f1->name[0] != f2->name[0] | |
3343 | || f1->visibility != f2->visibility | |
3344 | || f1->static_member != f2->static_member) | |
3345 | return false; | |
3346 | if (f1->static_member) | |
3347 | { | |
3348 | if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0) | |
3349 | return false; | |
3350 | } | |
3351 | else | |
3352 | { | |
3353 | if (f1->u.f.bitpos != f2->u.f.bitpos | |
3354 | || f1->u.f.bitsize != f2->u.f.bitsize) | |
3355 | return false; | |
3356 | } | |
3357 | /* We do the checks which require function calls last. We | |
3358 | don't require that the types of fields have the same | |
3359 | names, since that sometimes fails in the presence of | |
3360 | typedefs and we really don't care. */ | |
3361 | if (strcmp (f1->name, f2->name) != 0 | |
3362 | || ! debug_type_samep (info, | |
3363 | debug_get_real_type ((PTR) info, | |
3364 | f1->type), | |
3365 | debug_get_real_type ((PTR) info, | |
3366 | f2->type))) | |
3367 | return false; | |
3368 | } | |
3369 | if (*pf1 != NULL || *pf2 != NULL) | |
3370 | return false; | |
3371 | } | |
3372 | ||
3373 | if (c1->vptrbase != NULL) | |
3374 | { | |
3375 | if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase)) | |
3376 | return false; | |
3377 | } | |
3378 | ||
3379 | if (c1->baseclasses != NULL) | |
3380 | { | |
3381 | struct debug_baseclass **pb1, **pb2; | |
3382 | ||
3383 | for (pb1 = c1->baseclasses, pb2 = c2->baseclasses; | |
3384 | *pb1 != NULL && *pb2 != NULL; | |
3385 | ++pb1, ++pb2) | |
3386 | { | |
3387 | struct debug_baseclass *b1, *b2; | |
3388 | ||
3389 | b1 = *pb1; | |
3390 | b2 = *pb2; | |
3391 | if (b1->bitpos != b2->bitpos | |
3392 | || b1->virtual != b2->virtual | |
3393 | || b1->visibility != b2->visibility | |
3394 | || ! debug_type_samep (info, b1->type, b2->type)) | |
3395 | return false; | |
3396 | } | |
3397 | if (*pb1 != NULL || *pb2 != NULL) | |
3398 | return false; | |
3399 | } | |
3400 | ||
3401 | if (c1->methods != NULL) | |
3402 | { | |
3403 | struct debug_method **pm1, **pm2; | |
3404 | ||
3405 | for (pm1 = c1->methods, pm2 = c2->methods; | |
3406 | *pm1 != NULL && *pm2 != NULL; | |
3407 | ++pm1, ++pm2) | |
3408 | { | |
3409 | struct debug_method *m1, *m2; | |
3410 | ||
3411 | m1 = *pm1; | |
3412 | m2 = *pm2; | |
3413 | if (m1->name[0] != m2->name[0] | |
3414 | || strcmp (m1->name, m2->name) != 0 | |
3415 | || (m1->variants == NULL) != (m2->variants == NULL)) | |
3416 | return false; | |
3417 | if (m1->variants == NULL) | |
3418 | { | |
3419 | struct debug_method_variant **pv1, **pv2; | |
3420 | ||
3421 | for (pv1 = m1->variants, pv2 = m2->variants; | |
3422 | *pv1 != NULL && *pv2 != NULL; | |
3423 | ++pv1, ++pv2) | |
3424 | { | |
3425 | struct debug_method_variant *v1, *v2; | |
3426 | ||
3427 | v1 = *pv1; | |
3428 | v2 = *pv2; | |
3429 | if (v1->physname[0] != v2->physname[0] | |
3430 | || v1->visibility != v2->visibility | |
3431 | || v1->constp != v2->constp | |
3432 | || v1->volatilep != v2->volatilep | |
3433 | || v1->voffset != v2->voffset | |
3434 | || (v1->context == NULL) != (v2->context == NULL) | |
3435 | || strcmp (v1->physname, v2->physname) != 0 | |
3436 | || ! debug_type_samep (info, v1->type, v2->type)) | |
3437 | return false; | |
3438 | if (v1->context != NULL) | |
3439 | { | |
3440 | if (! debug_type_samep (info, v1->context, | |
3441 | v2->context)) | |
3442 | return false; | |
3443 | } | |
3444 | } | |
3445 | if (*pv1 != NULL || *pv2 != NULL) | |
3446 | return false; | |
3447 | } | |
3448 | } | |
3449 | if (*pm1 != NULL || *pm2 != NULL) | |
3450 | return false; | |
3451 | } | |
3452 | ||
3453 | return true; | |
e1c14599 | 3454 | } |