Package vtrace :: Package platforms :: Module solaris
[hide private]
[frames] | no frames]

Source Code for Module vtrace.platforms.solaris

  1  """ 
  2  Solaris Platform Module (Incomplete) 
  3  """ 
  4  # Copyright (C) 2007 Invisigoth - See LICENSE file for details 
  5  import os 
  6  import struct 
  7  import array 
  8   
  9  # Control codes (long values) for messages written to ctl and lwpctl files. 
 10  PCNULL   = 0L# null request, advance to next message */ 
 11  PCSTOP   = 1L# direct process or lwp to stop and wait for stop */ 
 12  PCDSTOP  = 2L# direct process or lwp to stop */ 
 13  PCWSTOP  = 3L# wait for process or lwp to stop, no timeout */ 
 14  PCTWSTOP = 4L# wait for stop, with long millisecond timeout arg */ 
 15  PCRUN    = 5L# make process/lwp runnable, w/ long flags argument */ 
 16  PCCSIG   = 6L# clear current signal from lwp */ 
 17  PCCFAULT = 7L# clear current fault from lwp */ 
 18  PCSSIG   = 8L# set current signal from siginfo_t argument */ 
 19  PCKILL   = 9L# post a signal to process/lwp, long argument */ 
 20  PCUNKILL = 10L# delete a pending signal from process/lwp, long arg */ 
 21  PCSHOLD  = 11L# set lwp signal mask from sigset_t argument */ 
 22  PCSTRACE = 12L# set traced signal set from sigset_t argument */ 
 23  PCSFAULT = 13L# set traced fault set from fltset_t argument */ 
 24  PCSENTRY = 14L# set traced syscall entry set from sysset_t arg */ 
 25  PCSEXIT  = 15L# set traced syscall exit set from sysset_t arg */ 
 26  PCSET    = 16L# set modes from long argument */ 
 27  PCUNSET  = 17L# unset modes from long argument */ 
 28  PCSREG   = 18L# set lwp general registers from prgregset_t arg */ 
 29  PCSFPREG = 19L# set lwp floating-point registers from prfpregset_t */ 
 30  PCSXREG  = 20L# set lwp extra registers from prxregset_t arg */ 
 31  PCNICE   = 21L# set nice priority from long argument */ 
 32  PCSVADDR = 22L# set %pc virtual address from long argument */ 
 33  PCWATCH  = 23L# set/unset watched memory area from prwatch_t arg */ 
 34  PCAGENT  = 24L# create agent lwp with regs from prgregset_t arg */ 
 35  PCREAD   = 25L# read from the address space via priovec_t arg */ 
 36  PCWRITE  = 26L# write to the address space via priovec_t arg */ 
 37  PCSCRED  = 27L# set process credentials from prcred_t argument */ 
 38  PCSASRS  = 28L# set ancillary state registers from asrset_t arg */ 
 39  PCSPRIV  = 29L# set process privileges from prpriv_t argument */ 
 40  PCSZONE  = 30L# set zoneid from zoneid_t argument */ 
 41  PCSCREDX = 31L# as PCSCRED but with supplemental groups */ 
 42   
 43  # PCRUN long operand flags. 
 44  PRCSIG   = 0x01# clear current signal, if any */ 
 45  PRCFAULT = 0x02# clear current fault, if any */ 
 46  PRSTEP   = 0x04# direct the lwp to single-step */ 
 47  PRSABORT = 0x08# abort syscall, if in syscall */ 
 48  PRSTOP   = 0x10# set directed stop request */ 
 49   
 50  # Status flags 
 51  PR_STOPPED  = 0x00000001# lwp is stopped */ 
 52  PR_ISTOP    = 0x00000002# lwp is stopped on an event of interest */ 
 53  PR_DSTOP    = 0x00000004# lwp has a stop directive in effect */ 
 54  PR_STEP     = 0x00000008# lwp has a single-step directive in effect */ 
 55  PR_ASLEEP   = 0x00000010# lwp is sleeping in a system call */ 
 56  PR_PCINVAL  = 0x00000020# contents of pr_instr undefined */ 
 57  PR_ASLWP    = 0x00000040# obsolete flag; never set */ 
 58  PR_AGENT    = 0x00000080# this lwp is the /proc agent lwp */ 
 59  PR_DETACH   = 0x00000100# this is a detached lwp */ 
 60  PR_DAEMON   = 0x00000200# this is a daemon lwp */ 
 61  # The following flags apply to the process, not to an individual lwp */ 
 62  PR_ISSYS    = 0x00001000# this is a system process */ 
 63  PR_VFORKP   = 0x00002000# process is the parent of a vfork()d child */ 
 64  PR_ORPHAN   = 0x00004000# process's process group is orphaned */ 
 65  # The following process flags are modes settable by PCSET/PCUNSET */ 
 66  PR_FORK     = 0x00100000# inherit-on-fork is in effect */ 
 67  PR_RLC      = 0x00200000# run-on-last-close is in effect */ 
 68  PR_KLC      = 0x00400000# kill-on-last-close is in effect */ 
 69  PR_ASYNC    = 0x00800000# asynchronous-stop is in effect */ 
 70  PR_MSACCT   = 0x01000000# micro-state usage accounting is in effect */ 
 71  PR_BPTADJ   = 0x02000000# breakpoint trap pc adjustment is in effect */ 
 72  PR_PTRACE   = 0x04000000# ptrace-compatibility mode is in effect */ 
 73  PR_MSFORK   = 0x08000000# micro-state accounting inherited on fork */ 
 74  PR_IDLE     = 0x10000000# lwp is a cpu's idle thread */ 
 75   
 76   
 77  # Permissions... 
 78  MA_READ    = 0x04# readable by the traced process */ 
 79  MA_WRITE   = 0x02# writable by the traced process */ 
 80  MA_EXEC    = 0x01# executable by the traced process */ 
 81  MA_SHARED  = 0x08# changes are shared by mapped object */ 
 82  MA_ANON    = 0x40# anonymous memory (e.g. /dev/zero) */ 
 83  MA_ISM     = 0x80# intimate shared mem (shared MMU resources) */ 
 84  MA_NORESERVE = 0x100# mapped with MAP_NORESERVE */ 
 85  MA_SHM     = 0x200# System V shared memory */ 
 86  MA_RESERVED1 = 0x400# reserved for future use */ 
 87   
