From: Doug Evans <dje@transmeta.com>
To: Eli Zaretskii <eliz@is.elta.co.il>
Cc: gdb@sources.redhat.com
Subject: Re: does bpstat_print stop printing prematurely?
Date: Mon, 15 Apr 2002 23:43:00 -0000 [thread overview]
Message-ID: <15547.51222.125386.852824@casey.transmeta.com> (raw)
In-Reply-To: <Pine.SUN.3.91.1020416084918.14169B-100000@is>
Eli Zaretskii writes:
> Do you actually have an example of this, or can craft one?
Trivially.
> You see, I think it's all but impossible to have a breakpoint and a
> watchpoint trigger at the same PC. That's because the CPU carefully
> designs its faults and traps so that one always preceeds the other.
Nope. When control stops, all gdb may know is that _some_ breakpoint hit.
[where "breakpoint" here includes "watchpoint" but no matter]
Some targets may assist gdb in partially distinguishing them, but
such a distinction is insufficient.
Note for example that you can have multiple pc breakpoints at the
same location. This is useful if each has its own condition and commands.
When execution stops, gdb can't know which of the two triggered because
it hasn't evaluated the conditions yet. The distinction between the
two is a gdb artifact and there's nothing the O/S (*) can do to tell
gdb which of the two fired: all gdb told the O/S was "stop at this pc
value please."
Thus when execution stops there can be several reasons.
The `stop_bpstat' list records all of them.
And gdb makes an effort to print all of them (or some of them) which is great,
but it'd be nice if the effort was complete.
Now, if the gdb maintainers want to make the bug go away by defining
it away that's their prerogative. It's a step backwards though.
(*): or embedded system or simulator or ... etc.
> Cannot reproduce this on my machine with GDB 5.1.1: if I set two
> watchpoints on the same address, GDB announces both of them. Please tell
> what OS did you try that on, and which version of GDB was that.
You need to recreate the conditions of having the stop_bpstat list contain
a watchpoint, then a pc breakpoint, then another watchpoint.
bpstat_print will stop printing at the pc breakpoint, but it hasn't
printed the final watchpoint yet.
Here's a session showing how to recreate it.
The first gdb session shows gdb printing all 3 breakpoints: two watchpoints
and a pc breakpoint. It does this because of the order in which the 3 were
created. The second gdb session shows gdb not printing the second watchpoint.
In this case the second watchpoint was created after the pc breakpoint.
A quick skim of the code will explain why gdb is behaving this way.
I'm hoping people will agree it's a bug rather than defining the problem away.
casey:~$ cat -n foo.c
1 int foo;
2 int bar;
3
4 int
5 main ()
6 {
7 foo = 42;
8 return 0;
9 }
casey:~$ gcc -g foo.c
casey:~$ gdb-5.1.1 a.out
GNU gdb 5.1.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) watch foo
Hardware watchpoint 1: foo
(gdb) cond 1 bar != -1
(gdb) watch foo
Hardware watchpoint 2: foo
(gdb) cond 2 bar >= 0
(gdb) b foo.c:8
Breakpoint 3 at 0x80483ad: file foo.c, line 8.
(gdb) b main
Breakpoint 4 at 0x80483a3: file foo.c, line 7.
(gdb) r
Starting program: /home/dje/a.out
Hardware watchpoint 1: foo
Hardware watchpoint 2: foo
Hardware watchpoint 1: foo
Hardware watchpoint 2: foo
Breakpoint 4, main () at foo.c:7
7 foo = 42;
(gdb) c
Continuing.
Hardware watchpoint 1: foo
Old value = 0
New value = 42
Hardware watchpoint 2: foo
Old value = 0
New value = 42
Breakpoint 3, main () at foo.c:8
8 return 0;
(gdb) q
The program is running. Exit anyway? (y or n) y
casey:~$ gdb-5.1.1 a.out
GNU gdb 5.1.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) watch foo
Hardware watchpoint 1: foo
(gdb) cond 1 bar != -1
(gdb) b foo.c:8
Breakpoint 2 at 0x80483ad: file foo.c, line 8.
(gdb) watch foo
Hardware watchpoint 3: foo
(gdb) cond 3 bar >= 0
(gdb) b main
Breakpoint 4 at 0x80483a3: file foo.c, line 7.
(gdb) i b
Num Type Disp Enb Address What
1 hw watchpoint keep y foo
stop only if bar != -1
2 breakpoint keep y 0x080483ad in main at foo.c:8
3 hw watchpoint keep y foo
stop only if bar >= 0
4 breakpoint keep y 0x080483a3 in main at foo.c:7
(gdb) r
Starting program: /home/dje/a.out
Hardware watchpoint 1: foo
Hardware watchpoint 3: foo
Hardware watchpoint 1: foo
Hardware watchpoint 3: foo
Breakpoint 4, main () at foo.c:7
7 foo = 42;
(gdb) c
Continuing.
Hardware watchpoint 1: foo
Old value = 0
New value = 42
Breakpoint 2, main () at foo.c:8
8 return 0;
(gdb) q
The program is running. Exit anyway? (y or n) y
casey:~$
next prev parent reply other threads:[~2002-04-16 6:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-15 13:03 Doug Evans
2002-04-15 22:03 ` Eli Zaretskii
2002-04-15 23:43 ` Doug Evans [this message]
2002-04-16 0:40 ` Eli Zaretskii
2002-04-16 5:55 ` Eli Zaretskii
2002-04-16 8:43 ` Doug Evans
2002-04-16 10:50 ` Doug Evans
2002-05-09 20:44 ` Andrew Cagney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=15547.51222.125386.852824@casey.transmeta.com \
--to=dje@transmeta.com \
--cc=eliz@is.elta.co.il \
--cc=gdb@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox