wrstabs.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,416 行 · 第 1/4 页
C
2,416 行
in the debugging output. */ /* We need a domain. I'm not sure DOMAINP can ever be false, anyhow. */ if (! domainp) { if (! stab_empty_type (p)) return false; } definition = info->type_stack->definition; domain = stab_pop_type (info); /* A non-varargs function is indicated by making the last parameter type be void. */ if (argcount < 0) { args = NULL; argcount = 0; } else if (argcount == 0) { if (varargs) args = NULL; else { args = (char **) xmalloc (1 * sizeof (*args)); if (! stab_empty_type (p)) return false; definition = definition || info->type_stack->definition; args[0] = stab_pop_type (info); argcount = 1; } } else { args = (char **) xmalloc ((argcount + 1) * sizeof (*args)); for (i = argcount - 1; i >= 0; i--) { definition = definition || info->type_stack->definition; args[i] = stab_pop_type (info); } if (! varargs) { if (! stab_empty_type (p)) return false; definition = definition || info->type_stack->definition; args[argcount] = stab_pop_type (info); ++argcount; } } definition = definition || info->type_stack->definition; return_type = stab_pop_type (info); len = strlen (domain) + strlen (return_type) + 10; for (i = 0; i < argcount; i++) len += strlen (args[i]); buf = (char *) xmalloc (len); sprintf (buf, "#%s,%s", domain, return_type); free (domain); free (return_type); for (i = 0; i < argcount; i++) { strcat (buf, ","); strcat (buf, args[i]); free (args[i]); } strcat (buf, ";"); if (args != NULL) free (args); if (! stab_push_string (info, buf, 0, definition, 0)) return false; free (buf); return true;}/* Push a const version of a type. */static booleanstab_const_type (p) PTR p;{ struct stab_write_handle *info = (struct stab_write_handle *) p; return stab_modify_type (info, 'k', info->type_stack->size, (long **) NULL, (size_t *) NULL);}/* Push a volatile version of a type. */static booleanstab_volatile_type (p) PTR p;{ struct stab_write_handle *info = (struct stab_write_handle *) p; return stab_modify_type (info, 'B', info->type_stack->size, (long **) NULL, (size_t *) NULL);}/* Get the type index to use for a struct/union/class ID. This should return -1 if it fails. */static longstab_get_struct_index (info, tag, id, kind, psize) struct stab_write_handle *info; const char *tag; unsigned int id; enum debug_type_kind kind; unsigned int *psize;{ if (id >= info->type_cache.struct_types_alloc) { size_t alloc; alloc = info->type_cache.struct_types_alloc; if (alloc == 0) alloc = 10; while (id >= alloc) alloc *= 2; info->type_cache.struct_types = (struct stab_tag *) xrealloc (info->type_cache.struct_types, alloc * sizeof (struct stab_tag)); memset ((info->type_cache.struct_types + info->type_cache.struct_types_alloc), 0, ((alloc - info->type_cache.struct_types_alloc) * sizeof (struct stab_tag))); info->type_cache.struct_types_alloc = alloc; } if (info->type_cache.struct_types[id].index == 0) { info->type_cache.struct_types[id].index = info->type_index; ++info->type_index; info->type_cache.struct_types[id].tag = tag; info->type_cache.struct_types[id].kind = kind; } if (kind == DEBUG_KIND_ILLEGAL) { /* This is a definition of the struct. */ info->type_cache.struct_types[id].kind = kind; info->type_cache.struct_types[id].size = *psize; } else *psize = info->type_cache.struct_types[id].size; return info->type_cache.struct_types[id].index;}/* Start outputting a struct. We ignore the tag, and handle it in stab_tag. *//*ARGSUSED*/static booleanstab_start_struct_type (p, tag, id, structp, size) PTR p; const char *tag; unsigned int id; boolean structp; unsigned int size;{ struct stab_write_handle *info = (struct stab_write_handle *) p; long index; boolean definition; char *buf; buf = (char *) xmalloc (40); if (id == 0) { index = 0; *buf = '\0'; definition = false; } else { index = stab_get_struct_index (info, tag, id, DEBUG_KIND_ILLEGAL, &size); if (index < 0) return false; sprintf (buf, "%ld=", index); definition = true; } sprintf (buf + strlen (buf), "%c%u", structp ? 's' : 'u', size); if (! stab_push_string (info, buf, index, definition, size)) return false; info->type_stack->fields = (char *) xmalloc (1); info->type_stack->fields[0] = '\0'; return true;}/* Add a field to a struct. */static booleanstab_struct_field (p, name, bitpos, bitsize, visibility) PTR p; const char *name; bfd_vma bitpos; bfd_vma bitsize; enum debug_visibility visibility;{ struct stab_write_handle *info = (struct stab_write_handle *) p; boolean definition; unsigned int size; char *s, *n; const char *vis; definition = info->type_stack->definition; size = info->type_stack->size; s = stab_pop_type (info); /* Add this field to the end of the current struct fields, which is currently on the top of the stack. */ assert (info->type_stack->fields != NULL); n = (char *) xmalloc (strlen (info->type_stack->fields) + strlen (name) + strlen (s) + 50); switch (visibility) { default: abort (); case DEBUG_VISIBILITY_PUBLIC: vis = ""; break; case DEBUG_VISIBILITY_PRIVATE: vis = "/0"; break; case DEBUG_VISIBILITY_PROTECTED: vis = "/1"; break; } if (bitsize == 0) { bitsize = size * 8; if (bitsize == 0) non_fatal (_("%s: warning: unknown size for field `%s' in struct"), bfd_get_filename (info->abfd), name); } sprintf (n, "%s%s:%s%s,%ld,%ld;", info->type_stack->fields, name, vis, s, (long) bitpos, (long) bitsize); free (info->type_stack->fields); info->type_stack->fields = n; if (definition) info->type_stack->definition = true; return true;}/* Finish up a struct. */static booleanstab_end_struct_type (p) PTR p;{ struct stab_write_handle *info = (struct stab_write_handle *) p; boolean definition; long index; unsigned int size; char *fields, *first, *buf; assert (info->type_stack != NULL && info->type_stack->fields != NULL); definition = info->type_stack->definition; index = info->type_stack->index; size = info->type_stack->size; fields = info->type_stack->fields; first = stab_pop_type (info); buf = (char *) xmalloc (strlen (first) + strlen (fields) + 2); sprintf (buf, "%s%s;", first, fields); free (first); free (fields); if (! stab_push_string (info, buf, index, definition, size)) return false; free (buf); return true;}/* Start outputting a class. */static booleanstab_start_class_type (p, tag, id, structp, size, vptr, ownvptr) PTR p; const char *tag; unsigned int id; boolean structp; unsigned int size; boolean vptr; boolean ownvptr;{ struct stab_write_handle *info = (struct stab_write_handle *) p; boolean definition; char *vstring; if (! vptr || ownvptr) { definition = false; vstring = NULL; } else { definition = info->type_stack->definition; vstring = stab_pop_type (info); } if (! stab_start_struct_type (p, tag, id, structp, size)) return false; if (vptr) { char *vtable; if (ownvptr) { assert (info->type_stack->index > 0); vtable = (char *) xmalloc (20); sprintf (vtable, "~%%%ld", info->type_stack->index); } else { vtable = (char *) xmalloc (strlen (vstring) + 3); sprintf (vtable, "~%%%s", vstring); free (vstring); } info->type_stack->vtable = vtable; } if (definition) info->type_stack->definition = true; return true;}/* Add a static member to the class on the type stack. */static booleanstab_class_static_member (p, name, physname, visibility) PTR p; const char *name; const char *physname; enum debug_visibility visibility;{ struct stab_write_handle *info = (struct stab_write_handle *) p; boolean definition; char *s, *n; const char *vis; definition = info->type_stack->definition; s = stab_pop_type (info); /* Add this field to the end of the current struct fields, which is currently on the top of the stack. */ assert (info->type_stack->fields != NULL); n = (char *) xmalloc (strlen (info->type_stack->fields) + strlen (name) + strlen (s) + strlen (physname) + 10); switch (visibility) { default: abort (); case DEBUG_VISIBILITY_PUBLIC: vis = ""; break; case DEBUG_VISIBILITY_PRIVATE: vis = "/0"; break; case DEBUG_VISIBILITY_PROTECTED: vis = "/1"; break; } sprintf (n, "%s%s:%s%s:%s;", info->type_stack->fields, name, vis, s, physname); free (info->type_stack->fields); info->type_stack->fields = n; if (definition) info->type_stack->definition = true; return true;}/* Add a base class to the class on the type stack. */static booleanstab_class_baseclass (p, bitpos, virtual, visibility) PTR p; bfd_vma bitpos; boolean virtual; enum debug_visibility visibility;{ struct stab_write_handle *info = (struct stab_write_handle *) p; boolean definition; char *s; char *buf; unsigned int c; char **baseclasses; definition = info->type_stack->definition; s = stab_pop_type (info); /* Build the base class specifier. */ buf = (char *) xmalloc (strlen (s) + 25); buf[0] = virtual ? '1' : '0'; switch (visibility) { default: abort (); case DEBUG_VISIBILITY_PRIVATE: buf[1] = '0'; break; case DEBUG_VISIBILITY_PROTECTED: buf[1] = '1'; break; case DEBUG_VISIBILITY_PUBLIC: buf[1] = '2'; break; } sprintf (buf + 2, "%ld,%s;", (long) bitpos, s); free (s); /* Add the new baseclass to the existing ones. */ assert (info->type_stack != NULL && info->type_stack->fields != NULL); if (info->type_stack->baseclasses == NULL) c = 0; else { c = 0; while (info->type_stack->baseclasses[c] != NULL) ++c; } baseclasses = (char **) xrealloc (info->type_stack->baseclasses, (c + 2) * sizeof (*baseclasses)); baseclasses[c] = buf; baseclasses[c + 1] = NULL; info->type_stack->baseclasses = baseclasses; if (definition) info->type_stack->definition = true; return true;}/* Start adding a method to the class on the type stack. */static booleanstab_class_start_method (p, name) PTR p; const char *name;{ struct stab_write_handle *info = (struct stab_write_handle *) p; char *m; assert (info->type_stack != NULL && info->type_stack->fields != NULL); if (info->type_stack->methods == NULL) { m = (char *) xmalloc (strlen (name) + 3); *m = '\0'; } else { m = (char *) xrealloc (info->type_stack->methods, (strlen (info->type_stack->methods) + strlen (name) + 4)); } sprintf (m + strlen (m), "%s::", name); info->type_stack->methods = m; return true;}/* Add a variant, either static or not, to the current method. */static booleanstab_class_method_var (info, physname, visibility, staticp, constp, volatilep, voffset, contextp) struct stab_write_handle *info; const char *physname; enum debug_visibility visibility; boolean staticp; boolean constp; boolean volatilep; bfd_vma voffset; boolean contextp;{ boolean definition; char *type; char *context = NULL; char visc, qualc, typec; definition = info->type_stack->definition; type = stab_pop_type (info); if (contextp) { definition = definition || info->type_stack->definition; context = stab_pop_type (info); } assert (info->type_stack != NULL && info->type_stack->methods != NULL); switch (visibility) { default: abort (); case DEBUG_VISIBILITY_PRIVATE: visc = '0'; break; case DEBUG_VISIBILITY_PROTECTED: visc = '1'; break; case DEBUG_VISIBILITY_PUBLIC: visc = '2'; break; } if (constp) { if (volatilep) qualc = 'D'; else qualc = 'B'; } else { if (volatilep) qualc = 'C'; else qualc = 'A'; } if (staticp) typec = '?'; else if (! contextp) typec = '.'; else typec = '*'; info->type_stack->methods = (char *) xrealloc (info->type_stack->methods, (strlen (info->type_stack->methods) + strlen (type) + strlen (physname) + (contextp ? strlen (context) : 0) + 40)); sprintf (info->type_stack->methods + strlen (info->type_stack->methods), "%s:%s;%c%c%c", type, physname, visc, qualc, typec); free (type);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?