How can I use GDB with GCOV?

I looked at this article here: http://www.linux-mag.com/id/1409/

#include <stdlib.h>

#include <stdio.h>


int main(argc, argv)

int argc;

char **argv;

{

  int x, y;

  int arraysize;

  int **array;

  if (argc != 2) {

    printf(“Usage: %s Enter arraysize value n”,argv[0]);

    exit(-1);

  } else {

    arraysize = atoi (argv[1]);

    if (arraysize <= 0) {

      printf(“Array size must be larger than 0 n”);

      exit(-1);

    }

  }


  array = (int **) malloc (arraysize*sizeof (int *));


  printf(“Creating an %d by %d array n”, arraysize, arraysize);


  if (array == NULL) {

    printf(“Malloc failed for array size %d n”, arraysize);

    exit(-1);

  }

  for (x=0; x < arraysize; x++) {

    array[x] = (int *) malloc (arraysize*sizeof (int));

    if (array[x] == NULL) {

34:      printf(“Failed malloc for array size %d n”, arraysize);

      exit(-1);

    }

  }

  exit(0);

}

And the article is straightforward. It suggests using GDB to get coverage by "jump"ing to the lines which are normally unreachable. However, it doesn't work as described. What I found is that if I use the "jump" command in GDB, gcov does not recognize the line as executed. I have to actually break on the line before, and munge the array variable to force the code to recognize a malloc failure. In general, this may or may not be as easy. Jump seems like an easier way to get to code, but it's not working.

So there are really 2 questions here.

Why doesn't gcov recognize a gdb jump?

Why does one version of gcov/gdb recognize a jump and another does not? How can I tell whether the 2 programs are compatible or not?

Thanks.

链接地址: http://www.djcxy.com/p/51010.html

上一篇: gcov不会生成头文件的覆盖率信息

下一篇: 我如何在GCOV上使用GDB?