なぜこれが必要なのですか?入力データがあまりにも変化するため、データムの場所は変化し続けます。出力する以外に、手動で GDB に入力できるように 30 秒間スリープしてからプログラムを続行します。見る。しかし、そのようなことは可能ですか?
1 に答える
0
あなたは近づくことができます。簡単にするためにC/C++言語を想定
追跡するデータムへの参照を返す関数を定義します。
// debug.h
extern "C" mydatastruct* GetDatumForDebug();
// debug.cpp
mydatastruct* GetDatumForDebug()
{
if (s_initialized)
return &some_complicated_address_lookup_perhaps_in_Cpp_or_java_orwhatever();
return (mydatastruct*) 0;
}
その後、
(gdb) display GetDatumForDebug()
あるいは
(gdb) display GetDatumForDebug()->s
GetDatumForDebug()の結果をデバッグウォッチで使用できると思いますが、何をするのか、どのように行うのかわかりません:)
これは、速度のために単一のソース(test.cpp)に詰め込まれた実際の例ですg++ -g test.cpp -o test
。
static bool s_initialized = false;
struct mydatastruct { const char* s; };
static mydatastruct& some_complicated_address_lookup_perhaps_in_Cpp_or_java_orwhatever()
{
static mydatastruct s_instance = { "hello world" };
s_initialized = true;
return s_instance;
}
extern "C" mydatastruct* GetDatumForDebug();
// debug.cpp
mydatastruct* GetDatumForDebug()
{
if (s_initialized)
return &some_complicated_address_lookup_perhaps_in_Cpp_or_java_orwhatever();
return (mydatastruct*) 0;
}
int main()
{
// force initialize for demo purpose:
some_complicated_address_lookup_perhaps_in_Cpp_or_java_orwhatever();
return 42;
}
gdbコマンドを自動化する
.gdbinit
作業ディレクトリに以下を追加します。
break main
run
call some_complicated_address_lookup_perhaps_in_Cpp_or_java_orwhatever()
display GetDatumForDebug()? GetDatumForDebug()->s : ""
これにより、そのディレクトリでgdbを起動すると、これらのコマンドが自動的に実行されます。
于 2011-05-18T14:53:56.893 に答える