break *main
和break main()
本质上有什么区别?例如:
#include <iostream>
using namespace std;
int main()
{
int x=30;
int y=40;
x=y;
return 0;
}
当我使用 break *main
and时watch x
,它是这样的:
(gdb) b *main
Breakpoint 1 at 0x400674: file aa.cpp, line 4.
(gdb) r
Starting program: /root/dd/aa.out
Breakpoint 1, main () at aa.cpp:4
4 {
(gdb) n
5 int x=30;
(gdb) watch x
Hardware watchpoint 2: x
(gdb) c
Continuing.
Hardware watchpoint 2: x
Old value = 0
New value = 30
main () at aa.cpp:6
6 int y=40;
(gdb) c
Continuing.
Hardware watchpoint 2: x
Old value = 30
New value = 40
main () at aa.cpp:8
8 return 0;
(gdb)
但是当我使用break main()
and时watch x
,它是这样的:
(gdb) b main()
Breakpoint 1 at 0x400678: file aa.cpp, line 5.
(gdb) r
Starting program: /root/dd/aa.out
Breakpoint 1, main () at aa.cpp:5
5 int x=30;
(gdb) watch x
Hardware watchpoint 2: x
(gdb) c
Continuing.
Hardware watchpoint 2: x
Old value = 0
New value = 40
main () at aa.cpp:8
8 return 0;
(gdb)
为什么它们不同?本质上有什么区别?
当我观察一个数组时,如果我使用break main()
,它会出现:
Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
但如果我使用break *main
,它不会出现,为什么?