I'm doing the chapter in Learn C the Hard Way about Valgrind, but my line numbers aren't showing up despite using -g. I'm running Yosemite 10.10.3 and Valgrind 3.10.1.
My 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)
and my ex4.c file: (Intentionally broken)
#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;
}
I've looked at this, which is my exact issue through on Ubuntu but the solution isn't working for me. I've also created my .dSYM file. My valgrind output is:
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)
Thanks to @JonathanLeffler for helping me solve the issue. After his comment, I changed my Makefile to:
and the line numbers are showing up and the
warning: no debug symbols in executable (-arch x86_64
error is gone.