2016-12-04 7 views
3

break *mainbreak main()の本質的な違いは何ですか?例えば :GDBでブレーク*メインVSブレークmain()

#include <iostream> 
    using namespace std; 
    int main() 
    { 
     int x=30; 
     int y=40; 
     x=y; 
     return 0; 
    } 

私はbreak *mainwatch 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()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を使用している場合、それがなぜ、表示されないのだろうか?関数プロローグ後の最初の命令b main休憩しながら、

+0

'gdb 7.12'と' g ++ 6.2.1'で再現できませんでしたが、これはバージョンによって異なるかもしれません。あなたが使用したバージョンと使用したコンパイルオプションを投稿できますか? –

+0

私のgdbバージョンは6.6、g ++ 4.1.2で、最適化は-O0です(g ++ -g -o aa.out aa.cpp)@FrederikDeweerdt –

答えて

5

そして、どのような違いが違い

本質であるが、mainの最初の命令にb *main休憩ということです。私のビルドで

g++ -g t.ccgcc 4.8.4-2ubuntu1~14.04.3gdb 7.9を使用して)、あなたのソースの分解は、次のようになります。

(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. 

そしてb *mainb mainを設定すると、生成します。私は再現できない

(gdb) b *main 
Breakpoint 1 at 0x4006cd: file t.c, line 4. 
(gdb) b main 
Breakpoint 2 at 0x4006d1: file t.c, line 5. 

あなたが観察した問題:

(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; 
+0

"違いは、メインの最初の命令ではb *メインブレーク、b関数プロローグの後の最初の命令のメインブレーク。 "彼らはほとんど同じ意味ですか? @Employed Russian –

+0

@李鹏程はい、ほとんど同じですが、まったく同じではありません。違いは正確に説明されているとおりです。私はあなたのコメントのポイントを理解していない。 –

関連する問題