2013-08-23 11 views
7

과 줄 번호 정보를 생성하지 않습니다GCC는 내가 만든 소스에서 GCC 4.8.1 설치 한 경우에도 -g 옵션

$ gcc -v 
Using built-in specs. 
COLLECT_GCC=gcc 
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper 
Target: x86_64-unknown-linux-gnu 
Configured with: ./configure --disable-multilib 
Thread model: posix 
gcc version 4.8.1 (GCC) 

그리고 간단한 쓸모없는 프로그램을 작성했습니다 :

$ cat hw.c 
#include <stdio.h> 

void foo() 
{ 
    int a; 
    scanf("%d", &a); /* So I can press ctrl+c here. */ 
    printf("Hello world!\n"); 
} 

int main() 
{ 
    foo(); 
} 

지금이 컴파일 :

$ gcc -g -O0 hw.c -o hw 

그런 다음 GDB로 디버깅 시작 :

$ gdb hw 
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04 
Copyright (C) 2012 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. Type "show copying" 
and "show warranty" for details. 
This GDB was configured as "x86_64-linux-gnu". 
For bug reporting instructions, please see: 
<http://bugs.launchpad.net/gdb-linaro/>... 
Reading symbols from /home/calmarius/workdir/crucible/hw/hw...done. 
(gdb) 

실행 그것과 Ctrl + C 즉시 : 나는 역 추적에 함수 이름을 가지고

(gdb) run 
Starting program: /home/dcsirmaz/workdir/crucible/hw/hw 
^C 
Program received signal SIGINT, Interrupt. 
0x00007ffff7b018b0 in __read_nocancel() at ../sysdeps/unix/syscall-template.S:82 
82 ../sysdeps/unix/syscall-template.S: Nincs ilyen fájl vagy könyvtár. 

하지만 내 코드에서 어떤 행 번호가 :

(gdb) bt 
#0 0x00007ffff7b018b0 in __read_nocancel() at ../sysdeps/unix/syscall-template.S:82 
#1 0x00007ffff7a95ff8 in _IO_new_file_underflow (fp=0x7ffff7dd4340) at fileops.c:619 
#2 0x00007ffff7a9703e in _IO_default_uflow (fp=0x7ffff7dd4340) at genops.c:440 
#3 0x00007ffff7a74fb6 in _IO_vfscanf_internal (s=<optimized out>, format=<optimized out>, argptr=0x7fffffffe018, errp=0x0) at vfscanf.c:620 
#4 0x00007ffff7a790bd in __isoc99_scanf (format=<optimized out>) at isoc99_scanf.c:37 
#5 0x000000000040054e in foo() 
#6 0x0000000000400568 in main() 

잘못 됐을없는 일이야? 어쩌면 구성이있는 것입니까?

답변

15

여러분의 GDB는 너무 오래 - 당신이 컴파일, GCC에 의해 4.8.1

+3

보다 정확하게 GCC-4.8의 기본값은 dwarf4 (http://gcc.gnu.org/gcc-4.8/changes.html)이지만 GDB는 너무 오래되어서 이해할 수 없습니다. '-gdwarf-2'로 빌드하면 라인 번호를 다시 얻을 수 있습니다. 또는 GDB를 소스 빌드의 최신 버전으로 업데이트하십시오. –

+0

그래서 gdb 7.4가 너무 오래되었습니다. – Calmarius

+1

gdb 7.6 빌드 및 설치로 문제가 해결되었습니다. – Calmarius

8

보통 GCC는 주 디버깅 파일 형식으로 dwarf를 사용하므로 플래그 --with-dwarf2으로 gcc를 빌드 할 때 드워프 지원을 활성화해야합니다.

컴파일 된 개체를 빌드하는 동안보다 구체적인 해결책 인 -g 대신 -ggdb을 사용할 수 있지만 just for gdb을 사용할 수 있습니다.

+0

확인 생성 된 디버깅 정보를 이해하기 위해 최근 GDB (나는 7.6을 사용)가 필요합니다. 작동한다면, 나는 이것을 받아 들일 것이다. – Calmarius

+1

실제로 드워프는 문제가 있습니다. 우분투의 구버전 인 gdb는 최신 버전의 gcc에서 생성 된 디버그 정보를 이해하지 못합니다. –

+0

예, --with-dwarf2 스위치로 문제가 해결되지 않았습니다. – Calmarius