ウォッチポイント番号を知らずにウォッチポイントを削除することはできますか?
ブレークポイントにアタッチされたコマンドを使用して、メモリ位置にウォッチポイントを設定しています。別のブレークポイントでウォッチポイントをクリアしたいのですが、ウォッチポイント番号なしでウォッチポイントをクリアする方法がわかりません。メモリ位置ごとにウォッチポイントを削除できるコマンドはありますか?
ウォッチポイント番号を知らずにウォッチポイントを削除することはできますか?
ブレークポイントにアタッチされたコマンドを使用して、メモリ位置にウォッチポイントを設定しています。別のブレークポイントでウォッチポイントをクリアしたいのですが、ウォッチポイント番号なしでウォッチポイントをクリアする方法がわかりません。メモリ位置ごとにウォッチポイントを削除できるコマンドはありますか?
最も簡単な方法は、$bpnum コンビニエンス変数を使用することです。後でブレークポイント/ウォッチポイントを作成したときに変更されないように、別のコンビニエンス変数に格納することをお勧めします。
(gdb) watch y
(gdb) set $foo_bp=$bpnum
Hardware watchpoint 2: y
(gdb) p $foo_bp
$1 = 2
(gdb) delete $foo_bp
ウォッチポイント番号を保存してから、この番号を使用してウォッチポイントを削除するのはどうですか?
これは一例です。私はC++プログラムを持っています。5 行目のブレークポイントに到達したときに 3 つのウォッチポイントを設定します。ウォッチポイント #2 では、後で削除するために gdb コマンド ファイルを保存します。9 のブレークポイントに到達したら、次の gdb コマンド ファイルを実行します。
これは main.cpp です:
#include <stdio.h>
int main()
{
int v3=2, v2=1, v1 =0 ;
printf("Set a watchpoint\n");
v1 = 1;
v1 = 2;
printf("Clear the watchpoint\n");
v1 = 3;
v1 = 4;
return 0;
}
これは .gdbinit です:
file ./a.out
b 5
commands
watch v2
watch v1
set pagination off
shell rm -f all_watchpoints
set logging file all_watchpoints
set logging on
info watchpoints
set logging off
shell rm -f delete_my_watchpoint
shell tail -n 1 all_watchpoints | awk ' {print "delete "$1 }' > delete_my_watchpoint
watch v3
echo Done\n
c
end
b 9
commands
source delete_my_watchpoint
info watchpoints
end
r
これは、ウォッチポイントを削除するコマンドでファイルを保存する代わりに、ウォッチポイント番号を保存する .gdbinit のわずかに変更されたバージョンです。
file ./a.out
b 5
commands
watch v2
watch v1
set pagination off
shell rm -f all_watchpoints
set logging file all_watchpoints
set logging on
info watchpoints
set logging off
shell rm -f delete_my_watchpoint
shell tail -n 1 all_watchpoints | awk ' {print "set $watchpoint_to_delete_later="$1 }' > save_my_watchpoint_number
source save_my_watchpoint_number
shell rm -f save_my_watchpoint_number
shell rm -f all_watchpoints
watch v3
echo Done\n
c
end
b 9
commands
delete $watchpoint_to_delete_later
info watchpoints
end
r
この方法でアドレスを使用してウォッチポイントを設定した場合:
(gdb) watch *((int*)0x22ff44)
Hardware watchpoint 3: *((int*)0x22ff44)
(gdb) info watchpoints
Num Type Disp Enb Address What
3 hw watchpoint keep y *((int*)0x22ff44)
このアドレスは に表示されるため、後で見つけることもできます。info watchpoints
(gdb) set logging file all_watchpoints
(gdb) set logging on
Copying output to all_watchpoints.
(gdb) info watchpoints
Num Type Disp Enb Address What
3 hw watchpoint keep y *((int*)0x22ff44)
4 hw watchpoint keep y *((int*)0x22ff48)
5 hw watchpoint keep y *((int*)0x22ff4B)
(gdb) set logging of
Done logging to all_watchpoints.
(gdb) shell grep 0x22ff48 all_watchpoints
4 hw watchpoint keep y *((int*)0x22ff48)
(gdb) shell grep 0x22ff48 all_watchpoints | awk ' {print $1}'
4
(gdb) shell grep 0x22ff48 all_watchpoints | awk ' {print "delete "$1}' > delete_watchpoint
(gdb) source delete_watchpoint
(gdb) info watchpoints
Num Type Disp Enb Address What
3 hw watchpoint keep y *((int*)0x22ff44)
5 hw watchpoint keep y *((int*)0x22ff4B)