From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20786 invoked by alias); 26 May 2011 08:00:00 -0000 Received: (qmail 20776 invoked by uid 22791); 26 May 2011 07:59:59 -0000 X-SWARE-Spam-Status: No, hits=1.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,MIME_CHARSET_FARAWAY,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-yx0-f169.google.com (HELO mail-yx0-f169.google.com) (209.85.213.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 May 2011 07:59:45 +0000 Received: by yxt33 with SMTP id 33so245477yxt.0 for ; Thu, 26 May 2011 00:59:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.193.71 with SMTP id j47mr612983yhn.383.1306396785024; Thu, 26 May 2011 00:59:45 -0700 (PDT) Received: by 10.236.161.41 with HTTP; Thu, 26 May 2011 00:59:45 -0700 (PDT) Date: Thu, 26 May 2011 08:00:00 -0000 Message-ID: Subject: Question about the watchpoint From: Qian Hao To: gdb@sourceware.org Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2011-05/txt/msg00135.txt.bz2 Hello everyone, I am new to use gdb. I have a question about the watchpoint. For the following program: #include void main(const char *name) { int a; a=3D1; a=3D2; printf("%d.\n",a); } Reading symbols from /home/yorua007/tmp/static-library/test...done. (gdb) b main Breakpoint 1 at 0x80483ed: file test.c, line 5. (gdb) r Starting program: /home/yorua007/tmp/static-library/test Breakpoint 1, main (name=3D0x1
) at test.c:5 5 a=3D1; (gdb) p a $1 =3D -1208205324 (gdb) watch a Hardware watchpoint 2: a (gdb) c Continuing. Hardware watchpoint 2: a Old value =3D -1208205324 New value =3D 2 main (name=3D0x1
) at test.c:7 7 printf("%d.\n",a); (gdb) You see that the program did not break when "a" changed from -1208205324 to 1. It seems to relate with the hardware watchpoint. When I configured to use the software watchpoint: (gdb) set can-use-hw-watchpoint 0 (gdb) r Starting program: /home/yorua007/tmp/static-library/test Breakpoint 1, main (name=3D0x1
) at test.c:5 5 a=3D1; (gdb) watch a Watchpoint 3: a (gdb) c Continuing. Watchpoint 3: a Old value =3D -1208205324 New value =3D 1 main (name=3D0x1
) at test.c:6 6 a=3D2; (gdb) The program broke when "a" changed to 1. Could someone explain the differences between the hardware and software watchpints ? Besides this, another question about the watchpoint is that: I have a program linked with a static library. In the static library, there is a global variable(for example gl_a). After reading symbols from the program, (gdb) p gl_a $1 =3D 1 (gdb) watch gl_a Hardware watchpoint 1: gl_a (gdb) r The program executed without any break. But the value of "gl_a" did changed(to 0) during the execution. When I set a breakpoint somewhere in the program before "gl_a" had changed, the program stopped there, and I made it continue to execute, the program stopped where the value of "gl_a" changed. I could not figure it out why. --=20 =B4=CB=D6=C2 =BE=B4=C0=F1=A3=A1