[PATCH] fix minidebugger bitrot

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] fix minidebugger bitrot

Paolo Bonzini-2
The changes were minor, except that I didn't anticipate having to modify
the interpreter.  I'll check if this has to be backported to 2.3 too.

Paolo

2007-07-11  Paolo Bonzini  <[hidden email]>

        * examples/MiniDebugger.st: Fix bitrot, use #lines.
        * kernel/CompildCode.st: Fix generation of source code line map.

        * libgst/interp-bc.inl: Reset _gst_except_flag to false at beginning
        of monitor_byte_codes.

        * packages/browser/Debugger.st: Highlight line 1 for nil context.


--- orig/examples/MiniDebugger.st
+++ mod/examples/MiniDebugger.st
@@ -331,6 +331,7 @@ continue
 !MiniDebugger methodsFor: 'source code'!
 
 currentMethodSource
+    activeContext isNil ifTrue: [ ^#() ].
     ^methodSourceCodeCache at: activeContext method ifAbsentPut: [
  self linesOf: activeContext method methodSourceString
     ]
@@ -338,6 +339,7 @@ currentMethodSource
 
 currentLine
     | lineMap |
+    activeContext isNil ifTrue: [ ^self ].
     lineMap := methodLineMapCache at: activeContext method ifAbsentPut: [
  activeContext method sourceCodeMap
     ].
@@ -345,23 +347,15 @@ currentLine
 !
 
 linesOf: aString
-    | oc start |
-    aString isNil ifTrue: [ ^#() ].
-    oc := OrderedCollection new.
-    start := 0.
-    aString keysAndValuesDo: [ :index :each |
- each == Character nl
-    ifTrue: [
- oc add: (aString copyFrom: start to: index - 1).
- start := index + 1
-    ]
-    ].
-    oc add: (aString copyFrom: start).
-    ^oc
+    aString isNil ifTrue: [ ^nil ].
+    ^aString readStream lines contents
 !
 
 printCurrentMethod
-    self currentMethodSource keysAndValuesDo: [ :line :code |
+    | source |
+    source := self currentMethodSource.
+    source isNil ifTrue: [ ^self ].
+    source keysAndValuesDo: [ :line :code |
  self rightJustify: line.
  stdout
     space;
@@ -371,14 +365,16 @@ printCurrentMethod
 !
 
 printCurrentLine
-    | line |
+    | line source |
+    source := self currentMethodSource.
+    source isNil ifTrue: [ ^self ].
     line := self currentLine.
     line = 0 ifTrue: [ ^self ].
 
     self rightJustify: line.
     stdout
  space;
- nextPutAll: (self currentMethodSource at: line ifAbsent: [ '' ]);
+ nextPutAll: (source at: line ifAbsent: [ '' ]);
  nl
 ! !
 
@@ -402,8 +398,10 @@ doStepCommand
  (command == $c) ifTrue: [ self continue ].
     ].
 
-    activeContext == context ifFalse: [ activeContext printNl ].
-    self printCurrentLine.
+    activeContext isNil ifFalse: [
+ activeContext == context ifFalse: [ activeContext printNl ].
+ self printCurrentLine ].
+
     ^true
 !
 
@@ -519,8 +517,8 @@ initializeFor: aProcess
     [ activeContext isInternalExceptionHandlingContext ]
  whileTrue: [ self finish ].
 
-    process suspendedContext backtraceOn: stdout.
-    ObjectMemory globalGarbageCollect.
+    self backtraceOf: process.
+    self printCurrentLine.
 !
 
 backtraceOf: aProcess


--- orig/kernel/CompildCode.st
+++ mod/kernel/CompildCode.st
@@ -474,7 +474,7 @@ sourceCodeMap
     map := ByteArray new: self size.
     line := 1.
     self allByteCodeIndicesDo: [ :each :byte :operand |
-        (self class bytecodeInfoTable at: byte * 4 + 4) > 128 ifTrue: [
+        (self class bytecodeInfoTable at: byte * 4 + 4) >= 128 ifTrue: [
     line := operand.
             operand > 255 ifTrue: [ map := map asArray ]
         ].



--- orig/libgst/interp-bc.inl
+++ mod/libgst/interp-bc.inl
@@ -506,6 +506,7 @@ _gst_interpret (OOP processOOP)
   IMPORT_REGS ();
 
 monitor_byte_codes:
+  SET_EXCEPT_FLAG (false);
   if (!disable_preemption)
     {
       _gst_disable_interrupts (); /* block out everything! */
@@ -571,12 +572,12 @@ monitor_byte_codes:
 
       printf ("%5td:", (ptrdiff_t) (ip - method_base));
       _gst_print_bytecode_name (ip, ip - method_base, _gst_literals, "");
+      SET_EXCEPT_FLAG (true);
     }
 
   if UNCOMMON (time_to_preempt)
     set_preemption_timer ();
 
-  SET_EXCEPT_FLAG (_gst_execution_tracing);
   FETCH (normal_byte_codes);
 
   /* Some more routines we need... */


--- orig/packages/browser/Debugger.st
+++ mod/packages/browser/Debugger.st
@@ -297,6 +297,7 @@ currentLine
 
 lineFor: context
     | lineMap |
+    context isNil ifTrue: [ ^1 ].
     lineMap := methodLineMapCache at: context method
  ifAbsentPut: [ context method sourceCodeMap ].
     ^lineMap at: context ip + 1 ifAbsent: [ 1 ]!




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk