Helios-Debugger.st 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 isBlockContext ] whileTrue: [
  20. inspectedContext := inspectedContext outerContext.
  21. variables addAll: inspectedContext locals ].
  22. anInspector
  23. setLabel: 'Context';
  24. setVariables: variables
  25. ! !
  26. !HLContextInspectorDecorator class methodsFor: 'instance creation'!
  27. on: aContext
  28. ^ self new
  29. initializeFromContext: aContext;
  30. yourself
  31. ! !
  32. HLFocusableWidget subclass: #HLDebugger
  33. instanceVariableNames: 'model stackListWidget codeWidget inspectorWidget'
  34. package: 'Helios-Debugger'!
  35. !HLDebugger commentStamp!
  36. I am the main widget for the Helios debugger.!
  37. !HLDebugger methodsFor: 'accessing'!
  38. codeWidget
  39. ^ codeWidget ifNil: [ codeWidget := HLBrowserCodeWidget new
  40. browserModel: self model;
  41. yourself ]
  42. !
  43. initializeFromMethodContext: aMethodContext
  44. model := HLDebuggerModel on: aMethodContext.
  45. self observeModel
  46. !
  47. inspectorWidget
  48. ^ inspectorWidget ifNil: [
  49. inspectorWidget := HLInspectorWidget new ]
  50. !
  51. model
  52. ^ model ifNil: [ model := HLDebuggerModel new ]
  53. !
  54. stackListWidget
  55. ^ stackListWidget ifNil: [
  56. stackListWidget := (HLStackListWidget on: self model)
  57. next: self codeWidget;
  58. yourself ]
  59. ! !
  60. !HLDebugger methodsFor: 'actions'!
  61. focus
  62. self stackListWidget focus
  63. !
  64. observeModel
  65. self model announcer
  66. on: HLDebuggerContextSelected
  67. send: #onContextSelected:
  68. to: self
  69. ! !
  70. !HLDebugger methodsFor: 'reactions'!
  71. onContextSelected: anAnnouncement
  72. self inspectorWidget inspect: (HLContextInspectorDecorator on: anAnnouncement context)
  73. ! !
  74. !HLDebugger methodsFor: 'rendering'!
  75. open
  76. HLManager current addTab: (HLTab on: self labelled: self class tabLabel)
  77. !
  78. renderContentOn: html
  79. html with: (HLContainer with: (HLHorizontalSplitter
  80. with: self stackListWidget
  81. with: (HLVerticalSplitter
  82. with: self codeWidget
  83. with: self inspectorWidget)))
  84. ! !
  85. !HLDebugger class methodsFor: 'accessing'!
  86. tabLabel
  87. ^ 'Debugger'
  88. ! !
  89. !HLDebugger class methodsFor: 'instance creation'!
  90. on: aMethodContext
  91. ^ self new
  92. initializeFromMethodContext: aMethodContext;
  93. yourself
  94. ! !
  95. HLToolModel subclass: #HLDebuggerModel
  96. instanceVariableNames: 'rootContext currentContext contexts'
  97. package: 'Helios-Debugger'!
  98. !HLDebuggerModel commentStamp!
  99. I am a model for Helios debugging.
  100. My instances hold a reference to an `AIContext` instance, built from a `MethodContext`. The context should be the root of the context stack.!
  101. !HLDebuggerModel methodsFor: 'accessing'!
  102. contexts
  103. ^ contexts
  104. !
  105. currentContext
  106. currentContext ifNil: [ self currentContext: self rootContext ].
  107. ^ currentContext
  108. !
  109. currentContext: aContext
  110. self withChangesDo: [
  111. currentContext := aContext.
  112. self announcer announce: (HLDebuggerContextSelected new
  113. context: aContext;
  114. yourself).
  115. self selectedMethod: aContext method ]
  116. !
  117. rootContext
  118. ^ rootContext
  119. ! !
  120. !HLDebuggerModel methodsFor: 'initialization'!
  121. initializeContexts
  122. "Flatten the context stack into an OrderedCollection"
  123. | context |
  124. contexts := OrderedCollection new.
  125. context := self rootContext.
  126. [ context notNil ] whileTrue: [
  127. contexts add: context.
  128. context := context outerContext ]
  129. !
  130. initializeFromContext: aMethodContext
  131. rootContext := AIContext fromMethodContext: aMethodContext.
  132. self initializeContexts
  133. ! !
  134. !HLDebuggerModel class methodsFor: 'instance creation'!
  135. on: aMethodContext
  136. ^ self new
  137. initializeFromContext: aMethodContext;
  138. yourself
  139. ! !
  140. HLToolListWidget subclass: #HLStackListWidget
  141. instanceVariableNames: ''
  142. package: 'Helios-Debugger'!
  143. !HLStackListWidget methodsFor: 'accessing'!
  144. items
  145. ^ items ifNil: [ items := self model contexts ]
  146. !
  147. label
  148. ^ 'Stack'
  149. ! !
  150. !HLStackListWidget methodsFor: 'actions'!
  151. selectItem: aContext
  152. self model currentContext: aContext
  153. ! !