16"""Disassembler related module."""
39_disassemblers_dict = {}
43 """A base class from which all user implemented disassemblers must
47 """Constructor. Takes a name, which should be a string, which can be
48 used to identify this disassembler in diagnostic messages.
"""
52 """A default implementation of __call__. All sub-classes must
53 override this method. Calling this default implementation will throw
54 a NotImplementedError exception."""
55 raise NotImplementedError(
"Disassembler.__call__")
59 """Register a disassembler. DISASSEMBLER is a sub-
class of
61 string, the name of an architecture known to GDB.
63 DISASSEMBLER
is registered
as a disassembler
for ARCHITECTURE,
or
64 all architectures when ARCHITECTURE
is None.
66 Returns the previous disassembler registered
with this
70 if not isinstance(disassembler, Disassembler)
and disassembler
is not None:
71 raise TypeError(
"disassembler should sub-class gdb.disassembler.Disassembler")
74 if architecture
in _disassemblers_dict:
75 old = _disassemblers_dict[architecture]
76 del _disassemblers_dict[architecture]
77 if disassembler
is not None:
78 _disassemblers_dict[architecture] = disassembler
86 _gdb.disassembler._set_enabled(len(_disassemblers_dict) > 0)
91 """This function is called by GDB when it wants to disassemble an
92 instruction. INFO describes the instruction to be
95 def lookup_disassembler(arch):
100 if name
in _disassemblers_dict:
101 return _disassemblers_dict[name]
102 if None in _disassemblers_dict:
103 return _disassemblers_dict[
None]
112 disassembler = lookup_disassembler(info.architecture)
113 if disassembler
is None:
115 return disassembler(info)
120 List all registered Python disassemblers.
122 List the name of all registered Python disassemblers, next to the
123 name of the architecture for which the disassembler
is registered.
125 The
global Python disassembler
is listed next to the string
128 The disassembler that matches the architecture of the currently
129 selected inferior will be marked, this
is an indication of which
130 disassembler will be invoked
if any disassembly
is performed
in
131 the current inferior.
135 super().
__init__(
"maintenance info python-disassemblers", gdb.COMMAND_USER)
139 if len(_disassemblers_dict) == 0:
140 print(
"No Python disassemblers registered.")
145 longest_arch_name = 0
146 for architecture
in _disassemblers_dict:
147 if architecture
is not None:
148 name = _disassemblers_dict[architecture].name
149 if len(name) > longest_arch_name:
150 longest_arch_name = len(name)
157 if gdb.selected_inferior()
is not None:
158 curr_arch = gdb.selected_inferior().architecture().
name()
162 match_tag =
"\t(Matches current architecture)"
163 fmt_len = max(longest_arch_name, len(
"Architecture"))
164 format_string =
"{:" + str(fmt_len) +
"s} {:s}"
165 print(format_string.format(
"Architecture",
"Disassember Name"))
166 for architecture
in _disassemblers_dict:
167 if architecture
is not None:
168 name = _disassemblers_dict[architecture].name
169 if architecture == curr_arch:
172 print(format_string.format(architecture, name))
173 if None in _disassemblers_dict:
174 name = _disassemblers_dict[
None].name + match_tag
175 print(format_string.format(
"GLOBAL", name))
def invoke(self, args, from_tty)
def register_disassembler(disassembler, architecture=None)