[comp.unix.wizards] ptrace in unix tracing non-child processes

narayan@tandem.UUCP (Narayan Mohanram) (04/09/88)

Has any one considered implementing a `xptrace ()' which can 
debug non-child processes. This will get one the ability to
debug processes such as daemons that are already running.

eg:

	debug -p pid

Then background processes and demon processes that have no
relationship to the debugger can be debugged.


THE SUPREME DALAK from SCAROS

chris@mimsy.UUCP (Chris Torek) (04/10/88)

In article <352@tandem.UUCP> narayan@tandem.UUCP (Narayan Mohanram) writes:
>Has any one considered implementing a `xptrace ()' which can 
>debug non-child processes. This will get one the ability to
>debug processes such as daemons that are already running.

Better: throw out ptrace entirely and adopt the V8/V9 `/proc' approach.
ptrace is ugly and slow; /proc is moderatly odd (ioctls for process
control!?) and much less so.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

karl@triceratops.cis.ohio-state.edu (Karl Kleinpaste) (04/11/88)

chris@mimsy.UUCP writes:
   Better: throw out ptrace entirely and adopt the V8/V9 `/proc' approach.

Yea, verily, and amen.

   ptrace is ugly and slow; /proc is moderatly odd (ioctls for process
   control!?) and much less so.

True, but it completes the "everything is a file" paradigm.

brent%terra@Sun.COM (Brent Callaghan) (04/12/88)

SunOs ptrace() has this facility.  You can give it a pid with
the PTRACE_ATTACH request and attach to another process.  The other
process must be one of "yours" i.e. same uid/gid.  The process gets
a SIGSTOP.  A PTRACE_DETACH is used to send the traced process on
it's way when you've lost interest.

This facility is used by dbx.  You can give it a pid in place of
a core file name e.g. "dbx fnurg 1022".


Made in New Zealand -->  Brent Callaghan  @ Sun Microsystems
			 uucp: sun!bcallaghan
			 phone: (415) 691 6188

ron@iconsys.UUCP (Ron Holt) (04/14/88)

In article <352@tandem.UUCP> narayan@tandem.UUCP (Narayan Mohanram) writes:
>Has any one considered implementing a `xptrace ()' which can 
>debug non-child processes. This will get one the ability to
>debug processes such as daemons that are already running.

We've extended the existing ptrace() call to support tracing of arbitrary
processes in ICON/UX (our version of 4.xBSD and SVRx).  The debuggers
adb, sdb and dbx have been modified to take advantage of this.  I
believe Sun has done something similar.  There's no need to invent a
new system call; just extend the existing one.  The time spent in
implementing this functionality has been amply repaid in the ability to
debug non-child processes.

-- 
Ron Holt                     UUCP: {ihnp4,uunet,caeco,nrc-ut}!iconsys!ron
Software Development Manager ARPANET: icon%byuadam.bitnet@cunyvm.cuny.edu
Icon International, Inc.     BITNET: icon%byuadam.bitnet
Orem, Utah 84058             PHONE: (801) 225-6888

aj@zyx.UUCP (Arndt Jonasson) (04/14/88)

In article <49161@sun.uucp> brent%terra@Sun.COM (Brent Callaghan) writes:
>SunOs ptrace() has this facility.  You can give it a pid with
>the PTRACE_ATTACH request and attach to another process.  The other
>process must be one of "yours" i.e. same uid/gid.  The process gets
>a SIGSTOP.  A PTRACE_DETACH is used to send the traced process on
>it's way when you've lost interest.

The HP-UX system for HP 9000 series 800 also has that facility (though
the symbols are named PT_ATTACH and PT_DETACH).

Btw, I recently posted my file openings trapper to comp.sources.misc
(though it doesn't seem to have shown up yet).  It also includes
(undocumented) the current state of my options parser (which started
the interesting discussion about option parsing). If anyone feels like
porting the trapper to something other than HP-UX or Vax/4.2BSD, please
send the changes back to me.

[By writing this program, I got quite acquainted with the 'ptrace' call.
Brrr, what a kludge it is..]
-- 
Arndt Jonasson, ZYX Sweden AB, Styrmansgatan 6, 114 54 Stockholm, Sweden
email address:	 aj@zyx.SE	or	<backbone>!mcvax!enea!zyx!aj

dannyb@kulcs.uucp (Danny Backx) (04/14/88)

In article <49161@sun.uucp> brent%terra@Sun.COM (Brent Callaghan) writes:
>SunOs ptrace() has this facility.  You can give it a pid with
>the PTRACE_ATTACH request and attach to another process.  The other
>process must be one of "yours" i.e. same uid/gid.  The process gets
>a SIGSTOP.  A PTRACE_DETACH is used to send the traced process on
>it's way when you've lost interest.
>
>This facility is used by dbx.  You can give it a pid in place of
>a core file name e.g. "dbx fnurg 1022".

There is a bug related to this in the SunOS 3.4 kernel, though.
(At least I think this is a bug)

Sometimes when a process is being debugged it can be caused to just hang.
Don't ask me how I did it.
I just know the machine I work on has had one of my processes being traced
and stopped (yes, both !), and there was absolutely no way to remove the
process except for rebooting the system.

It seems such a process is in a state in which it never returns to user mode.
Since processes only receive signals when going into user mode, you obviously
can't kill it.

If anybody knows a solution I am not aware of... please post !

	Danny
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Danny Backx                            |  mail: Katholieke Universiteit Leuven 
 Tel: +32 16 200656 x 3058              |        Dept. Computer Science
 E-mail: dannyb@kulcs.UUCP              |        Celestijnenlaan 200 A
         ... mcvax!prlb2!kulcs!dannyb   |        B-3030 Leuven
         dannyb@blekul60.BITNET         |        Belgium     

decot@hpisod2.HP.COM (Dave Decot) (04/15/88)

HP-UX supports attaching to and debugging non-child processes, via an
extension to ptrace().

Dave Decot
hpda!decot

archer@elysium.SGI.COM (Archer Sully) (04/16/88)

The Silicon Graphics release 3.0 UNIX (coming soon to an IRIS
4D workstation near you) supports debugging of arbitrary
processes through /proc, which we call /debug.  Has anyone
else done it this way?

Archer Sully
archer@sgi.com

allbery@ncoast.UUCP (Brandon Allbery) (04/20/88)

As quoted from <352@tandem.UUCP> by narayan@tandem.UUCP (Narayan Mohanram):
+---------------
| Has any one considered implementing a `xptrace ()' which can 
| debug non-child processes. This will get one the ability to
| debug processes such as daemons that are already running.
+---------------

Plexus System V and a few other System V's I've seen have ptrace() requests
8 and 9 which do this.  I'm not sure if it's a System V feature or a special
hack added by certain Unix resellers.
-- 
	      Brandon S. Allbery, moderator of comp.sources.misc
	{well!hoptoad,uunet!marque,cbosgd,sun!mandrill}!ncoast!allbery
Delphi: ALLBERY						     MCI Mail: BALLBERY