2017-05-27 8 views
-1

デバッグの学習にgdbを使用しようとしています。オプションを指定せずに次のコードをコンパイルすると、gdbはデバッグシンボルが見つからないことを指摘します。デバッギング情報のデフォルトリンカースクリプト

int main() 
{ 
    return 0; 
} 

$gcc debug.c 
$gdb a.out 
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1 
Copyright (C) 2016 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 "i686-linux-gnu". 
Type "show configuration" for configuration details. 
For bug reporting instructions, please see: 
<http://www.gnu.org/software/gdb/bugs/>. 
Find the GDB manual and other documentation resources online at: 
<http://www.gnu.org/software/gdb/documentation/>. 
For help, type "help". 
Type "apropos word" to search for commands related to "word"... 
Reading symbols from a.out...(no debugging symbols found)...done. 
(gdb) quit 

しかし、私はgcc-gフラグを与えるとき、次のような出力が見られます:

GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1 
Copyright (C) 2016 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 "i686-linux-gnu". 
Type "show configuration" for configuration details. 
For bug reporting instructions, please see: 
<http://www.gnu.org/software/gdb/bugs/>. 
Find the GDB manual and other documentation resources online at: 
<http://www.gnu.org/software/gdb/documentation/>. 
For help, type "help". 
Type "apropos word" to search for commands related to "word"... 
Reading symbols from a.out...done. 
(gdb) Quit 
(gdb) quit 

私が間違っているかを把握し、リンカがどこかにデバッグ情報のストリッピングを有効にしているかどうかを確認するにはどうすればよいです?

+2

完全なビルドトレース(コンパイラ+リンカ)および/またはコマンドライン/メイクファイルが必要です。 –

+0

明示的にメイクファイルを使用しないでください – anushka

答えて

0

ここにはデバッグが含まれていないので、ここではストリッピングはありません。

-gオプションは、が必要です。デバッグ情報を有効にするには、が必要です。 (任意のオプションなし)デフォルトでは

は、デバッグ情報がオブジェクトファイル

に埋め込まではありませんので、正しい方法は次のとおりです。彼らは含まれていない他に、デバッグシンボルを埋め込むようにコンパイラに指示する-gを有効にしますgdbが見つかりません。

(はい、それらを見つけるために、デバッガを回避するための別の方法は、リンカに-Wl,--strip-debugを渡すことですが、それはまた別の話だ)

0

しかし、私はgcc-gフラグを与えるとき、次のような出力が見られます: gdbがエラーなしでデバッグシンボルを読み取るときに、あなたが得る出力だ

Reading symbols from a.out...done.

。それでその時点でデバッガはどこにブレークポイントを置くべきか、そしてデバッグ中のプログラムを実行する準備ができています。