debug.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,665 行 · 第 1/5 页

C
2,665
字号
/* debug.c -- Handle generic debugging information.   Copyright 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.   Written by Ian Lance Taylor <ian@cygnus.com>.   This file is part of GNU Binutils.   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA   02111-1307, USA.  *//* This file implements a generic debugging format.  We may eventually   have readers which convert different formats into this generic   format, and writers which write it out.  The initial impetus for   this was writing a convertor from stabs to HP IEEE-695 debugging   format.  */#include <stdio.h>#include <assert.h>#include "bfd.h"#include "bucomm.h"#include "libiberty.h"#include "debug.h"/* Global information we keep for debugging.  A pointer to this   structure is the debugging handle passed to all the routines.  */struct debug_handle{  /* A linked list of compilation units.  */  struct debug_unit *units;  /* The current compilation unit.  */  struct debug_unit *current_unit;  /* The current source file.  */  struct debug_file *current_file;  /* The current function.  */  struct debug_function *current_function;  /* The current block.  */  struct debug_block *current_block;  /* The current line number information for the current unit.  */  struct debug_lineno *current_lineno;  /* Mark.  This is used by debug_write.  */  unsigned int mark;  /* A struct/class ID used by debug_write.  */  unsigned int class_id;  /* The base for class_id for this call to debug_write.  */  unsigned int base_id;  /* The current line number in debug_write.  */  struct debug_lineno *current_write_lineno;  unsigned int current_write_lineno_index;  /* A list of classes which have assigned ID's during debug_write.     This is linked through the next_id field of debug_class_type.  */  struct debug_class_id *id_list;  /* A list used to avoid recursion during debug_type_samep.  */  struct debug_type_compare_list *compare_list;};/* Information we keep for a single compilation unit.  */struct debug_unit{  /* The next compilation unit.  */  struct debug_unit *next;  /* A list of files included in this compilation unit.  The first     file is always the main one, and that is where the main file name     is stored.  */  struct debug_file *files;  /* Line number information for this compilation unit.  This is not     stored by function, because assembler code may have line number     information without function information.  */  struct debug_lineno *linenos;};/* Information kept for a single source file.  */struct debug_file{  /* The next source file in this compilation unit.  */  struct debug_file *next;  /* The name of the source file.  */  const char *filename;  /* Global functions, variables, types, etc.  */  struct debug_namespace *globals;};/* A type.  */struct debug_type{  /* Kind of type.  */  enum debug_type_kind kind;  /* Size of type (0 if not known).  */  unsigned int size;  /* Type which is a pointer to this type.  */  debug_type pointer;  /* Tagged union with additional information about the type.  */  union    {      /* DEBUG_KIND_INDIRECT.  */      struct debug_indirect_type *kindirect;      /* DEBUG_KIND_INT.  */      /* Whether the integer is unsigned.  */      boolean kint;      /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,         DEBUG_KIND_UNION_CLASS.  */      struct debug_class_type *kclass;      /* DEBUG_KIND_ENUM.  */      struct debug_enum_type *kenum;      /* DEBUG_KIND_POINTER.  */      struct debug_type *kpointer;      /* DEBUG_KIND_FUNCTION.  */      struct debug_function_type *kfunction;      /* DEBUG_KIND_REFERENCE.  */      struct debug_type *kreference;      /* DEBUG_KIND_RANGE.  */      struct debug_range_type *krange;      /* DEBUG_KIND_ARRAY.  */      struct debug_array_type *karray;      /* DEBUG_KIND_SET.  */      struct debug_set_type *kset;      /* DEBUG_KIND_OFFSET.  */      struct debug_offset_type *koffset;      /* DEBUG_KIND_METHOD.  */      struct debug_method_type *kmethod;      /* DEBUG_KIND_CONST.  */      struct debug_type *kconst;      /* DEBUG_KIND_VOLATILE.  */      struct debug_type *kvolatile;      /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED.  */      struct debug_named_type *knamed;    } u;};/* Information kept for an indirect type.  */struct debug_indirect_type{  /* Slot where the final type will appear.  */  debug_type *slot;  /* Tag.  */  const char *tag;};/* Information kept for a struct, union, or class.  */struct debug_class_type{  /* NULL terminated array of fields.  */  debug_field *fields;  /* A mark field which indicates whether the struct has already been     printed.  */  unsigned int mark;  /* This is used to uniquely identify unnamed structs when printing.  */  unsigned int id;  /* The remaining fields are only used for DEBUG_KIND_CLASS and     DEBUG_KIND_UNION_CLASS.  */  /* NULL terminated array of base classes.  */  debug_baseclass *baseclasses;  /* NULL terminated array of methods.  */  debug_method *methods;  /* The type of the class providing the virtual function table for     this class.  This may point to the type itself.  */  debug_type vptrbase;};/* Information kept for an enum.  */struct debug_enum_type{  /* NULL terminated array of names.  */  const char **names;  /* Array of corresponding values.  */  bfd_signed_vma *values;};/* Information kept for a function.  FIXME: We should be able to   record the parameter types.  */struct debug_function_type{  /* Return type.  */  debug_type return_type;  /* NULL terminated array of argument types.  */  debug_type *arg_types;  /* Whether the function takes a variable number of arguments.  */  boolean varargs;};/* Information kept for a range.  */struct debug_range_type{  /* Range base type.  */  debug_type type;  /* Lower bound.  */  bfd_signed_vma lower;  /* Upper bound.  */  bfd_signed_vma upper;};/* Information kept for an array.  */struct debug_array_type{  /* Element type.  */  debug_type element_type;  /* Range type.  */  debug_type range_type;  /* Lower bound.  */  bfd_signed_vma lower;  /* Upper bound.  */  bfd_signed_vma upper;  /* Whether this array is really a string.  */  boolean stringp;};/* Information kept for a set.  */struct debug_set_type{  /* Base type.  */  debug_type type;  /* Whether this set is really a bitstring.  */  boolean bitstringp;};/* Information kept for an offset type (a based pointer).  */struct debug_offset_type{  /* The type the pointer is an offset from.  */  debug_type base_type;  /* The type the pointer points to.  */  debug_type target_type;};/* Information kept for a method type.  */struct debug_method_type{  /* The return type.  */  debug_type return_type;  /* The object type which this method is for.  */  debug_type domain_type;  /* A NULL terminated array of argument types.  */  debug_type *arg_types;  /* Whether the method takes a variable number of arguments.  */  boolean varargs;};/* Information kept for a named type.  */struct debug_named_type{  /* Name.  */  struct debug_name *name;  /* Real type.  */  debug_type type;};/* A field in a struct or union.  */struct debug_field{  /* Name of the field.  */  const char *name;  /* Type of the field.  */  struct debug_type *type;  /* Visibility of the field.  */  enum debug_visibility visibility;  /* Whether this is a static member.  */  boolean static_member;  union    {      /* If static_member is false.  */      struct	{	  /* Bit position of the field in the struct.  */	  unsigned int bitpos;	  /* Size of the field in bits.  */	  unsigned int bitsize;	} f;      /* If static_member is true.  */      struct	{	  const char *physname;	} s;    } u;};/* A base class for an object.  */struct debug_baseclass{  /* Type of the base class.  */  struct debug_type *type;  /* Bit position of the base class in the object.  */  unsigned int bitpos;  /* Whether the base class is virtual.  */  boolean virtual;  /* Visibility of the base class.  */  enum debug_visibility visibility;};/* A method of an object.  */struct debug_method{  /* The name of the method.  */  const char *name;  /* A NULL terminated array of different types of variants.  */  struct debug_method_variant **variants;};/* The variants of a method function of an object.  These indicate   which method to run.  */struct debug_method_variant{  /* The physical name of the function.  */  const char *physname;  /* The type of the function.  */  struct debug_type *type;  /* The visibility of the function.  */  enum debug_visibility visibility;  /* Whether the function is const.  */  boolean constp;  /* Whether the function is volatile.  */  boolean volatilep;  /* The offset to the function in the virtual function table.  */  bfd_vma voffset;  /* If voffset is VOFFSET_STATIC_METHOD, this is a static method.  */#define VOFFSET_STATIC_METHOD ((bfd_vma) -1)  /* Context of a virtual method function.  */  struct debug_type *context;};/* A variable.  This is the information we keep for a variable object.   This has no name; a name is associated with a variable in a   debug_name structure.  */struct debug_variable{  /* Kind of variable.  */  enum debug_var_kind kind;  /* Type.  */  debug_type type;  /* Value.  The interpretation of the value depends upon kind.  */  bfd_vma val;};/* A function.  This has no name; a name is associated with a function   in a debug_name structure.  */struct debug_function{  /* Return type.  */  debug_type return_type;  /* Parameter information.  */  struct debug_parameter *parameters;  /* Block information.  The first structure on the list is the main     block of the function, and describes function local variables.  */  struct debug_block *blocks;};/* A function parameter.  */struct debug_parameter{  /* Next parameter.  */  struct debug_parameter *next;  /* Name.  */  const char *name;  /* Type.  */  debug_type type;  /* Kind.  */  enum debug_parm_kind kind;  /* Value (meaning depends upon kind).  */  bfd_vma val;};/* A typed constant.  */struct debug_typed_constant{  /* Type.  */  debug_type type;  /* Value.  FIXME: We may eventually need to support non-integral     values.  */  bfd_vma val;};/* Information about a block within a function.  */struct debug_block{  /* Next block with the same parent.  */  struct debug_block *next;  /* Parent block.  */  struct debug_block *parent;  /* List of child blocks.  */  struct debug_block *children;  /* Start address of the block.  */  bfd_vma start;  /* End address of the block.  */  bfd_vma end;  /* Local variables.  */  struct debug_namespace *locals;};/* Line number information we keep for a compilation unit.  FIXME:   This structure is easy to create, but can be very space   inefficient.  */struct debug_lineno{  /* More line number information for this block.  */  struct debug_lineno *next;  /* Source file.  */  struct debug_file *file;  /* Line numbers, terminated by a -1 or the end of the array.  */#define DEBUG_LINENO_COUNT 10  unsigned long linenos[DEBUG_LINENO_COUNT];  /* Addresses for the line numbers.  */  bfd_vma addrs[DEBUG_LINENO_COUNT];};/* A namespace.  This is a mapping from names to objects.  FIXME: This   should be implemented as a hash table.  */struct debug_namespace{  /* List of items in this namespace.  */  struct debug_name *list;  /* Pointer to where the next item in this namespace should go.  */  struct debug_name **tail;};/* Kinds of objects that appear in a namespace.  */enum debug_object_kind{  /* A type.  */  DEBUG_OBJECT_TYPE,  /* A tagged type (really a different sort of namespace).  */  DEBUG_OBJECT_TAG,  /* A variable.  */  DEBUG_OBJECT_VARIABLE,  /* A function.  */  DEBUG_OBJECT_FUNCTION,  /* An integer constant.  */  DEBUG_OBJECT_INT_CONSTANT,  /* A floating point constant.  */  DEBUG_OBJECT_FLOAT_CONSTANT,  /* A typed constant.  */  DEBUG_OBJECT_TYPED_CONSTANT};/* Linkage of an object that appears in a namespace.  */enum debug_object_linkage{  /* Local variable.  */  DEBUG_LINKAGE_AUTOMATIC,  /* Static--either file static or function static, depending upon the     namespace is.  */  DEBUG_LINKAGE_STATIC,  /* Global.  */  DEBUG_LINKAGE_GLOBAL,  /* No linkage.  */  DEBUG_LINKAGE_NONE};/* A name in a namespace.  */struct debug_name{  /* Next name in this namespace.  */  struct debug_name *next;  /* Name.  */  const char *name;  /* Mark.  This is used by debug_write.  */  unsigned int mark;  /* Kind of object.  */  enum debug_object_kind kind;  /* Linkage of object.  */  enum debug_object_linkage linkage;  /* Tagged union with additional information about the object.  */  union    {      /* DEBUG_OBJECT_TYPE.  */      struct debug_type *type;      /* DEBUG_OBJECT_TAG.  */      struct debug_type *tag;      /* DEBUG_OBJECT_VARIABLE.  */      struct debug_variable *variable;      /* DEBUG_OBJECT_FUNCTION.  */      struct debug_function *function;      /* DEBUG_OBJECT_INT_CONSTANT.  */      bfd_vma int_constant;      /* DEBUG_OBJECT_FLOAT_CONSTANT.  */      double float_constant;      /* DEBUG_OBJECT_TYPED_CONSTANT.  */      struct debug_typed_constant *typed_constant;    } u;};/* During debug_write, a linked list of these structures is used to   keep track of ID numbers that have been assigned to classes.  */struct debug_class_id{  /* Next ID number.  */  struct debug_class_id *next;  /* The type with the ID.  */  struct debug_type *type;  /* The tag; NULL if no tag.  */  const char *tag;};/* During debug_type_samep, a linked list of these structures is kept   on the stack to avoid infinite recursion.  */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?