00001 /* debug.c -- Handle generic debugging information. 00002 Copyright (C) 1995, 1996 Free Software Foundation, Inc. 00003 Written by Ian Lance Taylor <ian@cygnus.com>. 00004 00005 This file is part of GNU Binutils. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00020 02111-1307, USA. */ 00021 00022 /* This file implements a generic debugging format. We may eventually 00023 have readers which convert different formats into this generic 00024 format, and writers which write it out. The initial impetus for 00025 this was writing a convertor from stabs to HP IEEE-695 debugging 00026 format. */ 00027 00028 #include <stdio.h> 00029 #include <assert.h> 00030 00031 #include <bfd.h> 00032 #include "bucomm.h" 00033 #include <libiberty.h> 00034 #include "debug.h" 00035 00036 /* Global information we keep for debugging. A pointer to this 00037 structure is the debugging handle passed to all the routines. */ 00038 00039 struct debug_handle 00040 { 00041 /* A linked list of compilation units. */ 00042 struct debug_unit *units; 00043 /* The current compilation unit. */ 00044 struct debug_unit *current_unit; 00045 /* The current source file. */ 00046 struct debug_file *current_file; 00047 /* The current function. */ 00048 struct debug_function *current_function; 00049 /* The current block. */ 00050 struct debug_block *current_block; 00051 /* The current line number information for the current unit. */ 00052 struct debug_lineno *current_lineno; 00053 /* Mark. This is used by debug_write. */ 00054 unsigned int mark; 00055 /* A struct/class ID used by debug_write. */ 00056 unsigned int class_id; 00057 /* The base for class_id for this call to debug_write. */ 00058 unsigned int base_id; 00059 /* The current line number in debug_write. */ 00060 struct debug_lineno *current_write_lineno; 00061 unsigned int current_write_lineno_index; 00062 /* A list of classes which have assigned ID's during debug_write. 00063 This is linked through the next_id field of debug_class_type. */ 00064 struct debug_class_id *id_list; 00065 /* A list used to avoid recursion during debug_type_samep. */ 00066 struct debug_type_compare_list *compare_list; 00067 }; 00068 00069 /* Information we keep for a single compilation unit. */ 00070 00071 struct debug_unit 00072 { 00073 /* The next compilation unit. */ 00074 struct debug_unit *next; 00075 /* A list of files included in this compilation unit. The first 00076 file is always the main one, and that is where the main file name 00077 is stored. */ 00078 struct debug_file *files; 00079 /* Line number information for this compilation unit. This is not 00080 stored by function, because assembler code may have line number 00081 information without function information. */ 00082 struct debug_lineno *linenos; 00083 }; 00084 00085 /* Information kept for a single source file. */ 00086 00087 struct debug_file 00088 { 00089 /* The next source file in this compilation unit. */ 00090 struct debug_file *next; 00091 /* The name of the source file. */ 00092 const char *filename; 00093 /* Global functions, variables, types, etc. */ 00094 struct debug_namespace *globals; 00095 }; 00096 00097 /* A type. */ 00098 00099 struct debug_type 00100 { 00101 /* Kind of type. */ 00102 enum debug_type_kind kind; 00103 /* Size of type (0 if not known). */ 00104 unsigned int size; 00105 /* Type which is a pointer to this type. */ 00106 debug_type pointer; 00107 /* Tagged union with additional information about the type. */ 00108 union 00109 { 00110 /* DEBUG_KIND_INDIRECT. */ 00111 struct debug_indirect_type *kindirect; 00112 /* DEBUG_KIND_INT. */ 00113 /* Whether the integer is unsigned. */ 00114 boolean kint; 00115 /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS, 00116 DEBUG_KIND_UNION_CLASS. */ 00117 struct debug_class_type *kclass; 00118 /* DEBUG_KIND_ENUM. */ 00119 struct debug_enum_type *kenum; 00120 /* DEBUG_KIND_POINTER. */ 00121 struct debug_type *kpointer; 00122 /* DEBUG_KIND_FUNCTION. */ 00123 struct debug_function_type *kfunction; 00124 /* DEBUG_KIND_REFERENCE. */ 00125 struct debug_type *kreference; 00126 /* DEBUG_KIND_RANGE. */ 00127 struct debug_range_type *krange; 00128 /* DEBUG_KIND_ARRAY. */ 00129 struct debug_array_type *karray; 00130 /* DEBUG_KIND_SET. */ 00131 struct debug_set_type *kset; 00132 /* DEBUG_KIND_OFFSET. */ 00133 struct debug_offset_type *koffset; 00134 /* DEBUG_KIND_METHOD. */ 00135 struct debug_method_type *kmethod; 00136 /* DEBUG_KIND_CONST. */ 00137 struct debug_type *kconst; 00138 /* DEBUG_KIND_VOLATILE. */ 00139 struct debug_type *kvolatile; 00140 /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */ 00141 struct debug_named_type *knamed; 00142 } u; 00143 }; 00144 00145 /* Information kept for an indirect type. */ 00146 00147 struct debug_indirect_type 00148 { 00149 /* Slot where the final type will appear. */ 00150 debug_type *slot; 00151 /* Tag. */ 00152 const char *tag; 00153 }; 00154 00155 /* Information kept for a struct, union, or class. */ 00156 00157 struct debug_class_type 00158 { 00159 /* NULL terminated array of fields. */ 00160 debug_field *fields; 00161 /* A mark field which indicates whether the struct has already been 00162 printed. */ 00163 unsigned int mark; 00164 /* This is used to uniquely identify unnamed structs when printing. */ 00165 unsigned int id; 00166 /* The remaining fields are only used for DEBUG_KIND_CLASS and 00167 DEBUG_KIND_UNION_CLASS. */ 00168 /* NULL terminated array of base classes. */ 00169 debug_baseclass *baseclasses; 00170 /* NULL terminated array of methods. */ 00171 debug_method *methods; 00172 /* The type of the class providing the virtual function table for 00173 this class. This may point to the type itself. */ 00174 debug_type vptrbase; 00175 }; 00176 00177 /* Information kept for an enum. */ 00178 00179 struct debug_enum_type 00180 { 00181 /* NULL terminated array of names. */ 00182 const char **names; 00183 /* Array of corresponding values. */ 00184 bfd_signed_vma *values; 00185 }; 00186 00187 /* Information kept for a function. FIXME: We should be able to 00188 record the parameter types. */ 00189 00190 struct debug_function_type 00191 { 00192 /* Return type. */ 00193 debug_type return_type; 00194 /* NULL terminated array of argument types. */ 00195 debug_type *arg_types; 00196 /* Whether the function takes a variable number of arguments. */ 00197 boolean varargs; 00198 }; 00199 00200 /* Information kept for a range. */ 00201 00202 struct debug_range_type 00203 { 00204 /* Range base type. */ 00205 debug_type type; 00206 /* Lower bound. */ 00207 bfd_signed_vma lower; 00208 /* Upper bound. */ 00209 bfd_signed_vma upper; 00210 }; 00211 00212 /* Information kept for an array. */ 00213 00214 struct debug_array_type 00215 { 00216 /* Element type. */ 00217 debug_type element_type; 00218 /* Range type. */ 00219 debug_type range_type; 00220 /* Lower bound. */ 00221 bfd_signed_vma lower; 00222 /* Upper bound. */ 00223 bfd_signed_vma upper; 00224 /* Whether this array is really a string. */ 00225 boolean stringp; 00226 }; 00227 00228 /* Information kept for a set. */ 00229 00230 struct debug_set_type 00231 { 00232 /* Base type. */ 00233 debug_type type; 00234 /* Whether this set is really a bitstring. */ 00235 boolean bitstringp; 00236 }; 00237 00238 /* Information kept for an offset type (a based pointer). */ 00239 00240 struct debug_offset_type 00241 { 00242 /* The type the pointer is an offset from. */ 00243 debug_type base_type; 00244 /* The type the pointer points to. */ 00245 debug_type target_type; 00246 }; 00247 00248 /* Information kept for a method type. */ 00249 00250 struct debug_method_type 00251 { 00252 /* The return type. */ 00253 debug_type return_type; 00254 /* The object type which this method is for. */ 00255 debug_type domain_type; 00256 /* A NULL terminated array of argument types. */ 00257 debug_type *arg_types; 00258 /* Whether the method takes a variable number of arguments. */ 00259 boolean varargs; 00260 }; 00261 00262 /* Information kept for a named type. */ 00263 00264 struct debug_named_type 00265 { 00266 /* Name. */ 00267 struct debug_name *name; 00268 /* Real type. */ 00269 debug_type type; 00270 }; 00271 00272 /* A field in a struct or union. */ 00273 00274 struct debug_field 00275 { 00276 /* Name of the field. */ 00277 const char *name; 00278 /* Type of the field. */ 00279 struct debug_type *type; 00280 /* Visibility of the field. */ 00281 enum debug_visibility visibility; 00282 /* Whether this is a static member. */ 00283 boolean static_member; 00284 union 00285 { 00286 /* If static_member is false. */ 00287 struct 00288 { 00289 /* Bit position of the field in the struct. */ 00290 unsigned int bitpos; 00291 /* Size of the field in bits. */ 00292 unsigned int bitsize; 00293 } f; 00294 /* If static_member is true. */ 00295 struct 00296 { 00297 const char *physname; 00298 } s; 00299 } u; 00300 }; 00301 00302 /* A base class for an object. */ 00303 00304 struct debug_baseclass 00305 { 00306 /* Type of the base class. */ 00307 struct debug_type *type; 00308 /* Bit position of the base class in the object. */ 00309 unsigned int bitpos; 00310 /* Whether the base class is virtual. */ 00311 boolean virtual; 00312 /* Visibility of the base class. */ 00313 enum debug_visibility visibility; 00314 }; 00315 00316 /* A method of an object. */ 00317 00318 struct debug_method 00319 { 00320 /* The name of the method. */ 00321 const char *name; 00322 /* A NULL terminated array of different types of variants. */ 00323 struct debug_method_variant **variants; 00324 }; 00325 00326 /* The variants of a method function of an object. These indicate 00327 which method to run. */ 00328 00329 struct debug_method_variant 00330 { 00331 /* The physical name of the function. */ 00332 const char *physname; 00333 /* The type of the function. */ 00334 struct debug_type *type; 00335 /* The visibility of the function. */ 00336 enum debug_visibility visibility; 00337 /* Whether the function is const. */ 00338 boolean constp; 00339 /* Whether the function is volatile. */ 00340 boolean volatilep; 00341 /* The offset to the function in the virtual function table. */ 00342 bfd_vma voffset; 00343 /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */ 00344 #define VOFFSET_STATIC_METHOD ((bfd_vma) -1) 00345 /* Context of a virtual method function. */ 00346 struct debug_type *context; 00347 }; 00348 00349 /* A variable. This is the information we keep for a variable object. 00350 This has no name; a name is associated with a variable in a 00351 debug_name structure. */ 00352 00353 struct debug_variable 00354 { 00355 /* Kind of variable. */ 00356 enum debug_var_kind kind; 00357 /* Type. */ 00358 debug_type type; 00359 /* Value. The interpretation of the value depends upon kind. */ 00360 bfd_vma val; 00361 }; 00362 00363 /* A function. This has no name; a name is associated with a function 00364 in a debug_name structure. */ 00365 00366 struct debug_function 00367 { 00368 /* Return type. */ 00369 debug_type return_type; 00370 /* Parameter information. */ 00371 struct debug_parameter *parameters; 00372 /* Block information. The first structure on the list is the main 00373 block of the function, and describes function local variables. */ 00374 struct debug_block *blocks; 00375 }; 00376 00377 /* A function parameter. */ 00378 00379 struct debug_parameter 00380 { 00381 /* Next parameter. */ 00382 struct debug_parameter *next; 00383 /* Name. */ 00384 const char *name; 00385 /* Type. */ 00386 debug_type type; 00387 /* Kind. */ 00388 enum debug_parm_kind kind; 00389 /* Value (meaning depends upon kind). */ 00390 bfd_vma val; 00391 }; 00392 00393 /* A typed constant. */ 00394 00395 struct debug_typed_constant 00396 { 00397 /* Type. */ 00398 debug_type type; 00399 /* Value. FIXME: We may eventually need to support non-integral 00400 values. */ 00401 bfd_vma val; 00402 }; 00403 00404 /* Information about a block within a function. */ 00405 00406 struct debug_block 00407 { 00408 /* Next block with the same parent. */ 00409 struct debug_block *next; 00410 /* Parent block. */ 00411 struct debug_block *parent; 00412 /* List of child blocks. */ 00413 struct debug_block *children; 00414 /* Start address of the block. */ 00415 bfd_vma start; 00416 /* End address of the block. */ 00417 bfd_vma end; 00418 /* Local variables. */ 00419 struct debug_namespace *locals; 00420 }; 00421 00422 /* Line number information we keep for a compilation unit. FIXME: 00423 This structure is easy to create, but can be very space 00424 inefficient. */ 00425 00426 struct debug_lineno 00427 { 00428 /* More line number information for this block. */ 00429 struct debug_lineno *next; 00430 /* Source file. */ 00431 struct debug_file *file; 00432 /* Line numbers, terminated by a -1 or the end of the array. */ 00433 #define DEBUG_LINENO_COUNT 10 00434 unsigned long linenos[DEBUG_LINENO_COUNT]; 00435 /* Addresses for the line numbers. */ 00436 bfd_vma addrs[DEBUG_LINENO_COUNT]; 00437 }; 00438 00439 /* A namespace. This is a mapping from names to objects. FIXME: This 00440 should be implemented as a hash table. */ 00441 00442 struct debug_namespace 00443 { 00444 /* List of items in this namespace. */ 00445 struct debug_name *list; 00446 /* Pointer to where the next item in this namespace should go. */ 00447 struct debug_name **tail; 00448 }; 00449 00450 /* Kinds of objects that appear in a namespace. */ 00451 00452 enum debug_object_kind 00453 { 00454 /* A type. */ 00455 DEBUG_OBJECT_TYPE, 00456 /* A tagged type (really a different sort of namespace). */ 00457 DEBUG_OBJECT_TAG, 00458 /* A variable. */ 00459 DEBUG_OBJECT_VARIABLE, 00460 /* A function. */ 00461 DEBUG_OBJECT_FUNCTION, 00462 /* An integer constant. */ 00463 DEBUG_OBJECT_INT_CONSTANT, 00464 /* A floating point constant. */ 00465 DEBUG_OBJECT_FLOAT_CONSTANT, 00466 /* A typed constant. */ 00467 DEBUG_OBJECT_TYPED_CONSTANT 00468 }; 00469 00470 /* Linkage of an object that appears in a namespace. */ 00471 00472 enum debug_object_linkage 00473 { 00474 /* Local variable. */ 00475 DEBUG_LINKAGE_AUTOMATIC, 00476 /* Static--either file static or function static, depending upon the 00477 namespace is. */ 00478 DEBUG_LINKAGE_STATIC, 00479 /* Global. */ 00480 DEBUG_LINKAGE_GLOBAL, 00481 /* No linkage. */ 00482 DEBUG_LINKAGE_NONE 00483 }; 00484 00485 /* A name in a namespace. */ 00486 00487 struct debug_name 00488 { 00489 /* Next name in this namespace. */ 00490 struct debug_name *next; 00491 /* Name. */ 00492 const char *name; 00493 /* Mark. This is used by debug_write. */ 00494 unsigned int mark; 00495 /* Kind of object. */ 00496 enum debug_object_kind kind; 00497 /* Linkage of object. */ 00498 enum debug_object_linkage linkage; 00499 /* Tagged union with additional information about the object. */ 00500 union 00501 { 00502 /* DEBUG_OBJECT_TYPE. */ 00503 struct debug_type *type; 00504 /* DEBUG_OBJECT_TAG. */ 00505 struct debug_type *tag; 00506 /* DEBUG_OBJECT_VARIABLE. */ 00507 struct debug_variable *variable; 00508 /* DEBUG_OBJECT_FUNCTION. */ 00509 struct debug_function *function; 00510 /* DEBUG_OBJECT_INT_CONSTANT. */ 00511 bfd_vma int_constant; 00512 /* DEBUG_OBJECT_FLOAT_CONSTANT. */ 00513 double float_constant; 00514 /* DEBUG_OBJECT_TYPED_CONSTANT. */ 00515 struct debug_typed_constant *typed_constant; 00516 } u; 00517 }; 00518 00519 /* During debug_write, a linked list of these structures is used to 00520 keep track of ID numbers that have been assigned to classes. */ 00521 00522 struct debug_class_id 00523 { 00524 /* Next ID number. */ 00525 struct debug_class_id *next; 00526 /* The type with the ID. */ 00527 struct debug_type *type; 00528 /* The tag; NULL if no tag. */ 00529 const char *tag; 00530 }; 00531 00532 /* During debug_type_samep, a linked list of these structures is kept 00533 on the stack to avoid infinite recursion. */ 00534 00535 struct debug_type_compare_list 00536 { 00537 /* Next type on list. */ 00538 struct debug_type_compare_list *next; 00539 /* The types we are comparing. */ 00540 struct debug_type *t1; 00541 struct debug_type *t2; 00542 }; 00543 00544 /* Local functions. */ 00545 00546 static void debug_error PARAMS ((const char *)); 00547 static struct debug_name *debug_add_to_namespace 00548 PARAMS ((struct debug_handle *, struct debug_namespace **, const char *, 00549 enum debug_object_kind, enum debug_object_linkage)); 00550 static struct debug_name *debug_add_to_current_namespace 00551 PARAMS ((struct debug_handle *, const char *, enum debug_object_kind, 00552 enum debug_object_linkage)); 00553 static struct debug_type *debug_make_type 00554 PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int)); 00555 static struct debug_type *debug_get_real_type PARAMS ((PTR, debug_type)); 00556 static boolean debug_write_name 00557 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, 00558 struct debug_name *)); 00559 static boolean debug_write_type 00560 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, 00561 struct debug_type *, struct debug_name *)); 00562 static boolean debug_write_class_type 00563 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, 00564 struct debug_type *, const char *)); 00565 static boolean debug_write_function 00566 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, 00567 const char *, enum debug_object_linkage, struct debug_function *)); 00568 static boolean debug_write_block 00569 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, 00570 struct debug_block *)); 00571 static boolean debug_write_linenos 00572 PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, 00573 bfd_vma)); 00574 static boolean debug_set_class_id 00575 PARAMS ((struct debug_handle *, const char *, struct debug_type *)); 00576 static boolean debug_type_samep 00577 PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *)); 00578 static boolean debug_class_type_samep 00579 PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *)); 00580 00581 /* Issue an error message. */ 00582 00583 static void 00584 debug_error (message) 00585 const char *message; 00586 { 00587 fprintf (stderr, "%s\n", message); 00588 } 00589 00590 /* Add an object to a namespace. */ 00591 00592 static struct debug_name * 00593 debug_add_to_namespace (info, nsp, name, kind, linkage) 00594 struct debug_handle *info; 00595 struct debug_namespace **nsp; 00596 const char *name; 00597 enum debug_object_kind kind; 00598 enum debug_object_linkage linkage; 00599 { 00600 struct debug_name *n; 00601 struct debug_namespace *ns; 00602 00603 n = (struct debug_name *) xmalloc (sizeof *n); 00604 memset (n, 0, sizeof *n); 00605 00606 n->name = name; 00607 n->kind = kind; 00608 n->linkage = linkage; 00609 00610 ns = *nsp; 00611 if (ns == NULL) 00612 { 00613 ns = (struct debug_namespace *) xmalloc (sizeof *ns); 00614 memset (ns, 0, sizeof *ns); 00615 00616 ns->tail = &ns->list; 00617 00618 *nsp = ns; 00619 } 00620 00621 *ns->tail = n; 00622 ns->tail = &n->next; 00623 00624 return n; 00625 } 00626 00627 /* Add an object to the current namespace. */ 00628 00629 static struct debug_name * 00630 debug_add_to_current_namespace (info, name, kind, linkage) 00631 struct debug_handle *info; 00632 const char *name; 00633 enum debug_object_kind kind; 00634 enum debug_object_linkage linkage; 00635 { 00636 struct debug_namespace **nsp; 00637 00638 if (info->current_unit == NULL 00639 || info->current_file == NULL) 00640 { 00641 debug_error ("debug_add_to_current_namespace: no current file"); 00642 return NULL; 00643 } 00644 00645 if (info->current_block != NULL) 00646 nsp = &info->current_block->locals; 00647 else 00648 nsp = &info->current_file->globals; 00649 00650 return debug_add_to_namespace (info, nsp, name, kind, linkage); 00651 } 00652 00653 /* Return a handle for debugging information. */ 00654 00655 PTR 00656 debug_init () 00657 { 00658 struct debug_handle *ret; 00659 00660 ret = (struct debug_handle *) xmalloc (sizeof *ret); 00661 memset (ret, 0, sizeof *ret); 00662 return (PTR) ret; 00663 } 00664 00665 /* Set the source filename. This implicitly starts a new compilation 00666 unit. */ 00667 00668 boolean 00669 debug_set_filename (handle, name) 00670 PTR handle; 00671 const char *name; 00672 { 00673 struct debug_handle *info = (struct debug_handle *) handle; 00674 struct debug_file *nfile; 00675 struct debug_unit *nunit; 00676 00677 if (name == NULL) 00678 name = ""; 00679 00680 nfile = (struct debug_file *) xmalloc (sizeof *nfile); 00681 memset (nfile, 0, sizeof *nfile); 00682 00683 nfile->filename = name; 00684 00685 nunit = (struct debug_unit *) xmalloc (sizeof *nunit); 00686 memset (nunit, 0, sizeof *nunit); 00687 00688 nunit->files = nfile; 00689 info->current_file = nfile; 00690 00691 if (info->current_unit != NULL) 00692 info->current_unit->next = nunit; 00693 else 00694 { 00695 assert (info->units == NULL); 00696 info->units = nunit; 00697 } 00698 00699 info->current_unit = nunit; 00700 00701 info->current_function = NULL; 00702 info->current_block = NULL; 00703 info->current_lineno = NULL; 00704 00705 return true; 00706 } 00707 00708 /* Change source files to the given file name. This is used for 00709 include files in a single compilation unit. */ 00710 00711 boolean 00712 debug_start_source (handle, name) 00713 PTR handle; 00714 const char *name; 00715 { 00716 struct debug_handle *info = (struct debug_handle *) handle; 00717 struct debug_file *f, **pf; 00718 00719 if (name == NULL) 00720 name = ""; 00721 00722 if (info->current_unit == NULL) 00723 { 00724 debug_error ("debug_start_source: no debug_set_filename call"); 00725 return false; 00726 } 00727 00728 for (f = info->current_unit->files; f != NULL; f = f->next) 00729 { 00730 if (f->filename[0] == name[0] 00731 && f->filename[1] == name[1] 00732 && strcmp (f->filename, name) == 0) 00733 { 00734 info->current_file = f; 00735 return true; 00736 } 00737 } 00738 00739 f = (struct debug_file *) xmalloc (sizeof *f); 00740 memset (f, 0, sizeof *f); 00741 00742 f->filename = name; 00743 00744 for (pf = &info->current_file->next; 00745 *pf != NULL; 00746 pf = &(*pf)->next) 00747 ; 00748 *pf = f; 00749 00750 info->current_file = f; 00751 00752 return true; 00753 } 00754 00755 /* Record a function definition. This implicitly starts a function 00756 block. The debug_type argument is the type of the return value. 00757 The boolean indicates whether the function is globally visible. 00758 The bfd_vma is the address of the start of the function. Currently 00759 the parameter types are specified by calls to 00760 debug_record_parameter. FIXME: There is no way to specify nested 00761 functions. */ 00762 00763 boolean 00764 debug_record_function (handle, name, return_type, global, addr) 00765 PTR handle; 00766 const char *name; 00767 debug_type return_type; 00768 boolean global; 00769 bfd_vma addr; 00770 { 00771 struct debug_handle *info = (struct debug_handle *) handle; 00772 struct debug_function *f; 00773 struct debug_block *b; 00774 struct debug_name *n; 00775 00776 if (name == NULL) 00777 name = ""; 00778 if (return_type == NULL) 00779 return false; 00780 00781 if (info->current_unit == NULL) 00782 { 00783 debug_error ("debug_record_function: no debug_set_filename call"); 00784 return false; 00785 } 00786 00787 f = (struct debug_function *) xmalloc (sizeof *f); 00788 memset (f, 0, sizeof *f); 00789 00790 f->return_type = return_type; 00791 00792 b = (struct debug_block *) xmalloc (sizeof *b); 00793 memset (b, 0, sizeof *b); 00794 00795 b->start = addr; 00796 b->end = (bfd_vma) -1; 00797 00798 f->blocks = b; 00799 00800 info->current_function = f; 00801 info->current_block = b; 00802 00803 /* FIXME: If we could handle nested functions, this would be the 00804 place: we would want to use a different namespace. */ 00805 n = debug_add_to_namespace (info, 00806 &info->current_file->globals, 00807 name, 00808 DEBUG_OBJECT_FUNCTION, 00809 (global 00810 ? DEBUG_LINKAGE_GLOBAL 00811 : DEBUG_LINKAGE_STATIC)); 00812 if (n == NULL) 00813 return false; 00814 00815 n->u.function = f; 00816 00817 return true; 00818 } 00819 00820 /* Record a parameter for the current function. */ 00821 00822 boolean 00823 debug_record_parameter (handle, name, type, kind, val) 00824 PTR handle; 00825 const char *name; 00826 debug_type type; 00827 enum debug_parm_kind kind; 00828 bfd_vma val; 00829 { 00830 struct debug_handle *info = (struct debug_handle *) handle; 00831 struct debug_parameter *p, **pp; 00832 00833 if (name == NULL || type == NULL) 00834 return false; 00835 00836 if (info->current_unit == NULL 00837 || info->current_function == NULL) 00838 { 00839 debug_error ("debug_record_parameter: no current function"); 00840 return false; 00841 } 00842 00843 p = (struct debug_parameter *) xmalloc (sizeof *p); 00844 memset (p, 0, sizeof *p); 00845 00846 p->name = name; 00847 p->type = type; 00848 p->kind = kind; 00849 p->val = val; 00850 00851 for (pp = &info->current_function->parameters; 00852 *pp != NULL; 00853 pp = &(*pp)->next) 00854 ; 00855 *pp = p; 00856 00857 return true; 00858 } 00859 00860 /* End a function. FIXME: This should handle function nesting. */ 00861 00862 boolean 00863 debug_end_function (handle, addr) 00864 PTR handle; 00865 bfd_vma addr; 00866 { 00867 struct debug_handle *info = (struct debug_handle *) handle; 00868 00869 if (info->current_unit == NULL 00870 || info->current_block == NULL 00871 || info->current_function == NULL) 00872 { 00873 debug_error ("debug_end_function: no current function"); 00874 return false; 00875 } 00876 00877 if (info->current_block->parent != NULL) 00878 { 00879 debug_error ("debug_end_function: some blocks were not closed"); 00880 return false; 00881 } 00882 00883 info->current_block->end = addr; 00884 00885 info->current_function = NULL; 00886 info->current_block = NULL; 00887 00888 return true; 00889 } 00890 00891 /* Start a block in a function. All local information will be 00892 recorded in this block, until the matching call to debug_end_block. 00893 debug_start_block and debug_end_block may be nested. The bfd_vma 00894 argument is the address at which this block starts. */ 00895 00896 boolean 00897 debug_start_block (handle, addr) 00898 PTR handle; 00899 bfd_vma addr; 00900 { 00901 struct debug_handle *info = (struct debug_handle *) handle; 00902 struct debug_block *b, **pb; 00903 00904 /* We must always have a current block: debug_record_function sets 00905 one up. */ 00906 if (info->current_unit == NULL 00907 || info->current_block == NULL) 00908 { 00909 debug_error ("debug_start_block: no current block"); 00910 return false; 00911 } 00912 00913 b = (struct debug_block *) xmalloc (sizeof *b); 00914 memset (b, 0, sizeof *b); 00915 00916 b->parent = info->current_block; 00917 b->start = addr; 00918 b->end = (bfd_vma) -1; 00919 00920 /* This new block is a child of the current block. */ 00921 for (pb = &info->current_block->children; 00922 *pb != NULL; 00923 pb = &(*pb)->next) 00924 ; 00925 *pb = b; 00926 00927 info->current_block = b; 00928 00929 return true; 00930 } 00931 00932 /* Finish a block in a function. This matches the call to 00933 debug_start_block. The argument is the address at which this block 00934 ends. */ 00935 00936 boolean 00937 debug_end_block (handle, addr) 00938 PTR handle; 00939 bfd_vma addr; 00940 { 00941 struct debug_handle *info = (struct debug_handle *) handle; 00942 struct debug_block *parent; 00943 00944 if (info->current_unit == NULL 00945 || info->current_block == NULL) 00946 { 00947 debug_error ("debug_end_block: no current block"); 00948 return false; 00949 } 00950 00951 parent = info->current_block->parent; 00952 if (parent == NULL) 00953 { 00954 debug_error ("debug_end_block: attempt to close top level block"); 00955 return false; 00956 } 00957 00958 info->current_block->end = addr; 00959 00960 info->current_block = parent; 00961 00962 return true; 00963 } 00964 00965 /* Associate a line number in the current source file and function 00966 with a given address. */ 00967 00968 boolean 00969 debug_record_line (handle, lineno, addr) 00970 PTR handle; 00971 unsigned long lineno; 00972 bfd_vma addr; 00973 { 00974 struct debug_handle *info = (struct debug_handle *) handle; 00975 struct debug_lineno *l; 00976 unsigned int i; 00977 00978 if (info->current_unit == NULL) 00979 { 00980 debug_error ("debug_record_line: no current unit"); 00981 return false; 00982 } 00983 00984 l = info->current_lineno; 00985 if (l != NULL && l->file == info->current_file) 00986 { 00987 for (i = 0; i < DEBUG_LINENO_COUNT; i++) 00988 { 00989 if (l->linenos[i] == (unsigned long) -1) 00990 { 00991 l->linenos[i] = lineno; 00992 l->addrs[i] = addr; 00993 return true; 00994 } 00995 } 00996 } 00997 00998 /* If we get here, then either 1) there is no current_lineno 00999 structure, which means this is the first line number in this 01000 compilation unit, 2) the current_lineno structure is for a 01001 different file, or 3) the current_lineno structure is full. 01002 Regardless, we want to allocate a new debug_lineno structure, put 01003 it in the right place, and make it the new current_lineno 01004 structure. */ 01005 01006 l = (struct debug_lineno *) xmalloc (sizeof *l); 01007 memset (l, 0, sizeof *l); 01008 01009 l->file = info->current_file; 01010 l->linenos[0] = lineno; 01011 l->addrs[0] = addr; 01012 for (i = 1; i < DEBUG_LINENO_COUNT; i++) 01013 l->linenos[i] = (unsigned long) -1; 01014 01015 if (info->current_lineno != NULL) 01016 info->current_lineno->next = l; 01017 else 01018 info->current_unit->linenos = l; 01019 01020 info->current_lineno = l; 01021 01022 return true; 01023 } 01024 01025 /* Start a named common block. This is a block of variables that may 01026 move in memory. */ 01027 01028 boolean 01029 debug_start_common_block (handle, name) 01030 PTR handle; 01031 const char *name; 01032 { 01033 /* FIXME */ 01034 debug_error ("debug_start_common_block: not implemented"); 01035 return false; 01036 } 01037 01038 /* End a named common block. */ 01039 01040 boolean 01041 debug_end_common_block (handle, name) 01042 PTR handle; 01043 const char *name; 01044 { 01045 /* FIXME */ 01046 debug_error ("debug_end_common_block: not implemented"); 01047 return false; 01048 } 01049 01050 /* Record a named integer constant. */ 01051 01052 boolean 01053 debug_record_int_const (handle, name, val) 01054 PTR handle; 01055 const char *name; 01056 bfd_vma val; 01057 { 01058 struct debug_handle *info = (struct debug_handle *) handle; 01059 struct debug_name *n; 01060 01061 if (name == NULL) 01062 return false; 01063 01064 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT, 01065 DEBUG_LINKAGE_NONE); 01066 if (n == NULL) 01067 return false; 01068 01069 n->u.int_constant = val; 01070 01071 return true; 01072 } 01073 01074 /* Record a named floating point constant. */ 01075 01076 boolean 01077 debug_record_float_const (handle, name, val) 01078 PTR handle; 01079 const char *name; 01080 double val; 01081 { 01082 struct debug_handle *info = (struct debug_handle *) handle; 01083 struct debug_name *n; 01084 01085 if (name == NULL) 01086 return false; 01087 01088 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT, 01089 DEBUG_LINKAGE_NONE); 01090 if (n == NULL) 01091 return false; 01092 01093 n->u.float_constant = val; 01094 01095 return true; 01096 } 01097 01098 /* Record a typed constant with an integral value. */ 01099 01100 boolean 01101 debug_record_typed_const (handle, name, type, val) 01102 PTR handle; 01103 const char *name; 01104 debug_type type; 01105 bfd_vma val; 01106 { 01107 struct debug_handle *info = (struct debug_handle *) handle; 01108 struct debug_name *n; 01109 struct debug_typed_constant *tc; 01110 01111 if (name == NULL || type == NULL) 01112 return false; 01113 01114 n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT, 01115 DEBUG_LINKAGE_NONE); 01116 if (n == NULL) 01117 return false; 01118 01119 tc = (struct debug_typed_constant *) xmalloc (sizeof *tc); 01120 memset (tc, 0, sizeof *tc); 01121 01122 tc->type = type; 01123 tc->val = val; 01124 01125 n->u.typed_constant = tc; 01126 01127 return true; 01128 } 01129 01130 /* Record a label. */ 01131 01132 boolean 01133 debug_record_label (handle, name, type, addr) 01134 PTR handle; 01135 const char *name; 01136 debug_type type; 01137 bfd_vma addr; 01138 { 01139 /* FIXME. */ 01140 debug_error ("debug_record_label not implemented"); 01141 return false; 01142 } 01143 01144 /* Record a variable. */ 01145 01146 boolean 01147 debug_record_variable (handle, name, type, kind, val) 01148 PTR handle; 01149 const char *name; 01150 debug_type type; 01151 enum debug_var_kind kind; 01152 bfd_vma val; 01153 { 01154 struct debug_handle *info = (struct debug_handle *) handle; 01155 struct debug_namespace **nsp; 01156 enum debug_object_linkage linkage; 01157 struct debug_name *n; 01158 struct debug_variable *v; 01159 01160 if (name == NULL || type == NULL) 01161 return false; 01162 01163 if (info->current_unit == NULL 01164 || info->current_file == NULL) 01165 { 01166 debug_error ("debug_record_variable: no current file"); 01167 return false; 01168 } 01169 01170 if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC) 01171 { 01172 nsp = &info->current_file->globals; 01173 if (kind == DEBUG_GLOBAL) 01174 linkage = DEBUG_LINKAGE_GLOBAL; 01175 else 01176 linkage = DEBUG_LINKAGE_STATIC; 01177 } 01178 else 01179 { 01180 if (info->current_block == NULL) 01181 { 01182 debug_error ("debug_record_variable: no current block"); 01183 return false; 01184 } 01185 nsp = &info->current_block->locals; 01186 linkage = DEBUG_LINKAGE_AUTOMATIC; 01187 } 01188 01189 n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage); 01190 if (n == NULL) 01191 return false; 01192 01193 v = (struct debug_variable *) xmalloc (sizeof *v); 01194 memset (v, 0, sizeof *v); 01195 01196 v->kind = kind; 01197 v->type = type; 01198 v->val = val; 01199 01200 n->u.variable = v; 01201 01202 return true; 01203 } 01204 01205 /* Make a type with a given kind and size. */ 01206 01207 /*ARGSUSED*/ 01208 static struct debug_type * 01209 debug_make_type (info, kind, size) 01210 struct debug_handle *info; 01211 enum debug_type_kind kind; 01212 unsigned int size; 01213 { 01214 struct debug_type *t; 01215 01216 t = (struct debug_type *) xmalloc (sizeof *t); 01217 memset (t, 0, sizeof *t); 01218 01219 t->kind = kind; 01220 t->size = size; 01221 01222 return t; 01223 } 01224 01225 /* Make an indirect type which may be used as a placeholder for a type 01226 which is referenced before it is defined. */ 01227 01228 debug_type 01229 debug_make_indirect_type (handle, slot, tag) 01230 PTR handle; 01231 debug_type *slot; 01232 const char *tag; 01233 { 01234 struct debug_handle *info = (struct debug_handle *) handle; 01235 struct debug_type *t; 01236 struct debug_indirect_type *i; 01237 01238 t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0); 01239 if (t == NULL) 01240 return DEBUG_TYPE_NULL; 01241 01242 i = (struct debug_indirect_type *) xmalloc (sizeof *i); 01243 memset (i, 0, sizeof *i); 01244 01245 i->slot = slot; 01246 i->tag = tag; 01247 01248 t->u.kindirect = i; 01249 01250 return t; 01251 } 01252 01253 /* Make a void type. There is only one of these. */ 01254 01255 debug_type 01256 debug_make_void_type (handle) 01257 PTR handle; 01258 { 01259 struct debug_handle *info = (struct debug_handle *) handle; 01260 01261 return debug_make_type (info, DEBUG_KIND_VOID, 0); 01262 } 01263 01264 /* Make an integer type of a given size. The boolean argument is true 01265 if the integer is unsigned. */ 01266 01267 debug_type 01268 debug_make_int_type (handle, size, unsignedp) 01269 PTR handle; 01270 unsigned int size; 01271 boolean unsignedp; 01272 { 01273 struct debug_handle *info = (struct debug_handle *) handle; 01274 struct debug_type *t; 01275 01276 t = debug_make_type (info, DEBUG_KIND_INT, size); 01277 if (t == NULL) 01278 return DEBUG_TYPE_NULL; 01279 01280 t->u.kint = unsignedp; 01281 01282 return t; 01283 } 01284 01285 /* Make a floating point type of a given size. FIXME: On some 01286 platforms, like an Alpha, you probably need to be able to specify 01287 the format. */ 01288 01289 debug_type 01290 debug_make_float_type (handle, size) 01291 PTR handle; 01292 unsigned int size; 01293 { 01294 struct debug_handle *info = (struct debug_handle *) handle; 01295 01296 return debug_make_type (info, DEBUG_KIND_FLOAT, size); 01297 } 01298 01299 /* Make a boolean type of a given size. */ 01300 01301 debug_type 01302 debug_make_bool_type (handle, size) 01303 PTR handle; 01304 unsigned int size; 01305 { 01306 struct debug_handle *info = (struct debug_handle *) handle; 01307 01308 return debug_make_type (info, DEBUG_KIND_BOOL, size); 01309 } 01310 01311 /* Make a complex type of a given size. */ 01312 01313 debug_type 01314 debug_make_complex_type (handle, size) 01315 PTR handle; 01316 unsigned int size; 01317 { 01318 struct debug_handle *info = (struct debug_handle *) handle; 01319 01320 return debug_make_type (info, DEBUG_KIND_COMPLEX, size); 01321 } 01322 01323 /* Make a structure type. The second argument is true for a struct, 01324 false for a union. The third argument is the size of the struct. 01325 The fourth argument is a NULL terminated array of fields. */ 01326 01327 debug_type 01328 debug_make_struct_type (handle, structp, size, fields) 01329 PTR handle; 01330 boolean structp; 01331 bfd_vma size; 01332 debug_field *fields; 01333 { 01334 struct debug_handle *info = (struct debug_handle *) handle; 01335 struct debug_type *t; 01336 struct debug_class_type *c; 01337 01338 t = debug_make_type (info, 01339 structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION, 01340 size); 01341 if (t == NULL) 01342 return DEBUG_TYPE_NULL; 01343 01344 c = (struct debug_class_type *) xmalloc (sizeof *c); 01345 memset (c, 0, sizeof *c); 01346 01347 c->fields = fields; 01348 01349 t->u.kclass = c; 01350 01351 return t; 01352 } 01353 01354 /* Make an object type. The first three arguments after the handle 01355 are the same as for debug_make_struct_type. The next arguments are 01356 a NULL terminated array of base classes, a NULL terminated array of 01357 methods, the type of the object holding the virtual function table 01358 if it is not this object, and a boolean which is true if this 01359 object has its own virtual function table. */ 01360 01361 debug_type 01362 debug_make_object_type (handle, structp, size, fields, baseclasses, 01363 methods, vptrbase, ownvptr) 01364 PTR handle; 01365 boolean structp; 01366 bfd_vma size; 01367 debug_field *fields; 01368 debug_baseclass *baseclasses; 01369 debug_method *methods; 01370 debug_type vptrbase; 01371 boolean ownvptr; 01372 { 01373 struct debug_handle *info = (struct debug_handle *) handle; 01374 struct debug_type *t; 01375 struct debug_class_type *c; 01376 01377 t = debug_make_type (info, 01378 structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS, 01379 size); 01380 if (t == NULL) 01381 return DEBUG_TYPE_NULL; 01382 01383 c = (struct debug_class_type *) xmalloc (sizeof *c); 01384 memset (c, 0, sizeof *c); 01385 01386 c->fields = fields; 01387 c->baseclasses = baseclasses; 01388 c->methods = methods; 01389 if (ownvptr) 01390 c->vptrbase = t; 01391 else 01392 c->vptrbase = vptrbase; 01393 01394 t->u.kclass = c; 01395 01396 return t; 01397 } 01398 01399 /* Make an enumeration type. The arguments are a null terminated 01400 array of strings, and an array of corresponding values. */ 01401 01402 debug_type 01403 debug_make_enum_type (handle, names, values) 01404 PTR handle; 01405 const char **names; 01406 bfd_signed_vma *values; 01407 { 01408 struct debug_handle *info = (struct debug_handle *) handle; 01409 struct debug_type *t; 01410 struct debug_enum_type *e; 01411 01412 t = debug_make_type (info, DEBUG_KIND_ENUM, 0); 01413 if (t == NULL) 01414 return DEBUG_TYPE_NULL; 01415 01416 e = (struct debug_enum_type *) xmalloc (sizeof *e); 01417 memset (e, 0, sizeof *e); 01418 01419 e->names = names; 01420 e->values = values; 01421 01422 t->u.kenum = e; 01423 01424 return t; 01425 } 01426 01427 /* Make a pointer to a given type. */ 01428 01429 debug_type 01430 debug_make_pointer_type (handle, type) 01431 PTR handle; 01432 debug_type type; 01433 { 01434 struct debug_handle *info = (struct debug_handle *) handle; 01435 struct debug_type *t; 01436 01437 if (type == NULL) 01438 return DEBUG_TYPE_NULL; 01439 01440 if (type->pointer != DEBUG_TYPE_NULL) 01441 return type->pointer; 01442 01443 t = debug_make_type (info, DEBUG_KIND_POINTER, 0); 01444 if (t == NULL) 01445 return DEBUG_TYPE_NULL; 01446 01447 t->u.kpointer = type; 01448 01449 type->pointer = t; 01450 01451 return t; 01452 } 01453 01454 /* Make a function returning a given type. FIXME: We should be able 01455 to record the parameter types. */ 01456 01457 debug_type 01458 debug_make_function_type (handle, type, arg_types, varargs) 01459 PTR handle; 01460 debug_type type; 01461 debug_type *arg_types; 01462 boolean varargs; 01463 { 01464 struct debug_handle *info = (struct debug_handle *) handle; 01465 struct debug_type *t; 01466 struct debug_function_type *f; 01467 01468 if (type == NULL) 01469 return DEBUG_TYPE_NULL; 01470 01471 t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0); 01472 if (t == NULL) 01473 return DEBUG_TYPE_NULL; 01474 01475 f = (struct debug_function_type *) xmalloc (sizeof *f); 01476 memset (f, 0, sizeof *f); 01477 01478 f->return_type = type; 01479 f->arg_types = arg_types; 01480 f->varargs = varargs; 01481 01482 t->u.kfunction = f; 01483 01484 return t; 01485 } 01486 01487 /* Make a reference to a given type. */ 01488 01489 debug_type 01490 debug_make_reference_type (handle, type) 01491 PTR handle; 01492 debug_type type; 01493 { 01494 struct debug_handle *info = (struct debug_handle *) handle; 01495 struct debug_type *t; 01496 01497 if (type == NULL) 01498 return DEBUG_TYPE_NULL; 01499 01500 t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0); 01501 if (t == NULL) 01502 return DEBUG_TYPE_NULL; 01503 01504 t->u.kreference = type; 01505 01506 return t; 01507 } 01508 01509 /* Make a range of a given type from a lower to an upper bound. */ 01510 01511 debug_type 01512 debug_make_range_type (handle, type, lower, upper) 01513 PTR handle; 01514 debug_type type; 01515 bfd_signed_vma lower; 01516 bfd_signed_vma upper; 01517 { 01518 struct debug_handle *info = (struct debug_handle *) handle; 01519 struct debug_type *t; 01520 struct debug_range_type *r; 01521 01522 if (type == NULL) 01523 return DEBUG_TYPE_NULL; 01524 01525 t = debug_make_type (info, DEBUG_KIND_RANGE, 0); 01526 if (t == NULL) 01527 return DEBUG_TYPE_NULL; 01528 01529 r = (struct debug_range_type *) xmalloc (sizeof *r); 01530 memset (r, 0, sizeof *r); 01531 01532 r->type = type; 01533 r->lower = lower; 01534 r->upper = upper; 01535 01536 t->u.krange = r; 01537 01538 return t; 01539 } 01540 01541 /* Make an array type. The second argument is the type of an element 01542 of the array. The third argument is the type of a range of the 01543 array. The fourth and fifth argument are the lower and upper 01544 bounds, respectively. The sixth argument is true if this array is 01545 actually a string, as in C. */ 01546 01547 debug_type 01548 debug_make_array_type (handle, element_type, range_type, lower, upper, 01549 stringp) 01550 PTR handle; 01551 debug_type element_type; 01552 debug_type range_type; 01553 bfd_signed_vma lower; 01554 bfd_signed_vma upper; 01555 boolean stringp; 01556 { 01557 struct debug_handle *info = (struct debug_handle *) handle; 01558 struct debug_type *t; 01559 struct debug_array_type *a; 01560 01561 if (element_type == NULL || range_type == NULL) 01562 return DEBUG_TYPE_NULL; 01563 01564 t = debug_make_type (info, DEBUG_KIND_ARRAY, 0); 01565 if (t == NULL) 01566 return DEBUG_TYPE_NULL; 01567 01568 a = (struct debug_array_type *) xmalloc (sizeof *a); 01569 memset (a, 0, sizeof *a); 01570 01571 a->element_type = element_type; 01572 a->range_type = range_type; 01573 a->lower = lower; 01574 a->upper = upper; 01575 a->stringp = stringp; 01576 01577 t->u.karray = a; 01578 01579 return t; 01580 } 01581 01582 /* Make a set of a given type. For example, a Pascal set type. The 01583 boolean argument is true if this set is actually a bitstring, as in 01584 CHILL. */ 01585 01586 debug_type 01587 debug_make_set_type (handle, type, bitstringp) 01588 PTR handle; 01589 debug_type type; 01590 boolean bitstringp; 01591 { 01592 struct debug_handle *info = (struct debug_handle *) handle; 01593 struct debug_type *t; 01594 struct debug_set_type *s; 01595 01596 if (type == NULL) 01597 return DEBUG_TYPE_NULL; 01598 01599 t = debug_make_type (info, DEBUG_KIND_SET, 0); 01600 if (t == NULL) 01601 return DEBUG_TYPE_NULL; 01602 01603 s = (struct debug_set_type *) xmalloc (sizeof *s); 01604 memset (s, 0, sizeof *s); 01605 01606 s->type = type; 01607 s->bitstringp = bitstringp; 01608 01609 t->u.kset = s; 01610 01611 return t; 01612 } 01613 01614 /* Make a type for a pointer which is relative to an object. The 01615 second argument is the type of the object to which the pointer is 01616 relative. The third argument is the type that the pointer points 01617 to. */ 01618 01619 debug_type 01620 debug_make_offset_type (handle, base_type, target_type) 01621 PTR handle; 01622 debug_type base_type; 01623 debug_type target_type; 01624 { 01625 struct debug_handle *info = (struct debug_handle *) handle; 01626 struct debug_type *t; 01627 struct debug_offset_type *o; 01628 01629 if (base_type == NULL || target_type == NULL) 01630 return DEBUG_TYPE_NULL; 01631 01632 t = debug_make_type (info, DEBUG_KIND_OFFSET, 0); 01633 if (t == NULL) 01634 return DEBUG_TYPE_NULL; 01635 01636 o = (struct debug_offset_type *) xmalloc (sizeof *o); 01637 memset (o, 0, sizeof *o); 01638 01639 o->base_type = base_type; 01640 o->target_type = target_type; 01641 01642 t->u.koffset = o; 01643 01644 return t; 01645 } 01646 01647 /* Make a type for a method function. The second argument is the 01648 return type, the third argument is the domain, and the fourth 01649 argument is a NULL terminated array of argument types. */ 01650 01651 debug_type 01652 debug_make_method_type (handle, return_type, domain_type, arg_types, varargs) 01653 PTR handle; 01654 debug_type return_type; 01655 debug_type domain_type; 01656 debug_type *arg_types; 01657 boolean varargs; 01658 { 01659 struct debug_handle *info = (struct debug_handle *) handle; 01660 struct debug_type *t; 01661 struct debug_method_type *m; 01662 01663 if (return_type == NULL) 01664 return DEBUG_TYPE_NULL; 01665 01666 t = debug_make_type (info, DEBUG_KIND_METHOD, 0); 01667 if (t == NULL) 01668 return DEBUG_TYPE_NULL; 01669 01670 m = (struct debug_method_type *) xmalloc (sizeof *m); 01671 memset (m, 0, sizeof *m); 01672 01673 m->return_type = return_type; 01674 m->domain_type = domain_type; 01675 m->arg_types = arg_types; 01676 m->varargs = varargs; 01677 01678 t->u.kmethod = m; 01679 01680 return t; 01681 } 01682 01683 /* Make a const qualified version of a given type. */ 01684 01685 debug_type 01686 debug_make_const_type (handle, type) 01687 PTR handle; 01688 debug_type type; 01689 { 01690 struct debug_handle *info = (struct debug_handle *) handle; 01691 struct debug_type *t; 01692 01693 if (type == NULL) 01694 return DEBUG_TYPE_NULL; 01695 01696 t = debug_make_type (info, DEBUG_KIND_CONST, 0); 01697 if (t == NULL) 01698 return DEBUG_TYPE_NULL; 01699 01700 t->u.kconst = type; 01701 01702 return t; 01703 } 01704 01705 /* Make a volatile qualified version of a given type. */ 01706 01707 debug_type 01708 debug_make_volatile_type (handle, type) 01709 PTR handle; 01710 debug_type type; 01711 { 01712 struct debug_handle *info = (struct debug_handle *) handle; 01713 struct debug_type *t; 01714 01715 if (type == NULL) 01716 return DEBUG_TYPE_NULL; 01717 01718 t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0); 01719 if (t == NULL) 01720 return DEBUG_TYPE_NULL; 01721 01722 t->u.kvolatile = type; 01723 01724 return t; 01725 } 01726 01727 /* Make an undefined tagged type. For example, a struct which has 01728 been mentioned, but not defined. */ 01729 01730 debug_type 01731 debug_make_undefined_tagged_type (handle, name, kind) 01732 PTR handle; 01733 const char *name; 01734 enum debug_type_kind kind; 01735 { 01736 struct debug_handle *info = (struct debug_handle *) handle; 01737 struct debug_type *t; 01738 01739 if (name == NULL) 01740 return DEBUG_TYPE_NULL; 01741 01742 switch (kind) 01743 { 01744 case DEBUG_KIND_STRUCT: 01745 case DEBUG_KIND_UNION: 01746 case DEBUG_KIND_CLASS: 01747 case DEBUG_KIND_UNION_CLASS: 01748 case DEBUG_KIND_ENUM: 01749 break; 01750 01751 default: 01752 debug_error ("debug_make_undefined_type: unsupported kind"); 01753 return DEBUG_TYPE_NULL; 01754 } 01755 01756 t = debug_make_type (info, kind, 0); 01757 if (t == NULL) 01758 return DEBUG_TYPE_NULL; 01759 01760 return debug_tag_type (handle, name, t); 01761 } 01762 01763 /* Make a base class for an object. The second argument is the base 01764 class type. The third argument is the bit position of this base 01765 class in the object (always 0 unless doing multiple inheritance). 01766 The fourth argument is whether this is a virtual class. The fifth 01767 argument is the visibility of the base class. */ 01768 01769 /*ARGSUSED*/ 01770 debug_baseclass 01771 debug_make_baseclass (handle, type, bitpos, virtual, visibility) 01772 PTR handle; 01773 debug_type type; 01774 bfd_vma bitpos; 01775 boolean virtual; 01776 enum debug_visibility visibility; 01777 { 01778 struct debug_baseclass *b; 01779 01780 b = (struct debug_baseclass *) xmalloc (sizeof *b); 01781 memset (b, 0, sizeof *b); 01782 01783 b->type = type; 01784 b->bitpos = bitpos; 01785 b->virtual = virtual; 01786 b->visibility = visibility; 01787 01788 return b; 01789 } 01790 01791 /* Make a field for a struct. The second argument is the name. The 01792 third argument is the type of the field. The fourth argument is 01793 the bit position of the field. The fifth argument is the size of 01794 the field (it may be zero). The sixth argument is the visibility 01795 of the field. */ 01796 01797 /*ARGSUSED*/ 01798 debug_field 01799 debug_make_field (handle, name, type, bitpos, bitsize, visibility) 01800 PTR handle; 01801 const char *name; 01802 debug_type type; 01803 bfd_vma bitpos; 01804 bfd_vma bitsize; 01805 enum debug_visibility visibility; 01806 { 01807 struct debug_field *f; 01808 01809 f = (struct debug_field *) xmalloc (sizeof *f); 01810 memset (f, 0, sizeof *f); 01811 01812 f->name = name; 01813 f->type = type; 01814 f->static_member = false; 01815 f->u.f.bitpos = bitpos; 01816 f->u.f.bitsize = bitsize; 01817 f->visibility = visibility; 01818 01819 return f; 01820 } 01821 01822 /* Make a static member of an object. The second argument is the 01823 name. The third argument is the type of the member. The fourth 01824 argument is the physical name of the member (i.e., the name as a 01825 global variable). The fifth argument is the visibility of the 01826 member. */ 01827 01828 /*ARGSUSED*/ 01829 debug_field 01830 debug_make_static_member (handle, name, type, physname, visibility) 01831 PTR handle; 01832 const char *name; 01833 debug_type type; 01834 const char *physname; 01835 enum debug_visibility visibility; 01836 { 01837 struct debug_field *f; 01838 01839 f = (struct debug_field *) xmalloc (sizeof *f); 01840 memset (f, 0, sizeof *f); 01841 01842 f->name = name; 01843 f->type = type; 01844 f->static_member = true; 01845 f->u.s.physname = physname; 01846 f->visibility = visibility; 01847 01848 return f; 01849 } 01850 01851 /* Make a method. The second argument is the name, and the third 01852 argument is a NULL terminated array of method variants. */ 01853 01854 /*ARGSUSED*/ 01855 debug_method 01856 debug_make_method (handle, name, variants) 01857 PTR handle; 01858 const char *name; 01859 debug_method_variant *variants; 01860 { 01861 struct debug_method *m; 01862 01863 m = (struct debug_method *) xmalloc (sizeof *m); 01864 memset (m, 0, sizeof *m); 01865 01866 m->name = name; 01867 m->variants = variants; 01868 01869 return m; 01870 } 01871 01872 /* Make a method argument. The second argument is the real name of 01873 the function. The third argument is the type of the function. The 01874 fourth argument is the visibility. The fifth argument is whether 01875 this is a const function. The sixth argument is whether this is a 01876 volatile function. The seventh argument is the offset in the 01877 virtual function table, if any. The eighth argument is the virtual 01878 function context. FIXME: Are the const and volatile arguments 01879 necessary? Could we just use debug_make_const_type? */ 01880 01881 /*ARGSUSED*/ 01882 debug_method_variant 01883 debug_make_method_variant (handle, physname, type, visibility, constp, 01884 volatilep, voffset, context) 01885 PTR handle; 01886 const char *physname; 01887 debug_type type; 01888 enum debug_visibility visibility; 01889 boolean constp; 01890 boolean volatilep; 01891 bfd_vma voffset; 01892 debug_type context; 01893 { 01894 struct debug_method_variant *m; 01895 01896 m = (struct debug_method_variant *) xmalloc (sizeof *m); 01897 memset (m, 0, sizeof *m); 01898 01899 m->physname = physname; 01900 m->type = type; 01901 m->visibility = visibility; 01902 m->constp = constp; 01903 m->volatilep = volatilep; 01904 m->voffset = voffset; 01905 m->context = context; 01906 01907 return m; 01908 } 01909 01910 /* Make a static method argument. The arguments are the same as for 01911 debug_make_method_variant, except that the last two are omitted 01912 since a static method can not also be virtual. */ 01913 01914 debug_method_variant 01915 debug_make_static_method_variant (handle, physname, type, visibility, 01916 constp, volatilep) 01917 PTR handle; 01918 const char *physname; 01919 debug_type type; 01920 enum debug_visibility visibility; 01921 boolean constp; 01922 boolean volatilep; 01923 { 01924 struct debug_method_variant *m; 01925 01926 m = (struct debug_method_variant *) xmalloc (sizeof *m); 01927 memset (m, 0, sizeof *m); 01928 01929 m->physname = physname; 01930 m->type = type; 01931 m->visibility = visibility; 01932 m->constp = constp; 01933 m->volatilep = volatilep; 01934 m->voffset = VOFFSET_STATIC_METHOD; 01935 01936 return m; 01937 } 01938 01939 /* Name a type. */ 01940 01941 debug_type 01942 debug_name_type (handle, name, type) 01943 PTR handle; 01944 const char *name; 01945 debug_type type; 01946 { 01947 struct debug_handle *info = (struct debug_handle *) handle; 01948 struct debug_type *t; 01949 struct debug_named_type *n; 01950 struct debug_name *nm; 01951 01952 if (name == NULL || type == NULL) 01953 return DEBUG_TYPE_NULL; 01954 01955 if (info->current_unit == NULL 01956 || info->current_file == NULL) 01957 { 01958 debug_error ("debug_name_type: no current file"); 01959 return DEBUG_TYPE_NULL; 01960 /* return false; */ 01961 } 01962 01963 t = debug_make_type (info, DEBUG_KIND_NAMED, 0); 01964 if (t == NULL) 01965 return DEBUG_TYPE_NULL; 01966 01967 n = (struct debug_named_type *) xmalloc (sizeof *n); 01968 memset (n, 0, sizeof *n); 01969 01970 n->type = type; 01971 01972 t->u.knamed = n; 01973 01974 /* We always add the name to the global namespace. This is probably 01975 wrong in some cases, but it seems to be right for stabs. FIXME. */ 01976 01977 nm = debug_add_to_namespace (info, &info->current_file->globals, name, 01978 DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE); 01979 if (nm == NULL) 01980 return DEBUG_TYPE_NULL; 01981 01982 nm->u.type = t; 01983 01984 n->name = nm; 01985 01986 return t; 01987 } 01988 01989 /* Tag a type. */ 01990 01991 debug_type 01992 debug_tag_type (handle, name, type) 01993 PTR handle; 01994 const char *name; 01995 debug_type type; 01996 { 01997 struct debug_handle *info = (struct debug_handle *) handle; 01998 struct debug_type *t; 01999 struct debug_named_type *n; 02000 struct debug_name *nm; 02001 02002 if (name == NULL || type == NULL) 02003 return DEBUG_TYPE_NULL; 02004 02005 if (info->current_file == NULL) 02006 { 02007 debug_error ("debug_tag_type: no current file"); 02008 return DEBUG_TYPE_NULL; 02009 } 02010 02011 if (type->kind == DEBUG_KIND_TAGGED) 02012 { 02013 if (strcmp (type->u.knamed->name->name, name) == 0) 02014 return type; 02015 debug_error ("debug_tag_type: extra tag attempted"); 02016 return DEBUG_TYPE_NULL; 02017 } 02018 02019 t = debug_make_type (info, DEBUG_KIND_TAGGED, 0); 02020 if (t == NULL) 02021 return DEBUG_TYPE_NULL; 02022 02023 n = (struct debug_named_type *) xmalloc (sizeof *n); 02024 memset (n, 0, sizeof *n); 02025 02026 n->type = type; 02027 02028 t->u.knamed = n; 02029 02030 /* We keep a global namespace of tags for each compilation unit. I 02031 don't know if that is the right thing to do. */ 02032 02033 nm = debug_add_to_namespace (info, &info->current_file->globals, name, 02034 DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE); 02035 if (nm == NULL) 02036 return DEBUG_TYPE_NULL; 02037 02038 nm->u.tag = t; 02039 02040 n->name = nm; 02041 02042 return t; 02043 } 02044 02045 /* Record the size of a given type. */ 02046 02047 /*ARGSUSED*/ 02048 boolean 02049 debug_record_type_size (handle, type, size) 02050 PTR handle; 02051 debug_type type; 02052 unsigned int size; 02053 { 02054 #if 0 02055 if (type->size != 0 && type->size != size) 02056 fprintf (stderr, "Warning: changing type size from %d to %d\n", 02057 type->size, size); 02058 #endif 02059 02060 type->size = size; 02061 02062 return true; 02063 } 02064 02065 /* Find a named type. */ 02066 02067 debug_type 02068 debug_find_named_type (handle, name) 02069 PTR handle; 02070 const char *name; 02071 { 02072 struct debug_handle *info = (struct debug_handle *) handle; 02073 struct debug_block *b; 02074 struct debug_file *f; 02075 02076 /* We only search the current compilation unit. I don't know if 02077 this is right or not. */ 02078 02079 if (info->current_unit == NULL) 02080 { 02081 debug_error ("debug_find_named_type: no current compilation unit"); 02082 return DEBUG_TYPE_NULL; 02083 } 02084 02085 for (b = info->current_block; b != NULL; b = b->parent) 02086 { 02087 if (b->locals != NULL) 02088 { 02089 struct debug_name *n; 02090 02091 for (n = b->locals->list; n != NULL; n = n->next) 02092 { 02093 if (n->kind == DEBUG_OBJECT_TYPE 02094 && n->name[0] == name[0] 02095 && strcmp (n->name, name) == 0) 02096 return n->u.type; 02097 } 02098 } 02099 } 02100 02101 for (f = info->current_unit->files; f != NULL; f = f->next) 02102 { 02103 if (f->globals != NULL) 02104 { 02105 struct debug_name *n; 02106 02107 for (n = f->globals->list; n != NULL; n = n->next) 02108 { 02109 if (n->kind == DEBUG_OBJECT_TYPE 02110 && n->name[0] == name[0] 02111 && strcmp (n->name, name) == 0) 02112 return n->u.type; 02113 } 02114 } 02115 } 02116 02117 return DEBUG_TYPE_NULL; 02118 } 02119 02120 /* Find a tagged type. */ 02121 02122 debug_type 02123 debug_find_tagged_type (handle, name, kind) 02124 PTR handle; 02125 const char *name; 02126 enum debug_type_kind kind; 02127 { 02128 struct debug_handle *info = (struct debug_handle *) handle; 02129 struct debug_unit *u; 02130 02131 /* We search the globals of all the compilation units. I don't know 02132 if this is correct or not. It would be easy to change. */ 02133 02134 for (u = info->units; u != NULL; u = u->next) 02135 { 02136 struct debug_file *f; 02137 02138 for (f = u->files; f != NULL; f = f->next) 02139 { 02140 struct debug_name *n; 02141 02142 if (f->globals != NULL) 02143 { 02144 for (n = f->globals->list; n != NULL; n = n->next) 02145 { 02146 if (n->kind == DEBUG_OBJECT_TAG 02147 && (kind == DEBUG_KIND_ILLEGAL 02148 || n->u.tag->kind == kind) 02149 && n->name[0] == name[0] 02150 && strcmp (n->name, name) == 0) 02151 return n->u.tag; 02152 } 02153 } 02154 } 02155 } 02156 02157 return DEBUG_TYPE_NULL; 02158 } 02159 02160 /* Get a base type. */ 02161 02162 static struct debug_type * 02163 debug_get_real_type (handle, type) 02164 PTR handle; 02165 debug_type type; 02166 { 02167 switch (type->kind) 02168 { 02169 default: 02170 return type; 02171 case DEBUG_KIND_INDIRECT: 02172 if (*type->u.kindirect->slot != NULL) 02173 return debug_get_real_type (handle, *type->u.kindirect->slot); 02174 return type; 02175 case DEBUG_KIND_NAMED: 02176 case DEBUG_KIND_TAGGED: 02177 return debug_get_real_type (handle, type->u.knamed->type); 02178 } 02179 /*NOTREACHED*/ 02180 } 02181 02182 /* Get the kind of a type. */ 02183 02184 enum debug_type_kind 02185 debug_get_type_kind (handle, type) 02186 PTR handle; 02187 debug_type type; 02188 { 02189 if (type == NULL) 02190 return DEBUG_KIND_ILLEGAL; 02191 type = debug_get_real_type (handle, type); 02192 return type->kind; 02193 } 02194 02195 /* Get the name of a type. */ 02196 02197 const char * 02198 debug_get_type_name (handle, type) 02199 PTR handle; 02200 debug_type type; 02201 { 02202 if (type->kind == DEBUG_KIND_INDIRECT) 02203 { 02204 if (*type->u.kindirect->slot != NULL) 02205 return debug_get_type_name (handle, *type->u.kindirect->slot); 02206 return type->u.kindirect->tag; 02207 } 02208 if (type->kind == DEBUG_KIND_NAMED 02209 || type->kind == DEBUG_KIND_TAGGED) 02210 return type->u.knamed->name->name; 02211 return NULL; 02212 } 02213 02214 /* Get the size of a type. */ 02215 02216 bfd_vma 02217 debug_get_type_size (handle, type) 02218 PTR handle; 02219 debug_type type; 02220 { 02221 if (type == NULL) 02222 return 0; 02223 02224 /* We don't call debug_get_real_type, because somebody might have 02225 called debug_record_type_size on a named or indirect type. */ 02226 02227 if (type->size != 0) 02228 return type->size; 02229 02230 switch (type->kind) 02231 { 02232 default: 02233 return 0; 02234 case DEBUG_KIND_INDIRECT: 02235 if (*type->u.kindirect->slot != NULL) 02236 return debug_get_type_size (handle, *type->u.kindirect->slot); 02237 return 0; 02238 case DEBUG_KIND_NAMED: 02239 case DEBUG_KIND_TAGGED: 02240 return debug_get_type_size (handle, type->u.knamed->type); 02241 } 02242 /*NOTREACHED*/ 02243 } 02244 02245 /* Get the return type of a function or method type. */ 02246 02247 debug_type 02248 debug_get_return_type (handle, type) 02249 PTR handle; 02250 debug_type type; 02251 { 02252 if (type == NULL) 02253 return DEBUG_TYPE_NULL; 02254 type = debug_get_real_type (handle, type); 02255 switch (type->kind) 02256 { 02257 default: 02258 return DEBUG_TYPE_NULL; 02259 case DEBUG_KIND_FUNCTION: 02260 return type->u.kfunction->return_type; 02261 case DEBUG_KIND_METHOD: 02262 return type->u.kmethod->return_type; 02263 } 02264 /*NOTREACHED*/ 02265 } 02266 02267 /* Get the parameter types of a function or method type (except that 02268 we don't currently store the parameter types of a function). */ 02269 02270 const debug_type * 02271 debug_get_parameter_types (handle, type, pvarargs) 02272 PTR handle; 02273 debug_type type; 02274 boolean *pvarargs; 02275 { 02276 if (type == NULL) 02277 return NULL; 02278 type = debug_get_real_type (handle, type); 02279 switch (type->kind) 02280 { 02281 default: 02282 return NULL; 02283 case DEBUG_KIND_FUNCTION: 02284 *pvarargs = type->u.kfunction->varargs; 02285 return type->u.kfunction->arg_types; 02286 case DEBUG_KIND_METHOD: 02287 *pvarargs = type->u.kmethod->varargs; 02288 return type->u.kmethod->arg_types; 02289 } 02290 /*NOTREACHED*/ 02291 } 02292 02293 /* Get the target type of a type. */ 02294 02295 debug_type 02296 debug_get_target_type (handle, type) 02297 PTR handle; 02298 debug_type type; 02299 { 02300 if (type == NULL) 02301 return NULL; 02302 type = debug_get_real_type (handle, type); 02303 switch (type->kind) 02304 { 02305 default: 02306 return NULL; 02307 case DEBUG_KIND_POINTER: 02308 return type->u.kpointer; 02309 case DEBUG_KIND_REFERENCE: 02310 return type->u.kreference; 02311 case DEBUG_KIND_CONST: 02312 return type->u.kconst; 02313 case DEBUG_KIND_VOLATILE: 02314 return type->u.kvolatile; 02315 } 02316 /*NOTREACHED*/ 02317 } 02318 02319 /* Get the NULL terminated array of fields for a struct, union, or 02320 class. */ 02321 02322 const debug_field * 02323 debug_get_fields (handle, type) 02324 PTR handle; 02325 debug_type type; 02326 { 02327 if (type == NULL) 02328 return NULL; 02329 type = debug_get_real_type (handle, type); 02330 switch (type->kind) 02331 { 02332 default: 02333 return NULL; 02334 case DEBUG_KIND_STRUCT: 02335 case DEBUG_KIND_UNION: 02336 case DEBUG_KIND_CLASS: 02337 case DEBUG_KIND_UNION_CLASS: 02338 return type->u.kclass->fields; 02339 } 02340 /*NOTREACHED*/ 02341 } 02342 02343 /* Get the type of a field. */ 02344 02345 /*ARGSUSED*/ 02346 debug_type 02347 debug_get_field_type (handle, field) 02348 PTR handle; 02349 debug_field field; 02350 { 02351 if (field == NULL) 02352 return NULL; 02353 return field->type; 02354 } 02355 02356 /* Get the name of a field. */ 02357 02358 /*ARGSUSED*/ 02359 const char * 02360 debug_get_field_name (handle, field) 02361 PTR handle; 02362 debug_field field; 02363 { 02364 if (field == NULL) 02365 return NULL; 02366 return field->name; 02367 } 02368 02369 /* Get the bit position of a field. */ 02370 02371 /*ARGSUSED*/ 02372 bfd_vma 02373 debug_get_field_bitpos (handle, field) 02374 PTR handle; 02375 debug_field field; 02376 { 02377 if (field == NULL || field->static_member) 02378 return (bfd_vma) -1; 02379 return field->u.f.bitpos; 02380 } 02381 02382 /* Get the bit size of a field. */ 02383 02384 /*ARGSUSED*/ 02385 bfd_vma 02386 debug_get_field_bitsize (handle, field) 02387 PTR handle; 02388 debug_field field; 02389 { 02390 if (field == NULL || field->static_member) 02391 return (bfd_vma) -1; 02392 return field->u.f.bitsize; 02393 } 02394 02395 /* Get the visibility of a field. */ 02396 02397 /*ARGSUSED*/ 02398 enum debug_visibility 02399 debug_get_field_visibility (handle, field) 02400 PTR handle; 02401 debug_field field; 02402 { 02403 if (field == NULL) 02404 return DEBUG_VISIBILITY_IGNORE; 02405 return field->visibility; 02406 } 02407 02408 /* Get the physical name of a field. */ 02409 02410 const char * 02411 debug_get_field_physname (handle, field) 02412 PTR handle; 02413 debug_field field; 02414 { 02415 if (field == NULL || ! field->static_member) 02416 return NULL; 02417 return field->u.s.physname; 02418 } 02419 02420 /* Write out the debugging information. This is given a handle to 02421 debugging information, and a set of function pointers to call. */ 02422 02423 boolean 02424 debug_write (handle, fns, fhandle) 02425 PTR handle; 02426 const struct debug_write_fns *fns; 02427 PTR fhandle; 02428 { 02429 struct debug_handle *info = (struct debug_handle *) handle; 02430 struct debug_unit *u; 02431 02432 /* We use a mark to tell whether we have already written out a 02433 particular name. We use an integer, so that we don't have to 02434 clear the mark fields if we happen to write out the same 02435 information more than once. */ 02436 ++info->mark; 02437 02438 /* The base_id field holds an ID value which will never be used, so 02439 that we can tell whether we have assigned an ID during this call 02440 to debug_write. */ 02441 info->base_id = info->class_id; 02442 02443 /* We keep a linked list of classes for which was have assigned ID's 02444 during this call to debug_write. */ 02445 info->id_list = NULL; 02446 02447 for (u = info->units; u != NULL; u = u->next) 02448 { 02449 struct debug_file *f; 02450 boolean first_file; 02451 02452 info->current_write_lineno = u->linenos; 02453 info->current_write_lineno_index = 0; 02454 02455 if (! (*fns->start_compilation_unit) (fhandle, u->files->filename)) 02456 return false; 02457 02458 first_file = true; 02459 for (f = u->files; f != NULL; f = f->next) 02460 { 02461 struct debug_name *n; 02462 02463 if (first_file) 02464 first_file = false; 02465 else 02466 { 02467 if (! (*fns->start_source) (fhandle, f->filename)) 02468 return false; 02469 } 02470 02471 if (f->globals != NULL) 02472 { 02473 for (n = f->globals->list; n != NULL; n = n->next) 02474 { 02475 if (! debug_write_name (info, fns, fhandle, n)) 02476 return false; 02477 } 02478 } 02479 } 02480 02481 /* Output any line number information which hasn't already been 02482 handled. */ 02483 if (! debug_write_linenos (info, fns, fhandle, (bfd_vma) -1)) 02484 return false; 02485 } 02486 02487 return true; 02488 } 02489 02490 /* Write out an element in a namespace. */ 02491 02492 static boolean 02493 debug_write_name (info, fns, fhandle, n) 02494 struct debug_handle *info; 02495 const struct debug_write_fns *fns; 02496 PTR fhandle; 02497 struct debug_name *n; 02498 { 02499 switch (n->kind) 02500 { 02501 case DEBUG_OBJECT_TYPE: 02502 if (! debug_write_type (info, fns, fhandle, n->u.type, n) 02503 || ! (*fns->typdef) (fhandle, n->name)) 02504 return false; 02505 return true; 02506 case DEBUG_OBJECT_TAG: 02507 if (! debug_write_type (info, fns, fhandle, n->u.tag, n)) 02508 return false; 02509 return (*fns->tag) (fhandle, n->name); 02510 case DEBUG_OBJECT_VARIABLE: 02511 if (! debug_write_type (info, fns, fhandle, n->u.variable->type, 02512 (struct debug_name *) NULL)) 02513 return false; 02514 return (*fns->variable) (fhandle, n->name, n->u.variable->kind, 02515 n->u.variable->val); 02516 case DEBUG_OBJECT_FUNCTION: 02517 return debug_write_function (info, fns, fhandle, n->name, 02518 n->linkage, n->u.function); 02519 case DEBUG_OBJECT_INT_CONSTANT: 02520 return (*fns->int_constant) (fhandle, n->name, n->u.int_constant); 02521 case DEBUG_OBJECT_FLOAT_CONSTANT: 02522 return (*fns->float_constant) (fhandle, n->name, n->u.float_constant); 02523 case DEBUG_OBJECT_TYPED_CONSTANT: 02524 if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type, 02525 (struct debug_name *) NULL)) 02526 return false; 02527 return (*fns->typed_constant) (fhandle, n->name, 02528 n->u.typed_constant->val); 02529 default: 02530 abort (); 02531 return false; 02532 } 02533 /*NOTREACHED*/ 02534 } 02535 02536 /* Write out a type. If the type is DEBUG_KIND_NAMED or 02537 DEBUG_KIND_TAGGED, then the name argument is the name for which we 02538 are about to call typedef or tag. If the type is anything else, 02539 then the name argument is a tag from a DEBUG_KIND_TAGGED type which 02540 points to this one. */ 02541 02542 static boolean 02543 debug_write_type (info, fns, fhandle, type, name) 02544 struct debug_handle *info; 02545 const struct debug_write_fns *fns; 02546 PTR fhandle; 02547 struct debug_type *type; 02548 struct debug_name *name; 02549 { 02550 unsigned int i; 02551 int is; 02552 const char *tag; 02553 02554 /* If we have a name for this type, just output it. We only output 02555 typedef names after they have been defined. We output type tags 02556 whenever we are not actually defining them. */ 02557 if ((type->kind == DEBUG_KIND_NAMED 02558 || type->kind == DEBUG_KIND_TAGGED) 02559 && (type->u.knamed->name->mark == info->mark 02560 || (type->kind == DEBUG_KIND_TAGGED 02561 && type->u.knamed->name != name))) 02562 { 02563 if (type->kind == DEBUG_KIND_NAMED) 02564 return (*fns->typedef_type) (fhandle, type->u.knamed->name->name); 02565 else 02566 { 02567 struct debug_type *real; 02568 unsigned int id; 02569 02570 real = debug_get_real_type ((PTR) info, type); 02571 id = 0; 02572 if ((real->kind == DEBUG_KIND_STRUCT 02573 || real->kind == DEBUG_KIND_UNION 02574 || real->kind == DEBUG_KIND_CLASS 02575 || real->kind == DEBUG_KIND_UNION_CLASS) 02576 && real->u.kclass != NULL) 02577 { 02578 if (real->u.kclass->id <= info->base_id) 02579 { 02580 if (! debug_set_class_id (info, 02581 type->u.knamed->name->name, 02582 real)) 02583 return false; 02584 } 02585 id = real->u.kclass->id; 02586 } 02587 02588 return (*fns->tag_type) (fhandle, type->u.knamed->name->name, id, 02589 real->kind); 02590 } 02591 } 02592 02593 /* Mark the name after we have already looked for a known name, so 02594 that we don't just define a type in terms of itself. We need to 02595 mark the name here so that a struct containing a pointer to 02596 itself will work. */ 02597 if (name != NULL) 02598 name->mark = info->mark; 02599 02600 tag = NULL; 02601 if (name != NULL 02602 && type->kind != DEBUG_KIND_NAMED 02603 && type->kind != DEBUG_KIND_TAGGED) 02604 { 02605 assert (name->kind == DEBUG_OBJECT_TAG); 02606 tag = name->name; 02607 } 02608 02609 switch (type->kind) 02610 { 02611 case DEBUG_KIND_ILLEGAL: 02612 debug_error ("debug_write_type: illegal type encountered"); 02613 return false; 02614 case DEBUG_KIND_INDIRECT: 02615 if (*type->u.kindirect->slot == DEBUG_TYPE_NULL) 02616 return (*fns->empty_type) (fhandle); 02617 return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot, 02618 name); 02619 case DEBUG_KIND_VOID: 02620 return (*fns->void_type) (fhandle); 02621 case DEBUG_KIND_INT: 02622 return (*fns->int_type) (fhandle, type->size, type->u.kint); 02623 case DEBUG_KIND_FLOAT: 02624 return (*fns->float_type) (fhandle, type->size); 02625 case DEBUG_KIND_COMPLEX: 02626 return (*fns->complex_type) (fhandle, type->size); 02627 case DEBUG_KIND_BOOL: 02628 return (*fns->bool_type) (fhandle, type->size); 02629 case DEBUG_KIND_STRUCT: 02630 case DEBUG_KIND_UNION: 02631 if (type->u.kclass != NULL) 02632 { 02633 if (type->u.kclass->id <= info->base_id) 02634 { 02635 if (! debug_set_class_id (info, tag, type)) 02636 return false; 02637 } 02638 02639 if (info->mark == type->u.kclass->mark) 02640 { 02641 /* We are currently outputting this struct, or we have 02642 already output it. I don't know if this can happen, 02643 but it can happen for a class. */ 02644 assert (type->u.kclass->id > info->base_id); 02645 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id, 02646 type->kind); 02647 } 02648 type->u.kclass->mark = info->mark; 02649 } 02650 02651 if (! (*fns->start_struct_type) (fhandle, tag, 02652 (type->u.kclass != NULL 02653 ? type->u.kclass->id 02654 : 0), 02655 type->kind == DEBUG_KIND_STRUCT, 02656 type->size)) 02657 return false; 02658 if (type->u.kclass != NULL 02659 && type->u.kclass->fields != NULL) 02660 { 02661 for (i = 0; type->u.kclass->fields[i] != NULL; i++) 02662 { 02663 struct debug_field *f; 02664 02665 f = type->u.kclass->fields[i]; 02666 if (! debug_write_type (info, fns, fhandle, f->type, 02667 (struct debug_name *) NULL) 02668 || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos, 02669 f->u.f.bitsize, f->visibility)) 02670 return false; 02671 } 02672 } 02673 return (*fns->end_struct_type) (fhandle); 02674 case DEBUG_KIND_CLASS: 02675 case DEBUG_KIND_UNION_CLASS: 02676 return debug_write_class_type (info, fns, fhandle, type, tag); 02677 case DEBUG_KIND_ENUM: 02678 if (type->u.kenum == NULL) 02679 return (*fns->enum_type) (fhandle, tag, (const char **) NULL, 02680 (bfd_signed_vma *) NULL); 02681 return (*fns->enum_type) (fhandle, tag, type->u.kenum->names, 02682 type->u.kenum->values); 02683 case DEBUG_KIND_POINTER: 02684 if (! debug_write_type (info, fns, fhandle, type->u.kpointer, 02685 (struct debug_name *) NULL)) 02686 return false; 02687 return (*fns->pointer_type) (fhandle); 02688 case DEBUG_KIND_FUNCTION: 02689 if (! debug_write_type (info, fns, fhandle, 02690 type->u.kfunction->return_type, 02691 (struct debug_name *) NULL)) 02692 return false; 02693 if (type->u.kfunction->arg_types == NULL) 02694 is = -1; 02695 else 02696 { 02697 for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++) 02698 if (! debug_write_type (info, fns, fhandle, 02699 type->u.kfunction->arg_types[is], 02700 (struct debug_name *) NULL)) 02701 return false; 02702 } 02703 return (*fns->function_type) (fhandle, is, 02704 type->u.kfunction->varargs); 02705 case DEBUG_KIND_REFERENCE: 02706 if (! debug_write_type (info, fns, fhandle, type->u.kreference, 02707 (struct debug_name *) NULL)) 02708 return false; 02709 return (*fns->reference_type) (fhandle); 02710 case DEBUG_KIND_RANGE: 02711 if (! debug_write_type (info, fns, fhandle, type->u.krange->type, 02712 (struct debug_name *) NULL)) 02713 return false; 02714 return (*fns->range_type) (fhandle, type->u.krange->lower, 02715 type->u.krange->upper); 02716 case DEBUG_KIND_ARRAY: 02717 if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type, 02718 (struct debug_name *) NULL) 02719 || ! debug_write_type (info, fns, fhandle, 02720 type->u.karray->range_type, 02721 (struct debug_name *) NULL)) 02722 return false; 02723 return (*fns->array_type) (fhandle, type->u.karray->lower, 02724 type->u.karray->upper, 02725 type->u.karray->stringp); 02726 case DEBUG_KIND_SET: 02727 if (! debug_write_type (info, fns, fhandle, type->u.kset->type, 02728 (struct debug_name *) NULL)) 02729 return false; 02730 return (*fns->set_type) (fhandle, type->u.kset->bitstringp); 02731 case DEBUG_KIND_OFFSET: 02732 if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type, 02733 (struct debug_name *) NULL) 02734 || ! debug_write_type (info, fns, fhandle, 02735 type->u.koffset->target_type, 02736 (struct debug_name *) NULL)) 02737 return false; 02738 return (*fns->offset_type) (fhandle); 02739 case DEBUG_KIND_METHOD: 02740 if (! debug_write_type (info, fns, fhandle, 02741 type->u.kmethod->return_type, 02742 (struct debug_name *) NULL)) 02743 return false; 02744 if (type->u.kmethod->arg_types == NULL) 02745 is = -1; 02746 else 02747 { 02748 for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++) 02749 if (! debug_write_type (info, fns, fhandle, 02750 type->u.kmethod->arg_types[is], 02751 (struct debug_name *) NULL)) 02752 return false; 02753 } 02754 if (type->u.kmethod->domain_type != NULL) 02755 { 02756 if (! debug_write_type (info, fns, fhandle, 02757 type->u.kmethod->domain_type, 02758 (struct debug_name *) NULL)) 02759 return false; 02760 } 02761 return (*fns->method_type) (fhandle, 02762 type->u.kmethod->domain_type != NULL, 02763 is, 02764 type->u.kmethod->varargs); 02765 case DEBUG_KIND_CONST: 02766 if (! debug_write_type (info, fns, fhandle, type->u.kconst, 02767 (struct debug_name *) NULL)) 02768 return false; 02769 return (*fns->const_type) (fhandle); 02770 case DEBUG_KIND_VOLATILE: 02771 if (! debug_write_type (info, fns, fhandle, type->u.kvolatile, 02772 (struct debug_name *) NULL)) 02773 return false; 02774 return (*fns->volatile_type) (fhandle); 02775 case DEBUG_KIND_NAMED: 02776 return debug_write_type (info, fns, fhandle, type->u.knamed->type, 02777 (struct debug_name *) NULL); 02778 case DEBUG_KIND_TAGGED: 02779 return debug_write_type (info, fns, fhandle, type->u.knamed->type, 02780 type->u.knamed->name); 02781 default: 02782 abort (); 02783 return false; 02784 } 02785 } 02786 02787 /* Write out a class type. */ 02788 02789 static boolean 02790 debug_write_class_type (info, fns, fhandle, type, tag) 02791 struct debug_handle *info; 02792 const struct debug_write_fns *fns; 02793 PTR fhandle; 02794 struct debug_type *type; 02795 const char *tag; 02796 { 02797 unsigned int i; 02798 unsigned int id; 02799 struct debug_type *vptrbase; 02800 02801 if (type->u.kclass == NULL) 02802 { 02803 id = 0; 02804 vptrbase = NULL; 02805 } 02806 else 02807 { 02808 if (type->u.kclass->id <= info->base_id) 02809 { 02810 if (! debug_set_class_id (info, tag, type)) 02811 return false; 02812 } 02813 02814 if (info->mark == type->u.kclass->mark) 02815 { 02816 /* We are currently outputting this class, or we have 02817 already output it. This can happen when there are 02818 methods for an anonymous class. */ 02819 assert (type->u.kclass->id > info->base_id); 02820 return (*fns->tag_type) (fhandle, tag, type->u.kclass->id, 02821 type->kind); 02822 } 02823 type->u.kclass->mark = info->mark; 02824 id = type->u.kclass->id; 02825 02826 vptrbase = type->u.kclass->vptrbase; 02827 if (vptrbase != NULL && vptrbase != type) 02828 { 02829 if (! debug_write_type (info, fns, fhandle, vptrbase, 02830 (struct debug_name *) NULL)) 02831 return false; 02832 } 02833 } 02834 02835 if (! (*fns->start_class_type) (fhandle, tag, id, 02836 type->kind == DEBUG_KIND_CLASS, 02837 type->size, 02838 vptrbase != NULL, 02839 vptrbase == type)) 02840 return false; 02841 02842 if (type->u.kclass != NULL) 02843 { 02844 if (type->u.kclass->fields != NULL) 02845 { 02846 for (i = 0; type->u.kclass->fields[i] != NULL; i++) 02847 { 02848 struct debug_field *f; 02849 02850 f = type->u.kclass->fields[i]; 02851 if (! debug_write_type (info, fns, fhandle, f->type, 02852 (struct debug_name *) NULL)) 02853 return false; 02854 if (f->static_member) 02855 { 02856 if (! (*fns->class_static_member) (fhandle, f->name, 02857 f->u.s.physname, 02858 f->visibility)) 02859 return false; 02860 } 02861 else 02862 { 02863 if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos, 02864 f->u.f.bitsize, f->visibility)) 02865 return false; 02866 } 02867 } 02868 } 02869 02870 if (type->u.kclass->baseclasses != NULL) 02871 { 02872 for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++) 02873 { 02874 struct debug_baseclass *b; 02875 02876 b = type->u.kclass->baseclasses[i]; 02877 if (! debug_write_type (info, fns, fhandle, b->type, 02878 (struct debug_name *) NULL)) 02879 return false; 02880 if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual, 02881 b->visibility)) 02882 return false; 02883 } 02884 } 02885 02886 if (type->u.kclass->methods != NULL) 02887 { 02888 for (i = 0; type->u.kclass->methods[i] != NULL; i++) 02889 { 02890 struct debug_method *m; 02891 unsigned int j; 02892 02893 m = type->u.kclass->methods[i]; 02894 if (! (*fns->class_start_method) (fhandle, m->name)) 02895 return false; 02896 for (j = 0; m->variants[j] != NULL; j++) 02897 { 02898 struct debug_method_variant *v; 02899 02900 v = m->variants[j]; 02901 if (v->context != NULL) 02902 { 02903 if (! debug_write_type (info, fns, fhandle, v->context, 02904 (struct debug_name *) NULL)) 02905 return false; 02906 } 02907 if (! debug_write_type (info, fns, fhandle, v->type, 02908 (struct debug_name *) NULL)) 02909 return false; 02910 if (v->voffset != VOFFSET_STATIC_METHOD) 02911 { 02912 if (! (*fns->class_method_variant) (fhandle, v->physname, 02913 v->visibility, 02914 v->constp, 02915 v->volatilep, 02916 v->voffset, 02917 v->context != NULL)) 02918 return false; 02919 } 02920 else 02921 { 02922 if (! (*fns->class_static_method_variant) (fhandle, 02923 v->physname, 02924 v->visibility, 02925 v->constp, 02926 v->volatilep)) 02927 return false; 02928 } 02929 } 02930 if (! (*fns->class_end_method) (fhandle)) 02931 return false; 02932 } 02933 } 02934 } 02935 02936 return (*fns->end_class_type) (fhandle); 02937 } 02938 02939 /* Write out information for a function. */ 02940 02941 static boolean 02942 debug_write_function (info, fns, fhandle, name, linkage, function) 02943 struct debug_handle *info; 02944 const struct debug_write_fns *fns; 02945 PTR fhandle; 02946 const char *name; 02947 enum debug_object_linkage linkage; 02948 struct debug_function *function; 02949 { 02950 struct debug_parameter *p; 02951 struct debug_block *b; 02952 02953 if (! debug_write_linenos (info, fns, fhandle, function->blocks->start)) 02954 return false; 02955 02956 if (! debug_write_type (info, fns, fhandle, function->return_type, 02957 (struct debug_name *) NULL)) 02958 return false; 02959 02960 if (! (*fns->start_function) (fhandle, name, 02961 linkage == DEBUG_LINKAGE_GLOBAL)) 02962 return false; 02963 02964 for (p = function->parameters; p != NULL; p = p->next) 02965 { 02966 if (! debug_write_type (info, fns, fhandle, p->type, 02967 (struct debug_name *) NULL) 02968 || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val)) 02969 return false; 02970 } 02971 02972 for (b = function->blocks; b != NULL; b = b->next) 02973 { 02974 if (! debug_write_block (info, fns, fhandle, b)) 02975 return false; 02976 } 02977 02978 return (*fns->end_function) (fhandle); 02979 } 02980 02981 /* Write out information for a block. */ 02982 02983 static boolean 02984 debug_write_block (info, fns, fhandle, block) 02985 struct debug_handle *info; 02986 const struct debug_write_fns *fns; 02987 PTR fhandle; 02988 struct debug_block *block; 02989 { 02990 struct debug_name *n; 02991 struct debug_block *b; 02992 02993 if (! debug_write_linenos (info, fns, fhandle, block->start)) 02994 return false; 02995 02996 /* I can't see any point to writing out a block with no local 02997 variables, so we don't bother, except for the top level block. */ 02998 if (block->locals != NULL || block->parent == NULL) 02999 { 03000 if (! (*fns->start_block) (fhandle, block->start)) 03001 return false; 03002 } 03003 03004 if (block->locals != NULL) 03005 { 03006 for (n = block->locals->list; n != NULL; n = n->next) 03007 { 03008 if (! debug_write_name (info, fns, fhandle, n)) 03009 return false; 03010 } 03011 } 03012 03013 for (b = block->children; b != NULL; b = b->next) 03014 { 03015 if (! debug_write_block (info, fns, fhandle, b)) 03016 return false; 03017 } 03018 03019 if (! debug_write_linenos (info, fns, fhandle, block->end)) 03020 return false; 03021 03022 if (block->locals != NULL || block->parent == NULL) 03023 { 03024 if (! (*fns->end_block) (fhandle, block->end)) 03025 return false; 03026 } 03027 03028 return true; 03029 } 03030 03031 /* Write out line number information up to ADDRESS. */ 03032 03033 static boolean 03034 debug_write_linenos (info, fns, fhandle, address) 03035 struct debug_handle *info; 03036 const struct debug_write_fns *fns; 03037 PTR fhandle; 03038 bfd_vma address; 03039 { 03040 while (info->current_write_lineno != NULL) 03041 { 03042 struct debug_lineno *l; 03043 03044 l = info->current_write_lineno; 03045 03046 while (info->current_write_lineno_index < DEBUG_LINENO_COUNT) 03047 { 03048 if (l->linenos[info->current_write_lineno_index] 03049 == (unsigned long) -1) 03050 break; 03051 03052 if (l->addrs[info->current_write_lineno_index] >= address) 03053 return true; 03054 03055 if (! (*fns->lineno) (fhandle, l->file->filename, 03056 l->linenos[info->current_write_lineno_index], 03057 l->addrs[info->current_write_lineno_index])) 03058 return false; 03059 03060 ++info->current_write_lineno_index; 03061 } 03062 03063 info->current_write_lineno = l->next; 03064 info->current_write_lineno_index = 0; 03065 } 03066 03067 return true; 03068 } 03069 03070 /* Get the ID number for a class. If during the same call to 03071 debug_write we find a struct with the same definition with the same 03072 name, we use the same ID. This type of things happens because the 03073 same struct will be defined by multiple compilation units. */ 03074 03075 static boolean 03076 debug_set_class_id (info, tag, type) 03077 struct debug_handle *info; 03078 const char *tag; 03079 struct debug_type *type; 03080 { 03081 struct debug_class_type *c; 03082 struct debug_class_id *l; 03083 03084 assert (type->kind == DEBUG_KIND_STRUCT 03085 || type->kind == DEBUG_KIND_UNION 03086 || type->kind == DEBUG_KIND_CLASS 03087 || type->kind == DEBUG_KIND_UNION_CLASS); 03088 03089 c = type->u.kclass; 03090 03091 if (c->id > info->base_id) 03092 return true; 03093 03094 for (l = info->id_list; l != NULL; l = l->next) 03095 { 03096 if (l->type->kind != type->kind) 03097 continue; 03098 03099 if (tag == NULL) 03100 { 03101 if (l->tag != NULL) 03102 continue; 03103 } 03104 else 03105 { 03106 if (l->tag == NULL 03107 || l->tag[0] != tag[0] 03108 || strcmp (l->tag, tag) != 0) 03109 continue; 03110 } 03111 03112 if (debug_type_samep (info, l->type, type)) 03113 { 03114 c->id = l->type->u.kclass->id; 03115 return true; 03116 } 03117 } 03118 03119 /* There are no identical types. Use a new ID, and add it to the 03120 list. */ 03121 ++info->class_id; 03122 c->id = info->class_id; 03123 03124 l = (struct debug_class_id *) xmalloc (sizeof *l); 03125 memset (l, 0, sizeof *l); 03126 03127 l->type = type; 03128 l->tag = tag; 03129 03130 l->next = info->id_list; 03131 info->id_list = l; 03132 03133 return true; 03134 } 03135 03136 /* See if two types are the same. At this point, we don't care about 03137 tags and the like. */ 03138 03139 static boolean 03140 debug_type_samep (info, t1, t2) 03141 struct debug_handle *info; 03142 struct debug_type *t1; 03143 struct debug_type *t2; 03144 { 03145 struct debug_type_compare_list *l; 03146 struct debug_type_compare_list top; 03147 boolean ret; 03148 03149 if (t1 == NULL) 03150 return t2 == NULL; 03151 if (t2 == NULL) 03152 return false; 03153 03154 while (t1->kind == DEBUG_KIND_INDIRECT) 03155 { 03156 t1 = *t1->u.kindirect->slot; 03157 if (t1 == NULL) 03158 return false; 03159 } 03160 while (t2->kind == DEBUG_KIND_INDIRECT) 03161 { 03162 t2 = *t2->u.kindirect->slot; 03163 if (t2 == NULL) 03164 return false; 03165 } 03166 03167 if (t1 == t2) 03168 return true; 03169 03170 /* As a special case, permit a typedef to match a tag, since C++ 03171 debugging output will sometimes add a typedef where C debugging 03172 output will not. */ 03173 if (t1->kind == DEBUG_KIND_NAMED 03174 && t2->kind == DEBUG_KIND_TAGGED) 03175 return debug_type_samep (info, t1->u.knamed->type, t2); 03176 else if (t1->kind == DEBUG_KIND_TAGGED 03177 && t2->kind == DEBUG_KIND_NAMED) 03178 return debug_type_samep (info, t1, t2->u.knamed->type); 03179 03180 if (t1->kind != t2->kind 03181 || t1->size != t2->size) 03182 return false; 03183 03184 /* Get rid of the trivial cases first. */ 03185 switch (t1->kind) 03186 { 03187 default: 03188 break; 03189 case DEBUG_KIND_VOID: 03190 case DEBUG_KIND_FLOAT: 03191 case DEBUG_KIND_COMPLEX: 03192 case DEBUG_KIND_BOOL: 03193 return true; 03194 case DEBUG_KIND_INT: 03195 return t1->u.kint == t2->u.kint; 03196 } 03197 03198 /* We have to avoid an infinite recursion. We do this by keeping a 03199 list of types which we are comparing. We just keep the list on 03200 the stack. If we encounter a pair of types we are currently 03201 comparing, we just assume that they are equal. */ 03202 for (l = info->compare_list; l != NULL; l = l->next) 03203 { 03204 if (l->t1 == t1 && l->t2 == t2) 03205 return true; 03206 } 03207 03208 top.t1 = t1; 03209 top.t2 = t2; 03210 top.next = info->compare_list; 03211 info->compare_list = ⊤ 03212 03213 switch (t1->kind) 03214 { 03215 default: 03216 abort (); 03217 ret = false; 03218 break; 03219 03220 case DEBUG_KIND_STRUCT: 03221 case DEBUG_KIND_UNION: 03222 case DEBUG_KIND_CLASS: 03223 case DEBUG_KIND_UNION_CLASS: 03224 if (t1->u.kclass == NULL) 03225 ret = t2->u.kclass == NULL; 03226 else if (t2->u.kclass == NULL) 03227 ret = false; 03228 else if (t1->u.kclass->id > info->base_id 03229 && t1->u.kclass->id == t2->u.kclass->id) 03230 ret = true; 03231 else 03232 ret = debug_class_type_samep (info, t1, t2); 03233 break; 03234 03235 case DEBUG_KIND_ENUM: 03236 if (t1->u.kenum == NULL) 03237 ret = t2->u.kenum == NULL; 03238 else if (t2->u.kenum == NULL) 03239 ret = false; 03240 else 03241 { 03242 const char **pn1, **pn2; 03243 bfd_signed_vma *pv1, *pv2; 03244 03245 pn1 = t1->u.kenum->names; 03246 pn2 = t2->u.kenum->names; 03247 pv1 = t1->u.kenum->values; 03248 pv2 = t2->u.kenum->values; 03249 while (*pn1 != NULL && *pn2 != NULL) 03250 { 03251 if (**pn1 != **pn2 03252 || *pv1 != *pv2 03253 || strcmp (*pn1, *pn2) != 0) 03254 break; 03255 ++pn1; 03256 ++pn2; 03257 ++pv1; 03258 ++pv2; 03259 } 03260 ret = *pn1 == NULL && *pn2 == NULL; 03261 } 03262 break; 03263 03264 case DEBUG_KIND_POINTER: 03265 ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer); 03266 break; 03267 03268 case DEBUG_KIND_FUNCTION: 03269 if (t1->u.kfunction->varargs != t2->u.kfunction->varargs 03270 || ! debug_type_samep (info, t1->u.kfunction->return_type, 03271 t2->u.kfunction->return_type) 03272 || ((t1->u.kfunction->arg_types == NULL) 03273 != (t2->u.kfunction->arg_types == NULL))) 03274 ret = false; 03275 else if (t1->u.kfunction->arg_types == NULL) 03276 ret = true; 03277 else 03278 { 03279 struct debug_type **a1, **a2; 03280 03281 a1 = t1->u.kfunction->arg_types; 03282 a2 = t2->u.kfunction->arg_types; 03283 while (*a1 != NULL && *a2 != NULL) 03284 if (! debug_type_samep (info, *a1, *a2)) 03285 break; 03286 ret = *a1 == NULL && *a2 == NULL; 03287 } 03288 break; 03289 03290 case DEBUG_KIND_REFERENCE: 03291 ret = debug_type_samep (info, t1->u.kreference, t2->u.kreference); 03292 break; 03293 03294 case DEBUG_KIND_RANGE: 03295 ret = (t1->u.krange->lower == t2->u.krange->lower 03296 && t1->u.krange->upper == t2->u.krange->upper 03297 && debug_type_samep (info, t1->u.krange->type, 03298 t2->u.krange->type)); 03299 03300 case DEBUG_KIND_ARRAY: 03301 ret = (t1->u.karray->lower == t2->u.karray->lower 03302 && t1->u.karray->upper == t2->u.karray->upper 03303 && t1->u.karray->stringp == t2->u.karray->stringp 03304 && debug_type_samep (info, t1->u.karray->element_type, 03305 t2->u.karray->element_type)); 03306 break; 03307 03308 case DEBUG_KIND_SET: 03309 ret = (t1->u.kset->bitstringp == t2->u.kset->bitstringp 03310 && debug_type_samep (info, t1->u.kset->type, t2->u.kset->type)); 03311 break; 03312 03313 case DEBUG_KIND_OFFSET: 03314 ret = (debug_type_samep (info, t1->u.koffset->base_type, 03315 t2->u.koffset->base_type) 03316 && debug_type_samep (info, t1->u.koffset->target_type, 03317 t2->u.koffset->target_type)); 03318 break; 03319 03320 case DEBUG_KIND_METHOD: 03321 if (t1->u.kmethod->varargs != t2->u.kmethod->varargs 03322 || ! debug_type_samep (info, t1->u.kmethod->return_type, 03323 t2->u.kmethod->return_type) 03324 || ! debug_type_samep (info, t1->u.kmethod->domain_type, 03325 t2->u.kmethod->domain_type) 03326 || ((t1->u.kmethod->arg_types == NULL) 03327 != (t2->u.kmethod->arg_types == NULL))) 03328 ret = false; 03329 else if (t1->u.kmethod->arg_types == NULL) 03330 ret = true; 03331 else 03332 { 03333 struct debug_type **a1, **a2; 03334 03335 a1 = t1->u.kmethod->arg_types; 03336 a2 = t2->u.kmethod->arg_types; 03337 while (*a1 != NULL && *a2 != NULL) 03338 if (! debug_type_samep (info, *a1, *a2)) 03339 break; 03340 ret = *a1 == NULL && *a2 == NULL; 03341 } 03342 break; 03343 03344 case DEBUG_KIND_CONST: 03345 ret = debug_type_samep (info, t1->u.kconst, t2->u.kconst); 03346 break; 03347 03348 case DEBUG_KIND_VOLATILE: 03349 ret = debug_type_samep (info, t1->u.kvolatile, t2->u.kvolatile); 03350 break; 03351 03352 case DEBUG_KIND_NAMED: 03353 case DEBUG_KIND_TAGGED: 03354 ret = (strcmp (t1->u.knamed->name->name, t2->u.knamed->name->name) == 0 03355 && debug_type_samep (info, t1->u.knamed->type, 03356 t2->u.knamed->type)); 03357 break; 03358 } 03359 03360 info->compare_list = top.next; 03361 03362 return ret; 03363 } 03364 03365 /* See if two classes are the same. This is a subroutine of 03366 debug_type_samep. */ 03367 03368 static boolean 03369 debug_class_type_samep (info, t1, t2) 03370 struct debug_handle *info; 03371 struct debug_type *t1; 03372 struct debug_type *t2; 03373 { 03374 struct debug_class_type *c1, *c2; 03375 03376 c1 = t1->u.kclass; 03377 c2 = t2->u.kclass; 03378 03379 if ((c1->fields == NULL) != (c2->fields == NULL) 03380 || (c1->baseclasses == NULL) != (c2->baseclasses == NULL) 03381 || (c1->methods == NULL) != (c2->methods == NULL) 03382 || (c1->vptrbase == NULL) != (c2->vptrbase == NULL)) 03383 return false; 03384 03385 if (c1->fields != NULL) 03386 { 03387 struct debug_field **pf1, **pf2; 03388 03389 for (pf1 = c1->fields, pf2 = c2->fields; 03390 *pf1 != NULL && *pf2 != NULL; 03391 pf1++, pf2++) 03392 { 03393 struct debug_field *f1, *f2; 03394 03395 f1 = *pf1; 03396 f2 = *pf2; 03397 if (f1->name[0] != f2->name[0] 03398 || f1->visibility != f2->visibility 03399 || f1->static_member != f2->static_member) 03400 return false; 03401 if (f1->static_member) 03402 { 03403 if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0) 03404 return false; 03405 } 03406 else 03407 { 03408 if (f1->u.f.bitpos != f2->u.f.bitpos 03409 || f1->u.f.bitsize != f2->u.f.bitsize) 03410 return false; 03411 } 03412 /* We do the checks which require function calls last. We 03413 don't require that the types of fields have the same 03414 names, since that sometimes fails in the presence of 03415 typedefs and we really don't care. */ 03416 if (strcmp (f1->name, f2->name) != 0 03417 || ! debug_type_samep (info, 03418 debug_get_real_type ((PTR) info, 03419 f1->type), 03420 debug_get_real_type ((PTR) info, 03421 f2->type))) 03422 return false; 03423 } 03424 if (*pf1 != NULL || *pf2 != NULL) 03425 return false; 03426 } 03427 03428 if (c1->vptrbase != NULL) 03429 { 03430 if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase)) 03431 return false; 03432 } 03433 03434 if (c1->baseclasses != NULL) 03435 { 03436 struct debug_baseclass **pb1, **pb2; 03437 03438 for (pb1 = c1->baseclasses, pb2 = c2->baseclasses; 03439 *pb1 != NULL && *pb2 != NULL; 03440 ++pb1, ++pb2) 03441 { 03442 struct debug_baseclass *b1, *b2; 03443 03444 b1 = *pb1; 03445 b2 = *pb2; 03446 if (b1->bitpos != b2->bitpos 03447 || b1->virtual != b2->virtual 03448 || b1->visibility != b2->visibility 03449 || ! debug_type_samep (info, b1->type, b2->type)) 03450 return false; 03451 } 03452 if (*pb1 != NULL || *pb2 != NULL) 03453 return false; 03454 } 03455 03456 if (c1->methods != NULL) 03457 { 03458 struct debug_method **pm1, **pm2; 03459 03460 for (pm1 = c1->methods, pm2 = c2->methods; 03461 *pm1 != NULL && *pm2 != NULL; 03462 ++pm1, ++pm2) 03463 { 03464 struct debug_method *m1, *m2; 03465 03466 m1 = *pm1; 03467 m2 = *pm2; 03468 if (m1->name[0] != m2->name[0] 03469 || strcmp (m1->name, m2->name) != 0 03470 || (m1->variants == NULL) != (m2->variants == NULL)) 03471 return false; 03472 if (m1->variants == NULL) 03473 { 03474 struct debug_method_variant **pv1, **pv2; 03475 03476 for (pv1 = m1->variants, pv2 = m2->variants; 03477 *pv1 != NULL && *pv2 != NULL; 03478 ++pv1, ++pv2) 03479 { 03480 struct debug_method_variant *v1, *v2; 03481 03482 v1 = *pv1; 03483 v2 = *pv2; 03484 if (v1->physname[0] != v2->physname[0] 03485 || v1->visibility != v2->visibility 03486 || v1->constp != v2->constp 03487 || v1->volatilep != v2->volatilep 03488 || v1->voffset != v2->voffset 03489 || (v1->context == NULL) != (v2->context == NULL) 03490 || strcmp (v1->physname, v2->physname) != 0 03491 || ! debug_type_samep (info, v1->type, v2->type)) 03492 return false; 03493 if (v1->context != NULL) 03494 { 03495 if (! debug_type_samep (info, v1->context, 03496 v2->context)) 03497 return false; 03498 } 03499 } 03500 if (*pv1 != NULL || *pv2 != NULL) 03501 return false; 03502 } 03503 } 03504 if (*pm1 != NULL || *pm2 != NULL) 03505 return false; 03506 } 03507 03508 return true; 03509 }
1.4.7

