newProcess debugging help

Bert Freudenberg bert at freudenbergs.de
Tue Sep 5 14:11:36 UTC 2006


Ron Teitelbaum schrieb:
> Hello all,
> 
> Is there a way to know that a method is being simulated in a debugger?  I
> would like to have two different paths 
> 
> thisContext isDebugging ifTrue: [aBlock value]
> 	ifFalse: [aBlock newProcess].
 >
> so that I can debug the new process without having to change the code and
> remove the threading.  Or is there a better way to step through code that is
> executing in a different thread?  It would be nice if when the debugger hit
> a new thread it would simply open up a new debugger on that thread, then you
> could keep stepping through either debugger.

Actually, when you step into a #newProcess send, you should get a new 
debugger (see ContextPart>>doPrimitive:method:receiver:args:). Maybe 
this mechanism could be used to do something more intelligent:

   (primitiveIndex = 19) ifTrue:[
     meth == (BlockContext>>#newProcess) ifTrue: [
       ^self push: [receiver halt: 'New process'; value] newProcess].
     ...

If you now try to step into #newProcess, a new process is created that 
raises a Halt when resumed. Alternatively, you could immediately open a 
Debugger on the new process:

(primitiveIndex = 19) ifTrue:[
     meth == (BlockContext>>#newProcess) ifTrue: [
       | process |
       process := receiver newProcess.
       process step; step. "step "
       process debugWithTitle: 'New process'].
       ...

Here, you have to be careful not to resume the process in the original 
debugger.

This interception of #newProcess will only work if you step "into" or 
"through" a send, stepping "over" does not simulate the code but runs it 
at full speed.

Anyway, that's the basic idea. I'm pretty sure you could do a lot more 
if you grok contexts and processes. To be really useful you would have 
to intercept waits, too.

- Bert -



More information about the Squeak-dev mailing list