def offcore_cb(tid, cpu, dummy) :
  """This callback fires before we take the fault.  Read out the
  CPU state and store it in our map"""

  u.log('410-tidinfo', 'OFFCORE %r %d' % (cpu, tid));

  tidcontext[tid] = u.trap_frame_from_cpu(cpu)
  SIM_hap_delete_callback_obj('Core_Exception', cpu, offcore_cb, tid)
  SIM_hap_add_callback_obj('Core_Exception_Return', cpu, 0, oncore_cb, tid)
def cmd_tidinfo(tid):
  if not tidcontext:
    print "This kernel does not appear to support the modern infrastructure for this command."
    print "*** If this is a reference kernel, perhaps you need to 'make update'? If that doesn't help, contact course staff."
    return
  if tid not in tidcontext :
    print "Kernel did not register a tid %d; are you sure that's right?" % tid
    return

  if tid in tidtaskname :
    u.log('410', 'TID %d symbols are in %s' % (tid, tidtaskname[tid]))
  else :
    u.log('410', 'TID %d has unknown symbol table' % (tid))

  tf = tidcontext[tid]
  if isinstance(tf, dict) :
    # Off core, stored decoded frame at registration time
    u.log('410', 'TID %d is off-core right now' % tid)
    u.print_trap_frame(tf)
  else :
    # On core, read from cpu right now
    u.log('410', 'TID %d is on-core right now: %s' % (tid, tf.name))
    u.print_trap_frame(u.trap_frame_from_cpu(tf))