home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / rexx / showprocess.cpr < prev    next >
Encoding:
Text File  |  1996-12-24  |  6.4 KB  |  204 lines

  1. /* 
  2. Usage: ShowProcess [<task name> | 0xnnnnnnnn]
  3. Version 1.01  04-Nov-88
  4.  
  5. Displays the process structure for the given task.  If none is specified,
  6. the current task under debugger control is displayed.  ShowProcess will
  7. verify that the indicated task is a valid process before displaying the
  8. information.
  9.  
  10. Note that because of the Amiga Scheduling, ShowProcess may not always be
  11. able to find a task specified by name.
  12.  
  13. Output is displayed in the form:
  14. --------------------------------
  15. 'RAW' in wait state at priority 5
  16. Type 13  Flags 00  IDNestCnt 0  TDNestCnt -1
  17. Signal:  Alloc 0000FFFF  Wait  00000100  Recvd 00000000  Except 00000000
  18. Trap:    Data  00000000  Code  00FF47EA  Alloc 8000  Able 0000
  19. Except:  Data  00000000  Code  00FC2FF0
  20. Stack:   Reg   0027368E  Lower 00272BFC  Upper 002736EC
  21. CPURegs: PC    00FC08F4  SR    0010
  22. D: 0023D158 00000000 002721CC 00272778 00000009 00000052 00000057 00272B9C
  23. A: 00FF4134 00272B40 00C04EC8 00FF9FF2 00FF4648 00C00240 00C00276
  24. Process Dependent ---------------------------------------------
  25. SegList    0x00200C6C  StackSize  0x00000AF0  GlobVec0x00C04EC8
  26. TaskNum             0  StackBase  0x00272BFC  Result2         0
  27. CurrentDir 0x00000000  CIS        0x00000000  COS    0x00000000
  28. ConsoleTask0x0022F264  FileSysTask0x00C00ADC  CLI    0x00000000
  29. ReturnAddr 0x002736E8  PktWait    0x00000000
  30. */
  31.  
  32. address 'COMMAND'
  33. 'version >nil: exec.library 36 '
  34. lrc = rc
  35.  
  36. if (rc = 0) then
  37.   check = addlib('rexxsupport.library',0,-30,0) 
  38.  
  39. address
  40.  
  41. parse arg name '0x' tsk .
  42.  
  43. NULL = "00000000"x
  44.  
  45. if (name = '?') then
  46.    do
  47.    do i = 2 to 11
  48.       'd "'||strip(sourceline(i),'T',"0a"x) '"'
  49.    end
  50.    exit(0)
  51.    end
  52. else if (name ~= '') then
  53.    do
  54.    taskbase = findtask(name)
  55.    name = "'"||name||"'"
  56.    end
  57. else if (tsk ~= '') then
  58.    do
  59.    name = right(tsk,8,'0')
  60.    taskbase = x2c(name)
  61.    name = '0x'||name
  62.    end
  63. else
  64.    do
  65.    options results
  66.    'opt task'
  67.    tasklist = result
  68.    options
  69.    tasklist = strip(tasklist)
  70.    name = right(tasklist, 9)
  71.    name = left(name,8)
  72.    taskbase = x2c(name)
  73.    name = '0x'||name
  74.    end
  75.  
  76. statenm.0 = 'invalid'
  77. statenm.1 = 'added'
  78. statenm.2 = 'run'
  79. statenm.3 = 'ready'
  80. statenm.4 = 'wait'
  81. statenm.5 = 'except'
  82. statenm.6 = 'removed'
  83.  
  84. type      = c2d(import(offset(taskbase,8),1))
  85. if (type ~= 13 & type ~= 1) then do
  86.    'd' '"'||name 'is not a valid process"'
  87.    exit(0)
  88. end
  89.  
  90. name      = "'"||import(import(offset(taskbase,10),4))||"'"
  91. state     = c2d(import(offset(taskbase,15),1))
  92. statename = statenm.state
  93. pri       = c2d(import(offset(taskbase,9),1))
  94. 'd' '"'||name 'in' statename 'state at priority' pri '"'
  95.  
  96. flags     = c2x(import(offset(taskbase,14),1))
  97. idnest    = c2d(import(offset(taskbase,16),1),1)
  98. tdnest    = c2d(import(offset(taskbase,17),1),1)
  99. 'd' '"Type' type ' Flags' flags ' IDNestCnt' idnest ' TDNestCnt' tdnest '"'
  100.  
  101. sigalloc  = c2x(import(offset(taskbase,18),4))
  102. sigwait   = c2x(import(offset(taskbase,22),4))
  103. sigrec    = c2x(import(offset(taskbase,26),4))
  104. sigexcept = c2x(import(offset(taskbase,30),4))
  105. 'd' '"Signal:  Alloc' sigalloc ' Wait ' sigwait ' Recvd' sigrec ' Except' sigexcept '"'
  106.  
  107. trapdata  = c2x(import(offset(taskbase,46),4))
  108. trapcode  = c2x(import(offset(taskbase,50),4))
  109. trapalloc = c2x(import(offset(taskbase,34),2))
  110. trapable  = c2x(import(offset(taskbase,36),2))
  111. 'd' '"Trap:    Data ' trapdata ' Code ' trapcode ' Alloc' trapalloc ' Able' trapable '"'
  112.  
  113. excptdata = c2x(import(offset(taskbase,38),4))
  114. excptcode = c2x(import(offset(taskbase,42),4))
  115. 'd' '"Except:  Data ' excptdata ' Code ' excptcode '"'
  116.  
  117. sp        = import(offset(taskbase,54),4)
  118. spreg     = c2x(sp)
  119. splower   = c2x(import(offset(taskbase,58),4))
  120. spupper   = c2x(import(offset(taskbase,62),4))
  121. 'd' '"Stack:   Reg  ' spreg ' Lower' splower ' Upper' spupper '"'
  122.  
  123. if (state >= 3 & state <= 6) then do
  124. options results
  125. 'r pc'
  126. options
  127. pc = substr(strip(result),4,8)
  128. options results
  129. 'r sr'
  130. options
  131. sr = substr(strip(result),8,4)
  132. 'd' '"CPURegs: PC   ' pc ' SR   ' sr '"'
  133.  
  134. options results
  135. 'regs'
  136. options
  137. regs = strip(result)
  138. dregs = substr(regs,4,8) || " " || substr(regs,17,8) || " " || substr(regs,30,8)
  139. dregs = dregs || " " || substr(regs,43,8) || " " || substr(regs,56,8)
  140. dregs = dregs || " " || substr(regs,69,8) || " " || substr(regs,83,8)
  141. dregs = dregs || " " || substr(regs,96,8)
  142. 'd' '"D:' dregs '"'
  143.  
  144. aregs = substr(regs,109,8) || " " || substr(regs,122,8) || " " || substr(regs,135,8)
  145. aregs = aregs || " " || substr(regs,148,8) || " " || substr(regs,162,8)
  146. aregs = aregs || " " || substr(regs,175,8) || " " || substr(regs,188,8)
  147. 'd' '"A:' aregs '"'
  148. end
  149.  
  150. if type = 13 then do
  151. 'd' '"Process Dependent ----------------------------------------------"'
  152.  
  153. segarray  = "0x"||c2x(d2c(c2d(import(offset(taskbase,128),4))*4,4))
  154. segptr  =  x2c(c2x(d2c(c2d(import(offset(taskbase,128),4))*4,4)))
  155. stacksize = right(c2d(import(offset(taskbase,132),4)), 9)
  156. globvec   = "0x"||c2x(import(offset(taskbase,136),4))
  157. 'd' '"SegArray   ' segarray ' StackSize   ' stacksize ' GlobVec ' globvec '"'
  158.  
  159. tasknum   = right(c2d(import(offset(taskbase,140),4)), 9)
  160. stackbase = "0x"||c2x(d2c(c2d(import(offset(taskbase,144),4))*4,4))
  161. result2   = right(c2d(import(offset(taskbase,148),4)), 9)
  162. 'd' '"TaskNum     ' tasknum ' StackBase  ' stackbase ' Result2 ' result2  '"'
  163.  
  164. curdir    = "0x"||c2x(d2c(c2d(import(offset(taskbase,152),4))*4,4))
  165. cis       = "0x"||c2x(d2c(c2d(import(offset(taskbase,156),4))*4,4))
  166. cos       = "0x"||c2x(d2c(c2d(import(offset(taskbase,160),4))*4,4))
  167. 'd' '"CurrentDir ' curdir ' CIS        ' cis ' COS     ' cos '"'
  168.  
  169. contask   = "0x"||c2x(import(offset(taskbase,164),4))
  170. filesys   = "0x"||c2x(import(offset(taskbase,168),4))
  171. cli       = "0x"||c2x(d2c(c2d(import(offset(taskbase,172),4))*4,4))
  172. 'd' '"ConsoleTask' contask ' FileSysTask' filesys ' CLI     ' cli '"'
  173.  
  174. retaddr   = "0x"||c2x(import(offset(taskbase,180),4))
  175. pktwait   = "0x"||c2x(import(offset(taskbase,184),4))
  176. seglist   = "0x"||c2x(d2c(c2d(import(offset(segptr,12),4))*4,4))
  177. 'd' '"ReturnAddr ' retaddr ' PktWait    ' pktwait ' SegList ' seglist '"'
  178. end
  179.  
  180. exit 0
  181.  
  182. /* Locate a task in the system based upon the name */
  183. findtask:
  184.   parse arg name
  185.   execbase = next("00000004"x)
  186.   liboff = 420
  187.   nodebase = import(offset(execbase, liboff), 4)
  188.  
  189. do while(import(nodebase,4) ~= NULL)
  190.    if import(import(offset(nodebase,10),4)) = name then return nodebase
  191.    nodebase = import(nodebase,4)
  192. end
  193.  
  194.   liboff = 406
  195.   nodebase = import(offset(execbase, liboff), 4)
  196.  
  197. do while(import(nodebase,4) ~= NULL)
  198.    if import(import(offset(nodebase,10),4)) = name then return nodebase
  199.    nodebase = import(nodebase,4)
  200. end
  201.  
  202. 'd' '"Could not find process' name||'"'
  203. exit(0)
  204.