2011-12-26 3 views
1

GDB의 감시 점을 연구 중입니다. 나는 다음과 같은 간단한 테스트 코드를 작성 : 내 테스트 코드에서왜 워치 포인트가 적용되지 않습니까?

int main(int argc, char **argv) 
{ 
    int x = 30; 
    int y = 10; 

    x = y; 

    return 0; 
} 

I build it via gcc -g -o wt watch.c. And then I started gdb and did following experiment: 
    [email protected]:~/mySrc$ gdb ./wt 
    GNU gdb (GDB) 7.3 
    Copyright (C) 2011 Free Software Foundation, Inc. 
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 
    This is free software: you are free to change and redistribute it. 
    There is NO WARRANTY, to the extent permitted by law. Type "show copying" 
    and "show warranty" for details. 
    This GDB was configured as "i686-pc-linux-gnu". 
    For bug reporting instructions, please see: 
    <http://www.gnu.org/software/gdb/bugs/>... 
    Reading symbols from /home/lihacker/mySrc/wt...done. 
    (gdb) b main 
    Breakpoint 1 at 0x80483a5: file watch.c, line 5. 
    (gdb) run 
    Starting program: /home/lihacker/mySrc/wt 

    Breakpoint 1, main (argc=<optimized out>, argv=<optimized out>) at watch.c:5 
    5  int x = 30; 
    (gdb) watch x 
    Hardware watchpoint 2: x 
    (gdb) c 
    Continuing. 

    Watchpoint 2 deleted because the program has left the block in 
    which its expression is valid. 
    0xb7e83775 in __libc_start_main() from /lib/tls/i686/cmov/libc.so.6 
    (gdb) 

는 변수는 "X"로 변경되지만, GDB는 멈추지 않습니다. 왜 워치 포인트가 여기에 영향을 미치지 않습니까? 고마워.

답변

1

이 :

Breakpoint 1, main (argc=<optimized out>, argv=<optimized out>) at watch.c:5

테스트를 구축 할 때 -O2 또는 일부 같은 플래그를 사용하는 것이 좋습니다. -O0으로 빌드를 시도해보십시오 (명시 적으로 최적화가 사용 중지됨).

GDB에는 글리치 (버그 렛)가 있습니다.

(gdb) b main 
Breakpoint 3 at 0x80483ba: file t.c, line 3. 
(gdb) r 

Breakpoint 3, main (argc=1, argv=0xffffca94) at t.c:3 
3  int x = 30; 
(gdb) watch x 
Hardware watchpoint 4: x 
(gdb) c 
Hardware watchpoint 4: x 

Old value = 0 
New value = 10 
main (argc=1, argv=0xffffca94) at t.c:8 
8  return 0; 
(gdb) c 

Watchpoint 4 deleted because the program has left the block in 
which its expression is valid. 
0xf7e7cbd6 in __libc_start_main() from /lib32/libc.so.6 

이 잘되지 않을 수있다 : 여기서 I는 무엇을보고하지 0 내지 I는 최초 지시에 브레이크 포인트를 설정하는 경우 10.

30 내지 10의 X의 값이 변경, 답장을 보내

(gdb) b *main 
Breakpoint 1 at 0x80483b4: file t.c, line 2. 
(gdb) r 

Breakpoint 1, main (argc=1, argv=0xffffca94) at t.c:2 
2 { 
(gdb) watch x 
Hardware watchpoint 2: x 
(gdb) c 
Hardware watchpoint 2: x 

Old value = 0 
New value = 30 
main (argc=1, argv=0xffffca94) at t.c:4 
4  int y = 10; 
(gdb) c 
Hardware watchpoint 2: x 

Old value = 30 
New value = 10 
main (argc=1, argv=0xffffca94) at t.c:8 
8  return 0; 
(gdb) c 

Watchpoint 2 deleted because the program has left the block in 
which its expression is valid. 
0xf7e7cbd6 in __libc_start_main() from /lib32/libc.so.6 
+0

감사합니다 : 주의, 이 예상대로 작동합니다. 실제로 gcc를 통해 빌드 할 때 최적화 플래그를 설정하지 않았습니다. 비록 당신이 말한 것처럼 -O0을 추가하더라도 결과는 동일합니다. 내 테스트 플랫폼은 가상 머신에서 실행되는 Ubuntu 9.0.4이고 gdb 버전은 최신 7.3입니다. 테스트 환경이 어떻습니까? – mingganz

관련 문제