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