From 015468d76d78882c913b7fd6667dc7d0e9baaebe Mon Sep 17 00:00:00 2001 From: Bilal Akhtar <bilal.akhtar@uwaterloo.ca> Date: Sun, 22 Jul 2018 21:14:48 -0400 Subject: [PATCH] And semantics, grouped printing, * fix --- src/libfibre/libfibre.so-gdb.py | 105 +++++++++++++++----------------- 1 file changed, 48 insertions(+), 57 deletions(-) diff --git a/src/libfibre/libfibre.so-gdb.py b/src/libfibre/libfibre.so-gdb.py index 5595390..b82c43e 100644 --- a/src/libfibre/libfibre.so-gdb.py +++ b/src/libfibre/libfibre.so-gdb.py @@ -146,7 +146,7 @@ class InfoFibres(gdb.Command): def get_frame_string(self, frame): # Print instruction pointer - result = str(gdb.parse_and_eval("$rip")).split(None, 1)[0] + result = str(frame.read_register('rip')).split(None, 1)[0] result += " in " + frame.name() sal = frame.find_sal() if sal is not None and sal.symtab is not None: @@ -155,7 +155,7 @@ class InfoFibres(gdb.Command): def get_row_for(self, idx, curr, frame, print_frame_info=True): result = "" - if (FibreSupport.list[idx] == curr): + if (str(FibreSupport.list[idx]) == curr): result += "* " else: result += " " @@ -163,7 +163,7 @@ class InfoFibres(gdb.Command): if frame is not None and print_frame_info == True: result += '\t' + self.get_frame_string(frame) - return result + '\n' + return result def print_all_fibres(self, curr): print(self.header) @@ -173,8 +173,7 @@ class InfoFibres(gdb.Command): def print_grouped_fibres(self, curr, n): all_fibres = FibreSupport.list - frame_groups = {} - line_groups = {} + groups = {} all_output = [] for i in range(len(FibreSupport.list)): with FibreSupport.get_frame(FibreSupport.list[i]) as frame: @@ -184,72 +183,64 @@ class InfoFibres(gdb.Command): )) if frame is None: continue - sal = frame.find_sal() - - if sal is not None and sal.symtab is not None: - # Find line similarities - source_str = "%s:%d" % (sal.symtab.filename, sal.line) - if source_str in line_groups: - line_groups[source_str].append(i) - else: - line_groups[source_str] = [i] - # Find stack similarities (up to n frames) - newframe = frame - for j in range(n+1): - name = newframe.name() - if name is None: - continue - if name in frame_groups: - frame_groups[name].append(i) - else: - frame_groups[name] = [i] - # Step one frame up - try: - newframe = newframe.older() - if newframe == None: - break - except: + # Find stack similarities (up to n frames) + newframe = frame + prevframe = None + rip_str = "" + for j in range(n+1): + rip_str += str(newframe.read_register('rip')).split(None, 1)[0] + "," + # Step one frame up ("older" in gdb's vernacular) + try: + prevframe = newframe + newframe = newframe.older() + if newframe == None: break + except: + break + elem = (i, prevframe.name()) + if rip_str in groups: + groups[rip_str].append(elem) + else: + groups[rip_str] = [elem] grouped_indices = set() - # Finally print the groups - for line, indices in line_groups.items(): - if len(indices) <= 1: - continue - print("Fibres at line ", line, " :") - print(self.header) - for i in indices: - fibre_info, frame_info = all_output[i] - print(fibre_info) # Consider if we should print frame_info - grouped_indices.add(i) - print() - line_grouped_indices = set(grouped_indices) - for frame, indices in frame_groups.items(): - # Eliminate line grouped fibres - indices = set(indices) - line_grouped_indices - if len(indices) <= 1: + sorted_groups = list(groups.items()) + sorted(sorted_groups, key=lambda x: len(x[1])) # Smaller groups first + for rip, fibres in sorted_groups: + if len(fibres) <= 1: + # Skip groups of 1 continue - print("Fibres called by ", frame, " :") - print(self.header) + print("Fibres called by same line in ", fibres[0][1], " :") + indices = map(lambda x: x[0], fibres) + joined_indices = [] for i in indices: - fibre_info, frame_info = all_output[i] - print(fibre_info, '\t', frame_info) grouped_indices.add(i) - print() + if len(joined_indices) > 0 and (joined_indices[-1][1] + 1) == i: + start, end = joined_indices[-1] + joined_indices[-1] = (start, i) + else: + joined_indices.append((i,i)) + joined_indices_strs = map( + lambda x: '%d-%d' % (x[0], x[1]) if x[0] < x[1] else str(x[0]), + joined_indices + ) + print(', '.join(list(joined_indices_strs))) + print() # Extra newline # Print anything not grouped ungrouped = set(range(len(all_output))) - grouped_indices - print('All ungrouped fibres') - print(self.header) - for i in ungrouped: - fibre_info, frame_info = all_output[i] - print(fibre_info, '\t', frame_info) + if len(ungrouped) > 0: + print('All ungrouped fibres') + print(self.header) + for i in ungrouped: + fibre_info, frame_info = all_output[i] + print(fibre_info, '\t', frame_info) def invoke(self, arg, from_tty): if (not FibreSupport.saved): return - curr = gdb.parse_and_eval("Context::currStack") + curr = str(gdb.parse_and_eval("Context::currStack")) try: if (arg != None and int(arg) >= 0): self.print_grouped_fibres(curr, int(arg)) -- GitLab