From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5554D3951C68; Mon, 15 Feb 2021 14:03:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5554D3951C68 From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug breakpoints/27422] New: Warn when degrading hw -> sw watchpoint Date: Mon, 15 Feb 2021 14:03:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: breakpoints X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Feb 2021 14:03:57 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D27422 Bug ID: 27422 Summary: Warn when degrading hw -> sw watchpoint Product: gdb Version: HEAD Status: NEW Severity: enhancement Priority: P2 Component: breakpoints Assignee: unassigned at sourceware dot org Reporter: vries at gcc dot gnu.org Target Milestone: --- Consider test-case test.c: ... $ cat -n test.c 1 #include 2 #include 3 volatile int a =3D 1; 4 volatile int b =3D 1; 5=20=20=20=20=20=20=20 6 int main (void) 7 { 8 volatile unsigned long long int i; 9 a =3D 2; 10 for (i =3D 0; i < 1000000000; ++i) 11 { 12 b =3D 2; 13 b =3D 3; 14 b =3D 4; 15 b =3D 5; 16 b =3D 6; 17 } 18 int *ap =3D malloc (sizeof(int)); 19 *ap =3D 1; 20 printf ("%p\n", ap); 21 *ap =3D 0; 22 a =3D 0; 23 return 0; 24 } ... Compiled with debug info: ... $ gcc -g test.c ... It takes a bit to execute: ... $ time ./a.out 0x2252260 real 0m2.192s user 0m2.188s sys 0m0.001s ... By disabling ASLR, we see that the malloc'ed pointer doesn't seem to change: ... $ setarch $(uname -m) -R ./a.out 0x602260 $ setarch $(uname -m) -R ./a.out 0x602260 ... Now consider the following debug session: ... $ gdb -q a.out Reading symbols from a.out... (gdb) b 20 Breakpoint 1 at 0x4005c5: file test.c, line 20. (gdb) r Starting program: a.out=20 Breakpoint 1, main () at test.c:20 20 printf ("%p\n", ap); (gdb) watch *(int *)0x602260 =3D=3D 0 Hardware watchpoint 2: *(int *)0x602260 =3D=3D 0 (gdb) c Continuing. 0x602260 Hardware watchpoint 2: *(int *)0x602260 =3D=3D 0 Old value =3D 0 New value =3D 1 main () at test.c:22 22 a =3D 0; (gdb) info break Num Type Disp Enb Address What 1 breakpoint keep y 0x00000000004005c5 in main at test.c:20 breakpoint already hit 1 time 2 hw watchpoint keep y *(int *)0x602260 =3D=3D 0 breakpoint already hit 1 time (gdb)=20 ... So far, so good. We set a watch point. It was reported as a hardware watchpoint when we set it, and it's still a hardware watchpoint when it's triggered. Now we restart, and ... this takes a long time, so we press ^C to know what happened: ... (gdb) r The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /home/vries/gdb_versions/devel/a.out=20 ^C Program received signal SIGINT, Interrupt. _dl_map_object_from_fd (name=3Dname@entry=3D0x400379 "libc.so.6", origname=3Dorigname@entry=3D0x0, fd=3D-1, fbp=3Dfbp@entry=3D0x7fffffffd3e0, realname=3D, loader=3Dloader@entry=3D0x7ffff7ffe110, l_type= =3D, mode=3D, stack_endp=3D, nsid=3D) at dl-load.c:1364 1364 if (__glibc_unlikely (GLRO(dl_profile) !=3D NULL) (gdb) info break Num Type Disp Enb Address What 1 breakpoint keep y 0x00000000004005c5 in main at test.c:20 2 watchpoint keep y *(int *)0x602260 =3D=3D 0 ... The hw watchpoint silently degraded to a software watchpoint (due to being = set on unmapped memory). It could be useful to warn in such a case, because a software watchpoint ma= y be much slower. --=20 You are receiving this mail because: You are on the CC list for the bug.=