aboutsummaryrefslogtreecommitdiff
path: root/gdb/NEWS
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2021-09-17 18:12:34 +0100
committerAndrew Burgess <aburgess@redhat.com>2022-06-15 09:44:54 +0100
commit15e15b2d9cd3b1db68f99cd3b047352142ddfd1c (patch)
tree6bc04a49dbf8d60839ec0d73638eee4803acd559 /gdb/NEWS
parente4ae302562aba1bd166919d76341fb631e2d470a (diff)
downloadgdb-15e15b2d9cd3b1db68f99cd3b047352142ddfd1c.zip
gdb-15e15b2d9cd3b1db68f99cd3b047352142ddfd1c.tar.gz
gdb-15e15b2d9cd3b1db68f99cd3b047352142ddfd1c.tar.bz2
gdb/python: implement the print_insn extension language hook
This commit extends the Python API to include disassembler support. The motivation for this commit was to provide an API by which the user could write Python scripts that would augment the output of the disassembler. To achieve this I have followed the model of the existing libopcodes disassembler, that is, instructions are disassembled one by one. This does restrict the type of things that it is possible to do from a Python script, i.e. all additional output has to fit on a single line, but this was all I needed, and creating something more complex would, I think, require greater changes to how GDB's internal disassembler operates. The disassembler API is contained in the new gdb.disassembler module, which defines the following classes: DisassembleInfo Similar to libopcodes disassemble_info structure, has read-only properties: address, architecture, and progspace. And has methods: __init__, read_memory, and is_valid. Each time GDB wants an instruction disassembled, an instance of this class is passed to a user written disassembler function, by reading the properties, and calling the methods (and other support methods in the gdb.disassembler module) the user can perform and return the disassembly. Disassembler This is a base-class which user written disassemblers should inherit from. This base class provides base implementations of __init__ and __call__ which the user written disassembler should override. DisassemblerResult This class can be used to hold the result of a call to the disassembler, it's really just a wrapper around a string (the text of the disassembled instruction) and a length (in bytes). The user can return an instance of this class from Disassembler.__call__ to represent the newly disassembled instruction. The gdb.disassembler module also provides the following functions: register_disassembler This function registers an instance of a Disassembler sub-class as a disassembler, either for one specific architecture, or, as a global disassembler for all architectures. builtin_disassemble This provides access to GDB's builtin disassembler. A common use case that I see is augmenting the existing disassembler output. The user code can call this function to have GDB disassemble the instruction in the normal way. The user gets back a DisassemblerResult object, which they can then read in order to augment the disassembler output in any way they wish. This function also provides a mechanism to intercept the disassemblers reads of memory, thus the user can adjust what GDB sees when it is disassembling. The included documentation provides a more detailed description of the API. There is also a new CLI command added: maint info python-disassemblers This command is defined in the Python gdb.disassemblers module, and can be used to list the currently registered Python disassemblers.
Diffstat (limited to 'gdb/NEWS')
-rw-r--r--gdb/NEWS34
1 files changed, 34 insertions, 0 deletions
diff --git a/gdb/NEWS b/gdb/NEWS
index 0efcce7..ac9a1aa 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -63,6 +63,40 @@ maintenance info line-table
** New method gdb.Frame.language that returns the name of the
frame's language.
+ ** New Python API for wrapping GDB's disassembler:
+
+ - gdb.disassembler.register_disassembler(DISASSEMBLER, ARCH).
+ DISASSEMBLER is a sub-class of gdb.disassembler.Disassembler.
+ ARCH is either None or a string containing a bfd architecture
+ name. DISASSEMBLER is registered as a disassembler for
+ architecture ARCH, or for all architectures if ARCH is None.
+ The previous disassembler registered for ARCH is returned, this
+ can be None if no previous disassembler was registered.
+
+ - gdb.disassembler.Disassembler is the class from which all
+ disassemblers should inherit. Its constructor takes a string,
+ a name for the disassembler, which is currently only used in
+ some debug output. Sub-classes should override the __call__
+ method to perform disassembly, invoking __call__ on this base
+ class will raise an exception.
+
+ - gdb.disassembler.DisassembleInfo is the class used to describe
+ a single disassembly request from GDB. An instance of this
+ class is passed to the __call__ method of
+ gdb.disassembler.Disassembler and has the following read-only
+ attributes: 'address', and 'architecture', as well as the
+ following method: 'read_memory'.
+
+ - gdb.disassembler.builtin_disassemble(INFO, MEMORY_SOURCE),
+ calls GDB's builtin disassembler on INFO, which is a
+ gdb.disassembler.DisassembleInfo object. MEMORY_SOURCE is
+ optional, its default value is None. If MEMORY_SOURCE is not
+ None then it must be an object that has a 'read_memory' method.
+
+ - gdb.disassembler.DisassemblerResult is a class that can be used
+ to wrap the result of a call to a Disassembler. It has
+ read-only attributes 'length' and 'string'.
+
*** Changes in GDB 12
* DBX mode is deprecated, and will be removed in GDB 13