Skip to content
Snippets Groups Projects

Add new argument to info fibres to enable grouping by line/stack

Merged Mohammed Bilal Akhtar requested to merge mbakhtar/KOS:fibre-grouping-initial into master
1 file
+ 48
57
Compare changes
  • Side-by-side
  • Inline
@@ -146,7 +146,7 @@ class InfoFibres(gdb.Command):
@@ -146,7 +146,7 @@ class InfoFibres(gdb.Command):
def get_frame_string(self, frame):
def get_frame_string(self, frame):
# Print instruction pointer
# 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()
result += " in " + frame.name()
sal = frame.find_sal()
sal = frame.find_sal()
if sal is not None and sal.symtab is not None:
if sal is not None and sal.symtab is not None:
@@ -155,7 +155,7 @@ class InfoFibres(gdb.Command):
@@ -155,7 +155,7 @@ class InfoFibres(gdb.Command):
def get_row_for(self, idx, curr, frame, print_frame_info=True):
def get_row_for(self, idx, curr, frame, print_frame_info=True):
result = ""
result = ""
if (FibreSupport.list[idx] == curr):
if (str(FibreSupport.list[idx]) == curr):
result += "* "
result += "* "
else:
else:
result += " "
result += " "
@@ -163,7 +163,7 @@ class InfoFibres(gdb.Command):
@@ -163,7 +163,7 @@ class InfoFibres(gdb.Command):
if frame is not None and print_frame_info == True:
if frame is not None and print_frame_info == True:
result += '\t' + self.get_frame_string(frame)
result += '\t' + self.get_frame_string(frame)
return result + '\n'
return result
def print_all_fibres(self, curr):
def print_all_fibres(self, curr):
print(self.header)
print(self.header)
@@ -173,8 +173,7 @@ class InfoFibres(gdb.Command):
@@ -173,8 +173,7 @@ class InfoFibres(gdb.Command):
def print_grouped_fibres(self, curr, n):
def print_grouped_fibres(self, curr, n):
all_fibres = FibreSupport.list
all_fibres = FibreSupport.list
frame_groups = {}
groups = {}
line_groups = {}
all_output = []
all_output = []
for i in range(len(FibreSupport.list)):
for i in range(len(FibreSupport.list)):
with FibreSupport.get_frame(FibreSupport.list[i]) as frame:
with FibreSupport.get_frame(FibreSupport.list[i]) as frame:
@@ -184,72 +183,64 @@ class InfoFibres(gdb.Command):
@@ -184,72 +183,64 @@ class InfoFibres(gdb.Command):
))
))
if frame is None:
if frame is None:
continue
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)
# Find stack similarities (up to n frames)
newframe = frame
newframe = frame
for j in range(n+1):
prevframe = None
name = newframe.name()
rip_str = ""
if name is None:
for j in range(n+1):
continue
rip_str += str(newframe.read_register('rip')).split(None, 1)[0] + ","
if name in frame_groups:
# Step one frame up ("older" in gdb's vernacular)
frame_groups[name].append(i)
try:
else:
prevframe = newframe
frame_groups[name] = [i]
newframe = newframe.older()
# Step one frame up
if newframe == None:
try:
newframe = newframe.older()
if newframe == None:
break
except:
break
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()
grouped_indices = set()
# Finally print the groups
sorted_groups = list(groups.items())
for line, indices in line_groups.items():
sorted(sorted_groups, key=lambda x: len(x[1])) # Smaller groups first
if len(indices) <= 1:
for rip, fibres in sorted_groups:
continue
if len(fibres) <= 1:
print("Fibres at line ", line, " :")
# Skip groups of 1
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:
continue
continue
print("Fibres called by ", frame, " :")
print("Fibres called by same line in ", fibres[0][1], " :")
print(self.header)
indices = map(lambda x: x[0], fibres)
 
joined_indices = []
for i in indices:
for i in indices:
fibre_info, frame_info = all_output[i]
print(fibre_info, '\t', frame_info)
grouped_indices.add(i)
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
# Print anything not grouped
ungrouped = set(range(len(all_output))) - grouped_indices
ungrouped = set(range(len(all_output))) - grouped_indices
print('All ungrouped fibres')
if len(ungrouped) > 0:
print(self.header)
print('All ungrouped fibres')
for i in ungrouped:
print(self.header)
fibre_info, frame_info = all_output[i]
for i in ungrouped:
print(fibre_info, '\t', frame_info)
fibre_info, frame_info = all_output[i]
 
print(fibre_info, '\t', frame_info)
def invoke(self, arg, from_tty):
def invoke(self, arg, from_tty):
if (not FibreSupport.saved):
if (not FibreSupport.saved):
return
return
curr = gdb.parse_and_eval("Context::currStack")
curr = str(gdb.parse_and_eval("Context::currStack"))
try:
try:
if (arg != None and int(arg) >= 0):
if (arg != None and int(arg) >= 0):
self.print_grouped_fibres(curr, int(arg))
self.print_grouped_fibres(curr, int(arg))
Loading