2012-04-19 3 views
1

gdbでwatchを使用中に問題が発生しました。私は を変数mで私のコードで監視しています。しかし何らかの理由で私は次のメッセージを受け取っています no symbol m in current context。私はmの範囲がわかるように7行目にブレークポイントを置いています。以下は設定GDBの時計が私のために働いていない

steps performed by me :- 
    1>g++ -g a.cpp 
    2>gdb a.out 
    3>(gdb)break 7 
    4>(gdb)watch m 

私のプログラムである: -

# include<iostream> 
    # include<stdio.h> 
    using namespace std; 

    int main() 
    { 

     int m=10; 
     char *abc = (char *)"ritesh"; 
     cout << abc << endl ; 
     m=11; 
     m=13; 
     abc=NULL; 
     cout << *abc <<endl; 

    return 0; 
    } 

私もHow can I use "watch" GDB?を見てきました。しかし、それは非常に私を助けていませんでした。誰かがあなたのプログラムがまだ実行されていないデバッガにロードすると、私のGNU

[email protected]:~$ gdb a.out 
    GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08 
    Copyright (C) 2011 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". 
    For bug reporting instructions, please see: 
    <http://bugs.launchpad.net/gdb-linaro/>... 
    Reading symbols from /home/ritesh/a.out...done. 

答えて

2

に関連した情報であり、私はfacing.Belowいますこの問題を説明することができます。しかし、シンボルを見ることを試みます。これは、関数 "main()"に "live"を開始し、関数から戻ると "消えます"。例えば

実行がfunc()に入るまで、このコード

void func() { 
    int b = 1; 
    ++b; 
    cout << b << endl; 
} 

int main() { 
    int a = 1; 
    func(); 
    cout << a << endl; 
} 

であなたがプログラムを実行開始前aの価値の時計を設定することはできません、とbの値に腕時計。

+0

私はそれを(mdb)のように動かすべきですか?いつ実行すればいいですか? – Invictus

+0

はい、1) 'break' 7; 2) '実行'(デバッガはメインで停止する); 3)「時計m」。 4) 'cont'(デバッガは' m = 11'の後に停止します) – pwes

+0

break文の後にプログラムを実行し、変数の監視を続けて成功しました – Invictus

関連する問題