(read_function_mappins): Use qsort to sort the symbols.
(search_mapped_symbol): New function.
(core_create_function_syms): Use bsearch to find symbols.
* corefile.h (struct function_map): Add new bit-field: is_first.
* cg_print.c (cmp_symbol_map): New function.
(cg_print_file_ordering): Sort the symbol map.
+2009-06-16 Homer Xing <homer.xing@yahoo.com>
+
+ * corefile.c (cmp_symbol_map): New function.
+ (read_function_mappins): Use qsort to sort the symbols.
+ (search_mapped_symbol): New function.
+ (core_create_function_syms): Use bsearch to find symbols.
+ * corefile.h (struct function_map): Add new bit-field: is_first.
+ * cg_print.c (cmp_symbol_map): New function.
+ (cg_print_file_ordering): Sort the symbol map.
+
2009-06-15 Homer Xing <homer.xing@yahoo.com>
* corefile.c (core_create_syms_from): Use BFD_VMA_FMT when
2009-06-15 Homer Xing <homer.xing@yahoo.com>
* corefile.c (core_create_syms_from): Use BFD_VMA_FMT when
/* cg_print.c - Print routines for displaying call graphs.
/* cg_print.c - Print routines for displaying call graphs.
- 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.
+/* Compare two function_map structs based on file name.
+ We want to sort in ascending order. */
+
+static int
+cmp_symbol_map (const void * l, const void * r)
+{
+ return strcmp (((struct function_map *) l)->file_name,
+ ((struct function_map *) r)->file_name);
+}
+
/* Print a suggested .o ordering for files on a link line based
on profiling information. This uses the function placement
code for the bulk of its work. */
void
/* Print a suggested .o ordering for files on a link line based
on profiling information. This uses the function placement
code for the bulk of its work. */
void
-cg_print_file_ordering ()
+cg_print_file_ordering (void)
{
unsigned long scratch_arc_count, index;
Arc **scratch_arcs;
{
unsigned long scratch_arc_count, index;
Arc **scratch_arcs;
printf ("%s\n", symtab.base[index].name);
}
printf ("%s\n", symtab.base[index].name);
}
+ qsort (symbol_map, symbol_map_count, sizeof (struct function_map), cmp_symbol_map);
+
/* Now output any .o's that didn't have any text symbols. */
last = NULL;
for (index = 0; index < symbol_map_count; index++)
/* Now output any .o's that didn't have any text symbols. */
last = NULL;
for (index = 0; index < symbol_map_count; index++)
+/* Compare two function_map structs based on function name.
+ We want to sort in ascending order. */
+
+static int
+cmp_symbol_map (const void * l, const void * r)
+{
+ return strcmp (((struct function_map *) l)->function_name,
+ ((struct function_map *) r)->function_name);
+}
+
static void
read_function_mappings (const char *filename)
{
static void
read_function_mappings (const char *filename)
{
- FILE *file = fopen (filename, "r");
+ FILE * file = fopen (filename, "r");
char dummy[1024];
int count = 0;
char dummy[1024];
int count = 0;
/* Record the size of the map table for future reference. */
symbol_map_count = count;
/* Record the size of the map table for future reference. */
symbol_map_count = count;
+ for (i = 0; i < symbol_map_count; ++i)
+ if (i == 0 || strcmp (symbol_map[i].file_name, symbol_map[i - 1].file_name))
+ symbol_map[i].is_first = 1;
+
+ qsort (symbol_map, symbol_map_count, sizeof (struct function_map), cmp_symbol_map);
+}
-core_init (const char *aout_name)
+core_init (const char * aout_name)
{
int core_sym_bytes;
asymbol *synthsyms;
{
int core_sym_bytes;
asymbol *synthsyms;
+static int
+search_mapped_symbol (const void * l, const void * r)
+{
+ return strcmp ((const char *) l, ((const struct function_map *) r)->function_name);
+}
+
/* Read in symbol table from core.
One symbol per function is entered. */
void
/* Read in symbol table from core.
One symbol per function is entered. */
void
-core_create_function_syms ()
+core_create_function_syms (void)
- bfd_vma min_vma = ~(bfd_vma) 0;
+ bfd_vma min_vma = ~ (bfd_vma) 0;
bfd_vma max_vma = 0;
int class;
bfd_vma max_vma = 0;
int class;
- long i, found, skip;
- unsigned int j;
+ long i;
+ struct function_map * found;
/* Pass 1 - determine upper bound on number of function names. */
symtab.len = 0;
/* Pass 1 - determine upper bound on number of function names. */
symtab.len = 0;
if (!core_sym_class (core_syms[i]))
continue;
if (!core_sym_class (core_syms[i]))
continue;
- /* This should be replaced with a binary search or hashed
- search. Gross.
-
- Don't create a symtab entry for a function that has
+ /* Don't create a symtab entry for a function that has
a mapping to a file, unless it's the first function
in the file. */
a mapping to a file, unless it's the first function
in the file. */
- skip = 0;
- for (j = 0; j < symbol_map_count; j++)
- if (!strcmp (core_syms[i]->name, symbol_map[j].function_name))
- {
- if (j > 0 && ! strcmp (symbol_map [j].file_name,
- symbol_map [j - 1].file_name))
- skip = 1;
- break;
- }
-
- if (!skip)
+ found = bsearch (core_syms[i]->name, symbol_map, symbol_map_count,
+ sizeof (struct function_map), search_mapped_symbol);
+ if (found == NULL || found->is_first)
- /* This should be replaced with a binary search or hashed
- search. Gross. */
- skip = 0;
- found = 0;
-
- for (j = 0; j < symbol_map_count; j++)
- if (!strcmp (core_syms[i]->name, symbol_map[j].function_name))
- {
- if (j > 0 && ! strcmp (symbol_map [j].file_name,
- symbol_map [j - 1].file_name))
- skip = 1;
- else
- found = j;
- break;
- }
-
- if (skip)
+ found = bsearch (core_syms[i]->name, symbol_map, symbol_map_count,
+ sizeof (struct function_map), search_mapped_symbol);
+ if (found && ! found->is_first)
continue;
sym_init (symtab.limit);
continue;
sym_init (symtab.limit);
if (sym_sec)
symtab.limit->addr += bfd_get_section_vma (sym_sec->owner, sym_sec);
if (sym_sec)
symtab.limit->addr += bfd_get_section_vma (sym_sec->owner, sym_sec);
- if (symbol_map_count
- && !strcmp (core_syms[i]->name, symbol_map[found].function_name))
- symtab.limit->name = symbol_map[found].file_name;
+ symtab.limit->name = found->file_name;
symtab.limit->mapped = 1;
}
else
symtab.limit->mapped = 1;
}
else
/* Lookup filename and line number, if we can. */
{
/* Lookup filename and line number, if we can. */
{
- const char *filename, *func_name;
+ const char * filename;
+ const char * func_name;
- if (get_src_info (symtab.limit->addr, &filename, &func_name,
- &symtab.limit->line_num))
+ if (get_src_info (symtab.limit->addr, & filename, & func_name,
+ & symtab.limit->line_num))
{
symtab.limit->file = source_file_lookup_path (filename);
{
symtab.limit->file = source_file_lookup_path (filename);
One symbol per line of source code is entered. */
void
One symbol per line of source code is entered. */
void
-core_create_line_syms ()
+core_create_line_syms (void)
{
char *prev_name, *prev_filename;
unsigned int prev_name_len, prev_filename_len;
{
char *prev_name, *prev_filename;
unsigned int prev_name_len, prev_filename_len;
- char *function_name;
- char *file_name;
+ char * function_name;
+ char * file_name;
+ unsigned int is_first:1; /* Is this the first symbol in an object file? */
};
extern struct function_map * symbol_map;
};
extern struct function_map * symbol_map;
extern bfd * core_bfd; /* BFD for core-file. */
extern asection * core_text_sect; /* Core text section. */
extern bfd * core_bfd; /* BFD for core-file. */
extern asection * core_text_sect; /* Core text section. */
-extern void * core_text_space; /* Text space of a.out in core. */
-extern int offset_to_code; /* Offset (in bytes) of code from entry
- address of routine. */
+extern void * core_text_space; /* Text space of a.out in core. */
+extern int offset_to_code; /* Offset (in bytes) of code from entry
+ address of routine. */
extern void core_init (const char *);
extern void core_get_text_space (bfd *);
extern void core_init (const char *);
extern void core_get_text_space (bfd *);