source

-g 플래그에도 불구하고 Valgrind에 행 번호가 표시되지 않음(Ubuntu 11.10/Virtual Box)

goodcode 2022. 7. 30. 19:13
반응형

-g 플래그에도 불구하고 Valgrind에 행 번호가 표시되지 않음(Ubuntu 11.10/Virtual Box)

나는 'Learn C the Hard Way', 특히 발그린드에 대한 을 따라가고 있다.이 챕터에서는 Valgrind가 어떻게 동작하는지 보여주기 위해 의도적으로 잘못된 프로그램을 제공합니다.

Valgrind에서 연습을 실행하면 스택트레이스에 회선번호는 표시되지 않고 오류에 대한 '아래'만 표시됩니다.

반드시 -g 플래그를 사용하여 컴파일하고 있습니다.

My 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)

Virtual Box 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  }

발그린드의 성과는 이상적이지 않다.초기화되지 않은 변수를 포함하는 스택프레임(함수)을 식별하지만 변수 이름은 출력하지 않습니다.

Virtual Box에서 Linux를 실행해도 Valgrind에는 영향이 없습니다.

나 역시 그 책과 함께 편집하고 있었다.-g플래그를 설정해도 회선번호는 취득되지 않습니다.를 제거한 후.dSYM내 앱의 디렉토리 및 valgrind를 실행한다.--dsymutil=yes옵션, 드디어 회선 번호를 알아냈어.

나는 이 문제를 추구했지만 다른 답변은 효과가 없었다.출력에 올바른 기호가 표시되었지만 행 번호가 표시되지 않았습니다.

제 경우, 문제의 라이브러리에서 .zdebug 압축행 번호 정보를 사용했기 때문에 사용하고 있는 valgrind 버전이 오래되어 아직 필요한 패치가 없습니다[0].

해결방법은밸런드를최신버전으로업그레이드하는 것이었습니다.

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

"-g" . gcc -g test.c -o test를 사용하여 컴파일한 후 valgrind --track-check=yes --valgrind --track-check=full ./test를 수행합니다.

cc가 아닌 gcc를 사용해 보세요.

cc는 회선번호를 제공하지 않지만 gcc는 회선번호를 제공합니다.

대부분의 경우 기본 버전의 glibc에는 디버깅 기호가 포함되어 있지 않습니다.

libc6-dbg 패키지를 설치해 보십시오.

--dsymutil=yes 솔루션과 함께 valgrind를 실행하는 것은 Mac OS X에서만 가능합니다.

문서에 따르면:

--dsymutil=no|yes [no] 이 옵션은 Mac OS X에서 Valgrind를 실행하는 경우에만 해당됩니다.

Mac OS X는 지연 디버깅 정보(debuginfo) 링크 방식을 사용합니다.debuginfo를 포함하는 오브젝트파일이 .dylib 또는 실행파일에 링크되어 있는 경우 debuginfo는 최종 파일에 복사되지 않습니다.대신 실행 파일 또는 .dylib에서 시스템에서 제공하는 유틸리티인 dsymutil을 실행하여 debuginfo를 수동으로 연결해야 합니다.결과적으로 조합된 debuginfo는 실행 파일 또는 .dylib와 함께 디렉토리에 배치되지만 확장자는 .d입니다.SYM

언급URL : https://stackoverflow.com/questions/9321385/valgrind-not-showing-line-numbers-in-spite-of-g-flag-on-ubuntu-11-10-virtualbo

반응형