Search code examples
debuggingforksmalltalkpharo

Pharo: How to view the senders of newProcess in a Debugger?


I am facing a debug situation like this. The oldest method I can see called is a BlockClosure newProcess.

But I need to see who originated the newProcess send. When I click over the method in the debugger method list, the stack does not expand as usually does showing the callers.

Is this possible in Pharo?


Solution

  • Short answer: no. A new process doesn't have any history from before its conception.

    Slightly longer answer: if you're willing to do a little work you can embed a reference to the caller process in the new process by using the normal closure creation. Here's an example:

    | currentStack forkedProcess |
    currentStack := thisContext copyStack.
    
    forkedProcess := [
        | referenceToCaller |
        referenceToCaller := currentStack.
        self performOperations ] fork.
    

    Note that this will not enhance your debugging experience since the debugger doesn't know that you have that reference. To do this you need to extend the stack of your current process (variant of the above):

    forkedProcess := [
        thisContext bottomContext privSender: currentStack.
        self performOperations ] fork.
    

    Be very careful when manipulating the context chain like this. You may end up in situations that are hard to understand and debug. What I've shown here is for illustration and shouldn't be used if you don't know how the system works.