2012-04-17 28 views
1

GDBでスタック上の特定の場所に何が格納されているかを調べようとしています。私は-0x10(場合%ebp)に0x176を比較することだし、-0x10(場合%ebp)に格納されているかを確認する方法があるかどうか、私は疑問に思って、この関数でGDBでスタックに格納された変数を見る方法

cmpl $0x176,-0x10(%ebp) 

:私は声明を持っています。

答えて

3

-0x10(%ebp)に格納されているものを確認する手段があるかどうかは疑問です。

デバッグ情報でコンパイルしたと仮定すると、info localsは現在のフレームのすべてのローカル変数について教えてくれます。その後、print (char*)&a_local - (char*)$ebpは、a_localから%ebpまでのオフセットを通知します。通常は、ローカルには0x176に近いものがあります。あなたの地元の人々が初期化子を持っている場合

また、あなたが解体を見て、再びオフセット何に配置されている地元の理解するためにdisas ADDR0,ADDR1そして、命令の範囲は、与えられたローカルの初期化に対応するアセンブリを把握するinfo line NNを行うことができます。

もう一つの選択肢は、readelf -w a.outにあり、このようなエントリを探します。

int foo(int x) { int a = x; int b = x + 1; return b - a; } 

<1><25>: Abbrev Number: 2 (DW_TAG_subprogram) 
<26> DW_AT_external : 1   
<27> DW_AT_name  : foo  
<2b> DW_AT_decl_file : 1   
<2c> DW_AT_decl_line : 1   
<2d> DW_AT_prototyped : 1   
<2e> DW_AT_type  : <0x67> 
<32> DW_AT_low_pc  : 0x0  
<36> DW_AT_high_pc  : 0x23  
<3a> DW_AT_frame_base : 0x0  (location list) 
<3e> DW_AT_sibling  : <0x67> 
<2><42>: Abbrev Number: 3 (DW_TAG_formal_parameter) 
<43> DW_AT_name  : x   
<45> DW_AT_decl_file : 1   
<46> DW_AT_decl_line : 1   
<47> DW_AT_type  : <0x67> 
<4b> DW_AT_location : 2 byte block: 91 0  (DW_OP_fbreg: 0) 
<2><4e>: Abbrev Number: 4 (DW_TAG_variable) 
<4f> DW_AT_name  : a   
<51> DW_AT_decl_file : 1   
<52> DW_AT_decl_line : 1   
<53> DW_AT_type  : <0x67> 
<57> DW_AT_location : 2 byte block: 91 74  (DW_OP_fbreg: -12) 
<2><5a>: Abbrev Number: 4 (DW_TAG_variable) 
<5b> DW_AT_name  : b   
<5d> DW_AT_decl_file : 1   
<5e> DW_AT_decl_line : 1   
<5f> DW_AT_type  : <0x67> 
<63> DW_AT_location : 2 byte block: 91 70  (DW_OP_fbreg: -16) 

これは、xfbreg+0に格納されていることを示していますfbreg-12a、およびfbreg-16b。今度は、fbreg%ebpから派生させる方法を見つけるために位置リストを調べるだけです。上記のコードのリストは次のようになります。身体のほとんどのため

Contents of the .debug_loc section: 

Offset Begin End  Expression 
00000000 00000000 00000001 (DW_OP_breg4: 4) 
00000000 00000001 00000003 (DW_OP_breg4: 8) 
00000000 00000003 00000023 (DW_OP_breg5: 8) 
00000000 <End of list> 

ので、fbrega%ebp-4であることを意味し、%ebp+8です。分解確認:

00000000 <foo>: 
    0: 55      push %ebp 
    1: 89 e5     mov %esp,%ebp 
    3: 83 ec 10    sub $0x10,%esp 
    6: 8b 45 08    mov 0x8(%ebp),%eax # 'x' => %eax 
    9: 89 45 fc    mov %eax,-0x4(%ebp) # '%eax' => 'a' 

...

関連する問題