Skip to content

pyrenode3 crashes when creating an Action`2 and passing it to SetHook #17

@jwise

Description

@jwise

I'm trying to get a hook attached through to pyrenode3 like I would in a resc file:

sysbus.cpu0 AddHook 0x8001d7c """
us = cpu.GetRegister(0).RawValue
print 'skipping delay of {} us'.format(us)
cpu.SetRegister(0, Antmicro.Renode.Peripherals.CPU.RegisterValue.Create(0, 32))
"""

But creating an Action by hand and passing it to AddHook causes pyrenode3 to crash anyway:

>>> def hook(cpu: "Antmicro.Renode.Peripherals.CPU.ICpuSupportingGdb", what: "System.UInt64") -> "UInt64":
...     print("fired!")
...     return 0
...
>>> import System
>>> import Antmicro.Renode.Peripherals.CPU
>>> getattr(System, "Action`2")[Antmicro.Renode.Peripherals.CPU.ICpuSupportingGdb, System.UInt64]
<class 'System.Action[ICpuSupportingGdb,UInt64]'>
>>> action = getattr(System, "Action`2")[Antmicro.Renode.Peripherals.CPU.ICpuSupportingGdb, System.UInt64](hook)
>>> ams.sysbus.cpu0.AddHook(0x8001d7c, action)
>>> e.StartAll()
Unhandled Exception:
Python.Runtime.PythonException: Cannot switch to a different thread
	Current:  <greenlet.greenlet object at 0x70399ad8b880 (otid=0x7039a6152c10) current active started main>
	Expected: <greenlet.greenlet object at 0x7039d7a9bd40 (otid=0x7039d7af2310) suspended active started main>
  at Python.Runtime.PythonException.ThrowLastAsClrException () [0x00025] in <4c57922ba7ce4753a801bba125b62f75>:0 
  at Python.Runtime.Dispatcher.TrueDispatch (System.Object[] args) [0x000ad] in <4c57922ba7ce4753a801bba125b62f75>:0 
  at Python.Runtime.Dispatcher.Dispatch (System.Object[] args) [0x00006] in <4c57922ba7ce4753a801bba125b62f75>:0 
  at __System_Action`2\[\[Antmicro_Renode_Peripherals_CPU_ICpuSupportingGdb\, Emulator\, Version=0_0_0_0\, Culture=neutral\, PublicKeyToken=null\]\,\[System_UInt64\, mscorlib\, Version=4_0_0_0\, Culture=neutral\, PublicKeyToken=b77a5c561934e089\]\]Dispatcher.Invoke (Antmicro.Renode.Peripherals.CPU.ICpuSupportingGdb , System.UInt64 ) [0x00022] in <3b6ae4eb72634353b0d26b4f0a61ee6e>:0 
  at Antmicro.Renode.Peripherals.CPU.TranslationCPU+HookDescriptor.ExecuteCallbacks () [0x0001a] in <efd51307fbcb4e0ab3e763837222423d>:0 
  at Antmicro.Renode.Peripherals.CPU.TranslationCPU.ExecuteHooks (System.UInt64 address) [0x00034] in <efd51307fbcb4e0ab3e763837222423d>:0 
  at Antmicro.Renode.Peripherals.CPU.TranslationCPU.ExecutionFinished (Antmicro.Renode.Peripherals.CPU.ExecutionResult result) [0x00011] in <efd51307fbcb4e0ab3e763837222423d>:0 
  at Antmicro.Renode.Peripherals.CPU.BaseCPU.CpuThreadBodyInner (System.Boolean singleStep) [0x00135] in <efd51307fbcb4e0ab3e763837222423d>:0 
  at Antmicro.Renode.Peripherals.CPU.BaseCPU.CpuThreadBody () [0x00155] in <efd51307fbcb4e0ab3e763837222423d>:0 
  at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00017] in <12b418a7818c4ca0893feeaaf67f1e7f>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x0008d] in <12b418a7818c4ca0893feeaaf67f1e7f>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <12b418a7818c4ca0893feeaaf67f1e7f>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x00031] in <12b418a7818c4ca0893feeaaf67f1e7f>:0 
  at System.Threading.ThreadHelper.ThreadStart () [0x0000b] in <12b418a7818c4ca0893feeaaf67f1e7f>:0

Is there a known correct way to create a hook that calls into pyrenode3?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions