GDB (xrefs)
Loading...
Searching...
No Matches
Classes | Macros | Functions | Variables
py-disasm.c File Reference
#include "defs.h"
#include "python-internal.h"
#include "language.h"
#include "dis-asm.h"
#include "arch-utils.h"
#include "charset.h"
#include "disasm.h"
#include "progspace.h"

Go to the source code of this file.

Classes

struct  disasm_info_object
 
struct  disasm_addr_part_object
 
struct  disasm_text_part_object
 
struct  disasm_result_object
 
struct  gdbpy_disassembler
 
struct  scoped_disasm_info_object
 

Macros

#define DISASMPY_DISASM_INFO_REQUIRE_VALID(Info)
 

Functions

PyTypeObject disasm_info_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_info_object")
 
PyTypeObject disasm_addr_part_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_addr_part_object")
 
PyTypeObject disasm_text_part_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_text_part_object")
 
PyTypeObject disasm_part_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("PyObject")
 
PyTypeObject disasm_result_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_result_object")
 
static bool disasm_info_object_is_valid (disasm_info_object *obj)
 
static void disasm_info_fill (disasm_info_object *obj, struct gdbarch *gdbarch, program_space *progspace, bfd_vma address, disassemble_info *di, disasm_info_object *next)
 
static int disasm_info_init (PyObject *self, PyObject *args, PyObject *kwargs)
 
static void disasm_info_dealloc (PyObject *self)
 
static PyObjectdisasmpy_info_repr (PyObject *self)
 
static PyObjectdisasmpy_info_is_valid (PyObject *self, PyObject *args)
 
static void disasmpy_set_memory_error_for_address (CORE_ADDR address)
 
static gdbpy_ref make_disasm_text_part (std::string &&str, enum disassembler_style style)
 
static gdbpy_ref make_disasm_addr_part (struct gdbarch *gdbarch, CORE_ADDR address)
 
static PyObjectdisasmpy_info_make_text_part (PyObject *self, PyObject *args, PyObject *kwargs)
 
static PyObjectdisasmpy_info_make_address_part (PyObject *self, PyObject *args, PyObject *kwargs)
 
static std::string disasmpy_part_to_string (const disasm_text_part_object *text_part)
 
static std::string disasmpy_part_to_string (const disasm_addr_part_object *addr_part)
 
static std::string disasmpy_parts_list_to_string (const std::vector< gdbpy_ref<> > &parts)
 
static void disasmpy_init_disassembler_result (disasm_result_object *obj, int length, std::vector< gdbpy_ref<> > &&parts)
 
