* debug.h (struct debug_write_fns): Add tag parameter to
[deliverable/binutils-gdb.git] / binutils / debug.c
1 /* debug.c -- Handle generic debugging information.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
4
5 This file is part of GNU Binutils.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22 /* This file implements a generic debugging format. We may eventually
23 have readers which convert different formats into this generic
24 format, and writers which write it out. The initial impetus for
25 this was writing a convertor from stabs to HP IEEE-695 debugging
26 format. */
27
28 #include <stdio.h>
29 #include <assert.h>
30
31 #include "bfd.h"
32 #include "bucomm.h"
33 #include "libiberty.h"
34 #include "debug.h"
35
36 /* Global information we keep for debugging. A pointer to this
37 structure is the debugging handle passed to all the routines. */
38
39 struct debug_handle
40 {
41 /* A linked list of compilation units. */
42 struct debug_unit *units;
43 /* The current compilation unit. */
44 struct debug_unit *current_unit;
45 /* The current source file. */
46 struct debug_file *current_file;
47 /* The current function. */
48 struct debug_function *current_function;
49 /* The current block. */
50 struct debug_block *current_block;
51 /* The current line number information for the current unit. */
52 struct debug_lineno *current_lineno;
53 /* Mark. This is used by debug_write. */
54 unsigned int mark;
55 /* Another mark used by debug_write. */
56 unsigned int class_mark;
57 };
58
59 /* Information we keep for a single compilation unit. */
60
61 struct debug_unit
62 {
63 /* The next compilation unit. */
64 struct debug_unit *next;
65 /* A list of files included in this compilation unit. The first
66 file is always the main one, and that is where the main file name
67 is stored. */
68 struct debug_file *files;
69 /* Line number information for this compilation unit. This is not
70 stored by function, because assembler code may have line number
71 information without function information. */
72 struct debug_lineno *linenos;
73 };
74
75 /* Information kept for a single source file. */
76
77 struct debug_file
78 {
79 /* The next source file in this compilation unit. */
80 struct debug_file *next;
81 /* The name of the source file. */
82 const char *filename;
83 /* Global functions, variables, types, etc. */
84 struct debug_namespace *globals;
85 };
86
87 /* A type. */
88
89 struct debug_type
90 {
91 /* Kind of type. */
92 enum debug_type_kind kind;
93 /* Size of type (0 if not known). */
94 unsigned int size;
95 /* Type which is a pointer to this type. */
96 debug_type pointer;
97 /* Tagged union with additional information about the type. */
98 union
99 {
100 /* DEBUG_KIND_INDIRECT. */
101 struct debug_indirect_type *kindirect;
102 /* DEBUG_KIND_INT. */
103 /* Whether the integer is unsigned. */
104 boolean kint;
105 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
106 DEBUG_KIND_UNION_CLASS. */
107 struct debug_class_type *kclass;
108 /* DEBUG_KIND_ENUM. */
109 struct debug_enum_type *kenum;
110 /* DEBUG_KIND_POINTER. */
111 struct debug_type *kpointer;
112 /* DEBUG_KIND_FUNCTION. */
113 struct debug_function_type *kfunction;
114 /* DEBUG_KIND_REFERENCE. */
115 struct debug_type *kreference;
116 /* DEBUG_KIND_RANGE. */
117 struct debug_range_type *krange;
118 /* DEBUG_KIND_ARRAY. */
119 struct debug_array_type *karray;
120 /* DEBUG_KIND_SET. */
121 struct debug_set_type *kset;
122 /* DEBUG_KIND_OFFSET. */
123 struct debug_offset_type *koffset;
124 /* DEBUG_KIND_METHOD. */
125 struct debug_method_type *kmethod;
126 /* DEBUG_KIND_CONST. */
127 struct debug_type *kconst;
128 /* DEBUG_KIND_VOLATILE. */
129 struct debug_type *kvolatile;
130 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
131 struct debug_named_type *knamed;
132 } u;
133 };
134
135 /* Information kept for an indirect type. */
136
137 struct debug_indirect_type
138 {
139 /* Slot where the final type will appear. */
140 debug_type *slot;
141 /* Tag. */
142 const char *tag;
143 };
144
145 /* Information kept for a struct, union, or class. */
146
147 struct debug_class_type
148 {
149 /* NULL terminated array of fields. */
150 debug_field *fields;
151 /* A mark field used to avoid recursively printing out structs. */
152 unsigned int mark;
153 /* The remaining fields are only used for DEBUG_KIND_CLASS and
154 DEBUG_KIND_UNION_CLASS. */
155 /* NULL terminated array of base classes. */
156 debug_baseclass *baseclasses;
157 /* NULL terminated array of methods. */
158 debug_method *methods;
159 /* The type of the class providing the virtual function table for
160 this class. This may point to the type itself. */
161 debug_type vptrbase;
162 };
163
164 /* Information kept for an enum. */
165
166 struct debug_enum_type
167 {
168 /* NULL terminated array of names. */
169 const char **names;
170 /* Array of corresponding values. */
171 bfd_signed_vma *values;
172 };
173
174 /* Information kept for a function. FIXME: We should be able to
175 record the parameter types. */
176
177 struct debug_function_type
178 {
179 /* Return type. */
180 debug_type return_type;
181 };
182
183 /* Information kept for a range. */
184
185 struct debug_range_type
186 {
187 /* Range base type. */
188 debug_type type;
189 /* Lower bound. */
190 bfd_signed_vma lower;
191 /* Upper bound. */
192 bfd_signed_vma upper;
193 };
194
195 /* Information kept for an array. */
196
197 struct debug_array_type
198 {
199 /* Element type. */
200 debug_type element_type;
201 /* Range type. */
202 debug_type range_type;
203 /* Lower bound. */
204 bfd_signed_vma lower;
205 /* Upper bound. */
206 bfd_signed_vma upper;
207 /* Whether this array is really a string. */
208 boolean stringp;
209 };
210
211 /* Information kept for a set. */
212
213 struct debug_set_type
214 {
215 /* Base type. */
216 debug_type type;
217 /* Whether this set is really a bitstring. */
218 boolean bitstringp;
219 };
220
221 /* Information kept for an offset type (a based pointer). */
222
223 struct debug_offset_type
224 {
225 /* The type the pointer is an offset from. */
226 debug_type base_type;
227 /* The type the pointer points to. */
228 debug_type target_type;
229 };
230
231 /* Information kept for a method type. */
232
233 struct debug_method_type
234 {
235 /* The return type. */
236 debug_type return_type;
237 /* The object type which this method is for. */
238 debug_type domain_type;
239 /* A NULL terminated array of argument types. */
240 debug_type *arg_types;
241 };
242
243 /* Information kept for a named type. */
244
245 struct debug_named_type
246 {
247 /* Name. */
248 struct debug_name *name;
249 /* Real type. */
250 debug_type type;
251 };
252
253 /* A field in a struct or union. */
254
255 struct debug_field
256 {
257 /* Name of the field. */
258 const char *name;
259 /* Type of the field. */
260 struct debug_type *type;
261 /* Visibility of the field. */
262 enum debug_visibility visibility;
263 /* Whether this is a static member. */
264 boolean static_member;
265 union
266 {
267 /* If static_member is false. */
268 struct
269 {
270 /* Bit position of the field in the struct. */
271 unsigned int bitpos;
272 /* Size of the field in bits. */
273 unsigned int bitsize;
274 } f;
275 /* If static_member is true. */
276 struct
277 {
278 const char *physname;
279 } s;
280 } u;
281 };
282
283 /* A base class for an object. */
284
285 struct debug_baseclass
286 {
287 /* Type of the base class. */
288 struct debug_type *type;
289 /* Bit position of the base class in the object. */
290 unsigned int bitpos;
291 /* Whether the base class is virtual. */
292 boolean virtual;
293 /* Visibility of the base class. */
294 enum debug_visibility visibility;
295 };
296
297 /* A method of an object. */
298
299 struct debug_method
300 {
301 /* The name of the method. */
302 const char *name;
303 /* A NULL terminated array of different types of variants. */
304 struct debug_method_variant **variants;
305 };
306
307 /* The variants of a method function of an object. These indicate
308 which method to run. */
309
310 struct debug_method_variant
311 {
312 /* The argument types of the function. */
313 const char *argtypes;
314 /* The type of the function. */
315 struct debug_type *type;
316 /* The visibility of the function. */
317 enum debug_visibility visibility;
318 /* Whether the function is const. */
319 boolean constp;
320 /* Whether the function is volatile. */
321 boolean volatilep;
322 /* The offset to the function in the virtual function table. */
323 bfd_vma voffset;
324 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
325 #define VOFFSET_STATIC_METHOD (1)
326 /* Context of a virtual method function. */
327 struct debug_type *context;
328 };
329
330 /* A variable. This is the information we keep for a variable object.
331 This has no name; a name is associated with a variable in a
332 debug_name structure. */
333
334 struct debug_variable
335 {
336 /* Kind of variable. */
337 enum debug_var_kind kind;
338 /* Type. */
339 debug_type type;
340 /* Value. The interpretation of the value depends upon kind. */
341 bfd_vma val;
342 };
343
344 /* A function. This has no name; a name is associated with a function
345 in a debug_name structure. */
346
347 struct debug_function
348 {
349 /* Return type. */
350 debug_type return_type;
351 /* Parameter information. */
352 struct debug_parameter *parameters;
353 /* Block information. The first structure on the list is the main
354 block of the function, and describes function local variables. */
355 struct debug_block *blocks;
356 };
357
358 /* A function parameter. */
359
360 struct debug_parameter
361 {
362 /* Next parameter. */
363 struct debug_parameter *next;
364 /* Name. */
365 const char *name;
366 /* Type. */
367 debug_type type;
368 /* Kind. */
369 enum debug_parm_kind kind;
370 /* Value (meaning depends upon kind). */
371 bfd_vma val;
372 };
373
374 /* A typed constant. */
375
376 struct debug_typed_constant
377 {
378 /* Type. */
379 debug_type type;
380 /* Value. FIXME: We may eventually need to support non-integral
381 values. */
382 bfd_vma val;
383 };
384
385 /* Information about a block within a function. */
386
387 struct debug_block
388 {
389 /* Next block with the same parent. */
390 struct debug_block *next;
391 /* Parent block. */
392 struct debug_block *parent;
393 /* List of child blocks. */
394 struct debug_block *children;
395 /* Start address of the block. */
396 bfd_vma start;
397 /* End address of the block. */
398 bfd_vma end;
399 /* Local variables. */
400 struct debug_namespace *locals;
401 };
402
403 /* Line number information we keep for a compilation unit. FIXME:
404 This structure is easy to create, but can be very space
405 inefficient. */
406
407 struct debug_lineno
408 {
409 /* More line number information for this block. */
410 struct debug_lineno *next;
411 /* Source file. */
412 struct debug_file *file;
413 /* Line numbers, terminated by a -1 or the end of the array. */
414 #define DEBUG_LINENO_COUNT 10
415 unsigned long linenos[DEBUG_LINENO_COUNT];
416 /* Addresses for the line numbers. */
417 bfd_vma addrs[DEBUG_LINENO_COUNT];
418 };
419
420 /* A namespace. This is a mapping from names to objects. FIXME: This
421 should be implemented as a hash table. */
422
423 struct debug_namespace
424 {
425 /* List of items in this namespace. */
426 struct debug_name *list;
427 /* Pointer to where the next item in this namespace should go. */
428 struct debug_name **tail;
429 };
430
431 /* Kinds of objects that appear in a namespace. */
432
433 enum debug_object_kind
434 {
435 /* A type. */
436 DEBUG_OBJECT_TYPE,
437 /* A tagged type (really a different sort of namespace). */
438 DEBUG_OBJECT_TAG,
439 /* A variable. */
440 DEBUG_OBJECT_VARIABLE,
441 /* A function. */
442 DEBUG_OBJECT_FUNCTION,
443 /* An integer constant. */
444 DEBUG_OBJECT_INT_CONSTANT,
445 /* A floating point constant. */
446 DEBUG_OBJECT_FLOAT_CONSTANT,
447 /* A typed constant. */
448 DEBUG_OBJECT_TYPED_CONSTANT
449 };
450
451 /* Linkage of an object that appears in a namespace. */
452
453 enum debug_object_linkage
454 {
455 /* Local variable. */
456 DEBUG_LINKAGE_AUTOMATIC,
457 /* Static--either file static or function static, depending upon the
458 namespace is. */
459 DEBUG_LINKAGE_STATIC,
460 /* Global. */
461 DEBUG_LINKAGE_GLOBAL,
462 /* No linkage. */
463 DEBUG_LINKAGE_NONE
464 };
465
466 /* A name in a namespace. */
467
468 struct debug_name
469 {
470 /* Next name in this namespace. */
471 struct debug_name *next;
472 /* Name. */
473 const char *name;
474 /* Mark. This is used by debug_write. */
475 unsigned int mark;
476 /* Kind of object. */
477 enum debug_object_kind kind;
478 /* Linkage of object. */
479 enum debug_object_linkage linkage;
480 /* Tagged union with additional information about the object. */
481 union
482 {
483 /* DEBUG_OBJECT_TYPE. */
484 struct debug_type *type;
485 /* DEBUG_OBJECT_TAG. */
486 struct debug_type *tag;
487 /* DEBUG_OBJECT_VARIABLE. */
488 struct debug_variable *variable;
489 /* DEBUG_OBJECT_FUNCTION. */
490 struct debug_function *function;
491 /* DEBUG_OBJECT_INT_CONSTANT. */
492 bfd_vma int_constant;
493 /* DEBUG_OBJECT_FLOAT_CONSTANT. */
494 double float_constant;
495 /* DEBUG_OBJECT_TYPED_CONSTANT. */
496 struct debug_typed_constant *typed_constant;
497 } u;
498 };
499
500 static void debug_error PARAMS ((const char *));
501 static struct debug_name *debug_add_to_namespace
502 PARAMS ((struct debug_handle *, struct debug_namespace **, const char *,
503 enum debug_object_kind, enum debug_object_linkage));
504 static struct debug_name *debug_add_to_current_namespace
505 PARAMS ((struct debug_handle *, const char *, enum debug_object_kind,
506 enum debug_object_linkage));
507 static struct debug_type *debug_make_type
508 PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int));
509 static boolean debug_write_name
510 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
511 struct debug_name *));
512 static boolean debug_write_type
513 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
514 struct debug_type *, struct debug_name *));
515 static boolean debug_write_class_type
516 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
517 struct debug_type *, const char *));
518 static boolean debug_write_function
519 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
520 const char *, enum debug_object_linkage, struct debug_function *));
521 static boolean debug_write_block
522 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
523 struct debug_block *));
524 \f
525 /* Issue an error message. */
526
527 static void
528 debug_error (message)
529 const char *message;
530 {
531 fprintf (stderr, "%s\n", message);
532 }
533
534 /* Add an object to a namespace. */
535
536 static struct debug_name *
537 debug_add_to_namespace (info, nsp, name, kind, linkage)
538 struct debug_handle *info;
539 struct debug_namespace **nsp;
540 const char *name;
541 enum debug_object_kind kind;
542 enum debug_object_linkage linkage;
543 {
544 struct debug_name *n;
545 struct debug_namespace *ns;
546
547 n = (struct debug_name *) xmalloc (sizeof *n);
548 memset (n, 0, sizeof *n);
549
550 n->name = name;
551 n->kind = kind;
552 n->linkage = linkage;
553
554 ns = *nsp;
555 if (ns == NULL)
556 {
557 ns = (struct debug_namespace *) xmalloc (sizeof *ns);
558 memset (ns, 0, sizeof *ns);
559
560 ns->tail = &ns->list;
561
562 *nsp = ns;
563 }
564
565 *ns->tail = n;
566 ns->tail = &n->next;
567
568 return n;
569 }
570
571 /* Add an object to the current namespace. */
572
573 static struct debug_name *
574 debug_add_to_current_namespace (info, name, kind, linkage)
575 struct debug_handle *info;
576 const char *name;
577 enum debug_object_kind kind;
578 enum debug_object_linkage linkage;
579 {
580 struct debug_namespace **nsp;
581
582 if (info->current_unit == NULL
583 || info->current_file == NULL)
584 {
585 debug_error ("debug_add_to_current_namespace: no current file");
586 return NULL;
587 }
588
589 if (info->current_block != NULL)
590 nsp = &info->current_block->locals;
591 else
592 nsp = &info->current_file->globals;
593
594 return debug_add_to_namespace (info, nsp, name, kind, linkage);
595 }
596 \f
597 /* Return a handle for debugging information. */
598
599 PTR
600 debug_init ()
601 {
602 struct debug_handle *ret;
603
604 ret = (struct debug_handle *) xmalloc (sizeof *ret);
605 memset (ret, 0, sizeof *ret);
606 return (PTR) ret;
607 }
608
609 /* Set the source filename. This implicitly starts a new compilation
610 unit. */
611
612 boolean
613 debug_set_filename (handle, name)
614 PTR handle;
615 const char *name;
616 {
617 struct debug_handle *info = (struct debug_handle *) handle;
618 struct debug_file *nfile;
619 struct debug_unit *nunit;
620
621 if (name == NULL)
622 name = "";
623
624 nfile = (struct debug_file *) xmalloc (sizeof *nfile);
625 memset (nfile, 0, sizeof *nfile);
626
627 nfile->filename = name;
628
629 nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
630 memset (nunit, 0, sizeof *nunit);
631
632 nunit->files = nfile;
633 info->current_file = nfile;
634
635 if (info->current_unit != NULL)
636 info->current_unit->next = nunit;
637 else
638 {
639 assert (info->units == NULL);
640 info->units = nunit;
641 }
642
643 info->current_unit = nunit;
644
645 info->current_function = NULL;
646 info->current_block = NULL;
647 info->current_lineno = NULL;
648
649 return true;
650 }
651
652 /* Append a string to the source filename. */
653
654 boolean
655 debug_append_filename (handle, string)
656 PTR handle;
657 const char *string;
658 {
659 struct debug_handle *info = (struct debug_handle *) handle;
660 char *n;
661
662 if (string == NULL)
663 string = "";
664
665 if (info->current_unit == NULL)
666 {
667 debug_error ("debug_append_filename: no current file");
668 return false;
669 }
670
671 n = (char *) xmalloc (strlen (info->current_unit->files->filename)
672 + strlen (string)
673 + 1);
674 sprintf (n, "%s%s", info->current_unit->files->filename, string);
675 info->current_unit->files->filename = n;
676
677 return true;
678 }
679
680 /* Change source files to the given file name. This is used for
681 include files in a single compilation unit. */
682
683 boolean
684 debug_start_source (handle, name)
685 PTR handle;
686 const char *name;
687 {
688 struct debug_handle *info = (struct debug_handle *) handle;
689 struct debug_file *f, **pf;
690
691 if (name == NULL)
692 name = "";
693
694 if (info->current_unit == NULL)
695 {
696 debug_error ("debug_start_source: no debug_set_filename call");
697 return false;
698 }
699
700 for (f = info->current_unit->files; f != NULL; f = f->next)
701 {
702 if (f->filename[0] == name[0]
703 && f->filename[1] == name[1]
704 && strcmp (f->filename, name) == 0)
705 {
706 info->current_file = f;
707 return true;
708 }
709 }
710
711 f = (struct debug_file *) xmalloc (sizeof *f);
712 memset (f, 0, sizeof *f);
713
714 f->filename = name;
715
716 for (pf = &info->current_file->next;
717 *pf != NULL;
718 pf = &(*pf)->next)
719 ;
720 *pf = f;
721
722 info->current_file = f;
723
724 return true;
725 }
726
727 /* Record a function definition. This implicitly starts a function
728 block. The debug_type argument is the type of the return value.
729 The boolean indicates whether the function is globally visible.
730 The bfd_vma is the address of the start of the function. Currently
731 the parameter types are specified by calls to
732 debug_record_parameter. FIXME: There is no way to specify nested
733 functions. FIXME: I don't think there is any way to record where a
734 function ends. */
735
736 boolean
737 debug_record_function (handle, name, return_type, global, addr)
738 PTR handle;
739 const char *name;
740 debug_type return_type;
741 boolean global;
742 bfd_vma addr;
743 {
744 struct debug_handle *info = (struct debug_handle *) handle;
745 struct debug_function *f;
746 struct debug_block *b;
747 struct debug_name *n;
748
749 if (name == NULL)
750 name = "";
751 if (return_type == NULL)
752 return false;
753
754 if (info->current_unit == NULL)
755 {
756 debug_error ("debug_record_function: no debug_set_filename call");
757 return false;
758 }
759
760 f = (struct debug_function *) xmalloc (sizeof *f);
761 memset (f, 0, sizeof *f);
762
763 f->return_type = return_type;
764
765 b = (struct debug_block *) xmalloc (sizeof *b);
766 memset (b, 0, sizeof *b);
767
768 b->start = addr;
769 b->end = (bfd_vma) -1;
770
771 f->blocks = b;
772
773 info->current_function = f;
774 info->current_block = b;
775
776 /* FIXME: If we could handle nested functions, this would be the
777 place: we would want to use a different namespace. */
778 n = debug_add_to_namespace (info,
779 &info->current_file->globals,
780 name,
781 DEBUG_OBJECT_FUNCTION,
782 (global
783 ? DEBUG_LINKAGE_GLOBAL
784 : DEBUG_LINKAGE_STATIC));
785 if (n == NULL)
786 return false;
787
788 n->u.function = f;
789
790 return true;
791 }
792
793 /* Record a parameter for the current function. */
794
795 boolean
796 debug_record_parameter (handle, name, type, kind, val)
797 PTR handle;
798 const char *name;
799 debug_type type;
800 enum debug_parm_kind kind;
801 bfd_vma val;
802 {
803 struct debug_handle *info = (struct debug_handle *) handle;
804 struct debug_parameter *p, **pp;
805
806 if (name == NULL || type == NULL)
807 return false;
808
809 if (info->current_unit == NULL
810 || info->current_function == NULL)
811 {
812 debug_error ("debug_record_parameter: no current function");
813 return false;
814 }
815
816 p = (struct debug_parameter *) xmalloc (sizeof *p);
817 memset (p, 0, sizeof *p);
818
819 p->name = name;
820 p->type = type;
821 p->kind = kind;
822 p->val = val;
823
824 for (pp = &info->current_function->parameters;
825 *pp != NULL;
826 pp = &(*pp)->next)
827 ;
828 *pp = p;
829
830 return true;
831 }
832
833 /* End a function. FIXME: This should handle function nesting. */
834
835 boolean
836 debug_end_function (handle, addr)
837 PTR handle;
838 bfd_vma addr;
839 {
840 struct debug_handle *info = (struct debug_handle *) handle;
841
842 if (info->current_unit == NULL
843 || info->current_block == NULL
844 || info->current_function == NULL)
845 {
846 debug_error ("debug_end_function: no current function");
847 return false;
848 }
849
850 if (info->current_block->parent != NULL)
851 {
852 debug_error ("debug_end_function: some blocks were not closed");
853 return false;
854 }
855
856 info->current_block->end = addr;
857
858 info->current_function = NULL;
859 info->current_block = NULL;
860
861 return true;
862 }
863
864 /* Start a block in a function. All local information will be
865 recorded in this block, until the matching call to debug_end_block.
866 debug_start_block and debug_end_block may be nested. The bfd_vma
867 argument is the address at which this block starts. */
868
869 boolean
870 debug_start_block (handle, addr)
871 PTR handle;
872 bfd_vma addr;
873 {
874 struct debug_handle *info = (struct debug_handle *) handle;
875 struct debug_block *b, **pb;
876
877 /* We must always have a current block: debug_record_function sets
878 one up. */
879 if (info->current_unit == NULL
880 || info->current_block == NULL)
881 {
882 debug_error ("debug_start_block: no current block");
883 return false;
884 }
885
886 b = (struct debug_block *) xmalloc (sizeof *b);
887 memset (b, 0, sizeof *b);
888
889 b->parent = info->current_block;
890 b->start = addr;
891 b->end = (bfd_vma) -1;
892
893 /* This new block is a child of the current block. */
894 for (pb = &info->current_block->children;
895 *pb != NULL;
896 pb = &(*pb)->next)
897 ;
898 *pb = b;
899
900 info->current_block = b;
901
902 return true;
903 }
904
905 /* Finish a block in a function. This matches the call to
906 debug_start_block. The argument is the address at which this block
907 ends. */
908
909 boolean
910 debug_end_block (handle, addr)
911 PTR handle;
912 bfd_vma addr;
913 {
914 struct debug_handle *info = (struct debug_handle *) handle;
915 struct debug_block *parent;
916
917 if (info->current_unit == NULL
918 || info->current_block == NULL)
919 {
920 debug_error ("debug_end_block: no current block");
921 return false;
922 }
923
924 parent = info->current_block->parent;
925 if (parent == NULL)
926 {
927 debug_error ("debug_end_block: attempt to close top level block");
928 return false;
929 }
930
931 info->current_block->end = addr;
932
933 info->current_block = parent;
934
935 return true;
936 }
937
938 /* Associate a line number in the current source file and function
939 with a given address. */
940
941 boolean
942 debug_record_line (handle, lineno, addr)
943 PTR handle;
944 unsigned long lineno;
945 bfd_vma addr;
946 {
947 struct debug_handle *info = (struct debug_handle *) handle;
948 struct debug_lineno *l;
949 unsigned int i;
950
951 if (info->current_unit == NULL)
952 {
953 debug_error ("debug_record_line: no current unit");
954 return false;
955 }
956
957 l = info->current_lineno;
958 if (l != NULL && l->file == info->current_file)
959 {
960 for (i = 0; i < DEBUG_LINENO_COUNT; i++)
961 {
962 if (l->linenos[i] == (unsigned long) -1)
963 {
964 l->linenos[i] = lineno;
965 l->addrs[i] = addr;
966 return true;
967 }
968 }
969 }
970
971 /* If we get here, then either 1) there is no current_lineno
972 structure, which means this is the first line number in this
973 compilation unit, 2) the current_lineno structure is for a
974 different file, or 3) the current_lineno structure is full.
975 Regardless, we want to allocate a new debug_lineno structure, put
976 it in the right place, and make it the new current_lineno
977 structure. */
978
979 l = (struct debug_lineno *) xmalloc (sizeof *l);
980 memset (l, 0, sizeof *l);
981
982 l->file = info->current_file;
983 l->linenos[0] = lineno;
984 l->addrs[0] = addr;
985 for (i = 1; i < DEBUG_LINENO_COUNT; i++)
986 l->linenos[i] = (unsigned long) -1;
987
988 if (info->current_lineno != NULL)
989 info->current_lineno->next = l;
990 else
991 info->current_unit->linenos = l;
992
993 info->current_lineno = l;
994
995 return true;
996 }
997
998 /* Start a named common block. This is a block of variables that may
999 move in memory. */
1000
1001 boolean
1002 debug_start_common_block (handle, name)
1003 PTR handle;
1004 const char *name;
1005 {
1006 /* FIXME */
1007 debug_error ("debug_start_common_block: not implemented");
1008 return false;
1009 }
1010
1011 /* End a named common block. */
1012
1013 boolean
1014 debug_end_common_block (handle, name)
1015 PTR handle;
1016 const char *name;
1017 {
1018 /* FIXME */
1019 debug_error ("debug_end_common_block: not implemented");
1020 return false;
1021 }
1022
1023 /* Record a named integer constant. */
1024
1025 boolean
1026 debug_record_int_const (handle, name, val)
1027 PTR handle;
1028 const char *name;
1029 bfd_vma val;
1030 {
1031 struct debug_handle *info = (struct debug_handle *) handle;
1032 struct debug_name *n;
1033
1034 if (name == NULL)
1035 return false;
1036
1037 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
1038 DEBUG_LINKAGE_NONE);
1039 if (n == NULL)
1040 return false;
1041
1042 n->u.int_constant = val;
1043
1044 return true;
1045 }
1046
1047 /* Record a named floating point constant. */
1048
1049 boolean
1050 debug_record_float_const (handle, name, val)
1051 PTR handle;
1052 const char *name;
1053 double val;
1054 {
1055 struct debug_handle *info = (struct debug_handle *) handle;
1056 struct debug_name *n;
1057
1058 if (name == NULL)
1059 return false;
1060
1061 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
1062 DEBUG_LINKAGE_NONE);
1063 if (n == NULL)
1064 return false;
1065
1066 n->u.float_constant = val;
1067
1068 return true;
1069 }
1070
1071 /* Record a typed constant with an integral value. */
1072
1073 boolean
1074 debug_record_typed_const (handle, name, type, val)
1075 PTR handle;
1076 const char *name;
1077 debug_type type;
1078 bfd_vma val;
1079 {
1080 struct debug_handle *info = (struct debug_handle *) handle;
1081 struct debug_name *n;
1082 struct debug_typed_constant *tc;
1083
1084 if (name == NULL || type == NULL)
1085 return false;
1086
1087 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
1088 DEBUG_LINKAGE_NONE);
1089 if (n == NULL)
1090 return false;
1091
1092 tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
1093 memset (tc, 0, sizeof *tc);
1094
1095 tc->type = type;
1096 tc->val = val;
1097
1098 n->u.typed_constant = tc;
1099
1100 return true;
1101 }
1102
1103 /* Record a label. */
1104
1105 boolean
1106 debug_record_label (handle, name, type, addr)
1107 PTR handle;
1108 const char *name;
1109 debug_type type;
1110 bfd_vma addr;
1111 {
1112 /* FIXME. */
1113 debug_error ("debug_record_label not implemented");
1114 return false;
1115 }
1116
1117 /* Record a variable. */
1118
1119 boolean
1120 debug_record_variable (handle, name, type, kind, val)
1121 PTR handle;
1122 const char *name;
1123 debug_type type;
1124 enum debug_var_kind kind;
1125 bfd_vma val;
1126 {
1127 struct debug_handle *info = (struct debug_handle *) handle;
1128 struct debug_namespace **nsp;
1129 enum debug_object_linkage linkage;
1130 struct debug_name *n;
1131 struct debug_variable *v;
1132
1133 if (name == NULL || type == NULL)
1134 return false;
1135
1136 if (info->current_unit == NULL
1137 || info->current_file == NULL)
1138 {
1139 debug_error ("debug_record_variable: no current file");
1140 return false;
1141 }
1142
1143 if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
1144 {
1145 nsp = &info->current_file->globals;
1146 if (kind == DEBUG_GLOBAL)
1147 linkage = DEBUG_LINKAGE_GLOBAL;
1148 else
1149 linkage = DEBUG_LINKAGE_STATIC;
1150 }
1151 else
1152 {
1153 if (info->current_block == NULL)
1154 {
1155 debug_error ("debug_record_variable: no current block");
1156 return false;
1157 }
1158 nsp = &info->current_block->locals;
1159 linkage = DEBUG_LINKAGE_AUTOMATIC;
1160 }
1161
1162 n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
1163 if (n == NULL)
1164 return false;
1165
1166 v = (struct debug_variable *) xmalloc (sizeof *v);
1167 memset (v, 0, sizeof *v);
1168
1169 v->kind = kind;
1170 v->type = type;
1171 v->val = val;
1172
1173 n->u.variable = v;
1174
1175 return true;
1176 }
1177
1178 /* Make a type with a given kind and size. */
1179
1180 /*ARGSUSED*/
1181 static struct debug_type *
1182 debug_make_type (info, kind, size)
1183 struct debug_handle *info;
1184 enum debug_type_kind kind;
1185 unsigned int size;
1186 {
1187 struct debug_type *t;
1188
1189 t = (struct debug_type *) xmalloc (sizeof *t);
1190 memset (t, 0, sizeof *t);
1191
1192 t->kind = kind;
1193 t->size = size;
1194
1195 return t;
1196 }
1197
1198 /* Make an indirect type which may be used as a placeholder for a type
1199 which is referenced before it is defined. */
1200
1201 debug_type
1202 debug_make_indirect_type (handle, slot, tag)
1203 PTR handle;
1204 debug_type *slot;
1205 const char *tag;
1206 {
1207 struct debug_handle *info = (struct debug_handle *) handle;
1208 struct debug_type *t;
1209 struct debug_indirect_type *i;
1210
1211 t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
1212 if (t == NULL)
1213 return DEBUG_TYPE_NULL;
1214
1215 i = (struct debug_indirect_type *) xmalloc (sizeof *i);
1216 memset (i, 0, sizeof *i);
1217
1218 i->slot = slot;
1219 i->tag = tag;
1220
1221 t->u.kindirect = i;
1222
1223 return t;
1224 }
1225
1226 /* Make a void type. There is only one of these. */
1227
1228 debug_type
1229 debug_make_void_type (handle)
1230 PTR handle;
1231 {
1232 struct debug_handle *info = (struct debug_handle *) handle;
1233
1234 return debug_make_type (info, DEBUG_KIND_VOID, 0);
1235 }
1236
1237 /* Make an integer type of a given size. The boolean argument is true
1238 if the integer is unsigned. */
1239
1240 debug_type
1241 debug_make_int_type (handle, size, unsignedp)
1242 PTR handle;
1243 unsigned int size;
1244 boolean unsignedp;
1245 {
1246 struct debug_handle *info = (struct debug_handle *) handle;
1247 struct debug_type *t;
1248
1249 t = debug_make_type (info, DEBUG_KIND_INT, size);
1250 if (t == NULL)
1251 return DEBUG_TYPE_NULL;
1252
1253 t->u.kint = unsignedp;
1254
1255 return t;
1256 }
1257
1258 /* Make a floating point type of a given size. FIXME: On some
1259 platforms, like an Alpha, you probably need to be able to specify
1260 the format. */
1261
1262 debug_type
1263 debug_make_float_type (handle, size)
1264 PTR handle;
1265 unsigned int size;
1266 {
1267 struct debug_handle *info = (struct debug_handle *) handle;
1268
1269 return debug_make_type (info, DEBUG_KIND_FLOAT, size);
1270 }
1271
1272 /* Make a boolean type of a given size. */
1273
1274 debug_type
1275 debug_make_bool_type (handle, size)
1276 PTR handle;
1277 unsigned int size;
1278 {
1279 struct debug_handle *info = (struct debug_handle *) handle;
1280
1281 return debug_make_type (info, DEBUG_KIND_BOOL, size);
1282 }
1283
1284 /* Make a complex type of a given size. */
1285
1286 debug_type
1287 debug_make_complex_type (handle, size)
1288 PTR handle;
1289 unsigned int size;
1290 {
1291 struct debug_handle *info = (struct debug_handle *) handle;
1292
1293 return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
1294 }
1295
1296 /* Make a structure type. The second argument is true for a struct,
1297 false for a union. The third argument is the size of the struct.
1298 The fourth argument is a NULL terminated array of fields. */
1299
1300 debug_type
1301 debug_make_struct_type (handle, structp, size, fields)
1302 PTR handle;
1303 boolean structp;
1304 bfd_vma size;
1305 debug_field *fields;
1306 {
1307 struct debug_handle *info = (struct debug_handle *) handle;
1308 struct debug_type *t;
1309 struct debug_class_type *c;
1310
1311 t = debug_make_type (info,
1312 structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
1313 size);
1314 if (t == NULL)
1315 return DEBUG_TYPE_NULL;
1316
1317 c = (struct debug_class_type *) xmalloc (sizeof *c);
1318 memset (c, 0, sizeof *c);
1319
1320 c->fields = fields;
1321
1322 t->u.kclass = c;
1323
1324 return t;
1325 }
1326
1327 /* Make an object type. The first three arguments after the handle
1328 are the same as for debug_make_struct_type. The next arguments are
1329 a NULL terminated array of base classes, a NULL terminated array of
1330 methods, the type of the object holding the virtual function table
1331 if it is not this object, and a boolean which is true if this
1332 object has its own virtual function table. */
1333
1334 debug_type
1335 debug_make_object_type (handle, structp, size, fields, baseclasses,
1336 methods, vptrbase, ownvptr)
1337 PTR handle;
1338 boolean structp;
1339 bfd_vma size;
1340 debug_field *fields;
1341 debug_baseclass *baseclasses;
1342 debug_method *methods;
1343 debug_type vptrbase;
1344 boolean ownvptr;
1345 {
1346 struct debug_handle *info = (struct debug_handle *) handle;
1347 struct debug_type *t;
1348 struct debug_class_type *c;
1349
1350 t = debug_make_type (info,
1351 structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
1352 size);
1353 if (t == NULL)
1354 return DEBUG_TYPE_NULL;
1355
1356 c = (struct debug_class_type *) xmalloc (sizeof *c);
1357 memset (c, 0, sizeof *c);
1358
1359 c->fields = fields;
1360 c->baseclasses = baseclasses;
1361 c->methods = methods;
1362 if (ownvptr)
1363 c->vptrbase = t;
1364 else
1365 c->vptrbase = vptrbase;
1366
1367 t->u.kclass = c;
1368
1369 return t;
1370 }
1371
1372 /* Make an enumeration type. The arguments are a null terminated
1373 array of strings, and an array of corresponding values. */
1374
1375 debug_type
1376 debug_make_enum_type (handle, names, values)
1377 PTR handle;
1378 const char **names;
1379 bfd_signed_vma *values;
1380 {
1381 struct debug_handle *info = (struct debug_handle *) handle;
1382 struct debug_type *t;
1383 struct debug_enum_type *e;
1384
1385 t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
1386 if (t == NULL)
1387 return DEBUG_TYPE_NULL;
1388
1389 e = (struct debug_enum_type *) xmalloc (sizeof *e);
1390 memset (e, 0, sizeof *e);
1391
1392 e->names = names;
1393 e->values = values;
1394
1395 t->u.kenum = e;
1396
1397 return t;
1398 }
1399
1400 /* Make a pointer to a given type. */
1401
1402 debug_type
1403 debug_make_pointer_type (handle, type)
1404 PTR handle;
1405 debug_type type;
1406 {
1407 struct debug_handle *info = (struct debug_handle *) handle;
1408 struct debug_type *t;
1409
1410 if (type == NULL)
1411 return DEBUG_TYPE_NULL;
1412
1413 if (type->pointer != DEBUG_TYPE_NULL)
1414 return type->pointer;
1415
1416 t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
1417 if (t == NULL)
1418 return DEBUG_TYPE_NULL;
1419
1420 t->u.kpointer = type;
1421
1422 type->pointer = t;
1423
1424 return t;
1425 }
1426
1427 /* Make a function returning a given type. FIXME: We should be able
1428 to record the parameter types. */
1429
1430 debug_type
1431 debug_make_function_type (handle, type)
1432 PTR handle;
1433 debug_type type;
1434 {
1435 struct debug_handle *info = (struct debug_handle *) handle;
1436 struct debug_type *t;
1437 struct debug_function_type *f;
1438
1439 if (type == NULL)
1440 return DEBUG_TYPE_NULL;
1441
1442 t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
1443 if (t == NULL)
1444 return DEBUG_TYPE_NULL;
1445
1446 f = (struct debug_function_type *) xmalloc (sizeof *f);
1447 memset (f, 0, sizeof *f);
1448
1449 f->return_type = type;
1450
1451 t->u.kfunction = f;
1452
1453 return t;
1454 }
1455
1456 /* Make a reference to a given type. */
1457
1458 debug_type
1459 debug_make_reference_type (handle, type)
1460 PTR handle;
1461 debug_type type;
1462 {
1463 struct debug_handle *info = (struct debug_handle *) handle;
1464 struct debug_type *t;
1465
1466 if (type == NULL)
1467 return DEBUG_TYPE_NULL;
1468
1469 t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
1470 if (t == NULL)
1471 return DEBUG_TYPE_NULL;
1472
1473 t->u.kreference = type;
1474
1475 return t;
1476 }
1477
1478 /* Make a range of a given type from a lower to an upper bound. */
1479
1480 debug_type
1481 debug_make_range_type (handle, type, lower, upper)
1482 PTR handle;
1483 debug_type type;
1484 bfd_signed_vma lower;
1485 bfd_signed_vma upper;
1486 {
1487 struct debug_handle *info = (struct debug_handle *) handle;
1488 struct debug_type *t;
1489 struct debug_range_type *r;
1490
1491 if (type == NULL)
1492 return DEBUG_TYPE_NULL;
1493
1494 t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
1495 if (t == NULL)
1496 return DEBUG_TYPE_NULL;
1497
1498 r = (struct debug_range_type *) xmalloc (sizeof *r);
1499 memset (r, 0, sizeof *r);
1500
1501 r->type = type;
1502 r->lower = lower;
1503 r->upper = upper;
1504
1505 t->u.krange = r;
1506
1507 return t;
1508 }
1509
1510 /* Make an array type. The second argument is the type of an element
1511 of the array. The third argument is the type of a range of the
1512 array. The fourth and fifth argument are the lower and upper
1513 bounds, respectively. The sixth argument is true if this array is
1514 actually a string, as in C. */
1515
1516 debug_type
1517 debug_make_array_type (handle, element_type, range_type, lower, upper,
1518 stringp)
1519 PTR handle;
1520 debug_type element_type;
1521 debug_type range_type;
1522 bfd_signed_vma lower;
1523 bfd_signed_vma upper;
1524 boolean stringp;
1525 {
1526 struct debug_handle *info = (struct debug_handle *) handle;
1527 struct debug_type *t;
1528 struct debug_array_type *a;
1529
1530 if (element_type == NULL || range_type == NULL)
1531 return DEBUG_TYPE_NULL;
1532
1533 t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
1534 if (t == NULL)
1535 return DEBUG_TYPE_NULL;
1536
1537 a = (struct debug_array_type *) xmalloc (sizeof *a);
1538 memset (a, 0, sizeof *a);
1539
1540 a->element_type = element_type;
1541 a->range_type = range_type;
1542 a->lower = lower;
1543 a->upper = upper;
1544 a->stringp = stringp;
1545
1546 t->u.karray = a;
1547
1548 return t;
1549 }
1550
1551 /* Make a set of a given type. For example, a Pascal set type. The
1552 boolean argument is true if this set is actually a bitstring, as in
1553 CHILL. */
1554
1555 debug_type
1556 debug_make_set_type (handle, type, bitstringp)
1557 PTR handle;
1558 debug_type type;
1559 boolean bitstringp;
1560 {
1561 struct debug_handle *info = (struct debug_handle *) handle;
1562 struct debug_type *t;
1563 struct debug_set_type *s;
1564
1565 if (type == NULL)
1566 return DEBUG_TYPE_NULL;
1567
1568 t = debug_make_type (info, DEBUG_KIND_SET, 0);
1569 if (t == NULL)
1570 return DEBUG_TYPE_NULL;
1571
1572 s = (struct debug_set_type *) xmalloc (sizeof *s);
1573 memset (s, 0, sizeof *s);
1574
1575 s->type = type;
1576 s->bitstringp = bitstringp;
1577
1578 t->u.kset = s;
1579
1580 return t;
1581 }
1582
1583 /* Make a type for a pointer which is relative to an object. The
1584 second argument is the type of the object to which the pointer is
1585 relative. The third argument is the type that the pointer points
1586 to. */
1587
1588 debug_type
1589 debug_make_offset_type (handle, base_type, target_type)
1590 PTR handle;
1591 debug_type base_type;
1592 debug_type target_type;
1593 {
1594 struct debug_handle *info = (struct debug_handle *) handle;
1595 struct debug_type *t;
1596 struct debug_offset_type *o;
1597
1598 if (base_type == NULL || target_type == NULL)
1599 return DEBUG_TYPE_NULL;
1600
1601 t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
1602 if (t == NULL)
1603 return DEBUG_TYPE_NULL;
1604
1605 o = (struct debug_offset_type *) xmalloc (sizeof *o);
1606 memset (o, 0, sizeof *o);
1607
1608 o->base_type = base_type;
1609 o->target_type = target_type;
1610
1611 t->u.koffset = o;
1612
1613 return t;
1614 }
1615
1616 /* Make a type for a method function. The second argument is the
1617 return type, the third argument is the domain, and the fourth
1618 argument is a NULL terminated array of argument types. */
1619
1620 debug_type
1621 debug_make_method_type (handle, return_type, domain_type, arg_types)
1622 PTR handle;
1623 debug_type return_type;
1624 debug_type domain_type;
1625 debug_type *arg_types;
1626 {
1627 struct debug_handle *info = (struct debug_handle *) handle;
1628 struct debug_type *t;
1629 struct debug_method_type *m;
1630
1631 if (return_type == NULL)
1632 return DEBUG_TYPE_NULL;
1633
1634 t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
1635 if (t == NULL)
1636 return DEBUG_TYPE_NULL;
1637
1638 m = (struct debug_method_type *) xmalloc (sizeof *m);
1639 memset (m, 0, sizeof *m);
1640
1641 m->return_type = return_type;
1642 m->domain_type = domain_type;
1643 m->arg_types = arg_types;
1644
1645 t->u.kmethod = m;
1646
1647 return t;
1648 }
1649
1650 /* Make a const qualified version of a given type. */
1651
1652 debug_type
1653 debug_make_const_type (handle, type)
1654 PTR handle;
1655 debug_type type;
1656 {
1657 struct debug_handle *info = (struct debug_handle *) handle;
1658 struct debug_type *t;
1659
1660 if (type == NULL)
1661 return DEBUG_TYPE_NULL;
1662
1663 t = debug_make_type (info, DEBUG_KIND_CONST, 0);
1664 if (t == NULL)
1665 return DEBUG_TYPE_NULL;
1666
1667 t->u.kconst = type;
1668
1669 return t;
1670 }
1671
1672 /* Make a volatile qualified version of a given type. */
1673
1674 debug_type
1675 debug_make_volatile_type (handle, type)
1676 PTR handle;
1677 debug_type type;
1678 {
1679 struct debug_handle *info = (struct debug_handle *) handle;
1680 struct debug_type *t;
1681
1682 if (type == NULL)
1683 return DEBUG_TYPE_NULL;
1684
1685 t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
1686 if (t == NULL)
1687 return DEBUG_TYPE_NULL;
1688
1689 t->u.kvolatile = type;
1690
1691 return t;
1692 }
1693
1694 /* Make an undefined tagged type. For example, a struct which has
1695 been mentioned, but not defined. */
1696
1697 debug_type
1698 debug_make_undefined_tagged_type (handle, name, kind)
1699 PTR handle;
1700 const char *name;
1701 enum debug_type_kind kind;
1702 {
1703 struct debug_handle *info = (struct debug_handle *) handle;
1704 struct debug_type *t;
1705
1706 if (name == NULL)
1707 return DEBUG_TYPE_NULL;
1708
1709 t = debug_make_type (info, kind, 0);
1710 if (t == NULL)
1711 return DEBUG_TYPE_NULL;
1712
1713 return debug_tag_type (handle, name, t);
1714 }
1715
1716 /* Make a base class for an object. The second argument is the base
1717 class type. The third argument is the bit position of this base
1718 class in the object (always 0 unless doing multiple inheritance).
1719 The fourth argument is whether this is a virtual class. The fifth
1720 argument is the visibility of the base class. */
1721
1722 /*ARGSUSED*/
1723 debug_baseclass
1724 debug_make_baseclass (handle, type, bitpos, virtual, visibility)
1725 PTR handle;
1726 debug_type type;
1727 bfd_vma bitpos;
1728 boolean virtual;
1729 enum debug_visibility visibility;
1730 {
1731 struct debug_baseclass *b;
1732
1733 b = (struct debug_baseclass *) xmalloc (sizeof *b);
1734 memset (b, 0, sizeof *b);
1735
1736 b->type = type;
1737 b->bitpos = bitpos;
1738 b->virtual = virtual;
1739 b->visibility = visibility;
1740
1741 return b;
1742 }
1743
1744 /* Make a field for a struct. The second argument is the name. The
1745 third argument is the type of the field. The fourth argument is
1746 the bit position of the field. The fifth argument is the size of
1747 the field (it may be zero). The sixth argument is the visibility
1748 of the field. */
1749
1750 /*ARGSUSED*/
1751 debug_field
1752 debug_make_field (handle, name, type, bitpos, bitsize, visibility)
1753 PTR handle;
1754 const char *name;
1755 debug_type type;
1756 bfd_vma bitpos;
1757 bfd_vma bitsize;
1758 enum debug_visibility visibility;
1759 {
1760 struct debug_field *f;
1761
1762 f = (struct debug_field *) xmalloc (sizeof *f);
1763 memset (f, 0, sizeof *f);
1764
1765 f->name = name;
1766 f->type = type;
1767 f->static_member = false;
1768 f->u.f.bitpos = bitpos;
1769 f->u.f.bitsize = bitsize;
1770 f->visibility = visibility;
1771
1772 return f;
1773 }
1774
1775 /* Make a static member of an object. The second argument is the
1776 name. The third argument is the type of the member. The fourth
1777 argument is the physical name of the member (i.e., the name as a
1778 global variable). The fifth argument is the visibility of the
1779 member. */
1780
1781 /*ARGSUSED*/
1782 debug_field
1783 debug_make_static_member (handle, name, type, physname, visibility)
1784 PTR handle;
1785 const char *name;
1786 debug_type type;
1787 const char *physname;
1788 enum debug_visibility visibility;
1789 {
1790 struct debug_field *f;
1791
1792 f = (struct debug_field *) xmalloc (sizeof *f);
1793 memset (f, 0, sizeof *f);
1794
1795 f->name = name;
1796 f->type = type;
1797 f->static_member = true;
1798 f->u.s.physname = physname;
1799 f->visibility = visibility;
1800
1801 return f;
1802 }
1803
1804 /* Make a method. The second argument is the name, and the third
1805 argument is a NULL terminated array of method variants. */
1806
1807 /*ARGSUSED*/
1808 debug_method
1809 debug_make_method (handle, name, variants)
1810 PTR handle;
1811 const char *name;
1812 debug_method_variant *variants;
1813 {
1814 struct debug_method *m;
1815
1816 m = (struct debug_method *) xmalloc (sizeof *m);
1817 memset (m, 0, sizeof *m);
1818
1819 m->name = name;
1820 m->variants = variants;
1821
1822 return m;
1823 }
1824
1825 /* Make a method argument. The second argument is the real name of
1826 the function. The third argument is the type of the function. The
1827 fourth argument is the visibility. The fifth argument is whether
1828 this is a const function. The sixth argument is whether this is a
1829 volatile function. The seventh argument is the offset in the
1830 virtual function table, if any. The eighth argument is the virtual
1831 function context. FIXME: Are the const and volatile arguments
1832 necessary? Could we just use debug_make_const_type? */
1833
1834 /*ARGSUSED*/
1835 debug_method_variant
1836 debug_make_method_variant (handle, argtypes, type, visibility, constp,
1837 volatilep, voffset, context)
1838 PTR handle;
1839 const char *argtypes;
1840 debug_type type;
1841 enum debug_visibility visibility;
1842 boolean constp;
1843 boolean volatilep;
1844 bfd_vma voffset;
1845 debug_type context;
1846 {
1847 struct debug_method_variant *m;
1848
1849 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1850 memset (m, 0, sizeof *m);
1851
1852 m->argtypes = argtypes;
1853 m->type = type;
1854 m->visibility = visibility;
1855 m->constp = constp;
1856 m->volatilep = volatilep;
1857 m->voffset = voffset;
1858 m->context = context;
1859
1860 return m;
1861 }
1862
1863 /* Make a static method argument. The arguments are the same as for
1864 debug_make_method_variant, except that the last two are omitted
1865 since a static method can not also be virtual. */
1866
1867 debug_method_variant
1868 debug_make_static_method_variant (handle, argtypes, type, visibility,
1869 constp, volatilep)
1870 PTR handle;
1871 const char *argtypes;
1872 debug_type type;
1873 enum debug_visibility visibility;
1874 boolean constp;
1875 boolean volatilep;
1876 {
1877 struct debug_method_variant *m;
1878
1879 m = (struct debug_method_variant *) xmalloc (sizeof *m);
1880 memset (m, 0, sizeof *m);
1881
1882 m->argtypes = argtypes;
1883 m->type = type;
1884 m->visibility = visibility;
1885 m->constp = constp;
1886 m->volatilep = volatilep;
1887 m->voffset = VOFFSET_STATIC_METHOD;
1888
1889 return m;
1890 }
1891
1892 /* Name a type. */
1893
1894 debug_type
1895 debug_name_type (handle, name, type)
1896 PTR handle;
1897 const char *name;
1898 debug_type type;
1899 {
1900 struct debug_handle *info = (struct debug_handle *) handle;
1901 struct debug_type *t;
1902 struct debug_named_type *n;
1903 struct debug_name *nm;
1904
1905 if (name == NULL || type == NULL)
1906 return DEBUG_TYPE_NULL;
1907
1908 t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
1909 if (t == NULL)
1910 return DEBUG_TYPE_NULL;
1911
1912 n = (struct debug_named_type *) xmalloc (sizeof *n);
1913 memset (n, 0, sizeof *n);
1914
1915 n->type = type;
1916
1917 t->u.knamed = n;
1918
1919 /* We also need to add the name to the current namespace. */
1920
1921 nm = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPE,
1922 DEBUG_LINKAGE_NONE);
1923 if (nm == NULL)
1924 return false;
1925
1926 nm->u.type = t;
1927
1928 n->name = nm;
1929
1930 return t;
1931 }
1932
1933 /* Tag a type. */
1934
1935 debug_type
1936 debug_tag_type (handle, name, type)
1937 PTR handle;
1938 const char *name;
1939 debug_type type;
1940 {
1941 struct debug_handle *info = (struct debug_handle *) handle;
1942 struct debug_type *t;
1943 struct debug_named_type *n;
1944 struct debug_name *nm;
1945
1946 if (name == NULL || type == NULL)
1947 return DEBUG_TYPE_NULL;
1948
1949 if (info->current_file == NULL)
1950 {
1951 debug_error ("debug_tag_type: no current file");
1952 return DEBUG_TYPE_NULL;
1953 }
1954
1955 if (type->kind == DEBUG_KIND_TAGGED)
1956 {
1957 if (strcmp (type->u.knamed->name->name, name) == 0)
1958 return type;
1959 debug_error ("debug_tag_type: extra tag attempted");
1960 return DEBUG_TYPE_NULL;
1961 }
1962
1963 t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
1964 if (t == NULL)
1965 return DEBUG_TYPE_NULL;
1966
1967 n = (struct debug_named_type *) xmalloc (sizeof *n);
1968 memset (n, 0, sizeof *n);
1969
1970 n->type = type;
1971
1972 t->u.knamed = n;
1973
1974 /* We keep a global namespace of tags for each compilation unit. I
1975 don't know if that is the right thing to do. */
1976
1977 nm = debug_add_to_namespace (info, &info->current_file->globals, name,
1978 DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
1979 if (nm == NULL)
1980 return false;
1981
1982 nm->u.tag = t;
1983
1984 n->name = nm;
1985
1986 return t;
1987 }
1988
1989 /* Record the size of a given type. */
1990
1991 /*ARGSUSED*/
1992 boolean
1993 debug_record_type_size (handle, type, size)
1994 PTR handle;
1995 debug_type type;
1996 unsigned int size;
1997 {
1998 if (type->size != 0 && type->size != size)
1999 fprintf (stderr, "Warning: changing type size from %d to %d\n",
2000 type->size, size);
2001
2002 type->size = size;
2003
2004 return true;
2005 }
2006
2007 /* Find a tagged type. */
2008
2009 debug_type
2010 debug_find_tagged_type (handle, name, kind)
2011 PTR handle;
2012 const char *name;
2013 enum debug_type_kind kind;
2014 {
2015 struct debug_handle *info = (struct debug_handle *) handle;
2016 struct debug_unit *u;
2017
2018 /* We search the globals of all the compilation units. I don't know
2019 if this is correct or not. It would be easy to change. */
2020
2021 for (u = info->units; u != NULL; u = u->next)
2022 {
2023 struct debug_file *f;
2024
2025 for (f = u->files; f != NULL; f = f->next)
2026 {
2027 struct debug_name *n;
2028
2029 if (f->globals != NULL)
2030 {
2031 for (n = f->globals->list; n != NULL; n = n->next)
2032 {
2033 if (n->kind == DEBUG_OBJECT_TAG
2034 && (kind == DEBUG_KIND_VOID
2035 || n->u.tag->kind == kind)
2036 && n->name[0] == name[0]
2037 && strcmp (n->name, name) == 0)
2038 return n->u.tag;
2039 }
2040 }
2041 }
2042 }
2043
2044 return DEBUG_TYPE_NULL;
2045 }
2046
2047 /* Get the name of a type. */
2048
2049 /*ARGSUSED*/
2050 const char *
2051 debug_get_type_name (handle, type)
2052 PTR handle;
2053 debug_type type;
2054 {
2055 if (type->kind == DEBUG_KIND_INDIRECT)
2056 {
2057 if (*type->u.kindirect->slot != NULL)
2058 return debug_get_type_name (handle, *type->u.kindirect->slot);
2059 return type->u.kindirect->tag;
2060 }
2061 if (type->kind == DEBUG_KIND_NAMED
2062 || type->kind == DEBUG_KIND_TAGGED)
2063 return type->u.knamed->name->name;
2064 return NULL;
2065 }
2066 \f
2067 /* Write out the debugging information. This is given a handle to
2068 debugging information, and a set of function pointers to call. */
2069
2070 boolean
2071 debug_write (handle, fns, fhandle)
2072 PTR handle;
2073 const struct debug_write_fns *fns;
2074 PTR fhandle;
2075 {
2076 struct debug_handle *info = (struct debug_handle *) handle;
2077 struct debug_unit *u;
2078
2079 /* We use a mark to tell whether we have already written out a
2080 particular name. We use an integer, so that we don't have to
2081 clear the mark fields if we happen to write out the same
2082 information more than once. */
2083 ++info->mark;
2084
2085 for (u = info->units; u != NULL; u = u->next)
2086 {
2087 struct debug_file *f;
2088 boolean first_file;
2089 struct debug_lineno *l;
2090
2091 if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
2092 return false;
2093
2094 first_file = true;
2095 for (f = u->files; f != NULL; f = f->next)
2096 {
2097 struct debug_name *n;
2098
2099 if (first_file)
2100 first_file = false;
2101 else
2102 {
2103 if (! (*fns->start_source) (fhandle, f->filename))
2104 return false;
2105 }
2106
2107 if (f->globals != NULL)
2108 {
2109 for (n = f->globals->list; n != NULL; n = n->next)
2110 {
2111 if (! debug_write_name (info, fns, fhandle, n))
2112 return false;
2113 }
2114 }
2115 }
2116
2117 for (l = u->linenos; l != NULL; l = l->next)
2118 {
2119 unsigned int i;
2120
2121 for (i = 0; i < DEBUG_LINENO_COUNT; i++)
2122 {
2123 if (l->linenos[i] == (unsigned long) -1)
2124 break;
2125 if (! (*fns->lineno) (fhandle, l->file->filename, l->linenos[i],
2126 l->addrs[i]))
2127 return false;
2128 }
2129 }
2130 }
2131
2132 return true;
2133 }
2134
2135 /* Write out an element in a namespace. */
2136
2137 static boolean
2138 debug_write_name (info, fns, fhandle, n)
2139 struct debug_handle *info;
2140 const struct debug_write_fns *fns;
2141 PTR fhandle;
2142 struct debug_name *n;
2143 {
2144 /* The class_mark field is used to prevent recursively outputting a
2145 struct or class. */
2146 ++info->class_mark;
2147
2148 switch (n->kind)
2149 {
2150 case DEBUG_OBJECT_TYPE:
2151 if (! debug_write_type (info, fns, fhandle, n->u.type, n)
2152 || ! (*fns->typdef) (fhandle, n->name))
2153 return false;
2154 return true;
2155 case DEBUG_OBJECT_TAG:
2156 if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
2157 return false;
2158 return (*fns->tag) (fhandle, n->name);
2159 case DEBUG_OBJECT_VARIABLE:
2160 if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
2161 (struct debug_name *) NULL))
2162 return false;
2163 return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
2164 n->u.variable->val);
2165 case DEBUG_OBJECT_FUNCTION:
2166 return debug_write_function (info, fns, fhandle, n->name,
2167 n->linkage, n->u.function);
2168 case DEBUG_OBJECT_INT_CONSTANT:
2169 return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
2170 case DEBUG_OBJECT_FLOAT_CONSTANT:
2171 return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
2172 case DEBUG_OBJECT_TYPED_CONSTANT:
2173 if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
2174 (struct debug_name *) NULL))
2175 return false;
2176 return (*fns->typed_constant) (fhandle, n->name,
2177 n->u.typed_constant->val);
2178 default:
2179 abort ();
2180 return false;
2181 }
2182 /*NOTREACHED*/
2183 }
2184
2185 /* Write out a type. If the type is DEBUG_KIND_NAMED or
2186 DEBUG_KIND_TAGGED, then the name argument is the name for which we
2187 are about to call typedef or tag. If the type is anything else,
2188 then the name argument is a tag from a DEBUG_KIND_TAGGED type which
2189 points to this one. */
2190
2191 static boolean
2192 debug_write_type (info, fns, fhandle, type, name)
2193 struct debug_handle *info;
2194 const struct debug_write_fns *fns;
2195 PTR fhandle;
2196 struct debug_type *type;
2197 struct debug_name *name;
2198 {
2199 unsigned int i;
2200 const char *tag;
2201
2202 /* If we have a name for this type, just output it. We only output
2203 typedef names after they have been defined. We output type tags
2204 whenever we are not actually defining them. */
2205 if ((type->kind == DEBUG_KIND_NAMED
2206 || type->kind == DEBUG_KIND_TAGGED)
2207 && (type->u.knamed->name->mark == info->mark
2208 || (type->kind == DEBUG_KIND_TAGGED
2209 && type->u.knamed->name != name)))
2210 {
2211 if (type->kind == DEBUG_KIND_NAMED)
2212 return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
2213 else
2214 return (*fns->tag_type) (fhandle, type->u.knamed->name->name,
2215 type->u.knamed->type->kind);
2216 }
2217
2218 /* Mark the name after we have already looked for a known name, so
2219 that we don't just define a type in terms of itself. We need to
2220 mark the name here so that a struct containing a pointer to
2221 itself will work. */
2222 if (name != NULL)
2223 name->mark = info->mark;
2224
2225 tag = NULL;
2226 if (name != NULL
2227 && type->kind != DEBUG_KIND_NAMED
2228 && type->kind != DEBUG_KIND_TAGGED)
2229 {
2230 assert (name->kind == DEBUG_OBJECT_TAG);
2231 tag = name->name;
2232 }
2233
2234 switch (type->kind)
2235 {
2236 case DEBUG_KIND_INDIRECT:
2237 if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
2238 return (*fns->empty_type) (fhandle);
2239 return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
2240 (struct debug_name *) NULL);
2241 case DEBUG_KIND_VOID:
2242 return (*fns->void_type) (fhandle);
2243 case DEBUG_KIND_INT:
2244 return (*fns->int_type) (fhandle, type->size, type->u.kint);
2245 case DEBUG_KIND_FLOAT:
2246 return (*fns->float_type) (fhandle, type->size);
2247 case DEBUG_KIND_COMPLEX:
2248 return (*fns->complex_type) (fhandle, type->size);
2249 case DEBUG_KIND_BOOL:
2250 return (*fns->bool_type) (fhandle, type->size);
2251 case DEBUG_KIND_STRUCT:
2252 case DEBUG_KIND_UNION:
2253 if (info->class_mark == type->u.kclass->mark)
2254 {
2255 /* We are currently outputting this struct. I don't know if
2256 this can happen, but it can happen for a class. */
2257 return (*fns->tag_type) (fhandle, "?defining?", type->kind);
2258 }
2259 type->u.kclass->mark = info->class_mark;
2260
2261 if (! (*fns->start_struct_type) (fhandle, tag,
2262 type->kind == DEBUG_KIND_STRUCT,
2263 type->size))
2264 return false;
2265 if (type->u.kclass->fields != NULL)
2266 {
2267 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2268 {
2269 struct debug_field *f;
2270
2271 f = type->u.kclass->fields[i];
2272 if (! debug_write_type (info, fns, fhandle, f->type,
2273 (struct debug_name *) NULL)
2274 || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2275 f->u.f.bitsize, f->visibility))
2276 return false;
2277 }
2278 }
2279 return (*fns->end_struct_type) (fhandle);
2280 case DEBUG_KIND_CLASS:
2281 case DEBUG_KIND_UNION_CLASS:
2282 return debug_write_class_type (info, fns, fhandle, type, tag);
2283 case DEBUG_KIND_ENUM:
2284 return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
2285 type->u.kenum->values);
2286 case DEBUG_KIND_POINTER:
2287 if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
2288 (struct debug_name *) NULL))
2289 return false;
2290 return (*fns->pointer_type) (fhandle);
2291 case DEBUG_KIND_FUNCTION:
2292 if (! debug_write_type (info, fns, fhandle,
2293 type->u.kfunction->return_type,
2294 (struct debug_name *) NULL))
2295 return false;
2296 return (*fns->function_type) (fhandle);
2297 case DEBUG_KIND_REFERENCE:
2298 if (! debug_write_type (info, fns, fhandle, type->u.kreference,
2299 (struct debug_name *) NULL))
2300 return false;
2301 return (*fns->reference_type) (fhandle);
2302 case DEBUG_KIND_RANGE:
2303 if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
2304 (struct debug_name *) NULL))
2305 return false;
2306 return (*fns->range_type) (fhandle, type->u.krange->lower,
2307 type->u.krange->upper);
2308 case DEBUG_KIND_ARRAY:
2309 if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
2310 (struct debug_name *) NULL)
2311 || ! debug_write_type (info, fns, fhandle,
2312 type->u.karray->range_type,
2313 (struct debug_name *) NULL))
2314 return false;
2315 return (*fns->array_type) (fhandle, type->u.karray->lower,
2316 type->u.karray->upper,
2317 type->u.karray->stringp);
2318 case DEBUG_KIND_SET:
2319 if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
2320 (struct debug_name *) NULL))
2321 return false;
2322 return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
2323 case DEBUG_KIND_OFFSET:
2324 if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
2325 (struct debug_name *) NULL)
2326 || ! debug_write_type (info, fns, fhandle,
2327 type->u.koffset->target_type,
2328 (struct debug_name *) NULL))
2329 return false;
2330 return (*fns->offset_type) (fhandle);
2331 case DEBUG_KIND_METHOD:
2332 if (! debug_write_type (info, fns, fhandle,
2333 type->u.kmethod->return_type,
2334 (struct debug_name *) NULL))
2335 return false;
2336 if (type->u.kmethod->arg_types == NULL)
2337 i = -1;
2338 else
2339 {
2340 for (i = 0; type->u.kmethod->arg_types[i] != NULL; i++)
2341 {
2342 if (! debug_write_type (info, fns, fhandle,
2343 type->u.kmethod->arg_types[i],
2344 (struct debug_name *) NULL))
2345 return false;
2346 }
2347 }
2348 if (type->u.kmethod->domain_type != NULL)
2349 {
2350 if (! debug_write_type (info, fns, fhandle,
2351 type->u.kmethod->domain_type,
2352 (struct debug_name *) NULL))
2353 return false;
2354 }
2355 return (*fns->method_type) (fhandle,
2356 type->u.kmethod->domain_type != NULL,
2357 i);
2358 case DEBUG_KIND_CONST:
2359 if (! debug_write_type (info, fns, fhandle, type->u.kconst,
2360 (struct debug_name *) NULL))
2361 return false;
2362 return (*fns->const_type) (fhandle);
2363 case DEBUG_KIND_VOLATILE:
2364 if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
2365 (struct debug_name *) NULL))
2366 return false;
2367 return (*fns->volatile_type) (fhandle);
2368 case DEBUG_KIND_NAMED:
2369 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2370 (struct debug_name *) NULL);
2371 case DEBUG_KIND_TAGGED:
2372 return debug_write_type (info, fns, fhandle, type->u.knamed->type,
2373 type->u.knamed->name);
2374 default:
2375 abort ();
2376 return false;
2377 }
2378 }
2379
2380 /* Write out a class type. */
2381
2382 static boolean
2383 debug_write_class_type (info, fns, fhandle, type, tag)
2384 struct debug_handle *info;
2385 const struct debug_write_fns *fns;
2386 PTR fhandle;
2387 struct debug_type *type;
2388 const char *tag;
2389 {
2390 unsigned int i;
2391
2392 if (info->class_mark == type->u.kclass->mark)
2393 {
2394 /* We are currently outputting this class. This can happen when
2395 there are methods for an anonymous class. */
2396 return (*fns->tag_type) (fhandle, "?defining?", type->kind);
2397 }
2398 type->u.kclass->mark = info->class_mark;
2399
2400 if (type->u.kclass->vptrbase != NULL
2401 && type->u.kclass->vptrbase != type)
2402 {
2403 if (! debug_write_type (info, fns, fhandle, type->u.kclass->vptrbase,
2404 (struct debug_name *) NULL))
2405 return false;
2406 }
2407
2408 if (! (*fns->start_class_type) (fhandle, tag,
2409 type->kind == DEBUG_KIND_CLASS,
2410 type->size,
2411 type->u.kclass->vptrbase != NULL,
2412 type->u.kclass->vptrbase == type))
2413 return false;
2414 if (type->u.kclass->fields != NULL)
2415 {
2416 for (i = 0; type->u.kclass->fields[i] != NULL; i++)
2417 {
2418 struct debug_field *f;
2419
2420 f = type->u.kclass->fields[i];
2421 if (! debug_write_type (info, fns, fhandle, f->type,
2422 (struct debug_name *) NULL))
2423 return false;
2424 if (f->static_member)
2425 {
2426 if (! (*fns->class_static_member) (fhandle, f->name,
2427 f->u.s.physname,
2428 f->visibility))
2429 return false;
2430 }
2431 else
2432 {
2433 if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
2434 f->u.f.bitsize, f->visibility))
2435 return false;
2436 }
2437 }
2438 }
2439
2440 if (type->u.kclass->baseclasses != NULL)
2441 {
2442 for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
2443 {
2444 struct debug_baseclass *b;
2445
2446 b = type->u.kclass->baseclasses[i];
2447 if (! debug_write_type (info, fns, fhandle, b->type,
2448 (struct debug_name *) NULL))
2449 return false;
2450 if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
2451 b->visibility))
2452 return false;
2453 }
2454 }
2455
2456 if (type->u.kclass->methods != NULL)
2457 {
2458 for (i = 0; type->u.kclass->methods[i] != NULL; i++)
2459 {
2460 struct debug_method *m;
2461 unsigned int j;
2462
2463 m = type->u.kclass->methods[i];
2464 if (! (*fns->class_start_method) (fhandle, m->name))
2465 return false;
2466 for (j = 0; m->variants[j] != NULL; j++)
2467 {
2468 struct debug_method_variant *v;
2469
2470 v = m->variants[j];
2471 if (v->context != NULL)
2472 {
2473 if (! debug_write_type (info, fns, fhandle, v->context,
2474 (struct debug_name *) NULL))
2475 return false;
2476 }
2477 if (! debug_write_type (info, fns, fhandle, v->type,
2478 (struct debug_name *) NULL))
2479 return false;
2480 if (v->voffset != VOFFSET_STATIC_METHOD)
2481 {
2482 if (! (*fns->class_method_variant) (fhandle, v->argtypes,
2483 v->visibility,
2484 v->constp, v->volatilep,
2485 v->voffset,
2486 v->context != NULL))
2487 return false;
2488 }
2489 else
2490 {
2491 if (! (*fns->class_static_method_variant) (fhandle,
2492 v->argtypes,
2493 v->visibility,
2494 v->constp,
2495 v->volatilep))
2496 return false;
2497 }
2498 }
2499 if (! (*fns->class_end_method) (fhandle))
2500 return false;
2501 }
2502 }
2503
2504 return (*fns->end_class_type) (fhandle);
2505 }
2506
2507 /* Write out information for a function. */
2508
2509 static boolean
2510 debug_write_function (info, fns, fhandle, name, linkage, function)
2511 struct debug_handle *info;
2512 const struct debug_write_fns *fns;
2513 PTR fhandle;
2514 const char *name;
2515 enum debug_object_linkage linkage;
2516 struct debug_function *function;
2517 {
2518 struct debug_parameter *p;
2519 struct debug_block *b;
2520
2521 if (! debug_write_type (info, fns, fhandle, function->return_type,
2522 (struct debug_name *) NULL))
2523 return false;
2524
2525 if (! (*fns->start_function) (fhandle, name,
2526 linkage == DEBUG_LINKAGE_GLOBAL))
2527 return false;
2528
2529 for (p = function->parameters; p != NULL; p = p->next)
2530 {
2531 if (! debug_write_type (info, fns, fhandle, p->type,
2532 (struct debug_name *) NULL)
2533 || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
2534 return false;
2535 }
2536
2537 for (b = function->blocks; b != NULL; b = b->next)
2538 {
2539 if (! debug_write_block (info, fns, fhandle, b))
2540 return false;
2541 }
2542
2543 return (*fns->end_function) (fhandle);
2544 }
2545
2546 /* Write out information for a block. */
2547
2548 static boolean
2549 debug_write_block (info, fns, fhandle, block)
2550 struct debug_handle *info;
2551 const struct debug_write_fns *fns;
2552 PTR fhandle;
2553 struct debug_block *block;
2554 {
2555 struct debug_name *n;
2556 struct debug_block *b;
2557
2558 if (! (*fns->start_block) (fhandle, block->start))
2559 return false;
2560
2561 if (block->locals != NULL)
2562 {
2563 for (n = block->locals->list; n != NULL; n = n->next)
2564 {
2565 if (! debug_write_name (info, fns, fhandle, n))
2566 return false;
2567 }
2568 }
2569
2570 for (b = block->children; b != NULL; b = b->next)
2571 {
2572 if (! debug_write_block (info, fns, fhandle, b))
2573 return false;
2574 }
2575
2576 return (*fns->end_block) (fhandle, block->end);
2577 }
This page took 0.084842 seconds and 5 git commands to generate.