* corefile.c (num_of_syms_in): New function - computes the number
of symbols in a given file. (core_create_syms_from): New function - populates a symbol table from the symbols found in a specified file. * corefile.h: Prototype core_create_syms_from. * gprof.c (long_options): Add --external-symbol-table. (usage): Mention it. (main): Initiailize external_symbol_table from --external-symbol-table option. If set use it. * gprof.texi: Document the new option. * NEWS: Mention new feature added to gprof.
This commit is contained in:
parent
f37111339e
commit
0e27a8f69b
@ -1,3 +1,7 @@
|
|||||||
|
2009-06-12 Homer Xing <homer.xing@yahoo.com>
|
||||||
|
|
||||||
|
* NEWS: Mention new feature added to gprof.
|
||||||
|
|
||||||
2009-06-12 John Reiser <jreiser@BitWagon.com>
|
2009-06-12 John Reiser <jreiser@BitWagon.com>
|
||||||
|
|
||||||
* readelf.c (process_symbol_table): Set gnubuckets to NULL after
|
* readelf.c (process_symbol_table): Set gnubuckets to NULL after
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
-*- text -*-
|
-*- text -*-
|
||||||
|
* The gprof program has been given a new command line option:
|
||||||
|
--external-symbols-table=<filename> which reads in symbols from a specified
|
||||||
|
file.
|
||||||
|
|
||||||
* The plugin target has been added to bfd. It can load the same shared objects
|
* The plugin target has been added to bfd. It can load the same shared objects
|
||||||
used by gold and uses them to provide basic support for new file formats.
|
used by gold and uses them to provide basic support for new file formats.
|
||||||
|
@ -1,3 +1,16 @@
|
|||||||
|
2009-06-12 Homer Xing <homer.xing@yahoo.com>
|
||||||
|
|
||||||
|
* corefile.c (num_of_syms_in): New function - computes the number
|
||||||
|
of symbols in a given file.
|
||||||
|
(core_create_syms_from): New function - populates a symbol table
|
||||||
|
from the symbols found in a specified file.
|
||||||
|
* corefile.h: Prototype core_create_syms_from.
|
||||||
|
* gprof.c (long_options): Add --external-symbol-table.
|
||||||
|
(usage): Mention it.
|
||||||
|
(main): Initiailize external_symbol_table from
|
||||||
|
--external-symbol-table option. If set use it.
|
||||||
|
* gprof.texi: Document the new option.
|
||||||
|
|
||||||
2009-06-04 Alan Modra <amodra@bigpond.net.au>
|
2009-06-04 Alan Modra <amodra@bigpond.net.au>
|
||||||
|
|
||||||
* dep-in.sed: Don't use \n in replacement part of s command.
|
* dep-in.sed: Don't use \n in replacement part of s command.
|
||||||
|
102
gprof/corefile.c
102
gprof/corefile.c
@ -1,6 +1,6 @@
|
|||||||
/* corefile.c
|
/* corefile.c
|
||||||
|
|
||||||
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
|
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
|
||||||
Free Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of GNU Binutils.
|
This file is part of GNU Binutils.
|
||||||
@ -33,7 +33,7 @@ bfd *core_bfd;
|
|||||||
static int core_num_syms;
|
static int core_num_syms;
|
||||||
static asymbol **core_syms;
|
static asymbol **core_syms;
|
||||||
asection *core_text_sect;
|
asection *core_text_sect;
|
||||||
PTR core_text_space;
|
void * core_text_space;
|
||||||
|
|
||||||
static int min_insn_size;
|
static int min_insn_size;
|
||||||
int offset_to_code;
|
int offset_to_code;
|
||||||
@ -434,6 +434,104 @@ get_src_info (bfd_vma addr, const char **filename, const char **name, int *line_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return number of symbols in a symbol-table file. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
num_of_syms_in (FILE * f)
|
||||||
|
{
|
||||||
|
const int BUFSIZE = 1024;
|
||||||
|
char * buf = (char *) xmalloc (BUFSIZE);
|
||||||
|
char * address = (char *) xmalloc (BUFSIZE);
|
||||||
|
char type;
|
||||||
|
char * name = (char *) xmalloc (BUFSIZE);
|
||||||
|
int num = 0;
|
||||||
|
|
||||||
|
while (!feof (f) && fgets (buf, BUFSIZE - 1, f))
|
||||||
|
{
|
||||||
|
if (sscanf (buf, "%s %c %s", address, &type, name) == 3)
|
||||||
|
if (type == 't' || type == 'T')
|
||||||
|
++num;
|
||||||
|
}
|
||||||
|
|
||||||
|
free (buf);
|
||||||
|
free (address);
|
||||||
|
free (name);
|
||||||
|
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read symbol table from a file. */
|
||||||
|
|
||||||
|
void
|
||||||
|
core_create_syms_from (const char * sym_table_file)
|
||||||
|
{
|
||||||
|
const int BUFSIZE = 1024;
|
||||||
|
char * buf = (char *) xmalloc (BUFSIZE);
|
||||||
|
char * address = (char *) xmalloc (BUFSIZE);
|
||||||
|
char type;
|
||||||
|
char * name = (char *) xmalloc (BUFSIZE);
|
||||||
|
bfd_vma min_vma = ~(bfd_vma) 0;
|
||||||
|
bfd_vma max_vma = 0;
|
||||||
|
FILE * f;
|
||||||
|
|
||||||
|
f = fopen (sym_table_file, "r");
|
||||||
|
if (!f)
|
||||||
|
{
|
||||||
|
fprintf (stderr, _("%s: could not open %s.\n"), whoami, sym_table_file);
|
||||||
|
done (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pass 1 - determine upper bound on number of function names. */
|
||||||
|
symtab.len = num_of_syms_in (f);
|
||||||
|
|
||||||
|
if (symtab.len == 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, _("%s: file `%s' has no symbols\n"), whoami, sym_table_file);
|
||||||
|
done (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
symtab.base = (Sym *) xmalloc (symtab.len * sizeof (Sym));
|
||||||
|
|
||||||
|
/* Pass 2 - create symbols. */
|
||||||
|
symtab.limit = symtab.base;
|
||||||
|
|
||||||
|
if (fseek (f, 0, SEEK_SET) != 0)
|
||||||
|
{
|
||||||
|
perror (sym_table_file);
|
||||||
|
done (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!feof (f) && fgets (buf, sizeof (buf), f))
|
||||||
|
{
|
||||||
|
if (sscanf (buf, "%s %c %s", address, &type, name) == 3)
|
||||||
|
if (type != 't' && type != 'T')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
sym_init (symtab.limit);
|
||||||
|
|
||||||
|
sscanf (address, "%lx", &(symtab.limit->addr) );
|
||||||
|
|
||||||
|
symtab.limit->name = (char *) xmalloc (strlen (name) + 1);
|
||||||
|
strcpy ((char *) symtab.limit->name, name);
|
||||||
|
symtab.limit->mapped = 0;
|
||||||
|
symtab.limit->is_func = TRUE;
|
||||||
|
symtab.limit->is_bb_head = TRUE;
|
||||||
|
symtab.limit->is_static = (type == 't');
|
||||||
|
min_vma = MIN (symtab.limit->addr, min_vma);
|
||||||
|
max_vma = MAX (symtab.limit->addr, max_vma);
|
||||||
|
|
||||||
|
++symtab.limit;
|
||||||
|
}
|
||||||
|
fclose (f);
|
||||||
|
|
||||||
|
symtab.len = symtab.limit - symtab.base;
|
||||||
|
symtab_finalize (&symtab);
|
||||||
|
|
||||||
|
free (buf);
|
||||||
|
free (address);
|
||||||
|
free (name);
|
||||||
|
}
|
||||||
|
|
||||||
/* Read in symbol table from core.
|
/* Read in symbol table from core.
|
||||||
One symbol per function is entered. */
|
One symbol per function is entered. */
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* corefile.h
|
/* corefile.h
|
||||||
|
|
||||||
Copyright 2000, 2001, 2002, 2004, 2007 Free Software Foundation, Inc.
|
Copyright 2000, 2001, 2002, 2004, 2007, 2009 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of GNU Binutils.
|
This file is part of GNU Binutils.
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ extern unsigned int symbol_map_count;
|
|||||||
|
|
||||||
extern bfd * core_bfd; /* BFD for core-file. */
|
extern bfd * core_bfd; /* BFD for core-file. */
|
||||||
extern asection * core_text_sect; /* Core text section. */
|
extern asection * core_text_sect; /* Core text section. */
|
||||||
extern PTR core_text_space; /* Text space of a.out in core. */
|
extern void * core_text_space; /* Text space of a.out in core. */
|
||||||
extern int offset_to_code; /* Offset (in bytes) of code from entry
|
extern int offset_to_code; /* Offset (in bytes) of code from entry
|
||||||
address of routine. */
|
address of routine. */
|
||||||
|
|
||||||
@ -41,5 +41,6 @@ extern void core_init (const char *);
|
|||||||
extern void core_get_text_space (bfd *);
|
extern void core_get_text_space (bfd *);
|
||||||
extern void core_create_function_syms (void);
|
extern void core_create_function_syms (void);
|
||||||
extern void core_create_line_syms (void);
|
extern void core_create_line_syms (void);
|
||||||
|
extern void core_create_syms_from (const char *);
|
||||||
|
|
||||||
#endif /* corefile_h */
|
#endif /* corefile_h */
|
||||||
|
@ -49,6 +49,7 @@ static void usage (FILE *, int) ATTRIBUTE_NORETURN;
|
|||||||
|
|
||||||
const char * whoami;
|
const char * whoami;
|
||||||
const char * function_mapping_file;
|
const char * function_mapping_file;
|
||||||
|
static const char * external_symbol_table;
|
||||||
const char * a_out_name = A_OUTNAME;
|
const char * a_out_name = A_OUTNAME;
|
||||||
long hz = HZ_WRONG;
|
long hz = HZ_WRONG;
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ static struct option long_options[] =
|
|||||||
{"line", no_argument, 0, 'l'},
|
{"line", no_argument, 0, 'l'},
|
||||||
{"no-static", no_argument, 0, 'a'},
|
{"no-static", no_argument, 0, 'a'},
|
||||||
{"ignore-non-functions", no_argument, 0, 'D'},
|
{"ignore-non-functions", no_argument, 0, 'D'},
|
||||||
|
{"external-symbol-table", required_argument, 0, 'S'},
|
||||||
|
|
||||||
/* output styles: */
|
/* output styles: */
|
||||||
|
|
||||||
@ -155,7 +157,7 @@ static void
|
|||||||
usage (FILE *stream, int status)
|
usage (FILE *stream, int status)
|
||||||
{
|
{
|
||||||
fprintf (stream, _("\
|
fprintf (stream, _("\
|
||||||
Usage: %s [-[abcDhilLsTvwxyz]] [-[ACeEfFJnNOpPqQZ][name]] [-I dirs]\n\
|
Usage: %s [-[abcDhilLsTvwxyz]] [-[ACeEfFJnNOpPqSQZ][name]] [-I dirs]\n\
|
||||||
[-d[num]] [-k from/to] [-m min-count] [-t table-length]\n\
|
[-d[num]] [-k from/to] [-m min-count] [-t table-length]\n\
|
||||||
[--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]\n\
|
[--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]\n\
|
||||||
[--[no-]flat-profile[=name]] [--[no-]graph[=name]]\n\
|
[--[no-]flat-profile[=name]] [--[no-]graph[=name]]\n\
|
||||||
@ -166,7 +168,7 @@ Usage: %s [-[abcDhilLsTvwxyz]] [-[ACeEfFJnNOpPqQZ][name]] [-I dirs]\n\
|
|||||||
[--no-static] [--print-path] [--separate-files]\n\
|
[--no-static] [--print-path] [--separate-files]\n\
|
||||||
[--static-call-graph] [--sum] [--table-length=len] [--traditional]\n\
|
[--static-call-graph] [--sum] [--table-length=len] [--traditional]\n\
|
||||||
[--version] [--width=n] [--ignore-non-functions]\n\
|
[--version] [--width=n] [--ignore-non-functions]\n\
|
||||||
[--demangle[=STYLE]] [--no-demangle] [@FILE]\n\
|
[--demangle[=STYLE]] [--no-demangle] [--external-symbol-table=name] [@FILE]\n\
|
||||||
[image-file] [profile-file...]\n"),
|
[image-file] [profile-file...]\n"),
|
||||||
whoami);
|
whoami);
|
||||||
if (REPORT_BUGS_TO[0] && status == 0)
|
if (REPORT_BUGS_TO[0] && status == 0)
|
||||||
@ -199,7 +201,7 @@ main (int argc, char **argv)
|
|||||||
expandargv (&argc, &argv);
|
expandargv (&argc, &argv);
|
||||||
|
|
||||||
while ((ch = getopt_long (argc, argv,
|
while ((ch = getopt_long (argc, argv,
|
||||||
"aA::bBcC::d::De:E:f:F:hiI:J::k:lLm:n:N:O:p::P::q::Q::rR:st:Tvw:xyzZ::",
|
"aA::bBcC::d::De:E:f:F:hiI:J::k:lLm:n:N:O:p::P::q::Q::rR:sS:t:Tvw:xyzZ::",
|
||||||
long_options, 0))
|
long_options, 0))
|
||||||
!= EOF)
|
!= EOF)
|
||||||
{
|
{
|
||||||
@ -398,6 +400,10 @@ main (int argc, char **argv)
|
|||||||
output_style |= STYLE_SUMMARY_FILE;
|
output_style |= STYLE_SUMMARY_FILE;
|
||||||
user_specified |= STYLE_SUMMARY_FILE;
|
user_specified |= STYLE_SUMMARY_FILE;
|
||||||
break;
|
break;
|
||||||
|
case 'S':
|
||||||
|
external_symbol_table = optarg;
|
||||||
|
DBG (AOUTDEBUG, printf ("external-symbol-table: %s\n", optarg));
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
bb_table_length = atoi (optarg);
|
bb_table_length = atoi (optarg);
|
||||||
if (bb_table_length < 0)
|
if (bb_table_length < 0)
|
||||||
@ -512,7 +518,9 @@ This program is free software. This program has absolutely no warranty.\n"));
|
|||||||
core_get_text_space (core_bfd);
|
core_get_text_space (core_bfd);
|
||||||
|
|
||||||
/* Create symbols from core image. */
|
/* Create symbols from core image. */
|
||||||
if (line_granularity)
|
if (external_symbol_table)
|
||||||
|
core_create_syms_from (external_symbol_table);
|
||||||
|
else if (line_granularity)
|
||||||
core_create_line_syms ();
|
core_create_line_syms ();
|
||||||
else
|
else
|
||||||
core_create_function_syms ();
|
core_create_function_syms ();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
\input texinfo @c -*-texinfo-*-
|
\input texinfo @c -*-texinfo-*-
|
||||||
@setfilename gprof.info
|
@setfilename gprof.info
|
||||||
@c Copyright 1988, 1992, 1993, 1998, 1999, 2000, 2001, 2002, 2003,
|
@c Copyright 1988, 1992, 1993, 1998, 1999, 2000, 2001, 2002, 2003,
|
||||||
@c 2004, 2007, 2008
|
@c 2004, 2007, 2008, 2009
|
||||||
@c Free Software Foundation, Inc.
|
@c Free Software Foundation, Inc.
|
||||||
@settitle GNU gprof
|
@settitle GNU gprof
|
||||||
@setchapternewpage odd
|
@setchapternewpage odd
|
||||||
@ -24,7 +24,7 @@ END-INFO-DIR-ENTRY
|
|||||||
This file documents the gprof profiler of the GNU system.
|
This file documents the gprof profiler of the GNU system.
|
||||||
|
|
||||||
@c man begin COPYRIGHT
|
@c man begin COPYRIGHT
|
||||||
Copyright @copyright{} 1988, 92, 97, 98, 99, 2000, 2001, 2003, 2007, 2008 Free Software Foundation, Inc.
|
Copyright @copyright{} 1988, 92, 97, 98, 99, 2000, 2001, 2003, 2007, 2008, 2009 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Permission is granted to copy, distribute and/or modify this document
|
Permission is granted to copy, distribute and/or modify this document
|
||||||
under the terms of the GNU Free Documentation License, Version 1.3
|
under the terms of the GNU Free Documentation License, Version 1.3
|
||||||
@ -57,7 +57,7 @@ execute programs. @sc{gnu} @code{gprof} was written by Jay Fenlason.
|
|||||||
Eric S. Raymond made some minor corrections and additions in 2003.
|
Eric S. Raymond made some minor corrections and additions in 2003.
|
||||||
|
|
||||||
@vskip 0pt plus 1filll
|
@vskip 0pt plus 1filll
|
||||||
Copyright @copyright{} 1988, 92, 97, 98, 99, 2000, 2003, 2008 Free Software Foundation, Inc.
|
Copyright @copyright{} 1988, 92, 97, 98, 99, 2000, 2003, 2008, 2009 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Permission is granted to copy, distribute and/or modify this document
|
Permission is granted to copy, distribute and/or modify this document
|
||||||
under the terms of the GNU Free Documentation License, Version 1.3
|
under the terms of the GNU Free Documentation License, Version 1.3
|
||||||
@ -128,7 +128,8 @@ gprof [ -[abcDhilLrsTvwxyz] ] [ -[ACeEfFJnNOpPqQZ][@var{name}] ]
|
|||||||
[ --static-call-graph ] [ --sum ] [ --table-length=@var{len} ]
|
[ --static-call-graph ] [ --sum ] [ --table-length=@var{len} ]
|
||||||
[ --traditional ] [ --version ] [ --width=@var{n} ]
|
[ --traditional ] [ --version ] [ --width=@var{n} ]
|
||||||
[ --ignore-non-functions ] [ --demangle[=@var{STYLE}] ]
|
[ --ignore-non-functions ] [ --demangle[=@var{STYLE}] ]
|
||||||
[ --no-demangle ] [ @var{image-file} ] [ @var{profile-file} @dots{} ]
|
[ --no-demangle ] [--external-symbol-table=name]
|
||||||
|
[ @var{image-file} ] [ @var{profile-file} @dots{} ]
|
||||||
@c man end
|
@c man end
|
||||||
@end smallexample
|
@end smallexample
|
||||||
|
|
||||||
@ -725,6 +726,13 @@ to only propagate times for symbols matching @var{symspec}.
|
|||||||
The @samp{-n} option causes @code{gprof}, in its call graph analysis,
|
The @samp{-n} option causes @code{gprof}, in its call graph analysis,
|
||||||
not to propagate times for symbols matching @var{symspec}.
|
not to propagate times for symbols matching @var{symspec}.
|
||||||
|
|
||||||
|
@item -S@var{filename}
|
||||||
|
@itemx --external-symbol-table=@var{filename}
|
||||||
|
The @samp{-S} option causes @code{gprof} to read an external symbol table
|
||||||
|
file, such as @file{/proc/kallsyms}, rather than read the symbol table
|
||||||
|
from the given object file (the default is @code{a.out}). This is useful
|
||||||
|
for profiling kernel modules.
|
||||||
|
|
||||||
@item -z
|
@item -z
|
||||||
@itemx --display-unused-functions
|
@itemx --display-unused-functions
|
||||||
If you give the @samp{-z} option, @code{gprof} will mention all
|
If you give the @samp{-z} option, @code{gprof} will mention all
|
||||||
|
Loading…
Reference in New Issue
Block a user