diff options
| author | Andrew Burgess <aburgess@redhat.com> | 2026-03-20 15:05:16 +0000 |
|---|---|---|
| committer | Andrew Burgess <aburgess@redhat.com> | 2026-03-23 10:15:11 +0000 |
| commit | 285072c3d5612f8eeaf3d621346ab4a2586c7bf0 (patch) | |
| tree | 2b74c06b87e9c9632d37b52d870b7ff4222ecab5 /gdb/python | |
| parent | 55a0f464f57f73f6e07d71f55e99a518265d80d7 (diff) | |
| download | binutils-285072c3d5612f8eeaf3d621346ab4a2586c7bf0.tar.gz binutils-285072c3d5612f8eeaf3d621346ab4a2586c7bf0.tar.bz2 binutils-285072c3d5612f8eeaf3d621346ab4a2586c7bf0.zip | |
gdb/python: allow Architecture.disassemble to give styled output
Extend the Architecture.disassemble API to allow the user to request
styled disassembler output via a new styling argument. A user can now
write:
insn = arch.disassemble(address, styling = True)
The instruction strings returned within INSN will contain ANSI escape
sequences so long as 'set style enabled on' is in effect. This means
that the user's personal settings (disabling styling) will override a
GDB extension that requests styled disassembler output. I think this
makes sense.
The default for the styling argument is False, this maintains the
current unstyled output as default.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python')
| -rw-r--r-- | gdb/python/py-arch.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index f40d7da1763..4031f925b04 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -124,18 +124,21 @@ archpy_name (PyObject *self, PyObject *args) static PyObject * archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) { - static const char *keywords[] = { "start_pc", "end_pc", "count", NULL }; + static const char *keywords[] = { + "start_pc", "end_pc", "count", "styling", nullptr + }; CORE_ADDR start = 0, end = 0; CORE_ADDR pc; long count = 0, i; PyObject *start_obj = nullptr, *end_obj = nullptr, *count_obj = nullptr; struct gdbarch *gdbarch = NULL; + int styling_p = 0; ARCHPY_REQUIRE_VALID (self, gdbarch); - if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O|OO", + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O|OOp", keywords, &start_obj, &end_obj, - &count_obj)) + &count_obj, &styling_p)) return NULL; if (get_addr_from_python (start_obj, &start) < 0) @@ -190,7 +193,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) if (PyList_Append (result_list.get (), insn_dict.get ())) return NULL; /* PyList_Append Sets the exception. */ - string_file stb; + string_file stb (styling_p); try { |
