Valgrind nie wyświetla numerów linii pomimo flagi-g (na Ubuntu 11.10/VirtualBox)

Podążam za "Learn C the Hard Way", a konkretnie rozdziałem o Valgrind . Ten rozdział daje celowo zły program, aby pokazać, jak działa Valgrind.

Kiedy uruchamiam ćwiczenie pod Valgrind, nie dostaję numerów linii w moim śledzeniu stosu, tylko '(poniżej main) ' dla błędów.

Jestemdefinitywnie kompiluję z flagą-g.

Moje wyjście Valgrind jest następujące:

djb@twin:~/projects/Learning/C$ valgrind ./ex4
==5190== Memcheck, a memory error detector
==5190== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==5190== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==5190== Command: ./ex4
==5190== 
==5190== Use of uninitialised value of size 4
==5190==    at 0x4078B2B: _itoa_word (_itoa.c:195)
==5190==    by 0x407CE55: vfprintf (vfprintf.c:1619)
==5190==    by 0x40831DE: printf (printf.c:35)
==5190==    by 0x4052112: (below main) (libc-start.c:226)
==5190== 
==5190== Conditional jump or move depends on uninitialised value(s)
==5190==    at 0x4078B33: _itoa_word (_itoa.c:195)
==5190==    by 0x407CE55: vfprintf (vfprintf.c:1619)
==5190==    by 0x40831DE: printf (printf.c:35)
==5190==    by 0x4052112: (below main) (libc-start.c:226)
==5190== 
==5190== Conditional jump or move depends on uninitialised value(s)
==5190==    at 0x407CC10: vfprintf (vfprintf.c:1619)
==5190==    by 0x40831DE: printf (printf.c:35)
==5190==    by 0x4052112: (below main) (libc-start.c:226)
==5190== 
==5190== Conditional jump or move depends on uninitialised value(s)
==5190==    at 0x407C742: vfprintf (vfprintf.c:1619)
==5190==    by 0x40831DE: printf (printf.c:35)
==5190==    by 0x4052112: (below main) (libc-start.c:226)
==5190== 
I am 0 years old.
I am 68882420 inches tall.
==5190== 
==5190== HEAP SUMMARY:
==5190==     in use at exit: 0 bytes in 0 blocks
==5190==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==5190== 
==5190== All heap blocks were freed -- no leaks are possible
==5190== 
==5190== For counts of detected and suppressed errors, rerun with: -v
==5190== Use --track-origins=yes to see where uninitialised values come from
==5190== ERROR SUMMARY: 22 errors from 4 contexts (suppressed: 11 from 6)
Używam Ubuntu 11.10 w wirtualnej maszynie wirtualnej VirtualBox.

Dziękuję za wszelką pomoc.

Update

Wydaje się, że jeśli wywołuję funkcję z {[1] } i ta funkcja zawiera błąd( np. niezainicjalizowaną zmienną), to wykonuję, aby uzyskać ślad do miejsca, w którym funkcja została wywołana w main(). Jednak błędy w main() pozostają nieokreślone. Zobacz ta pasta dla przykładu.

 56
Author: bmargulies, 2012-02-17

7 answers

Wynik podany w pytaniu zawiera następujący wiersz:

==5190== Use --track-origins=yes to see where uninitialised values come from

Na tę wiadomość należy uruchomić ./ex4 Tak:

valgrind --track-origins=yes ./ex4

Aby uniknąć problemów z valgrind nie może znaleźć informacji debugowania, możesz użyć statycznego linkowania:

gcc -static -g  -o ex4  ex4.c 

Wyjście Valgrind będzie zawierać komunikaty typu Uninitialised value was created by a stack allocation:

