drd*_*dot 2 c debugging valgrind
我在这里读到了一个类似的问题: Valgrind尽管没有-g标志显示行号(在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;
}
Run Code Online (Sandbox Code Playgroud)
Makefile文件:
CFLAGS = -Wall -g -static
src = ex4.c
all: $(src)
cc -o ex4 $(src)
clean:
rm -f ex4
Run Code Online (Sandbox Code Playgroud)
Valgrind命令:
$valgrind --track-origins=yes ./ex4
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)cc -o ex4 $(src)
你永远不会真正使用CFLAGS包含的变量-g.尝试:
cc $(CFLAGS) -o ex4 $(src)
Run Code Online (Sandbox Code Playgroud)