Valgrind no muestra los números de línea a pesar de la bandera-g (en Ubuntu 11.10 / VirtualBox)


Estoy siguiendo 'Aprende C de la manera Difícil', específicamente el capítulo sobre Valgrind . Este capítulo le da un programa deliberadamente equivocado para mostrar cómo funciona Valgrind.

Cuando corro el ejercicio bajo Valgrind no obtengo números de línea en mi seguimiento de pila, solo '(debajo de main)' para los errores.

Estoy definitivamente compilando con la bandera-g.

Mi salida de Valgrind es la siguiente:

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)

Estoy usando Ubuntu 11.10 en una VM VirtualBox.

Gracias para cualquier ayuda.

Update

Parece que si llamo a una función desde main() y esa función contiene un error (por ejemplo, una variable no inicializada), entonces hago obtengo un rastro al lugar donde se llamó a esa función en main(). Sin embargo, los errores dentro de main() permanecen sin especificar. Vea esta pasta para un ejemplo.

 56
Author: bmargulies, 2012-02-17

7 answers

La salida que proporcionaste en tu pregunta contiene la siguiente línea:

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

Por este mensaje deberías ejecutar ./ex4 así:

valgrind --track-origins=yes ./ex4

Para evitar algunos problemas con Valgrind que no puede encontrar información de depuración, puede usar enlaces estáticos:

gcc -static -g  -o ex4  ex4.c 

La salida de Valgrind contendrá mensajes como 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)

File 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  }

La salida de Valgrind no es ideal. Identifica el marco de pila (función) que contiene la variable no inicializada, pero no imprime el nombre de la variable.

Ejecutar Linux bajo VirtualBox no tiene ningún efecto sobre 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-05 14:13:52

Yo también estaba compilando con la bandera -g y todavía no obtenía números de línea. Después de eliminar el directorio .dSYM para mi aplicación, y ejecutar valgrind con la opción --dsymutil=yes, finalmente obtuve números de línea.

 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-01 21:39:12

En muchas distribuciones la versión predeterminada de glibc no contiene símbolos de depuración.

Intente instalar el paquete 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-02-26 22:48:24

Intente gcc no cc

Cc no proporciona los números de línea, pero gcc sí

 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-20 07:25:14

Debería compilarlo con "-g" . prueba gcc-g.prueba c-o y luego valgrind track 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-10 08:59:30

Tenga en cuenta que ejecutar valgrind con la solución d dsymutil=yes es solo para Mac OS X.

Según los documentos:

--dsymutil=no|sí [no] Esta opción solo es relevante cuando se ejecuta Valgrind en Mac OS X.

Mac OS X utiliza un esquema de enlace de información de depuración diferida (debuginfo). Cuando los archivos objeto que contienen debuginfo están vinculados a a .dylib o an ejecutable, el debuginfo no se copia en el archivo final. En su lugar, el debuginfo debe ser enlazado manualmente ejecutando dsymutil, a utilidad proporcionada por el sistema, en el ejecutable o .dylib. El resultado combined debuginfo se coloca en un directorio junto al ejecutable o .dylib, pero con la extensión .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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-24 20:09:37

Perseguí este problema y ninguna de las otras respuestas funcionó. Mi salida mostraba los símbolos correctos, pero los números de línea no estaban presentes.

En mi caso, se debió al uso de la biblioteca en cuestión .zdebug comprimió la información del número de línea, y la versión de valgrind que estaba usando era antigua y aún no tenía el parche necesario [0].

La solución fue actualizar valgrind a la última versión.

[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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-01 00:57:24