X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=gcc%2Fmips-tdump.c;h=d7040d95b70aecc1091464768ddbc49a8e082139;hp=6ca005ad6dc6f0b2a3c411758e8205120081ab01;hb=1268285a29c29c7772fc29e3ab2e19fc4d264cc2;hpb=47003e2a6cf44c989099e779402cdb9f3b2bedd6 diff --git a/gcc/mips-tdump.c b/gcc/mips-tdump.c index 6ca005ad6dc..d7040d95b70 100644 --- a/gcc/mips-tdump.c +++ b/gcc/mips-tdump.c @@ -1,31 +1,30 @@ /* Read and manage MIPS symbol tables from object modules. - Copyright (C) 1991, 1994, 1995, 1997 Free Software Foundation, Inc. + Copyright (C) 1991, 1994, 1995, 1997, 1998, 1999, 2000, 2001 + Free Software Foundation, Inc. Contributed by hartzell@boulder.colorado.edu, Rewritten by meissner@osf.org. -This file is part of GNU CC. +This file is part of GCC. -GNU CC 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, or (at your option) -any later version. +GCC 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, 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 of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +GCC 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 GNU CC; see the file COPYING. If not, write to -the Free Software Foundation, 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ +along with GCC; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. */ #include "config.h" #include "system.h" - #ifdef index #undef index -#undef rindex #endif #ifndef CROSS_COMPILE #include @@ -47,41 +46,13 @@ Boston, MA 02111-1307, USA. */ #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK) #endif -#ifdef __STDC__ -typedef void *PTR_T; -typedef const void *CPTR_T; -#define __proto(x) x -#else - -#if defined(_STDIO_H_) || defined(__STDIO_H__) /* Ultrix 4.0, SGI */ -typedef void *PTR_T; -typedef void *CPTR_T; - -#else -typedef char *PTR_T; /* Ultrix 3.1 */ -typedef char *CPTR_T; -#endif - -#define __proto(x) () -#define const -#endif - #define uchar unsigned char #define ushort unsigned short #define uint unsigned int #define ulong unsigned long - -/* Do to size_t being defined in sys/types.h and different - in stddef.h, we have to do this by hand..... Note, these - types are correct for MIPS based systems, and may not be - correct for other systems. */ - -#define size_t uint -#define ptrdiff_t int - -/* Redefinition of of storage classes as an enumeration for better +/* Redefinition of storage classes as an enumeration for better debugging. */ #ifndef stStaParam @@ -255,26 +226,19 @@ ulong *rfile_desc; /* relative file tables */ PDR *proc_desc; /* procedure tables */ /* Forward reference for functions. */ -PTR_T read_seek __proto((PTR_T, size_t, off_t, const char *)); -void read_tfile __proto((void)); -void print_global_hdr __proto((struct filehdr *)); -void print_sym_hdr __proto((HDRR *)); -void print_file_desc __proto((FDR *, int)); -void print_symbol __proto((SYMR *, int, char *, AUXU *, int, FDR *)); -void print_aux __proto((AUXU, int, int)); -void emit_aggregate __proto((char *, AUXU, AUXU, const char *, FDR *)); -char *st_to_string __proto((st_t)); -char *sc_to_string __proto((sc_t)); -char *glevel_to_string __proto((glevel_t)); -char *lang_to_string __proto((lang_t)); -char *type_to_string __proto((AUXU *, int, FDR *)); - -#ifndef __alpha -extern PTR_T malloc __proto((size_t)); -extern PTR_T calloc __proto((size_t, size_t)); -extern PTR_T realloc __proto((PTR_T, size_t)); -extern void free __proto((PTR_T)); -#endif +static PTR read_seek PARAMS ((PTR, size_t, off_t, const char *)); +static void read_tfile PARAMS ((void)); +static void print_global_hdr PARAMS ((struct filehdr *)); +static void print_sym_hdr PARAMS ((HDRR *)); +static void print_file_desc PARAMS ((FDR *, int)); +static void print_symbol PARAMS ((SYMR *, int, const char *, AUXU *, int, FDR *)); +static void print_aux PARAMS ((AUXU, int, int)); +static void emit_aggregate PARAMS ((char *, AUXU, AUXU, const char *, FDR *)); +static const char *st_to_string PARAMS ((st_t)); +static const char *sc_to_string PARAMS ((sc_t)); +static const char *glevel_to_string PARAMS ((glevel_t)); +static const char *lang_to_string PARAMS ((lang_t)); +static const char *type_to_string PARAMS ((AUXU *, int, FDR *)); extern char *optarg; extern int optind; @@ -283,7 +247,7 @@ extern int opterr; /* Create a table of debugging stab-codes and corresponding names. */ #define __define_stab(NAME, CODE, STRING) {(int)CODE, STRING}, -struct {short code; char string[10];} stab_names[] = { +const struct {const short code; const char string[10];} stab_names[] = { #include "stab.def" #undef __define_stab }; @@ -291,9 +255,9 @@ struct {short code; char string[10];} stab_names[] = { /* Read some bytes at a specified location, and return a pointer. */ -PTR_T +static PTR read_seek (ptr, size, offset, context) - PTR_T ptr; /* pointer to buffer or NULL */ + PTR ptr; /* pointer to buffer or NULL */ size_t size; /* # bytes to read */ off_t offset; /* offset to read at */ const char *context; /* context for error message */ @@ -303,15 +267,17 @@ read_seek (ptr, size, offset, context) if (size == 0) /* nothing to read */ return ptr; - if ((ptr == (PTR_T) 0 && (ptr = malloc (size)) == (PTR_T) 0) - || (tfile_offset != offset && lseek (tfile_fd, offset, 0) == -1) + if (!ptr) + ptr = xmalloc (size); + + if ((tfile_offset != offset && lseek (tfile_fd, offset, 0) == -1) || (read_size = read (tfile_fd, ptr, size)) < 0) { perror (context); exit (1); } - if (read_size != size) + if (read_size != (long) size) { fprintf (stderr, "%s: read %ld bytes, expected %ld bytes\n", context, read_size, (long) size); @@ -325,7 +291,7 @@ read_seek (ptr, size, offset, context) /* Convert language code to string format. */ -char * +static const char * lang_to_string (lang) lang_t lang; { @@ -348,7 +314,7 @@ lang_to_string (lang) /* Convert storage class to string. */ -char * +static const char * sc_to_string(storage_class) sc_t storage_class; { @@ -386,7 +352,7 @@ sc_to_string(storage_class) /* Convert symbol type to string. */ -char * +static const char * st_to_string(symbol_type) st_t symbol_type; { @@ -427,7 +393,7 @@ st_to_string(symbol_type) /* Convert debug level to string. */ -char * +static const char * glevel_to_string (g_level) glevel_t g_level; { @@ -445,7 +411,7 @@ glevel_to_string (g_level) /* Convert the type information to string format. */ -char * +static const char * type_to_string (aux_ptr, index, fdp) AUXU *aux_ptr; int index; @@ -758,7 +724,7 @@ type_to_string (aux_ptr, index, fdp) /* Print out the global file header for object files. */ -void +static void print_global_hdr (ptr) struct filehdr *ptr; { @@ -813,7 +779,7 @@ print_global_hdr (ptr) /* Print out the symbolic header. */ -void +static void print_sym_hdr (sym_ptr) HDRR *sym_ptr; { @@ -887,11 +853,11 @@ print_sym_hdr (sym_ptr) /* Print out a symbol. */ -void +static void print_symbol (sym_ptr, number, strbase, aux_base, ifd, fdp) SYMR *sym_ptr; int number; - char *strbase; + const char *strbase; AUXU *aux_base; int ifd; FDR *fdp; @@ -917,7 +883,7 @@ print_symbol (sym_ptr, number, strbase, aux_base, ifd, fdp) if (want_scope) { if (free_scope == (scope_t *) 0) - scope_ptr = (scope_t *) malloc (sizeof (scope_t)); + scope_ptr = (scope_t *) xmalloc (sizeof (scope_t)); else { scope_ptr = free_scope; @@ -937,7 +903,7 @@ print_symbol (sym_ptr, number, strbase, aux_base, ifd, fdp) else { used_ptr[index] = 1; - printf (" First symbol: %ld\n", aux_base[index].isym); + printf (" First symbol: %ld\n", (long) aux_base[index].isym); } if (want_scope) @@ -962,7 +928,7 @@ print_symbol (sym_ptr, number, strbase, aux_base, ifd, fdp) { used_ptr[index] = used_ptr[index+1] = 1; printf (" End+1 symbol: %-7ld Type: %s\n", - aux_base[index].isym, + (long) aux_base[index].isym, type_to_string (aux_base, index+1, fdp)); } else /* global symbol */ @@ -971,7 +937,7 @@ print_symbol (sym_ptr, number, strbase, aux_base, ifd, fdp) if (want_scope) { if (free_scope == (scope_t *) 0) - scope_ptr = (scope_t *) malloc (sizeof (scope_t)); + scope_ptr = (scope_t *) xmalloc (sizeof (scope_t)); else { scope_ptr = free_scope; @@ -1014,7 +980,7 @@ print_symbol (sym_ptr, number, strbase, aux_base, ifd, fdp) scope_ptr != (scope_t *) 0; scope_ptr = scope_ptr->prev) { - char *class; + const char *class; if (scope_ptr->st == st_Proc || scope_ptr->st == st_StaticProc) class = "func."; else if (scope_ptr->st == st_File) @@ -1045,9 +1011,10 @@ print_symbol (sym_ptr, number, strbase, aux_base, ifd, fdp) if (MIPS_IS_STAB(sym_ptr)) { - register int i = sizeof(stab_names) / sizeof(stab_names[0]); - char *stab_name = "stab"; + int i = ARRAY_SIZE (stab_names); + const char *stab_name = "stab"; short code = MIPS_UNMARK_STAB(sym_ptr->index); + while (--i >= 0) if (stab_names[i].code == code) { @@ -1066,7 +1033,7 @@ print_symbol (sym_ptr, number, strbase, aux_base, ifd, fdp) /* Print out a word from the aux. table in various formats. */ -void +static void print_aux (u, auxi, used) AUXU u; int auxi; @@ -1092,7 +1059,7 @@ print_aux (u, auxi, used) /* Write aggregate information to a string. */ -void +static void emit_aggregate (string, u, u2, which, fdp) char *string; AUXU u; @@ -1132,7 +1099,7 @@ emit_aggregate (string, u, u2, which, fdp) /* Print out information about a file descriptor, and the symbols, procedures, and line numbers within it. */ -void +static void print_file_desc (fdp, number) FDR *fdp; int number; @@ -1147,8 +1114,10 @@ print_file_desc (fdp, number) aux_base = aux_symbols + fdp->iauxBase; used_base = aux_used + (aux_base - aux_symbols); - printf ("\nFile #%d, \"%s\"\n\n", number, str_base + fdp->rss); - + printf ("\nFile #%d, \"%s\"\n\n", + number, + fdp->rss != issNil ? str_base + fdp->rss : ""); + printf (" Name index = %-10ld Readin = %s\n", (long) fdp->rss, (fdp->fReadin) ? "Yes" : "No"); @@ -1264,7 +1233,7 @@ print_file_desc (fdp, number) (ulong) fdp->rfdBase); rfd_ptr = rfile_desc + fdp->rfdBase; - for (i = 0; i < fdp->crfd; i++) + for (i = 0; i < (ulong) fdp->crfd; i++) { printf ("\t#%-5ld %11ld, 0x%08lx\n", i, *rfd_ptr, *rfd_ptr); rfd_ptr++; @@ -1282,9 +1251,10 @@ print_file_desc (fdp, number) PDR *proc_ptr = &proc_desc[pdi]; printf ("\n\tProcedure descriptor %d:\n", (pdi - fdp->ipdFirst)); - printf ("\t Name index = %-11ld Name = \"%s\"\n", - (long) l_symbols[proc_ptr->isym + fdp->isymBase].iss, - l_symbols[proc_ptr->isym + fdp->isymBase].iss + str_base); + if (l_symbols != 0) + printf ("\t Name index = %-11ld Name = \"%s\"\n", + (long) l_symbols[proc_ptr->isym + fdp->isymBase].iss, + l_symbols[proc_ptr->isym + fdp->isymBase].iss + str_base); printf ("\t .mask 0x%08lx,%-9ld .fmask 0x%08lx,%ld\n", (long) proc_ptr->regmask, @@ -1357,18 +1327,18 @@ print_file_desc (fdp, number) /* Read in the portions of the .T file that we will print out. */ -void -read_tfile __proto((void)) +static void +read_tfile () { short magic; off_t sym_hdr_offset = 0; - (void) read_seek ((PTR_T) &magic, sizeof (magic), (off_t) 0, "Magic number"); + (void) read_seek ((PTR) &magic, sizeof (magic), (off_t) 0, "Magic number"); if (!tfile) { /* Print out the global header, since this is not a T-file. */ - (void) read_seek ((PTR_T) &global_hdr, sizeof (global_hdr), (off_t) 0, + (void) read_seek ((PTR) &global_hdr, sizeof (global_hdr), (off_t) 0, "Global file header"); print_global_hdr (&global_hdr); @@ -1382,74 +1352,67 @@ read_tfile __proto((void)) sym_hdr_offset = global_hdr.f_symptr; } - (void) read_seek ((PTR_T) &sym_hdr, + (void) read_seek ((PTR) &sym_hdr, sizeof (sym_hdr), sym_hdr_offset, "Symbolic header"); print_sym_hdr (&sym_hdr); - lines = (LINER *) read_seek ((PTR_T) 0, + lines = (LINER *) read_seek (NULL, sym_hdr.cbLine, sym_hdr.cbLineOffset, "Line numbers"); - dense_nums = (DNR *) read_seek ((PTR_T) 0, + dense_nums = (DNR *) read_seek (NULL, sym_hdr.idnMax * sizeof (DNR), sym_hdr.cbDnOffset, "Dense numbers"); - proc_desc = (PDR *) read_seek ((PTR_T) 0, + proc_desc = (PDR *) read_seek (NULL, sym_hdr.ipdMax * sizeof (PDR), sym_hdr.cbPdOffset, "Procedure tables"); - l_symbols = (SYMR *) read_seek ((PTR_T) 0, + l_symbols = (SYMR *) read_seek (NULL, sym_hdr.isymMax * sizeof (SYMR), sym_hdr.cbSymOffset, "Local symbols"); - opt_symbols = (OPTR *) read_seek ((PTR_T) 0, + opt_symbols = (OPTR *) read_seek (NULL, sym_hdr.ioptMax * sizeof (OPTR), sym_hdr.cbOptOffset, "Optimization symbols"); - aux_symbols = (AUXU *) read_seek ((PTR_T) 0, + aux_symbols = (AUXU *) read_seek (NULL, sym_hdr.iauxMax * sizeof (AUXU), sym_hdr.cbAuxOffset, "Auxiliary symbols"); if (sym_hdr.iauxMax > 0) - { - aux_used = calloc (sym_hdr.iauxMax, 1); - if (aux_used == (char *) 0) - { - perror ("calloc"); - exit (1); - } - } + aux_used = xcalloc (sym_hdr.iauxMax, 1); - l_strings = (char *) read_seek ((PTR_T) 0, + l_strings = (char *) read_seek (NULL, sym_hdr.issMax, sym_hdr.cbSsOffset, "Local string table"); - e_strings = (char *) read_seek ((PTR_T) 0, + e_strings = (char *) read_seek (NULL, sym_hdr.issExtMax, sym_hdr.cbSsExtOffset, "External string table"); - file_desc = (FDR *) read_seek ((PTR_T) 0, + file_desc = (FDR *) read_seek (NULL, sym_hdr.ifdMax * sizeof (FDR), sym_hdr.cbFdOffset, "File tables"); - rfile_desc = (ulong *) read_seek ((PTR_T) 0, + rfile_desc = (ulong *) read_seek (NULL, sym_hdr.crfd * sizeof (ulong), sym_hdr.cbRfdOffset, "Relative file tables"); - e_symbols = (EXTR *) read_seek ((PTR_T) 0, + e_symbols = (EXTR *) read_seek (NULL, sym_hdr.iextMax * sizeof (EXTR), sym_hdr.cbExtOffset, "External symbols"); @@ -1457,6 +1420,8 @@ read_tfile __proto((void)) +extern int main PARAMS ((int, char **)); + int main (argc, argv) int argc; @@ -1582,31 +1547,3 @@ main (argc, argv) return 0; } - - -void -fancy_abort () -{ - fprintf (stderr, "mips-tdump internal error"); - exit (1); -} - -void -fatal(s) -char *s; -{ - fprintf(stderr, "%s\n", s); - exit(1); -} - -/* Same as `malloc' but report error if no memory available. */ - -PTR_T -xmalloc (size) - unsigned size; -{ - register PTR_T value = malloc (size); - if (value == 0) - fatal ("Virtual memory exhausted."); - return value; -}