diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-03-22 05:18:32 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-03-22 05:18:32 +0000 |
commit | 7c67d3134ec53a23ac833b10e0de842f21764474 (patch) | |
tree | ec4a490e5d7334da26e387cd944fda31666ca810 /usr.bin/gprof/gprof.c | |
parent | d93057278dedc689aefd0a88d48d49744ff95d9f (diff) |
_wall, err/warn; dummy hppa part, like others
Diffstat (limited to 'usr.bin/gprof/gprof.c')
-rw-r--r-- | usr.bin/gprof/gprof.c | 158 |
1 files changed, 60 insertions, 98 deletions
diff --git a/usr.bin/gprof/gprof.c b/usr.bin/gprof/gprof.c index 1829f9087af..afed1ac963f 100644 --- a/usr.bin/gprof/gprof.c +++ b/usr.bin/gprof/gprof.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gprof.c,v 1.6 2000/12/24 00:28:46 aaron Exp $ */ +/* $OpenBSD: gprof.c,v 1.7 2001/03/22 05:18:30 mickey Exp $ */ /* $NetBSD: gprof.c,v 1.8 1995/04/19 07:15:59 cgd Exp $ */ /* @@ -44,14 +44,12 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)gprof.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: gprof.c,v 1.6 2000/12/24 00:28:46 aaron Exp $"; +static char rcsid[] = "$OpenBSD: gprof.c,v 1.7 2001/03/22 05:18:30 mickey Exp $"; #endif #endif /* not lint */ #include "gprof.h" -char *whoami = "gprof"; - /* * things which get -E excluded by default. */ @@ -59,6 +57,7 @@ char *defaultEs[] = { "mcount" , "__mcleanup" , 0 }; static struct gmonhdr gmonhdr; +int main(argc, argv) int argc; char **argv; @@ -87,7 +86,7 @@ main(argc, argv) #if defined(__i386__) || defined(__vax__) || defined(__tahoe__) || defined(__sparc__) cflag = TRUE; #else - fprintf(stderr, "gprof: -c isn't supported on this architecture yet\n"); + fprintf(stderr, "%s: -c isn't supported on this architecture yet\n", __progname); exit(1); #endif break; @@ -99,7 +98,7 @@ main(argc, argv) # ifdef DEBUG printf("[main] debug = %d\n", debug); # else not DEBUG - printf("%s: -d ignored\n", whoami); + warnx("-d ignored"); # endif DEBUG break; case 'E': @@ -178,7 +177,7 @@ main(argc, argv) */ if (hz == 0) { hz = 1; - fprintf(stderr, "time is in ticks, not seconds\n"); + warnx("time is in ticks, not seconds"); } /* * dump out a gmon.sum file if requested @@ -206,7 +205,8 @@ main(argc, argv) * print the index */ printindex(); - done(); + + return (0); } /* @@ -214,21 +214,18 @@ main(argc, argv) * and optionally the text space. * On return symbol table is sorted by value. */ +void getnfile() { FILE *nfile; int valcmp(); nfile = fopen( a_outname ,"r"); - if (nfile == NULL) { - perror( a_outname ); - done(); - } + if (nfile == NULL) + err(1, "fopen: %s", a_outname); fread(&xbuf, 1, sizeof(xbuf), nfile); - if (N_BADMAG(xbuf)) { - fprintf(stderr, "%s: %s: bad format\n", whoami , a_outname ); - done(); - } + if (N_BADMAG(xbuf)) + errx(1, "%s: bad format", a_outname ); getstrtab(nfile); getsymtab(nfile); gettextspace( nfile ); @@ -245,32 +242,25 @@ getnfile() # endif DEBUG } +void getstrtab(nfile) FILE *nfile; { fseek(nfile, (long)(N_SYMOFF(xbuf) + xbuf.a_syms), 0); - if (fread(&ssiz, sizeof (ssiz), 1, nfile) == 0) { - fprintf(stderr, "%s: %s: no string table (old format?)\n" , - whoami , a_outname ); - done(); - } + if (fread(&ssiz, sizeof (ssiz), 1, nfile) == 0) + errx(1, "%s: no string table (old format?)" , a_outname); strtab = calloc(ssiz, 1); - if (strtab == NULL) { - fprintf(stderr, "%s: %s: no room for %d bytes of string table\n", - whoami , a_outname , ssiz); - done(); - } - if (fread(strtab+sizeof(ssiz), ssiz-sizeof(ssiz), 1, nfile) != 1) { - fprintf(stderr, "%s: %s: error reading string table\n", - whoami , a_outname ); - done(); - } + if (strtab == NULL) + errx(1, "%s: no room for %ld bytes of string table", a_outname , ssiz); + if (fread(strtab+sizeof(ssiz), ssiz-sizeof(ssiz), 1, nfile) != 1) + err(1, "%s: reading string table", a_outname); } /* * Read in symbol table */ +void getsymtab(nfile) FILE *nfile; { @@ -288,17 +278,13 @@ getsymtab(nfile) } nname++; } - if (nname == 0) { - fprintf(stderr, "%s: %s: no symbols\n", whoami , a_outname ); - done(); - } + if (nname == 0) + errx(1, "%s: no symbols", a_outname); askfor = nname + 1; nl = (nltype *) calloc( askfor , sizeof(nltype) ); - if (nl == 0) { - fprintf(stderr, "%s: No room for %d bytes of symbol table\n", - whoami, askfor * sizeof(nltype) ); - done(); - } + if (nl == 0) + errx(1, "No room for %d bytes of symbol table", + askfor * sizeof(nltype)); /* pass2 - read symbols */ fseek(nfile, (long)N_SYMOFF(xbuf), 0); @@ -332,6 +318,7 @@ getsymtab(nfile) /* * read in the text space of an a.out file */ +void gettextspace( nfile ) FILE *nfile; { @@ -341,17 +328,14 @@ gettextspace( nfile ) } textspace = (u_char *) malloc( xbuf.a_text ); if ( textspace == 0 ) { - fprintf( stderr , "%s: ran out room for %d bytes of text space: " , - whoami , xbuf.a_text ); - fprintf( stderr , "can't do -c\n" ); + warnx("ran out room for %d bytes of text space: can't do -c", xbuf.a_text ); return; } (void) fseek( nfile , N_TXTOFF( xbuf ) , 0 ); if ( fread( textspace , 1 , xbuf.a_text , nfile ) != xbuf.a_text ) { - fprintf( stderr , "%s: couldn't read text space: " , whoami ); - fprintf( stderr , "can't do -c\n" ); + warnx("couldn't read text space: can't do -c"); free( textspace ); - textspace = 0; + textspace = NULL; return; } } @@ -360,6 +344,7 @@ gettextspace( nfile ) * an array of sampling hits within pc ranges, * and the arcs. */ +void getpfile(filename) char *filename; { @@ -397,16 +382,12 @@ openpfile(filename) int size; int rate; - if((pfile = fopen(filename, "r")) == NULL) { - perror(filename); - done(); - } + if((pfile = fopen(filename, "r")) == NULL) + err(1, "fopen: %s", filename); fread(&tmp, sizeof(struct gmonhdr), 1, pfile); if ( s_highpc != 0 && ( tmp.lpc != gmonhdr.lpc || - tmp.hpc != gmonhdr.hpc || tmp.ncnt != gmonhdr.ncnt ) ) { - fprintf(stderr, "%s: incompatible with first gmon file\n", filename); - done(); - } + tmp.hpc != gmonhdr.hpc || tmp.ncnt != gmonhdr.ncnt)) + errx(1, "%s: incompatible with first gmon file", filename); gmonhdr = tmp; if ( gmonhdr.version == GMONVERSION ) { rate = gmonhdr.profrate; @@ -419,12 +400,9 @@ openpfile(filename) } if (hz == 0) { hz = rate; - } else if (hz != rate) { - fprintf(stderr, - "%s: profile clock rate (%d) %s (%d) in first gmon file\n", - filename, rate, "incompatible with clock rate", hz); - done(); - } + } else if (hz != rate) + errx(1, "%s: profile clock rate (%d) incompatible with clock rate " + "(%ld) in first gmon file", filename, rate, hz); s_lowpc = (unsigned long) gmonhdr.lpc; s_highpc = (unsigned long) gmonhdr.hpc; lowpc = (unsigned long)gmonhdr.lpc / sizeof(UNIT); @@ -447,6 +425,7 @@ openpfile(filename) return(pfile); } +void tally( rawp ) struct rawarc *rawp; { @@ -475,6 +454,7 @@ tally( rawp ) /* * dump out the gmon.sum file */ +void dumpsum( sumfile ) char *sumfile; { @@ -483,24 +463,18 @@ dumpsum( sumfile ) struct rawarc arc; FILE *sfile; - if ( ( sfile = fopen ( sumfile , "w" ) ) == NULL ) { - perror( sumfile ); - done(); - } + if ( ( sfile = fopen ( sumfile , "w" ) ) == NULL ) + err(1, "fopen: %s", sumfile); /* * dump the header; use the last header read in */ - if ( fwrite( &gmonhdr , sizeof gmonhdr , 1 , sfile ) != 1 ) { - perror( sumfile ); - done(); - } + if ( fwrite( &gmonhdr , sizeof gmonhdr , 1 , sfile ) != 1 ) + err(1, "fwrite: %s", sumfile); /* * dump the samples */ - if (fwrite(samples, sizeof (UNIT), nsamples, sfile) != nsamples) { - perror( sumfile ); - done(); - } + if (fwrite(samples, sizeof (UNIT), nsamples, sfile) != nsamples) + err(1, "fwrite: %s", sumfile); /* * dump the normalized raw arc information */ @@ -509,10 +483,8 @@ dumpsum( sumfile ) arc.raw_frompc = arcp -> arc_parentp -> value; arc.raw_selfpc = arcp -> arc_childp -> value; arc.raw_count = arcp -> arc_count; - if ( fwrite ( &arc , sizeof arc , 1 , sfile ) != 1 ) { - perror( sumfile ); - done(); - } + if (fwrite ( &arc , sizeof arc , 1 , sfile ) != 1) + err(1, "fwrite: %s", sumfile); # ifdef DEBUG if ( debug & SAMPLEDEBUG ) { printf( "[dumpsum] frompc 0x%x selfpc 0x%x count %d\n" , @@ -524,6 +496,7 @@ dumpsum( sumfile ) fclose( sfile ); } +int valcmp(p1, p2) nltype *p1, *p2; { @@ -536,19 +509,17 @@ valcmp(p1, p2) return EQUALTO; } +void readsamples(pfile) FILE *pfile; { - register i; UNIT sample; + register int i; if (samples == 0) { samples = (UNIT *) calloc(sampbytes, sizeof (UNIT)); - if (samples == 0) { - fprintf( stderr , "%s: No room for %d sample pc's\n", - whoami , sampbytes / sizeof (UNIT)); - done(); - } + if (samples == 0) + errx(1, "No room for %d sample pc's", sampbytes / sizeof (UNIT)); } for (i = 0; i < nsamples; i++) { fread(&sample, sizeof (UNIT), 1, pfile); @@ -556,12 +527,8 @@ readsamples(pfile) break; samples[i] += sample; } - if (i != nsamples) { - fprintf(stderr, - "%s: unexpected EOF after reading %d/%d samples\n", - whoami , i , nsamples ); - done(); - } + if (i != nsamples) + errx(1, "unexpected EOF after reading %d/%d samples", i, nsamples ); } /* @@ -596,6 +563,7 @@ readsamples(pfile) * only one sample for every four bytes of text space and never * have any overlap (the two end cases, above). */ +void asgnsamples() { register int j; @@ -685,6 +653,7 @@ max(a, b) * if it turns out that the entry point is in one bucket and the code * for a routine is in the next bucket. */ +void alignentries() { register struct nl *nlp; @@ -742,16 +711,9 @@ funcsymbol( nlistp ) return TRUE; } #endif - while ( c = *name++ ) { - if ( c == '.' ) { + while ((c = *name++)) + if (c == '.') return FALSE; - } - } - return TRUE; -} -done() -{ - - exit(0); + return TRUE; } |