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