def thread_settarget(cpu, tid): global target_tid global breakpoint gca.monitor_output("set target = %08x" % tid) if not thread_isalive(cpu, tid): print "not alive" return False if thread_getcurrent(cpu) == tid: return False if not breakpoint == False: breakpoint_cleanup() # ebp is a "framepointer" fp = unpack_int(thread_list[tid]["registers"]["ebp"]) # read the backtrace backtrace = read_linkedlist(cpu, fp) gca.monitor_output("backtrace is " + str(backtrace)) # when thread is in context switch backtrace looks like: # # #0 0x00114756 in _Thread_Dispatch () # #1 0x001113a1 in _Thread_Enable_dispatch () # #2 0x0011140c in rtems_task_wake_after () # #3 0x0010037e in Task_Relative_Period (unused=3) at tasks.c:167 # #4 0x0011e4c3 in _Thread_Handler () # #5 0x85b45d8b in ?? () # # #0 is the actual EIP, and not contained in the backtrace # # 1st position will trigger breakpoint on each context switch, # which is probably safer, but a lot slower # # Note: This will only work then context switch called without interrupts. # # index - where # 2 - breakpoint in user program # 1 - break in system call, called by program breakpoint = (backtrace[1], 4, 1) if gca.breakpoint_insert(*breakpoint): gca.monitor_output("Breakpoint planted") else: breakpoint = False raise "Unable to set breakpoint" target_tid = tid gca.monitor_output("Target Thread %08x" % tid) return True
def print_objects(self, cpu): ptrs = self.get_objectinfo_table(cpu) for i in range(1, len(ptrs)): if ptrs[i] == 0: continue for j in range(1, len(self._OBJECTS[i])): oi_ptr = deref_ptr(cpu, ptrs[i] + 4 * j) oi = self.get_objectinfo(cpu, oi_ptr) for k in range(0, oi["maximum"] + 1): objctrl_ptr = deref_ptr(cpu, oi["local_table"] + k * 4) if objctrl_ptr == 0: continue oc = self.get_objectcontrol(cpu, objctrl_ptr) gca.monitor_output( "%s %s %08x %s" % (self._OBJECTS_APIS[i], self._OBJECTS[i][j], oc["id"], repr(oc["name"])) )
def hook_signal_trap(cpu): global target_tid global breakpoint if breakpoint == False: return 0 # need to check that thread exists if not thread_isalive(cpu, target_tid): gca.monitor_output("Thread %08x no longer exists" % target_tid) breakpoint_cleanup() return 0 # user doesn't care about other threads if target_os.get_current_thread(cpu) != target_tid: return 2 gca.monitor_output("Cink - Your thread is ready!") breakpoint_cleanup() return 1
def set_thread_registers(self, cpu, tid, regs): r = self._target_cpu.parse_gdb_regs(regs) gca.monitor_output("Not implemented, yet") return 0