2

I have read a similar question here: Valgrind not showing line numbers in spite of -g flag (on Ubuntu 11.10/VirtualBox)

However, the solution does not solve my problem. See the output of valgrind below. It does not tell me the line number in my main function.

My software versions: gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) Valgrind-3.10.0.SVN

Here is the source code:

#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;
}

Makefile:

CFLAGS = -Wall -g -static
src = ex4.c

all: $(src)
  cc -o ex4 $(src)

clean:
  rm -f ex4

Valgrind command:

$valgrind --track-origins=yes ./ex4

Valgrind output:

==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)
Community
  • 1
  • 1
drdot
  • 3,215
  • 9
  • 46
  • 81

1 Answers1

6
cc -o ex4 $(src)

You never actually use the variable CFLAGS that contains -g. Try:

cc $(CFLAGS) -o ex4 $(src)
cnicutar
  • 178,505
  • 25
  • 365
  • 392
  • 1
    OP should have also included the '-Wall' parameter, as the compiler would have warned about the two problems in the program, long before valgrind even got executed. – user3629249 Dec 21 '14 at 04:54