88 -class SolarisMixin:
89
90 - def initMixin(self):
91 #import sunprocfs 92 self.ctl = None
93
94 - def platformGetRegs(self):
95 pid = self.getPid()
96 97 #def platformGetThreads(self): 98 #ret = [] 99 #for name in os.listdir("/proc/%d/lwp" % self.pid): 100 #ret.append(int(name)) 101 #return ret 102
103 - def platformAttach(self, pid):
104 self.ctl = file("/proc/%d/ctl" % pid, "ab") 105 self.ctl.write(struct.pack("<L", PRSTOP))
106
107 - def platformContinue(self):
108 """ 109 Tell the process to continue running 110 """ 111 self.writeCtl(struct.pack("<LL", PCRUN, 0))
112
113 - def platformWait(self):
114 """ 115 wait for the process to do someting "interesting" 116 """ 117 self.writeCtl(struct.pack("<L", PCWSTOP)) 118 bytes = file("/proc/%d/psinfo" % self.pid, "rb").read() 119 return bytes
120
121 - def writeCtl(self, bytes):
122 os.write(self.ctl.fileno(), bytes)
123
124 - def platformDetach(self):
125 print "SOLARIS DETACH" 126 self.ctl.close() 127 self.ctl = None
128
129 -class SolarisIntelMixin:
130 """ 131 Handle register formats for the intel solaris stuff 132 """
133 - def getRegisterFormat(self):
134 return ""
135
136 - def getRegisterNames(self):
137 return []
138
139 - def platformReadMemory(self, addr, size):
140 a = array.array('c',"\x00" * size) 141 baddr, blen = a.buffer_info() 142 priovec = struct.pack("<4L",PCREAD, baddr, blen, addr) 143 print repr(priovec) 144 self.writeCtl(priovec) 145 return a.tostring()
146
147 - def platformWriteMemory(self, addr, bytes):
148 a = array.array('c',bytes) 149 baddr,blen = a.buffer_info() 150 priovec = struct.pack("<LLLL", PCWRITE, baddr, blen, addr) 151 self.writeCtl(priovec)
152
153 - def platformGetMaps(self):
154 ret = [] 155 pid = self.getPid() 156 mapdata = file("/proc/%d/map" % pid, "rb").read() 157 while mapdata: 158 addr,size = struct.unpack("<LL", mapdata[:8]) 159 perms, = struct.unpack("<L", mapdata[80:84]) 160 perms = perms & 0x7 161 ret.append((addr,size, perms, "")) 162 mapdata = mapdata[96:] 163 return ret
164