sdbout.c

来自「GCC编译器源代码」· C语言 代码 · 共 1,635 行 · 第 1/4 页

C
1,635
字号
/* Output sdb-format symbol table information from GNU compiler.   Copyright (C) 1988, 92, 93, 94, 95, 96, 1997 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 <stdio.h>#include "tree.h"#include "rtl.h"#include "regs.h"#include "defaults.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.  Which syms.h file to use is a   target parameter so don't use the native one if we're cross compiling.  */#if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(_WIN32) && !defined(__linux__) && !defined(CROSS_COMPILE)#include <syms.h>/* Use T_INT if we don't have T_VOID.  */#ifndef T_VOID#define T_VOID T_INT#endif#else#include "gsyms.h"#endif/* #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 char *gen_fake_label		PROTO((void));static int plain_type			PROTO((tree));static int template_name_p		PROTO((tree));static void sdbout_record_type_name	PROTO((tree));static int plain_type_1			PROTO((tree, int));static void sdbout_block		PROTO((tree));static void sdbout_syms			PROTO((tree));static void sdbout_queue_anonymous_type	PROTO((tree));static void sdbout_dequeue_anonymous_types PROTO((void));static void sdbout_type			PROTO((tree));static void sbdout_field_types		PROTO((tree));static void sdbout_one_type		PROTO((tree));static void sdbout_parms		PROTO((tree));static void sdbout_reg_parms		PROTO((tree));/* 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/* Perform linker optimization of merging header file definitions together   for targets with MIPS_DEBUGGING_INFO defined.  This won't work without a   post 960826 version of GAS.  Nothing breaks with earlier versions of GAS,   the optimization just won't be done.  The native assembler already has the   necessary support.  */#ifdef MIPS_DEBUGGING_INFO#ifndef PUT_SDB_SRC_FILE#define PUT_SDB_SRC_FILE(FILENAME) \output_file_directive (asm_out_file, (FILENAME))#endif/* ECOFF linkers have an optimization that does the same kind of thing as   N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the   executable.  To achieve this, GCC must output a .file for each file   name change.  *//* This is a stack of input files.  */struct sdb_file{  struct sdb_file *next;  char *name;};/* This is the top of the stack.  */static struct sdb_file *current_file;#endif /* MIPS_DEBUGGING_INFO *//* 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 MIPS_DEBUGGING_INFO  current_file = (struct sdb_file *) xmalloc (sizeof *current_file);  current_file->next = NULL;  current_file->name = input_file_name;#endif#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/* 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;

⌨️ 快捷键说明

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