Valgrind没有显示行号 - 约塞米蒂10.10.3

时间:2015-06-14 22:32:45

标签: c macos valgrind

我正在学习关于Valgrind的艰难方法的章节,但尽管使用了-g,但我的行号并没有显示出来。我正在运行Yosemite 10.10.3和Valgrind 3.10.1。

我的Makefile:

CC = gcc
CFLAGS=-Wall -g -static

FILES = ex1 ex3 ex4

all: $(FILES)

ex1: ex1.c
    $(CC) $(CFlAGS) -o ex1 ex1.c

ex3: ex3.c
    $(CC) $(CFlAGS) -o ex3 ex3.c

ex4: ex4.c
    $(CC) $(CFlAGS) -o ex4 ex4.c

clean:
    $(RM) $(FILES)

和我的ex4.c文件:(故意破坏)

#include <stdio.h>

int main(int argc, char *argv[]){
    int age  = 18;
    int height;

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

    return 0;
}

我已经查看了this,这是我在Ubuntu上的确切问题,但解决方案并不适合我。我还创建了我的.dSYM文件。我的valgrind输出是:

MacBook-Pro:c jaredramirez$ valgrind --dsymutil=yes --track-origins=yes 

./ex4
==649== Memcheck, a memory error detector
==649== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==649== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==649== Command: ./ex4
==649== 
--649-- run: /usr/bin/dsymutil "./ex4"
warning: no debug symbols in executable (-arch x86_64)
==649== Conditional jump or move depends on uninitialised value(s)
==649==    at 0x1003FAC3F: _platform_memchr$VARIANT$Haswell (in /usr/lib/system/libsystem_platform.dylib)
==649==    by 0x1001EEB96: __sfvwrite (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F8FE5: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021E9AE: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021EC80: __xvprintf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F4B71: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F29D7: printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x100000F2D: main (in ./ex4)
==649==  Uninitialised value was created by a stack allocation
==649==    at 0x1001F4BF8: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==649== 
I am 75508496 years old.
==649== Conditional jump or move depends on uninitialised value(s)
==649==    at 0x1001F69F1: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021E9AE: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021EC80: __xvprintf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F4B71: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F29D7: printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x100000F41: main (in ./ex4)
==649==  Uninitialised value was created by a stack allocation
==649==    at 0x7FFF5FC01036: _dyld_start (in /usr/lib/dyld)
==649== 
==649== Conditional jump or move depends on uninitialised value(s)
==649==    at 0x1001F6B1B: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021E9AE: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021EC80: __xvprintf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F4B71: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F29D7: printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x100000F41: main (in ./ex4)
==649==  Uninitialised value was created by a stack allocation
==649==    at 0x7FFF5FC01036: _dyld_start (in /usr/lib/dyld)
==649== 
==649== Conditional jump or move depends on uninitialised value(s)
==649==    at 0x1001F9555: __ultoa (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F6B5E: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021E9AE: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021EC80: __xvprintf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F4B71: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F29D7: printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x100000F41: main (in ./ex4)
==649==  Uninitialised value was created by a stack allocation
==649==    at 0x7FFF5FC01036: _dyld_start (in /usr/lib/dyld)
==649== 
==649== Syscall param write(buf) points to uninitialised byte(s)
==649==    at 0x1002F997A: write$NOCANCEL (in /usr/lib/system/libsystem_kernel.dylib)
==649==    by 0x1001F39EC: _swrite (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001EC4A6: __sflush (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001EEC50: __sfvwrite (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F906C: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021E9AE: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021EC80: __xvprintf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F4B71: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F29D7: printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x100000F41: main (in ./ex4)
==649==  Address 0x100820385 is 5 bytes inside a block of size 4,096 alloc'd
==649==    at 0x1000084BB: malloc (in /usr/local/Cellar/valgrind/HEAD/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==649==    by 0x1001EF836: __smakebuf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x100204387: __swsetup (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021E75D: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x10021EC80: __xvprintf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F4B71: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x1001F29D7: printf (in /usr/lib/system/libsystem_c.dylib)
==649==    by 0x100000F2D: main (in ./ex4)
==649==  Uninitialised value was created by a stack allocation
==649==    at 0x7FFF5FC01036: _dyld_start (in /usr/lib/dyld)
==649== 
I am 0 inches tall.
==649== 
==649== HEAP SUMMARY:
==649==     in use at exit: 38,782 bytes in 425 blocks
==649==   total heap usage: 504 allocs, 79 frees, 44,886 bytes allocated
==649== 
==649== LEAK SUMMARY:
==649==    definitely lost: 0 bytes in 0 blocks
==649==    indirectly lost: 0 bytes in 0 blocks
==649==      possibly lost: 0 bytes in 0 blocks
==649==    still reachable: 0 bytes in 0 blocks
==649==         suppressed: 38,782 bytes in 425 blocks
==649== 
==649== For counts of detected and suppressed errors, rerun with: -v
==649== ERROR SUMMARY: 6 errors from 5 contexts (suppressed: 0 from 0)

1 个答案:

答案 0 :(得分:1)

感谢@JonathanLeffler帮助我解决问题。在他的评论之后,我将Makefile改为:

CC = gcc
CFLAGS=-Wall -g -static

FILES = ex1 ex3 ex4

all: $(FILES)

ex1: ex1.c
    $(CC) $(CFLAGS) -o ex1 ex1.c

ex3: ex3.c
    $(CC) $(CFLAGS) -o ex3 ex3.c

ex4: ex4.c
    $(CC) $(CFLAGS) -o ex4 ex4.c

clean:
    $(RM) $(FILES)

并显示行号,warning: no debug symbols in executable (-arch x86_64错误消失。