Valgrind不显示行号,尽管-g标志和--track origins=yes

Valgrind不显示行号,尽管-g标志和--track origins=yes,c,debugging,valgrind,C,Debugging,Valgrind,我在这里读到了一个类似的问题: 然而,解决方案并不能解决我的问题。请参见下面的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 heigh

我在这里读到了一个类似的问题:

然而,解决方案并不能解决我的问题。请参见下面的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;
}
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)
您从未实际使用包含
-g
的变量
CFLAGS
。尝试:

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

OP还应该包含'-Wall'参数,因为编译器早在valgrind执行之前就已经警告了程序中的两个问题。
cc -o ex4 $(src)
cc $(CFLAGS) -o ex4 $(src)