This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: A problem about read / access watchpoint
On Sun, 15 Jan 2006, Jim Blandy wrote:
> On 1/15/06, Wu Zhou <woodzltc@cn.ibm.com> wrote:
> > I did some tracing on that, and find that the kernel _did_ issue signal
> > trap on line 15, and gdb could also get the stopped data address by
> > ptrace. But when gdb call watchpoint_check to check if the value changed
> > or not. It will reports WP_VALUE_CHANGED, which really confuse me.
>
> Just out of curiosity, could you post a disassembly of main? The
> kernel is watching what the machine code version of the program does,
> and I wouldn't assume that it was the same as what the source code
> version does, even if you compile with -O0.
>
This is the related debugging session on x86:
(gdb) p &var1
$1 = (int *) 0xbff312c4
(gdb) rwatch var1
Hardware read watchpoint 2: var1
(gdb) c
Continuing.
just to do sth
Hardware read watchpoint 2: var1
Value = 0
0x080483c0 in main (argc=1, argv=0xbff31354) at rwatch.c:17
17 printf ("var0 = %d, var1 = %d\n", var0, var1);
(gdb) disassemble main
Dump of assembler code for function main:
0x08048380 <main+0>: push %ebp
0x08048381 <main+1>: mov %esp,%ebp
0x08048383 <main+3>: sub $0x8,%esp
0x08048386 <main+6>: and $0xfffffff0,%esp
0x08048389 <main+9>: mov $0x0,%eax
0x0804838e <main+14>: add $0xf,%eax
0x08048391 <main+17>: add $0xf,%eax
0x08048394 <main+20>: shr $0x4,%eax
0x08048397 <main+23>: shl $0x4,%eax
0x0804839a <main+26>: sub %eax,%esp
0x0804839c <main+28>: movl $0x0,0xfffffffc(%ebp)
0x080483a3 <main+35>: sub $0xc,%esp
0x080483a6 <main+38>: lea 0xfffffffc(%ebp),%eax
0x080483a9 <main+41>: push %eax
0x080483aa <main+42>: call 0x8048368 <subr>
0x080483af <main+47>: add $0x10,%esp
0x080483b2 <main+50>: mov 0xfffffffc(%ebp),%eax ===> read var1?
0x080483b5 <main+53>: mov %eax,0x80495e8
0x080483ba <main+58>: sub $0x4,%esp
0x080483bd <main+61>: pushl 0xfffffffc(%ebp) ===> read var1?
0x080483c0 <main+64>: pushl 0x80495e8
0x080483c6 <main+70>: push $0x80484c8
0x080483cb <main+75>: call 0x80482b0 <printf@plt>
0x080483d0 <main+80>: add $0x10,%esp
0x080483d3 <main+83>: leave
0x080483d4 <main+84>: ret
End of assembler dump.
(gdb) bt
#0 0x080483c0 in main (argc=1, argv=0xbff31354) at rwatch.c:17
(gdb) info registers
eax 0x0 0
ecx 0x0 0
edx 0xf 15
ebx 0xaa7ff4 11173876
esp 0xbff312a8 0xbff312a8
ebp 0xbff312c8 0xbff312c8 (== &var - 4)
esi 0xbff31354 -1074588844
edi 0xbff312e0 -1074588960
eip 0x80483c0 0x80483c0 <main+64>
eflags 0x296 662
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
I am not that comfortable with x86 assembly. But it seems that I am
correct on the guess, right?
Regards
- Wu Zhou