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