static PyObjectdisasmpy_builtin_disassemble (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObjectdisasmpy_set_enabled (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObjectdisasmpy_info_read_memory (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObjectdisasmpy_info_address (PyObject *self, void *closure)
 
static PyObjectdisasmpy_info_architecture (PyObject *self, void *closure)
 
static PyObjectdisasmpy_info_progspace (PyObject *self, void *closure)
 
static PyObjectdisasmpy_result_str (PyObject *self)
 
static PyObjectdisasmpy_result_length (PyObject *self, void *closure)
 
static PyObjectdisasmpy_result_string (PyObject *self, void *closure)
 
static PyObjectdisasmpy_result_parts (PyObject *self, void *closure)
 
static int disasmpy_result_init (PyObject *self, PyObject *args, PyObject *kwargs)
 
static PyObjectdisasmpy_result_repr (PyObject *self)
 
gdb::optional< int > gdbpy_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr, disassemble_info *info)
 
static void disasmpy_dealloc_result (PyObject *self)
 
static int disasmpy_part_init (PyObject *self, PyObject *args, PyObject *kwargs)
 
static const char * get_style_name (enum disassembler_style style)
 
static PyObjectdisasmpy_text_part_repr (PyObject *self)
 
static PyObjectdisasmpy_text_part_str (PyObject *self)
 
static PyObjectdisasmpy_text_part_string (PyObject *self, void *closure)
 
static PyObjectdisasmpy_text_part_style (PyObject *self, void *closure)
 
static PyObjectdisasmpy_addr_part_repr (PyObject *self)
 
static PyObjectdisasmpy_addr_part_str (PyObject *self)
 
static PyObjectdisasmpy_addr_part_string (PyObject *self, void *closure)
 
static PyObjectdisasmpy_addr_part_address (PyObject *self, void *closure)
 
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_disasm ()
 
 GDBPY_INITIALIZE_FILE (gdbpy_initialize_disasm)
 

Variables

static bool python_print_insn_enabled = false
 
static gdb_PyGetSetDef disasm_info_object_getset []
 
static PyMethodDef disasm_info_object_methods []
 
static gdb_PyGetSetDef disasm_result_object_getset []
 
static gdb_PyGetSetDef disasmpy_text_part_getset []
 
static gdb_PyGetSetDef disasmpy_addr_part_getset []
 
PyMethodDef python_disassembler_methods []
 
static struct PyModuleDef python_disassembler_module_def
 
PyTypeObject disasm_info_object_type
 
PyTypeObject disasm_result_object_type
 
PyTypeObject disasm_part_object_type
 
PyTypeObject disasm_text_part_object_type
 
PyTypeObject disasm_addr_part_object_type
 

Macro Definition Documentation

◆ DISASMPY_DISASM_INFO_REQUIRE_VALID

#define DISASMPY_DISASM_INFO_REQUIRE_VALID ( Info)
Value:
do { \
{ \
PyErr_SetString (PyExc_RuntimeError, \
_("DisassembleInfo is no longer valid.")); \
return nullptr; \
} \
} while (0)
static bool disasm_info_object_is_valid(disasm_info_object *obj)
Definition py-disasm.c:255

Definition at line 389 of file py-disasm.c.

Referenced by disasmpy_builtin_disassemble(), disasmpy_info_address(), disasmpy_info_architecture(), disasmpy_info_make_address_part(), disasmpy_info_make_text_part(), disasmpy_info_progspace(), and disasmpy_info_read_memory().

Function Documentation

◆ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF() [1/5]

PyTypeObject disasm_addr_part_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ( "disasm_addr_part_object" )
extern

◆ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF() [2/5]

PyTypeObject disasm_info_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ( "disasm_info_object" )
extern

◆ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF() [3/5]

PyTypeObject disasm_result_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ( "disasm_result_object" )
extern

◆ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF() [4/5]

PyTypeObject disasm_text_part_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ( "disasm_text_part_object" )
extern

◆ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF() [5/5]

PyTypeObject disasm_part_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ( "PyObject" )
extern

◆ disasm_info_dealloc()

static void disasm_info_dealloc ( PyObject * self)
static

Definition at line 303 of file py-disasm.c.

References disasm_info_object::next.

◆ disasm_info_fill()

static void disasm_info_fill ( disasm_info_object * obj,
struct gdbarch * gdbarch,
program_space * progspace,
bfd_vma address,
disassemble_info * di,
disasm_info_object * next )
static

◆ disasm_info_init()

static int disasm_info_init ( PyObject * self,
PyObject * args,
PyObject * kwargs )
static

◆ disasm_info_object_is_valid()

static bool disasm_info_object_is_valid ( disasm_info_object * obj)
static

Definition at line 255 of file py-disasm.c.

References disasm_info_object::gdb_info.

Referenced by disasmpy_info_is_valid().

◆ disasmpy_addr_part_address()

static PyObject * disasmpy_addr_part_address ( PyObject * self,
void * closure )
static

Definition at line 1533 of file py-disasm.c.

References disasm_addr_part_object::address, and gdb_py_object_from_longest().

◆ disasmpy_addr_part_repr()

static PyObject * disasmpy_addr_part_repr ( PyObject * self)
static

Definition at line 1490 of file py-disasm.c.

References disasm_addr_part_object::address.

◆ disasmpy_addr_part_str()

static PyObject * disasmpy_addr_part_str ( PyObject * self)
static

◆ disasmpy_addr_part_string()

static PyObject * disasmpy_addr_part_string ( PyObject * self,
void * closure )
static

Definition at line 1525 of file py-disasm.c.

References disasmpy_addr_part_str().

◆ disasmpy_builtin_disassemble()

static PyObject * disasmpy_builtin_disassemble ( PyObject * self,
PyObject * args,
PyObject * kw )
static

◆ disasmpy_dealloc_result()

static void disasmpy_dealloc_result ( PyObject * self)
static

Definition at line 1400 of file py-disasm.c.

References disasm_result_object::parts.

◆ disasmpy_info_address()

static PyObject * disasmpy_info_address ( PyObject * self,
void * closure )
static

◆ disasmpy_info_architecture()

static PyObject * disasmpy_info_architecture ( PyObject * self,
void * closure )
static

◆ disasmpy_info_is_valid()

static PyObject * disasmpy_info_is_valid ( PyObject * self,
PyObject * args )
static

Definition at line 335 of file py-disasm.c.

References disasm_info_object_is_valid().

◆ disasmpy_info_make_address_part()

static PyObject * disasmpy_info_make_address_part ( PyObject * self,
PyObject * args,
PyObject * kwargs )
static

◆ disasmpy_info_make_text_part()

static PyObject * disasmpy_info_make_text_part ( PyObject * self,
PyObject * args,
PyObject * kwargs )
static

◆ disasmpy_info_progspace()

static PyObject * disasmpy_info_progspace ( PyObject * self,
void * closure )
static

◆ disasmpy_info_read_memory()

static PyObject * disasmpy_info_read_memory ( PyObject * self,
PyObject * args,
PyObject * kw )
static

◆ disasmpy_info_repr()

static PyObject * disasmpy_info_repr ( PyObject * self)
static

◆ disasmpy_init_disassembler_result()

static void disasmpy_init_disassembler_result ( disasm_result_object * obj,
int length,
std::vector< gdbpy_ref<> > && parts )
static

◆ disasmpy_part_init()

static int disasmpy_part_init ( PyObject * self,
PyObject * args,
PyObject * kwargs )
static

Definition at line 1412 of file py-disasm.c.

◆ disasmpy_part_to_string() [1/2]

static std::string disasmpy_part_to_string ( const disasm_addr_part_object * addr_part)
static

◆ disasmpy_part_to_string() [2/2]

static std::string disasmpy_part_to_string ( const disasm_text_part_object * text_part)
static

Definition at line 463 of file py-disasm.c.

References disasm_text_part_object::string.

Referenced by disasmpy_parts_list_to_string().

◆ disasmpy_parts_list_to_string()

static std::string disasmpy_parts_list_to_string ( const std::vector< gdbpy_ref<> > & parts)
static

◆ disasmpy_result_init()

static int disasmpy_result_init ( PyObject * self,
PyObject * args,
PyObject * kwargs )
static

◆ disasmpy_result_length()

static PyObject * disasmpy_result_length ( PyObject * self,
void * closure )
static

Definition at line 947 of file py-disasm.c.

References gdb_py_object_from_longest(), and disasm_result_object::length.

◆ disasmpy_result_parts()

static PyObject * disasmpy_result_parts ( PyObject * self,
void * closure )
static

Definition at line 967 of file py-disasm.c.

References disasm_result_object::length, and disasm_result_object::parts.

◆ disasmpy_result_repr()

static PyObject * disasmpy_result_repr ( PyObject * self)
static

◆ disasmpy_result_str()

static PyObject * disasmpy_result_str ( PyObject * self)
static

◆ disasmpy_result_string()

static PyObject * disasmpy_result_string ( PyObject * self,
void * closure )
static

Definition at line 957 of file py-disasm.c.

References disasmpy_result_str().

◆ disasmpy_set_enabled()

static PyObject * disasmpy_set_enabled ( PyObject * self,
PyObject * args,
PyObject * kw )
static

Definition at line 639 of file py-disasm.c.

References gdb_PyArg_ParseTupleAndKeywords(), and python_print_insn_enabled.

◆ disasmpy_set_memory_error_for_address()

static void disasmpy_set_memory_error_for_address ( CORE_ADDR address)
static

◆ disasmpy_text_part_repr()

static PyObject * disasmpy_text_part_repr ( PyObject * self)
static

◆ disasmpy_text_part_str()

static PyObject * disasmpy_text_part_str ( PyObject * self)
static

Definition at line 1460 of file py-disasm.c.

References host_charset(), and disasm_text_part_object::string.

Referenced by disasmpy_text_part_string().

◆ disasmpy_text_part_string()

static PyObject * disasmpy_text_part_string ( PyObject * self,
void * closure )
static

Definition at line 1471 of file py-disasm.c.

References disasmpy_text_part_str().

◆ disasmpy_text_part_style()

static PyObject * disasmpy_text_part_style ( PyObject * self,
void * closure )
static

Definition at line 1479 of file py-disasm.c.

References gdb_py_object_from_longest(), and disasm_text_part_object::style.

◆ gdbpy_initialize_disasm()

static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_disasm ( )
static

◆ GDBPY_INITIALIZE_FILE()

GDBPY_INITIALIZE_FILE ( gdbpy_initialize_disasm )

◆ gdbpy_print_insn()

gdb::optional< int > gdbpy_print_insn ( struct gdbarch * gdbarch,
CORE_ADDR memaddr,
disassemble_info * info )

◆ get_style_name()

static const char * get_style_name ( enum disassembler_style style)
static

Definition at line 1423 of file py-disasm.c.

Referenced by disasmpy_text_part_repr(), and gdbpy_initialize_disasm().

◆ make_disasm_addr_part()

static gdbpy_ref make_disasm_addr_part ( struct gdbarch * gdbarch,
CORE_ADDR address )
static

◆ make_disasm_text_part()

static gdbpy_ref make_disasm_text_part ( std::string && str,
enum disassembler_style style )
static

Variable Documentation

◆ disasm_addr_part_object_type

PyTypeObject disasm_addr_part_object_type

◆ disasm_info_object_getset

gdb_PyGetSetDef disasm_info_object_getset[]
static
Initial value:
= {
{ "address", disasmpy_info_address, nullptr,
"Start address of the instruction to disassemble.", nullptr },
{ "architecture", disasmpy_info_architecture, nullptr,
"Architecture to disassemble in", nullptr },
{ "progspace", disasmpy_info_progspace, nullptr,
"Program space to disassemble in", nullptr },
{ nullptr }
}
static PyObject * disasmpy_info_architecture(PyObject *self, void *closure)
Definition py-disasm.c:717
static PyObject * disasmpy_info_address(PyObject *self, void *closure)
Definition py-disasm.c:706
static PyObject * disasmpy_info_progspace(PyObject *self, void *closure)
Definition py-disasm.c:728

Definition at line 1542 of file py-disasm.c.

◆ disasm_info_object_methods

PyMethodDef disasm_info_object_methods[]
static
Initial value:
= {
{ "read_memory", (PyCFunction) disasmpy_info_read_memory,
METH_VARARGS | METH_KEYWORDS,
"read_memory (LEN, OFFSET = 0) -> Octets[]\n\
Read LEN octets for the instruction to disassemble." },
{ "is_valid", disasmpy_info_is_valid, METH_NOARGS,
"is_valid () -> Boolean.\n\
Return true if this DisassembleInfo is valid, false if not." },
{ "text_part", (PyCFunction) disasmpy_info_make_text_part,
METH_VARARGS | METH_KEYWORDS,
"text_part (STRING, STYLE) -> DisassemblerTextPart\n\
Create a new text part, with contents STRING styled with STYLE." },
{ "address_part", (PyCFunction) disasmpy_info_make_address_part,
METH_VARARGS | METH_KEYWORDS,
"address_part (ADDRESS) -> DisassemblerAddressPart\n\
Create a new address part representing ADDRESS." },
{nullptr}
}
static PyObject * disasmpy_info_make_text_part(PyObject *self, PyObject *args, PyObject *kwargs)
Definition py-disasm.c:403
static PyObject * disasmpy_info_read_memory(PyObject *self, PyObject *args, PyObject *kw)
Definition py-disasm.c:666
static PyObject * disasmpy_info_is_valid(PyObject *self, PyObject *args)
Definition py-disasm.c:335
static PyObject * disasmpy_info_make_address_part(PyObject *self, PyObject *args, PyObject *kwargs)
Definition py-disasm.c:440

Definition at line 1554 of file py-disasm.c.

◆ disasm_info_object_type

PyTypeObject disasm_info_object_type

◆ disasm_part_object_type

PyTypeObject disasm_part_object_type

Definition at line 1805 of file py-disasm.c.

Referenced by gdbpy_initialize_disasm().

◆ disasm_result_object_getset

gdb_PyGetSetDef disasm_result_object_getset[]
static
Initial value:
= {
{ "length", disasmpy_result_length, nullptr,
"Length of the disassembled instruction.", nullptr },
{ "string", disasmpy_result_string, nullptr,
"String representing the disassembled instruction.", nullptr },
{ "parts", disasmpy_result_parts, nullptr,
"List of all the separate disassembly parts", nullptr },
{ nullptr }
}
static PyObject * disasmpy_result_length(PyObject *self, void *closure)
Definition py-disasm.c:947
static PyObject * disasmpy_result_parts(PyObject *self, void *closure)
Definition py-disasm.c:967
static PyObject * disasmpy_result_string(PyObject *self, void *closure)
Definition py-disasm.c:957

Definition at line 1575 of file py-disasm.c.

◆ disasm_result_object_type

PyTypeObject disasm_result_object_type

◆ disasm_text_part_object_type

PyTypeObject disasm_text_part_object_type

◆ disasmpy_addr_part_getset

gdb_PyGetSetDef disasmpy_addr_part_getset[]
static
Initial value:
= {
{ "string", disasmpy_addr_part_string, nullptr,
"String representing an address part.", nullptr },
{ "address", disasmpy_addr_part_address, nullptr,
"The address of this address part.", nullptr },
{ nullptr }
}
static PyObject * disasmpy_addr_part_string(PyObject *self, void *closure)
Definition py-disasm.c:1525
static PyObject * disasmpy_addr_part_address(PyObject *self, void *closure)
Definition py-disasm.c:1533

Definition at line 1597 of file py-disasm.c.

◆ disasmpy_text_part_getset

gdb_PyGetSetDef disasmpy_text_part_getset[]
static
Initial value:
= {
{ "string", disasmpy_text_part_string, nullptr,
"String representing a text part.", nullptr },
{ "style", disasmpy_text_part_style, nullptr,
"The style of this text part.", nullptr },
{ nullptr }
}
static PyObject * disasmpy_text_part_string(PyObject *self, void *closure)
Definition py-disasm.c:1471
static PyObject * disasmpy_text_part_style(PyObject *self, void *closure)
Definition py-disasm.c:1479

Definition at line 1587 of file py-disasm.c.

◆ python_disassembler_methods

PyMethodDef python_disassembler_methods[]
Initial value:
=
{
{ "builtin_disassemble", (PyCFunction) disasmpy_builtin_disassemble,
METH_VARARGS | METH_KEYWORDS,
"builtin_disassemble (INFO, MEMORY_SOURCE = None) -> None\n\
Disassemble using GDB's builtin disassembler. INFO is an instance of\n\
gdb.disassembler.DisassembleInfo. The MEMORY_SOURCE, if not None, should\n\
be an object with the read_memory method." },
{ "_set_enabled", (PyCFunction) disasmpy_set_enabled,
METH_VARARGS | METH_KEYWORDS,
"_set_enabled (STATE) -> None\n\
Set whether GDB should call into the Python _print_insn code or not." },
{nullptr, nullptr, 0, nullptr}
}
static PyObject * disasmpy_set_enabled(PyObject *self, PyObject *args, PyObject *kw)
Definition py-disasm.c:639
static PyObject * disasmpy_builtin_disassemble(PyObject *self, PyObject *args, PyObject *kw)
Definition py-disasm.c:541

Definition at line 1609 of file py-disasm.c.

◆ python_disassembler_module_def

struct PyModuleDef python_disassembler_module_def
static
Initial value:
=
{
PyModuleDef_HEAD_INIT,
"_gdb.disassembler",
nullptr,
-1,
nullptr,
nullptr,
nullptr,
nullptr
}
PyMethodDef python_disassembler_methods[]
Definition py-disasm.c:1609

Definition at line 1626 of file py-disasm.c.

Referenced by gdbpy_initialize_disasm().

◆ python_print_insn_enabled

bool python_print_insn_enabled = false
static

Definition at line 127 of file py-disasm.c.

Referenced by disasmpy_set_enabled(), and gdbpy_print_insn().