debuggers.hg

changeset 20919:857d7b2dd8c7

tools/gtraceview: fix SIGFPE

If there are 0 or 1 valid record in xentrace file,
SIGFPE will occur. Fix it.

Signed-off-by: Yu Zhiguo <yuzg@cn.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jan 29 08:59:46 2010 +0000 (2010-01-29)
parents b0ffb4912c46
children 5668c36282ea
files tools/misc/gtraceview.c
line diff
     1.1 --- a/tools/misc/gtraceview.c	Fri Jan 29 08:55:27 2010 +0000
     1.2 +++ b/tools/misc/gtraceview.c	Fri Jan 29 08:59:46 2010 +0000
     1.3 @@ -209,6 +209,11 @@ int main(int argc, char *argv[])
     1.4      if (load_file(fname))
     1.5          exit(EXIT_FAILURE);
     1.6  
     1.7 +    if (!data_cur) {
     1.8 +        fprintf(stderr, "file %s doesn't contain any valid record\n", fname);
     1.9 +        exit(EXIT_FAILURE);
    1.10 +    }
    1.11 +
    1.12      if (mode_init())
    1.13          exit(EXIT_FAILURE);
    1.14  
    1.15 @@ -939,14 +944,15 @@ int time_mode_rebuild(uint64_t start_tim
    1.16      struct cpu cur_state[MAX_CPU_NR];
    1.17      uint64_t tsc = start_time;
    1.18      struct state *state;
    1.19 -    uint64_t number, temp;
    1.20 +    uint64_t number, temp = 0;
    1.21      int state_cur = 0;
    1.22  
    1.23      for (i = 0; i < max_cpu_num; i++)
    1.24          cur_state[i].flag = FLAG_UNKNOWN;
    1.25  
    1.26      /* allocate spaces, it may be huge... */
    1.27 -    temp = (data[data_cur-1].tsc - start_time)/time_scale;
    1.28 +    if (time_scale)
    1.29 +        temp = (data[data_cur-1].tsc - start_time)/time_scale;
    1.30      number = 10000UL;
    1.31      if (temp < number)
    1.32          number = temp;