Valgrind gives invalid line numbers

I am currently running Ubuntu Raring Ringtail x86. After a new installation and upgrade, I installed Valgrind 3.8.1 according to the instructions in the Learning C The Hard Way tutorial. However, I can run Valgrind, instead of specifying the line number of the error in the code, it just gives me the following:

==9300== by 0x4060714: (below main) (libc-start.c:227) 

The full Valgrind report is here: http://pastebin.com/1spmkFrU

I'm sure I use the -g flag, and using --track-originins = yes will show me where the incorrect function starts, and not where the error is inside the function. (This is the result of using --track: http://pastebin.com/ktvY8HEM )

Here is the makefile code and the code I'm trying to use:

Makefile:

 CFLAGS=-Wall -g EXECUTABLES=ex1 ex3 ex4 all: $(EXECUTABLES) clean: rm -f $(EXECUTABLES) 

code:

 #include <stdio.h> /*This program is purposefully broken */ int main() { int age = 10; int height; printf("I am %d years old.\n"); printf("I am %d inches tall.\n", height); return 0; } 
+4
source share
2 answers

The stack allocation semantics for main() look strange. Try putting the erroneous code in another function, name it main() , and you are likely to get more meaningful results.

More importantly, try adding -Wall and -O to your CFLAGS . Unused variables and misuse of printf() can be detected at compile time.

0
source

This happened to me, in the same tutorials, in exercise 8. Even with tracking turned on, Valgrind did not find a line that was accessed by an illegal address.

It seems that errors that are not fatal to the program, but include access to memory at illegal addresses, are not tied to Valgrind. You can learn more about this here: Excerpt from Valgrind documentation

I think Valgrind will not save you from accessing the wrong places in your memory, so we must be careful.

0
source

All Articles