Bug 12953 - No hardware watchpoints on FreeBSD amd64
Summary: No hardware watchpoints on FreeBSD amd64
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 7.3
: P2 normal
Target Milestone: 7.5
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 9118 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-06-30 22:25 UTC by yuri
Modified: 2012-02-09 16:12 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Updated patch (2.17 KB, patch)
2011-12-05 00:42 UTC, Valery Khromov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description yuri 2011-06-30 22:25:20 UTC
When I set a watchpoint they came out software, not hardware.

This causes waste of time while waiting for software watchpoint to be triggered.
gdb should default to hardware watchpoints and should print an explanation why it can't be set in case it can't.
Comment 1 yuri 2011-07-01 00:47:53 UTC
I used this C++ program:
#include <string.h>

void ms(char *p) {
  memset(p, 0, 1024);
}

main() {
  char buf1[1024];
  buf1[256] = 7;
  ms(buf1);
}

gdb_7_3-branch.

In the log below you can see that it has set 'Watchpoint', not 'Hardware watchpoint'.

---- gdb session log ----
[yuri@mybsd ~/gdb]$ gdb ./main
GNU gdb (GDB) 7.2.90.20110630-cvs
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 "x86_64-unknown-freebsd8.2".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/home/yuri/gdb/main...done.
(gdb) b main
Breakpoint 1 at 0x40065b: file main.C, line 9.
(gdb) r
Starting program: /usr/home/yuri/gdb/main

Breakpoint 1, main () at main.C:9
9         buf1[256] = 7;
(gdb) n
10        ms(buf1);
(gdb) p &buf1[256]
$1 = 0x7fffffffddd0 "\a"
(gdb) watch *(char*)0x7fffffffddd0
Watchpoint 2: *(char*)0x7fffffffddd0
(gdb) c
Continuing.
Watchpoint 2: *(char*)0x7fffffffddd0

Old value = 7 '\a'
New value = 0 '\000'
0x0000000800b78074 in memset () from /lib/libc.so.7
(gdb) c
Continuing.
Watchpoint 2: *(char*)0x7fffffffddd0

Old value = 0 '\000'
New value = 1 '\001'
0x0000000800505c6c in ?? () from /libexec/ld-elf.so.1
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /usr/home/yuri/gdb/main
^C
Program received signal SIGINT, Interrupt.
0x0000000800505959 in ?? () from /libexec/ld-elf.so.1
(gdb) quit
A debugging session is active.

        Inferior 1 [process 49302] will be killed.

Quit anyway? (y or n) y
Comment 2 Valery Khromov 2011-12-04 21:19:46 UTC
See patch http://sourceware.org/bugzilla/attachment.cgi?id=6088&action=diff
Comment 3 yuri 2011-12-04 23:30:43 UTC
I tried the patch (with 7.3.1) and it didn't work.

Patch applied, and gdb compiled.
gdb now says it does set Hardware watchpoints.
But gdb didn't stop when the memory value actually changed.

8.2-STABLE amd64
Comment 4 Valery Khromov 2011-12-05 00:42:48 UTC
Created attachment 6089 [details]
Updated patch

Attached updated patch fixes watching local variables.


However, it looks like gdb isn't able to watch uninitialized variables:

$ cat main.c 
#include <string.h>

void ms(char *p) {
  memset(p, 0, 1024);
}

main() {
#ifdef INIT_BUF1
  char buf1[1024] = { 0 };
#else
  char buf1[1024];
#endif
  buf1[256] = 7;
  ms(buf1);
}

$ cc main.c -ggdb -O0 -o main-notinit

$ cc main.c -ggdb -O0 -DINIT_BUF1 -o main-init


$ gdb main-notinit              
GNU gdb (GDB) 7.3.1 [GDB v7.3.1 for FreeBSD]
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 "x86_64-portbld-freebsd8.2".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /place/home/qwerty/gdb-freebsd-fixes/tst/main-notinit...done.
(gdb) br main
Breakpoint 1 at 0x4005ab: file main.c, line 13.
(gdb) r
Starting program: /place/home/qwerty/gdb-freebsd-fixes/tst/main-notinit 

Breakpoint 1, main () at main.c:13
13	  buf1[256] = 7;
(gdb) wa buf1[256]
Hardware watchpoint 2: buf1[256]
(gdb) c
Continuing.

Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
0x00000000004004ee in _start ()


