在GDB中,主要的VS break main() [英] break *main VS break main() in GDB
问题描述
从本质上讲, break * main
和 break main()
之间有什么区别?例如:
:
#include< iostream>
使用namespace std;
int main()
{
int x = 30;
int y = 40;
x = y;
返回0;
}
当我使用 break * main
和 watch x
,它是这样的:
(gdb )b * main
在0x400674的断点1:文件aa.cpp,第4行。
(gdb)r
启动程序:/root/dd/aa.out
断点1 ,main()at aa.cpp:4
4 {
(gdb)n
5 int x = 30;
(gdb)手表x
硬件观察点2:x
(gdb)c
继续。
硬件观察点2:x
旧值= 0
新值= 30
aa.cpp的main():6
6 int y = 40;
(gdb)c
继续。
硬件观察点2:x
旧值= 30
新值= 40
main()at aa.cpp:8
8 return 0;
(gdb)
但是当我使用 break main() 和
watch x
,它是这样的:
<$ c $
(gdb)r
启动程序:/root/dd/aa.out
断点1,aa.cpp处的main():5
5 int x = 30;
(gdb)手表x
硬件观察点2:x
(gdb)c
继续。
硬件观察点2:x
旧值= 0
新值= 40
main()at aa.cpp:8
8 return 0;
(gdb)
他们为什么不同?而当我看到一个数组时,如果我使用 break main()
,那么在本质上有什么区别呢?
,它会出现:
Watchpoint 2被删除,因为程序已经离开
中的块,其表达式有效。
但是如果我使用 break * main
,它不会出现,为什么?
本质上的区别是什么
不同的是 b * main
在 main
,while b main
在函数prolog 之后的第一条指令中断。
在我的版本中( g ++ -g t.cc
,使用 gcc 4.8.4-2ubuntu1〜14.04.3
和
gdb 7.9
),反汇编源代码如下所示:
< code $(gdb)disas main
函数main()的汇编代码转储:
0x00000000004006cd< + 0> ;: push%rbp
0x00000000004006ce< + 1> ;: mov %rsp,%rbp
0x00000000004006d1< + 4> ;: movl $ 0x1e,-0x8(%rbp)
0x00000000004006d8< + 11> ;: movl $ 0x28,-0x4(%rbp)
0x00000000004006df< + 18> ;: mov -0x4(%rbp),%e ax
0x00000000004006e2< + 21> ;: mov%eax,-0x8(%rbp)
0x00000000004006e5< + 24> ;: mov $ 0x0,%eax
0x00000000004006ea< + 29>: pop%rbp
0x00000000004006eb< + 30>:retq
汇编程序转储结束。
设置 b * main
vs. <
$ main $
$ main $ $ $ $ $ $断点1在0x4006cd:文件tc,第4行。
(gdb)b main
断点2在0x4006d1:文件tc,第5行。
$ p
$ b
我无法重现您观察到的问题:
$ $ $ $ $ $ $ $ r
启动程序:/tmp/a.out
断点1,main()在tc:4
4 {
(gdb)c
继续。
断点2,t.c中的main():5
5 int x = 30;
(gdb)p x
$ 1 = 0
(gdb)手表x
硬件观察点3:x
(gdb)c
继续。
硬件观察点3:x
旧值= 0
新值= 30
main()在t.c:6
6 int y = 40;
what is the difference between break *main
and break main()
in essence?
for example:
#include <iostream>
using namespace std;
int main()
{
int x=30;
int y=40;
x=y;
return 0;
}
when I use break *main
and watch x
, it is this:
(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)
but when I use break main()
and watch x
, it is this:
(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)
why are they different? And what is the difference in essence?
And when I watch an array, if I use break main()
, it will appear:
Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
but if I use break *main
, it will not appear, why?
And what is the difference in essence
The difference is that b *main
breaks on the first instruction of main
, while b main
breaks on the first instruction after function prolog.
In my build (g++ -g t.cc
, using gcc 4.8.4-2ubuntu1~14.04.3
and gdb 7.9
), disassembly of your source looks like this:
(gdb) disas main
Dump of assembler code for function main():
0x00000000004006cd <+0>: push %rbp
0x00000000004006ce <+1>: mov %rsp,%rbp
0x00000000004006d1 <+4>: movl $0x1e,-0x8(%rbp)
0x00000000004006d8 <+11>: movl $0x28,-0x4(%rbp)
0x00000000004006df <+18>: mov -0x4(%rbp),%eax
0x00000000004006e2 <+21>: mov %eax,-0x8(%rbp)
0x00000000004006e5 <+24>: mov $0x0,%eax
0x00000000004006ea <+29>: pop %rbp
0x00000000004006eb <+30>: retq
End of assembler dump.
And setting b *main
vs. b main
produces:
(gdb) b *main
Breakpoint 1 at 0x4006cd: file t.c, line 4.
(gdb) b main
Breakpoint 2 at 0x4006d1: file t.c, line 5.
I can not reproduce the problem you observed:
(gdb) r
Starting program: /tmp/a.out
Breakpoint 1, main () at t.c:4
4 {
(gdb) c
Continuing.
Breakpoint 2, main () at t.c:5
5 int x=30;
(gdb) p x
$1 = 0
(gdb) watch x
Hardware watchpoint 3: x
(gdb) c
Continuing.
Hardware watchpoint 3: x
Old value = 0
New value = 30
main () at t.c:6
6 int y=40;
这篇关于在GDB中,主要的VS break main()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!