Subject: proc(4): updating for LWP
To: None <tech-kern@netbsd.org>
From: Matt Thomas <matt@3am-software.com>
List: tech-kern
Date: 03/27/2003 14:57:25
The NetSD proc(4) (AKA procfs) is fairly old and don't understand LWP at
all.  ttrace(2) from HP-UX might be a better interface for GDB but proc(4)
can be useful because you don't need a program to glance at things.  It
also seems (to me) that it'd be easier to adapter to LWPs (and get GDB
support) than implmenting ttrace(2) from stratch.

I'd to propose that the NetBSD proc(4) be extended to allow for  debugging
of LWP's.  Rather than invent something unique to NetBSD, NetBSD should
adopt the Solaris 2.9 proc(4) interface (for more information, see
http://docs.sun.com/db/doc/816-0219/6m6njqbb6?a=view ).  Here's a listing
of my ksh process from a Solaris 8 system:

total 1877
       3396 -rw-------   1 mthomas   1900544 Mar 27 14:23 as
       3407 -r--------   1 mthomas       152 Mar 27 14:23 auxv
       3405 -r--------   1 mthomas        32 Mar 27 14:23 cred
       3397 --w-------   1 mthomas         0 Mar 27 14:23 ctl
       3412 lr-x------   1 mthomas         0 Mar 27 14:23 cwd ->
       3414 dr-x------   2 mthomas      2064 Mar 27 14:23 fd
       3401 -r--r--r--   1 mthomas       120 Mar 27 14:23 lpsinfo
       3399 -r--------   1 mthomas       912 Mar 27 14:23 lstatus
       3409 -r--r--r--   1 mthomas       536 Mar 27 14:23 lusage
       3418 dr-xr-xr-x   3 mthomas        48 Mar 27 14:23 lwp
       3402 -r--------   1 mthomas      2016 Mar 27 14:23 map
       3416 dr-x------   2 mthomas       544 Mar 27 14:23 object
       3410 -r--------   1 mthomas      2376 Mar 27 14:23 pagedata
       3400 -r--r--r--   1 mthomas       336 Mar 27 14:23 psinfo
       3403 -r--------   1 mthomas      2016 Mar 27 14:23 rmap
       3413 lr-x------   1 mthomas         0 Mar 27 14:23 root ->
       3406 -r--------   1 mthomas      1440 Mar 27 14:23 sigact
       3398 -r--------   1 mthomas      1232 Mar 27 14:23 status
       3408 -r--r--r--   1 mthomas       256 Mar 27 14:23 usage
       3411 -r--------   1 mthomas         0 Mar 27 14:23 watch
       3404 -r--------   1 mthomas      3192 Mar 27 14:23 xmap

fd:
total 1
       3415 c---------   1 mthomas   24,   4 Mar 27 14:55 0
     265559 c---------   1 mthomas   24,   4 Mar 27 14:55 1
     527703 c---------   1 mthomas   24,   4 Mar 27 14:55 2
    1314135 c---------   1 mthomas   24,   4 Mar 27 14:55 5
    1576279 c---------   1 mthomas   24,   4 Mar 27 14:55 6
   16518487 -rw-------   1 mthomas       356 Mar 27 14:47 63
    1838423 c---------   1 mthomas   24,   4 Mar 27 14:55 7

lwp:
total 0
       3419 dr-xr-xr-x   2 mthomas       288 Mar 27 14:23 1

lwp/1:
total 2
       3425 -r--------   1 mthomas         0 Mar 27 14:23 gwindows
       3420 --w-------   1 mthomas         0 Mar 27 14:23 lwpctl
       3422 -r--r--r--   1 mthomas       104 Mar 27 14:23 lwpsinfo
       3421 -r--------   1 mthomas       896 Mar 27 14:23 lwpstatus
       3423 -r--r--r--   1 mthomas       256 Mar 27 14:23 lwpusage
       3424 -r--------   1 mthomas       248 Mar 27 14:23 xregs

object:
total 2541
     467970 -r-xr-xr-x   3 root       200936 Jan  5  2000 a.out
     214663 -r-xr-xr-x   1 root        17096 Jan  5  2000 ufs.136.0.214663
     280812 -r-xr-xr-x   1 bin         25564 Nov 23  1999 ufs.136.0.280812
      71601 -r-xr-xr-x   1 root       195104 Nov  9  2000 ufs.136.0.71601
      71704 -r-xr-xr-x   1 root      1129948 Nov 23  2000 ufs.136.0.71704
      71717 -r-xr-xr-x   1 root         4624 Nov  9  2000 ufs.136.0.71717
      71737 -r-xr-xr-x   1 root        24968 Jan  5  2000 ufs.136.0.71737
      71740 -r-xr-xr-x   1 root       888508 Jun  8  2000 ufs.136.0.71740
      71760 -r-xr-xr-x   1 root        70260 Jan  5  2000 ufs.136.0.71760

Some of the significant changes are the fd, object, and lwp subdirectories.
The fd subdir contain file entries for each open fd of the process; exactly
the same a /dev/fd put per-process.  The object subdir contain file entries
so that the objects that have mmap'ed pages can be easily opened by the
debugger to get symbol tables, etc.  The lwp subdir contains one subdir for
each lightweight process in the process.

Note that the register contents are in the lwp/1/lwpstatus file, not in the
top-level process directory file regs.

I can either make native proc(4) look like the above or make it optional
(similar to the existing -o linux option to mount_procfs).  Any comments
or suggestions?

-- 
Matt Thomas               Internet:   matt@3am-software.com
3am Software Foundry      WWW URL:    http://www.3am-software.com/bio/matt/
Cupertino, CA             Disclaimer: I avow all knowledge of this message