-g 플래그에도 불구하고 Valgrind가 줄 번호를 표시하지 않음 (Ubuntu 11.10 / VirtualBox에서)
나는 'Learn C the Hard Way', 특히 Valgrind에 대한 장을 따르고 있습니다. 이 장에서는 Valgrind의 작동 방식을 보여주는 의도적으로 잘못된 프로그램을 제공합니다.
Valgrind에서 연습을 실행할 때 스택 추적에서 줄 번호를 얻지 못하고 오류에 대해 '(기본 아래)'만 얻습니다.
나는 확실히 -g 플래그로 컴파일하고 있습니다.
내 Valgrind 출력은 다음과 같습니다.
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)
VirtualBox VM에서 Ubuntu 11.10을 사용하고 있습니다.
도움을 주셔서 감사합니다.
최신 정보
내가에서 함수를 호출하는 경우 것 같다 main()
, 그 함수는 실수 (예를 들어 초기화되지 않은 변수)를 포함, 그럼 내가 않는 함수가 호출되었다는 장소로 추적을 얻을 main()
. 그러나 내의 오류 main()
는 지정되지 않습니다. 예제는 이 페이스트 를 참조하십시오 .
질문에 제공 한 출력에는 다음 행이 포함됩니다.
==5190== Use --track-origins=yes to see where uninitialised values come from
이 메시지에 따라 다음 ./ex4
과 같이 실행해야합니다 .
valgrind --track-origins=yes ./ex4
Valgrind가 디버그 정보를 찾을 수없는 문제를 방지하려면 정적 링크를 사용할 수 있습니다.
gcc -static -g -o ex4 ex4.c
Valgrind의 출력에는 다음과 같은 메시지가 포함됩니다 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)
파일 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 }
Valgrind의 출력은 이상적이지 않습니다. 초기화되지 않은 변수가 포함 된 스택 프레임 (함수)을 식별하지만 변수 이름을 인쇄하지 않습니다.
Running Linux under VirtualBox has no effect on Valgrind.
I too was compiling with the -g
flag and still not getting line numbers. After removing the .dSYM
directory for my app, and running valgrind with the --dsymutil=yes
option, I finally got line numbers.
On many distros the default version of glibc doesn't contain debug symbols.
Try installing the libc6-dbg package.
try gcc not cc
cc does not provide the line numbers, but gcc does
you should compile it with "-g" . gcc -g test.c -o test and then valgrind --track-origins=yes --leak-check=full ./test
Note that running valgrind with the --dsymutil=yes solution es just for Mac OS X.
According to the docs:
--dsymutil=no|yes [no] This option is only relevant when running Valgrind on Mac OS X.
Mac OS X uses a deferred debug information (debuginfo) linking scheme. When object files containing debuginfo are linked into a .dylib or an executable, the debuginfo is not copied into the final file. Instead, the debuginfo must be linked manually by running dsymutil, a system-provided utility, on the executable or .dylib. The resulting combined debuginfo is placed in a directory alongside the executable or .dylib, but with the extension .dSYM.
I chased this problem and none of the other answers worked. My output displayed the correct symbols, but line numbers were not present.
In my case, it was due to the library in question using .zdebug compressed line number info, and the version of valgrind I was using was old and did not yet have the needed patch [0].
The solution was to upgrade valgrind to the latest version.
'Program Tip' 카테고리의 다른 글
MySQL의 기본 ON DELETE 동작은 무엇입니까? (0) | 2020.11.28 |
---|---|
"localhost", 호스트 및 포트의 요점은 무엇입니까? (0) | 2020.11.28 |
Go 프로그래밍에서 [] byte를 int로 변환하는 방법 (0) | 2020.11.28 |
favicon.ico 파일을 루트가 아닌 경로에 넣는 것이 나쁜 생각입니까? (0) | 2020.11.28 |
푸시 알림 자격 경고 누락 (0) | 2020.11.28 |