==17673== Memcheck, a memory error detector
==17673== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==17673== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==17673== Command: ./ex4
...
==17673== Use of uninitialised value of size 4
==17673==    at 0x805CA7B: _itoa_word (in /home/user/ex4)
==17673==    by 0x8049D5F: printf (in /home/user/ex4)
==17673==    by 0x8048ECD: main (ex4.c:8)
==17673==  Uninitialised value was created by a stack allocation
==17673==    at 0x8048EFA: bad_function (ex4.c:17)
...
==17673== Use of uninitialised value of size 4
==17673==    at 0x805CA7B: _itoa_word (in /home/user/ex4)
==17673==    by 0x8049D5F: printf (in /home/user/ex4)
==17673==    by 0x80490BE: (below main) (in /home/user/ex4)
==17673==  Uninitialised value was created by a stack allocation
==17673==    at 0x8048EBE: main (ex4.c:4)
...
I am -1094375076 years old.
...
I am -1094369310 inches tall.
...
==17673== 
==17673== HEAP SUMMARY:
==17673==     in use at exit: 0 bytes in 0 blocks
==17673==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==17673== 
==17673== All heap blocks were freed -- no leaks are possible
==17673== 
==17673== For counts of detected and suppressed errors, rerun with: -v
==17673== ERROR SUMMARY: 83 errors from 21 contexts (suppressed: 0 from 0)

Plik ex4.c:

 1  #include <stdio.h>
 2
 3  int main()
 4  {
 5          int age = 10;
 6          int height;
 7
 8          bad_function();
 9
10          printf("I am %d years old.\n");
11          printf("I am %d inches tall.\n", height);
12
13          return 0;
14  }
15
16  int bad_function() 
17  {
18          int x;
19          printf("%d\n", x);
20  }

Wyjście Valgrinda nie jest idealne. Identyfikuje ramkę stosu (funkcję) zawierającą niezainicjowaną zmienną, ale nie wypisuje nazwy zmiennej.

Uruchomienie Linuksa pod VirtualBox nie ma wpływu na Valgrind.

 53
Author: ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-03-05 14:13:52

Ja też kompilowałem z flagą -g i nadal nie otrzymywałem numerów linii. Po usunięciu katalogu .dSYM dla mojej aplikacji i uruchomieniu valgrind z opcją --dsymutil=yes, w końcu dostałem numery linii.

 16
Author: Jason Denney,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-08-01 21:39:12

W wielu dystrybucjach domyślna wersja glibc nie zawiera symboli debugowania.

Spróbuj zainstalować pakiet libc6-dbg.

 2
Author: wilsaj,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-02-26 22:48:24

Try gcc not cc

Cc nie podaje numerów linii, ale gcc robi

 1
Author: Mujju,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-20 07:25:14

Powinieneś skompilować go za pomocą "- g". test gcc-G.badanie c-O i wtedy valgrind --track-origins=yes --leak-check = full ./ test

 1
Author: sam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-10 08:59:30

Zauważ, że uruchamianie valgrind z --dsymutil=Yes solution es tylko dla Mac OS X.

Według docs:

--dsymutil = nie / tak [nie] Ta opcja jest ważna tylko podczas uruchamiania Valgrind na Mac OS X.

Mac OS X używa systemu linkowania deferred debug information (debuginfo). Gdy pliki obiektowe zawierające debuginfo są połączone wdylib lub an wykonywalny, debuginfo nie jest kopiowane do ostatecznego pliku. Zamiast, debuginfo musi być połączone ręcznie poprzez uruchomienie dsymutil, a systemowe narzędzie, na pliku wykonywalnym lub .dylib. W wyniku połączone debuginfo jest umieszczane w katalogu obok pliku wykonywalnego albo .dylib, ale z przedłużeniem .dSYM.

 1
Author: pablomtz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-24 20:09:37

Ścigałem ten problem i żadna z innych odpowiedzi nie zadziałała. Moje wyjście wyświetla prawidłowe symbole, ale numery linii nie były obecne.

W moim przypadku było to spowodowane używaniem danej biblioteki .zdebug skompresował informacje o numerze linii, a wersja valgrind, której używałem, była stara i nie miała jeszcze wymaganej łatki [0].

Rozwiązaniem było uaktualnienie valgrind do najnowszej wersji.

[0] https://bugs.kde.org/show_bug.cgi?id=303877

 0
Author: feedbackloop,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-12-01 00:57:24