public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Re: gdb doesn't work very well with dynamic linked binaries
@ 2000-09-06  3:54 James Cownie
  2000-09-06  4:58 ` Mark Kettenis
  0 siblings, 1 reply; 33+ messages in thread
From: James Cownie @ 2000-09-06  3:54 UTC (permalink / raw)
  To: gdb

This threads seems really to have morphed to be about using the
hardware watchpoint registers on IA32.

So :-

Note that there are a couple of linux kernel bugs in 2.2 (one of which
was fixed in 2.2.17) which affect the use of the debug registers.

The first bug (which was fixed in 2.2.17) was that the debug status
register wasn't being saved where it could be seen by ptrace, so if
you were relying on looking at the hardware status register you were
stuffed.

The second (which isn't yet fixed) I described with a test case in a
previous mail here. ( http://sources.redhat.com/ml/gdb/2000-08/msg00072.html )
Basically the kernel ignores all hardware
watchpoints from the point where one of them is triggered inside the
kernel until a reschedule. This means many watchpoints at user level
can be silently skipped :-(

AFAICS both bugs remain in 2.4.0-test7.

-- Jim 

James Cownie	<jcownie@etnus.com>
Etnus, LLC.     +44 117 9071438
http://www.etnus.com



-- 
-- Jim
James Cownie
jcownie@etnus.com
Etnus, Inc.
Phone +44 117 9071438

^ permalink raw reply	[flat|nested] 33+ messages in thread
* Re: gdb doesn't work very well with dynamic linked binaries
@ 2000-09-07  1:55 James Cownie
  2000-09-07  3:09 ` Mark Kettenis
  0 siblings, 1 reply; 33+ messages in thread
From: James Cownie @ 2000-09-07  1:55 UTC (permalink / raw)
  To: gdb

Mark Kettenis wrote :-
  I'm not sure whether the debug registers are
  per-thread or per-VM-space in Linux.  I'll probably need to look into
  the kernel source.

To save you the time, they are per-thread, just like all the 
other process' registers.

They are conceptually saved and restored on process scheduling
events (which for linuxthreads is the same thing as thread 
scheduling events, since linuxthreads _are_ processes as far as
the scheduler is concerned). 

The bug I mentioned previously is exactly that they're getting
cleared by the kernel and then not getting restored on return
to user space, leaving them wrong until the next reschedule :-(

-- 
-- Jim
James Cownie
jcownie@etnus.com
Etnus, Inc.
Phone +44 117 9071438

^ permalink raw reply	[flat|nested] 33+ messages in thread
* Re: gdb doesn't work very well with dynamic linked binaries
@ 2000-09-07  3:27 James Cownie
  0 siblings, 0 replies; 33+ messages in thread
From: James Cownie @ 2000-09-07  3:27 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb, eliz

> I think I understand the problems now.  It basically means that one
> cannot reliably watch area's that are somehow used in system calls.

There are two slightly separate issues here 
1) If the kernel triggers a watchpoint do you get to see it
2) If the kernel triggers a watchpoint does that break 
   subsequent user level watchpoints.

The ideal behaviour, of course, would be that you saw the watchpoint
whether or not it was triggered by the kernel, and that didn't
break anything. (I believe this is what 2.0 kernels achieved).

The current (2.2.17) Linux behaviour is that 
1) The kernel triggered watchpoint is not reported to the debugger
*AND*
2) After the watchpoint is triggered by the kernel _all_ watchpoints
   in the thread are disabled until it gets rescheduled. (So some
   arbitrary number of user level watchpoint hits can be missed).

My patch would remove the second property, but would still leave
us ignorant about watchpoint hits from the kernel. 

So, with my kernel patch all watchpoint hits from user space are
reported, but watchpoint hits from kernel space are ignored. (Therefore
reading over a watched area doesn't get reported).

The ideal patch would also report kernel watchpoint hits back to the
process. Unfortunately I don't see any "free" way of doing that. 
(By which I mean a way which doesn't add code to the system call
return path whether or not debugging is enabled).

The current bug was introduced in the move from 2.0 to 2.2 because
the system call return path was optimised to remove the restoration
of the debug registers (which is fine as long as the kernel doesn't
change them, unfortunately it does).

> I suspect that Linux isn't the only kernel with this bug.  AFAICS
> FreeBSD also simply disables any (user-space) watchpoints triggered
> from within the kernel.  I don't know what the various x86 System V's
> (Solaris, SCO Open Server 5) do, but I wouldn't be surprised if it is
> broken there too.

It all depends on whether these OSes restore the debug registers in
the system call return path. If so changing them in the kernel is 
OK.

-- 
-- Jim
James Cownie
jcownie@etnus.com
Etnus, Inc.
Phone +44 117 9071438



^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2000-10-14 23:09 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20000901192328.A28312@valinux.com>
     [not found] ` <200009041047.LAA10659@phal.cygnus.co.uk>
2000-09-04  8:49   ` gdb doesn't work very well with dynamic linked binaries H . J . Lu
2000-09-04 10:52     ` Mark Kettenis
2000-09-04 11:11       ` Daniel Berlin
2000-09-04 11:22         ` Ulrich Drepper
     [not found]           ` <drepper@redhat.com>
2000-09-05 19:12             ` Kevin Buettner
2000-09-04 16:45       ` H . J . Lu
2000-09-04 22:49         ` Eli Zaretskii
2000-09-04 23:32           ` H . J . Lu
2000-09-05  3:36             ` Eli Zaretskii
2000-09-05  6:34               ` Mark Kettenis
2000-09-05  8:47                 ` Eli Zaretskii
2000-09-05 17:06                   ` Mark Kettenis
2000-09-05 22:52                     ` Eli Zaretskii
2000-09-05  8:49                 ` H . J . Lu
2000-09-05 18:23                   ` Stan Shebs
2000-09-05 18:33                     ` H . J . Lu
2000-09-05 22:54                       ` Eli Zaretskii
2000-09-05  8:44               ` H . J . Lu
2000-09-05 18:02               ` Stan Shebs
2000-09-05 20:45                 ` H . J . Lu
2000-09-05 22:55                   ` Eli Zaretskii
2000-10-14 23:09                   ` Andrew Cagney
2000-09-05 22:53                 ` Eli Zaretskii
     [not found]               ` <3.0.6.32.20000906001339.00b0ae90@idefix.wisa.be>
2000-09-05 23:08                 ` About unified debug register handling for i386 CPU Eli Zaretskii
2000-09-06 10:10                   ` Chris Faylor
2000-09-06  3:54 gdb doesn't work very well with dynamic linked binaries James Cownie
2000-09-06  4:58 ` Mark Kettenis
2000-09-07  1:55 James Cownie
2000-09-07  3:09 ` Mark Kettenis
2000-09-07  8:02   ` Eli Zaretskii
2000-09-08  8:30     ` Mark Kettenis
2000-09-09 14:39   ` Peter.Schauer
2000-09-07  3:27 James Cownie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).