Skip to content

Instantly share code, notes, and snippets.

@k3DW
Created August 15, 2024 03:24
Show Gist options
  • Save k3DW/19f0acbaef749efd9414527ef45cf113 to your computer and use it in GitHub Desktop.
Save k3DW/19f0acbaef749efd9414527ef45cf113 to your computer and use it in GitHub Desktop.
class BoostUnorderedPrintStatsCommand(gdb.Command):
def __init__(self):
super(BoostUnorderedPrintStatsCommand, self).__init__("print_stats", gdb.COMMAND_USER)
def invoke(self, args, from_tty):
args = gdb.string_to_argv(args)
val = gdb.parse_and_eval(args[-1])
visualizer = gdb.default_visualizer(val)
if type(visualizer) is not BoostUnorderedFoaPrinter:
# Usage string adapted from https://sourceware.org/gdb/current/onlinedocs/gdb.html/Data.html
print("Error: Incorrect type\nUsage: print_stats [[options] --] [/f] <open-addressing-container>")
return
try:
val["table_"]["cstats"]
except gdb.error:
print("Error: Cannot print stats. Binary was compiled without stats\nSolution: define `BOOST_UNORDERED_ENABLE_STATS`")
return
other_args = " ".join(args[:-1])
printed = gdb.execute(f"print {other_args} {args[-1]}.table_.cstats", from_tty, True)
output = re.sub("^(\$[1-9]+ = )", f"\\1{visualizer.to_string()} ", printed)
print(output, end="")
BoostUnorderedPrintStatsCommand()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment