⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdbout.c

📁 gcc库的原代码,对编程有很大帮助.
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Output sdb-format symbol table information from GNU compiler.   Copyright (C) 1988, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.This file is part of GNU CC.GNU CC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU CC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU CC; see the file COPYING.  If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA.  *//*  mike@tredysvr.Tredydev.Unisys.COM says:I modified the struct.c example and have a nm of a .o resulting from theAT&T C compiler.  From the example below I would conclude the following:1. All .defs from structures are emitted as scanned.  The example below   clearly shows the symbol table entries for BoxRec2 are after the first   function.2. All functions and their locals (including statics) are emitted as scanned.3. All nested unnamed union and structure .defs must be emitted before   the structure in which they are nested.  The AT&T assembler is a   one pass beast as far as symbolics are concerned.4. All structure .defs are emitted before the typedefs that refer to them.5. All top level static and external variable definitions are moved to the   end of file with all top level statics occurring first before externs.6. All undefined references are at the end of the file.*/#include "config.h"#ifdef SDB_DEBUGGING_INFO#include "tree.h"#include "rtl.h"#include <stdio.h>#include "regs.h"#include "flags.h"#include "insn-config.h"#include "reload.h"/* Mips systems use the SDB functions to dump out symbols, but   do not supply usable syms.h include files.  */#if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(_WIN32) && !defined(__linux__)#include <syms.h>/* Use T_INT if we don't have T_VOID.  */#ifndef T_VOID#define T_VOID T_INT#endif#else /* not USG, or MIPS */#include "gsyms.h"#endif /* not USG, or MIPS *//* #include <storclass.h>  used to be this instead of syms.h.  *//* 1 if PARM is passed to this function in memory.  */#define PARM_PASSED_IN_MEMORY(PARM) \ (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)/* A C expression for the integer offset value of an automatic variable   (C_AUTO) having address X (an RTX).  */#ifndef DEBUGGER_AUTO_OFFSET#define DEBUGGER_AUTO_OFFSET(X) \  (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)#endif/* A C expression for the integer offset value of an argument (C_ARG)   having address X (an RTX).  The nominal offset is OFFSET.  */#ifndef DEBUGGER_ARG_OFFSET#define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)#endif/* Line number of beginning of current function, minus one.   Negative means not in a function or not using sdb.  */int sdb_begin_function_line = -1;/* Counter to generate unique "names" for nameless struct members.  */static int unnamed_struct_number = 0;extern FILE *asm_out_file;extern tree current_function_decl;void sdbout_init ();void sdbout_symbol ();void sdbout_types();static void sdbout_typedefs ();static void sdbout_syms ();static void sdbout_one_type ();static void sdbout_queue_anonymous_type ();static void sdbout_dequeue_anonymous_types ();static int plain_type_1 ();/* Define the default sizes for various types.  */#ifndef CHAR_TYPE_SIZE#define CHAR_TYPE_SIZE BITS_PER_UNIT#endif#ifndef SHORT_TYPE_SIZE#define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))#endif#ifndef INT_TYPE_SIZE#define INT_TYPE_SIZE BITS_PER_WORD#endif#ifndef LONG_TYPE_SIZE#define LONG_TYPE_SIZE BITS_PER_WORD#endif#ifndef LONG_LONG_TYPE_SIZE#define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)#endif#ifndef FLOAT_TYPE_SIZE#define FLOAT_TYPE_SIZE BITS_PER_WORD#endif#ifndef DOUBLE_TYPE_SIZE#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)#endif#ifndef LONG_DOUBLE_TYPE_SIZE#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)#endif/* Random macros describing parts of SDB data.  *//* Put something here if lines get too long */#define CONTIN/* Default value of delimiter is ";".  */#ifndef SDB_DELIM#define SDB_DELIM	";"#endif/* Maximum number of dimensions the assembler will allow.  */#ifndef SDB_MAX_DIM#define SDB_MAX_DIM 4#endif#ifndef PUT_SDB_SCL#define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)#endif#ifndef PUT_SDB_INT_VAL#define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d%s", (a), SDB_DELIM)#endif#ifndef PUT_SDB_VAL#define PUT_SDB_VAL(a)				\( fputs ("\t.val\t", asm_out_file),		\  output_addr_const (asm_out_file, (a)),	\  fprintf (asm_out_file, SDB_DELIM))#endif#ifndef PUT_SDB_DEF#define PUT_SDB_DEF(a)				\do { fprintf (asm_out_file, "\t.def\t");	\     ASM_OUTPUT_LABELREF (asm_out_file, a); 	\     fprintf (asm_out_file, SDB_DELIM); } while (0)#endif#ifndef PUT_SDB_PLAIN_DEF#define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)#endif#ifndef PUT_SDB_ENDEF#define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)#endif#ifndef PUT_SDB_TYPE#define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)#endif#ifndef PUT_SDB_SIZE#define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d%s", a, SDB_DELIM)#endif#ifndef PUT_SDB_START_DIM#define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")#endif#ifndef PUT_SDB_NEXT_DIM#define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)#endif#ifndef PUT_SDB_LAST_DIM#define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)#endif#ifndef PUT_SDB_TAG#define PUT_SDB_TAG(a)				\do { fprintf (asm_out_file, "\t.tag\t");	\     ASM_OUTPUT_LABELREF (asm_out_file, a);	\     fprintf (asm_out_file, SDB_DELIM); } while (0)#endif#ifndef PUT_SDB_BLOCK_START#define PUT_SDB_BLOCK_START(LINE)		\  fprintf (asm_out_file,			\	   "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \	   SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)#endif#ifndef PUT_SDB_BLOCK_END#define PUT_SDB_BLOCK_END(LINE)			\  fprintf (asm_out_file,			\	   "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n",  \	   SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)#endif#ifndef PUT_SDB_FUNCTION_START#define PUT_SDB_FUNCTION_START(LINE)		\  fprintf (asm_out_file,			\	   "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \	   SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)#endif#ifndef PUT_SDB_FUNCTION_END#define PUT_SDB_FUNCTION_END(LINE)		\  fprintf (asm_out_file,			\	   "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \	   SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)#endif#ifndef PUT_SDB_EPILOGUE_END#define PUT_SDB_EPILOGUE_END(NAME)			\do { fprintf (asm_out_file, "\t.def\t");		\     ASM_OUTPUT_LABELREF (asm_out_file, NAME);		\     fprintf (asm_out_file,				\	      "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",	\	      SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)#endif#ifndef SDB_GENERATE_FAKE#define SDB_GENERATE_FAKE(BUFFER, NUMBER) \  sprintf ((BUFFER), ".%dfake", (NUMBER));#endif/* Return the sdb tag identifier string for TYPE   if TYPE has already been defined; otherwise return a null pointer.   */#define KNOWN_TYPE_TAG(type)  TYPE_SYMTAB_POINTER (type)/* Set the sdb tag identifier string for TYPE to NAME.  */#define SET_KNOWN_TYPE_TAG(TYPE, NAME) \  TYPE_SYMTAB_POINTER (TYPE) = (NAME)/* Return the name (a string) of the struct, union or enum tag   described by the TREE_LIST node LINK.  This is 0 for an anonymous one.  */#define TAG_NAME(link) \  (((link) && TREE_PURPOSE ((link)) \    && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \   ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)/* Ensure we don't output a negative line number.  */#define MAKE_LINE_SAFE(line)  \  if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1/* Set up for SDB output at the start of compilation.  */voidsdbout_init (asm_file, input_file_name, syms)     FILE *asm_file;     char *input_file_name;     tree syms;{#ifdef RMS_QUICK_HACK_1  tree t;  for (t = syms; t; t = TREE_CHAIN (t))    if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0	&& !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))      sdbout_symbol (t, 0);#endif  #if 0 /* Nothing need be output for the predefined types.  */  /* Get all permanent types that have typedef names,     and output them all, except for those already output.  */  sdbout_typedefs (syms);#endif}#if 0/* return the tag identifier for type */char *tag_of_ru_type (type,link)     tree type,link;{  if (TYPE_SYMTAB_ADDRESS (type))    return TYPE_SYMTAB_ADDRESS (type);  if (link && TREE_PURPOSE (link)      && IDENTIFIER_POINTER (TREE_PURPOSE (link)))    TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));  else    return (char *) TYPE_SYMTAB_ADDRESS (type);}#endif/* Return a unique string to name an anonymous type.  */static char *gen_fake_label (){  char label[10];  char *labelstr;  SDB_GENERATE_FAKE (label, unnamed_struct_number);  unnamed_struct_number++;  labelstr = (char *) permalloc (strlen (label) + 1);  strcpy (labelstr, label);  return labelstr;}/* Return the number which describes TYPE for SDB.   For pointers, etc., this function is recursive.   Each record, union or enumeral type must already have had a   tag number output.  *//* The number is given by d6d5d4d3d2d1bbbb   where bbbb is 4 bit basic type, and di indicate  one of notype,ptr,fn,array.   Thus, char *foo () has bbbb=T_CHAR			  d1=D_FCN			  d2=D_PTR N_BTMASK=     017       1111     basic type field. N_TSHIFT=       2                derived type shift N_BTSHFT=       4                Basic type shift *//* Produce the number that describes a pointer, function or array type.   PREV is the number describing the target, value or element type.   DT_type describes how to transform that type.  */#define PUSH_DERIVED_LEVEL(DT_type,PREV)		\  ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT)		\   | ((int)DT_type << (int)N_BTSHFT)			\   | ((PREV) & (int)N_BTMASK))/* Number of elements used in sdb_dims.  */static int sdb_n_dims = 0;/* Table of array dimensions of current type.  */static int sdb_dims[SDB_MAX_DIM];/* Size of outermost array currently being processed.  */static int sdb_type_size = -1;static intplain_type (type)     tree type;{  int val = plain_type_1 (type, 0);  /* If we have already saved up some array dimensions, print them now.  */  if (sdb_n_dims > 0)    {      int i;      PUT_SDB_START_DIM;      for (i = sdb_n_dims - 1; i > 0; i--)	PUT_SDB_NEXT_DIM (sdb_dims[i]);      PUT_SDB_LAST_DIM (sdb_dims[0]);      sdb_n_dims = 0;      sdb_type_size = int_size_in_bytes (type);      /* Don't kill sdb if type is not laid out or has variable size.  */      if (sdb_type_size < 0)	sdb_type_size = 0;    }  /* If we have computed the size of an array containing this type,     print it now.  */  if (sdb_type_size >= 0)    {      PUT_SDB_SIZE (sdb_type_size);      sdb_type_size = -1;    }  return val;}static inttemplate_name_p (name)     tree name;{  register char *ptr = IDENTIFIER_POINTER (name);  while (*ptr && *ptr != '<')    ptr++;  return *ptr != '\0';}static voidsdbout_record_type_name (type)     tree type;{  char *name = 0;  int no_name;  if (KNOWN_TYPE_TAG (type))    return;  if (TYPE_NAME (type) != 0)    {      tree t = 0;      /* Find the IDENTIFIER_NODE for the type name.  */      if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)	t = TYPE_NAME (type);      else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)	{	  t = DECL_NAME (TYPE_NAME (type));	  /* The DECL_NAME for templates includes "<>", which breaks	     most assemblers.  Use its assembler name instead, which	     has been mangled into being safe.  */	  if (t && template_name_p (t))	    t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));	}      /* Now get the name as a string, or invent one.  */      if (t != NULL_TREE)	name = IDENTIFIER_POINTER (t);    }  no_name = (name == 0 || *name == 0);  if (no_name)    name = gen_fake_label ();  SET_KNOWN_TYPE_TAG (type, name);#ifdef SDB_ALLOW_FORWARD_REFERENCES  if (no_name)    sdbout_queue_anonymous_type (type);#endif}/* Return the .type value for type TYPE.   LEVEL indicates how many levels deep we have recursed into the type.   The SDB debug format can only represent 6 derived levels of types.   After that, we must output inaccurate debug info.  We deliberately   stop before the 7th level, so that ADA recursive types will not give an   infinite loop.  */static intplain_type_1 (type, level)     tree type;     int level;{  if (type == 0)    type = void_type_node;  else if (type == error_mark_node)    type = integer_type_node;  else    type = TYPE_MAIN_VARIANT (type);  switch (TREE_CODE (type))    {    case VOID_TYPE:      return T_VOID;    case INTEGER_TYPE:      {	int size = int_size_in_bytes (type) * BITS_PER_UNIT;	/* Carefully distinguish all the standard types of C,	   without messing up if the language is not C.	   Note that we check only for the names that contain spaces;	   other names might occur by coincidence in other languages.  */	if (TYPE_NAME (type) != 0	    && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL	    && DECL_NAME (TYPE_NAME (type)) != 0	    && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)	  {	    char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));	    if (!strcmp (name, "unsigned char"))	      return T_UCHAR;	    if (!strcmp (name, "signed char"))	      return T_CHAR;	    if (!strcmp (name, "unsigned int"))	      return T_UINT;	    if (!strcmp (name, "short int"))	      return T_SHORT;	    if (!strcmp (name, "short unsigned int"))	      return T_USHORT;	    if (!strcmp (name, "long int"))	      return T_LONG;	    if (!strcmp (name, "long unsigned int"))	      return T_ULONG;	  }	if (size == CHAR_TYPE_SIZE)	  return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);	if (size == SHORT_TYPE_SIZE)	  return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);	if (size == INT_TYPE_SIZE)	  return (TREE_UNSIGNED (type) ? T_UINT : T_INT);	if (size == LONG_TYPE_SIZE)	  return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);	if (size == LONG_LONG_TYPE_SIZE)	/* better than nothing */

⌨️ 快捷键说明

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