mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-09-10 12:22:20 +08:00
Fixed bugs (both typos and algorithmic) bugs. It now matches native gprof's
on both the sparc (SunOS) and Mach386 systems, more or less. (The differences are at least partially due to what I think might be bugs in the native gprof.)
This commit is contained in:
@ -29,6 +29,8 @@ static char sccsid[] = "@(#)gprof.c 5.6 (Berkeley) 6/1/90";
|
|||||||
|
|
||||||
#include "gprof.h"
|
#include "gprof.h"
|
||||||
|
|
||||||
|
bfd *abfd;
|
||||||
|
|
||||||
char *whoami = "gprof";
|
char *whoami = "gprof";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -185,7 +187,6 @@ main(argc, argv)
|
|||||||
*/
|
*/
|
||||||
getnfile()
|
getnfile()
|
||||||
{
|
{
|
||||||
bfd *abfd;
|
|
||||||
int valcmp();
|
int valcmp();
|
||||||
|
|
||||||
abfd = bfd_openr (a_outname, NULL);
|
abfd = bfd_openr (a_outname, NULL);
|
||||||
@ -216,33 +217,9 @@ getnfile()
|
|||||||
# endif DEBUG
|
# endif DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
/*
|
||||||
getstrtab(nfile)
|
* Read in symbol table
|
||||||
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();
|
|
||||||
}
|
|
||||||
strtab = (char *)calloc(ssiz, 1);
|
|
||||||
if (strtab == NULL) {
|
|
||||||
fprintf(stderr, "%s: %s: no room for %d bytes of string table",
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* 0 */
|
|
||||||
/*
|
|
||||||
* Read in symbol table
|
|
||||||
*/
|
|
||||||
getsymtab(abfd)
|
getsymtab(abfd)
|
||||||
bfd *abfd;
|
bfd *abfd;
|
||||||
{
|
{
|
||||||
@ -349,6 +326,9 @@ getpfile(filename)
|
|||||||
* a bunch of <from,self,count> tuples.
|
* a bunch of <from,self,count> tuples.
|
||||||
*/
|
*/
|
||||||
while ( fread( &arc , sizeof arc , 1 , pfile ) == 1 ) {
|
while ( fread( &arc , sizeof arc , 1 , pfile ) == 1 ) {
|
||||||
|
arc.raw_frompc = bfd_get_32 (abfd, &arc.raw_frompc);
|
||||||
|
arc.raw_selfpc = bfd_get_32 (abfd, &arc.raw_selfpc);
|
||||||
|
arc.raw_count = bfd_get_32 (abfd, &arc.raw_count);
|
||||||
# ifdef DEBUG
|
# ifdef DEBUG
|
||||||
if ( debug & SAMPLEDEBUG ) {
|
if ( debug & SAMPLEDEBUG ) {
|
||||||
printf( "[getpfile] frompc 0x%x selfpc 0x%x count %d\n" ,
|
printf( "[getpfile] frompc 0x%x selfpc 0x%x count %d\n" ,
|
||||||
@ -375,6 +355,10 @@ openpfile(filename)
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
fread(&tmp, sizeof(struct hdr), 1, pfile);
|
fread(&tmp, sizeof(struct hdr), 1, pfile);
|
||||||
|
tmp.lowpc = bfd_get_32 (abfd, &tmp.lowpc);
|
||||||
|
tmp.highpc = bfd_get_32 (abfd, &tmp.highpc);
|
||||||
|
tmp.ncnt = bfd_get_32 (abfd, &tmp.ncnt);
|
||||||
|
|
||||||
if ( s_highpc != 0 && ( tmp.lowpc != h.lowpc ||
|
if ( s_highpc != 0 && ( tmp.lowpc != h.lowpc ||
|
||||||
tmp.highpc != h.highpc || tmp.ncnt != h.ncnt ) ) {
|
tmp.highpc != h.highpc || tmp.ncnt != h.ncnt ) ) {
|
||||||
fprintf(stderr, "%s: incompatible with first gmon file\n", filename);
|
fprintf(stderr, "%s: incompatible with first gmon file\n", filename);
|
||||||
@ -496,15 +480,17 @@ readsamples(pfile)
|
|||||||
UNIT sample;
|
UNIT sample;
|
||||||
|
|
||||||
if (samples == 0) {
|
if (samples == 0) {
|
||||||
samples = (UNIT *) calloc(sampbytes, sizeof (UNIT));
|
samples = (UNIT *) malloc (sampbytes * sizeof(UNIT));
|
||||||
if (samples == 0) {
|
if (samples == 0) {
|
||||||
fprintf( stderr , "%s: No room for %d sample pc's\n",
|
fprintf( stderr , "%s: No room for %d sample pc's\n",
|
||||||
whoami , sampbytes / sizeof (UNIT));
|
whoami , sampbytes / sizeof (UNIT));
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
memset (samples, 0, sampbytes * sizeof(UNIT));
|
||||||
}
|
}
|
||||||
for (i = 0; i < nsamples; i++) {
|
for (i = 0; i < nsamples; i++) {
|
||||||
fread(&sample, sizeof (UNIT), 1, pfile);
|
fread(&sample, sizeof (UNIT), 1, pfile);
|
||||||
|
sample = bfd_get_16 (abfd, &sample);
|
||||||
if (feof(pfile))
|
if (feof(pfile))
|
||||||
break;
|
break;
|
||||||
samples[i] += sample;
|
samples[i] += sample;
|
||||||
@ -667,22 +653,25 @@ funcsymbol( symp )
|
|||||||
extern char *strtab; /* string table from a.out */
|
extern char *strtab; /* string table from a.out */
|
||||||
extern int aflag; /* if static functions aren't desired */
|
extern int aflag; /* if static functions aren't desired */
|
||||||
char *name;
|
char *name;
|
||||||
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* must be a text symbol,
|
* must be a text symbol,
|
||||||
* and static text symbols don't qualify if aflag set.
|
* and static text symbols don't qualify if aflag set.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
if (!symp->section)
|
if (!symp->section)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (!aflag && (symp->flags&BSF_LOCAL)) {
|
if (!aflag && (symp->flags&BSF_LOCAL)) {
|
||||||
#ifdef DEBUG
|
#if defined(DEBUG)
|
||||||
fprintf (stderr, "%s(%d): %s: not a function\n", __FILE__, __LINE__, symp->name);
|
fprintf (stderr, "%s(%d): %s: not a function\n", __FILE__, __LINE__, symp->name);
|
||||||
#endif
|
#endif
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
#endif /* 0 */
|
||||||
/*
|
/*
|
||||||
* can't have any `funny' characters in name,
|
* can't have any `funny' characters in name,
|
||||||
* where `funny' includes `.', .o file names
|
* where `funny' includes `.', .o file names
|
||||||
@ -696,7 +685,14 @@ funcsymbol( symp )
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
|
||||||
|
i = bfd_decode_symclass (symp);
|
||||||
|
#if defined(DEBUG) && 0
|
||||||
|
if (i != 'T' && i != 't')
|
||||||
|
fprintf (stderr, "%s(%d): %s is of class %c\n", __FILE__, __LINE__, symp->name, i);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return (i == 'T' || i == 't');
|
||||||
}
|
}
|
||||||
|
|
||||||
done()
|
done()
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#ifdef __STDC__
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#endif /* __STDC__ */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "bfd.h"
|
#include "bfd.h"
|
||||||
|
Reference in New Issue
Block a user