Index: tools/gdb/utils-gdb.py
===================================================================
--- tools/gdb/utils-gdb.py	(revision bb75b4eb5d1b016e0bedea943435055a867301fe)
+++ tools/gdb/utils-gdb.py	(revision fd4d3017a6c341cbc364e580b8b6740cb795380c)
@@ -25,5 +25,5 @@
 CfaTypes = collections.namedtuple('CfaTypes', 'cluster_ptr processor_ptr thread_ptr int_ptr thread_state')
 
-class Thread:
+class ThreadInfo:
     tid = 0
     cluster = None
@@ -100,4 +100,12 @@
         print('No clusters, program terminated')
     return cluster_root
+
+def find_curr_thread():
+    # btstr = gdb.execute('bt', to_string = True).splitlines()
+    # if len(btstr) == 0:
+    #     print('error')
+    #     return None
+    # return btstr[0].split('this=',1)[1].split(',')[0].split(')')[0]
+    return None
 
 def lookup_cluster(name = None):
@@ -134,4 +142,36 @@
     return cluster
 
+def lookup_threads_by_cluster(cluster):
+        # Iterate through a circular linked list of threads and accumulate them in an array
+        threads = []
+
+        cfa_t = get_cfa_types()
+        root = cluster['_X7threadsS8__dllist_S7$thread__1']['_X4headPY15__TYPE_generic__1'].cast(cfa_t.thread_ptr)
+
+        if root == 0x0 or root.address == 0x0:
+            print('There are no tasks for cluster: {}'.format(cluster))
+            return threads
+
+        curr = root
+        tid = 0
+        sid = -1
+
+        while True:
+            t = ThreadInfo(cluster, curr)
+            if t.is_system():
+                t.tid = sid
+                sid -= 1
+            else:
+                t.tid = tid
+                tid += 1
+
+            threads.append(t)
+
+            curr = curr['node']['next']
+            if curr == root or curr == 0x0:
+                break
+
+        return threads
+
 def system_thread(thread):
     return False
@@ -257,4 +297,10 @@
 ############
 class Threads(gdb.Command):
+    """Cforall: Display currently known threads
+Usage:
+    cfathreads                           : print Main Cluster threads, application threads only
+    cfathreads all                       : print all clusters, all threads
+    cfathreads <clusterName>             : print cluster threads, application threads only
+    """
     def __init__(self):
         # The first parameter of the line below is the name of the command. You
@@ -262,10 +308,35 @@
         super(Threads, self).__init__('info cfathreads', gdb.COMMAND_USER)
 
-    def print_usage(self):
-        print_usage("""
-    cfathread                            : print userCluster tasks, application tasks only
-    cfathread all                        : print all clusters, all tasks
-    cfathread <clusterName>              : print cluster tasks, application tasks only
-    """)
+    def print_formatted(self, marked, tid, name, state, address):
+        print('{:>1}  {:>4}  {:>20}  {:>10}  {:>20}'.format('*' if marked else ' ', tid, name, state, address))
+
+    def print_thread(self, thread, tid, marked):
+        cfa_t = get_cfa_types()
+        self.print_formatted(marked, tid, thread['self_cor']['name'].string(), str(thread['state'].cast(cfa_t.thread_state)), str(thread))
+
+    def print_formatted_cluster(self, str_format, cluster_name, cluster_addr):
+        print(str_format.format(cluster_name, cluster_addr))
+
+    def print_threads_by_cluster(self, cluster, print_system = False):
+        # Iterate through a circular linked list of tasks and print out its
+        # name along with address associated to each cluster
+        threads = lookup_threads_by_cluster(cluster)
+        if not threads:
+            return
+
+        running_thread = find_curr_thread()
+        if running_thread is None:
+            print('Could not identify current thread')
+
+        self.print_formatted(False, '', 'Name', 'State', 'Address')
+
+        for t in threads:
+            if not t.is_system() or print_system:
+                self.print_thread(t.value, t.tid, t.value == running_thread if running_thread else False)
+
+        print()
+
+    def print_all_threads(self):
+        print("Not implemented")
 
     def invoke(self, arg, from_tty):
@@ -277,7 +348,5 @@
             return
 
-        argv = parse(arg)
-        print(argv)
-        if len(argv) == 0:
+        if not arg:
             cluster = lookup_cluster()
             if not cluster:
@@ -288,29 +357,17 @@
             self.print_threads_by_cluster(cluster, False)
 
-        elif len(argv) == 1:
-            if argv[0] == 'help':
-                self.print_usage()
-            # print tasks
-            elif argv[0] == 'all':
-                self.print_all_threads() # all tasks, all clusters
-            else:
-                """
-                Print out all the tasks available in the specified cluster
-                @cluster_name: str
-                """
-                print("cfathread by name")
-                cluster = lookup_cluster(argv[0])
-                if not cluster:
-                    return
-
-                # all tasks, specified cluster
-                self.print_threads_by_cluster(cluster, True)
-
-        elif len(argv) == 2:
-            # push task
-            self.pushtask_by_id(argv[0], argv[1]) # by id, specified cluster
+        elif arg == 'all':
+            # all threads, all clusters
+            self.print_all_threads()
+
         else:
-            print('Invalid arguments')
-            self.print_usage()
+            cluster = lookup_cluster(arg)
+            if not cluster:
+                print("Could not find cluster '{}'".format(arg))
+                return
+
+            # all tasks, specified cluster
+            self.print_threads_by_cluster(cluster, True)
+
 
 ############
@@ -343,12 +400,4 @@
         print(str_format.format(cluster_name, cluster_addr))
 
-    def find_curr_thread(self):
-        # btstr = gdb.execute('bt', to_string = True).splitlines()
-        # if len(btstr) == 0:
-        #     print('error')
-        #     return None
-        # return btstr[0].split('this=',1)[1].split(',')[0].split(')')[0]
-        return None
-
     def print_tasks_by_cluster_all(self, cluster_address):
         """
@@ -404,36 +453,4 @@
             return
 
-    def threads_by_cluster(self, cluster):
-        # Iterate through a circular linked list of threads and accumulate them in an array
-        threads = []
-
-        cfa_t = get_cfa_types()
-        root = cluster['_X7threadsS8__dllist_S7$thread__1']['_X4headPY15__TYPE_generic__1'].cast(cfa_t.thread_ptr)
-
-        if root == 0x0 or root.address == 0x0:
-            print('There are no tasks for cluster: {}'.format(cluster))
-            return threads
-
-        curr = root
-        tid = 0
-        sid = -1
-
-        while True:
-            t = Thread(cluster, curr)
-            if t.is_system():
-                t.tid = sid
-                sid -= 1
-            else:
-                t.tid = tid
-                tid += 1
-
-            threads.append(t)
-
-            curr = curr['node']['next']
-            if curr == root or curr == 0x0:
-                break
-
-        return threads
-
     def print_threads_by_cluster(self, cluster, print_system = False):
         """
@@ -457,5 +474,5 @@
         for t in threads:
             if not t.is_system() or print_system:
-                self.print_thread(t.value, t.tid, tivalue == running_thread if running_thread else False)
+                self.print_thread(t.value, t.tid, t.value == running_thread if running_thread else False)
 
         print()
