尽管-g标志和-track-originins =是,但Valgrind没有显示行号

时间:2014-12-20 23:25:18

标签: c debugging valgrind

我在这里读过类似的问题: Valgrind not showing line numbers in spite of -g flag (on Ubuntu 11.10/VirtualBox)

但是,解决方案并没有解决我的问题。请参阅下面的valgrind输出。它没有告诉我主函数中的行号。

我的软件版本: gcc版本4.8.2(Ubuntu 4.8.2-19ubuntu1) Valgrind的-3.10.0.SVN

以下是源代码:

#include<stdio.h>

/* warining: this program is wrong on purpose. */
int main(){
  int age = 10;
  int height;

  printf("I am %d years old.\n");
  printf("I am %d inches tall.\n", height);

  return 0;
}

生成文件:

CFLAGS = -Wall -g -static
src = ex4.c

all: $(src)
  cc -o ex4 $(src)

clean:
  rm -f ex4

Valgrind命令:

$valgrind --track-origins=yes ./ex4

Valgrind输出:

==10268== Memcheck, a memory error detector
==10268== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==10268== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==10268== Command: ./ex4
==10268== 
I am -16779272 years old.
==10268== Conditional jump or move depends on uninitialised value(s)
==10268==    at 0x4E8147E: vfprintf (vfprintf.c:1660)
==10268==    by 0x4E8B388: printf (printf.c:33)
==10268==    by 0x40055E: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268==  Uninitialised value was created by a stack allocation
==10268==    at 0x40052D: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268== 
==10268== Use of uninitialised value of size 8
==10268==    at 0x4E8093B: _itoa_word (_itoa.c:179)
==10268==    by 0x4E845E6: vfprintf (vfprintf.c:1660)
==10268==    by 0x4E8B388: printf (printf.c:33)
==10268==    by 0x40055E: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268==  Uninitialised value was created by a stack allocation
==10268==    at 0x40052D: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268== 
==10268== Conditional jump or move depends on uninitialised value(s)
==10268==    at 0x4E80945: _itoa_word (_itoa.c:179)
==10268==    by 0x4E845E6: vfprintf (vfprintf.c:1660)
==10268==    by 0x4E8B388: printf (printf.c:33)
==10268==    by 0x40055E: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268==  Uninitialised value was created by a stack allocation
==10268==    at 0x40052D: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268== 
==10268== Conditional jump or move depends on uninitialised value(s)
==10268==    at 0x4E84632: vfprintf (vfprintf.c:1660)
==10268==    by 0x4E8B388: printf (printf.c:33)
==10268==    by 0x40055E: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268==  Uninitialised value was created by a stack allocation
==10268==    at 0x40052D: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268== 
==10268== Conditional jump or move depends on uninitialised value(s)
==10268==    at 0x4E81549: vfprintf (vfprintf.c:1660)
==10268==    by 0x4E8B388: printf (printf.c:33)
==10268==    by 0x40055E: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268==  Uninitialised value was created by a stack allocation
==10268==    at 0x40052D: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268== 
==10268== Conditional jump or move depends on uninitialised value(s)
==10268==    at 0x4E815CC: vfprintf (vfprintf.c:1660)
==10268==    by 0x4E8B388: printf (printf.c:33)
==10268==    by 0x40055E: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268==  Uninitialised value was created by a stack allocation
==10268==    at 0x40052D: main (in /home/rex/rex/projects/programming/c/learn_hard_way/ex4/ex4)
==10268== 
I am 0 inches tall.
==10268== 
==10268== HEAP SUMMARY:
==10268==     in use at exit: 0 bytes in 0 blocks
==10268==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==10268== 
==10268== All heap blocks were freed -- no leaks are possible
==10268== 
==10268== For counts of detected and suppressed errors, rerun with: -v
==10268== ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 0 from 0)

1 个答案:

答案 0 :(得分:5)

cc -o ex4 $(src)

您实际上从未使用包含CFLAGS的变量-g。尝试:

cc $(CFLAGS) -o ex4 $(src)