* basic_blocks.h (bb_min_calls): Change to unsigned long.
* call_graph.h (cg_tally): Change count parameter to unsigned
long.
* cg_arcs.h (Arc): Change count field to unsigned long.
(arc_add): Change count parameter to unsigned long.
* source.h (Source_File): Change ncalls field to unsigned long.
* symtab.h (Sym): Change fields ncalls, bb_calls, and
cg.self_calls to unsigned long.
* Many files: Update accordingly.
+Wed Aug 12 14:59:06 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ Avoid some overflow cases:
+ * basic_blocks.h (bb_min_calls): Change to unsigned long.
+ * call_graph.h (cg_tally): Change count parameter to unsigned
+ long.
+ * cg_arcs.h (Arc): Change count field to unsigned long.
+ (arc_add): Change count parameter to unsigned long.
+ * source.h (Source_File): Change ncalls field to unsigned long.
+ * symtab.h (Sym): Change fields ncalls, bb_calls, and
+ cg.self_calls to unsigned long.
+ * Many files: Update accordingly.
+
+ * configure, Makefile.in, aclocal.m4: Rebuild with current tools.
+
Fri Jul 10 17:29:49 1998 Stan Cox <scox@equinox.cygnus.com>
* configure.in (BSD44_FORMAT): Define for cygwin32, win32, mingw32
printf (_("[find_call] 0x%lx: jsr%s <indirect_child>\n"),
(bfd_vma) pc - delta,
pc->j.func == Jxx_FUNC_JSR ? "" : "_coroutine"));
- arc_add (parent, &indirect_child, 0);
+ arc_add (parent, &indirect_child, (unsigned long) 0);
}
break;
{
DBG (CALLDEBUG, printf ("\n"));
/* a hit: */
- arc_add (parent, child, 0);
+ arc_add (parent, child, (unsigned long) 0);
continue;
}
}
* Default option values:
*/
bool bb_annotate_all_lines = FALSE;
-int bb_min_calls = 1;
+unsigned long bb_min_calls = 1;
int bb_table_length = 10;
/*
return -1;
}
- if (right->ncalls != left->ncalls)
- {
- return right->ncalls - left->ncalls;
- }
+ if (left->ncalls < right->ncalls)
+ return 1;
+ else if (left->ncalls > right->ncalls)
+ return -1;
return left->line_num - right->line_num;
}
{
int nblocks, b;
bfd_vma addr;
- long ncalls;
+ unsigned long ncalls;
Sym *sym;
if (fread (&nblocks, sizeof (nblocks), 1, ifp) != 1)
int i;
DBG (BBDEBUG,
- printf ("[bb_read_rec] 0x%lx->0x%lx (%s:%d) cnt=%ld\n",
+ printf ("[bb_read_rec] 0x%lx->0x%lx (%s:%d) cnt=%lu\n",
addr, sym->addr, sym->name, sym->line_num, ncalls));
for (i = 0; i < NBBS; i++)
const unsigned char tag = GMON_TAG_BB_COUNT;
int nblocks = 0;
bfd_vma addr;
- long ncalls;
+ unsigned long ncalls;
Sym *sym;
int i;
{
if (sym->ncalls > 0 || ! ignore_zeros)
{
- printf (_("%s:%d: (%s:0x%lx) %d executions\n"),
+ printf (_("%s:%d: (%s:0x%lx) %lu executions\n"),
sym->file ? sym->file->name : _("<unknown>"), sym->line_num,
sym->name, sym->addr, sym->ncalls);
}
{
if (sym->bb_calls[j] > 0 || ! ignore_zeros)
{
- printf (_("%s:%d: (%s:0x%lx) %d executions\n"),
+ printf (_("%s:%d: (%s:0x%lx) %lu executions\n"),
sym->file ? sym->file->name : _("<unknown>"), sym->line_num,
sym->name, sym->bb_addr[j], sym->bb_calls[j]);
}
Source_File *sf = arg;
Sym *b;
int i;
- static int last_count;
- int last_print=-1;
+ static unsigned long last_count;
+ unsigned long last_print = (unsigned long) -1;
b = NULL;
if (line_num <= sf->num_lines)
{
char tmpbuf[NBBS * 30];
char *p;
- int ncalls;
+ unsigned long ncalls;
+ int ncalls_set;
int len;
++num_executable_lines;
p = tmpbuf;
*p = '\0';
- ncalls = -1;
+ ncalls = 0;
+ ncalls_set = 0;
/* If this is a function entry point, label the line no matter what.
* Otherwise, we're in the middle of a function, so check to see
if (b->is_func)
{
- sprintf (p, "%d", b->ncalls);
+ sprintf (p, "%lu", b->ncalls);
p += strlen (p);
last_count = b->ncalls;
last_print = last_count;
ncalls = b->ncalls;
+ ncalls_set = 1;
}
else if (bb_annotate_all_lines
&& b->bb_addr[0] && b->bb_addr[0] > b->addr)
{
- sprintf (p, "%d", last_count);
+ sprintf (p, "%lu", last_count);
p += strlen (p);
last_print = last_count;
ncalls = last_count;
+ ncalls_set = 1;
}
/* Loop through all of this line's basic-blocks. For each one,
for (i = 0; i < NBBS && b->bb_addr[i]; i++)
{
last_count = b->bb_calls[i];
- if (ncalls < 0)
- ncalls = 0;
+ if (! ncalls_set)
+ {
+ ncalls = 0;
+ ncalls_set = 1;
+ }
ncalls += last_count;
if (bb_annotate_all_lines && last_count == last_print)
if (p > tmpbuf)
*p++ = ',';
- sprintf (p, "%d", last_count);
+ sprintf (p, "%lu", last_count);
p += strlen (p);
last_print = last_count;
if (bb_annotate_all_lines && p == tmpbuf)
{
- sprintf (p, "%d", last_count);
+ sprintf (p, "%lu", last_count);
p += strlen (p);
ncalls = last_count;
+ ncalls_set = 1;
}
- if (ncalls < 0)
+ if (! ncalls_set)
{
int c;
for (i = 0; i < table_len; ++i)
{
sym = sf->line[i];
- if (!sym || sym->ncalls <= 0)
+ if (!sym || sym->ncalls == 0)
{
break;
}
- fprintf (ofp, "%9d %10d\n", sym->line_num, sym->ncalls);
+ fprintf (ofp, "%9d %10lu\n", sym->line_num, sym->ncalls);
}
}
num_executable_lines
? 100.0 * num_lines_executed / (double) num_executable_lines
: 100.0);
- fprintf (ofp, _("\n%9d Total number of line executions\n"), sf->ncalls);
+ fprintf (ofp, _("\n%9lu Total number of line executions\n"),
+ sf->ncalls);
fprintf (ofp, _("%9.2f Average executions per line\n"),
num_executable_lines
- ? sf->ncalls / (double) num_executable_lines
+ ? (double) sf->ncalls / (double) num_executable_lines
: 0.0);
if (ofp != stdout)
{
* Options:
*/
extern bool bb_annotate_all_lines; /* force annotation of all lines? */
-extern int bb_table_length; /* length of most-used bb table */
-extern int bb_min_calls; /* minimum execution count */
+extern int bb_table_length; /* length of most-used bb table */
+extern unsigned long bb_min_calls; /* minimum execution count */
extern void bb_read_rec PARAMS ((FILE * ifp, const char *filename));
extern void bb_write_blocks PARAMS ((FILE * ofp, const char *filename));
extern void
DEFUN (cg_tally, (from_pc, self_pc, count),
- bfd_vma from_pc AND bfd_vma self_pc AND int count)
+ bfd_vma from_pc AND bfd_vma self_pc AND unsigned long count)
{
Sym *parent;
Sym *child;
{
child->ncalls += count;
DBG (TALLYDEBUG,
- printf (_("[cg_tally] arc from %s to %s traversed %d times\n"),
+ printf (_("[cg_tally] arc from %s to %s traversed %lu times\n"),
parent->name, child->name, count));
arc_add (parent, child, count);
}
{
bfd_vma from_pc, self_pc;
struct gmon_cg_arc_record arc;
- int count;
+ unsigned long count;
if (fread (&arc, sizeof (arc), 1, ifp) != 1)
{
self_pc = get_vma (core_bfd, (bfd_byte *) arc.self_pc);
count = bfd_get_32 (core_bfd, (bfd_byte *) arc.count);
DBG (SAMPLEDEBUG,
- printf ("[cg_read_rec] frompc 0x%lx selfpc 0x%lx count %d\n",
+ printf ("[cg_read_rec] frompc 0x%lx selfpc 0x%lx count %lu\n",
from_pc, self_pc, count));
/* add this arc: */
cg_tally (from_pc, self_pc, count);
done (1);
}
DBG (SAMPLEDEBUG,
- printf ("[cg_write_arcs] frompc 0x%lx selfpc 0x%lx count %d\n",
+ printf ("[cg_write_arcs] frompc 0x%lx selfpc 0x%lx count %lu\n",
arc->parent->addr, arc->child->addr, arc->count));
}
}
#include "gprof.h"
#include "symtab.h"
-extern void cg_tally PARAMS ((bfd_vma from_pc, bfd_vma self_pc, int count));
+extern void cg_tally PARAMS ((bfd_vma from_pc, bfd_vma self_pc,
+ unsigned long count));
extern void cg_read_rec PARAMS ((FILE * ifp, const char *filename));
extern void cg_write_arcs PARAMS ((FILE * ofp, const char *filename));
*/
void
DEFUN (arc_add, (parent, child, count),
- Sym * parent AND Sym * child AND int count)
+ Sym * parent AND Sym * child AND unsigned long count)
{
static unsigned int maxarcs = 0;
Arc *arc, **newarcs;
- DBG (TALLYDEBUG, printf ("[arc_add] %d arcs from %s to %s\n",
+ DBG (TALLYDEBUG, printf ("[arc_add] %lu arcs from %s to %s\n",
count, parent->name, child->name));
arc = arc_lookup (parent, child);
if (arc)
/*
* A hit: just increment the count.
*/
- DBG (TALLYDEBUG, printf ("[tally] hit %d += %d\n",
+ DBG (TALLYDEBUG, printf ("[tally] hit %lu += %lu\n",
arc->count, count));
arc->count += count;
return;
DBG (PROPDEBUG,
printf ("[prop_time] child \t");
print_name (child);
- printf (" with %f %f %d/%d\n", child->hist.time,
+ printf (" with %f %f %lu/%lu\n", child->hist.time,
child->cg.child_time, arc->count, child->ncalls);
printf ("[prop_time] parent\t");
print_name (parent);
* is static (and all others are, too)) no time propagates
* along this arc.
*/
- if (child->ncalls)
+ if (child->ncalls != 0)
{
child->cg.prop.fract += parent->cg.prop.fract
* (((double) arc->count) / ((double) child->ncalls));
* arc is static (and all others are, too)) no time
* propagates along this arc.
*/
- if (head->ncalls)
+ if (head->ncalls != 0)
{
head->cg.prop.fract += parent->cg.prop.fract
* (((double) arc->count) / ((double) head->ncalls));
{
Sym *parent; /* source vertice of arc */
Sym *child; /* dest vertice of arc */
- int count; /* # of calls from parent to child */
+ unsigned long count; /* # of calls from parent to child */
double time; /* time inherited along arc */
double child_time; /* child-time inherited along arc */
struct arc *next_parent; /* next parent of CHILD */
extern unsigned int num_cycles; /* number of cycles discovered */
extern Sym *cycle_header; /* cycle headers */
-extern void arc_add PARAMS ((Sym * parent, Sym * child, int count));
+extern void arc_add PARAMS ((Sym * parent, Sym * child, unsigned long count));
extern Arc *arc_lookup PARAMS ((Sym * parent, Sym * child));
extern Sym **cg_assemble PARAMS ((void));
extern Arc **arcs;
sprintf (buf, "[%d]", cyc->cg.index);
printf (bsd_style_output
- ? "%-6.6s %5.1f %7.2f %11.2f %7d"
- : "%-6.6s %5.1f %7.2f %7.2f %7d", buf,
+ ? "%-6.6s %5.1f %7.2f %11.2f %7lu"
+ : "%-6.6s %5.1f %7.2f %7.2f %7lu", buf,
100 * (cyc->cg.prop.self + cyc->cg.prop.child) / print_time,
cyc->cg.prop.self / hz, cyc->cg.prop.child / hz, cyc->ncalls);
if (cyc->cg.self_calls != 0)
{
- printf ("+%-7d", cyc->cg.self_calls);
+ printf ("+%-7lu", cyc->cg.self_calls);
}
else
{
{
double left_time = left->cg.prop.self + left->cg.prop.child;
double right_time = right->cg.prop.self + right->cg.prop.child;
- long left_calls = left->ncalls + left->cg.self_calls;
- long right_calls = right->ncalls + right->cg.self_calls;
+ unsigned long left_calls = left->ncalls + left->cg.self_calls;
+ unsigned long right_calls = right->ncalls + right->cg.self_calls;
if (left_time > right_time)
{
for (member = cyc->cg.cyc.next; member; member = member->cg.cyc.next)
{
printf (bsd_style_output
- ? "%6.6s %5.5s %7.2f %11.2f %7d"
- : "%6.6s %5.5s %7.2f %7.2f %7d",
+ ? "%6.6s %5.5s %7.2f %11.2f %7lu"
+ : "%6.6s %5.5s %7.2f %7.2f %7lu",
"", "", member->cg.prop.self / hz, member->cg.prop.child / hz,
member->ncalls);
if (member->cg.self_calls != 0)
{
- printf ("+%-7d", member->cg.self_calls);
+ printf ("+%-7lu", member->cg.self_calls);
}
else
{
print_name (left_parent);
printf (" calls ");
print_name (left_child);
- printf (" %f + %f %d/%d\n", left->time, left->child_time,
+ printf (" %f + %f %lu/%lu\n", left->time, left->child_time,
left->count, left_child->ncalls);
printf ("[cmp_arc] ");
print_name (right_parent);
printf (" calls ");
print_name (right_child);
- printf (" %f + %f %d/%d\n", right->time, right->child_time,
+ printf (" %f + %f %lu/%lu\n", right->time, right->child_time,
right->count, right_child->ncalls);
printf ("\n");
);
{
/* selfcall or call among siblings: */
printf (bsd_style_output
- ? "%6.6s %5.5s %7.7s %11.11s %7d %7.7s "
- : "%6.6s %5.5s %7.7s %7.7s %7d %7.7s ",
+ ? "%6.6s %5.5s %7.7s %11.11s %7lu %7.7s "
+ : "%6.6s %5.5s %7.7s %7.7s %7lu %7.7s ",
"", "", "", "",
arc->count, "");
print_name (parent);
{
/* regular parent of child: */
printf (bsd_style_output
- ? "%6.6s %5.5s %7.2f %11.2f %7d/%-7d "
- : "%6.6s %5.5s %7.2f %7.2f %7d/%-7d ",
+ ? "%6.6s %5.5s %7.2f %11.2f %7lu/%-7lu "
+ : "%6.6s %5.5s %7.2f %7.2f %7lu/%-7lu ",
"", "",
arc->time / hz, arc->child_time / hz,
arc->count, cycle_head->ncalls);
{
/* self call or call to sibling: */
printf (bsd_style_output
- ? "%6.6s %5.5s %7.7s %11.11s %7d %7.7s "
- : "%6.6s %5.5s %7.7s %7.7s %7d %7.7s ",
+ ? "%6.6s %5.5s %7.7s %11.11s %7lu %7.7s "
+ : "%6.6s %5.5s %7.7s %7.7s %7lu %7.7s ",
"", "", "", "", arc->count, "");
print_name (child);
printf ("\n");
{
/* regular child of parent: */
printf (bsd_style_output
- ? "%6.6s %5.5s %7.2f %11.2f %7d/%-7d "
- : "%6.6s %5.5s %7.2f %7.2f %7d/%-7d ",
+ ? "%6.6s %5.5s %7.2f %11.2f %7lu/%-7lu "
+ : "%6.6s %5.5s %7.2f %7.2f %7lu/%-7lu ",
"", "",
arc->time / hz, arc->child_time / hz,
arc->count, child->cg.cyc.head->ncalls);
np->cg.prop.self / hz, np->cg.prop.child / hz);
if ((np->ncalls + np->cg.self_calls) != 0)
{
- printf (" %7d", np->ncalls);
+ printf (" %7lu", np->ncalls);
if (np->cg.self_calls != 0)
{
- printf ("+%-7d ", np->cg.self_calls);
+ printf ("+%-7lu ", np->cg.self_calls);
}
else
{
bfd_vma high_pc;
int ncnt;
};
- int i, samp_bytes, count;
+ int i, samp_bytes;
+ unsigned long count;
bfd_vma from_pc, self_pc;
struct raw_arc raw_arc;
struct raw_phdr raw;
self_pc = get_vma (core_bfd, (bfd_byte *) raw_arc.self_pc);
count = bfd_get_32 (core_bfd, (bfd_byte *) raw_arc.count);
DBG (SAMPLEDEBUG,
- printf ("[gmon_out_read] frompc 0x%lx selfpc 0x%lx count %d\n",
+ printf ("[gmon_out_read] frompc 0x%lx selfpc 0x%lx count %lu\n",
from_pc, self_pc, count));
/* add this arc: */
cg_tally (from_pc, self_pc, count);
done (1);
}
DBG (SAMPLEDEBUG,
- printf ("[dumpsum] frompc 0x%lx selfpc 0x%lx count %d\n",
+ printf ("[dumpsum] frompc 0x%lx selfpc 0x%lx count %lu\n",
arc->parent->addr, arc->child->addr, arc->count));
}
}
print_path = TRUE;
break;
case 'm':
- bb_min_calls = atoi (optarg);
+ bb_min_calls = (unsigned long) strtoul (optarg, (char **) NULL, 10);
break;
case 'n':
sym_id_add (optarg, INCL_TIME);
total_time > 0.0 ? 100 * sym->hist.time / total_time : 0.0,
accum_time / hz, sym->hist.time / hz);
}
- if (sym->ncalls)
+ if (sym->ncalls != 0)
{
- printf (" %8d %8.2f %8.2f ",
+ printf (" %8lu %8.2f %8.2f ",
sym->ncalls, scale * sym->hist.time / hz / sym->ncalls,
scale * (sym->hist.time + sym->cg.child_time) / hz / sym->ncalls);
}
const Sym *left = *(const Sym **) lp;
const Sym *right = *(const Sym **) rp;
double time_diff;
- long call_diff;
time_diff = right->hist.time - left->hist.time;
if (time_diff > 0.0)
return -1;
}
- call_diff = right->ncalls - left->ncalls;
- if (call_diff > 0)
+ if (right->ncalls > left->ncalls)
{
return 1;
}
- if (call_diff < 0)
+ if (right->ncalls < left->ncalls)
{
return -1;
}
for (index = 0; index < symtab.len; ++index)
{
sym = time_sorted_syms[index];
- if (sym->ncalls)
+ if (sym->ncalls != 0)
{
time = (sym->hist.time + sym->cg.child_time) / sym->ncalls;
if (time > top_time)
}
}
}
- if (top_dog && top_dog->ncalls && top_time > 0.0)
+ if (top_dog && top_dog->ncalls != 0 && top_time > 0.0)
{
top_time /= hz;
while (SItab[log_scale].scale * top_time < 1000.0
*/
DBG (CALLDEBUG,
printf ("\tdestpc 0x%lx (%s)\n", destpc, child->name));
- arc_add (parent, child, (long) 0);
+ arc_add (parent, child, (unsigned long) 0);
instructp += 4; /* call is a 5 byte instruction */
continue;
}
{
struct source_file *next;
const char *name; /* name of source file */
- int ncalls; /* # of "calls" to this file */
+ unsigned long ncalls; /* # of "calls" to this file */
int num_lines; /* # of lines in file */
int nalloced; /* number of lines allocated */
void **line; /* usage-dependent per-line data */
if (child->addr == dest_pc)
{
/* a hit: */
- arc_add (parent, child, 0);
+ arc_add (parent, child, (unsigned long) 0);
continue;
}
}
right->name ? right->name : "*", right->addr,
right->end_addr,
table_name[id->which_table]));
- arc_add (left, right, 0);
+ arc_add (left, right, (unsigned long) 0);
}
}
}
is_bb_head:1, /* is this the head of a basic-blk? */
mapped:1, /* this symbol was mapped to another name */
has_been_placed:1; /* have we placed this symbol? */
- int ncalls; /* how many times executed */
+ unsigned long ncalls; /* how many times executed */
int nuses; /* how many times this symbol appears in
a particular context */
bfd_vma bb_addr[NBBS]; /* address of basic-block start */
- int bb_calls[NBBS]; /* how many times basic-block was called */
+ unsigned long bb_calls[NBBS]; /* how many times basic-block was called */
struct sym *next; /* for building chains of syms */
struct sym *prev; /* for building chains of syms */
/* call-graph specific info: */
struct
{
- int self_calls; /* how many calls to self */
+ unsigned long self_calls; /* how many calls to self */
double child_time; /* cumulative ticks in children */
int index; /* index in the graph list */
int top_order; /* graph call chain top-sort order */
* [are there others that we miss?,
* e.g. arrays of pointers to functions???]
*/
- arc_add (parent, &indirectchild, (long) 0);
+ arc_add (parent, &indirectchild, (unsigned long) 0);
length += tahoe_operandlength (instructp + length);
continue;
case byterel:
/*
* a hit
*/
- arc_add (parent, child, (long) 0);
+ arc_add (parent, child, (unsigned long) 0);
length += tahoe_operandlength (instructp + length);
continue;
}
* [are there others that we miss?,
* e.g. arrays of pointers to functions???]
*/
- arc_add (parent, &indirectchild, (long) 0);
+ arc_add (parent, &indirectchild, (unsigned long) 0);
length += vax_operandlength (
(struct modebyte *) (instructp + length));
continue;
/*
* a hit
*/
- arc_add (parent, child, (long) 0);
+ arc_add (parent, child, (unsigned long) 0);
length += vax_operandlength ((struct modebyte *)
(instructp + length));
continue;