我向makefile添加了-g选项,如下所示:

CFLAGS=-Wall -g

all:
        cc hello.c -o hello
        cc badprog.c -o badprog

当我使用make编译时:
 cc hello.c -o hello
 cc badprog.c -o badprog

我在这里看不到-g选项。valgrind --track-origins=yes ./badprog的结果如下:
 ==14412== Conditional jump or move depends on uninitialised value(s)
 ==14412==    at 0x4E7D665: _itoa_word (_itoa.c:179)
 ==14412==    by 0x4E81B91: vfprintf (vfprintf.c:1654)
 ==14412==    by 0x4E880A8: printf (printf.c:34)
 ==14412==    by 0x400564: main (in /home/anr/Desktop/c programming/badprog)
 ==14412==  Uninitialised value was created by a stack allocation
 ==14412==    at 0x40052C: main (in /home/anr/Desktop/c programming/badprog)

最佳答案

因为编译命令中没有引用CFLAGS。将Makefile修改为:

CFLAGS=-Wall -g

all:
        cc hello.c $(CFLAGS) -o hello
        cc badprog.c $(CFLAGS) -o badprog

关于c - Valgrind不显示行号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20170492/

10-08 22:55