1
0

Helios-Debugger.st 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. Smalltalk current createPackage: 'Helios-Debugger'!
  2. Object subclass: #HLContextInspectorDecorator
  3. instanceVariableNames: 'context'
  4. package: 'Helios-Debugger'!
  5. !HLContextInspectorDecorator methodsFor: 'accessing'!
  6. context
  7. ^ context
  8. ! !
  9. !HLContextInspectorDecorator methodsFor: 'initialization'!
  10. initializeFromContext: aContext
  11. context := aContext
  12. ! !
  13. !HLContextInspectorDecorator methodsFor: 'inspecting'!
  14. inspectOn: anInspector
  15. | variables inspectedContext |
  16. variables := Dictionary new.
  17. inspectedContext := self context.
  18. variables addAll: inspectedContext locals.
  19. [ inspectedContext notNil and: [ inspectedContext isBlockContext ] ] whileTrue: [
  20. inspectedContext := inspectedContext outerContext.
  21. inspectedContext ifNotNil: [
  22. variables addAll: inspectedContext locals ] ].
  23. anInspector
  24. setLabel: 'Context';
  25. setVariables: variables
  26. ! !
  27. !HLContextInspectorDecorator class methodsFor: 'instance creation'!
  28. on: aContext
  29. ^ self new
  30. initializeFromContext: aContext;
  31. yourself
  32. ! !
  33. HLFocusableWidget subclass: #HLDebugger
  34. instanceVariableNames: 'model stackListWidget codeWidget inspectorWidget'
  35. package: 'Helios-Debugger'!
  36. !HLDebugger commentStamp!
  37. I am the main widget for the Helios debugger.!
  38. !HLDebugger methodsFor: 'accessing'!
  39. codeWidget
  40. ^ codeWidget ifNil: [ codeWidget := HLDebuggerCodeWidget new
  41. browserModel: self model;
  42. yourself ]
  43. !
  44. initializeFromMethodContext: aMethodContext
  45. model := HLDebuggerModel on: aMethodContext.
  46. self observeModel
  47. !
  48. inspectorWidget
  49. ^ inspectorWidget ifNil: [
  50. inspectorWidget := HLInspectorWidget new ]
  51. !
  52. model
  53. ^ model ifNil: [ model := HLDebuggerModel new ]
  54. !
  55. stackListWidget
  56. ^ stackListWidget ifNil: [
  57. stackListWidget := (HLStackListWidget on: self model)
  58. next: self codeWidget;
  59. yourself ]
  60. ! !
  61. !HLDebugger methodsFor: 'actions'!
  62. focus
  63. self stackListWidget focus
  64. !
  65. observeModel
  66. self model announcer
  67. on: HLDebuggerContextSelected
  68. send: #onContextSelected:
  69. to: self
  70. ! !
  71. !HLDebugger methodsFor: 'reactions'!
  72. onContextSelected: anAnnouncement
  73. self inspectorWidget inspect: (HLContextInspectorDecorator on: anAnnouncement context)
  74. ! !
  75. !HLDebugger methodsFor: 'rendering'!
  76. open
  77. HLManager current addTab: (HLTab on: self labelled: self class tabLabel)
  78. !
  79. renderContentOn: html
  80. html with: (HLContainer with: (HLHorizontalSplitter
  81. with: self stackListWidget
  82. with: (HLVerticalSplitter
  83. with: self codeWidget
  84. with: self inspectorWidget)))
  85. ! !
  86. !HLDebugger class methodsFor: 'accessing'!
  87. tabClass
  88. ^ 'debugger'
  89. !
  90. tabLabel
  91. ^ 'Debugger'
  92. ! !
  93. !HLDebugger class methodsFor: 'instance creation'!
  94. on: aMethodContext
  95. ^ self new
  96. initializeFromMethodContext: aMethodContext;
  97. yourself
  98. ! !
  99. HLBrowserCodeWidget subclass: #HLDebuggerCodeWidget
  100. instanceVariableNames: 'highlightedNode'
  101. package: 'Helios-Debugger'!
  102. !HLDebuggerCodeWidget methodsFor: 'accessing'!
  103. contents: aString
  104. self clearHighlight.
  105. super contents: aString
  106. !
  107. editorOptions
  108. ^ super editorOptions
  109. at: 'gutters' put: #('CodeMirror-linenumbers' 'stops');
  110. yourself
  111. !
  112. highlightedNode
  113. ^ highlightedNode
  114. !
  115. highlightedNode: aNode
  116. highlightedNode := aNode
  117. ! !
  118. !HLDebuggerCodeWidget methodsFor: 'actions'!
  119. addStopAt: anInteger
  120. editor
  121. setGutterMarker: anInteger
  122. gutter: 'stops'
  123. value: '<div class="stop"></stop>' asJQuery toArray first
  124. !
  125. clearHighlight
  126. editor clearGutter: 'stops'.
  127. self highlightedNode ifNotNil: [ :node |
  128. editor
  129. removeLineClass: node position x - 1
  130. where: 'background'
  131. class: 'highlighted' ]
  132. !
  133. highlight
  134. | anchor head selection |
  135. head := #{
  136. 'line' -> (self highlightedNode position x - 1).
  137. 'ch' -> (self highlightedNode position y - 1)
  138. }.
  139. anchor := #{
  140. 'line' -> (self highlightedNode extent x - 1).
  141. 'ch' -> (self highlightedNode extent y - 1)
  142. }.
  143. editor setSelection: head to: anchor
  144. !
  145. highlightLine: anInteger
  146. editor
  147. addLineClass: anInteger
  148. where: 'background'
  149. class: 'highlighted'
  150. !
  151. highlightNode: aNode
  152. | line |
  153. aNode ifNotNil: [
  154. line := aNode position x - 1.
  155. self
  156. clearHighlight;
  157. addStopAt: line;
  158. highlightLine: line;
  159. highlightedNode: aNode
  160. ]
  161. !
  162. observeBrowserModel
  163. super observeBrowserModel.
  164. self browserModel announcer
  165. on: HLDebuggerContextSelected
  166. send: #onContextSelected
  167. to: self
  168. ! !
  169. !HLDebuggerCodeWidget methodsFor: 'reactions'!
  170. onContextSelected
  171. self highlightNode: self browserModel nextNode
  172. ! !
  173. HLToolModel subclass: #HLDebuggerModel
  174. instanceVariableNames: 'rootContext currentContext contexts interpreter'
  175. package: 'Helios-Debugger'!
  176. !HLDebuggerModel commentStamp!
  177. I am a model for Helios debugging.
  178. My instances hold a reference to an `AIContext` instance, built from a `MethodContext`. The context should be the root of the context stack.!
  179. !HLDebuggerModel methodsFor: 'accessing'!
  180. contexts
  181. ^ contexts
  182. !
  183. currentContext
  184. currentContext ifNil: [ self currentContext: self rootContext ].
  185. ^ currentContext
  186. !
  187. currentContext: aContext
  188. self withChangesDo: [
  189. self selectedMethod: aContext method.
  190. currentContext := aContext.
  191. interpreter := ASTDebugger context: aContext.
  192. self announcer announce: (HLDebuggerContextSelected new
  193. context: aContext;
  194. yourself) ]
  195. !
  196. interpreter
  197. ^ interpreter
  198. !
  199. nextNode
  200. ^ self interpreter nextNode
  201. !
  202. rootContext
  203. ^ rootContext
  204. ! !
  205. !HLDebuggerModel methodsFor: 'initialization'!
  206. initializeContexts
  207. "Flatten the context stack into an OrderedCollection"
  208. | context |
  209. contexts := OrderedCollection new.
  210. context := self rootContext.
  211. [ context notNil ] whileTrue: [
  212. contexts add: context.
  213. context := context outerContext ]
  214. !
  215. initializeFromContext: aMethodContext
  216. rootContext := AIContext fromMethodContext: aMethodContext.
  217. self initializeContexts
  218. ! !
  219. !HLDebuggerModel class methodsFor: 'instance creation'!
  220. on: aMethodContext
  221. ^ self new
  222. initializeFromContext: aMethodContext;
  223. yourself
  224. ! !
  225. ErrorHandler subclass: #HLErrorHandler
  226. instanceVariableNames: ''
  227. package: 'Helios-Debugger'!
  228. !HLErrorHandler methodsFor: 'error handling'!
  229. handleError: anError
  230. [ (HLDebugger on: anError context)
  231. open ] on: Error do: [ :error |
  232. ErrorHandler new handleError: error ]
  233. ! !
  234. HLToolListWidget subclass: #HLStackListWidget
  235. instanceVariableNames: ''
  236. package: 'Helios-Debugger'!
  237. !HLStackListWidget methodsFor: 'accessing'!
  238. items
  239. ^ items ifNil: [ items := self model contexts ]
  240. !
  241. label
  242. ^ 'Call stack'
  243. ! !
  244. !HLStackListWidget methodsFor: 'actions'!
  245. selectItem: aContext
  246. self model currentContext: aContext
  247. ! !