Created
March 13, 2024 11:51
-
-
Save Alemiz112/22876467dd84ba7ac073f963ea7dd1a9 to your computer and use it in GitHub Desktop.
GDB Tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gdb | |
def print_enum(argstr, mapper): | |
typename = argstr | |
if not typename or typename.isspace(): | |
raise gdb.GdbError("Usage: print-enum type") | |
try: | |
t = gdb.lookup_type(typename) | |
except gdb.error: | |
typename = "enum " + typename | |
try: | |
t = gdb.lookup_type(typename) | |
except gdb.error: | |
raise gdb.GdbError("type " + typename + " not found") | |
if t.code != gdb.TYPE_CODE_ENUM: | |
raise gdb.GdbError("type " + typename + " is not an enum") | |
for f in t.fields(): | |
print(f.name, "=", mapper(f.enumval)) | |
# | |
# Register commands | |
# | |
class PrintEnumCmd(gdb.Command): | |
def __init__(self): | |
super(PrintEnumCmd, self).__init__("print-enum", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION) | |
def invoke(self, argstr, from_tty): | |
print_enum(argstr, lambda x: x) | |
PrintEnumCmd() | |
class PrintCommandParamsCmd(gdb.Command): | |
def __init__(self): | |
super(PrintCommandParamsCmd, self).__init__("command-params", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION) | |
def invoke(self, argstr, from_tty): | |
print_enum("CommandRegistry::HardNonTerminal", lambda x: x & ~0x100000) | |
PrintCommandParamsCmd() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment