Index: tools/gdb/utils-gdb.py
===================================================================
--- tools/gdb/utils-gdb.py	(revision b7d94ac5737a4c841871096ccb6bf5567f53423c)
+++ tools/gdb/utils-gdb.py	(revision 0d24ff2dd7c47457bb583e12ae019d6c9b6e19a6)
@@ -89,62 +89,105 @@
 	return argv
 
-def get_cluster_root():
-	"""
-	Return: gdb.Value of globalClusters.root (is an address)
-	"""
+class ClusterIter:
+	def __init__(self, root):
+		self.curr = None
+		self.root = root
+
+	def __iter__(self):
+		return self
+
+	def __next__(self):
+		# Clusters form a cycle
+		# If we haven't seen the root yet, then the root is the first
+		if not self.curr:
+			self.curr = self.root
+			return self.curr
+
+		# if we already saw the root, then go forward
+		self.curr = self.curr['_X4nodeS26__cluster____dbg_node_cltr_1']['_X4nextPS7cluster_1']
+
+		# if we reached the root again, then we are done
+		if self.curr == self.root:
+			raise StopIteration
+
+		# otherwise return the next
+		return self.curr
+
+def all_clusters():
+	"""
+	Return: a list of all the clusters as an iterator.
+	obtained from gdb.Value of globalClusters.root (is an address)
+	"""
+	if not is_cforall():
+		return []
+
 	cluster_root = gdb.parse_and_eval('_X11mainClusterPS7cluster_1')
 	if cluster_root.address == 0x0:
 		print('No clusters, program terminated')
-	return cluster_root
-
-def get_sched_lock():
-	"""
-	Return: gdb.Value of __scheduler_lock
-	"""
-	lock = gdb.parse_and_eval('_X16__scheduler_lockPS20__scheduler_RWLock_t_1')
-	if lock.address == 0x0:
-		print('No scheduler lock, program terminated')
-	return lock
-
-def all_clusters():
-	if not is_cforall():
-		return None
-
-	cluster_root = get_cluster_root()
-	if cluster_root.address == 0x0:
-		return
-
-	curr = cluster_root
-	ret = [curr]
-
-	while True:
-		curr = curr['_X4nodeS26__cluster____dbg_node_cltr_1']['_X4nextPS7cluster_1']
-		if curr == cluster_root:
-			break
-
-		ret.append(curr)
-
-	return ret
+		return []
+
+	return ClusterIter(cluster_root)
+
+class ProcIter:
+	def __init__(self, root):
+		self.curr = None
+		self.root = root
+
+	def __iter__(self):
+		return self
+
+	def check(self):
+		# check if this is the last value
+		addr = int(self.curr)
+		mask = 1 << ((8 * int(gdb.parse_and_eval('sizeof(void*)'))) - 1)
+		if 0 != (mask & addr):
+			raise StopIteration
+
+	def __next__(self):
+		cfa_t = get_cfa_types()
+
+		# Processors form a cycle
+		# If we haven't seen the root yet, then the root is the first
+		if not self.curr:
+			my_next = self.root
+			self.curr = my_next.cast(cfa_t.processor_ptr)
+
+			#check if this is an empty list
+			self.check()
+
+			return self.curr
+
+		# if we already saw the root, then go forward
+		my_next = self.curr['__anonymous_object2225']['_X4nextPY13__tE_generic__1']
+		self.curr = my_next.cast(cfa_t.processor_ptr)
+
+		#check if we reached the end
+		self.check()
+
+		# otherwise return the next
+		return self.curr
+
+def proc_list(cluster):
+	"""
+	Return: for a given processor, return the active and idle processors, as 2 iterators
+	"""
+	cfa_t = get_cfa_types()
+	proclist = cluster['_X5procsS19__cluster_proc_list_1']
+	idle = proclist['_X5idlesS5dlist_S9processorS5dlink_S9processor___1']['__anonymous_object2167']['_X4nextPY13__tE_generic__1']
+	active = proclist['_X7activesS5dlist_S9processorS5dlink_S9processor___1']['__anonymous_object2167']['_X4nextPY13__tE_generic__1']
+	return ProcIter(active.cast(cfa_t.processor_ptr)), ProcIter(idle.cast(cfa_t.processor_ptr))
 
 def all_processors():
-	if not is_cforall():
-		return None
-
-	cfa_t = get_cfa_types()
-
-	# get processors from registration to the RWlock
-	lock = get_sched_lock()
-
-	#get number of elements
-	count = lock['_X5readyVj_1']
-
-	#find all the procs
-	raw_procs = [lock['_X4dataPS21__scheduler_lock_id_t_1'][i]['_X6handleVPS16__processor_id_t_1'] for i in range(count)]
-
-	# pre cast full procs
-	procs = [p.cast(cfa_t.processor_ptr) for p in raw_procs if p['_X9full_procb_1']]
-
-	# sort procs by clusters
-	return sorted(procs, key=lambda p: p['_X4cltrPS7cluster_1'])
+	procs = []
+	for c in all_clusters():
+		active, idle = proc_list(c)
+		for p in active:
+			procs.append(p)
+
+		for p in idle:
+			procs.append(p)
+
+	print(procs)
+	return procs
 
 def tls_for_pthread(pthrd):
@@ -160,5 +203,5 @@
 
 def tls_for_proc(proc):
-	return tls_for_pthread(proc['_X13kernel_threadm_1'])
+	return proc['_X10local_dataPS16KernelThreadData_1']
 
 def thread_for_pthread(pthrd):
@@ -180,5 +223,5 @@
 def lookup_cluster(name = None):
 	"""
-	Look up a cluster given its ID
+	Look up one or more cluster given a name
 	@name: str
 	Return: gdb.Value
@@ -187,27 +230,20 @@
 		return None
 
-	root = get_cluster_root()
-	if root.address == 0x0:
+	clusters = all_clusters()
+	if not clusters:
 		return None
 
 	if not name:
-		return root
+		return clusters.root
 
 	# lookup for the task associated with the id
-	cluster = None
-	curr = root
-	while True:
-		if curr['_X4namePKc_1'].string() == name:
-			cluster = curr.address
-			break
-		curr = curr['_X4nodeS26__cluster____dbg_node_cltr_1']['_X4nextPS7cluster_1']
-		if curr == root or curr == 0x0:
-			break
-
-	if not cluster:
+	found = [c for c in clusters if c['_X4namePKc_1'].string() == name]
+
+	if not found:
 		print("Cannot find a cluster with the name: {}.".format(name))
 		return None
 
-	return cluster
+	return found
+
 
 def lookup_threads_by_cluster(cluster):
@@ -294,11 +330,8 @@
 		super(Processors, self).__init__('info processors', gdb.COMMAND_USER)
 
-	def print_processor(self, processor):
+	def print_processor(self, processor, in_stats):
 		should_stop = processor['_X12do_terminateVb_1']
 		if not should_stop:
-			midle = processor['_X6$linksS7$dlinks_S9processor__1']['_X4nextS9$mgd_link_Y13__tE_generic___1']['_X4elemPY13__tE_generic__1'] != 0x0
-			end   = processor['_X6$linksS7$dlinks_S9processor__1']['_X4nextS9$mgd_link_Y13__tE_generic___1']['_X10terminatorPv_1'] != 0x0
-
-			status = 'Idle' if midle or end else 'Active'
+			status = in_stats
 		else:
 			stop_count  = processor['_X10terminatedS9semaphore_1']['_X5counti_1']
@@ -336,19 +369,18 @@
 			return
 
-		procs = all_processors()
-
 		print('{:>20}  {:>11}  {:<7}  {}'.format('Processor', '', 'Pending', 'Object'))
 		print('{:>20}  {:>11}  {:<7}  {}'.format('Name', 'Status', 'Yield', 'Address'))
-		cl = None
-		for p in procs:
-			# if this is a different cluster print it
-			if cl != p['_X4cltrPS7cluster_1']:
-				if cl:
-					print()
-				cl = p['_X4cltrPS7cluster_1']
-				print('Cluster {}'.format(cl['_X4namePKc_1'].string()))
-
+		for c in clusters:
+			print('Cluster {}'.format(c['_X4namePKc_1'].string()))
+
+			active, idle = proc_list(c)
 			# print the processor information
-			self.print_processor(p)
+			for p in active:
+				self.print_processor(p, 'Active')
+
+			for p in idle:
+				self.print_processor(p, 'Idle')
+
+			print()
 
 		print()
@@ -433,5 +465,5 @@
 			cluster = lookup_cluster(arg)
 			if not cluster:
-				print("Could not find cluster '{}'".format(arg))
+				print("No matching cluster")
 				return
 
