This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] aarch64: PR 19806: watchpoints: false negatives -> false positives


On Wed, 08 Jun 2016 20:46:35 +0200, Pedro Alves wrote:
> I thought of a case where this is the wrong thing to do.
> (Alternative below.)
> 
> The same example as before: e.g., a machine that only supports
> watching 32-bit-aligned words.  Then with:
> 
> union
> {
>   char buf[4];
>   uint32_t force_align;
> } global;
> 
> (gdb) watch global.buf[1];
> Hardware watchpoint 1 ...
> (gdb) watch global.buf[3];
> Hardware watchpoint 2 ...
> 
> ... if the program writes to global.buf[3], and the target
> reports a memory access to 'global.buf + 1' (because that's the
> first watchpoint in its own watchpoint list that overlaps
> the global.buf[0]..global.buf[3] range (what is really being
> watched)), gdb will believe that watchpoint 1 triggered, notice
> the value didn't change, and thus incorrectly ignore the watchpoint hit.

Here if the program really does 'global.buf[3] = 0xff;' then it still does
work as despite GDB places watchpoint at &global.buf[0] for 4 bytes aarch64
still reports the exact 1-byte location &global.buf[3]:
	echo -e 'union { char buf[8]; unsigned long ul; } u; int main(void) {\n u.buf[3]=0xff;\n return 0; }'|gcc -Wall -g -x c -;./gdb -data-directory ./data-directory/ ./a.out -ex start -ex 'watch u.buf[1]' -ex 'watch u.buf[3]' -ex c -ex 'p u.buf[1]' -ex 'p u.buf[3]'
	Hardware watchpoint 2: u.buf[1]
	Hardware watchpoint 3: u.buf[3]
	Continuing.
	Hardware watchpoint 3: u.buf[3]
	Old value = 0 '\000'
	New value = 255 '\377'
	main () at <stdin>:3
	3	in <stdin>
	$1 = 0 '\000'
	$2 = 255 '\377'

But you are right the watchpoint gets missed if the program writes to
&global.buf[0] a 4-byte value not modifying the contents of global.buf[1] but
modifying the contents of global.buf[3]:
	echo -e 'union { char buf[8]; unsigned long ul; } u; int main(void) {\n u.ul=0xff000000;\n return 0; }'|gcc -Wall -g -x c -;./gdb -data-directory ./data-directory/ ./a.out -ex start -ex 'watch u.buf[1]' -ex 'watch u.buf[3]' -ex 'b 3' -ex c -ex 'p u.buf[1]' -ex 'p u.buf[3]'
	Hardware watchpoint 2: u.buf[1]
	Hardware watchpoint 3: u.buf[3]
	Breakpoint 4 at 0x400570: file <stdin>, line 3.
	Continuing.
	Breakpoint 4, main () at <stdin>:3
	3	in <stdin>
	$1 = 0 '\000'
	$2 = 255 '\377'

I will follow with an add-on patch as I guess you think it makes sense to fix
GDB even for older kernels (assuming aarch64 kernel gets fixed in some time).


Thanks,
Jan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]