freemyipod r137 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r136‎ | r137 | r138 >
Date:11:46, 14 August 2010
Author:benedikt93
Status:new
Tags:
Comment:
fix libembios -> getprocinfo at least partially
Modified paths:
  • /embios/trunk/tools/libembios.py (modified) (history)

Diff [purge]

Index: embios/trunk/tools/libembios.py
@@ -763,7 +763,7 @@
764764 <silent> = 0: Process information struct version, Process information table size
765765 <silent> = 1: nothing
766766 """
767 -
 767+ # inline functions ----------------------------------------------
768768 def procinfotolist(processinfo, structver):
769769 if (structver == 1): # Process information struct version == 1
770770 ptr = 0
@@ -770,41 +770,43 @@
771771 process_n = 0
772772 retval = []
773773 while ptr < len(processinfo):
 774+ if struct.unpack("<I", processinfo[ptr:ptr + 4])[0] == 0: continue # THREAD_FREE
 775+
774776 retval.append({})
775777
776778 retval[process_n]['regs'] = struct.unpack("<IIIIIIIIIIIIIIII", processinfo[ptr:ptr + 64])
777779 ptr += 16 * 0x4
778 - retval[process_n]['cpsr'] = int(struct.unpack("<I", processinfo[ptr:ptr + 4])[0])
 780+ retval[process_n]['cpsr'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
779781 ptr += 1 * 0x4
780 - retval[process_n]['state'] = int(struct.unpack("<I", processinfo[ptr:ptr + 4])[0])
 782+ retval[process_n]['state'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
781783 ptr += 1 * 0x4
782 - retval[process_n]['name_ptr'] = int(struct.unpack("<I", processinfo[ptr:ptr + 4])[0])
 784+ retval[process_n]['name_ptr'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
783785 ptr += 1 * 0x4
784 - retval[process_n]['cputime_current'] = int(struct.unpack("<I", processinfo[ptr:ptr + 4])[0])
 786+ retval[process_n]['cputime_current'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
785787 ptr += 1 * 0x4
786788 retval[process_n]['cputime_total'] = struct.unpack("<Q", processinfo[ptr:ptr + 8])[0]
787789 ptr += 1 * 0x8
788 - retval[process_n]['startusec'] = int(struct.unpack("<I", processinfo[ptr:ptr + 4])[0])
 790+ retval[process_n]['startusec'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
789791 ptr += 1 * 0x4
790 - retval[process_n]['queue_next_ptr'] = int(struct.unpack("<I", processinfo[ptr:ptr + 4])[0])
 792+ retval[process_n]['queue_next_ptr'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
791793 ptr += 1 * 0x4
792 - retval[process_n]['timeout'] = int(struct.unpack("<I", processinfo[ptr:ptr + 4])[0])
 794+ retval[process_n]['timeout'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
793795 ptr += 1 * 0x4
794 - retval[process_n]['blocked_since'] = int(struct.unpack("<I", processinfo[ptr:ptr + 4])[0])
 796+ retval[process_n]['blocked_since'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
795797 ptr += 1 * 0x4
796 - retval[process_n]['blocked_by_ptr'] = int(struct.unpack("<I", processinfo[ptr:ptr + 4])[0])
 798+ retval[process_n]['blocked_by_ptr'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
797799 ptr += 1 * 0x4
798 - retval[process_n]['stack_ptr'] = int(struct.unpack("<I", processinfo[ptr:ptr + 4])[0])
 800+ retval[process_n]['stack_ptr'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
799801 ptr += 1 * 0x4
800 - retval[process_n]['err_no'] = int(struct.unpack("<I", processinfo[ptr:ptr + 4])[0])
 802+ retval[process_n]['err_no'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
801803 ptr += 1 * 0x4
802 - retval[process_n]['block_type'] = int(struct.unpack("<B", processinfo[ptr:ptr + 1])[0])
 804+ retval[process_n]['block_type'] = struct.unpack("<B", processinfo[ptr:ptr + 1])[0]
803805 ptr += 1 * 0x1
804 - retval[process_n]['thread_type'] = int(struct.unpack("<B", processinfo[ptr:ptr + 1])[0])
 806+ retval[process_n]['thread_type'] = struct.unpack("<B", processinfo[ptr:ptr + 1])[0]
805807 ptr += 1 * 0x1
806 - retval[process_n]['priority'] = int(struct.unpack("<B", processinfo[ptr:ptr + 1])[0])
 808+ retval[process_n]['priority'] = struct.unpack("<B", processinfo[ptr:ptr + 1])[0]
807809 ptr += 1 * 0x1
808 - retval[process_n]['cpuload'] = int(struct.unpack("<B", processinfo[ptr:ptr + 1])[0])
 810+ retval[process_n]['cpuload'] = struct.unpack("<B", processinfo[ptr:ptr + 1])[0]
809811 ptr += 1 * 0x1
810812
811813 process_n += 1
@@ -812,28 +814,35 @@
813815 return retval
814816
815817
816 - def state2name(state):
817 - if state == 0: return "THREAD_FREE"
818 - elif state == 1: return "THREAD_SUSPENDED"
819 - elif state == 2: return "THREAD_READY"
820 - elif state == 3: return "THREAD_RUNNING"
821 - elif state == 4: return "THREAD_BLOCKED"
822 - elif state == 5: return "THREAD_DEFUNCT"
823 - elif state == 6: return "THREAD_DEFUNCT_ACK"
 818+ def state2name(state, structver):
 819+ if structver == 1:
 820+ if state == 0: return "THREAD_FREE"
 821+ elif state == 1: return "THREAD_SUSPENDED"
 822+ elif state == 2: return "THREAD_READY"
 823+ elif state == 3: return "THREAD_RUNNING"
 824+ elif state == 4: return "THREAD_BLOCKED"
 825+ elif state == 5: return "THREAD_DEFUNCT"
 826+ elif state == 6: return "THREAD_DEFUNCT_ACK"
 827+ else: return "UNKNOWN"
824828 else: return "UNKNOWN"
825829
826 - def blocktype2name(blocktype):
827 - if blocktype == 0: return "THREAD_NOT_BLOCKED"
828 - elif blocktype == 1: return "THREAD_BLOCK_SLEEP"
829 - elif blocktype == 2: return "THREAD_BLOCK_MUTEX"
830 - elif blocktype == 3: return "THREAD_BLOCK_WAKEUP"
831 - elif blocktype == 4: return "THREAD_DEFUNCT_STKOV"
832 - elif blocktype == 5: return "THREAD_DEFUNCT_PANIC"
 830+ def blocktype2name(blocktype, structver):
 831+ if structver == 1:
 832+ if blocktype == 0: return "THREAD_NOT_BLOCKED"
 833+ elif blocktype == 1: return "THREAD_BLOCK_SLEEP"
 834+ elif blocktype == 2: return "THREAD_BLOCK_MUTEX"
 835+ elif blocktype == 3: return "THREAD_BLOCK_WAKEUP"
 836+ elif blocktype == 4: return "THREAD_DEFUNCT_STKOV"
 837+ elif blocktype == 5: return "THREAD_DEFUNCT_PANIC"
 838+ else: return "UNKNOWN"
833839 else: return "UNKNOWN"
834840
835 - def threadtype2name (threadtype):
836 - if threadtype == 0: return "USER_THREAD"
837 - elif threadtype == 1: return "SYSTEM_THREAD"
 841+ def threadtype2name (threadtype, structver):
 842+ if structver == 1:
 843+ if threadtype == 0: return "USER_THREAD"
 844+ elif threadtype == 1: return "OS_THREAD"
 845+ elif threadtype == 2: return "CORE_THREAD"
 846+ else: return "UNKNOWN"
838847 else: return "UNKNOWN"
839848
840849 def procinfotostring(procinfolist, structver):
@@ -850,7 +859,7 @@
851860 + "R12: 0x%08x, SP: 0x%08x, LR: 0x%08x, PC: 0x%08x\n" \
852861 % (procinfolist[ptr]['regs'][12], procinfolist[ptr]['regs'][13], procinfolist[ptr]['regs'][14], procinfolist[ptr]['regs'][15])
853862 processinfoprint += "cpsr: 0x%08x " % (procinfolist[ptr]['cpsr'])
854 - processinfoprint += "state: %s " % (state2name([procinfolist[ptr]['state']]))
 863+ processinfoprint += "state: %s " % (state2name([procinfolist[ptr]['state']], structver))
855864 processinfoprint += "nameptr: 0x%08x\n" % (procinfolist[ptr]['name_ptr'])
856865 processinfoprint += "current cpu time: 0x%08x " % (procinfolist[ptr]['cputime_current'])
857866 processinfoprint += "total cpu time: 0x%016x\n" % (procinfolist[ptr]['cputime_total'])
@@ -860,8 +869,8 @@
861870 processinfoprint += "blocked since: 0x%08x " % (procinfolist[ptr]['blocked_since'])
862871 processinfoprint += "blocked by ptr: 0x%08x\n" % (procinfolist[ptr]['blocked_by_ptr'])
863872 processinfoprint += "err_no: 0x%08x " % (procinfolist[ptr]['err_no'])
864 - processinfoprint += "block type: %s\n" % (blocktype2name([procinfolist[ptr]['block_type']]))
865 - processinfoprint += "thread type: %s\n" % (threadtype2name([procinfolist[ptr]['thread_type']]))
 873+ processinfoprint += "block type: %s\n" % (blocktype2name([procinfolist[ptr]['block_type']], structver))
 874+ processinfoprint += "thread type: %s\n" % (threadtype2name([procinfolist[ptr]['thread_type']], structver))
866875 processinfoprint += "priority: 0x%02x " % (procinfolist[ptr]['priority'])
867876 processinfoprint += "cpu load: 0x%02x\n" % (procinfolist[ptr]['cpuload'])
868877
@@ -871,7 +880,7 @@
872881
873882 return processinfoprint
874883
875 -
 884+ # reading code --------------------------------------------------
876885 self.__myprint("Retrieving process information...", silent)
877886
878887 offset = 0