2013-08-23 63 views
7

我已經構建並從源代碼安裝GCC 4.8.1:GCC不會產生行號信息,即使-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是太舊了 - 你需要一個較新的gdb的(我用7.6),以瞭解通過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使用矮作爲其主要調試文件格式,你需要用標誌--with-dwarf2構建GCC時啓用矮人支持。

在構建編譯對象時,可以使用-ggdb而不是-g,這是一個更具體的解決方案,但是可以使用just for gdb

+0

好的調試信息,編譯。如果它有效,我會接受。 – Calmarius

+1

其實,矮的問題是 - 他使用Ubuntu的舊版本不理解由海灣合作委員會的最新版本生成調試信息的gdb。 –

+0

呀,--with-DWARF2開關並沒有解決問題。 – Calmarius