* corefile.c (core_init): Use a separate local variable,

core_sym_bytes, to make the units from bfd_get_symtab_upper_bound
	more obvious.
	(core_create_function_syms): Discard cbfd argument.  Eliminate
	`offset' variable and calculate VMA directly. Update all users.
	* corefile.h (core_create_function_syms): Update prototype.
	(core_create_line_syms): Likewise.
	* gprof.c (main): Remove #ifdef PROF_SUPPORT_IMPLEMENTED code.
	Tidy.
This commit is contained in:
Ben Elliston
2004-05-26 04:06:26 +00:00
parent 6d1be3f186
commit 37b1bfcd81
4 changed files with 47 additions and 78 deletions

View File

@@ -1,3 +1,15 @@
2004-05-26 Ben Elliston <bje@au.ibm.com>
* corefile.c (core_init): Use a separate local variable,
core_sym_bytes, to make the units from bfd_get_symtab_upper_bound
more obvious.
(core_create_function_syms): Discard cbfd argument. Eliminate
`offset' variable and calculate VMA directly. Update all users.
* corefile.h (core_create_function_syms): Update prototype.
(core_create_line_syms): Likewise.
* gprof.c (main): Remove #ifdef PROF_SUPPORT_IMPLEMENTED code.
Tidy.
2004-05-17 Ben Elliston <bje@au.ibm.com> 2004-05-17 Ben Elliston <bje@au.ibm.com>
* gprof.texi (Output Options): Correct last patch to use @itemx, not * gprof.texi (Output Options): Correct last patch to use @itemx, not

View File

