1

watchgdb で使用中に問題に直面しています。コード内の変数を監視しようとしてmいます。しかし、何らかの理由で次のメッセージが表示されます no symbol m in current context。m のスコープがわかるように、7 行目にブレークポイントを設定しました。

    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;
    }

また、「ウォッチ」GDB を使用するにはどうすればよいですか?も見ました。しかし、それはあまり役に立ちませんでした。誰かが私が直面しているこの問題を説明できますか.以下は私のGNUに関連する情報です

    ritesh@ubuntu:~$ 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.
4

1 に答える 1

2

プログラムをデバッガーにロードするとき、プログラムはまだ実行されていません。main()ただし、関数内で "ライブ" を開始し、関数から戻ると "消える"シンボルを見ようとします。

たとえば、このコードでは

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

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

aプログラムの実行を開始する前の値のウォッチとb、実行が入るまでの値のウォッチを設定することはできませんfunc()

于 2012-04-19T18:50:54.380 に答える