2011-10-03 7 views
17

私はGoogleのヒープチェッカーを使用してメモリリークを追跡しています。私はこれらのメモリアドレスが対応どのようなコードの機能/ラインを決定するにはどうすればよいGDBを使用してメモリアドレスがどの機能に対応しているかを調べる

Leak of 21 bytes in 1 objects allocated from:                                        
    @ 0xf6088241                                                
    @ 0xf60890d2                                                
    @ 0xf6089246                                                
    @ 0x8054781                                                 
    @ 0x8054862                                                 
    @ 0xf684ee76                                                
    @ 0xf684f343                                                
    @ 0x804be4c                                                 
    @ 0x80544f6                                                 
    @ 0xf5e52bb6                                                
    @ 0x804b101 

:それはのような私にスタックトレースを与えますか?

+3

Googleのヒープチェッカーがこの変換を実行しないことに驚いています。あなたは "-g"でコンパイルしてもよろしいですか? (また、[addr2lineコマンド](http://sourceware.org/binutils/docs/binutils/addr2line.html)をご覧ください) – Nemo

+0

シンボルタイプの質問:http://stackoverflow.com/questions/762628/ gdb-get-a-memory-address-from-a-memory-address –

答えて

33

info symbol gdbコマンドを使用してください。 16 Examining the Symbol Table

info symbol addr 
Print the name of a symbol which is stored at the address addr. If no symbol is stored exactly at addr, gdb prints the nearest symbol and an offset from it: 
      (gdb) info symbol 0x54320 
      _initialize_vx + 396 in section .text 

This is the opposite of the info address command. You can use it to find out the name of a variable or a function given its address. 

For dynamically linked executables, the name of executable or shared library containing the symbol is also printed: 

      (gdb) info symbol 0x400225 
      _start + 5 in section .text of /tmp/a.out 
      (gdb) info symbol 0x2aaaac2811cf 
      __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6 
+0

infoコマンドのリストを得た後、 'info address'がアドレスを参照していないことを知り、' info symbolコマンドは、シンボルを照会しません。 –

2

があなたのバイナリと仮定すると、あなたが情報を取得するためにx/を使用することができるかもしれg++ -gデバッグ情報を持って、私はvtableをのために働くことを知っています。

x/<num>xw<num>の16進数の単語を印刷します。gdbは左側のページにそのアドレスの情報を注釈します。

1

元の質問には、GDBでこれを行う方法を尋ねた:

# NOT what you want; note the lack of '*': 
(gdb) info symbol 0xfde09edc 
blah() + 388 in section .text of /tmp/libblah.so 

# IS what you want; note the presence of '*': 
(gdb) info line *0xfde09edc 
Line 91 of "blah.cc" 
    starts at address 0xfde09ebc <blah()+356> 
    and ends at 0xfde09ee4 <blah()+396> 

*info lineのために必要であるとinfo symbolのために使用すべきではありません。

また、その/mフラグを付けてdisassembleコマンドを使用することができます。

(gdb) disassemble /m 0xfde09edc 

...それはかなり冗長だとinfo lineが要求された、まさに提供しますけれども。

+0

'/ m'修飾子は'/s'を優先して廃止されました(gdb 7.11に登場)。とにかく、関数全体を逆アセンブルするのではなく、 'x/i 0xfde09edc'の出力をあまり控えめに使うことができます。 – Ruslan

関連する問題