$ gdb main-init   
GNU gdb (GDB) 7.3.1 [GDB v7.3.1 for FreeBSD]
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 "x86_64-portbld-freebsd8.2".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /place/home/qwerty/gdb-freebsd-fixes/tst/main-init...done.
(gdb) br main
Breakpoint 1 at 0x4005ab: file main.c, line 9.
(gdb) r
Starting program: /place/home/qwerty/gdb-freebsd-fixes/tst/main-init 

Breakpoint 1, main () at main.c:9
9	  char buf1[1024] = { 0 };
(gdb) wa buf1[256]
Hardware watchpoint 2: buf1[256]
(gdb) c
Continuing.
Hardware watchpoint 2: buf1[256]

Old value = 0 '\000'
New value = 7 '\a'
main () at main.c:14
14	  ms(buf1);
(gdb) 
Continuing.
Hardware watchpoint 2: buf1[256]

Old value = 7 '\a'
New value = 0 '\000'
0x000000003273b1c4 in memset () from /lib/libc.so.7
(gdb) 
Continuing.

Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
0x00000000004004ee in _start ()



I tested it on Linux with the similar result: the watchpoint is triggered on the second variable change by memset, not on the first assignment:

$ gdb main-notinit
GNU gdb (GDB) 7.0-debian
Copyright (C) 2009 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 "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/ll/main-notinit...done.
(gdb) br main
Breakpoint 1 at 0x400518: file main.c, line 13.
(gdb) r
Starting program: /tmp/ll/main-notinit 

Breakpoint 1, main () at main.c:13
13	  buf1[256] = 7;
(gdb) wa buf1[256]
Hardware watchpoint 2: buf1[256]
(gdb) c
Continuing.
Hardware watchpoint 2: buf1[256]

Old value = -16 '\360'
New value = 0 '\000'
memset () at ../sysdeps/x86_64/memset.S:1017
1017	../sysdeps/x86_64/memset.S: No such file or directory.
	in ../sysdeps/x86_64/memset.S
Current language:  auto
The current source language is "auto; currently asm".
Comment 5 yuri 2011-12-05 01:13:43 UTC
The latest patch works. Thanks!
Comment 6 Valery Khromov 2011-12-05 01:19:10 UTC
*** Bug 9118 has been marked as a duplicate of this bug. ***
Comment 7 Tom Tromey 2011-12-05 21:29:24 UTC
The best thing to do now is follow the contribution instructions:
http://sourceware.org/gdb/contribute/
Comment 8 Valery Khromov 2011-12-06 19:09:02 UTC
I have sent an e-mail with the patch to gdb-patches@
Tom, could you please review it?
Comment 9 Sourceware Commits 2012-02-09 16:06:51 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	palves@sourceware.org	2012-02-09 16:06:44

Modified files:
	gdb            : ChangeLog Makefile.in amd64bsd-nat.c 
	                 amd64fbsd-nat.c 
	gdb/config/i386: fbsd64.mh 
Added files:
	gdb            : amd64bsd-nat.h 

Log message:
	2012-02-09  Valery Khromov  <valery.khromov@gmail.com>
	
	PR gdb/12953
	* Makefile.in (HFILES_NO_SRCDIR): Add amd64bsd-nat.h.
	* amd64bsd-nat.c: Add support for debug registers (adapted from
	i386bsd-nat.c).
	[HAVE_PT_GETDBREGS] (amd64bsd_dr_get, amd64bsd_dr_set)
	(amd64bsd_dr_set_control, amd64bsd_dr_set_addr)
	(amd64bsd_dr_get_addr, amd64bsd_dr_get_status)
	(amd64bsd_dr_get_control): New functions.
	* amd64bsd-nat.h: New file (adapted from i386bsd-nat.h).
	* amd64fbsd-nat.c: Include "amd64bsd-nat.h", "i386-nat.h".
	[HAVE_PT_GETDBREGS] (_initialize_amd64fbsd_nat): Add hardware
	watchpoints initialization.
	* config/i386/fbsd64.mh (NATDEPFILES): Add i386-nat.o.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/amd64bsd-nat.h.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.13818&r2=1.13819
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/Makefile.in.diff?cvsroot=src&r1=1.1187&r2=1.1188
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/amd64bsd-nat.c.diff?cvsroot=src&r1=1.19&r2=1.20
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/amd64fbsd-nat.c.diff?cvsroot=src&r1=1.28&r2=1.29
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/config/i386/fbsd64.mh.diff?cvsroot=src&r1=1.12&r2=1.13
Comment 10 Pedro Alves 2012-02-09 16:12:00 UTC
Patch checked in.  Thank you.