@@ -142,6 +142,7 @@ void
core_init (aout_name) core_init (aout_name)
const char *aout_name; const char *aout_name;
{ {
int core_sym_bytes;
core_bfd = bfd_openr (aout_name, 0); core_bfd = bfd_openr (aout_name, 0);
if (!core_bfd) if (!core_bfd)
@@ -172,15 +173,15 @@ core_init (aout_name)
/* Read core's symbol table. */ /* Read core's symbol table. */
/* This will probably give us more than we need, but that's ok. */ /* This will probably give us more than we need, but that's ok. */
core_num_syms = bfd_get_symtab_upper_bound (core_bfd); core_sym_bytes = bfd_get_symtab_upper_bound (core_bfd);
if (core_num_syms < 0) if (core_sym_bytes < 0)
{ {
fprintf (stderr, "%s: %s: %s\n", whoami, aout_name, fprintf (stderr, "%s: %s: %s\n", whoami, aout_name,
bfd_errmsg (bfd_get_error ())); bfd_errmsg (bfd_get_error ()));
done (1); done (1);
} }
core_syms = (asymbol **) xmalloc (core_num_syms); core_syms = (asymbol **) xmalloc (core_sym_bytes);
core_num_syms = bfd_canonicalize_symtab (core_bfd, core_syms); core_num_syms = bfd_canonicalize_symtab (core_bfd, core_syms);
if (core_num_syms < 0) if (core_num_syms < 0)
@@ -405,8 +406,7 @@ get_src_info (addr, filename, name, line_num)
One symbol per function is entered. */ One symbol per function is entered. */
void void
core_create_function_syms (cbfd) core_create_function_syms ()
bfd *cbfd ATTRIBUTE_UNUSED;
{ {
bfd_vma min_vma = ~(bfd_vma) 0; bfd_vma min_vma = ~(bfd_vma) 0;
bfd_vma max_vma = 0; bfd_vma max_vma = 0;
@@ -592,13 +592,11 @@ core_create_function_syms (cbfd)
One symbol per line of source code is entered. */ One symbol per line of source code is entered. */
void void
core_create_line_syms (cbfd) core_create_line_syms ()
bfd *cbfd;
{ {
char *prev_name, *prev_filename; char *prev_name, *prev_filename;
unsigned int prev_name_len, prev_filename_len; unsigned int prev_name_len, prev_filename_len;
bfd_vma vma, min_vma = ~(bfd_vma) 0, max_vma = 0; bfd_vma vma, min_vma = ~(bfd_vma) 0, max_vma = 0;
bfd_vma offset;
Sym *prev, dummy, *sentinel, *sym; Sym *prev, dummy, *sentinel, *sym;
const char *filename; const char *filename;
int prev_line_num; int prev_line_num;
@@ -607,9 +605,9 @@ core_create_line_syms (cbfd)
/* Create symbols for functions as usual. This is necessary in /* Create symbols for functions as usual. This is necessary in
cases where parts of a program were not compiled with -g. For cases where parts of a program were not compiled with -g. For
those parts we still want to get info at the function level. */ those parts we still want to get info at the function level. */
core_create_function_syms (cbfd); core_create_function_syms ();
/* Pass 1 - counter number of symbols. */ /* Pass 1: count the number of symbols. */
/* To find all line information, walk through all possible /* To find all line information, walk through all possible
text-space addresses (one by one!) and get the debugging text-space addresses (one by one!) and get the debugging
@@ -617,7 +615,7 @@ core_create_line_syms (cbfd)
it is time to create a new symbol. it is time to create a new symbol.
Of course, this is rather slow and it would be better if Of course, this is rather slow and it would be better if
bfd would provide an iterator for enumerating all line infos. */ BFD would provide an iterator for enumerating all line infos. */
prev_name_len = PATH_MAX; prev_name_len = PATH_MAX;
prev_filename_len = PATH_MAX; prev_filename_len = PATH_MAX;
prev_name = xmalloc (prev_name_len); prev_name = xmalloc (prev_name_len);
@@ -625,12 +623,11 @@ core_create_line_syms (cbfd)
ltab.len = 0; ltab.len = 0;
prev_line_num = 0; prev_line_num = 0;
for (offset = 0; offset < core_text_sect->_raw_size; offset += min_insn_size) bfd_vma vma_high = core_text_sect->vma + core_text_sect->_raw_size;
for (vma = core_text_sect->vma; vma < vma_high; vma += min_insn_size)
{ {
unsigned int len; unsigned int len;
vma = core_text_sect->vma + offset;
if (!get_src_info (vma, &filename, &dummy.name, &dummy.line_num) if (!get_src_info (vma, &filename, &dummy.name, &dummy.line_num)
|| (prev_line_num == dummy.line_num || (prev_line_num == dummy.line_num
&& prev_name != NULL && prev_name != NULL
@@ -693,12 +690,11 @@ core_create_line_syms (cbfd)
lot cleaner now. */ lot cleaner now. */
prev = 0; prev = 0;
for (offset = 0; offset < core_text_sect->_raw_size; offset += min_insn_size) for (vma = core_text_sect->vma; vma < vma_high; vma += min_insn_size)
{ {
sym_init (ltab.limit); sym_init (ltab.limit);
if (!get_src_info (core_text_sect->vma + offset, &filename, if (!get_src_info (vma, &filename, &ltab.limit->name, &ltab.limit->line_num)
&ltab.limit->name, &ltab.limit->line_num)
|| (prev && prev->line_num == ltab.limit->line_num || (prev && prev->line_num == ltab.limit->line_num
&& strcmp (prev->name, ltab.limit->name) == 0 && strcmp (prev->name, ltab.limit->name) == 0
&& strcmp (prev->file->name, filename) == 0)) && strcmp (prev->file->name, filename) == 0))
@@ -708,7 +704,7 @@ core_create_line_syms (cbfd)
ltab.limit->name = xstrdup (ltab.limit->name); ltab.limit->name = xstrdup (ltab.limit->name);
ltab.limit->file = source_file_lookup_path (filename); ltab.limit->file = source_file_lookup_path (filename);
ltab.limit->addr = core_text_sect->vma + offset; ltab.limit->addr = vma;
/* Set is_static based on the enclosing function, using either: /* Set is_static based on the enclosing function, using either:
1) the previous symbol, if it's from the same function, or 1) the previous symbol, if it's from the same function, or

View File

@@ -41,7 +41,7 @@ extern int offset_to_code; /* Offset (in bytes) of code from entry
extern void core_init PARAMS ((const char *)); extern void core_init PARAMS ((const char *));
extern void core_get_text_space PARAMS ((bfd *)); extern void core_get_text_space PARAMS ((bfd *));
extern void core_create_function_syms PARAMS ((bfd *)); extern void core_create_function_syms PARAMS ((void));
extern void core_create_line_syms PARAMS ((bfd *)); extern void core_create_line_syms PARAMS ((void));
#endif /* corefile_h */ #endif /* corefile_h */

View File

@@ -483,7 +483,8 @@ This program is free software. This program has absolutely no warranty.\n"));
done (1); done (1);
} }
/* --sum implies --line, otherwise we'd lose b-b counts in gmon.sum */ /* --sum implies --line, otherwise we'd lose basic block counts in
gmon.sum */
if (output_style & STYLE_SUMMARY_FILE) if (output_style & STYLE_SUMMARY_FILE)
{ {
line_granularity = 1; line_granularity = 1;
@@ -520,71 +521,36 @@ This program is free software. This program has absolutely no warranty.\n"));
* functions off the flat profile: * functions off the flat profile:
*/ */
if (line_granularity) if (line_granularity)
{ for (sp = &default_excluded_list[0]; *sp; sp++)
for (sp = &default_excluded_list[0]; *sp; sp++) sym_id_add (*sp, EXCL_FLAT);
{
sym_id_add (*sp, EXCL_FLAT);
}
}
/* /* Read symbol table from core file. */
* Read symbol table from core file:
*/
core_init (a_out_name); core_init (a_out_name);
/* /* If we should ignore direct function calls, we need to load to
* If we should ignore direct function calls, we need to load core's text-space. */
* to core's text-space:
*/
if (ignore_direct_calls) if (ignore_direct_calls)
{ 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 (line_granularity)
{ core_create_line_syms ();
core_create_line_syms (core_bfd);
}
else else
{ core_create_function_syms ();
core_create_function_syms (core_bfd);
}
/* /* Translate sym specs into syms. */
* Translate sym specs into syms:
*/
sym_id_parse (); sym_id_parse ();
if (file_format == FF_PROF) if (file_format == FF_PROF)
{ {
#ifdef PROF_SUPPORT_IMPLEMENTED
/*
* Get information about mon.out file(s):
*/
do
{
mon_out_read (gmon_name);
if (optind < argc)
{
gmon_name = argv[optind];
}
}
while (optind++ < argc);
#else
fprintf (stderr, fprintf (stderr,
_("%s: sorry, file format `prof' is not yet supported\n"), _("%s: sorry, file format `prof' is not yet supported\n"),
whoami); whoami);
done (1); done (1);
#endif
} }
else else
{ {
/* /* Get information about gmon.out file(s). */
* Get information about gmon.out file(s):
*/
do do
{ {
gmon_out_read (gmon_name); gmon_out_read (gmon_name);
@@ -603,19 +569,15 @@ This program is free software. This program has absolutely no warranty.\n"));
if (output_style == 0) if (output_style == 0)
{ {
if (gmon_input & (INPUT_HISTOGRAM | INPUT_CALL_GRAPH)) if (gmon_input & (INPUT_HISTOGRAM | INPUT_CALL_GRAPH))
{ output_style = STYLE_FLAT_PROFILE | STYLE_CALL_GRAPH;
output_style = STYLE_FLAT_PROFILE | STYLE_CALL_GRAPH;
}
else else
{ output_style = STYLE_EXEC_COUNTS;
output_style = STYLE_EXEC_COUNTS;
}
output_style &= ~user_specified; output_style &= ~user_specified;
} }
/* /* Dump a gmon.sum file if requested (before any other
* Dump a gmon.sum file if requested (before any other processing!): processing!) */
*/
if (output_style & STYLE_SUMMARY_FILE) if (output_style & STYLE_SUMMARY_FILE)
{ {
gmon_out_write (GMONSUM); gmon_out_write (GMONSUM);
@@ -631,8 +593,7 @@ This program is free software. This program has absolutely no warranty.\n"));
cg = cg_assemble (); cg = cg_assemble ();
} }
/* do some simple sanity checks: */ /* Do some simple sanity checks. */
if ((output_style & STYLE_FLAT_PROFILE) if ((output_style & STYLE_FLAT_PROFILE)
&& !(gmon_input & INPUT_HISTOGRAM)) && !(gmon_input & INPUT_HISTOGRAM))
{ {